Commit 0dc678ff authored by Dominik Röttsches's avatar Dominik Röttsches Committed by Commit Bot

Fix Mimehandler out-of-process FontConfig access

r572930 moved FontConfig out of process access from a global file
descriptor to Mojo messages. In one instance, PepperFlashFontFileHost,
an IPC performing FontConfig method was replaced with one that tries to
access FontConfig inside the sandboxed process, which fails. The
mimehandler process needs access to FontConfig as well for providing
fonts matching to PDFium.

This CL fixes mimehandler out of process font access and moves back to
using the MatchFontWithFallback FontConfig logic which was previously
used in this file, before it was moved to using Skia font matching like
on Windows. This implies that on Linux additional font fallback logic is
used again, which finds replacements for non-existing fonts such as
SimSun.

Bug: 862051
Change-Id: I67136d51b45f72db0ae74201353369e34885f2ef
Reviewed-on: https://chromium-review.googlesource.com/1131938
Commit-Queue: Dominik Röttsches <drott@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#574119}
parent 858ba7c4
...@@ -219,6 +219,10 @@ static_library("renderer") { ...@@ -219,6 +219,10 @@ static_library("renderer") {
"//ppapi/proxy:ipc", "//ppapi/proxy:ipc",
"//ppapi/shared_impl", "//ppapi/shared_impl",
] ]
if (is_linux) {
deps += [ "//components/services/font/public/cpp" ]
}
} }
if (safe_browsing_mode != 0) { if (safe_browsing_mode != 0) {
......
include_rules = [ include_rules = [
"+components/nacl/common", "+components/nacl/common",
"+components/nacl/renderer", "+components/nacl/renderer",
"+components/services/font",
"+ppapi/host", "+ppapi/host",
"+ppapi/proxy", "+ppapi/proxy",
......
...@@ -7,44 +7,19 @@ ...@@ -7,44 +7,19 @@
#include "base/sys_byteorder.h" #include "base/sys_byteorder.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "content/public/renderer/renderer_ppapi_host.h" #include "content/public/renderer/renderer_ppapi_host.h"
#include "ppapi/c/pp_errors.h" #include "ppapi/c/pp_errors.h"
#include "ppapi/host/dispatch_host_message.h" #include "ppapi/host/dispatch_host_message.h"
#include "ppapi/host/host_message_context.h" #include "ppapi/host/host_message_context.h"
#include "ppapi/host/ppapi_host.h" #include "ppapi/host/ppapi_host.h"
#include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/proxy/serialized_structs.h" #include "ppapi/proxy/serialized_structs.h"
#include "third_party/skia/include/core/SkFontMgr.h"
#if !defined(OS_WIN)
namespace {
SkFontStyle::Weight PepperWeightToSkWeight(int pepper_weight) {
switch (pepper_weight) {
case PP_BROWSERFONT_TRUSTED_WEIGHT_100:
return SkFontStyle::kThin_Weight;
case PP_BROWSERFONT_TRUSTED_WEIGHT_200:
return SkFontStyle::kExtraLight_Weight;
case PP_BROWSERFONT_TRUSTED_WEIGHT_300:
return SkFontStyle::kLight_Weight;
case PP_BROWSERFONT_TRUSTED_WEIGHT_400:
return SkFontStyle::kNormal_Weight;
case PP_BROWSERFONT_TRUSTED_WEIGHT_500:
return SkFontStyle::kMedium_Weight;
case PP_BROWSERFONT_TRUSTED_WEIGHT_600:
return SkFontStyle::kSemiBold_Weight;
case PP_BROWSERFONT_TRUSTED_WEIGHT_700:
return SkFontStyle::kBold_Weight;
case PP_BROWSERFONT_TRUSTED_WEIGHT_800:
return SkFontStyle::kExtraBold_Weight;
case PP_BROWSERFONT_TRUSTED_WEIGHT_900:
return SkFontStyle::kBlack_Weight;
default:
NOTREACHED();
return SkFontStyle::kInvisible_Weight;
}
}
} // namespace #if defined(OS_LINUX) || defined(OS_OPENBSD)
#include "components/services/font/public/cpp/font_loader.h"
#include "content/public/common/common_sandbox_support_linux.h"
#elif defined(OS_WIN)
#include "third_party/skia/include/core/SkFontMgr.h"
#endif #endif
PepperFlashFontFileHost::PepperFlashFontFileHost( PepperFlashFontFileHost::PepperFlashFontFileHost(
...@@ -54,16 +29,25 @@ PepperFlashFontFileHost::PepperFlashFontFileHost( ...@@ -54,16 +29,25 @@ PepperFlashFontFileHost::PepperFlashFontFileHost(
const ppapi::proxy::SerializedFontDescription& description, const ppapi::proxy::SerializedFontDescription& description,
PP_PrivateFontCharset charset) PP_PrivateFontCharset charset)
: ResourceHost(host->GetPpapiHost(), instance, resource) { : ResourceHost(host->GetPpapiHost(), instance, resource) {
int weight; #if defined(OS_LINUX)
#if defined(OS_WIN) // The global SkFontConfigInterface is configured and initialized with a
// TODO(https://crbug.com/857388): Figure out why this diverges from the // SkFontconfigInterface compatible font_service::FontLoader in
// #else block. // RendererBlinkPlatformImpl (called from RenderThreadImpl::Init) at startup
weight = description.weight; // of the mimehandler process, which is a renderer type process. We can reuse
// it here to call a plugin specific font matching method out of process here.
// TODO(drott): Find a way to pass this through instead of casting.
font_service::FontLoader* font_loader_casted =
reinterpret_cast<font_service::FontLoader*>(
SkFontConfigInterface::RefGlobal().get());
font_loader_casted->MatchFontWithFallback(
description.face,
description.weight >= PP_BROWSERFONT_TRUSTED_WEIGHT_BOLD,
description.italic, charset, PP_BROWSERFONT_TRUSTED_FAMILY_DEFAULT,
&font_file_);
#elif defined(OS_WIN)
int weight = description.weight;
if (weight == FW_DONTCARE) if (weight == FW_DONTCARE)
weight = SkFontStyle::kNormal_Weight; weight = SkFontStyle::kNormal_Weight;
#else
weight = PepperWeightToSkWeight(description.weight);
#endif
SkFontStyle style(weight, SkFontStyle::kNormal_Width, SkFontStyle style(weight, SkFontStyle::kNormal_Width,
description.italic ? SkFontStyle::kItalic_Slant description.italic ? SkFontStyle::kItalic_Slant
: SkFontStyle::kUpright_Slant); : SkFontStyle::kUpright_Slant);
...@@ -71,6 +55,7 @@ PepperFlashFontFileHost::PepperFlashFontFileHost( ...@@ -71,6 +55,7 @@ PepperFlashFontFileHost::PepperFlashFontFileHost(
typeface_ = sk_sp<SkTypeface>( typeface_ = sk_sp<SkTypeface>(
font_mgr->matchFamilyStyle(description.face.c_str(), style)); font_mgr->matchFamilyStyle(description.face.c_str(), style));
#endif
} }
PepperFlashFontFileHost::~PepperFlashFontFileHost() {} PepperFlashFontFileHost::~PepperFlashFontFileHost() {}
...@@ -89,6 +74,13 @@ bool PepperFlashFontFileHost::GetFontData(uint32_t table, ...@@ -89,6 +74,13 @@ bool PepperFlashFontFileHost::GetFontData(uint32_t table,
void* buffer, void* buffer,
size_t* length) { size_t* length) {
bool result = false; bool result = false;
#if defined(OS_LINUX)
if (font_file_.IsValid()) {
result = content::GetFontTable(font_file_.GetPlatformFile(), table,
0 /* offset */,
reinterpret_cast<uint8_t*>(buffer), length);
}
#elif defined(OS_WIN)
if (typeface_) { if (typeface_) {
table = base::ByteSwap(table); table = base::ByteSwap(table);
if (buffer == NULL) { if (buffer == NULL) {
...@@ -101,6 +93,7 @@ bool PepperFlashFontFileHost::GetFontData(uint32_t table, ...@@ -101,6 +93,7 @@ bool PepperFlashFontFileHost::GetFontData(uint32_t table,
result = true; result = true;
} }
} }
#endif
return result; return result;
} }
......
...@@ -14,8 +14,12 @@ ...@@ -14,8 +14,12 @@
#include "ppapi/c/private/pp_private_font_charset.h" #include "ppapi/c/private/pp_private_font_charset.h"
#include "ppapi/host/resource_host.h" #include "ppapi/host/resource_host.h"
#if defined(OS_LINUX) || defined(OS_OPENBSD)
#include "base/files/file.h"
#elif defined(OS_WIN)
#include "third_party/skia/include/core/SkRefCnt.h" #include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/skia/include/core/SkTypeface.h" #include "third_party/skia/include/core/SkTypeface.h"
#endif
namespace content { namespace content {
class RendererPpapiHost; class RendererPpapiHost;
...@@ -46,7 +50,11 @@ class PepperFlashFontFileHost : public ppapi::host::ResourceHost { ...@@ -46,7 +50,11 @@ class PepperFlashFontFileHost : public ppapi::host::ResourceHost {
uint32_t table); uint32_t table);
bool GetFontData(uint32_t table, void* buffer, size_t* length); bool GetFontData(uint32_t table, void* buffer, size_t* length);
#if defined(OS_LINUX)
base::File font_file_;
#elif defined(OS_WIN)
sk_sp<SkTypeface> typeface_; sk_sp<SkTypeface> typeface_;
#endif
DISALLOW_COPY_AND_ASSIGN(PepperFlashFontFileHost); DISALLOW_COPY_AND_ASSIGN(PepperFlashFontFileHost);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment