[unseasoned-pdf] Avoid using blink::WebString in the Pepper process
blink::WebString's allocators can only be used if Blink is initialized. Instead of initializing Blink, just avoid using blink::WebString in the few places they're used in the Pepper process, at least for as long as the Pepper process exists. Change-Id: I73130fb840179a2c02e6ed6e1aeffae2e4f2f704 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3018059 Commit-Queue: Daniel Hosseinian <dhoss@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Cr-Commit-Position: refs/heads/master@{#900584}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
e4d8f80727
commit
e42d6a6412
pdf
@ -144,7 +144,12 @@ void* MapFont(FPDF_SYSFONTINFO*,
|
||||
if (strcmp(face, "Symbol") == 0)
|
||||
return nullptr;
|
||||
|
||||
// TODO(crbug.com/702993): `blink::WebFontDescription::family` is a
|
||||
// `blink::WebString`, which can only be used if Blink is initialized. Store
|
||||
// the field in `font_family` for now, but remove the variable when this code
|
||||
// will only execute in a renderer process.
|
||||
blink::WebFontDescription desc;
|
||||
std::string font_family;
|
||||
|
||||
if (pitch_family & FXFONT_FF_FIXEDPITCH) {
|
||||
desc.generic_family = blink::WebFontDescription::kGenericFamilyMonospace;
|
||||
@ -203,7 +208,7 @@ void* MapFont(FPDF_SYSFONTINFO*,
|
||||
size_t i;
|
||||
for (i = 0; i < base::size(kPdfFontSubstitutions); ++i) {
|
||||
if (strcmp(face, kPdfFontSubstitutions[i].pdf_name) == 0) {
|
||||
desc.family = blink::WebString::FromUTF8(kPdfFontSubstitutions[i].face);
|
||||
font_family = kPdfFontSubstitutions[i].face;
|
||||
if (kPdfFontSubstitutions[i].bold)
|
||||
desc.weight = blink::WebFontDescription::kWeightBold;
|
||||
if (kPdfFontSubstitutions[i].italic)
|
||||
@ -228,15 +233,16 @@ void* MapFont(FPDF_SYSFONTINFO*,
|
||||
if (face_utf8.empty())
|
||||
return nullptr;
|
||||
|
||||
desc.family = blink::WebString::FromUTF8(face_utf8);
|
||||
font_family = face_utf8;
|
||||
desc.weight = WeightToBlinkWeight(weight);
|
||||
desc.italic = italic > 0;
|
||||
}
|
||||
|
||||
if (PDFiumEngine::GetFontMappingMode() == FontMappingMode::kPepper)
|
||||
return MapPepperFont(desc, charset);
|
||||
return MapPepperFont(desc, font_family, charset);
|
||||
|
||||
DCHECK_EQ(PDFiumEngine::GetFontMappingMode(), FontMappingMode::kBlink);
|
||||
desc.family = blink::WebString::FromUTF8(font_family);
|
||||
return GetBlinkFontMapper().MapFont(desc, charset);
|
||||
}
|
||||
|
||||
|
@ -39,8 +39,11 @@ FONT_WEIGHT_MATCH_ASSERT(900);
|
||||
|
||||
} // namespace
|
||||
|
||||
void* MapPepperFont(const blink::WebFontDescription& desc, int charset) {
|
||||
void* MapPepperFont(const blink::WebFontDescription& desc,
|
||||
const std::string& font_family,
|
||||
int charset) {
|
||||
DCHECK(pp::PDF::IsAvailable());
|
||||
DCHECK(desc.family.IsEmpty());
|
||||
|
||||
pp::BrowserFontDescription description;
|
||||
|
||||
@ -52,7 +55,7 @@ void* MapPepperFont(const blink::WebFontDescription& desc, int charset) {
|
||||
description.set_family(PP_BROWSERFONT_TRUSTED_FAMILY_SERIF);
|
||||
}
|
||||
|
||||
description.set_face(desc.family.Utf8());
|
||||
description.set_face(font_family);
|
||||
description.set_weight(ToPepperWeight(desc.weight));
|
||||
description.set_italic(desc.italic);
|
||||
|
||||
|
@ -5,6 +5,8 @@
|
||||
#ifndef PDF_PPAPI_MIGRATION_PDFIUM_FONT_LINUX_H_
|
||||
#define PDF_PPAPI_MIGRATION_PDFIUM_FONT_LINUX_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace blink {
|
||||
struct WebFontDescription;
|
||||
}
|
||||
@ -15,9 +17,12 @@ class Instance;
|
||||
|
||||
namespace chrome_pdf {
|
||||
|
||||
// Returns a handle to the font mapped based on `desc` and `charset`, for use
|
||||
// as the font_id in GetPepperFontData() and DeletePepperFont() below.
|
||||
void* MapPepperFont(const blink::WebFontDescription& desc, int charset);
|
||||
// Returns a handle to the font mapped based on `desc`, `font_family`, and
|
||||
// `charset`. The handle is for use as the `font_id` in `GetPepperFontData()`
|
||||
// and `DeletePepperFont()` below.
|
||||
void* MapPepperFont(const blink::WebFontDescription& desc,
|
||||
const std::string& font_family,
|
||||
int charset);
|
||||
|
||||
// Reads data from the `font_id` handle for `table` into a `buffer` of
|
||||
// `buf_size`. Returns the amount of data read on success, or 0 on failure. If
|
||||
|
Reference in New Issue
Block a user