- Revision
- 169122
- Author
- [email protected]
- Date
- 2014-05-20 11:44:52 -0700 (Tue, 20 May 2014)
Log 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.
Modified Paths
Diff
Modified: trunk/Source/WebKit2/ChangeLog (169121 => 169122)
--- trunk/Source/WebKit2/ChangeLog 2014-05-20 18:07:48 UTC (rev 169121)
+++ trunk/Source/WebKit2/ChangeLog 2014-05-20 18:44:52 UTC (rev 169122)
@@ -1,3 +1,25 @@
+2014-05-20 Alexey Proskuryakov <[email protected]>
+
+ [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.
+
+ * 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.
+
2014-05-20 Anders Carlsson <[email protected]>
Fix a header comment
Modified: trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.Development.mm (169121 => 169122)
--- trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.Development.mm 2014-05-20 18:07:48 UTC (rev 169121)
+++ trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.Development.mm 2014-05-20 18:44:52 UTC (rev 169122)
@@ -31,6 +31,22 @@
#import <stdlib.h>
#import "XPCPtr.h"
+#if __has_include(<Foundation/NSPrivateDecls.h>)
+#import <Foundation/NSPrivateDecls.h>
+#endif
+
+#if __has_include(<xpc/private.h>)
+#import <xpc/private.h>
+#endif
+
+#if PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 10100
+extern "C" xpc_object_t xpc_copy_bootstrap();
+#endif
+
+@interface NSUserDefaults (Details)
+- (void)setObject:(id)value forKey:(NSString *)defaultName inDomain:(NSString *)domain;
+@end
+
namespace WebKit {
struct ReexecInfo {
@@ -155,12 +171,25 @@
xpc_connection_resume(peer);
}
+static void handleXPCBootstrap()
+{
+#if PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 10100
+ auto bootstrapData = IPC::adoptXPC(xpc_copy_bootstrap());
+ const char* localization = xpc_dictionary_get_string(bootstrapData.get(), "localization");
+ if (localization) {
+ // Do this before calling xpc_main(), so that the preference is set before any CFBundle code runs.
+ [[NSUserDefaults standardUserDefaults] setObject:@[ [NSString stringWithUTF8String:localization] ] forKey:@"AppleLanguages" inDomain:NSArgumentDomain];
+ }
+#endif
+}
+
} // namespace WebKit;
using namespace WebKit;
int main(int argc, char** argv)
{
+ handleXPCBootstrap();
xpc_main(XPCServiceEventHandler);
return 0;
}
Modified: trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.mm (169121 => 169122)
--- trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.mm 2014-05-20 18:07:48 UTC (rev 169121)
+++ trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.mm 2014-05-20 18:44:52 UTC (rev 169122)
@@ -26,6 +26,22 @@
#import <CoreFoundation/CoreFoundation.h>
#import "XPCPtr.h"
+#if __has_include(<Foundation/NSPrivateDecls.h>)
+#import <Foundation/NSPrivateDecls.h>
+#endif
+
+#if __has_include(<xpc/private.h>)
+#import <xpc/private.h>
+#endif
+
+#if PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 10100
+extern "C" xpc_object_t xpc_copy_bootstrap();
+#endif
+
+@interface NSUserDefaults (Details)
+- (void)setObject:(id)value forKey:(NSString *)defaultName inDomain:(NSString *)domain;
+@end
+
namespace WebKit {
static void XPCServiceEventHandler(xpc_connection_t peer)
@@ -68,12 +84,25 @@
xpc_connection_resume(peer);
}
+static void handleXPCBootstrap()
+{
+#if PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 10100
+ auto bootstrapData = IPC::adoptXPC(xpc_copy_bootstrap());
+ const char* localization = xpc_dictionary_get_string(bootstrapData.get(), "localization");
+ if (localization) {
+ // Do this before calling xpc_main(), so that the preference is set before any CFBundle code runs.
+ [[NSUserDefaults standardUserDefaults] setObject:@[ [NSString stringWithUTF8String:localization] ] forKey:@"AppleLanguages" inDomain:NSArgumentDomain];
+ }
+#endif
+}
+
} // namespace WebKit
using namespace WebKit;
int main(int argc, char** argv)
{
+ handleXPCBootstrap();
xpc_main(XPCServiceEventHandler);
return 0;
}
Modified: trunk/Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm (169121 => 169122)
--- trunk/Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm 2014-05-20 18:07:48 UTC (rev 169121)
+++ trunk/Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm 2014-05-20 18:44:52 UTC (rev 169122)
@@ -44,12 +44,20 @@
#import <wtf/text/WTFString.h>
#import <xpc/xpc.h>
+#if __has_include(<xpc/private.h>)
+#import <xpc/private.h>
+#endif
+
// FIXME: We should be doing this another way.
extern "C" kern_return_t bootstrap_register2(mach_port_t, name_t, mach_port_t, uint64_t);
extern "C" void xpc_connection_set_instance(xpc_connection_t, uuid_t);
extern "C" void xpc_dictionary_set_mach_send(xpc_object_t, const char*, mach_port_t);
+#if PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 10100
+extern "C" void xpc_connection_set_bootstrap(xpc_connection_t connection, xpc_object_t bootstrap);
+#endif
+
namespace WebKit {
namespace {
@@ -176,6 +184,20 @@
auto connection = IPC::adoptXPC(xpc_connection_create(serviceName(launchOptions, forDevelopment), 0));
xpc_connection_set_instance(connection.get(), instanceUUID->uuid);
+#if PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 10100
+ // Inherit UI process localization. It can be different from child process default localization:
+ // 1. When the application and system frameworks simply have different localized resources available, we should match the application.
+ // 1.1. An important case is WebKitTestRunner, where we should use English localizations for all system frameworks.
+ // 2. When AppleLanguages is passed as command line argument for UI process, or set in its preferences, we should respect it in child processes.
+ // FIXME: When UI process allows for mixed localizations (CFBundleAllowMixedLocalizations), we should probably send the whole AppleLanguages array.
+ RetainPtr<CFStringRef> localization = adoptCF(WKCopyCFLocalizationPreferredName(0));
+ if (localization) {
+ auto initializationMessage = IPC::adoptXPC(xpc_dictionary_create(nullptr, nullptr, 0));
+ xpc_dictionary_set_string(initializationMessage.get(), "localization", String(localization.get()).ascii().data());
+ xpc_connection_set_bootstrap(connection.get(), initializationMessage.get());
+ }
+#endif
+
// XPC requires having an event handler, even if it is not used.
xpc_connection_set_event_handler(connection.get(), ^(xpc_object_t event) { });
xpc_connection_resume(connection.get());
@@ -199,6 +221,7 @@
NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
CString clientIdentifier = bundleIdentifier ? String([[NSBundle mainBundle] bundleIdentifier]).utf8() : *_NSGetProgname();
+ // FIXME: Switch to xpc_connection_set_bootstrap once it's available everywhere we need.
auto bootstrapMessage = IPC::adoptXPC(xpc_dictionary_create(nullptr, nullptr, 0));
xpc_dictionary_set_string(bootstrapMessage.get(), "message-name", "bootstrap");
xpc_dictionary_set_string(bootstrapMessage.get(), "framework-executable-path", [[[NSBundle bundleWithIdentifier:@"com.apple.WebKit"] executablePath] fileSystemRepresentation]);
Modified: trunk/Tools/ChangeLog (169121 => 169122)
--- trunk/Tools/ChangeLog 2014-05-20 18:07:48 UTC (rev 169121)
+++ trunk/Tools/ChangeLog 2014-05-20 18:44:52 UTC (rev 169122)
@@ -1,3 +1,17 @@
+2014-05-20 Alexey Proskuryakov <[email protected]>
+
+ [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.
+
+ * 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.
+
2014-05-19 David Farler <[email protected]>
Move WebKitTestRunner to std::unique_ptr
Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/mac/InjectedBundleMac.mm (169121 => 169122)
--- trunk/Tools/WebKitTestRunner/InjectedBundle/mac/InjectedBundleMac.mm 2014-05-20 18:07:48 UTC (rev 169121)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/mac/InjectedBundleMac.mm 2014-05-20 18:44:52 UTC (rev 169122)
@@ -54,9 +54,11 @@
@"NSScrollAnimationEnabled": @NO,
@"NSOverlayScrollersEnabled": @NO,
@"AppleShowScrollBars": @"Always",
+#if !PLATFORM(IOS) && __MAC_OS_X_VERSION_MIN_REQUIRED <= 1090
// FIXME (<rdar://problem/13396515>): It is too late to set AppleLanguages here, as loaded frameworks localizations cannot be changed.
// This breaks some accessibility tests on machines with non-English user language.
@"AppleLanguages": @[ @"en" ],
+#endif
// FIXME: Why does this dictionary not match the one in DumpRenderTree?
@"NSTestCorrectionDictionary": @{
@"notationl": @"notational"