⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 172975 in webkit


Ignore:
Timestamp:
Aug 26, 2014, 2:06:07 PM (12 years ago)
Author:
mjs@apple.com
Message:

Replace use of WKCopyCFLocalizationPreferredName with NSLocale public API
https://bugs.webkit.org/show_bug.cgi?id=136082

Reviewed by Alexey Proskuryakov.

Source/WebCore:

  • platform/mac/Language.mm:

(WebCore::httpStyleLanguageCode): Replace use of WKCopyCFLocalizationPreferredName
with new WebCoreNSStringExtras helper.

  • platform/mac/WebCoreNSStringExtras.mm: Replacements for the aspects of

WKCopyCFLocalizationPreferredName.
(preferredBundleLocalizationName): New helper - most preferred localization available
in the main bundle, canonicalized the way we like it.
(canonicalLocalizationName): Convert a lcalization name to a string with language and
country code, using default if necessary (e.g. "en" maps to "en_US").

  • WebCore.order: Remove mention of WKCopyCFLocalizationPreferredName.
  • WebCore.exp.in: ditto; also export preferredBundleLocalizationName for WebKit(2).
  • platform/ios/WebCoreSystemInterfaceIOS.mm: ditto
  • platform/mac/WebCoreSystemInterface.h: ditto
  • platform/mac/WebCoreSystemInterface.mm: ditto
  • platform/spi/cf: Added.
  • platform/spi/cf/CFLocaleSPI.h: Added. Declare

CFLocaleGetLanguageRegionEncodingForLocaleIdentifier.

Source/WebKit/mac:

  • Plugins/Hosted/NetscapePluginHostManager.mm:

(WebKit::NetscapePluginHostManager::spawnPluginHost): Get current
localization name using WebCore helper instead of SPI.

  • Plugins/WebBasePluginPackage.mm: Fixed the include style for this

file.
(-[WebBasePluginPackage getPluginInfoFromPLists]): Get current
localization name using WebCore helper instead of SPI.
(+[WebBasePluginPackage preferredLocalizationName]): Deleted. This
helper no longer pulls its weight.

  • WebCoreSupport/WebSystemInterface.mm:

(InitWebCoreSystemInterface): Remove mention of
WKCopyCFLocalizationPreferredName.

  • WebKit.order: ditto

Source/WebKit2:

  • UIProcess/Launcher/mac/ProcessLauncherMac.mm:

(WebKit::connectToService): Remove accidental leftover retrieval
of the localization.
(WebKit::createProcess): Get current localization name from
CFBundle API instead of using SPI.

  • WebProcess/WebCoreSupport/mac/WebSystemInterface.mm:

(InitWebCoreSystemInterface): Remove mention of WKCopyCFLocalizationPreferredName

  • mac/WebKit2.order: ditto
Location:
trunk/Source
Files:
2 added
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r172973 r172975  
     12014-08-25  Maciej Stachowiak  <mjs@apple.com>
     2
     3        Replace use of WKCopyCFLocalizationPreferredName with NSLocale public API
     4        https://bugs.webkit.org/show_bug.cgi?id=136082
     5
     6        Reviewed by Alexey Proskuryakov.
     7
     8        * platform/mac/Language.mm:
     9        (WebCore::httpStyleLanguageCode): Replace use of WKCopyCFLocalizationPreferredName
     10        with new WebCoreNSStringExtras helper.
     11        * platform/mac/WebCoreNSStringExtras.mm: Replacements for the aspects of
     12        WKCopyCFLocalizationPreferredName.
     13        (preferredBundleLocalizationName): New helper - most preferred localization available
     14        in the main bundle, canonicalized the way we like it.
     15        (canonicalLocalizationName): Convert a lcalization name to a string with language and
     16        country code, using default if necessary (e.g. "en" maps to "en_US").
     17        * WebCore.order: Remove mention of WKCopyCFLocalizationPreferredName.
     18        * WebCore.exp.in: ditto; also export preferredBundleLocalizationName for WebKit(2).
     19        * platform/ios/WebCoreSystemInterfaceIOS.mm: ditto
     20        * platform/mac/WebCoreSystemInterface.h: ditto
     21        * platform/mac/WebCoreSystemInterface.mm: ditto
     22        * platform/spi/cf: Added.
     23        * platform/spi/cf/CFLocaleSPI.h: Added. Declare
     24        CFLocaleGetLanguageRegionEncodingForLocaleIdentifier.
     25
    1262014-08-26  Zoltan Horvath  <zoltan@webkit.org>
    227
  • trunk/Source/WebCore/WebCore.exp.in

    r172946 r172975  
    20782078_hasCaseInsensitiveSubstring
    20792079_hasCaseInsensitiveSuffix
     2080_preferredBundleLocalizationName
    20802081_stringIsCaseInsensitiveEqualToString
    20812082_suggestedFilenameWithMIMEType
     
    20882089_wkCGPatternCreateWithImageAndTransform
    20892090_wkCTRunGetInitialAdvance
    2090 _wkCopyCFLocalizationPreferredName
    20912091_wkCopyCFURLResponseSuggestedFilename
    20922092_wkCopyCONNECTProxyResponse
  • trunk/Source/WebCore/WebCore.order

    r172930 r172975  
    3059130591_wkCGContextDrawsWithCorrectShadowOffsets
    3059230592_wkCGPatternCreateWithImageAndTransform
    30593 _wkCopyCFLocalizationPreferredName
    3059430593_wkCopyNSURLResponseStatusLine
    3059530594_wkCopyNSURLResponseCertificateChain
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r172963 r172975  
    92329232                637B7ADE0E8767B800E32194 /* ElementRareData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ElementRareData.h; sourceTree = "<group>"; };
    92339233                63D7B32C0E78CD3F00F7617C /* NodeRenderStyle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NodeRenderStyle.h; sourceTree = "<group>"; };
     9234                65086DA719AC1719009AF46B /* CFLocaleSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CFLocaleSPI.h; sourceTree = "<group>"; };
    92349235                650F53DB09D15DDA00C9B0C8 /* CSSGrammar.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = CSSGrammar.h; sourceTree = "<group>"; };
    92359236                650FBF270D9AF046008FC292 /* SVGHKernElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGHKernElement.cpp; sourceTree = "<group>"; };
     
    1615816159                        sourceTree = "<group>";
    1615916160                };
     16161                65086DA619AC1719009AF46B /* cf */ = {
     16162                        isa = PBXGroup;
     16163                        children = (
     16164                                65086DA719AC1719009AF46B /* CFLocaleSPI.h */,
     16165                        );
     16166                        path = cf;
     16167                        sourceTree = "<group>";
     16168                };
    1616016169                653EF83619A043AE0052202C /* spi */ = {
    1616116170                        isa = PBXGroup;
    1616216171                        children = (
     16172                                65086DA619AC1719009AF46B /* cf */,
    1616316173                                653EF83719A043AE0052202C /* cocoa */,
    1616416174                        );
  • trunk/Source/WebCore/platform/ios/WebCoreSystemInterfaceIOS.mm

    r172875 r172975  
    3131WEBCORE_EXPORT CGPatternRef (*wkCGPatternCreateWithImageAndTransform)(CGImageRef, CGAffineTransform, int);
    3232WEBCORE_EXPORT void (*wkCGContextResetClip)(CGContextRef);
    33 WEBCORE_EXPORT CFStringRef (*wkCopyCFLocalizationPreferredName)(CFStringRef);
    3433WEBCORE_EXPORT void (*wkClearGlyphVector)(void* glyphs);
    3534WEBCORE_EXPORT OSStatus (*wkConvertCharToGlyphs)(void* styleGroup, const UniChar*, unsigned numCharacters, void* glyphs);
  • trunk/Source/WebCore/platform/mac/Language.mm

    r172875 r172975  
    2828
    2929#import "BlockExceptions.h"
    30 #import "WebCoreSystemInterface.h"
     30#import "WebCoreNSStringExtras.h"
    3131#import <mutex>
    3232#import <wtf/Assertions.h>
     
    7878namespace WebCore {
    7979
    80 static String httpStyleLanguageCode(NSString *languageCode)
     80static String httpStyleLanguageCode(NSString *language)
    8181{
    82     // Look up the language code using CFBundle.
    83     RetainPtr<CFStringRef> preferredLanguageCode = adoptCF(wkCopyCFLocalizationPreferredName((CFStringRef)languageCode));
    84 
    85     if (preferredLanguageCode)
    86         languageCode = (NSString *)preferredLanguageCode.get();
    87 
    88     // Make the string lowercase.
    89     NSString *lowercaseLanguageCode = [languageCode lowercaseString];
    90 
    91     // Turn a '_' into a '-' if it appears after a 2-letter language code.
    92     if ([lowercaseLanguageCode length] >= 3 && [lowercaseLanguageCode characterAtIndex:2] == '_') {
    93         RetainPtr<NSMutableString> mutableLanguageCode = adoptNS([lowercaseLanguageCode mutableCopy]);
    94         [mutableLanguageCode.get() replaceCharactersInRange:NSMakeRange(2, 1) withString:@"-"];
    95         return mutableLanguageCode.get();
    96     }
    97 
    98     return lowercaseLanguageCode;
     82    return [[NSLocale canonicalLanguageIdentifierFromString:canonicalLocaleName(language)] lowercaseString];
    9983}
    10084
  • trunk/Source/WebCore/platform/mac/WebCoreNSStringExtras.h

    r172875 r172975  
    4949#endif
    5050
     51NSString *preferredBundleLocalizationName();
     52NSString *canonicalLocaleName(NSString *);
     53
    5154#ifdef __cplusplus
    5255}
  • trunk/Source/WebCore/platform/mac/WebCoreNSStringExtras.mm

    r172875 r172975  
    2929#import "config.h"
    3030#import "WebCoreNSStringExtras.h"
     31#import "CFLocaleSPI.h"
    3132
    3233#import <wtf/RetainPtr.h>
     
    128129
    129130#endif // !PLATFORM(IOS)
     131
     132
     133
     134NSString *preferredBundleLocalizationName()
     135{
     136    // FIXME: Any use of this function to pass localizations to another
     137    // process is likely not completely right, since it only considers
     138    // one localization.
     139    NSArray *preferredLocalizations = [[NSBundle mainBundle] preferredLocalizations];
     140    if (!preferredLocalizations || ![preferredLocalizations count])
     141        return @"en_US";
     142
     143    return canonicalLocaleName([preferredLocalizations objectAtIndex:0]);
     144}
     145
     146NSString *canonicalLocaleName(NSString *language)
     147{
     148    // FIXME: <rdar://problem/18083880> Replace use of Script Manager
     149    // to canonicalize locales with a custom Web-specific table
     150    LangCode languageCode;
     151    RegionCode regionCode;
     152
     153    Boolean success = CFLocaleGetLanguageRegionEncodingForLocaleIdentifier((CFStringRef)language, &languageCode, &regionCode, nullptr, nullptr);
     154    if (!success)
     155        return @"en_US";
     156
     157    RetainPtr<CFStringRef> code = adoptCF(CFLocaleCreateCanonicalLocaleIdentifierFromScriptManagerCodes(0, languageCode, regionCode));
     158    return (NSString *)code.autorelease();
     159}
  • trunk/Source/WebCore/platform/mac/WebCoreSystemInterface.h

    r172875 r172975  
    150150    void (*formUnschedule)(CFReadStreamRef, CFRunLoopRef, CFStringRef, void *),
    151151    void *context);
    152 extern CFStringRef (*wkCopyCFLocalizationPreferredName)(CFStringRef);
    153152extern NSString* (*wkCopyNSURLResponseStatusLine)(NSURLResponse*);
    154153extern CFArrayRef (*wkCopyNSURLResponseCertificateChain)(NSURLResponse*);
  • trunk/Source/WebCore/platform/mac/WebCoreSystemInterface.mm

    r172875 r172975  
    3636#endif
    3737CGPatternRef (*wkCGPatternCreateWithImageAndTransform)(CGImageRef, CGAffineTransform, int);
    38 CFStringRef (*wkCopyCFLocalizationPreferredName)(CFStringRef);
    3938NSString* (*wkCopyNSURLResponseStatusLine)(NSURLResponse*);
    4039CFArrayRef (*wkCopyNSURLResponseCertificateChain)(NSURLResponse*);
  • trunk/Source/WebKit/mac/ChangeLog

    r172938 r172975  
     12014-08-25  Maciej Stachowiak  <mjs@apple.com>
     2
     3        Replace use of WKCopyCFLocalizationPreferredName with NSLocale public API
     4        https://bugs.webkit.org/show_bug.cgi?id=136082
     5
     6        Reviewed by Alexey Proskuryakov.
     7
     8        * Plugins/Hosted/NetscapePluginHostManager.mm:
     9        (WebKit::NetscapePluginHostManager::spawnPluginHost): Get current
     10        localization name using WebCore helper instead of SPI.
     11        * Plugins/WebBasePluginPackage.mm: Fixed the include style for this
     12        file.
     13        (-[WebBasePluginPackage getPluginInfoFromPLists]): Get current
     14        localization name using WebCore helper instead of SPI.
     15        (+[WebBasePluginPackage preferredLocalizationName]): Deleted. This
     16        helper no longer pulls its weight.
     17        * WebCoreSupport/WebSystemInterface.mm:
     18        (InitWebCoreSystemInterface): Remove mention of
     19        WKCopyCFLocalizationPreferredName.
     20        * WebKit.order: ditto
     21
    1222014-08-25  Daniel Bates  <dabates@apple.com>
    223
  • trunk/Source/WebKit/mac/Plugins/Hosted/NetscapePluginHostManager.mm

    r172875 r172975  
    3333#import "WebKitSystemInterface.h"
    3434#import "WebNetscapePluginPackage.h"
     35#import <WebCore/WebCoreNSStringExtras.h>
    3536#import <mach/mach_port.h>
    3637#import <servers/bootstrap.h>
     
    114115    NSString *pluginHostAppExecutablePath = [[NSBundle bundleWithPath:pluginHostAppPath] executablePath];
    115116
    116     RetainPtr<CFStringRef> localization = adoptCF(WKCopyCFLocalizationPreferredName(NULL));
    117    
    118117    NSDictionary *launchProperties = [[NSDictionary alloc] initWithObjectsAndKeys:
    119118                                      pluginHostAppExecutablePath, @"pluginHostPath",
    120119                                      [NSNumber numberWithInt:pluginArchitecture], @"cpuType",
    121                                       (NSString *)localization.get(), @"localization",
     120                                      preferredBundleLocalizationName(), @"localization",
    122121                                      nil];
    123122
  • trunk/Source/WebKit/mac/Plugins/WebBasePluginPackage.mm

    r172875 r172975  
    2727 */
    2828
    29 #import <WebKitLegacy/WebBasePluginPackage.h>
    30 
     29#import "WebBasePluginPackage.h"
     30
     31#import "WebKitLogging.h"
     32#import "WebKitNSStringExtras.h"
     33#import "WebNetscapePluginPackage.h"
     34#import "WebPluginPackage.h"
     35#import "WebTypesInternal.h"
     36#import <WebCore/WebCoreNSStringExtras.h>
     37#import <WebCore/WebCoreObjCExtras.h>
    3138#import <algorithm>
    32 #import <WebCore/WebCoreObjCExtras.h>
    33 #import <WebKitLegacy/WebKitNSStringExtras.h>
    34 #import <WebKitLegacy/WebNetscapePluginPackage.h>
    35 #import <WebKitLegacy/WebPluginPackage.h>
     39#import <mach-o/arch.h>
     40#import <mach-o/fat.h>
     41#import <mach-o/loader.h>
    3642#import <runtime/InitializeThreading.h>
    3743#import <wtf/Assertions.h>
     
    4248#import <wtf/text/CString.h>
    4349
    44 #import <WebKitSystemInterface.h>
    45 
    46 #import "WebKitLogging.h"
    47 #import "WebTypesInternal.h"
    48 
    49 #import <mach-o/arch.h>
    50 #import <mach-o/fat.h>
    51 #import <mach-o/loader.h>
    5250
    5351#define JavaCocoaPluginIdentifier   "com.apple.JavaPluginCocoa"
     
    8987
    9088    return [pluginPackage autorelease];
    91 }
    92 
    93 + (NSString *)preferredLocalizationName
    94 {
    95     return CFBridgingRelease(WKCopyCFLocalizationPreferredName(NULL));
    9689}
    9790
     
    197190            // If the plist isn't localized, have the plug-in recreate it in the preferred language.
    198191            NSString *localizationName = [pList objectForKey:WebPluginLocalizationNameKey];
    199             if (![localizationName isEqualToString:[[self class] preferredLocalizationName]])
     192            if (![localizationName isEqualToString:preferredBundleLocalizationName()])
    200193                pList = [self pListForPath:pListPath createFile:YES];
    201194            MIMETypes = [pList objectForKey:WebPluginMIMETypesKey];
  • trunk/Source/WebKit/mac/WebCoreSupport/WebSystemInterface.mm

    r172875 r172975  
    5858    INIT(CTFontTransformGlyphs);
    5959#endif
    60     INIT(CopyCFLocalizationPreferredName);
    6160    INIT(CopyCONNECTProxyResponse);
    6261    INIT(CopyNSURLResponseStatusLine);
  • trunk/Source/WebKit/mac/WebKit.order

    r172875 r172975  
    2727+[WebView _shouldAutomaticTextReplacementBeEnabled]
    2828+[WebView _shouldAutomaticSpellingCorrectionBeEnabled]
    29 _WKCopyCFLocalizationPreferredName
    3029+[WebView(WebPrivate) _setDomainRelaxationForbidden:forURLScheme:]
    3130+[WebView(WebPrivate) _registerURLSchemeAsAllowingLocalStorageAccessInPrivateBrowsing:]
     
    850849-[WebBasePluginPackage isNativeLibraryData:]
    851850-[WebBasePluginPackage pListForPath:createFile:]
    852 +[WebBasePluginPackage preferredLocalizationName]
    853851-[WebPluginDatabase(Internal) _addPlugin:]
    854852-[WebBasePluginPackage path]
  • trunk/Source/WebKit2/ChangeLog

    r172974 r172975  
     12014-08-25  Maciej Stachowiak  <mjs@apple.com>
     2
     3        Replace use of WKCopyCFLocalizationPreferredName with NSLocale public API
     4        https://bugs.webkit.org/show_bug.cgi?id=136082
     5
     6        Reviewed by Alexey Proskuryakov.
     7
     8        * UIProcess/Launcher/mac/ProcessLauncherMac.mm:
     9        (WebKit::connectToService): Remove accidental leftover retrieval
     10        of the localization.
     11        (WebKit::createProcess): Get current localization name from
     12        CFBundle API instead of using SPI.
     13        * WebProcess/WebCoreSupport/mac/WebSystemInterface.mm:
     14        (InitWebCoreSystemInterface): Remove mention of WKCopyCFLocalizationPreferredName
     15        * mac/WebKit2.order: ditto
     16
    1172014-08-26  Dana Burkart  <dburkart@apple.com>
    218
  • trunk/Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm

    r172875 r172975  
    2929#import "DynamicLinkerEnvironmentExtractor.h"
    3030#import "EnvironmentVariables.h"
    31 #import "WebKitSystemInterface.h"
    3231#import <WebCore/SoftLinking.h>
     32#import <WebCore/WebCoreNSStringExtras.h>
    3333#import <crt_externs.h>
    3434#import <mach-o/dyld.h>
     
    211211    // 1.1. An important case is WebKitTestRunner, where we should use English localizations for all system frameworks.
    212212    // 2. When AppleLanguages is passed as command line argument for UI process, or set in its preferences, we should respect it in child processes.
    213     RetainPtr<CFStringRef> localization = adoptCF(WKCopyCFLocalizationPreferredName(0));
    214     if (localization && _CFBundleSetupXPCBootstrapPtr()) {
     213    if (_CFBundleSetupXPCBootstrapPtr()) {
    215214        auto initializationMessage = IPC::adoptXPC(xpc_dictionary_create(nullptr, nullptr, 0));
    216215        _CFBundleSetupXPCBootstrapPtr()(initializationMessage.get());
     
    458457    // 1.1. An important case is WebKitTestRunner, where we should use English localizations for all system frameworks.
    459458    // 2. When AppleLanguages is passed as command line argument for UI process, or set in its preferences, we should respect it in child processes.
    460     CString appleLanguagesArgument = String("('" + String(adoptCF(WKCopyCFLocalizationPreferredName(0)).get()) + "')").utf8();
     459    CString appleLanguagesArgument = String("('" + String(preferredBundleLocalizationName()) + "')").utf8();
    461460
    462461    Vector<const char*> args;
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebSystemInterface.mm

    r172875 r172975  
    4141#endif
    4242        INIT(CALayerEnumerateRectsBeingDrawnWithBlock);
    43         INIT(CopyCFLocalizationPreferredName);
    4443        INIT(CGContextGetShouldSmoothFonts);
    4544        INIT(CGPatternCreateWithImageAndTransform);
  • trunk/Source/WebKit2/mac/WebKit2.order

    r172875 r172975  
    34243424__ZN3WTF6VectorINSt3__14pairINS_7CStringES3_EELm0ENS_15CrashOnOverflowEED2Ev
    34253425__ZN3WTF6VectorINSt3__14pairINS_7CStringES3_EELm0ENS_15CrashOnOverflowEE6shrinkEm
    3426 _WKCopyCFLocalizationPreferredName
    34273426__ZN6WebKit15ProcessLauncher19processTypeAsStringENS0_11ProcessTypeE
    34283427__ZNK3WTF12StringAppendIPKcNS_6StringEEcvS3_Ev
Note: See TracChangeset for help on using the changeset viewer.