Title: [128021] trunk/Source/WebKit2
Revision
128021
Author
[email protected]
Date
2012-09-10 00:05:28 -0700 (Mon, 10 Sep 2012)

Log Message

Simplify WebKit2 XPC service backend now that I know it doesn't need to soft link WebKit2.framework
https://bugs.webkit.org/show_bug.cgi?id=96228

Reviewed by Dan Bernstein.

We soft link the non-XPC service WebProcess backend to the WebKit2 framework to
ensure that we can close all the necessary file descriptors at launch, without
fear that we will be closing one we open while initializing WebKit2 or one of its
dependencies. Since we don't need to close file descriptors in the XPC service 
backend, we don't need to soft link! While here, also do some cleanup and code
sharing.

* UIProcess/Launcher/mac/ProcessLauncherMac.mm:
(WebKit::launchXPCService):
We don't need to send the framework executable path anymore (it was used for the
soft linking), but we do need the client identifier.
        
* WebKit2.xcodeproj/project.pbxproj:
Add new files. Link the XPC service to WebKit2.framework.

* WebKit2Service/MainMacService.mm:
Now that we don't have to soft link, just make this a stub that calls immediately
into the WebKit2 framework.
        
* WebProcess/mac/WebProcessInitialization.h: Added.
* WebProcess/mac/WebProcessInitialization.mm: Added.
(WebKit::InitializeWebProcess):
Move initialization that is common between the XPC and non-XPC backends here.

* WebProcess/mac/WebProcessMainMac.mm:
(WebKit::WebProcessMain):
Remove XPC backend related code. Use new shared InitializeWebProcess function.

* WebProcess/mac/WebProcessXPCServiceMain.h: Added.
* WebProcess/mac/WebProcessXPCServiceMain.mm: Added.
(WebKit::WebKit2ServiceEventHandler):
(WebProcessXPCServiceMain):
Move XPC service backend initialization here.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (128020 => 128021)


--- trunk/Source/WebKit2/ChangeLog	2012-09-10 06:54:43 UTC (rev 128020)
+++ trunk/Source/WebKit2/ChangeLog	2012-09-10 07:05:28 UTC (rev 128021)
@@ -1,3 +1,44 @@
+2012-09-09  Sam Weinig  <[email protected]>
+
+        Simplify WebKit2 XPC service backend now that I know it doesn't need to soft link WebKit2.framework
+        https://bugs.webkit.org/show_bug.cgi?id=96228
+
+        Reviewed by Dan Bernstein.
+
+        We soft link the non-XPC service WebProcess backend to the WebKit2 framework to
+        ensure that we can close all the necessary file descriptors at launch, without
+        fear that we will be closing one we open while initializing WebKit2 or one of its
+        dependencies. Since we don't need to close file descriptors in the XPC service 
+        backend, we don't need to soft link! While here, also do some cleanup and code
+        sharing.
+
+        * UIProcess/Launcher/mac/ProcessLauncherMac.mm:
+        (WebKit::launchXPCService):
+        We don't need to send the framework executable path anymore (it was used for the
+        soft linking), but we do need the client identifier.
+        
+        * WebKit2.xcodeproj/project.pbxproj:
+        Add new files. Link the XPC service to WebKit2.framework.
+
+        * WebKit2Service/MainMacService.mm:
+        Now that we don't have to soft link, just make this a stub that calls immediately
+        into the WebKit2 framework.
+        
+        * WebProcess/mac/WebProcessInitialization.h: Added.
+        * WebProcess/mac/WebProcessInitialization.mm: Added.
+        (WebKit::InitializeWebProcess):
+        Move initialization that is common between the XPC and non-XPC backends here.
+
+        * WebProcess/mac/WebProcessMainMac.mm:
+        (WebKit::WebProcessMain):
+        Remove XPC backend related code. Use new shared InitializeWebProcess function.
+
+        * WebProcess/mac/WebProcessXPCServiceMain.h: Added.
+        * WebProcess/mac/WebProcessXPCServiceMain.mm: Added.
+        (WebKit::WebKit2ServiceEventHandler):
+        (WebProcessXPCServiceMain):
+        Move XPC service backend initialization here.
+
 2012-09-09  Emil A Eklund  <[email protected]>
 
         Rename Node::getRect/getPixelSnappedRect and remove ContainerNode::getRect

Modified: trunk/Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm (128020 => 128021)


--- trunk/Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm	2012-09-10 06:54:43 UTC (rev 128020)
+++ trunk/Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm	2012-09-10 07:05:28 UTC (rev 128021)
@@ -105,10 +105,13 @@
     // Insert a send right so we can send to it.
     mach_port_insert_right(mach_task_self(), listeningPort, listeningPort, MACH_MSG_TYPE_MAKE_SEND);
 
+    NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
+    CString clientIdentifier = bundleIdentifier ? String([[NSBundle mainBundle] bundleIdentifier]).utf8() : *_NSGetProgname();
+
     xpc_object_t bootStrapMessage = xpc_dictionary_create(0, 0, 0);
     xpc_dictionary_set_string(bootStrapMessage, "message-name", "bootstrap");
-    xpc_dictionary_set_string(bootStrapMessage, "framework-executable-path", [[[NSBundle bundleWithIdentifier:@"com.apple.WebKit2"] executablePath] fileSystemRepresentation]);
     xpc_dictionary_set_mach_send(bootStrapMessage, "server-port", listeningPort);
+    xpc_dictionary_set_string(bootStrapMessage, "client-identifier", clientIdentifier.data());
 
     that->ref();
 

Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (128020 => 128021)


--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2012-09-10 06:54:43 UTC (rev 128020)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2012-09-10 07:05:28 UTC (rev 128021)
@@ -581,7 +581,6 @@
 		BC33DD681238464600360F3F /* WebNumber.h in Headers */ = {isa = PBXBuildFile; fileRef = BC33DD671238464600360F3F /* WebNumber.h */; };
 		BC33E0D112408E8600360F3F /* InjectedBundleRangeHandle.h in Headers */ = {isa = PBXBuildFile; fileRef = BC33E0CF12408E8600360F3F /* InjectedBundleRangeHandle.h */; };
 		BC33E0D212408E8600360F3F /* InjectedBundleRangeHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC33E0D012408E8600360F3F /* InjectedBundleRangeHandle.cpp */; };
-		BC3DE46915A91763008D26FC /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BC3DE46815A91763008D26FC /* Foundation.framework */; };
 		BC3DE47215A91764008D26FC /* MainMacService.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC3DE47115A91764008D26FC /* MainMacService.mm */; };
 		BC4075F3124FF0270068F20A /* WKArray.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC4075D7124FF0270068F20A /* WKArray.cpp */; };
 		BC4075F4124FF0270068F20A /* WKArray.h in Headers */ = {isa = PBXBuildFile; fileRef = BC4075D8124FF0270068F20A /* WKArray.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -796,6 +795,11 @@
 		BCD598AC112B7FDF00EC8C23 /* WebPreferencesStore.h in Headers */ = {isa = PBXBuildFile; fileRef = BCD598AA112B7FDF00EC8C23 /* WebPreferencesStore.h */; };
 		BCD598AD112B7FDF00EC8C23 /* WebPreferencesStore.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCD598AB112B7FDF00EC8C23 /* WebPreferencesStore.cpp */; };
 		BCDB86C11200FB97007254BE /* WebURL.h in Headers */ = {isa = PBXBuildFile; fileRef = BCDB86C01200FB97007254BE /* WebURL.h */; };
+		BCDC308715FD6A8B006B6695 /* WebProcessInitialization.mm in Sources */ = {isa = PBXBuildFile; fileRef = BCDC308515FD6A8B006B6695 /* WebProcessInitialization.mm */; };
+		BCDC308815FD6A8B006B6695 /* WebProcessInitialization.h in Headers */ = {isa = PBXBuildFile; fileRef = BCDC308615FD6A8B006B6695 /* WebProcessInitialization.h */; };
+		BCDC308B15FD6CD1006B6695 /* WebProcessXPCServiceMain.mm in Sources */ = {isa = PBXBuildFile; fileRef = BCDC308915FD6CD1006B6695 /* WebProcessXPCServiceMain.mm */; };
+		BCDC308C15FD6CD1006B6695 /* WebProcessXPCServiceMain.h in Headers */ = {isa = PBXBuildFile; fileRef = BCDC308A15FD6CD1006B6695 /* WebProcessXPCServiceMain.h */; };
+		BCDC308E15FDB9A7006B6695 /* WebKit2.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* WebKit2.framework */; };
 		BCDDB317124EBD130048D13C /* WKBase.h in Headers */ = {isa = PBXBuildFile; fileRef = BCDDB316124EBD130048D13C /* WKBase.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		BCDDB32B124EC2AB0048D13C /* WKSharedAPICast.h in Headers */ = {isa = PBXBuildFile; fileRef = BCDDB32A124EC2AB0048D13C /* WKSharedAPICast.h */; };
 		BCDDB32D124EC2E10048D13C /* WKAPICast.h in Headers */ = {isa = PBXBuildFile; fileRef = BCDDB32C124EC2E10048D13C /* WKAPICast.h */; };
@@ -1873,6 +1877,10 @@
 		BCD598AA112B7FDF00EC8C23 /* WebPreferencesStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebPreferencesStore.h; sourceTree = "<group>"; };
 		BCD598AB112B7FDF00EC8C23 /* WebPreferencesStore.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebPreferencesStore.cpp; sourceTree = "<group>"; };
 		BCDB86C01200FB97007254BE /* WebURL.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebURL.h; sourceTree = "<group>"; };
+		BCDC308515FD6A8B006B6695 /* WebProcessInitialization.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebProcessInitialization.mm; sourceTree = "<group>"; };
+		BCDC308615FD6A8B006B6695 /* WebProcessInitialization.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebProcessInitialization.h; sourceTree = "<group>"; };
+		BCDC308915FD6CD1006B6695 /* WebProcessXPCServiceMain.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebProcessXPCServiceMain.mm; sourceTree = "<group>"; };
+		BCDC308A15FD6CD1006B6695 /* WebProcessXPCServiceMain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebProcessXPCServiceMain.h; sourceTree = "<group>"; };
 		BCDDB316124EBD130048D13C /* WKBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKBase.h; sourceTree = "<group>"; };
 		BCDDB32A124EC2AB0048D13C /* WKSharedAPICast.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKSharedAPICast.h; sourceTree = "<group>"; };
 		BCDDB32C124EC2E10048D13C /* WKAPICast.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKAPICast.h; sourceTree = "<group>"; };
@@ -2063,11 +2071,11 @@
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
-		BC3DE46315A91763008D26FC /* Frameworks */ = {
+		BCDC308D15FDB99A006B6695 /* Frameworks */ = {
 			isa = PBXFrameworksBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
-				BC3DE46915A91763008D26FC /* Foundation.framework in Frameworks */,
+				BCDC308E15FDB9A7006B6695 /* WebKit2.framework in Frameworks */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -2264,10 +2272,14 @@
 				512DF6D7138C181A00A22FC6 /* KeychainItemShimMethods.mm */,
 				511F8A7D138B46FE00A95F44 /* SecItemShimMethods.h */,
 				511F8A7E138B46FE00A95F44 /* SecItemShimMethods.mm */,
+				BCDC308615FD6A8B006B6695 /* WebProcessInitialization.h */,
+				BCDC308515FD6A8B006B6695 /* WebProcessInitialization.mm */,
 				BC3065C312592F8900E71278 /* WebProcessMac.mm */,
 				1A6FA01D11E1526300DB1371 /* WebProcessMainMac.mm */,
 				511F8A77138B460900A95F44 /* WebProcessShim.h */,
 				511F8A78138B460900A95F44 /* WebProcessShim.mm */,
+				BCDC308A15FD6CD1006B6695 /* WebProcessXPCServiceMain.h */,
+				BCDC308915FD6CD1006B6695 /* WebProcessXPCServiceMain.mm */,
 			);
 			path = mac;
 			sourceTree = "<group>";
@@ -4239,6 +4251,8 @@
 				3F87B9BE158940190090FF62 /* WebColorChooser.h in Headers */,
 				3F87B9C0158940D80090FF62 /* WebColorChooserProxy.h in Headers */,
 				BC59548915C7868500FD1E3E /* WebKit2.h in Headers */,
+				BCDC308815FD6A8B006B6695 /* WebProcessInitialization.h in Headers */,
+				BCDC308C15FD6CD1006B6695 /* WebProcessXPCServiceMain.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -4331,7 +4345,7 @@
 			buildConfigurationList = BC3DE47615A91764008D26FC /* Build configuration list for PBXNativeTarget "WebKit2Service" */;
 			buildPhases = (
 				BC3DE46215A91763008D26FC /* Sources */,
-				BC3DE46315A91763008D26FC /* Frameworks */,
+				BCDC308D15FDB99A006B6695 /* Frameworks */,
 				BC3DE46415A91763008D26FC /* Resources */,
 			);
 			buildRules = (
@@ -5029,6 +5043,8 @@
 				1A2A4B0E1586A2240090C9E9 /* ColorSpaceData.mm in Sources */,
 				3F87B9BD158940120090FF62 /* WebColorChooser.cpp in Sources */,
 				CD67D30E15C08F9A00843ADF /* InjectedBundlePageDiagnosticLoggingClient.cpp in Sources */,
+				BCDC308715FD6A8B006B6695 /* WebProcessInitialization.mm in Sources */,
+				BCDC308B15FD6CD1006B6695 /* WebProcessXPCServiceMain.mm in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: trunk/Source/WebKit2/WebKit2Service/MainMacService.mm (128020 => 128021)


--- trunk/Source/WebKit2/WebKit2Service/MainMacService.mm	2012-09-10 06:54:43 UTC (rev 128020)
+++ trunk/Source/WebKit2/WebKit2Service/MainMacService.mm	2012-09-10 07:05:28 UTC (rev 128021)
@@ -23,61 +23,15 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <AvailabilityMacros.h>
+#import <AvailabilityMacros.h>
 
 #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 
-#include <dlfcn.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <xpc/xpc.h>
+#import "WebProcessXPCServiceMain.h"
 
-extern "C" mach_port_t xpc_dictionary_copy_mach_send(xpc_object_t, const char*);
-
-static void WebKit2ServiceEventHandler(xpc_connection_t peer)
-{
-    xpc_connection_set_target_queue(peer, dispatch_get_main_queue());
-    xpc_connection_set_event_handler(peer, ^(xpc_object_t event) {
-        xpc_type_t type = xpc_get_type(event);
-        if (type == XPC_TYPE_ERROR) {
-            if (event == XPC_ERROR_CONNECTION_INVALID || event == XPC_ERROR_TERMINATION_IMMINENT) {
-                // FIXME: Handle this case more gracefully.
-                exit(EXIT_FAILURE);
-            }
-        } else {
-            assert(type == XPC_TYPE_DICTIONARY);
-
-            if (!strcmp(xpc_dictionary_get_string(event, "message-name"), "bootstrap")) {
-                static void* frameworkLibrary = dlopen(xpc_dictionary_get_string(event, "framework-executable-path"), RTLD_NOW);
-                if (!frameworkLibrary) {
-                    NSLog(@"Unable to load WebKit2.framework: %s\n", dlerror());
-                    exit(EXIT_FAILURE);
-                }
-
-                typedef int (*WebKitMainFunction)(xpc_connection_t connection, mach_port_t serverPort);
-                WebKitMainFunction webKitMainXPC = reinterpret_cast<WebKitMainFunction>(dlsym(frameworkLibrary, "WebKitMainXPC"));
-                if (!webKitMainXPC) {
-                    NSLog(@"Unable to find entry point in WebKit2.framework: %s\n", dlerror());
-                    exit(EXIT_FAILURE);
-                }
-
-                xpc_object_t reply = xpc_dictionary_create_reply(event);
-                xpc_dictionary_set_string(reply, "message-name", "process-finished-launching");
-                xpc_connection_send_message(xpc_dictionary_get_remote_connection(event), reply);
-                xpc_release(reply);
-
-                webKitMainXPC(peer, xpc_dictionary_copy_mach_send(event, "server-port"));
-            }
-        }
-    });
-
-    xpc_connection_resume(peer);
-}
-
 int main(int argc, char** argv)
 {
-    xpc_main(WebKit2ServiceEventHandler);
-    return 0;
+    return WebProcessXPCServiceMain(argc, argv);
 }
 
 #else

Added: trunk/Source/WebKit2/WebProcess/mac/WebProcessInitialization.h (0 => 128021)


--- trunk/Source/WebKit2/WebProcess/mac/WebProcessInitialization.h	                        (rev 0)
+++ trunk/Source/WebKit2/WebProcess/mac/WebProcessInitialization.h	2012-09-10 07:05:28 UTC (rev 128021)
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebProcessInitialization_h
+#define WebProcessInitialization_h
+
+#include "Connection.h"
+
+namespace WebKit {
+
+void InitializeWebProcess(const String& clientIdentifier, CoreIPC::Connection::Identifier connectionIdentifier);
+
+} // namespace WebKit
+
+#endif // WebProcessInitialization_h

Added: trunk/Source/WebKit2/WebProcess/mac/WebProcessInitialization.mm (0 => 128021)


--- trunk/Source/WebKit2/WebProcess/mac/WebProcessInitialization.mm	                        (rev 0)
+++ trunk/Source/WebKit2/WebProcess/mac/WebProcessInitialization.mm	2012-09-10 07:05:28 UTC (rev 128021)
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "WebProcessInitialization.h"
+
+#import "WebProcess.h"
+#import "WebSystemInterface.h"
+#import <WebCore/RunLoop.h>
+#import <WebKitSystemInterface.h>
+#import <runtime/InitializeThreading.h>
+#import <wtf/MainThread.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+void InitializeWebProcess(const String& clientIdentifier, CoreIPC::Connection::Identifier connectionIdentifier)
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+    InitWebCoreSystemInterface();
+    JSC::initializeThreading();
+    WTF::initializeMainThread();
+    RunLoop::initializeMainRunLoop();
+
+    WebProcess::shared().initializeShim();
+    WebProcess::shared().initializeSandbox(clientIdentifier);
+    WebProcess::shared().initialize(connectionIdentifier, RunLoop::main());
+
+    WKAXRegisterRemoteApp();
+
+    [pool drain];
+}
+
+} // namespace WebKit

Modified: trunk/Source/WebKit2/WebProcess/mac/WebProcessMainMac.mm (128020 => 128021)


--- trunk/Source/WebKit2/WebProcess/mac/WebProcessMainMac.mm	2012-09-10 06:54:43 UTC (rev 128020)
+++ trunk/Source/WebKit2/WebProcess/mac/WebProcessMainMac.mm	2012-09-10 07:05:28 UTC (rev 128021)
@@ -31,27 +31,21 @@
 #import "EnvironmentVariables.h"
 #import "StringUtilities.h"
 #import "WebProcess.h"
-#import "WebSystemInterface.h"
+#import "WebProcessInitialization.h"
 #import <WebCore/RunLoop.h>
 #import <WebKitSystemInterface.h>
 #import <mach/mach_error.h>
 #import <objc/objc-auto.h>
-#import <runtime/InitializeThreading.h>
 #import <servers/bootstrap.h>
 #import <signal.h>
 #import <spawn.h>
 #import <stdio.h>
 #import <sysexits.h>
 #import <unistd.h>
-#import <wtf/MainThread.h>
 #import <wtf/RetainPtr.h>
 #import <wtf/text/CString.h>
-#import <wtf/text/StringBuilder.h>
+#import <wtf/text/WTFString.h>
 
-#if HAVE(XPC)
-#import <xpc/xpc.h>
-#endif
-
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 extern "C" kern_return_t bootstrap_register2(mach_port_t, name_t, mach_port_t, uint64_t);
 #endif
@@ -66,48 +60,8 @@
 
 using namespace WebCore;
 
-#if HAVE(XPC)
 namespace WebKit {
-int WebProcessMainXPC(xpc_connection_t xpcConnection, mach_port_t serverPort);
-}
 
-extern "C" WK_EXPORT int WebKitMainXPC(xpc_connection_t xpcConnection, mach_port_t serverPort);
-
-int WebKitMainXPC(xpc_connection_t xpcConnection, mach_port_t serverPort)
-{
-    ASSERT(!objc_collectingEnabled());
-
-    return WebKit::WebProcessMainXPC(xpcConnection, serverPort);
-}
-#endif
-
-namespace WebKit {
-
-#if HAVE(XPC)
-
-int WebProcessMainXPC(xpc_connection_t xpcConnection, mach_port_t serverPort)
-{
-    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
-    InitWebCoreSystemInterface();
-    JSC::initializeThreading();
-    WTF::initializeMainThread();
-    RunLoop::initializeMainRunLoop();
-
-    // FIXME: Make the shim work.
-    WebProcess::shared().initializeShim();
-    // FIXME: Pass the client identifier here.
-    WebProcess::shared().initializeSandbox(String());
-    WebProcess::shared().initialize(CoreIPC::Connection::Identifier(serverPort, xpcConnection), RunLoop::main());
-
-    WKAXRegisterRemoteApp();
-
-    [pool drain];
-
-    return 0;
-}
-#endif
-
 int WebProcessMain(const CommandLine& commandLine)
 {
     // Remove the WebProcess shim from the DYLD_INSERT_LIBRARIES environment variable so any processes spawned by
@@ -211,6 +165,8 @@
     if (cfLocalization)
         WKSetDefaultLocalization(cfLocalization.get());
 
+    [pool drain];
+
 #if !SHOW_CRASH_REPORTER
     // Installs signal handlers that exit on a crash so that CrashReporter does not show up.
     signal(SIGILL, _exit);
@@ -219,11 +175,6 @@
     signal(SIGSEGV, _exit);
 #endif
 
-    InitWebCoreSystemInterface();
-    JSC::initializeThreading();
-    WTF::initializeMainThread();
-    RunLoop::initializeMainRunLoop();
-
 #if USE(APPKIT)
      // Initialize AppKit.
     [NSApplication sharedApplication];
@@ -233,14 +184,8 @@
     [[NSApplication sharedApplication] _installAutoreleasePoolsOnCurrentThreadIfNecessary];
 #endif
 
-    WebProcess::shared().initializeShim();
-    WebProcess::shared().initializeSandbox(clientIdentifier);
-    WebProcess::shared().initialize(CoreIPC::Connection::Identifier(serverPort), RunLoop::main());
+    InitializeWebProcess(clientIdentifier, CoreIPC::Connection::Identifier(serverPort));
 
-    WKAXRegisterRemoteApp();
-
-    [pool drain];
-
     RunLoop::run();
 
     // FIXME: Do more cleanup here.

Added: trunk/Source/WebKit2/WebProcess/mac/WebProcessXPCServiceMain.h (0 => 128021)


--- trunk/Source/WebKit2/WebProcess/mac/WebProcessXPCServiceMain.h	                        (rev 0)
+++ trunk/Source/WebKit2/WebProcess/mac/WebProcessXPCServiceMain.h	2012-09-10 07:05:28 UTC (rev 128021)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebProcessXPCServiceMain_h
+#define WebProcessXPCServiceMain_h
+
+#if HAVE(XPC)
+
+#include "WKBase.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+WK_EXPORT int WebProcessXPCServiceMain(int argc, char** argv);
+
+#ifdef __cplusplus
+}; // extern "C"
+#endif
+
+#endif // HAVE(XPC)
+
+#endif // WebProcessXPCServiceMain_h

Added: trunk/Source/WebKit2/WebProcess/mac/WebProcessXPCServiceMain.mm (0 => 128021)


--- trunk/Source/WebKit2/WebProcess/mac/WebProcessXPCServiceMain.mm	                        (rev 0)
+++ trunk/Source/WebKit2/WebProcess/mac/WebProcessXPCServiceMain.mm	2012-09-10 07:05:28 UTC (rev 128021)
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "WebProcessXPCServiceMain.h"
+
+#if HAVE(XPC)
+
+#import "EnvironmentUtilities.h"
+#import "WebProcessInitialization.h"
+#import <stdio.h>
+#import <stdlib.h>
+#import <xpc/xpc.h>
+
+extern "C" mach_port_t xpc_dictionary_copy_mach_send(xpc_object_t, const char*);
+
+namespace WebKit {
+
+static void WebKit2ServiceEventHandler(xpc_connection_t peer)
+{
+    xpc_connection_set_target_queue(peer, dispatch_get_main_queue());
+    xpc_connection_set_event_handler(peer, ^(xpc_object_t event) {
+        xpc_type_t type = xpc_get_type(event);
+        if (type == XPC_TYPE_ERROR) {
+            if (event == XPC_ERROR_CONNECTION_INVALID || event == XPC_ERROR_TERMINATION_IMMINENT) {
+                // FIXME: Handle this case more gracefully.
+                exit(EXIT_FAILURE);
+            }
+        } else {
+            ASSERT(type == XPC_TYPE_DICTIONARY);
+
+            if (!strcmp(xpc_dictionary_get_string(event, "message-name"), "bootstrap")) {
+                xpc_object_t reply = xpc_dictionary_create_reply(event);
+                xpc_dictionary_set_string(reply, "message-name", "process-finished-launching");
+                xpc_connection_send_message(xpc_dictionary_get_remote_connection(event), reply);
+                xpc_release(reply);
+
+                InitializeWebProcess(String(xpc_dictionary_get_string(event, "client-identifier")), CoreIPC::Connection::Identifier(xpc_dictionary_copy_mach_send(event, "server-port"), peer));
+            }
+        }
+    });
+
+    xpc_connection_resume(peer);
+}
+
+} // namespace WebKit
+
+int WebProcessXPCServiceMain(int argc, char** argv)
+{
+    // Remove the WebProcess shim from the DYLD_INSERT_LIBRARIES environment variable so any processes spawned by
+    // the WebProcess don't try to insert the shim and crash.
+    WebKit::EnvironmentUtilities::stripValuesEndingWithString("DYLD_INSERT_LIBRARIES", "/WebProcessShim.dylib");
+
+    xpc_main(WebKit::WebKit2ServiceEventHandler);
+    return 0;
+}
+
+#endif // HAVE(XPC)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to