summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-31 08:04:27 +0000
committerjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-31 08:04:27 +0000
commit29328c606509c3ad53ea52d6c5c212a0f1ae9da0 (patch)
tree02ef90a5e09dc8626a588acc44bd95af5094dafd
parent9b3a5c2ad001c69b049b5aca7836773e4c5cff2f (diff)
downloadchromium_src-29328c606509c3ad53ea52d6c5c212a0f1ae9da0.zip
chromium_src-29328c606509c3ad53ea52d6c5c212a0f1ae9da0.tar.gz
chromium_src-29328c606509c3ad53ea52d6c5c212a0f1ae9da0.tar.bz2
Mac: Part 1 of a fix to get OOP font loading working in the renderer on 10.6.6 .
When the renderer can't load a font due to sandbox restrictions, it sends an IPC over to the browser to return a copy of the font file, which it then activates. Before doing this, the renderer retrieves the ATSFontContainerRef corresponding to the font it couldn't load. This value is unique for each font file and having this value allows the renderer to determine if the font in question has already been retrieved from the browser and activated. Without doing this, the renderer would need to activate a font each time it was requested. In 10.6.6 the function used to get the unique ID from the font in the renderer was changed so it fails in the sandbox (it now tries to access the on-disk font file). In order to work around this, we need to get the unique id on the browser side and send it back over IPC. This is the first part of said change. BUG=72727 TEST=None Review URL: http://codereview.chromium.org/7080024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87282 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/browser/renderer_host/render_message_filter.cc11
-rw-r--r--content/browser/renderer_host/render_message_filter.h3
-rw-r--r--content/common/font_loader_mac.h4
-rw-r--r--content/common/font_loader_mac.mm20
-rw-r--r--content/common/sandbox_mac_fontloading_unittest.mm4
-rw-r--r--content/common/view_messages.h5
-rw-r--r--content/renderer/renderer_webkitclient_impl.cc34
7 files changed, 62 insertions, 19 deletions
diff --git a/content/browser/renderer_host/render_message_filter.cc b/content/browser/renderer_host/render_message_filter.cc
index efdb533..960d191 100644
--- a/content/browser/renderer_host/render_message_filter.cc
+++ b/content/browser/renderer_host/render_message_filter.cc
@@ -533,16 +533,19 @@ void RenderMessageFilter::OnCookiesEnabled(
#if defined(OS_MACOSX)
void RenderMessageFilter::OnLoadFont(const FontDescriptor& font,
uint32* handle_size,
- base::SharedMemoryHandle* handle) {
+ base::SharedMemoryHandle* handle,
+ uint32* font_id) {
base::SharedMemory font_data;
uint32 font_data_size = 0;
bool ok = FontLoader::LoadFontIntoBuffer(font.ToNSFont(), &font_data,
- &font_data_size);
- if (!ok || font_data_size == 0) {
+ &font_data_size, font_id);
+ if (!ok || font_data_size == 0 || *font_id == 0) {
LOG(ERROR) << "Couldn't load font data for " << font.font_name <<
- " ok=" << ok << " font_data_size=" << font_data_size;
+ " ok=" << ok << " font_data_size=" << font_data_size <<
+ " font id=" << *font_id;
*handle_size = 0;
*handle = base::SharedMemory::NULLHandle();
+ *font_id = 0;
return;
}
diff --git a/content/browser/renderer_host/render_message_filter.h b/content/browser/renderer_host/render_message_filter.h
index 9b9379f..433f711 100644
--- a/content/browser/renderer_host/render_message_filter.h
+++ b/content/browser/renderer_host/render_message_filter.h
@@ -131,7 +131,8 @@ class RenderMessageFilter : public BrowserMessageFilter {
#if defined(OS_MACOSX)
void OnLoadFont(const FontDescriptor& font,
uint32* handle_size,
- base::SharedMemoryHandle* handle);
+ base::SharedMemoryHandle* handle,
+ uint32* font_id);
#endif
#if defined(OS_WIN) // This hack is Windows-specific.
diff --git a/content/common/font_loader_mac.h b/content/common/font_loader_mac.h
index 532a09c..4043dce 100644
--- a/content/common/font_loader_mac.h
+++ b/content/common/font_loader_mac.h
@@ -32,9 +32,11 @@ class FontLoader {
// |font_data| - shared memory buffer containing the raw data for the font
// file.
// |font_data_size| - size of data contained in |font_data|.
+ // |font_id| - unique identifier for the on-disk file we load for the font.
static bool LoadFontIntoBuffer(NSFont* font_to_encode,
base::SharedMemory* font_data,
- uint32* font_data_size);
+ uint32* font_data_size,
+ uint32* font_id);
// Given a shared memory buffer containing the raw data for a font file, load
// the font and return a container ref.
diff --git a/content/common/font_loader_mac.mm b/content/common/font_loader_mac.mm
index 124708b..595322f 100644
--- a/content/common/font_loader_mac.mm
+++ b/content/common/font_loader_mac.mm
@@ -16,9 +16,13 @@
// static
bool FontLoader::LoadFontIntoBuffer(NSFont* font_to_encode,
base::SharedMemory* font_data,
- uint32* font_data_size) {
- CHECK(font_data && font_data_size);
+ uint32* font_data_size,
+ uint32* font_id) {
+ CHECK(font_data);
+ CHECK(font_data_size);
+ CHECK(font_id);
*font_data_size = 0;
+ *font_id = 0;
// Used only for logging.
std::string font_name([[font_to_encode fontName] UTF8String]);
@@ -37,6 +41,17 @@ bool FontLoader::LoadFontIntoBuffer(NSFont* font_to_encode,
return false;
}
+ // Retrieve the ATSFontContainerRef corresponding to the font file we want to
+ // load. This is a unique identifier that allows the caller determine if the
+ // font file in question is already loaded.
+ COMPILE_ASSERT(sizeof(ATSFontContainerRef) == sizeof(font_id),
+ uint32_cant_hold_fontcontainer_ref);
+ ATSFontContainerRef fontContainer = kATSFontContainerRefUnspecified;
+ if (ATSFontGetContainer(ats_font, 0, &fontContainer) != noErr) {
+ LOG(ERROR) << "Failed to get font container ref for " << font_name;
+ return false;
+ }
+
// ATSFontRef -> File path.
// Warning: Calling this function on a font activated from memory will result
// in failure with a -50 - paramErr. This may occur if
@@ -79,6 +94,7 @@ bool FontLoader::LoadFontIntoBuffer(NSFont* font_to_encode,
}
*font_data_size = font_file_size_32;
+ *font_id = fontContainer;
return true;
}
diff --git a/content/common/sandbox_mac_fontloading_unittest.mm b/content/common/sandbox_mac_fontloading_unittest.mm
index f6518a2..b4b1a88 100644
--- a/content/common/sandbox_mac_fontloading_unittest.mm
+++ b/content/common/sandbox_mac_fontloading_unittest.mm
@@ -162,10 +162,12 @@ TEST_F(MacSandboxTest, FontLoadingTest) {
base::SharedMemory font_data;
uint32 font_data_size;
+ uint32 font_id;
NSFont* srcFont = [NSFont fontWithName:@"Geeza Pro" size:16.0];
EXPECT_TRUE(FontLoader::LoadFontIntoBuffer(srcFont,
- &font_data, &font_data_size));
+ &font_data, &font_data_size, &font_id));
EXPECT_GT(font_data_size, 0U);
+ EXPECT_GT(font_id, 0U);
file_util::WriteFileDescriptor(fileno(temp_file),
static_cast<const char *>(font_data.memory()), font_data_size);
diff --git a/content/common/view_messages.h b/content/common/view_messages.h
index 2dce7b8..7f828b2 100644
--- a/content/common/view_messages.h
+++ b/content/common/view_messages.h
@@ -1633,10 +1633,11 @@ IPC_SYNC_MESSAGE_ROUTED1_0(ViewHostMsg_DestroyPluginContainer,
#if defined(OS_MACOSX)
// Request that the browser load a font into shared memory for us.
-IPC_SYNC_MESSAGE_CONTROL1_2(ViewHostMsg_LoadFont,
+IPC_SYNC_MESSAGE_CONTROL1_3(ViewHostMsg_LoadFont,
FontDescriptor /* font to load */,
uint32 /* buffer size */,
- base::SharedMemoryHandle /* font data */)
+ base::SharedMemoryHandle /* font data */,
+ uint32 /* font id */)
#endif
#if defined(OS_WIN)
diff --git a/content/renderer/renderer_webkitclient_impl.cc b/content/renderer/renderer_webkitclient_impl.cc
index 6dafa8d..33c8673 100644
--- a/content/renderer/renderer_webkitclient_impl.cc
+++ b/content/renderer/renderer_webkitclient_impl.cc
@@ -113,7 +113,10 @@ class RendererWebKitClientImpl::SandboxSupport
#if defined(OS_WIN)
virtual bool ensureFontLoaded(HFONT);
#elif defined(OS_MACOSX)
+ // TODO(jeremy): Remove once WebKit side of patch lands - crbug.com/72727 .
virtual bool loadFont(NSFont* srcFont, ATSFontContainerRef* out);
+ virtual bool loadFont(
+ NSFont* srcFont, ATSFontContainerRef* container, uint32* fontID);
#elif defined(OS_LINUX)
virtual WebKit::WebString getFontFamilyForCharacters(
const WebKit::WebUChar* characters,
@@ -463,30 +466,45 @@ void RendererWebKitClientImpl::SandboxSupport::getRenderStyleForStrike(
#elif defined(OS_MACOSX)
-bool RendererWebKitClientImpl::SandboxSupport::loadFont(NSFont* srcFont,
- ATSFontContainerRef* out) {
+// TODO(jeremy): Remove once WebKit side of patch lands - crbug.com/72727 .
+bool RendererWebKitClientImpl::SandboxSupport::loadFont(
+ NSFont* srcFont, ATSFontContainerRef* out) {
+ uint32 temp;
+ return loadFont(srcFont, out, &temp);
+}
+
+bool RendererWebKitClientImpl::SandboxSupport::loadFont(
+ NSFont* srcFont, ATSFontContainerRef* container, uint32* fontID) {
DCHECK(srcFont);
- DCHECK(out);
+ DCHECK(container);
+ DCHECK(fontID);
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))) {
+ src_font_descriptor, &font_data_size, &font_data, fontID))) {
LOG(ERROR) << "Sending ViewHostMsg_LoadFont() IPC failed for " <<
src_font_descriptor.font_name;
- *out = kATSFontContainerRefUnspecified;
+ *container = kATSFontContainerRefUnspecified;
+ *fontID = 0;
return false;
}
- if (font_data_size == 0 || font_data == base::SharedMemory::NULLHandle()) {
+ if (font_data_size == 0 || font_data == base::SharedMemory::NULLHandle() ||
+ *fontID == 0) {
LOG(ERROR) << "Bad response from ViewHostMsg_LoadFont() for " <<
src_font_descriptor.font_name;
- *out = kATSFontContainerRefUnspecified;
+ *container = kATSFontContainerRefUnspecified;
+ *fontID = 0;
return false;
}
- return FontLoader::ATSFontContainerFromBuffer(font_data, font_data_size, out);
+ // TODO(jeremy): Need to call back into WebKit to make sure that the font
+ // isn't already activated, based on the font id. If it's already
+ // activated, don't reactivate it here - crbug.com/72727 .
+ return FontLoader::ATSFontContainerFromBuffer(font_data, font_data_size,
+ container);
}
#endif