Changeset 169122 in webkit


Ignore:
Timestamp:
May 20, 2014 11:44:52 AM (10 years ago)
Author:
ap@apple.com
Message:

[Mac] WebProcess doesn't follow localization of UI process when run as a service
https://bugs.webkit.org/show_bug.cgi?id=133126
<rdar://problem/13396515>
<rdar://problem/16561084>

Reviewed by Sam Weinig and Tim Horton.

Source/WebKit2:

  • Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.Development.mm:

(WebKit::handleXPCBootstrap):
(main):

  • Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.mm:

(WebKit::handleXPCBootstrap):
(main):
Set localization very early in process lifetime (in development builds, that's
even before WebKit framework is loaded).

  • UIProcess/Launcher/mac/ProcessLauncherMac.mm: (WebKit::connectToService):

Pass UI process localization to the service, computing it in the same way we do
for child processes.

Tools:

  • WebKitTestRunner/InjectedBundle/mac/InjectedBundleMac.mm:

(WTR::InjectedBundle::platformInitialize): It was too late to override language
here, and it's not necessary any more. Keeping the code for older OS versions in
case it did have effect in some code paths.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r169114 r169122  
     12014-05-20  Alexey Proskuryakov  <ap@apple.com>
     2
     3        [Mac] WebProcess doesn't follow localization of UI process when run as a service
     4        https://bugs.webkit.org/show_bug.cgi?id=133126
     5        <rdar://problem/13396515>
     6        <rdar://problem/16561084>
     7
     8        Reviewed by Sam Weinig and Tim Horton.
     9
     10        * Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.Development.mm:
     11        (WebKit::handleXPCBootstrap):
     12        (main):
     13        * Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.mm:
     14        (WebKit::handleXPCBootstrap):
     15        (main):
     16        Set localization very early in process lifetime (in development builds, that's
     17        even before WebKit framework is loaded).
     18
     19        * UIProcess/Launcher/mac/ProcessLauncherMac.mm: (WebKit::connectToService):
     20        Pass UI process localization to the service, computing it in the same way we do
     21        for child processes.
     22
    1232014-05-20  Anders Carlsson  <andersca@apple.com>
    224
  • trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.Development.mm

    r168584 r169122  
    3131#import <stdlib.h>
    3232#import "XPCPtr.h"
     33
     34#if __has_include(<Foundation/NSPrivateDecls.h>)
     35#import <Foundation/NSPrivateDecls.h>
     36#endif
     37
     38#if __has_include(<xpc/private.h>)
     39#import <xpc/private.h>
     40#endif
     41
     42#if PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 10100
     43extern "C" xpc_object_t xpc_copy_bootstrap();
     44#endif
     45
     46@interface NSUserDefaults (Details)
     47- (void)setObject:(id)value forKey:(NSString *)defaultName inDomain:(NSString *)domain;
     48@end
    3349
    3450namespace WebKit {
     
    156172}
    157173
     174static void handleXPCBootstrap()
     175{
     176#if PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 10100
     177    auto bootstrapData = IPC::adoptXPC(xpc_copy_bootstrap());
     178    const char* localization = xpc_dictionary_get_string(bootstrapData.get(), "localization");
     179    if (localization) {
     180        // Do this before calling xpc_main(), so that the preference is set before any CFBundle code runs.
     181        [[NSUserDefaults standardUserDefaults] setObject:@[ [NSString stringWithUTF8String:localization] ] forKey:@"AppleLanguages" inDomain:NSArgumentDomain];
     182    }
     183#endif
     184}
     185
    158186} // namespace WebKit;
    159187
     
    162190int main(int argc, char** argv)
    163191{
     192    handleXPCBootstrap();
    164193    xpc_main(XPCServiceEventHandler);
    165194    return 0;
  • trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.mm

    r168584 r169122  
    2626#import <CoreFoundation/CoreFoundation.h>
    2727#import "XPCPtr.h"
     28
     29#if __has_include(<Foundation/NSPrivateDecls.h>)
     30#import <Foundation/NSPrivateDecls.h>
     31#endif
     32
     33#if __has_include(<xpc/private.h>)
     34#import <xpc/private.h>
     35#endif
     36
     37#if PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 10100
     38extern "C" xpc_object_t xpc_copy_bootstrap();
     39#endif
     40
     41@interface NSUserDefaults (Details)
     42- (void)setObject:(id)value forKey:(NSString *)defaultName inDomain:(NSString *)domain;
     43@end
    2844
    2945namespace WebKit {
     
    6985}
    7086
     87static void handleXPCBootstrap()
     88{
     89#if PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 10100
     90    auto bootstrapData = IPC::adoptXPC(xpc_copy_bootstrap());
     91    const char* localization = xpc_dictionary_get_string(bootstrapData.get(), "localization");
     92    if (localization) {
     93        // Do this before calling xpc_main(), so that the preference is set before any CFBundle code runs.
     94        [[NSUserDefaults standardUserDefaults] setObject:@[ [NSString stringWithUTF8String:localization] ] forKey:@"AppleLanguages" inDomain:NSArgumentDomain];
     95    }
     96#endif
     97}
     98
    7199} // namespace WebKit
    72100
     
    75103int main(int argc, char** argv)
    76104{
     105    handleXPCBootstrap();
    77106    xpc_main(XPCServiceEventHandler);
    78107    return 0;
  • trunk/Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm

    r168584 r169122  
    4545#import <xpc/xpc.h>
    4646
     47#if __has_include(<xpc/private.h>)
     48#import <xpc/private.h>
     49#endif
     50
    4751// FIXME: We should be doing this another way.
    4852extern "C" kern_return_t bootstrap_register2(mach_port_t, name_t, mach_port_t, uint64_t);
     
    5054extern "C" void xpc_connection_set_instance(xpc_connection_t, uuid_t);
    5155extern "C" void xpc_dictionary_set_mach_send(xpc_object_t, const char*, mach_port_t);
     56
     57#if PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 10100
     58extern "C" void xpc_connection_set_bootstrap(xpc_connection_t connection, xpc_object_t bootstrap);
     59#endif
    5260
    5361namespace WebKit {
     
    177185    xpc_connection_set_instance(connection.get(), instanceUUID->uuid);
    178186
     187#if PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 10100
     188    // Inherit UI process localization. It can be different from child process default localization:
     189    // 1. When the application and system frameworks simply have different localized resources available, we should match the application.
     190    // 1.1. An important case is WebKitTestRunner, where we should use English localizations for all system frameworks.
     191    // 2. When AppleLanguages is passed as command line argument for UI process, or set in its preferences, we should respect it in child processes.
     192    // FIXME: When UI process allows for mixed localizations (CFBundleAllowMixedLocalizations), we should probably send the whole AppleLanguages array.
     193    RetainPtr<CFStringRef> localization = adoptCF(WKCopyCFLocalizationPreferredName(0));
     194    if (localization) {
     195        auto initializationMessage = IPC::adoptXPC(xpc_dictionary_create(nullptr, nullptr, 0));
     196        xpc_dictionary_set_string(initializationMessage.get(), "localization", String(localization.get()).ascii().data());
     197        xpc_connection_set_bootstrap(connection.get(), initializationMessage.get());
     198    }
     199#endif
     200
    179201    // XPC requires having an event handler, even if it is not used.
    180202    xpc_connection_set_event_handler(connection.get(), ^(xpc_object_t event) { });
     
    200222    CString clientIdentifier = bundleIdentifier ? String([[NSBundle mainBundle] bundleIdentifier]).utf8() : *_NSGetProgname();
    201223
     224    // FIXME: Switch to xpc_connection_set_bootstrap once it's available everywhere we need.
    202225    auto bootstrapMessage = IPC::adoptXPC(xpc_dictionary_create(nullptr, nullptr, 0));
    203226    xpc_dictionary_set_string(bootstrapMessage.get(), "message-name", "bootstrap");
  • trunk/Tools/ChangeLog

    r169113 r169122  
     12014-05-20  Alexey Proskuryakov  <ap@apple.com>
     2
     3        [Mac] WebProcess doesn't follow localization of UI process when run as a service
     4        https://bugs.webkit.org/show_bug.cgi?id=133126
     5        <rdar://problem/13396515>
     6        <rdar://problem/16561084>
     7
     8        Reviewed by Sam Weinig and Tim Horton.
     9
     10        * WebKitTestRunner/InjectedBundle/mac/InjectedBundleMac.mm:
     11        (WTR::InjectedBundle::platformInitialize): It was too late to override language
     12        here, and it's not necessary any more. Keeping the code for older OS versions in
     13        case it did have effect in some code paths.
     14
    1152014-05-19  David Farler  <dfarler@apple.com>
    216
  • trunk/Tools/WebKitTestRunner/InjectedBundle/mac/InjectedBundleMac.mm

    r158326 r169122  
    5555        @"NSOverlayScrollersEnabled": @NO,
    5656        @"AppleShowScrollBars": @"Always",
     57#if !PLATFORM(IOS) && __MAC_OS_X_VERSION_MIN_REQUIRED <= 1090
    5758        // FIXME (<rdar://problem/13396515>): It is too late to set AppleLanguages here, as loaded frameworks localizations cannot be changed.
    5859        // This breaks some accessibility tests on machines with non-English user language.
    5960        @"AppleLanguages": @[ @"en" ],
     61#endif
    6062        // FIXME: Why does this dictionary not match the one in DumpRenderTree?
    6163        @"NSTestCorrectionDictionary": @{
Note: See TracChangeset for help on using the changeset viewer.