Font fallback in WebKitTestRunner depends on user settings
[WebKit-https.git] / Tools / WebKitTestRunner / InjectedBundle / mac / InjectedBundleMac.mm
index 5ab6bda7e351078c050b8c19111331e98758e5b3..1bbff4156b20b7c6722a22f5545784c4046c4388 100644 (file)
 
 #import "InjectedBundle.h"
 
-#import <AppKit/AppKit.h>
 #import <Foundation/Foundation.h>
-#import <objc/objc-runtime.h>
 
 namespace WTR {
 
-static NSSet *allowedFontFamilySet()
-{
-    static NSSet *fontFamiliySet = [[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",
-        @"ColorBits",
-        @"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 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",
-        @"STFangsong",
-        @"STHeiti",
-        @"STKaiti",
-        @"STSong",
-        @"Symbol",
-        @"Tahoma",
-        @"Thonburi",
-        @"Times New Roman",
-        @"Times",
-        @"Trebuchet MS",
-        @"Verdana",
-        @"Webdings",
-        @"WebKit WeightWatcher",
-        @"Wingdings 2",
-        @"Wingdings 3",
-        @"Wingdings",
-        @"Zapf Dingbats",
-        @"Zapfino",
-        nil] retain];
-    
-    return fontFamiliySet;
-}
-
-static IMP appKitAvailableFontFamiliesIMP;
-static IMP appKitAvailableFontsIMP;
-
-static NSArray *drt_NSFontManager_availableFontFamilies(id self, SEL _cmd)
-{
-    static NSArray *availableFontFamilies;
-    if (availableFontFamilies)
-        return availableFontFamilies;
-    
-    NSArray *availableFamilies = appKitAvailableFontFamiliesIMP(self, _cmd);
-
-    NSMutableSet *prunedFamiliesSet = [NSMutableSet setWithArray:availableFamilies];
-    [prunedFamiliesSet intersectSet:allowedFontFamilySet()];
-
-    availableFontFamilies = [[prunedFamiliesSet allObjects] retain];
-    return availableFontFamilies;
-}
-
-static NSArray *drt_NSFontManager_availableFonts(id self, SEL _cmd)
-{
-    static NSArray *availableFonts;
-    if (availableFonts)
-        return availableFonts;
-    
-    NSSet *allowedFamilies = allowedFontFamilySet();
-    NSMutableArray *availableFontList = [[NSMutableArray alloc] initWithCapacity:[allowedFamilies count] * 2];
-    for (NSString *fontFamily in allowedFontFamilySet()) {
-        NSArray* fontsForFamily = [[NSFontManager sharedFontManager] availableMembersOfFontFamily:fontFamily];
-        for (NSArray* fontInfo in fontsForFamily) {
-            // Font name is the first entry in the array.
-            [availableFontList addObject:[fontInfo objectAtIndex:0]];
-        }
-    }
-    
-    availableFonts = availableFontList;
-    return availableFonts;
-}
-
-static void swizzleNSFontManagerMethods()
-{
-    Method availableFontFamiliesMethod = class_getInstanceMethod(objc_getClass("NSFontManager"), @selector(availableFontFamilies));
-    ASSERT(availableFontFamiliesMethod);
-    if (!availableFontFamiliesMethod) {
-        NSLog(@"Failed to swizzle the \"availableFontFamilies\" method on NSFontManager");
-        return;
-    }
-    
-    appKitAvailableFontFamiliesIMP = method_setImplementation(availableFontFamiliesMethod, (IMP)drt_NSFontManager_availableFontFamilies);
-
-    Method availableFontsMethod = class_getInstanceMethod(objc_getClass("NSFontManager"), @selector(availableFonts));
-    ASSERT(availableFontsMethod);
-    if (!availableFontsMethod) {
-        NSLog(@"Failed to swizzle the \"availableFonts\" method on NSFontManager");
-        return;
-    }
-    
-    appKitAvailableFontsIMP = method_setImplementation(availableFontsMethod, (IMP)drt_NSFontManager_availableFonts);
-}
-
 void InjectedBundle::platformInitialize(WKTypeRef)
 {
     NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
@@ -218,11 +37,10 @@ void InjectedBundle::platformInitialize(WKTypeRef)
         [NSNumber numberWithBool:NO],     @"AppleScrollAnimationEnabled",
         [NSNumber numberWithBool:NO],     @"NSOverlayScrollersEnabled",
         @"Always",                        @"AppleShowScrollBars",
+        [NSArray arrayWithObject:@"en"],  @"AppleLanguages",
         nil];
 
-    [[NSUserDefaults standardUserDefaults] registerDefaults:dict];
-    
-    swizzleNSFontManagerMethods();
+    [[NSUserDefaults standardUserDefaults] setVolatileDomain:dict forName:NSArgumentDomain];    
 }
 
 } // namespace WTR