[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc
jeremy at chromium.org
jeremy at chromium.org
Wed Dec 22 12:53:47 UTC 2010
The following commit has been merged in the debian/experimental branch:
commit 3b6daa04ae194f05e2d6bc7564dfc4f0be317bb5
Author: jeremy at chromium.org <jeremy at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Wed Sep 1 04:49:31 2010 +0000
2010-08-31 Jeremy Moskovich <jeremy at chromium.org>
Reviewed by Dimitri Glazkov.
Unfork Chromium's FontPlatformDataChromiumMac.mm.
Modified FontPlatformDataCocoa to provide hooks needed by Chromium.
Moved Chromium's mechanics for OOP font loading to CrossProcessFontLoading.mm.
Added ::create() function to MemoryActivatedFont to match new guidelines for
RefCounted<> classes.
Not possible to test due to sandbox interaction.
* WebCore.gypi: Update files for chromium build.
* platform/graphics/chromium/CrossProcessFontLoading.h: Added.
(WebCore::MemoryActivatedFont::cgFont):
(WebCore::MemoryActivatedFont::atsFontRef):
* platform/graphics/chromium/CrossProcessFontLoading.mm: Added.
(WebCore::MemoryActivatedFont::create):
(WebCore::MemoryActivatedFont::MemoryActivatedFont):
(WebCore::MemoryActivatedFont::~MemoryActivatedFont):
(WebCore::FontPlatformData::loadFont):
* platform/graphics/chromium/FontPlatformDataChromiumMac.mm: Removed.
* platform/graphics/cocoa/FontPlatformData.h:
* platform/graphics/cocoa/FontPlatformDataCocoa.mm:
(WebCore::FontPlatformData::loadFont):
(WebCore::FontPlatformData::FontPlatformData):
(WebCore::FontPlatformData::operator=):
(WebCore::FontPlatformData::setFont):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@66574 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 58c1cbc..bfd0bb5 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,33 @@
+2010-08-31 Jeremy Moskovich <jeremy at chromium.org>
+
+ Reviewed by Dimitri Glazkov.
+
+ Unfork Chromium's FontPlatformDataChromiumMac.mm.
+
+ Modified FontPlatformDataCocoa to provide hooks needed by Chromium.
+ Moved Chromium's mechanics for OOP font loading to CrossProcessFontLoading.mm.
+ Added ::create() function to MemoryActivatedFont to match new guidelines for
+ RefCounted<> classes.
+
+ Not possible to test due to sandbox interaction.
+
+ * WebCore.gypi: Update files for chromium build.
+ * platform/graphics/chromium/CrossProcessFontLoading.h: Added.
+ (WebCore::MemoryActivatedFont::cgFont):
+ (WebCore::MemoryActivatedFont::atsFontRef):
+ * platform/graphics/chromium/CrossProcessFontLoading.mm: Added.
+ (WebCore::MemoryActivatedFont::create):
+ (WebCore::MemoryActivatedFont::MemoryActivatedFont):
+ (WebCore::MemoryActivatedFont::~MemoryActivatedFont):
+ (WebCore::FontPlatformData::loadFont):
+ * platform/graphics/chromium/FontPlatformDataChromiumMac.mm: Removed.
+ * platform/graphics/cocoa/FontPlatformData.h:
+ * platform/graphics/cocoa/FontPlatformDataCocoa.mm:
+ (WebCore::FontPlatformData::loadFont):
+ (WebCore::FontPlatformData::FontPlatformData):
+ (WebCore::FontPlatformData::operator=):
+ (WebCore::FontPlatformData::setFont):
+
2010-08-31 Martin Robinson <mrobinson at igalia.com>
Reviewed by Adam Barth.
diff --git a/WebCore/WebCore.gypi b/WebCore/WebCore.gypi
index cf12a76..85240e2 100644
--- a/WebCore/WebCore.gypi
+++ b/WebCore/WebCore.gypi
@@ -2252,6 +2252,8 @@
'platform/graphics/chromium/CanvasLayerChromium.h',
'platform/graphics/chromium/ContentLayerChromium.cpp',
'platform/graphics/chromium/ContentLayerChromium.h',
+ 'platform/graphics/chromium/CrossProcessFontLoading.h',
+ 'platform/graphics/chromium/CrossProcessFontLoading.mm',
'platform/graphics/chromium/FontCacheChromiumWin.cpp',
'platform/graphics/chromium/FontCacheLinux.cpp',
'platform/graphics/chromium/FontChromiumWin.cpp',
@@ -2259,7 +2261,6 @@
'platform/graphics/chromium/FontCustomPlatformData.h',
'platform/graphics/chromium/FontLinux.cpp',
'platform/graphics/chromium/FontPlatformData.h',
- 'platform/graphics/chromium/FontPlatformDataChromiumMac.mm',
'platform/graphics/chromium/FontPlatformDataChromiumWin.cpp',
'platform/graphics/chromium/FontPlatformDataChromiumWin.h',
'platform/graphics/chromium/FontPlatformDataLinux.cpp',
@@ -2296,6 +2297,7 @@
'platform/graphics/chromium/VideoLayerChromium.cpp',
'platform/graphics/chromium/VideoLayerChromium.h',
'platform/graphics/cocoa/FontPlatformData.h',
+ 'platform/graphics/cocoa/FontPlatformDataCocoa.mm',
'platform/graphics/filters/FEBlend.cpp',
'platform/graphics/filters/FEBlend.h',
'platform/graphics/filters/FEColorMatrix.cpp',
diff --git a/WebCore/platform/graphics/chromium/CrossProcessFontLoading.h b/WebCore/platform/graphics/chromium/CrossProcessFontLoading.h
new file mode 100644
index 0000000..e1fb740
--- /dev/null
+++ b/WebCore/platform/graphics/chromium/CrossProcessFontLoading.h
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CrossProcessFontLoading_h
+#define CrossProcessFontLoading_h
+
+#import <wtf/RefCounted.h>
+#import <wtf/RetainPtr.h>
+
+typedef struct CGFont* CGFontRef;
+typedef UInt32 ATSFontContainerRef;
+typedef UInt32 ATSFontRef;
+
+namespace WebCore {
+
+// MemoryActivatedFont encapsulates a font loaded from another process and
+// activated from memory.
+//
+// Responsibilities:
+// * Holder for the CGFontRef & ATSFontRef belonging to the activated font.
+// * Responsible for unloading the font container when done.
+//
+// Memory Management:
+// The class is reference counted, with each instance of FontPlatformData that
+// uses this class holding a reference to it.
+// Entries are kept track of internally in a hash to allow quick lookup
+// of existing instances for reuse:
+// - fontCacheBySrcFontContainerRef() - key is the ATSFontContainerRef
+// corresponding to the *original in-process NSFont* whose loading was blocked
+// by the sandbox.
+// This is needed to allow lookup of a pre-existing MemoryActivatedFont when
+// creating a new FontPlatformData object.
+//
+// Assumptions:
+// This code assumes that an ATSFontRef is a unique identifier tied to an
+// activated font. i.e. After we activate a font, its ATSFontRef doesn't
+// change.
+// It also assumes that the ATSFoncontainerRef for two in-memory NSFonts that
+// correspond to the same on-disk font file are always the same and don't change
+// with time.
+//
+// Flushing caches:
+// When the system notifies us of a system font cache flush, all FontDataCache
+// objects are destroyed. This should in turn dereference all
+// MemoryActivatedFonts and thus unload all in-memory fonts.
+class MemoryActivatedFont : public RefCounted<MemoryActivatedFont> {
+public:
+ // Use to create a new object, see docs on constructor below.
+ static PassRefPtr<MemoryActivatedFont> create(ATSFontContainerRef srcFontContainerRef, ATSFontContainerRef container);
+ ~MemoryActivatedFont();
+
+ // Get cached CGFontRef corresponding to the in-memory font.
+ CGFontRef cgFont() { return m_cgFont.get(); }
+
+ // Get cached ATSFontRef corresponding to the in-memory font.
+ ATSFontRef atsFontRef() { return m_atsFontRef; }
+
+private:
+ // srcFontRef - ATSFontRef belonging to the NSFont object that failed to
+ // load in-process.
+ // container - a font container corresponding to an identical font that
+ // we loaded cross-process.
+ MemoryActivatedFont(ATSFontContainerRef srcFontContainerRef, ATSFontContainerRef container);
+
+ ATSFontContainerRef m_fontContainer;
+ WTF::RetainPtr<CGFontRef> m_cgFont;
+ ATSFontRef m_atsFontRef;
+ ATSFontContainerRef m_srcFontContainerRef;
+};
+
+} // namespace WebCore
+
+#endif // CrossProcessFontLoading_h
diff --git a/WebCore/platform/graphics/chromium/CrossProcessFontLoading.mm b/WebCore/platform/graphics/chromium/CrossProcessFontLoading.mm
new file mode 100644
index 0000000..a7ec03a
--- /dev/null
+++ b/WebCore/platform/graphics/chromium/CrossProcessFontLoading.mm
@@ -0,0 +1,217 @@
+/*
+ * This file is part of the internal font implementation.
+ *
+ * Copyright (c) 2010 Google Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+// This file provides additional functionality to the Mac FontPlatformData class
+// defined in WebCore/platform/cocoa/FontPlatformDataCocoa.mm .
+// Because we want to support loading fonts between processes in the face of
+// font loading being blocked by the sandbox, we need a mechnasim to both
+// do the loading of in-memory fonts and keep track of them.
+
+#import "config.h"
+#import "CrossProcessFontLoading.h"
+
+#import "../graphics/cocoa/FontPlatformData.h"
+#import "ChromiumBridge.h"
+#import <AppKit/NSFont.h>
+#import <wtf/HashMap.h>
+
+namespace WebCore {
+
+namespace {
+
+typedef HashMap<ATSFontContainerRef, MemoryActivatedFont*> FontContainerRefMemoryFontHash;
+
+// On 10.5, font loading is not blocked by the sandbox and thus there is no
+// need for the cross-process font loading mechanim.
+// On system versions >=10.6 cross-process font loading is required.
+bool OutOfProcessFontLoadingEnabled()
+{
+ static SInt32 systemVersion = 0;
+ if (!systemVersion) {
+ if (Gestalt(gestaltSystemVersion, &systemVersion) != noErr)
+ return false;
+ }
+
+ return systemVersion >= 0x1060;
+}
+
+FontContainerRefMemoryFontHash& fontCacheBySrcFontContainerRef()
+{
+ DEFINE_STATIC_LOCAL(FontContainerRefMemoryFontHash, srcFontRefCache, ());
+ return srcFontRefCache;
+}
+
+ATSFontContainerRef fontContainerRefFromNSFont(NSFont* srcFont)
+{
+ ATSFontRef fontRef = CTFontGetPlatformFont(toCTFontRef(srcFont), 0);
+ if (!fontRef)
+ return kATSFontContainerRefUnspecified;
+ ATSFontContainerRef fontContainer = kATSFontContainerRefUnspecified;
+ if (ATSFontGetContainer(fontRef, 0, &fontContainer) != noErr)
+ return kATSFontContainerRefUnspecified;
+ return fontContainer;
+}
+
+// The only way we can tell that an in-process font has failed to load
+// is if CTFontCopyGraphicsFont() returns the LastResort font.
+bool isLastResortFont(CGFontRef cgFont)
+{
+ NSString* fontName = (NSString*)CGFontCopyPostScriptName(cgFont);
+ return [fontName isEqualToString:@"LastResort"];
+}
+
+// Given an in-process font which has failed to load, return a
+// MemoryActivatedFont* corresponding to an in-memory representation of the
+// same font loaded from the browser process.
+// On failure this function returns a PassRefPtr pointing to 0.
+PassRefPtr<MemoryActivatedFont> loadFontFromBrowserProcess(NSFont* nsFont)
+{
+ ATSFontContainerRef container;
+ // Send cross-process request to load font.
+ if (!ChromiumBridge::loadFont(nsFont, &container))
+ return 0;
+
+ ATSFontContainerRef srcFontContainerRef = fontContainerRefFromNSFont(nsFont);
+ if (!srcFontContainerRef) {
+ ATSFontDeactivate(container, 0, kATSOptionFlagsDefault);
+ return 0;
+ }
+
+ PassRefPtr<MemoryActivatedFont> font = adoptRef(fontCacheBySrcFontContainerRef().get(srcFontContainerRef));
+ if (font.get())
+ return font;
+
+ return MemoryActivatedFont::create(srcFontContainerRef, container);
+}
+
+} // namespace
+
+PassRefPtr<MemoryActivatedFont> MemoryActivatedFont::create(ATSFontContainerRef srcFontContainerRef, ATSFontContainerRef container)
+{
+ MemoryActivatedFont* font = new MemoryActivatedFont(srcFontContainerRef, container);
+ if (!font->cgFont()) // Object construction failed.
+ {
+ delete font;
+ return 0;
+ }
+ return adoptRef(font);
+}
+
+MemoryActivatedFont::MemoryActivatedFont(ATSFontContainerRef srcFontContainerRef, ATSFontContainerRef container)
+ : m_fontContainer(container)
+ , m_atsFontRef(kATSFontRefUnspecified)
+ , m_srcFontContainerRef(srcFontContainerRef)
+{
+ if (!container)
+ return;
+
+ // Count the number of fonts in the container.
+ ItemCount fontCount = 0;
+ OSStatus err = ATSFontFindFromContainer(container, kATSOptionFlagsDefault, 0, 0, &fontCount);
+ if (err != noErr || fontCount < 1)
+ return;
+
+ // For now always assume that we want the first font in the container.
+ ATSFontFindFromContainer(container, kATSOptionFlagsDefault, 1, &m_atsFontRef, 0);
+
+ if (!m_atsFontRef)
+ return;
+
+ // Cache CGFont representation of the font.
+ m_cgFont.adoptCF(CGFontCreateWithPlatformFont(&m_atsFontRef));
+
+ if (!m_cgFont.get())
+ return;
+
+ // Add ourselves to cache.
+ fontCacheBySrcFontContainerRef().add(m_srcFontContainerRef, this);
+}
+
+// Destructor - Unload font container from memory and remove ourselves
+// from cache.
+MemoryActivatedFont::~MemoryActivatedFont()
+{
+ if (m_cgFont.get()) {
+ // First remove ourselves from the caches.
+ ASSERT(fontCacheBySrcFontContainerRef().contains(m_srcFontContainerRef));
+
+ fontCacheBySrcFontContainerRef().remove(m_srcFontContainerRef);
+
+ // Make sure the CGFont is destroyed before its font container.
+ m_cgFont.releaseRef();
+ }
+
+ if (m_fontContainer != kATSFontContainerRefUnspecified)
+ ATSFontDeactivate(m_fontContainer, 0, kATSOptionFlagsDefault);
+}
+
+// Given an NSFont, try to load a representation of that font into the cgFont
+// parameter. If loading is blocked by the sandbox, the font may be loaded
+// cross-process.
+// If sandbox loading also fails, a fallback font is loaded.
+//
+// Considerations:
+// * cgFont must be CFRelease()ed by the caller when done.
+//
+// Parameters:
+// * nsFont - The font we wish to load.
+// * fontSize - point size of the font we wish to load.
+// * outNSFont - The font that was actually loaded, may be different from nsFont
+// if a fallback font was used.
+// * cgFont - on output this contains the CGFontRef corresponding to the NSFont
+// that was picked in the end. The caller is responsible for calling
+// CFRelease() on this parameter when done with it.
+// * fontID - on output, the ID corresponding to nsFont.
+void FontPlatformData::loadFont(NSFont* nsFont, float fontSize, NSFont*& outNSFont, CGFontRef& cgFont, ATSUFontID& fontID)
+{
+ outNSFont = nsFont;
+ cgFont = CTFontCopyGraphicsFont(toCTFontRef(outNSFont), 0);
+ MemoryActivatedFont* memFont = 0;
+ if (OutOfProcessFontLoadingEnabled() && outNSFont && cgFont && isLastResortFont(cgFont)) {
+ // Release old CGFontRef since it points at the LastResort font which we don't want.
+ CFRelease(cgFont);
+ cgFont = 0;
+
+ // Font loading was blocked by the Sandbox.
+ m_inMemoryFont = loadFontFromBrowserProcess(outNSFont);
+ if (m_inMemoryFont.get()) {
+ cgFont = m_inMemoryFont->cgFont();
+
+ // Need to add an extra retain so output semantics of this function
+ // are consistent.
+ CFRetain(cgFont);
+ } else {
+ // If we still can't load the font, then return Times,
+ // rather than the LastResort font.
+ outNSFont = [NSFont fontWithName:@"Times" size:fontSize];
+ cgFont = CTFontCopyGraphicsFont(toCTFontRef(outNSFont), 0);
+ }
+ }
+
+ if (memFont) {
+ fontID = m_inMemoryFont->atsFontRef();
+ } else {
+ fontID = CTFontGetPlatformFont(toCTFontRef(outNSFont), 0);
+ }
+}
+
+} // namespace WebCore
diff --git a/WebCore/platform/graphics/chromium/FontPlatformDataChromiumMac.mm b/WebCore/platform/graphics/chromium/FontPlatformDataChromiumMac.mm
deleted file mode 100644
index 903109e..0000000
--- a/WebCore/platform/graphics/chromium/FontPlatformDataChromiumMac.mm
+++ /dev/null
@@ -1,458 +0,0 @@
-/*
- * This file is part of the internal font implementation.
- *
- * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
- * Copyright (c) 2010 Google Inc. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- *
- */
-
-// This file is a clone of platform/graphics/mac/FontPlatformDataMac.mm.
-// Because we want to support loading fonts between processes in the face of
-// font loading being blocked by the sandbox, we must maintain a fork.
-// Please maintain this file by performing parallel changes to it.
-//
-// The only changes from FontPlatformDataMac should be:
-// - The functions at the top of this file for loading and caching fonts
-// cross-process.
-// - Changes to FontPlatformData::FontPlatformData(NSFont,bool,bool)
-// - Changes to FontPlatformData::setFont()
-// - Changes to FontPlatformData::~FontPlatformData()
-// - Calls to refMemoryFont() in FontPlatformData::operator= and copy
-// constructor.
-//
-// All changes are marked with "Start/End Chromium Change"
-//
-// For all other differences, if it was introduced in this file, then the
-// maintainer forgot to include it in the list; otherwise it is an update that
-// should have been applied to this file but was not.
-
-
-// Start Chromium Change
-#import "config.h"
-#import "../graphics/cocoa/FontPlatformData.h"
-
-#import "ChromiumBridge.h"
-#import "PlatformString.h"
-#import "WebCoreSystemInterface.h"
-#import <AppKit/NSFont.h>
-#import <wtf/HashMap.h>
-#import <wtf/RefCounted.h>
-#import <wtf/RetainPtr.h>
-#import <wtf/Vector.h>
-
-namespace WebCore {
-
-namespace {
-
-class MemoryActivatedFont;
-typedef HashMap<ATSFontRef, MemoryActivatedFont*> FontRefMemoryFontHash;
-typedef HashMap<ATSFontContainerRef, MemoryActivatedFont*> FontContainerRefMemoryFontHash;
-
-// On 10.5, font loading is not blocked by the sandbox and thus there is no
-// need for the cross-process font loading mechanim.
-// On system versions >=10.6 cross-process font loading is required.
-bool OutOfProcessFontLoadingEnabled()
-{
- static SInt32 systemVersion = 0;
- if (!systemVersion) {
- if (Gestalt(gestaltSystemVersion, &systemVersion) != noErr)
- return false;
- }
-
- return systemVersion >= 0x1060;
-}
-
-FontContainerRefMemoryFontHash& fontCacheBySrcFontContainerRef()
-{
- DEFINE_STATIC_LOCAL(FontContainerRefMemoryFontHash, srcFontRefCache, ());
- return srcFontRefCache;
-}
-
-FontRefMemoryFontHash& fontCacheByActualFontRef()
-{
- DEFINE_STATIC_LOCAL(FontRefMemoryFontHash, realFontRefCache, ());
- return realFontRefCache;
-}
-
-ATSFontContainerRef fontContainerRefFromNSFont(NSFont* srcFont)
-{
- ATSFontRef fontRef = CTFontGetPlatformFont(toCTFontRef(srcFont), 0);
- if (!fontRef)
- return kATSFontContainerRefUnspecified;
- ATSFontContainerRef fontContainer = kATSFontContainerRefUnspecified;
- if (ATSFontGetContainer(fontRef, 0, &fontContainer) != noErr)
- return kATSFontContainerRefUnspecified;
- return fontContainer;
-}
-
-// MemoryActivatedFont encapsulates a font loaded from another process and
-// activated from memory.
-//
-// Responsibilities:
-// * Holder for the CGFontRef & ATSFontRef belonging to the activated font.
-// * Responsible for unloading the font container when done.
-//
-// Memory Management:
-// The class is reference counted, with each instance of FontPlatformData that
-// uses this class holding a reference to it.
-// Entries in 2 hashes are maintained internally to allow quick lookup
-// of existing instances for reuse:
-// - fontCacheBySrcFontContainerRef() - key is the ATSFontContainerRef
-// corresponding to the *original in-process NSFont* whose loading was blocked
-// by the sandbox.
-// This is needed to allow lookup of a pre-existing MemoryActivatedFont when
-// creating a new FontPlatformData object.
-// - fontCacheByActualFontRef() - key is the ATSFontRef corresponding to the
-// *new in-memory font* that we got from the browser process.
-// This is needed so that a FontPlatformData object can refer back to the
-// MemoryActivatedFont it's using. Currently this is only needed to release
-// the font on FontPlatformData destruction.
-//
-// Assumptions:
-// This code assumes that an ATSFontRef is a unique identifier tied to an
-// activated font. i.e. After we activate a font, its ATSFontRef doesn't
-// change.
-// It also assumes that the ATSFoncontainerRef for two in-memory NSFonts that
-// correspond to the same on-disk font file are always the same and don't change
-// with time.
-//
-// Flushing caches:
-// When the system notifies us of a system font cache flush, all FontDataCache
-// objects are destroyed. This should in turn dereference all
-// MemoryActivatedFonts and thus unload all in-memory fonts.
-class MemoryActivatedFont : public RefCounted<MemoryActivatedFont> {
-public:
- // srcFontRef - ATSFontRef belonging to the NSFont object that failed to
- // load in-process.
- // container - a font container corresponding to an identical font that
- // we loaded cross-process.
- MemoryActivatedFont(ATSFontContainerRef srcFontContainerRef, ATSFontContainerRef container)
- : m_fontContainer(container)
- , m_atsFontRef(kATSFontRefUnspecified)
- , m_srcFontContainerRef(srcFontContainerRef)
- {
- if (!container)
- return;
-
- // Count the number of fonts in the container.
- ItemCount fontCount = 0;
- OSStatus err = ATSFontFindFromContainer(container, kATSOptionFlagsDefault, 0, 0, &fontCount);
- if (err != noErr || fontCount < 1)
- return;
-
- // For now always assume that we want the first font in the container.
- ATSFontFindFromContainer(container, kATSOptionFlagsDefault, 1, &m_atsFontRef, 0);
-
- if (!m_atsFontRef)
- return;
-
- // Cache CGFont representation of the font.
- m_cgFont.adoptCF(CGFontCreateWithPlatformFont(&m_atsFontRef));
-
- if (!m_cgFont.get())
- return;
-
- // Add ourselves to caches.
- fontCacheBySrcFontContainerRef().add(m_srcFontContainerRef, this);
- fontCacheByActualFontRef().add(m_atsFontRef, this);
- }
-
- // Get cached CGFontRef corresponding to the in-memory font.
- CGFontRef cgFont()
- {
- return m_cgFont.get();
- }
-
- // Get cached ATSFontRef corresponding to the in-memory font.
- ATSFontRef atsFontRef()
- {
- return m_atsFontRef;
- }
-
- // Destructor - Unload font container from memory and remove ourselves
- // from hashes.
- ~MemoryActivatedFont()
- {
- if (m_cgFont.get()) { // Object construction succeeded.
- // First remove ourselves from the caches.
- ASSERT(fontCacheBySrcFontContainerRef().contains(m_srcFontContainerRef));
- ASSERT(fontCacheByActualFontRef().contains(m_atsFontRef));
-
- fontCacheBySrcFontContainerRef().remove(m_srcFontContainerRef);
- fontCacheByActualFontRef().remove(m_atsFontRef);
-
- // Make sure the CGFont is destroyed before its font container.
- m_cgFont.releaseRef();
- }
-
- if (m_fontContainer != kATSFontContainerRefUnspecified)
- ATSFontDeactivate(m_fontContainer, 0, kATSOptionFlagsDefault);
- }
-
-private:
- ATSFontContainerRef m_fontContainer;
- WTF::RetainPtr<CGFontRef> m_cgFont;
- ATSFontRef m_atsFontRef;
- ATSFontContainerRef m_srcFontContainerRef;
-};
-
-// The only way we can tell that an in-process font has failed to load
-// is if CTFontCopyGraphicsFont() returns the LastResort font.
-bool isLastResortFont(CGFontRef cgFont)
-{
- NSString* fontName = (NSString*)CGFontCopyPostScriptName(cgFont);
- return [fontName isEqualToString:@"LastResort"];
-}
-
-// Given an in-process font which has failed to load, return a
-// MemoryActivatedFont* corresponding to an in-memory representation of the
-// same font loaded from the browser process.
-// The caller is responsbile for calling derefMemoryFont() on the ATSFontRef
-// of the returned font.
-// On failure this function returns 0, in which case the caller doesn't need
-// to perform any additional cleanup.
-MemoryActivatedFont* loadFontFromBrowserProcess(NSFont* nsFont)
-{
- ATSFontContainerRef container;
- // Send cross-process request to load font.
- if (!ChromiumBridge::loadFont(nsFont, &container))
- return 0;
-
- ATSFontContainerRef srcFontContainerRef = fontContainerRefFromNSFont(nsFont);
- if (!srcFontContainerRef) {
- ATSFontDeactivate(container, 0, kATSOptionFlagsDefault);
- return 0;
- }
-
- MemoryActivatedFont* font = fontCacheBySrcFontContainerRef().get(srcFontContainerRef);
- if (!font) {
- font = new MemoryActivatedFont(srcFontContainerRef, container);
- if (!font->cgFont()) {
- delete font;
- return 0;
- }
- } else {
- font->ref();
- }
-
- return font;
-}
-
-// deref() the MemoryActivatedFont corresponding to the given ATSFontRef. If no
-// corresponding MemoryActivatedFont object exists, no action is performed.
-void derefMemoryFont(ATSFontRef fontRef)
-{
- if (fontRef == kATSFontRefUnspecified)
- return;
- MemoryActivatedFont* font = fontCacheByActualFontRef().get(fontRef);
- if (font)
- font->deref();
-}
-
-// ref() the MemoryActivatedFont corresponding to the given ATSFontRef. If no
-// corresponding MemoryActivatedFont object exists, no action is performed.
-void refMemoryFont(ATSFontRef fontRef)
-{
- if (fontRef == kATSFontRefUnspecified)
- return;
- MemoryActivatedFont* font = fontCacheByActualFontRef().get(fontRef);
- if (font)
- font->ref();
-}
-
-// Given an NSFont, try to load a representation of that font into the cgFont
-// parameter. If loading is blocked by the sandbox, the font may be loaded
-// cross-process.
-// If sandbox loading also fails, a fallback font is loaded.
-//
-// Considerations:
-// * cgFont must be CFReleas()ed by the caller when done.
-//
-// Parameters:
-// * nsFont - The font we wish to load.
-// * fontSize - point size of the font we wish to load.
-// * outNSFont - The font that was actually loaded, may be different from nsFont
-// if a fallback font was used.
-// * cgFont - on output this contains the CGFontRef corresponding to the NSFont
-// that was picked in the end. The caller is responsible for calling
-// CFRelease() on this parameter when done with it.
-// * fontID - on output, the ID corresponding to nsFont.
-void loadFont(NSFont* nsFont, float fontSize, NSFont*& outNSFont, CGFontRef& cgFont, ATSUFontID& fontID)
-{
- outNSFont = nsFont;
- cgFont = CTFontCopyGraphicsFont(toCTFontRef(outNSFont), 0);
- MemoryActivatedFont* memFont = 0;
- if (OutOfProcessFontLoadingEnabled() && outNSFont && cgFont && isLastResortFont(cgFont)) {
- // Release old CGFontRef since it points at the LastResort font which we don't want.
- CFRelease(cgFont);
- cgFont = 0;
-
- // Font loading was blocked by the Sandbox.
- memFont = loadFontFromBrowserProcess(outNSFont);
- if (memFont) {
- cgFont = memFont->cgFont();
-
- // Need to add an extra retain so output semantics of this function
- // are consistent.
- CFRetain(cgFont);
- } else {
- // If we still can't load the font, then return Times,
- // rather than the LastResort font.
- outNSFont = [NSFont fontWithName:@"Times" size:fontSize];
- cgFont = CTFontCopyGraphicsFont(toCTFontRef(outNSFont), 0);
- }
- }
-
- if (memFont) {
- fontID = memFont->atsFontRef();
- } else {
- fontID = CTFontGetPlatformFont(toCTFontRef(outNSFont), 0);
- }
-}
-
-} // namespace
-// End Chromium Change
-
-FontPlatformData::FontPlatformData(NSFont *nsFont, bool syntheticBold, bool syntheticOblique)
- : m_syntheticBold(syntheticBold)
- , m_syntheticOblique(syntheticOblique)
- , m_font(nsFont)
-#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
- , m_isColorBitmapFont(CTFontGetSymbolicTraits(toCTFontRef(nsFont)) & kCTFontColorGlyphsTrait)
-#else
- , m_isColorBitmapFont(false)
-#endif
-{
-// Start Chromium Change
- m_size = nsFont ? [nsFont pointSize] : 0.0f;
- CGFontRef cgFont = 0;
- NSFont* loadedFont = 0;
- loadFont(nsFont, m_size, loadedFont, cgFont, m_atsuFontID);
- m_font = loadedFont;
- if (m_font)
- CFRetain(m_font);
- m_cgFont.adoptCF(cgFont);
-// End Chromium Change
-}
-
-FontPlatformData::FontPlatformData(const FontPlatformData& f)
-{
- m_font = f.m_font && f.m_font != reinterpret_cast<NSFont *>(-1) ? const_cast<NSFont *>(static_cast<const NSFont *>(CFRetain(f.m_font))) : f.m_font;
-
- m_syntheticBold = f.m_syntheticBold;
- m_syntheticOblique = f.m_syntheticOblique;
- m_size = f.m_size;
- m_cgFont = f.m_cgFont;
- m_atsuFontID = f.m_atsuFontID;
- m_isColorBitmapFont = f.m_isColorBitmapFont;
- // Start Chromium Change
- refMemoryFont(m_atsuFontID);
- // End Chromium Change
-}
-
-FontPlatformData::~FontPlatformData()
-{
- if (m_font && m_font != reinterpret_cast<NSFont *>(-1))
- CFRelease(m_font);
-
- // Start Chromium Change
- derefMemoryFont(m_atsuFontID);
- // End Chromium Change
-}
-
-const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& f)
-{
- m_syntheticBold = f.m_syntheticBold;
- m_syntheticOblique = f.m_syntheticOblique;
- m_size = f.m_size;
- m_cgFont = f.m_cgFont;
- m_atsuFontID = f.m_atsuFontID;
- if (m_font == f.m_font)
- return *this;
- if (f.m_font && f.m_font != reinterpret_cast<NSFont *>(-1))
- CFRetain(f.m_font);
- if (m_font && m_font != reinterpret_cast<NSFont *>(-1))
- CFRelease(m_font);
- m_font = f.m_font;
- m_isColorBitmapFont = f.m_isColorBitmapFont;
- // Start Chromium Change
- refMemoryFont(m_atsuFontID);
- // End Chromium Change
- return *this;
-}
-
-void FontPlatformData::setFont(NSFont *font)
-{
- if (m_font == font)
- return;
- if (font)
- CFRetain(font);
- if (m_font && m_font != reinterpret_cast<NSFont *>(-1))
- CFRelease(m_font);
- m_font = font;
- m_size = font ? [font pointSize] : 0.0f;
-
- // Start Chromium Change
- CGFontRef cgFont = 0;
- NSFont* loadedFont = 0;
- loadFont(m_font, m_size, loadedFont, cgFont, m_atsuFontID);
-
- // If loadFont replaced m_font with a fallback font, then release the
- // previous font to counter the retain above. Then retain the new font.
- if (loadedFont != m_font) {
- CFRelease(m_font);
- m_font = loadedFont;
- CFRetain(m_font);
- }
- m_cgFont.adoptCF(cgFont);
-#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
- m_isColorBitmapFont = CTFontGetSymbolicTraits(toCTFontRef(m_font)) & kCTFontColorGlyphsTrait;
-#endif
- // End Chromium Change
-}
-
-bool FontPlatformData::roundsGlyphAdvances() const
-{
- return [m_font renderingMode] == NSFontAntialiasedIntegerAdvancementsRenderingMode;
-}
-
-bool FontPlatformData::allowsLigatures() const
-{
- return ![[m_font coveredCharacterSet] characterIsMember:'a'];
-}
-
-#if USE(CORE_TEXT)
-CTFontRef FontPlatformData::ctFont() const
-{
- if (m_font)
- return toCTFontRef(m_font);
- if (!m_CTFont)
- m_CTFont.adoptCF(CTFontCreateWithGraphicsFont(m_cgFont.get(), m_size, 0, 0));
- return m_CTFont.get();
-}
-#endif // USE(CORE_TEXT)
-
-#ifndef NDEBUG
-String FontPlatformData::description() const
-{
- RetainPtr<CFStringRef> cgFontDescription(AdoptCF, CFCopyDescription(cgFont()));
- return String(cgFontDescription.get()) + " " + String::number(m_size) + (m_syntheticBold ? " synthetic bold" : "") + (m_syntheticOblique ? " synthetic oblique" : "");
-}
-#endif
-
-} // namespace WebCore
diff --git a/WebCore/platform/graphics/cocoa/FontPlatformData.h b/WebCore/platform/graphics/cocoa/FontPlatformData.h
index dc876a8..034e23b 100644
--- a/WebCore/platform/graphics/cocoa/FontPlatformData.h
+++ b/WebCore/platform/graphics/cocoa/FontPlatformData.h
@@ -42,7 +42,13 @@ typedef const struct __CTFont* CTFontRef;
#include <wtf/Forward.h>
#include <wtf/RetainPtr.h>
+#if PLATFORM(CHROMIUM) && OS(DARWIN)
+#include "CrossProcessFontLoading.h"
+#endif
+
+
typedef UInt32 ATSUFontID;
+typedef UInt32 ATSFontRef;
namespace WebCore {
@@ -133,6 +139,15 @@ class FontPlatformData {
private:
static NSFont *hashTableDeletedFontValue() { return reinterpret_cast<NSFont *>(-1); }
+
+ // Load various data about the font specified by |nsFont| with the size fontSize into the following output paramters:
+ // Note: Callers should always take into account that for the Chromium port, |outNSFont| isn't necessarily the same
+ // font as |nsFont|. This because the sandbox may block loading of the original font.
+ // * outNSFont - The font that was actually loaded, for the Chromium port this may be different than nsFont.
+ // The caller is responsible for calling CFRelease() on this parameter when done with it.
+ // * cgFont - CGFontRef representing the input font at the specified point size.
+ // * fontID - ID of loaded font.
+ void loadFont(NSFont* nsFont, float fontSize, NSFont*& outNSFont, CGFontRef& cgFont, ATSUFontID& fontID);
NSFont *m_font;
@@ -147,8 +162,12 @@ private:
#endif
bool m_isColorBitmapFont;
+
+#if PLATFORM(CHROMIUM) && OS(DARWIN)
+ RefPtr<MemoryActivatedFont> m_inMemoryFont;
+#endif
};
-}
+} // namespace WebCore
#endif
diff --git a/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm b/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm
index d905b62..bd49dcc 100644
--- a/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm
+++ b/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm
@@ -2,6 +2,7 @@
* This file is part of the internal font implementation.
*
* Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
+ * Copyright (c) 2010 Google Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -29,11 +30,27 @@
namespace WebCore {
+#if PLATFORM(MAC)
+void FontPlatformData::loadFont(NSFont* nsFont, float, NSFont*& outNSFont, CGFontRef& cgFont, ATSUFontID& fontID)
+{
+ outNSFont = nsFont;
+#ifndef BUILDING_ON_TIGER
+ cgFont = CTFontCopyGraphicsFont(toCTFontRef(nsFont), 0);
+ fontID = CTFontGetPlatformFont(toCTFontRef(nsFont), 0);
+#else
+ cgFont = wkGetCGFontFromNSFont(nsFont);
+ fontID = wkGetNSFontATSUFontId(nsFont);
+#endif
+}
+#endif // PLATFORM(MAC)
+
FontPlatformData::FontPlatformData(NSFont *nsFont, bool syntheticBold, bool syntheticOblique)
: m_syntheticBold(syntheticBold)
, m_syntheticOblique(syntheticOblique)
, m_font(nsFont)
#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
+ // FIXME: Chromium: The following code isn't correct for the Chromium port since the sandbox might
+ // have blocked font loading, in which case we'll only have the real loaded font file after the call to loadFont().
, m_isColorBitmapFont(CTFontGetSymbolicTraits(toCTFontRef(nsFont)) & kCTFontColorGlyphsTrait)
#else
, m_isColorBitmapFont(false)
@@ -41,14 +58,18 @@ FontPlatformData::FontPlatformData(NSFont *nsFont, bool syntheticBold, bool synt
{
ASSERT_ARG(nsFont, nsFont);
- CFRetain(nsFont);
m_size = [nsFont pointSize];
+
+ CGFontRef cgFont = 0;
+ loadFont(nsFont, m_size, m_font, cgFont, m_atsuFontID);
+
+ if (m_font)
+ CFRetain(m_font);
+
#ifndef BUILDING_ON_TIGER
- m_cgFont.adoptCF(CTFontCopyGraphicsFont(toCTFontRef(nsFont), 0));
- m_atsuFontID = CTFontGetPlatformFont(toCTFontRef(nsFont), 0);
+ m_cgFont.adoptCF(cgFont);
#else
- m_cgFont = wkGetCGFontFromNSFont(nsFont);
- m_atsuFontID = wkGetNSFontATSUFontId(nsFont);
+ m_cgFont = cgFont;
#endif
}
@@ -65,6 +86,9 @@ FontPlatformData::FontPlatformData(const FontPlatformData& f)
#if USE(CORE_TEXT)
m_CTFont = f.m_CTFont;
#endif
+#if PLATFORM(CHROMIUM) && OS(DARWIN)
+ m_inMemoryFont = f.m_inMemoryFont;
+#endif
}
FontPlatformData:: ~FontPlatformData()
@@ -91,6 +115,9 @@ const FontPlatformData& FontPlatformData::operator=(const FontPlatformData& f)
#if USE(CORE_TEXT)
m_CTFont = f.m_CTFont;
#endif
+#if PLATFORM(CHROMIUM) && OS(DARWIN)
+ m_inMemoryFont = f.m_inMemoryFont;
+#endif
return *this;
}
@@ -107,15 +134,28 @@ void FontPlatformData::setFont(NSFont *font)
CFRelease(m_font);
m_font = font;
m_size = [font pointSize];
+
+ CGFontRef cgFont = 0;
+ NSFont* loadedFont = 0;
+ loadFont(m_font, m_size, loadedFont, cgFont, m_atsuFontID);
+
+#if PLATFORM(CHROMIUM) && OS(DARWIN)
+ // If loadFont replaced m_font with a fallback font, then release the
+ // previous font to counter the retain above. Then retain the new font.
+ if (loadedFont != m_font) {
+ CFRelease(m_font);
+ CFRetain(loadedFont);
+ m_font = loadedFont;
+ }
+#endif
+
#ifndef BUILDING_ON_TIGER
- m_cgFont.adoptCF(CTFontCopyGraphicsFont(toCTFontRef(font), 0));
- m_atsuFontID = CTFontGetPlatformFont(toCTFontRef(font), 0);
+ m_cgFont.adoptCF(cgFont);
#else
- m_cgFont = wkGetCGFontFromNSFont(font);
- m_atsuFontID = wkGetNSFontATSUFontId(font);
+ m_cgFont = cgFont;
#endif
#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
- m_isColorBitmapFont = CTFontGetSymbolicTraits(toCTFontRef(font)) & kCTFontColorGlyphsTrait;
+ m_isColorBitmapFont = CTFontGetSymbolicTraits(toCTFontRef(m_font)) & kCTFontColorGlyphsTrait;
#endif
#if USE(CORE_TEXT)
m_CTFont = 0;
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list