summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-20 06:54:00 +0000
committerjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-20 06:54:00 +0000
commitbce61677147749792bf45b63acedb406125792e1 (patch)
treebb86c271405aa1482c67ad5c92bdc0f1c3f9fd4e
parentdb42ae05e7e08e3845900f45c711a3f02879bbd6 (diff)
downloadchromium_src-bce61677147749792bf45b63acedb406125792e1.zip
chromium_src-bce61677147749792bf45b63acedb406125792e1.tar.gz
chromium_src-bce61677147749792bf45b63acedb406125792e1.tar.bz2
Re-commit r50321 after rollback.
Mac: Infrastructure for serialization of OS fonts over IPC. Renderer & Browser bits to send and receive IPC message for OOP font loading. Review URL: http://codereview.chromium.org/2841019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50323 0039d316-1c4b-4281-b951-d872f2087c98
-rwxr-xr-xchrome/browser/renderer_host/resource_message_filter.cc31
-rwxr-xr-xchrome/browser/renderer_host/resource_message_filter.h11
-rw-r--r--chrome/renderer/renderer_webkitclient_impl.cc39
-rw-r--r--chrome/renderer/renderer_webkitclient_impl.h10
4 files changed, 79 insertions, 12 deletions
diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc
index a382042..75957c2 100755
--- a/chrome/browser/renderer_host/resource_message_filter.cc
+++ b/chrome/browser/renderer_host/resource_message_filter.cc
@@ -14,6 +14,7 @@
#include "base/histogram.h"
#include "base/process_util.h"
#include "base/thread.h"
+#include "base/utf_string_conversions.h"
#include "chrome/browser/appcache/appcache_dispatcher_host.h"
#include "chrome/browser/browser_about_handler.h"
#include "chrome/browser/child_process_security_policy.h"
@@ -55,6 +56,10 @@
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/extensions/extension_file_util.h"
#include "chrome/common/extensions/extension_message_bundle.h"
+#if defined(OS_MACOSX)
+#include "chrome/common/font_descriptor_mac.h"
+#include "chrome/common/font_loader_mac.h"
+#endif
#include "chrome/common/notification_service.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/render_messages.h"
@@ -473,6 +478,9 @@ bool ResourceMessageFilter::OnMessageReceived(const IPC::Message& msg) {
OnGetRawCookies)
IPC_MESSAGE_HANDLER(ViewHostMsg_DeleteCookie, OnDeleteCookie)
IPC_MESSAGE_HANDLER(ViewHostMsg_GetCookiesEnabled, OnGetCookiesEnabled)
+#if defined(OS_MACOSX)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_LoadFont, OnLoadFont)
+#endif
#if defined(OS_WIN) // This hack is Windows-specific.
IPC_MESSAGE_HANDLER(ViewHostMsg_PreCacheFont, OnPreCacheFont)
#endif
@@ -753,6 +761,27 @@ void ResourceMessageFilter::OnGetCookiesEnabled(
*enabled = GetRequestContextForURL(url)->AreCookiesEnabled();
}
+#if defined(OS_MACOSX)
+void ResourceMessageFilter::OnLoadFont(const FontDescriptor& font,
+ uint32* handle_size,
+ base::SharedMemoryHandle* handle) {
+ base::SharedMemory font_data;
+ uint32 font_data_size = 0;
+ bool ok = FontLoader::LoadFontIntoBuffer(font.nsFont(), &font_data,
+ &font_data_size);
+ if (!ok || font_data_size == 0) {
+ LOG(ERROR) << "Couldn't load font data for " << font.font_name <<
+ " ok=" << ok << " font_data_size=" << font_data_size;
+ *handle_size = 0;
+ *handle = base::SharedMemory::NULLHandle();
+ return;
+ }
+
+ *handle_size = font_data_size;
+ font_data.GiveToProcess(base::GetCurrentProcessHandle(), handle);
+}
+#endif // OS_MACOSX
+
#if defined(OS_WIN) // This hack is Windows-specific.
void ResourceMessageFilter::OnPreCacheFont(LOGFONT font) {
// If the renderer is running in a sandbox, GetTextMetrics()
@@ -795,7 +824,7 @@ void ResourceMessageFilter::OnPreCacheFont(LOGFONT font) {
hdcs[font_index] = hdc;
font_index = (font_index + 1) % kFontCacheSize;
}
-#endif
+#endif // OS_WIN
void ResourceMessageFilter::OnGetPlugins(bool refresh,
IPC::Message* reply_msg) {
diff --git a/chrome/browser/renderer_host/resource_message_filter.h b/chrome/browser/renderer_host/resource_message_filter.h
index e79934a..63f39c0 100755
--- a/chrome/browser/renderer_host/resource_message_filter.h
+++ b/chrome/browser/renderer_host/resource_message_filter.h
@@ -39,6 +39,7 @@ class ChromeURLRequestContext;
class DatabaseDispatcherHost;
class DOMStorageDispatcherHost;
class ExtensionMessageService;
+struct FontDescriptor;
class GeolocationDispatcherHost;
class HostZoomMap;
class IndexedDBDispatcherHost;
@@ -63,10 +64,6 @@ namespace webkit_glue {
struct WebCookie;
}
-namespace WebKit {
-struct WebScreenInfo;
-}
-
struct ViewHostMsg_ScriptedPrint_Params;
#if defined(OS_POSIX) && !defined(OS_MACOSX)
struct ViewHostMsg_DidPrintPage_Params;
@@ -160,6 +157,12 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter,
const std::wstring& filter,
uint32 user_data);
+#if defined(OS_MACOSX)
+ void OnLoadFont(const FontDescriptor& font,
+ uint32* handle_size,
+ base::SharedMemoryHandle* handle);
+#endif
+
#if defined(OS_WIN) // This hack is Windows-specific.
// Cache fonts for the renderer. See ResourceMessageFilter::OnPreCacheFont
// implementation for more details.
diff --git a/chrome/renderer/renderer_webkitclient_impl.cc b/chrome/renderer/renderer_webkitclient_impl.cc
index 7135038..4229d66 100644
--- a/chrome/renderer/renderer_webkitclient_impl.cc
+++ b/chrome/renderer/renderer_webkitclient_impl.cc
@@ -13,6 +13,7 @@
#include "base/command_line.h"
#include "base/file_path.h"
#include "base/platform_file.h"
+#include "base/shared_memory.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/database_util.h"
#include "chrome/common/render_messages.h"
@@ -32,11 +33,15 @@
#include "third_party/WebKit/WebKit/chromium/public/WebGraphicsContext3D.h"
#include "third_party/WebKit/WebKit/chromium/public/WebIndexedDatabase.h"
#include "third_party/WebKit/WebKit/chromium/public/WebStorageEventDispatcher.h"
-#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
#include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
#include "webkit/glue/webkit_glue.h"
+#if defined(OS_MACOSX)
+#include "chrome/common/font_descriptor_mac.h"
+#include "chrome/common/font_loader_mac.h"
+#endif
+
#if defined(OS_LINUX)
#include "chrome/renderer/renderer_sandbox_support_linux.h"
#endif
@@ -77,11 +82,7 @@ WebKit::WebFileSystem* RendererWebKitClientImpl::fileSystem() {
}
WebKit::WebSandboxSupport* RendererWebKitClientImpl::sandboxSupport() {
-#if defined(OS_WIN) || defined(OS_LINUX)
return &sandbox_support_;
-#else
- return NULL;
-#endif
}
WebKit::WebCookieJar* RendererWebKitClientImpl::cookieJar() {
@@ -333,6 +334,34 @@ void RendererWebKitClientImpl::SandboxSupport::getRenderStyleForStrike(
renderer_sandbox_support::getRenderStyleForStrike(family, sizeAndStyle, out);
}
+#elif defined(OS_MACOSX)
+
+bool RendererWebKitClientImpl::SandboxSupport::loadFont(NSFont* srcFont,
+ ATSFontContainerRef* out) {
+ DCHECK(srcFont);
+ DCHECK(out);
+
+ uint32 font_data_size;
+ FontDescriptor src_font_descriptor(srcFont);
+ base::SharedMemoryHandle font_data;
+ if (!RenderThread::current()->Send(new ViewHostMsg_LoadFont(
+ src_font_descriptor, &font_data_size, &font_data))) {
+ LOG(ERROR) << "Sending ViewHostMsg_LoadFont() IPC failed for " <<
+ src_font_descriptor.font_name;
+ *out = kATSFontContainerRefUnspecified;
+ return false;
+ }
+
+ if (font_data_size == 0 || font_data == base::SharedMemory::NULLHandle()) {
+ LOG(ERROR) << "Bad response from ViewHostMsg_LoadFont() for " <<
+ src_font_descriptor.font_name;
+ *out = kATSFontContainerRefUnspecified;
+ return false;
+ }
+
+ return FontLoader::ATSFontContainerFromBuffer(font_data, font_data_size, out);
+}
+
#endif
//------------------------------------------------------------------------------
diff --git a/chrome/renderer/renderer_webkitclient_impl.h b/chrome/renderer/renderer_webkitclient_impl.h
index 17e706f..86fdf1f 100644
--- a/chrome/renderer/renderer_webkitclient_impl.h
+++ b/chrome/renderer/renderer_webkitclient_impl.h
@@ -20,6 +20,8 @@
#include <map>
#include "base/lock.h"
#include "third_party/WebKit/WebKit/chromium/public/linux/WebSandboxSupport.h"
+#elif defined(OS_MACOSX)
+#include "third_party/WebKit/WebKit/chromium/public/mac/WebSandboxSupport.h"
#endif
namespace IPC {
@@ -113,6 +115,11 @@ class RendererWebKitClientImpl : public webkit_glue::WebKitClientImpl {
Lock unicode_font_families_mutex_;
std::map<std::string, std::string> unicode_font_families_;
};
+#elif defined(OS_MACOSX)
+ class SandboxSupport : public WebKit::WebSandboxSupport {
+ public:
+ virtual bool loadFont(NSFont* srcFont, ATSFontContainerRef* out);
+ };
#endif
// Helper function to send synchronous message from any thread.
@@ -123,9 +130,8 @@ class RendererWebKitClientImpl : public webkit_glue::WebKitClientImpl {
FileSystem file_system_;
MimeRegistry mime_registry_;
-#if defined(OS_WIN) || defined(OS_LINUX)
+
SandboxSupport sandbox_support_;
-#endif
// This counter keeps track of the number of times sudden termination is
// enabled or disabled. It starts at 0 (enabled) and for every disable