<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[169122] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/169122">169122</a></dd>
<dt>Author</dt> <dd>ap@apple.com</dd>
<dt>Date</dt> <dd>2014-05-20 11:44:52 -0700 (Tue, 20 May 2014)</dd>
</dl>

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

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.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2SharedEntryPointUtilitiesmacXPCServiceXPCServiceMainDevelopmentmm">trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.Development.mm</a></li>
<li><a href="#trunkSourceWebKit2SharedEntryPointUtilitiesmacXPCServiceXPCServiceMainmm">trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessLaunchermacProcessLauncherMacmm">trunk/Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsWebKitTestRunnerInjectedBundlemacInjectedBundleMacmm">trunk/Tools/WebKitTestRunner/InjectedBundle/mac/InjectedBundleMac.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (169121 => 169122)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,25 @@
</span><ins>+2014-05-20  Alexey Proskuryakov  &lt;ap@apple.com&gt;
+
+        [Mac] WebProcess doesn't follow localization of UI process when run as a service
+        https://bugs.webkit.org/show_bug.cgi?id=133126
+        &lt;rdar://problem/13396515&gt;
+        &lt;rdar://problem/16561084&gt;
+
+        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.
+
</ins><span class="cx"> 2014-05-20  Anders Carlsson  &lt;andersca@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Fix a header comment
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedEntryPointUtilitiesmacXPCServiceXPCServiceMainDevelopmentmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.Development.mm (169121 => 169122)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -31,6 +31,22 @@
</span><span class="cx"> #import &lt;stdlib.h&gt;
</span><span class="cx"> #import &quot;XPCPtr.h&quot;
</span><span class="cx"> 
</span><ins>+#if __has_include(&lt;Foundation/NSPrivateDecls.h&gt;)
+#import &lt;Foundation/NSPrivateDecls.h&gt;
+#endif
+
+#if __has_include(&lt;xpc/private.h&gt;)
+#import &lt;xpc/private.h&gt;
+#endif
+
+#if PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED &gt;= 10100
+extern &quot;C&quot; xpc_object_t xpc_copy_bootstrap();
+#endif
+
+@interface NSUserDefaults (Details)
+- (void)setObject:(id)value forKey:(NSString *)defaultName inDomain:(NSString *)domain;
+@end
+
</ins><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><span class="cx"> struct ReexecInfo {
</span><span class="lines">@@ -155,12 +171,25 @@
</span><span class="cx">     xpc_connection_resume(peer);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static void handleXPCBootstrap()
+{
+#if PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED &gt;= 10100
+    auto bootstrapData = IPC::adoptXPC(xpc_copy_bootstrap());
+    const char* localization = xpc_dictionary_get_string(bootstrapData.get(), &quot;localization&quot;);
+    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:@&quot;AppleLanguages&quot; inDomain:NSArgumentDomain];
+    }
+#endif
+}
+
</ins><span class="cx"> } // namespace WebKit;
</span><span class="cx"> 
</span><span class="cx"> using namespace WebKit;
</span><span class="cx"> 
</span><span class="cx"> int main(int argc, char** argv)
</span><span class="cx"> {
</span><ins>+    handleXPCBootstrap();
</ins><span class="cx">     xpc_main(XPCServiceEventHandler);
</span><span class="cx">     return 0;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedEntryPointUtilitiesmacXPCServiceXPCServiceMainmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.mm (169121 => 169122)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -26,6 +26,22 @@
</span><span class="cx"> #import &lt;CoreFoundation/CoreFoundation.h&gt;
</span><span class="cx"> #import &quot;XPCPtr.h&quot;
</span><span class="cx"> 
</span><ins>+#if __has_include(&lt;Foundation/NSPrivateDecls.h&gt;)
+#import &lt;Foundation/NSPrivateDecls.h&gt;
+#endif
+
+#if __has_include(&lt;xpc/private.h&gt;)
+#import &lt;xpc/private.h&gt;
+#endif
+
+#if PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED &gt;= 10100
+extern &quot;C&quot; xpc_object_t xpc_copy_bootstrap();
+#endif
+
+@interface NSUserDefaults (Details)
+- (void)setObject:(id)value forKey:(NSString *)defaultName inDomain:(NSString *)domain;
+@end
+
</ins><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><span class="cx"> static void XPCServiceEventHandler(xpc_connection_t peer)
</span><span class="lines">@@ -68,12 +84,25 @@
</span><span class="cx">     xpc_connection_resume(peer);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static void handleXPCBootstrap()
+{
+#if PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED &gt;= 10100
+    auto bootstrapData = IPC::adoptXPC(xpc_copy_bootstrap());
+    const char* localization = xpc_dictionary_get_string(bootstrapData.get(), &quot;localization&quot;);
+    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:@&quot;AppleLanguages&quot; inDomain:NSArgumentDomain];
+    }
+#endif
+}
+
</ins><span class="cx"> } // namespace WebKit
</span><span class="cx"> 
</span><span class="cx"> using namespace WebKit;
</span><span class="cx"> 
</span><span class="cx"> int main(int argc, char** argv)
</span><span class="cx"> {
</span><ins>+    handleXPCBootstrap();
</ins><span class="cx">     xpc_main(XPCServiceEventHandler);
</span><span class="cx">     return 0;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessLaunchermacProcessLauncherMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm (169121 => 169122)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -44,12 +44,20 @@
</span><span class="cx"> #import &lt;wtf/text/WTFString.h&gt;
</span><span class="cx"> #import &lt;xpc/xpc.h&gt;
</span><span class="cx"> 
</span><ins>+#if __has_include(&lt;xpc/private.h&gt;)
+#import &lt;xpc/private.h&gt;
+#endif
+
</ins><span class="cx"> // FIXME: We should be doing this another way.
</span><span class="cx"> extern &quot;C&quot; kern_return_t bootstrap_register2(mach_port_t, name_t, mach_port_t, uint64_t);
</span><span class="cx"> 
</span><span class="cx"> extern &quot;C&quot; void xpc_connection_set_instance(xpc_connection_t, uuid_t);
</span><span class="cx"> extern &quot;C&quot; void xpc_dictionary_set_mach_send(xpc_object_t, const char*, mach_port_t);
</span><span class="cx"> 
</span><ins>+#if PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED &gt;= 10100
+extern &quot;C&quot; void xpc_connection_set_bootstrap(xpc_connection_t connection, xpc_object_t bootstrap);
+#endif
+
</ins><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><span class="cx"> namespace {
</span><span class="lines">@@ -176,6 +184,20 @@
</span><span class="cx">     auto connection = IPC::adoptXPC(xpc_connection_create(serviceName(launchOptions, forDevelopment), 0));
</span><span class="cx">     xpc_connection_set_instance(connection.get(), instanceUUID-&gt;uuid);
</span><span class="cx"> 
</span><ins>+#if PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED &gt;= 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&lt;CFStringRef&gt; localization = adoptCF(WKCopyCFLocalizationPreferredName(0));
+    if (localization) {
+        auto initializationMessage = IPC::adoptXPC(xpc_dictionary_create(nullptr, nullptr, 0));
+        xpc_dictionary_set_string(initializationMessage.get(), &quot;localization&quot;, String(localization.get()).ascii().data());
+        xpc_connection_set_bootstrap(connection.get(), initializationMessage.get());
+    }
+#endif
+
</ins><span class="cx">     // XPC requires having an event handler, even if it is not used.
</span><span class="cx">     xpc_connection_set_event_handler(connection.get(), ^(xpc_object_t event) { });
</span><span class="cx">     xpc_connection_resume(connection.get());
</span><span class="lines">@@ -199,6 +221,7 @@
</span><span class="cx">     NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
</span><span class="cx">     CString clientIdentifier = bundleIdentifier ? String([[NSBundle mainBundle] bundleIdentifier]).utf8() : *_NSGetProgname();
</span><span class="cx"> 
</span><ins>+    // FIXME: Switch to xpc_connection_set_bootstrap once it's available everywhere we need.
</ins><span class="cx">     auto bootstrapMessage = IPC::adoptXPC(xpc_dictionary_create(nullptr, nullptr, 0));
</span><span class="cx">     xpc_dictionary_set_string(bootstrapMessage.get(), &quot;message-name&quot;, &quot;bootstrap&quot;);
</span><span class="cx">     xpc_dictionary_set_string(bootstrapMessage.get(), &quot;framework-executable-path&quot;, [[[NSBundle bundleWithIdentifier:@&quot;com.apple.WebKit&quot;] executablePath] fileSystemRepresentation]);
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (169121 => 169122)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2014-05-20 18:07:48 UTC (rev 169121)
+++ trunk/Tools/ChangeLog        2014-05-20 18:44:52 UTC (rev 169122)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2014-05-20  Alexey Proskuryakov  &lt;ap@apple.com&gt;
+
+        [Mac] WebProcess doesn't follow localization of UI process when run as a service
+        https://bugs.webkit.org/show_bug.cgi?id=133126
+        &lt;rdar://problem/13396515&gt;
+        &lt;rdar://problem/16561084&gt;
+
+        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.
+
</ins><span class="cx"> 2014-05-19  David Farler  &lt;dfarler@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Move WebKitTestRunner to std::unique_ptr
</span></span></pre></div>
<a id="trunkToolsWebKitTestRunnerInjectedBundlemacInjectedBundleMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/mac/InjectedBundleMac.mm (169121 => 169122)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -54,9 +54,11 @@
</span><span class="cx">         @&quot;NSScrollAnimationEnabled&quot;: @NO,
</span><span class="cx">         @&quot;NSOverlayScrollersEnabled&quot;: @NO,
</span><span class="cx">         @&quot;AppleShowScrollBars&quot;: @&quot;Always&quot;,
</span><ins>+#if !PLATFORM(IOS) &amp;&amp; __MAC_OS_X_VERSION_MIN_REQUIRED &lt;= 1090
</ins><span class="cx">         // FIXME (&lt;rdar://problem/13396515&gt;): It is too late to set AppleLanguages here, as loaded frameworks localizations cannot be changed.
</span><span class="cx">         // This breaks some accessibility tests on machines with non-English user language.
</span><span class="cx">         @&quot;AppleLanguages&quot;: @[ @&quot;en&quot; ],
</span><ins>+#endif
</ins><span class="cx">         // FIXME: Why does this dictionary not match the one in DumpRenderTree?
</span><span class="cx">         @&quot;NSTestCorrectionDictionary&quot;: @{
</span><span class="cx">             @&quot;notationl&quot;: @&quot;notational&quot;
</span></span></pre>
</div>
</div>

</body>
</html>