Commit f0bb9a2a authored by Robert Sesek's avatar Robert Sesek Committed by Commit Bot

Merge the FontLoaderMac Mojo interface into SandboxSupportMac.

This reduces some setup and layer plumbing because the WebSandboxSupport
is now implemented on top of Mojo.

Change-Id: Ib969ce301963151d6abb048aaa0319283b987b57
Reviewed-on: https://chromium-review.googlesource.com/c/1351727Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Reviewed-by: default avatarDominik Röttsches <drott@chromium.org>
Commit-Queue: Robert Sesek <rsesek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611766}
parent 61dafa0c
......@@ -12,7 +12,7 @@
},
"requires": {
"*": [ "app" ],
"content_browser": [ "font_loader" ],
"content_browser": [ "sandbox_support" ],
"ui": [ "discardable_memory" ]
}
}
......
......@@ -107,11 +107,6 @@ void PdfCompositorService::OnStart() {
// It is just a quick and simple check to catch things like improper sandbox
// policy setup.
DCHECK(SkFontMgr::RefDefault()->countFamilies());
// Initialize a connection to FontLoaderMac service so blink platform's web
// sandbox support can communicate with it to load font.
content::UtilityThread::Get()->InitializeFontLoaderMac(
binding_.GetConnector());
#endif
}
......
......@@ -30,6 +30,9 @@ class SandboxSupportMacImpl : public mojom::SandboxSupportMac {
// content::mojom::SandboxSupportMac:
void GetSystemColors(GetSystemColorsCallback callback) override;
void LoadFont(const base::string16& font_name,
float font_point_size,
LoadFontCallback callback) override;
private:
mojo::BindingSet<mojom::SandboxSupportMac> bindings_;
......
......@@ -8,6 +8,7 @@
#include "base/task/post_task.h"
#include "base/task_runner_util.h"
#import "content/browser/theme_helper_mac.h"
#include "content/common/mac/font_loader.h"
#include "content/public/browser/browser_task_traits.h"
namespace content {
......@@ -32,4 +33,10 @@ void SandboxSupportMacImpl::GetSystemColors(GetSystemColorsCallback callback) {
std::move(callback));
}
void SandboxSupportMacImpl::LoadFont(const base::string16& font_name,
float font_point_size,
LoadFontCallback callback) {
FontLoader::LoadFont(font_name, font_point_size, std::move(callback));
}
} // namespace content
......@@ -34,7 +34,6 @@
#include "content/public/common/font_cache_dispatcher_win.h"
#elif defined(OS_MACOSX)
#include "content/browser/sandbox_support_mac_impl.h"
#include "content/common/font_loader_dispatcher_mac.h"
#endif
namespace content {
......@@ -51,7 +50,6 @@ class ConnectionFilterImpl : public ConnectionFilter {
base::CreateSequencedTaskRunnerWithTraits(
{base::TaskPriority::USER_BLOCKING, base::MayBlock()}));
#elif defined(OS_MACOSX)
registry_.AddInterface(base::BindRepeating(&FontLoaderDispatcher::Create));
registry_.AddInterface(
base::BindRepeating(&SandboxSupportMacImpl::BindRequest,
base::Owned(new SandboxSupportMacImpl)));
......
......@@ -28,8 +28,6 @@ WebSandboxSupportMac::WebSandboxSupportMac(
WebSandboxSupportMac::~WebSandboxSupportMac() = default;
// TODO(rsesek): Move font loading off the content.mojom.FontLoaderMac
// interface and onto the SandboxSupportMac interface.
bool WebSandboxSupportMac::LoadFont(CTFontRef font,
CGFontRef* out,
uint32_t* font_id) {
......@@ -37,8 +35,8 @@ bool WebSandboxSupportMac::LoadFont(CTFontRef font,
base::string16 font_name = SysCFStringRefToUTF16(name_ref);
float font_point_size = CTFontGetSize(font);
mojo::ScopedSharedBufferHandle font_data;
bool success = content::ChildThread::Get()->LoadFont(
font_name, font_point_size, &font_data, font_id) &&
bool success = sandbox_support_->LoadFont(font_name, font_point_size,
&font_data, font_id) &&
*font_id > 0 && font_data.is_valid();
if (!success) {
DLOG(ERROR) << "Bad response from LoadFont() for " << font_name;
......
......@@ -638,22 +638,6 @@ mojom::FontCacheWin* ChildThreadImpl::GetFontCacheWin() {
}
return font_cache_win_ptr_.get();
}
#elif defined(OS_MACOSX)
bool ChildThreadImpl::LoadFont(const base::string16& font_name,
float font_point_size,
mojo::ScopedSharedBufferHandle* out_font_data,
uint32_t* out_font_id) {
return GetFontLoaderMac()->LoadFont(font_name, font_point_size, out_font_data,
out_font_id);
}
mojom::FontLoaderMac* ChildThreadImpl::GetFontLoaderMac() {
if (!font_loader_mac_ptr_) {
GetConnector()->BindInterface(mojom::kBrowserServiceName,
&font_loader_mac_ptr_);
}
return font_loader_mac_ptr_.get();
}
#endif
void ChildThreadImpl::RecordAction(const base::UserMetricsAction& action) {
......
......@@ -35,8 +35,6 @@
#if defined(OS_WIN)
#include "content/public/common/font_cache_win.mojom.h"
#elif defined(OS_MACOSX)
#include "content/common/font_loader_mac.mojom.h"
#endif
namespace IPC {
......@@ -89,11 +87,6 @@ class CONTENT_EXPORT ChildThreadImpl
#if defined(OS_WIN)
void PreCacheFont(const LOGFONT& log_font) override;
void ReleaseCachedFonts() override;
#elif defined(OS_MACOSX)
bool LoadFont(const base::string16& font_name,
float font_point_size,
mojo::ScopedSharedBufferHandle* out_font_data,
uint32_t* out_font_id) override;
#endif
void RecordAction(const base::UserMetricsAction& action) override;
void RecordComputedAction(const std::string& action) override;
......@@ -173,10 +166,6 @@ class CONTENT_EXPORT ChildThreadImpl
bool IsInBrowserProcess() const;
#if defined(OS_MACOSX)
virtual mojom::FontLoaderMac* GetFontLoaderMac();
#endif
private:
class ChildThreadMessageRouter : public IPC::MessageRouter {
public:
......@@ -228,8 +217,6 @@ class CONTENT_EXPORT ChildThreadImpl
mojom::RouteProviderAssociatedPtr remote_route_provider_;
#if defined(OS_WIN)
mojom::FontCacheWinPtr font_cache_win_ptr_;
#elif defined(OS_MACOSX)
mojom::FontLoaderMacPtr font_loader_mac_ptr_;
#endif
std::unique_ptr<IPC::SyncChannel> channel_;
......
......@@ -115,8 +115,6 @@ source_set("common") {
"font_list_fontconfig.cc",
"font_list_mac.mm",
"font_list_win.cc",
"font_loader_dispatcher_mac.cc",
"font_loader_dispatcher_mac.h",
"frame_message_enums.h",
"frame_message_structs.cc",
"frame_message_structs.h",
......@@ -545,7 +543,6 @@ mojom("mojo_bindings") {
if (is_mac) {
sources += [
"font_loader_mac.mojom",
"render_widget_host_ns_view.mojom",
"sandbox_support_mac.mojom",
]
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/common/font_loader_dispatcher_mac.h"
#include <memory>
#include <utility>
#include "base/strings/string16.h"
#include "content/common/mac/font_loader.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "services/service_manager/public/cpp/bind_source_info.h"
namespace content {
FontLoaderDispatcher::FontLoaderDispatcher() {}
FontLoaderDispatcher::~FontLoaderDispatcher() {}
// static
void FontLoaderDispatcher::Create(
mojom::FontLoaderMacRequest request,
const service_manager::BindSourceInfo& source_info) {
mojo::MakeStrongBinding(std::make_unique<FontLoaderDispatcher>(),
std::move(request));
}
void FontLoaderDispatcher::LoadFont(
const base::string16& font_name,
float font_point_size,
mojom::FontLoaderMac::LoadFontCallback callback) {
FontLoader::LoadFont(font_name, font_point_size, std::move(callback));
}
} // namespace content
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_COMMON_FONT_LOADER_DISPATCHER_MAC_H_
#define CONTENT_COMMON_FONT_LOADER_DISPATCHER_MAC_H_
#include "content/common/font_loader_mac.mojom.h"
namespace service_manager {
struct BindSourceInfo;
}
namespace content {
// Dispatches message used for font loading on Mac. This is needed because
// Mac can't load fonts outside its conventional font locations in sandboxed
// processes. So the sandboxed process asks the browser process to do this
// for it.
class FontLoaderDispatcher : public mojom::FontLoaderMac {
public:
FontLoaderDispatcher();
~FontLoaderDispatcher() override;
static void Create(mojom::FontLoaderMacRequest request,
const service_manager::BindSourceInfo& source_info);
private:
// mojom::FontLoaderMac
void LoadFont(const base::string16& font_name,
float font_point_size,
mojom::FontLoaderMac::LoadFontCallback callback) override;
DISALLOW_COPY_AND_ASSIGN(FontLoaderDispatcher);
};
} // namespace content
#endif // CONTENT_COMMON_FONT_LOADER_DISPATCHER_MAC_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module content.mojom;
import "mojo/public/mojom/base/string16.mojom";
interface FontLoaderMac {
// Request the browser to load a font into shared memory for us.
[Sync]
LoadFont(mojo_base.mojom.String16 font_name, float font_point_size)
=> (handle<shared_buffer>? font_data, uint32 font_id);
};
......@@ -5,6 +5,7 @@
module content.mojom;
import "mojo/public/mojom/base/shared_memory.mojom";
import "mojo/public/mojom/base/string16.mojom";
// Interface for a sandboxed child process to request services of
// the browser.
......@@ -12,4 +13,9 @@ interface SandboxSupportMac {
// Returns the shared memory region containing system theme color
// information.
GetSystemColors() => (mojo_base.mojom.ReadOnlySharedMemoryRegion region);
// Request the browser to load a font into a shared memory buffer.
[Sync]
LoadFont(mojo_base.mojom.String16 font_name, float font_point_size)
=> (handle<shared_buffer>? font_data, uint32 font_id);
};
......@@ -24,9 +24,6 @@
"font_cache": [
"content.mojom.FontCacheWin"
],
"font_loader": [
"content.mojom.FontLoaderMac"
],
"gpu": [
"discardable_memory.mojom.DiscardableSharedMemoryManager",
"media.mojom.AndroidOverlayProvider"
......
......@@ -32,7 +32,6 @@
"content_browser": [
"dwrite_font_proxy",
"field_trials",
"font_loader",
"renderer",
"sandbox_support"
],
......
......@@ -14,8 +14,6 @@
#if defined(OS_WIN)
#include <windows.h>
#elif defined(OS_MACOSX)
#include "mojo/public/cpp/system/buffer.h"
#endif
namespace base {
......@@ -81,12 +79,6 @@ class CONTENT_EXPORT ChildThread : public IPC::Sender {
// Release cached font.
virtual void ReleaseCachedFonts() = 0;
#elif defined(OS_MACOSX)
// Load specified font into shared memory.
virtual bool LoadFont(const base::string16& font_name,
float font_point_size,
mojo::ScopedSharedBufferHandle* out_font_data,
uint32_t* out_font_id) = 0;
#endif
};
......
......@@ -234,13 +234,6 @@ void MockRenderThread::PreCacheFont(const LOGFONT& log_font) {
void MockRenderThread::ReleaseCachedFonts() {
}
#elif defined(OS_MACOSX)
bool MockRenderThread::LoadFont(const base::string16& font_name,
float font_point_size,
mojo::ScopedSharedBufferHandle* out_font_data,
uint32_t* out_font_id) {
return false; // Not implemented.
}
#endif
ServiceManagerConnection* MockRenderThread::GetServiceManagerConnection() {
......
......@@ -19,10 +19,6 @@
#include "ipc/message_filter.h"
#include "services/service_manager/public/mojom/connector.mojom.h"
#if defined(OS_MACOSX)
#include "mojo/public/cpp/system/buffer.h"
#endif
struct FrameHostMsg_CreateChildFrame_Params;
namespace IPC {
......@@ -86,11 +82,6 @@ class MockRenderThread : public RenderThread {
#if defined(OS_WIN)
void PreCacheFont(const LOGFONT& log_font) override;
void ReleaseCachedFonts() override;
#elif defined(OS_MACOSX)
bool LoadFont(const base::string16& font_name,
float font_point_size,
mojo::ScopedSharedBufferHandle* out_font_data,
uint32_t* out_font_id) override;
#endif
ServiceManagerConnection* GetServiceManagerConnection() override;
service_manager::Connector* GetConnector() override;
......
......@@ -8,10 +8,6 @@
#include "build/build_config.h"
#include "content/public/child/child_thread.h"
namespace service_manager {
class Connector;
}
namespace content {
class CONTENT_EXPORT UtilityThread : virtual public ChildThread {
......@@ -33,15 +29,6 @@ class CONTENT_EXPORT UtilityThread : virtual public ChildThread {
// Initializes blink with web sandbox support.
virtual void EnsureBlinkInitializedWithSandboxSupport() = 0;
#endif
#if defined(OS_MACOSX)
// Initializes a connection to FontLoaderMac service.
// Generic utility processes don't possess the content_browser's font_loader
// capability to access the interface. Specialized utility processes, such as
// pdf_compositor service, do require it.
virtual void InitializeFontLoaderMac(
service_manager::Connector* connector) = 0;
#endif
};
} // namespace content
......
......@@ -24,12 +24,6 @@
#include "net/proxy_resolution/proxy_resolver_v8.h"
#endif
#if defined(OS_MACOSX)
#include "content/common/font_loader_mac.mojom.h"
#include "content/public/common/service_names.mojom.h"
#include "services/service_manager/public/cpp/connector.h"
#endif
namespace content {
#if !defined(OS_ANDROID)
......@@ -164,21 +158,6 @@ bool UtilityThreadImpl::OnControlMessageReceived(const IPC::Message& msg) {
return GetContentClient()->utility()->OnMessageReceived(msg);
}
#if defined(OS_MACOSX)
mojom::FontLoaderMac* UtilityThreadImpl::GetFontLoaderMac() {
DCHECK(font_loader_mac_ptr_);
return font_loader_mac_ptr_.get();
}
void UtilityThreadImpl::InitializeFontLoaderMac(
service_manager::Connector* connector) {
if (!font_loader_mac_ptr_) {
connector->BindInterface(content::mojom::kBrowserServiceName,
&font_loader_mac_ptr_);
}
}
#endif
void UtilityThreadImpl::BindServiceFactoryRequest(
service_manager::mojom::ServiceFactoryRequest request) {
DCHECK(service_factory_);
......
......@@ -19,10 +19,6 @@
namespace content {
class UtilityServiceFactory;
namespace mojom {
class FontLoaderMac;
}
#if defined(COMPILER_MSVC)
// See explanation for other RenderViewHostImpl which is the same issue.
#pragma warning(push)
......@@ -45,9 +41,6 @@ class UtilityThreadImpl : public UtilityThread,
#if defined(OS_POSIX) && !defined(OS_ANDROID)
void EnsureBlinkInitializedWithSandboxSupport() override;
#endif
#if defined(OS_MACOSX)
void InitializeFontLoaderMac(service_manager::Connector* connector) override;
#endif
private:
void EnsureBlinkInitializedInternal(bool sandbox_support);
......@@ -55,9 +48,6 @@ class UtilityThreadImpl : public UtilityThread,
// ChildThreadImpl:
bool OnControlMessageReceived(const IPC::Message& msg) override;
#if defined(OS_MACOSX)
mojom::FontLoaderMac* GetFontLoaderMac() override;
#endif
// Binds requests to our |service factory_|.
void BindServiceFactoryRequest(
......@@ -74,10 +64,6 @@ class UtilityThreadImpl : public UtilityThread,
mojo::BindingSet<service_manager::mojom::ServiceFactory>
service_factory_bindings_;
#if defined(OS_MACOSX)
content::mojom::FontLoaderMacPtr font_loader_mac_ptr_;
#endif
DISALLOW_COPY_AND_ASSIGN(UtilityThreadImpl);
};
......
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