Title: [183562] trunk
Revision
183562
Author
[email protected]
Date
2015-04-29 11:31:35 -0700 (Wed, 29 Apr 2015)

Log Message

[OS X] Use CTFontCreateForCSS instead of doing font search ourselves
https://bugs.webkit.org/show_bug.cgi?id=132159

Reviewed by Darin Adler.

Source/WebCore:

On platforms that support it, delegate font selection logic to the platform. Currently, this is
only supported on Mac, using CTFontCreateForCSS().

This also changes the mechanism that enforces our font whitelist in our tests. We used to
swizzle the implementations of NSFontManager methods. This patch migrates to using a whitelist of
font family names instead.

Note that this patch is a work in progress, because it makes the following tests fail:
fast/css/font-weight-1.html
fast/forms/validation-message-appearance.html
fast/forms/select/optgroup-rendering.html

No new tests, because there is no behavior change.

* platform/graphics/FontCache.h: Add a function to set the whitlist.
* platform/graphics/mac/FontCacheMac.mm:
(WebCore::fontWhitelist):
(WebCore::FontCache::setFontWhitelist):
(WebCore::toAppKitFontWeight):
(WebCore::toCoreTextFontWeight):
(WebCore::fontWithFamily): If ENABLE(PLATFORM_FONT_LOOKUP), use CTFontCreateForCSS().
(WebCore::FontCache::createFontPlatformData):
* platform/spi/cocoa/CoreTextSPI.h: Add signature for CTFontCreateForCSS().

Source/WebKit/mac:

Add SPI to set the font whitelist.

* WebView/WebView.mm:
(+[WebView _setFontWhitelist:]):
* WebView/WebViewPrivate.h:

Source/WebKit2:

Add SPI to set the font whitelist.

* Shared/WebProcessCreationParameters.cpp:
(WebKit::WebProcessCreationParameters::encode):
(WebKit::WebProcessCreationParameters::decode):
* Shared/WebProcessCreationParameters.h:
* UIProcess/API/C/WKContext.cpp:
(WKContextSetFontWhitelist):
* UIProcess/API/C/WKContextPrivate.h:
* UIProcess/Cocoa/WebProcessPoolCocoa.mm:
(WebKit::WebProcessPool::platformInitializeWebProcess):
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::setFontWhitelist):
* UIProcess/WebProcessPool.h:
* WebProcess/cocoa/WebProcessCocoa.mm:
(WebKit::WebProcess::platformInitializeWebProcess):

Source/WTF:

* wtf/Platform.h:

Opt-in using ENABLE(PLATFORM_FONT_LOOKUP)

Tools:

Make DumpRenderTree and WebKitTestRunner use the new font whitelist instead of
swizzling NSFontManager methods. This is predicated on ENABLE(PLATFORM_FONT_LOOKUP).

* DumpRenderTree/mac/DumpRenderTree.mm:
(fontWhitelist):
(adjustFonts):
(createWebViewAndOffscreenWindow):
* WebKitTestRunner/InjectedBundle/cocoa/ActivateFontsCocoa.mm:
(WTR::activateFonts):
* WebKitTestRunner/mac/TestControllerMac.mm:
(WTR::allowedFontFamilySet):
(WTR::systemHiddenFontFamilySet):
(WTR::generateWhitelist):
(WTR::TestController::platformInitializeContext):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (183561 => 183562)


--- trunk/Source/WTF/ChangeLog	2015-04-29 18:13:49 UTC (rev 183561)
+++ trunk/Source/WTF/ChangeLog	2015-04-29 18:31:35 UTC (rev 183562)
@@ -1,3 +1,14 @@
+2015-04-29  Myles C. Maxfield  <[email protected]>
+
+        [OS X] Use CTFontCreateForCSS instead of doing font search ourselves
+        https://bugs.webkit.org/show_bug.cgi?id=132159
+
+        Reviewed by Darin Adler.
+
+        * wtf/Platform.h:
+
+        Opt-in using ENABLE(PLATFORM_FONT_LOOKUP)
+
 2015-04-29  Yusuke Suzuki  <[email protected]>
 
         REGRESSION (r183373): ASSERT failed in wtf/SHA1.h

Modified: trunk/Source/WTF/wtf/Platform.h (183561 => 183562)


--- trunk/Source/WTF/wtf/Platform.h	2015-04-29 18:13:49 UTC (rev 183561)
+++ trunk/Source/WTF/wtf/Platform.h	2015-04-29 18:31:35 UTC (rev 183562)
@@ -1095,6 +1095,10 @@
 #define ENABLE_CSS3_TEXT_DECORATION_SKIP_INK 1
 #endif
 
+#if PLATFORM(IOS) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED > 101000)
+#define ENABLE_PLATFORM_FONT_LOOKUP 1
+#endif
+
 #if COMPILER(MSVC)
 #undef __STDC_LIMIT_MACROS
 #define __STDC_LIMIT_MACROS

Modified: trunk/Source/WebCore/ChangeLog (183561 => 183562)


--- trunk/Source/WebCore/ChangeLog	2015-04-29 18:13:49 UTC (rev 183561)
+++ trunk/Source/WebCore/ChangeLog	2015-04-29 18:31:35 UTC (rev 183562)
@@ -1,3 +1,34 @@
+2015-04-29  Myles C. Maxfield  <[email protected]>
+
+        [OS X] Use CTFontCreateForCSS instead of doing font search ourselves
+        https://bugs.webkit.org/show_bug.cgi?id=132159
+
+        Reviewed by Darin Adler.
+
+        On platforms that support it, delegate font selection logic to the platform. Currently, this is
+        only supported on Mac, using CTFontCreateForCSS().
+
+        This also changes the mechanism that enforces our font whitelist in our tests. We used to
+        swizzle the implementations of NSFontManager methods. This patch migrates to using a whitelist of
+        font family names instead.
+
+        Note that this patch is a work in progress, because it makes the following tests fail:
+        fast/css/font-weight-1.html
+        fast/forms/validation-message-appearance.html
+        fast/forms/select/optgroup-rendering.html
+
+        No new tests, because there is no behavior change.
+
+        * platform/graphics/FontCache.h: Add a function to set the whitlist.
+        * platform/graphics/mac/FontCacheMac.mm:
+        (WebCore::fontWhitelist):
+        (WebCore::FontCache::setFontWhitelist):
+        (WebCore::toAppKitFontWeight):
+        (WebCore::toCoreTextFontWeight):
+        (WebCore::fontWithFamily): If ENABLE(PLATFORM_FONT_LOOKUP), use CTFontCreateForCSS().
+        (WebCore::FontCache::createFontPlatformData):
+        * platform/spi/cocoa/CoreTextSPI.h: Add signature for CTFontCreateForCSS().
+
 2015-04-29  Jer Noble  <[email protected]>
 
         Unreviewed iOS build fix after r183553: fix declaration of QLPreviewScheme

Modified: trunk/Source/WebCore/platform/graphics/FontCache.h (183561 => 183562)


--- trunk/Source/WebCore/platform/graphics/FontCache.h	2015-04-29 18:13:49 UTC (rev 183561)
+++ trunk/Source/WebCore/platform/graphics/FontCache.h	2015-04-29 18:31:35 UTC (rev 183562)
@@ -119,6 +119,9 @@
 #if PLATFORM(IOS)
     static float weightOfCTFont(CTFontRef);
 #endif
+#if PLATFORM(MAC)
+    WEBCORE_EXPORT static void setFontWhitelist(const Vector<String>&);
+#endif
 #if PLATFORM(WIN)
     IMLangFontLinkType* getFontLinkInterface();
     static void comInitialize();

Modified: trunk/Source/WebCore/platform/graphics/mac/FontCacheMac.mm (183561 => 183562)


--- trunk/Source/WebCore/platform/graphics/mac/FontCacheMac.mm	2015-04-29 18:13:49 UTC (rev 183561)
+++ trunk/Source/WebCore/platform/graphics/mac/FontCacheMac.mm	2015-04-29 18:31:35 UTC (rev 183562)
@@ -33,6 +33,7 @@
 #if !PLATFORM(IOS)
 
 #import "CoreGraphicsSPI.h"
+#import "CoreTextSPI.h"
 #import "Font.h"
 #import "FontCascade.h"
 #import "FontPlatformData.h"
@@ -48,6 +49,8 @@
 
 namespace WebCore {
 
+#if !ENABLE(PLATFORM_FONT_LOOKUP)
+
 #define SYNTHESIZED_FONT_TRAITS (NSBoldFontMask | NSItalicFontMask)
 
 #define IMPORTANT_FONT_TRAITS (0 \
@@ -108,6 +111,8 @@
     return candidateWeightDeltaMagnitude < chosenWeightDeltaMagnitude;
 }
 
+#endif
+
 static inline FontTraitsMask toTraitsMask(NSFontTraitMask appKitTraits, NSInteger appKitWeight)
 {
     return static_cast<FontTraitsMask>(((appKitTraits & NSFontItalicTrait) ? FontStyleItalicMask : FontStyleNormalMask)
@@ -132,6 +137,7 @@
     return dictionary;
 }
 
+#if !ENABLE(PLATFORM_FONT_LOOKUP)
 static inline void rememberDesiredFamilyToAvailableFamilyMapping(NSString* desiredFamily, NSString* availableFamily)
 {
     static const NSUInteger maxCacheSize = 128;
@@ -147,18 +153,67 @@
     [familyMapping setObject:value forKey:desiredFamily];
 }
 
+#else
+
+static uint16_t toCoreTextFontWeight(FontWeight fontWeight)
+{
+    static int coreTextFontWeights[] = {
+        100, // FontWeight100
+        200, // FontWeight200
+        300, // FontWeight300
+        400, // FontWeight400
+        500, // FontWeight500
+        600, // FontWeight600
+        700, // FontWeight700
+        800, // FontWeight800
+        900, // FontWeight900
+    };
+    return coreTextFontWeights[fontWeight];
+}
+#endif
+
+typedef HashSet<String, CaseFoldingHash> Whitelist;
+static Whitelist& fontWhitelist()
+{
+    static NeverDestroyed<Whitelist> whitelist;
+    return whitelist;
+}
+
+void FontCache::setFontWhitelist(const Vector<String>& inputWhitelist)
+{
+    Whitelist& whitelist = fontWhitelist();
+    whitelist.clear();
+    for (auto& item : inputWhitelist)
+        whitelist.add(item);
+}
+
+static int toAppKitFontWeight(FontWeight fontWeight)
+{
+    static int appKitFontWeights[] = {
+        2, // FontWeight100
+        3, // FontWeight200
+        4, // FontWeight300
+        5, // FontWeight400
+        6, // FontWeight500
+        8, // FontWeight600
+        9, // FontWeight700
+        10, // FontWeight800
+        12, // FontWeight900
+    };
+    return appKitFontWeights[fontWeight];
+}
+
 // Family name is somewhat of a misnomer here. We first attempt to find an exact match
 // comparing the desiredFamily to the PostScript name of the installed fonts. If that fails
 // we then do a search based on the family names of the installed fonts.
-static NSFont *fontWithFamily(NSString *desiredFamily, NSFontTraitMask desiredTraits, int desiredWeight, float size)
+static NSFont *fontWithFamily(const AtomicString& family, NSFontTraitMask desiredTraits, FontWeight weight, float size)
 {
-    if (stringIsCaseInsensitiveEqualToString(desiredFamily, @"-webkit-system-font")
-        || stringIsCaseInsensitiveEqualToString(desiredFamily, @"-apple-system-font")) {
+    if (equalIgnoringASCIICase(family.string(), String(@"-webkit-system-font")) || equalIgnoringASCIICase(family.string(), String(@"-apple-system-font"))) {
         // We ignore italic for system font.
-        return (desiredWeight >= 7) ? [NSFont boldSystemFontOfSize:size] : [NSFont systemFontOfSize:size];
+        return (weight >= FontWeight600) ? [NSFont boldSystemFontOfSize:size] : [NSFont systemFontOfSize:size];
     }
 
-    if (stringIsCaseInsensitiveEqualToString(desiredFamily, @"-apple-system-font-monospaced-numbers")) {
+    if (equalIgnoringASCIICase(family.string(), String(@"-apple-system-font-monospaced-numbers"))) {
         NSArray *featureArray = @[ @{ NSFontFeatureTypeIdentifierKey : @(kNumberSpacingType),
             NSFontFeatureSelectorIdentifierKey : @(kMonospacedNumbersSelector) } ];
 
@@ -167,14 +222,37 @@
         return [NSFont fontWithDescriptor:desc size:size];
     }
 
+    NSFontManager *fontManager = [NSFontManager sharedFontManager];
+    NSString *desiredFamily = family;
+    NSString *availableFamily;
+    int chosenWeight;
+    NSFont *font;
+
+#if ENABLE(PLATFORM_FONT_LOOKUP)
+
+    if (family.length() > 0 && family[0] == '.')
+        return [NSFont fontWithName:desiredFamily size:size];
+    const auto& whitelist = fontWhitelist();
+    if (whitelist.size() && !whitelist.contains(family.lower()))
+        return nil;
+    CTFontSymbolicTraits requestedTraits = 0;
+    if (desiredTraits & NSFontItalicTrait)
+        requestedTraits |= kCTFontItalicTrait;
+    if (weight >= FontWeight600)
+        requestedTraits |= kCTFontBoldTrait;
+    font = CFBridgingRelease(CTFontCreateForCSS((CFStringRef)desiredFamily, toCoreTextFontWeight(weight), requestedTraits, size));
+    availableFamily = [font familyName];
+    chosenWeight = [fontManager weightOfFont:font];
+
+#else
+
     id cachedAvailableFamily = [desiredFamilyToAvailableFamilyDictionary() objectForKey:desiredFamily];
     if (cachedAvailableFamily == [NSNull null]) {
         // We already know this font is not available.
         return nil;
     }
 
-    NSFontManager *fontManager = [NSFontManager sharedFontManager];
-    NSString *availableFamily = cachedAvailableFamily;
+    availableFamily = cachedAvailableFamily;
     if (!availableFamily) {
         // Do a simple case insensitive search for a matching font family.
         // NSFontManager requires exact name matches.
@@ -187,7 +265,7 @@
         if (!availableFamily) {
             // Match by PostScript name.
             NSFont *nameMatchedFont = nil;
-            NSFontTraitMask desiredTraitsForNameMatch = desiredTraits | (desiredWeight >= 7 ? NSBoldFontMask : 0);
+            NSFontTraitMask desiredTraitsForNameMatch = desiredTraits | (weight >= FontWeight600 ? NSBoldFontMask : 0);
             for (NSString *availableFont in [fontManager availableFonts]) {
                 if ([desiredFamily caseInsensitiveCompare:availableFont] == NSOrderedSame) {
                     nameMatchedFont = [NSFont fontWithName:availableFont size:size];
@@ -214,10 +292,11 @@
 
     // Found a family, now figure out what weight and traits to use.
     bool choseFont = false;
-    int chosenWeight = 0;
+    chosenWeight = 0;
     NSFontTraitMask chosenTraits = 0;
     NSString *chosenFullName = 0;
 
+    int appKitDesiredWeight = toAppKitFontWeight(weight);
     NSArray *fonts = [fontManager availableMembersOfFontFamily:availableFamily];
     for (NSArray *fontInfo in fonts) {
         // Array indices must be hard coded because of lame AppKit API.
@@ -229,7 +308,7 @@
         if (!choseFont)
             newWinner = acceptableChoice(desiredTraits, fontTraits);
         else
-            newWinner = betterChoice(desiredTraits, desiredWeight, chosenTraits, chosenWeight, fontTraits, fontWeight);
+            newWinner = betterChoice(desiredTraits, appKitDesiredWeight, chosenTraits, chosenWeight, fontTraits, fontWeight);
 
         if (newWinner) {
             choseFont = YES;
@@ -237,7 +316,7 @@
             chosenTraits = fontTraits;
             chosenFullName = fontFullName;
 
-            if (chosenWeight == desiredWeight && (chosenTraits & IMPORTANT_FONT_TRAITS) == (desiredTraits & IMPORTANT_FONT_TRAITS))
+            if (chosenWeight == appKitDesiredWeight && (chosenTraits & IMPORTANT_FONT_TRAITS) == (desiredTraits & IMPORTANT_FONT_TRAITS))
                 break;
         }
     }
@@ -245,8 +324,10 @@
     if (!choseFont)
         return nil;
 
-    NSFont *font = [NSFont fontWithName:chosenFullName size:size];
+    font = [NSFont fontWithName:chosenFullName size:size];
 
+#endif
+
     if (!font)
         return nil;
 
@@ -255,7 +336,7 @@
         actualTraits = [fontManager traitsOfFont:font];
     int actualWeight = [fontManager weightOfFont:font];
 
-    bool syntheticBold = desiredWeight >= 7 && actualWeight < 7;
+    bool syntheticBold = toAppKitFontWeight(weight) >= 7 && actualWeight < 7;
     bool syntheticOblique = (desiredTraits & NSFontItalicTrait) && !(actualTraits & NSFontItalicTrait);
 
     // There are some malformed fonts that will be correctly returned by -fontWithFamily:traits:weight:size: as a match for a particular trait,
@@ -303,22 +384,6 @@
     CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(), this, fontCacheRegisteredFontsChangedNotificationCallback, kCTFontManagerRegisteredFontsChangedNotification, 0, CFNotificationSuspensionBehaviorDeliverImmediately);
 }
 
-static int toAppKitFontWeight(FontWeight fontWeight)
-{
-    static int appKitFontWeights[] = {
-        2,  // FontWeight100
-        3,  // FontWeight200
-        4,  // FontWeight300
-        5,  // FontWeight400
-        6,  // FontWeight500
-        8,  // FontWeight600
-        9,  // FontWeight700
-        10, // FontWeight800
-        12, // FontWeight900
-    };
-    return appKitFontWeights[fontWeight];
-}
-
 static inline bool isAppKitFontWeightBold(NSInteger appKitFontWeight)
 {
     return appKitFontWeight >= 7;
@@ -485,10 +550,9 @@
 std::unique_ptr<FontPlatformData> FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
 {
     NSFontTraitMask traits = fontDescription.italic() ? NSFontItalicTrait : 0;
-    NSInteger weight = toAppKitFontWeight(fontDescription.weight());
     float size = fontDescription.computedPixelSize();
 
-    NSFont *nsFont = fontWithFamily(family, traits, weight, size);
+    NSFont *nsFont = fontWithFamily(family, traits, fontDescription.weight(), size);
     if (!nsFont) {
         if (!shouldAutoActivateFontIfNeeded(family))
             return nullptr;
@@ -497,7 +561,7 @@
         // Ignore the result because we want to use our own algorithm to actually find the font.
         [NSFont fontWithName:family size:size];
 
-        nsFont = fontWithFamily(family, traits, weight, size);
+        nsFont = fontWithFamily(family, traits, fontDescription.weight(), size);
         if (!nsFont)
             return nullptr;
     }
@@ -509,7 +573,7 @@
     NSInteger actualWeight = [fontManager weightOfFont:nsFont];
 
     NSFont *platformFont = [nsFont printerFont];
-    bool syntheticBold = (fontDescription.fontSynthesis() & FontSynthesisWeight) && isAppKitFontWeightBold(weight) && !isAppKitFontWeightBold(actualWeight);
+    bool syntheticBold = (fontDescription.fontSynthesis() & FontSynthesisWeight) && isAppKitFontWeightBold(toAppKitFontWeight(fontDescription.weight())) && !isAppKitFontWeightBold(actualWeight);
     bool syntheticOblique = (fontDescription.fontSynthesis() & FontSynthesisStyle) && (traits & NSFontItalicTrait) && !(actualTraits & NSFontItalicTrait);
 
     return std::make_unique<FontPlatformData>(reinterpret_cast<CTFontRef>(platformFont), size, syntheticBold, syntheticOblique, fontDescription.orientation(), fontDescription.widthVariant());

Modified: trunk/Source/WebCore/platform/spi/cocoa/CoreTextSPI.h (183561 => 183562)


--- trunk/Source/WebCore/platform/spi/cocoa/CoreTextSPI.h	2015-04-29 18:13:49 UTC (rev 183561)
+++ trunk/Source/WebCore/platform/spi/cocoa/CoreTextSPI.h	2015-04-29 18:31:35 UTC (rev 183562)
@@ -85,6 +85,7 @@
 #endif
 
 bool CTFontDescriptorIsSystemUIFont(CTFontDescriptorRef);
+CTFontRef CTFontCreateForCSS(CFStringRef name, uint16_t weight, CTFontSymbolicTraits, CGFloat size);
 
 #if PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 10100
 extern const CFStringRef kCTUIFontTextStyleShortHeadline;

Modified: trunk/Source/WebKit/mac/ChangeLog (183561 => 183562)


--- trunk/Source/WebKit/mac/ChangeLog	2015-04-29 18:13:49 UTC (rev 183561)
+++ trunk/Source/WebKit/mac/ChangeLog	2015-04-29 18:31:35 UTC (rev 183562)
@@ -1,3 +1,16 @@
+2015-04-29  Myles C. Maxfield  <[email protected]>
+
+        [OS X] Use CTFontCreateForCSS instead of doing font search ourselves
+        https://bugs.webkit.org/show_bug.cgi?id=132159
+
+        Reviewed by Darin Adler.
+
+        Add SPI to set the font whitelist.
+
+        * WebView/WebView.mm:
+        (+[WebView _setFontWhitelist:]):
+        * WebView/WebViewPrivate.h:
+
 2015-04-28  Timothy Horton  <[email protected]>
 
         [TextIndicator] Yellow highlight takes too long to fade out on scroll

Modified: trunk/Source/WebKit/mac/WebView/WebView.mm (183561 => 183562)


--- trunk/Source/WebKit/mac/WebView/WebView.mm	2015-04-29 18:13:49 UTC (rev 183561)
+++ trunk/Source/WebKit/mac/WebView/WebView.mm	2015-04-29 18:31:35 UTC (rev 183562)
@@ -133,6 +133,7 @@
 #import <WebCore/EventHandler.h>
 #import <WebCore/ExceptionHandlers.h>
 #import <WebCore/FocusController.h>
+#import <WebCore/FontCache.h>
 #import <WebCore/FrameLoader.h>
 #import <WebCore/FrameSelection.h>
 #import <WebCore/FrameTree.h>
@@ -8819,6 +8820,20 @@
 }
 @end
 
+@implementation WebView (WebViewFontSelection)
++ (void)_setFontWhitelist:(NSArray *)whitelist
+{
+#if !PLATFORM(MAC)
+    UNUSED_PARAM(whitelist);
+#else
+    Vector<String> vector;
+    for (NSString *string in whitelist)
+        vector.append(string);
+    WebCore::FontCache::setFontWhitelist(vector);
+#endif
+}
+@end
+
 #if PLATFORM(IOS)
 @implementation WebView (WebViewIOSPDF)
 

Modified: trunk/Source/WebKit/mac/WebView/WebViewPrivate.h (183561 => 183562)


--- trunk/Source/WebKit/mac/WebView/WebViewPrivate.h	2015-04-29 18:13:49 UTC (rev 183561)
+++ trunk/Source/WebKit/mac/WebView/WebViewPrivate.h	2015-04-29 18:31:35 UTC (rev 183562)
@@ -1039,6 +1039,10 @@
 - (uint64_t)_notificationIDForTesting:(JSValueRef)jsNotification;
 @end
 
+@interface WebView (WebViewFontSelection)
++ (void)_setFontWhitelist:(NSArray *)whitelist;
+@end
+
 #if TARGET_OS_IPHONE
 @interface WebView (WebViewIOSPDF)
 + (Class)_getPDFRepresentationClass;

Modified: trunk/Source/WebKit2/ChangeLog (183561 => 183562)


--- trunk/Source/WebKit2/ChangeLog	2015-04-29 18:13:49 UTC (rev 183561)
+++ trunk/Source/WebKit2/ChangeLog	2015-04-29 18:31:35 UTC (rev 183562)
@@ -1,3 +1,27 @@
+2015-04-29  Myles C. Maxfield  <[email protected]>
+
+        [OS X] Use CTFontCreateForCSS instead of doing font search ourselves
+        https://bugs.webkit.org/show_bug.cgi?id=132159
+
+        Reviewed by Darin Adler.
+
+        Add SPI to set the font whitelist.
+
+        * Shared/WebProcessCreationParameters.cpp:
+        (WebKit::WebProcessCreationParameters::encode):
+        (WebKit::WebProcessCreationParameters::decode):
+        * Shared/WebProcessCreationParameters.h:
+        * UIProcess/API/C/WKContext.cpp:
+        (WKContextSetFontWhitelist):
+        * UIProcess/API/C/WKContextPrivate.h:
+        * UIProcess/Cocoa/WebProcessPoolCocoa.mm:
+        (WebKit::WebProcessPool::platformInitializeWebProcess):
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::setFontWhitelist):
+        * UIProcess/WebProcessPool.h:
+        * WebProcess/cocoa/WebProcessCocoa.mm:
+        (WebKit::WebProcess::platformInitializeWebProcess):
+
 2015-04-29  Martin Robinson  <[email protected]>
 
         [CMake] [GTK] Organize and clean up unused CMake variables

Modified: trunk/Source/WebKit2/Shared/WebProcessCreationParameters.cpp (183561 => 183562)


--- trunk/Source/WebKit2/Shared/WebProcessCreationParameters.cpp	2015-04-29 18:13:49 UTC (rev 183561)
+++ trunk/Source/WebKit2/Shared/WebProcessCreationParameters.cpp	2015-04-29 18:31:35 UTC (rev 183562)
@@ -104,6 +104,7 @@
     encoder << shouldAlwaysUseComplexTextCodePath;
     encoder << shouldEnableMemoryPressureReliefLogging;
     encoder << shouldUseFontSmoothing;
+    encoder << fontWhitelist;
     encoder << iconDatabaseEnabled;
     encoder << terminationTimeout;
     encoder << languages;
@@ -232,6 +233,8 @@
         return false;
     if (!decoder.decode(parameters.shouldUseFontSmoothing))
         return false;
+    if (!decoder.decode(parameters.fontWhitelist))
+        return false;
     if (!decoder.decode(parameters.iconDatabaseEnabled))
         return false;
     if (!decoder.decode(parameters.terminationTimeout))

Modified: trunk/Source/WebKit2/Shared/WebProcessCreationParameters.h (183561 => 183562)


--- trunk/Source/WebKit2/Shared/WebProcessCreationParameters.h	2015-04-29 18:13:49 UTC (rev 183561)
+++ trunk/Source/WebKit2/Shared/WebProcessCreationParameters.h	2015-04-29 18:31:35 UTC (rev 183562)
@@ -110,6 +110,8 @@
     bool shouldEnableMemoryPressureReliefLogging;
     bool shouldUseFontSmoothing;
 
+    Vector<String> fontWhitelist;
+
     bool iconDatabaseEnabled;
 
     double terminationTimeout;

Modified: trunk/Source/WebKit2/UIProcess/API/C/WKContext.cpp (183561 => 183562)


--- trunk/Source/WebKit2/UIProcess/API/C/WKContext.cpp	2015-04-29 18:13:49 UTC (rev 183561)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKContext.cpp	2015-04-29 18:31:35 UTC (rev 183562)
@@ -604,3 +604,8 @@
 {
     toImpl(contextRef)->setMemoryCacheDisabled(disabled);
 }
+
+void WKContextSetFontWhitelist(WKContextRef contextRef, WKArrayRef arrayRef)
+{
+    toImpl(contextRef)->setFontWhitelist(toImpl(arrayRef));
+}

Modified: trunk/Source/WebKit2/UIProcess/API/C/WKContextPrivate.h (183561 => 183562)


--- trunk/Source/WebKit2/UIProcess/API/C/WKContextPrivate.h	2015-04-29 18:13:49 UTC (rev 183561)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKContextPrivate.h	2015-04-29 18:31:35 UTC (rev 183562)
@@ -91,6 +91,8 @@
     
 WK_EXPORT void WKContextSetMemoryCacheDisabled(WKContextRef, bool disabled);
 
+WK_EXPORT void WKContextSetFontWhitelist(WKContextRef, WKArrayRef);
+
 #ifdef __cplusplus
 }
 #endif

Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebProcessPoolCocoa.mm (183561 => 183562)


--- trunk/Source/WebKit2/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2015-04-29 18:13:49 UTC (rev 183561)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2015-04-29 18:31:35 UTC (rev 183562)
@@ -218,6 +218,8 @@
     }
 #endif
 
+    parameters.fontWhitelist = m_fontWhitelist;
+
     if (m_bundleParameters) {
         auto data = "" alloc] init]);
         auto keyedArchiver = adoptNS([[NSKeyedArchiver alloc] initForWritingWithMutableData:data.get()]);

Modified: trunk/Source/WebKit2/UIProcess/WebProcessPool.cpp (183561 => 183562)


--- trunk/Source/WebKit2/UIProcess/WebProcessPool.cpp	2015-04-29 18:13:49 UTC (rev 183561)
+++ trunk/Source/WebKit2/UIProcess/WebProcessPool.cpp	2015-04-29 18:31:35 UTC (rev 183562)
@@ -1456,4 +1456,15 @@
     sendToAllProcesses(Messages::WebProcess::SetMemoryCacheDisabled(disabled));
 }
 
+void WebProcessPool::setFontWhitelist(API::Array* array)
+{
+    m_fontWhitelist.clear();
+    if (array) {
+        for (size_t i = 0; i < array->size(); ++i) {
+            if (API::String* font = array->at<API::String>(i))
+                m_fontWhitelist.append(font->string());
+        }
+    }
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit2/UIProcess/WebProcessPool.h (183561 => 183562)


--- trunk/Source/WebKit2/UIProcess/WebProcessPool.h	2015-04-29 18:13:49 UTC (rev 183561)
+++ trunk/Source/WebKit2/UIProcess/WebProcessPool.h	2015-04-29 18:31:35 UTC (rev 183562)
@@ -347,6 +347,7 @@
 #endif
 
     void setMemoryCacheDisabled(bool);
+    void setFontWhitelist(API::Array*);
 
     UserObservablePageToken userObservablePageCount()
     {
@@ -471,6 +472,8 @@
     bool m_alwaysUsesComplexTextCodePath;
     bool m_shouldUseFontSmoothing;
 
+    Vector<String> m_fontWhitelist;
+
     // Messages that were posted before any pages were created.
     // The client should use initialization messages instead, so that a restarted process would get the same state.
     Vector<std::pair<String, RefPtr<API::Object>>> m_messagesToInjectedBundlePostedToEmptyContext;

Modified: trunk/Source/WebKit2/WebProcess/cocoa/WebProcessCocoa.mm (183561 => 183562)


--- trunk/Source/WebKit2/WebProcess/cocoa/WebProcessCocoa.mm	2015-04-29 18:13:49 UTC (rev 183561)
+++ trunk/Source/WebKit2/WebProcess/cocoa/WebProcessCocoa.mm	2015-04-29 18:31:35 UTC (rev 183562)
@@ -44,6 +44,7 @@
 #import <WebCore/AXObjectCache.h>
 #import <WebCore/CFNetworkSPI.h>
 #import <WebCore/FileSystem.h>
+#import <WebCore/FontCache.h>
 #import <WebCore/FontCascade.h>
 #import <WebCore/LocalizedStrings.h>
 #import <WebCore/MemoryCache.h>
@@ -171,6 +172,10 @@
     }
 #endif
 
+#if PLATFORM(MAC)
+    WebCore::FontCache::setFontWhitelist(parameters.fontWhitelist);
+#endif
+
     m_compositingRenderServerPort = WTF::move(parameters.acceleratedCompositingPort);
     m_presenterApplicationPid = parameters.presenterApplicationPid;
     FontCascade::setDefaultTypesettingFeatures(parameters.shouldEnableKerningAndLigaturesByDefault ? Kerning | Ligatures : 0);

Modified: trunk/Tools/ChangeLog (183561 => 183562)


--- trunk/Tools/ChangeLog	2015-04-29 18:13:49 UTC (rev 183561)
+++ trunk/Tools/ChangeLog	2015-04-29 18:31:35 UTC (rev 183562)
@@ -1,3 +1,25 @@
+2015-04-29  Myles C. Maxfield  <[email protected]>
+
+        [OS X] Use CTFontCreateForCSS instead of doing font search ourselves
+        https://bugs.webkit.org/show_bug.cgi?id=132159
+
+        Reviewed by Darin Adler.
+
+        Make DumpRenderTree and WebKitTestRunner use the new font whitelist instead of
+        swizzling NSFontManager methods. This is predicated on ENABLE(PLATFORM_FONT_LOOKUP).
+
+        * DumpRenderTree/mac/DumpRenderTree.mm:
+        (fontWhitelist):
+        (adjustFonts):
+        (createWebViewAndOffscreenWindow):
+        * WebKitTestRunner/InjectedBundle/cocoa/ActivateFontsCocoa.mm:
+        (WTR::activateFonts):
+        * WebKitTestRunner/mac/TestControllerMac.mm:
+        (WTR::allowedFontFamilySet):
+        (WTR::systemHiddenFontFamilySet):
+        (WTR::generateWhitelist):
+        (WTR::TestController::platformInitializeContext):
+
 2015-04-29  Alexey Proskuryakov  <[email protected]>
 
         fast/frames/flattening/iframe-flattening-resize-event-count.html times out on Yosemite WK2

Modified: trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm (183561 => 183562)


--- trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm	2015-04-29 18:13:49 UTC (rev 183561)
+++ trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm	2015-04-29 18:31:35 UTC (rev 183562)
@@ -414,6 +414,7 @@
     return fontFamilySet;
 }
 
+#if !ENABLE(PLATFORM_FONT_LOOKUP)
 static IMP appKitAvailableFontFamiliesIMP;
 static IMP appKitAvailableFontsIMP;
 
@@ -473,6 +474,29 @@
     appKitAvailableFontsIMP = method_setImplementation(availableFontsMethod, (IMP)drt_NSFontManager_availableFonts);
 }
 
+#else
+
+static NSArray *fontWhitelist()
+{
+    static NSArray *availableFonts;
+    if (availableFonts)
+        return availableFonts;
+
+    NSMutableArray *availableFontList = [[NSMutableArray alloc] init];
+    for (NSString *fontFamily in allowedFontFamilySet()) {
+        NSArray* fontsForFamily = [[NSFontManager sharedFontManager] availableMembersOfFontFamily:fontFamily];
+        [availableFontList addObject:fontFamily];
+        for (NSArray* fontInfo in fontsForFamily) {
+            // Font name is the first entry in the array.
+            [availableFontList addObject:[fontInfo objectAtIndex:0]];
+        }
+    }
+
+    availableFonts = availableFontList;
+    return availableFonts;
+}
+#endif
+
 // Activating system copies of these fonts overrides any others that could be preferred, such as ones
 // in /Library/Fonts/Microsoft, and which don't always have the same metrics.
 // FIXME: Switch to a solution from <rdar://problem/19553550> once it's available.
@@ -549,7 +573,9 @@
 
 static void adjustFonts()
 {
+#if !ENABLE(PLATFORM_FONT_LOOKUP)
     swizzleNSFontManagerMethods();
+#endif
     activateSystemCoreWebFonts();
     activateTestingFonts();
 }
@@ -732,6 +758,10 @@
     [WebView registerURLSchemeAsLocal:@"feeds"];
     [WebView registerURLSchemeAsLocal:@"feedsearch"];
     
+#if PLATFORM(MAC) && ENABLE(PLATFORM_FONT_LOOKUP)
+    [WebView _setFontWhitelist:fontWhitelist()];
+#endif
+
 #if !PLATFORM(IOS)
     [webView setContinuousSpellCheckingEnabled:YES];
     [webView setAutomaticQuoteSubstitutionEnabled:NO];

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/cocoa/ActivateFontsCocoa.mm (183561 => 183562)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/cocoa/ActivateFontsCocoa.mm	2015-04-29 18:13:49 UTC (rev 183561)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/cocoa/ActivateFontsCocoa.mm	2015-04-29 18:31:35 UTC (rev 183562)
@@ -45,6 +45,7 @@
 
 #if USE(APPKIT)
 
+#if !ENABLE(PLATFORM_FONT_LOOKUP)
 static NSSet *allowedFontFamilySet()
 {
     static NSSet *fontFamilySet = [[NSSet setWithObjects:
@@ -240,6 +241,7 @@
     
     appKitAvailableFontsIMP = method_setImplementation(availableFontsMethod, (IMP)wtr_NSFontManager_availableFonts);
 }
+#endif
 
 // Activating system copies of these fonts overrides any others that could be preferred, such as ones
 // in /Library/Fonts/Microsoft, and which don't always have the same metrics.
@@ -317,7 +319,9 @@
     }
 
 #if USE(APPKIT)
+#if !ENABLE(PLATFORM_FONT_LOOKUP)
     swizzleNSFontManagerMethods();
+#endif
     activateSystemCoreWebFonts();
 #endif // USE(APPKIT)
 }

Modified: trunk/Tools/WebKitTestRunner/mac/TestControllerMac.mm (183561 => 183562)


--- trunk/Tools/WebKitTestRunner/mac/TestControllerMac.mm	2015-04-29 18:13:49 UTC (rev 183561)
+++ trunk/Tools/WebKitTestRunner/mac/TestControllerMac.mm	2015-04-29 18:31:35 UTC (rev 183562)
@@ -31,6 +31,7 @@
 #import "PoseAsClass.h"
 #import "TestInvocation.h"
 #import "WebKitTestRunnerPasteboard.h"
+#import <WebKit/WKContextPrivate.h>
 #import <WebKit/WKPageGroup.h>
 #import <WebKit/WKStringCF.h>
 #import <WebKit/WKURLCF.h>
@@ -141,6 +142,160 @@
         [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:endDate];
 }
 
+#if ENABLE(PLATFORM_FONT_LOOKUP)
+static NSSet *allowedFontFamilySet()
+{
+    static NSSet *fontFamilySet = [[NSSet setWithObjects:
+        @"Ahem",
+        @"Al Bayan",
+        @"American Typewriter",
+        @"Andale Mono",
+        @"Apple Braille",
+        @"Apple Color Emoji",
+        @"Apple Chancery",
+        @"Apple Garamond BT",
+        @"Apple LiGothic",
+        @"Apple LiSung",
+        @"Apple Symbols",
+        @"AppleGothic",
+        @"AppleMyungjo",
+        @"Arial Black",
+        @"Arial Hebrew",
+        @"Arial Narrow",
+        @"Arial Rounded MT Bold",
+        @"Arial Unicode MS",
+        @"Arial",
+        @"Ayuthaya",
+        @"Baghdad",
+        @"Baskerville",
+        @"BiauKai",
+        @"Big Caslon",
+        @"Brush Script MT",
+        @"Chalkboard",
+        @"Chalkduster",
+        @"Charcoal CY",
+        @"Cochin",
+        @"Comic Sans MS",
+        @"Copperplate",
+        @"Corsiva Hebrew",
+        @"Courier New",
+        @"Courier",
+        @"DecoType Naskh",
+        @"Devanagari MT",
+        @"Didot",
+        @"Euphemia UCAS",
+        @"Futura",
+        @"GB18030 Bitmap",
+        @"Geeza Pro",
+        @"Geneva CY",
+        @"Geneva",
+        @"Georgia",
+        @"Gill Sans",
+        @"Gujarati MT",
+        @"GungSeo",
+        @"Gurmukhi MT",
+        @"HeadLineA",
+        @"Hei",
+        @"Heiti SC",
+        @"Heiti TC",
+        @"Helvetica CY",
+        @"Helvetica Neue",
+        @"Helvetica",
+        @"Herculanum",
+        @"Hiragino Kaku Gothic Pro",
+        @"Hiragino Kaku Gothic ProN",
+        @"Hiragino Kaku Gothic Std",
+        @"Hiragino Kaku Gothic StdN",
+        @"Hiragino Maru Gothic Monospaced",
+        @"Hiragino Maru Gothic Pro",
+        @"Hiragino Maru Gothic ProN",
+        @"Hiragino Mincho Pro",
+        @"Hiragino Mincho ProN",
+        @"Hiragino Sans GB",
+        @"Hoefler Text",
+        @"Impact",
+        @"InaiMathi",
+        @"Kai",
+        @"Kailasa",
+        @"Kokonor",
+        @"Krungthep",
+        @"KufiStandardGK",
+        @"LiHei Pro",
+        @"LiSong Pro",
+        @"Lucida Grande",
+        @"Marker Felt",
+        @"Menlo",
+        @"Microsoft Sans Serif",
+        @"Monaco",
+        @"Mshtakan",
+        @"Nadeem",
+        @"New Peninim MT",
+        @"Optima",
+        @"Osaka",
+        @"Papyrus",
+        @"PCMyungjo",
+        @"PilGi",
+        @"Plantagenet Cherokee",
+        @"Raanana",
+        @"Sathu",
+        @"Silom",
+        @"Skia",
+        @"Songti SC",
+        @"Songti TC",
+        @"STFangsong",
+        @"STHeiti",
+        @"STIXGeneral",
+        @"STIXSizeOneSym",
+        @"STKaiti",
+        @"STSong",
+        @"Symbol",
+        @"System Font",
+        @"Tahoma",
+        @"Thonburi",
+        @"Times New Roman",
+        @"Times",
+        @"Trebuchet MS",
+        @"Verdana",
+        @"Webdings",
+        @"WebKit WeightWatcher",
+        @"Wingdings 2",
+        @"Wingdings 3",
+        @"Wingdings",
+        @"Zapf Dingbats",
+        @"Zapfino",
+        nil] retain];
+
+    return fontFamilySet;
+}
+
+static NSSet *systemHiddenFontFamilySet()
+{
+    static NSSet *fontFamilySet = [[NSSet setWithObjects:
+        @".LucidaGrandeUI",
+        nil] retain];
+
+    return fontFamilySet;
+}
+
+static WKRetainPtr<WKArrayRef> generateWhitelist()
+{
+    WKMutableArrayRef result = WKMutableArrayCreate();
+    for (NSString *fontFamily in allowedFontFamilySet()) {
+        NSArray *fontsForFamily = [[NSFontManager sharedFontManager] availableMembersOfFontFamily:fontFamily];
+        WKArrayAppendItem(result, WKStringCreateWithUTF8CString([fontFamily UTF8String]));
+        for (NSArray *fontInfo in fontsForFamily) {
+            // Font name is the first entry in the array.
+            WKArrayAppendItem(result, WKStringCreateWithUTF8CString([[fontInfo objectAtIndex:0] UTF8String]));
+        }
+    }
+
+    for (NSString *hiddenFontFamily in systemHiddenFontFamilySet())
+        WKArrayAppendItem(result, WKStringCreateWithUTF8CString([hiddenFontFamily UTF8String]));
+
+    return adoptWK(result);
+}
+#endif
+
 void TestController::platformInitializeContext()
 {
     // Testing uses a private session, which is memory only. However creating one instantiates a shared NSURLCache,
@@ -151,6 +306,10 @@
                                       diskCapacity:0
                                           diskPath:nil]);
     [NSURLCache setSharedURLCache:sharedCache.get()];
+
+#if ENABLE(PLATFORM_FONT_LOOKUP)
+    WKContextSetFontWhitelist(m_context.get(), generateWhitelist().get());
+#endif
 }
 
 void TestController::setHidden(bool hidden)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to