summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
Diffstat (limited to 'content')
-rw-r--r--content/common/font_loader_mac.h16
-rw-r--r--content/common/font_loader_mac.mm32
-rw-r--r--content/common/sandbox_mac_fontloading_unittest.mm57
-rw-r--r--content/ppapi_plugin/ppapi_webkitplatformsupport_impl.cc24
-rw-r--r--content/renderer/renderer_webkitplatformsupport_impl.cc56
5 files changed, 111 insertions, 74 deletions
diff --git a/content/common/font_loader_mac.h b/content/common/font_loader_mac.h
index 4043dce..410e076 100644
--- a/content/common/font_loader_mac.h
+++ b/content/common/font_loader_mac.h
@@ -19,7 +19,7 @@ class NSFont;
// Provides functionality to transmit fonts over IPC.
//
// Note about font formats: .dfont (datafork suitcase) fonts are currently not
-// supported by this code since ATSFontActivateFromMemory() can't handle them
+// supported by this code since CGFontCreateWithDataProvider() can't handle them
// directly.
class FontLoader {
@@ -39,16 +39,22 @@ class FontLoader {
uint32* font_id);
// Given a shared memory buffer containing the raw data for a font file, load
- // the font and return a container ref.
+ // the font and return a CGFontRef.
//
// |data| - A shared memory handle pointing to the raw data from a font file.
// |data_size| - Size of |data|.
//
// On return:
// returns true on success, false on failure.
- // |font_container| - A font container corresponding to the designated font.
- // The caller is responsible for releasing this value via ATSFontDeactivate()
- // when done
+ // |out| - A CGFontRef corresponding to the designated font.
+ // The caller is responsible for releasing this value via CGFontRelease()
+ // when done.
+ static bool CGFontRefFromBuffer(base::SharedMemoryHandle font_data,
+ uint32 font_data_size,
+ CGFontRef* out);
+
+
+ // TODO(jeremy): Remove once http://webk.it/66935 lands.
static bool ATSFontContainerFromBuffer(base::SharedMemoryHandle font_data,
uint32 font_data_size,
ATSFontContainerRef* font_container);
diff --git a/content/common/font_loader_mac.mm b/content/common/font_loader_mac.mm
index b2ff8f4..867e1d3 100644
--- a/content/common/font_loader_mac.mm
+++ b/content/common/font_loader_mac.mm
@@ -10,7 +10,9 @@
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/logging.h"
+#include "base/mac/foundation_util.h"
#include "base/mac/mac_util.h"
+#include "base/mac/scoped_cftyperef.h"
#include "base/sys_string_conversions.h"
extern "C" {
@@ -135,6 +137,36 @@ bool FontLoader::LoadFontIntoBuffer(NSFont* font_to_encode,
}
// static
+bool FontLoader::CGFontRefFromBuffer(base::SharedMemoryHandle font_data,
+ uint32 font_data_size,
+ CGFontRef* out) {
+ *out = NULL;
+
+ using base::SharedMemory;
+ DCHECK(SharedMemory::IsHandleValid(font_data));
+ DCHECK_GT(font_data_size, 0U);
+
+ SharedMemory shm(font_data, /*read_only=*/true);
+ if (!shm.Map(font_data_size))
+ return false;
+
+ NSData* data = [NSData dataWithBytes:shm.memory()
+ length:font_data_size];
+ base::mac::ScopedCFTypeRef<CGDataProviderRef> provider(
+ CGDataProviderCreateWithCFData(base::mac::NSToCFCast(data)));
+ if (!provider)
+ return false;
+
+ *out = CGFontCreateWithDataProvider(provider.get());
+
+ if (*out == NULL)
+ return false;
+
+ return true;
+}
+
+// TODO(jeremy): Remove once http://webk.it/66935 lands.
+// static
bool FontLoader::ATSFontContainerFromBuffer(base::SharedMemoryHandle font_data,
uint32 font_data_size,
ATSFontContainerRef* font_container)
diff --git a/content/common/sandbox_mac_fontloading_unittest.mm b/content/common/sandbox_mac_fontloading_unittest.mm
index b4b1a88..bca576d 100644
--- a/content/common/sandbox_mac_fontloading_unittest.mm
+++ b/content/common/sandbox_mac_fontloading_unittest.mm
@@ -18,48 +18,6 @@ namespace {
using sandboxtest::MacSandboxTest;
using sandbox::Sandbox;
-bool CGFontFromFontContainer(ATSFontContainerRef container, CGFontRef* out) {
- // Count the number of fonts that were loaded.
- ItemCount fontCount = 0;
- OSStatus err = ATSFontFindFromContainer(container, kATSOptionFlagsDefault, 0,
- NULL, &fontCount);
-
- if (err != noErr || fontCount < 1) {
- return false;
- }
-
- // Load font from container.
- ATSFontRef font_ref_ats = 0;
- ATSFontFindFromContainer(container, kATSOptionFlagsDefault, 1,
- &font_ref_ats, NULL);
-
- if (!font_ref_ats) {
- return false;
- }
-
- // Convert to cgFont.
- CGFontRef font_ref_cg = CGFontCreateWithPlatformFont(&font_ref_ats);
-
- if (!font_ref_cg) {
- return false;
- }
-
- *out = font_ref_cg;
- return true;
-}
-
-class ScopedFontContainer {
- public:
- explicit ScopedFontContainer(ATSFontContainerRef ref)
- : container_ref(ref) {}
-
- ~ScopedFontContainer() {
- ATSFontDeactivate(container_ref, NULL, kATSOptionFlagsDefault);
- }
-
- ATSFontContainerRef container_ref;
-};
-
class FontLoadingTestCase : public sandboxtest::MacSandboxTestCase {
public:
FontLoadingTestCase() : font_data_length_(-1) {}
@@ -112,19 +70,10 @@ bool FontLoadingTestCase::SandboxedTest() {
return false;
}
- ATSFontContainerRef font_container;
- if (!FontLoader::ATSFontContainerFromBuffer(shmem_handle, font_data_length_,
- &font_container)) {
- LOG(ERROR) << "Call to CreateCGFontFromBuffer() failed";
- return false;
- }
-
- // Unload the font container when done.
- ScopedFontContainer scoped_unloader(font_container);
-
CGFontRef cg_font_ref;
- if (!CGFontFromFontContainer(font_container, &cg_font_ref)) {
- LOG(ERROR) << "CGFontFromFontContainer failed";
+ if (!FontLoader::CGFontRefFromBuffer(shmem_handle, font_data_length_,
+ &cg_font_ref)) {
+ LOG(ERROR) << "Call to CreateCGFontFromBuffer() failed";
return false;
}
diff --git a/content/ppapi_plugin/ppapi_webkitplatformsupport_impl.cc b/content/ppapi_plugin/ppapi_webkitplatformsupport_impl.cc
index 7a17787..f5b425c 100644
--- a/content/ppapi_plugin/ppapi_webkitplatformsupport_impl.cc
+++ b/content/ppapi_plugin/ppapi_webkitplatformsupport_impl.cc
@@ -26,6 +26,10 @@ using WebKit::WebSandboxSupport;
using WebKit::WebString;
using WebKit::WebUChar;
+// TODO(jeremy): Remove once http://webk.it/66935 lands.
+typedef uintptr_t ATSFontContainerRef;
+typedef struct CGFont* CGFontRef;
+
class PpapiWebKitPlatformSupportImpl::SandboxSupport : public WebSandboxSupport {
public:
virtual ~SandboxSupport() {}
@@ -34,6 +38,9 @@ class PpapiWebKitPlatformSupportImpl::SandboxSupport : public WebSandboxSupport
virtual bool ensureFontLoaded(HFONT);
#elif defined(OS_MACOSX)
virtual bool loadFont(
+ NSFont* srcFont, CGFontRef* out, uint32_t* fontID);
+ // TODO(jeremy): Remove once http://webk.it/66935 lands.
+ virtual bool loadFont(
NSFont* srcFont, ATSFontContainerRef* out, uint32_t* fontID);
#elif defined(OS_POSIX)
virtual WebString getFontFamilyForCharacters(
@@ -66,8 +73,21 @@ bool PpapiWebKitPlatformSupportImpl::SandboxSupport::ensureFontLoaded(
#elif defined(OS_MACOSX)
-bool PpapiWebKitPlatformSupportImpl::SandboxSupport::loadFont(NSFont* srcFont,
- ATSFontContainerRef* out, uint32_t* fontID) {
+bool PpapiWebKitPlatformSupportImpl::SandboxSupport::loadFont(
+ NSFont* src_font,
+ CGFontRef* out,
+ uint32_t* font_id) {
+ // TODO(brettw) this should do the something similar to what
+ // RendererWebKitClientImpl does and request that the browser load the font.
+ NOTIMPLEMENTED();
+ return false;
+}
+
+// TODO(jeremy): Remove once http://webk.it/66935 lands.
+bool PpapiWebKitPlatformSupportImpl::SandboxSupport::loadFont(
+ NSFont* src_font,
+ ATSFontContainerRef* out,
+ uint32_t* font_id) {
// TODO(brettw) this should do the something similar to what
// RendererWebKitPlatformSupportImpl does and request that the browser load
// the font.
diff --git a/content/renderer/renderer_webkitplatformsupport_impl.cc b/content/renderer/renderer_webkitplatformsupport_impl.cc
index 8c56c00..512d2cb 100644
--- a/content/renderer/renderer_webkitplatformsupport_impl.cc
+++ b/content/renderer/renderer_webkitplatformsupport_impl.cc
@@ -116,7 +116,14 @@ class RendererWebKitPlatformSupportImpl::SandboxSupport
virtual bool ensureFontLoaded(HFONT);
#elif defined(OS_MACOSX)
virtual bool loadFont(
- NSFont* srcFont, ATSFontContainerRef* container, uint32* fontID);
+ NSFont* src_font,
+ CGFontRef* container,
+ uint32* font_id);
+ // TODO(jeremy): Remove once http://webk.it/66935 lands.
+ virtual bool loadFont(
+ NSFont* src_font,
+ ATSFontContainerRef* out,
+ uint32_t* font_id);
#elif defined(OS_POSIX)
virtual WebKit::WebString getFontFamilyForCharacters(
const WebKit::WebUChar* characters,
@@ -448,29 +455,52 @@ bool RendererWebKitPlatformSupportImpl::SandboxSupport::ensureFontLoaded(
#elif defined(OS_MACOSX)
bool RendererWebKitPlatformSupportImpl::SandboxSupport::loadFont(
- NSFont* srcFont, ATSFontContainerRef* container, uint32* fontID) {
- DCHECK(srcFont);
- DCHECK(container);
- DCHECK(fontID);
-
+ NSFont* src_font, CGFontRef* out, uint32* font_id) {
uint32 font_data_size;
- FontDescriptor src_font_descriptor(srcFont);
+ FontDescriptor src_font_descriptor(src_font);
base::SharedMemoryHandle font_data;
if (!RenderThread::current()->Send(new ViewHostMsg_LoadFont(
- src_font_descriptor, &font_data_size, &font_data, fontID))) {
- LOG(ERROR) << "Sending ViewHostMsg_LoadFont() IPC failed for " <<
+ src_font_descriptor, &font_data_size, &font_data, font_id))) {
+ *out = NULL;
+ *font_id = 0;
+ return false;
+ }
+
+ if (font_data_size == 0 || font_data == base::SharedMemory::NULLHandle() ||
+ *font_id == 0) {
+ NOTREACHED() << "Bad response from ViewHostMsg_LoadFont() for " <<
src_font_descriptor.font_name;
+ *out = NULL;
+ *font_id = 0;
+ return false;
+ }
+
+ // 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::CGFontRefFromBuffer(font_data, font_data_size, out);
+}
+
+// TODO(jeremy): Remove once http://webk.it/66935 lands.
+bool RendererWebKitPlatformSupportImpl::SandboxSupport::loadFont(
+ NSFont* src_font, ATSFontContainerRef* container, uint32* font_id) {
+ uint32 font_data_size;
+ FontDescriptor src_font_descriptor(src_font);
+ base::SharedMemoryHandle font_data;
+ if (!RenderThread::current()->Send(new ViewHostMsg_LoadFont(
+ src_font_descriptor, &font_data_size, &font_data, font_id))) {
*container = kATSFontContainerRefUnspecified;
- *fontID = 0;
+ *font_id = 0;
return false;
}
if (font_data_size == 0 || font_data == base::SharedMemory::NULLHandle() ||
- *fontID == 0) {
- LOG(ERROR) << "Bad response from ViewHostMsg_LoadFont() for " <<
+ *font_id == 0) {
+ NOTREACHED() << "Bad response from ViewHostMsg_LoadFont() for " <<
src_font_descriptor.font_name;
*container = kATSFontContainerRefUnspecified;
- *fontID = 0;
+ *font_id = 0;
return false;
}