Title: [140919] trunk/Source/WebKit2
Revision
140919
Author
[email protected]
Date
2013-01-26 16:40:16 -0800 (Sat, 26 Jan 2013)

Log Message

Refactor XPCService initialization to make it easier to add more services
https://bugs.webkit.org/show_bug.cgi?id=108015

Reviewed by Dan Bernstein.

* Shared/EntryPointUtilities/mac/XPCService/XPCServiceBootstrapper.Development.h: Added.
(WebKit::XPCServiceEventHandler):
* Shared/EntryPointUtilities/mac/XPCService/XPCServiceBootstrapper.h: Added.
(WebKit::XPCServiceEventHandler):
Move bootstrapping to Shared (like we have for the legacy process). For now, we use
a macro to define the actual initialization point function to use, in the future, we
could consider alternatives, such as getting the function name from the bundle.

* WebKit2.xcodeproj/project.pbxproj:
Update files.

* WebProcess/EntryPoint/mac/XPCService/WebContentService.Development/WebContentServiceMain.Development.mm:
* WebProcess/EntryPoint/mac/XPCService/WebContentService/WebContentServiceMain.mm:
Simplify to use the new XPCServiceBootstrapper.

* WebProcess/EntryPoint/mac/XPCService/WebContentServiceEntryPoint.mm: Copied from Source/WebKit2/WebProcess/mac/WebProcessServiceEntryPoints.mm.
(initializeWebContentService):
* WebProcess/mac/WebProcessServiceEntryPoints.h: Removed.
* WebProcess/mac/WebProcessServiceEntryPoints.mm: Removed.
Move the entry point to where it belongs and extract the bootstrapping parts.

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (140918 => 140919)


--- trunk/Source/WebKit2/ChangeLog	2013-01-27 00:09:39 UTC (rev 140918)
+++ trunk/Source/WebKit2/ChangeLog	2013-01-27 00:40:16 UTC (rev 140919)
@@ -1,3 +1,31 @@
+2013-01-26  Sam Weinig  <[email protected]>
+
+        Refactor XPCService initialization to make it easier to add more services
+        https://bugs.webkit.org/show_bug.cgi?id=108015
+
+        Reviewed by Dan Bernstein.
+
+        * Shared/EntryPointUtilities/mac/XPCService/XPCServiceBootstrapper.Development.h: Added.
+        (WebKit::XPCServiceEventHandler):
+        * Shared/EntryPointUtilities/mac/XPCService/XPCServiceBootstrapper.h: Added.
+        (WebKit::XPCServiceEventHandler):
+        Move bootstrapping to Shared (like we have for the legacy process). For now, we use
+        a macro to define the actual initialization point function to use, in the future, we
+        could consider alternatives, such as getting the function name from the bundle.
+
+        * WebKit2.xcodeproj/project.pbxproj:
+        Update files.
+
+        * WebProcess/EntryPoint/mac/XPCService/WebContentService.Development/WebContentServiceMain.Development.mm:
+        * WebProcess/EntryPoint/mac/XPCService/WebContentService/WebContentServiceMain.mm:
+        Simplify to use the new XPCServiceBootstrapper.
+
+        * WebProcess/EntryPoint/mac/XPCService/WebContentServiceEntryPoint.mm: Copied from Source/WebKit2/WebProcess/mac/WebProcessServiceEntryPoints.mm.
+        (initializeWebContentService):
+        * WebProcess/mac/WebProcessServiceEntryPoints.h: Removed.
+        * WebProcess/mac/WebProcessServiceEntryPoints.mm: Removed.
+        Move the entry point to where it belongs and extract the bootstrapping parts.
+
 2013-01-26  Adenilson Cavalcanti  <[email protected]>
 
         [Qt]Qt build fix

Added: trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceBootstrapper.Development.h (0 => 140919)


--- trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceBootstrapper.Development.h	                        (rev 0)
+++ trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceBootstrapper.Development.h	2013-01-27 00:40:16 UTC (rev 140919)
@@ -0,0 +1,158 @@
+/*
+ * Copyright (C) 2013 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 XPCServiceBootstrapper_Development_h
+#define XPCServiceBootstrapper_Development_h
+
+#if !defined(WEBKIT_XPC_SERVICE_INITIALIZER)
+#error WEBKIT_XPC_SERVICE_INITIALIZER must be defined.
+#endif
+
+#import <AvailabilityMacros.h>
+#import <crt_externs.h>
+#import <dlfcn.h>
+#import <mach-o/dyld.h>
+#import <spawn.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*);
+
+#define STRINGIZE(exp) #exp
+#define STRINGIZE_VALUE_OF(exp) STRINGIZE(exp)
+
+namespace WebKit {
+
+static void XPCServiceEventHandler(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"), "re-exec")) {
+                posix_spawnattr_t attr;
+                posix_spawnattr_init(&attr);
+
+                short flags = 0;
+
+                // We just want to set the process state, not actually launch a new process,
+                // so we are going to use the darwin extension to posix_spawn POSIX_SPAWN_SETEXEC
+                // to act like a more full featured exec.
+                flags |= POSIX_SPAWN_SETEXEC;
+
+                sigset_t signalMaskSet;
+                sigemptyset(&signalMaskSet);
+                posix_spawnattr_setsigmask(&attr, &signalMaskSet);
+                flags |= POSIX_SPAWN_SETSIGMASK;
+
+                static const int allowExecutableHeapFlag = 0x2000;
+                if (xpc_dictionary_get_bool(event, "executable-heap"))
+                    flags |= allowExecutableHeapFlag;
+
+                posix_spawnattr_setflags(&attr, flags);
+
+                cpu_type_t cpuTypes[] = { (cpu_type_t)xpc_dictionary_get_uint64(event, "architecture") };
+                size_t outCount = 0;
+                posix_spawnattr_setbinpref_np(&attr, 1, cpuTypes, &outCount);
+
+                char path[4 * PATH_MAX];
+                uint32_t pathLength = sizeof(path);
+                _NSGetExecutablePath(path, &pathLength);
+
+                char** argv = *_NSGetArgv();
+                const char* programName = argv[0];
+                const char* args[] = { programName, 0 };
+
+                xpc_object_t environmentArray = xpc_dictionary_get_value(event, "environment");
+                size_t numberOfEnvironmentVariables = xpc_array_get_count(environmentArray);
+
+                char** environment = (char**)malloc(numberOfEnvironmentVariables * sizeof(char*) + 1);
+                for (size_t i = 0; i < numberOfEnvironmentVariables; ++i) {
+                    const char* string =  xpc_array_get_string(environmentArray, i);
+                    size_t stringLength = strlen(string);
+
+                    char* environmentVariable = (char*)malloc(stringLength + 1);
+                    memcpy(environmentVariable, string, stringLength);
+                    environmentVariable[stringLength] = '\0';
+
+                    environment[i] = environmentVariable;
+                }
+                environment[numberOfEnvironmentVariables] = 0;
+
+                pid_t processIdentifier = 0;
+                posix_spawn(&processIdentifier, path, 0, &attr, const_cast<char**>(args), environment);
+
+                posix_spawnattr_destroy(&attr);
+
+                NSLog(@"Unable to re-exec for path: %s", path);
+                exit(EXIT_FAILURE);
+            }
+
+            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 at path: %s (Error: %s)", xpc_dictionary_get_string(event, "framework-executable-path"), dlerror());
+                    exit(EXIT_FAILURE);
+                }
+
+                typedef void (*InitializerFunction)(const char* clientIdentifer, xpc_connection_t connection, mach_port_t serverPort, const char* uiProcessName);
+                InitializerFunction initializerFunctionPtr = reinterpret_cast<InitializerFunction>(dlsym(frameworkLibrary, STRINGIZE(WEBKIT_XPC_SERVICE_INITIALIZER)));
+                if (!initializerFunctionPtr) {
+                    NSLog(@"Unable to find entry point in WebKit2.framework loaded from path: %s (Error: %s)", xpc_dictionary_get_string(event, "framework-executable-path"), 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);
+
+                dup2(xpc_dictionary_dup_fd(event, "stdout"), STDOUT_FILENO);
+                dup2(xpc_dictionary_dup_fd(event, "stderr"), STDERR_FILENO);
+
+                initializerFunctionPtr(
+                    xpc_dictionary_get_string(event, "client-identifier"),
+                    peer,
+                    xpc_dictionary_copy_mach_send(event, "server-port"),
+                    xpc_dictionary_get_string(event, "ui-process-name")
+                );
+            }
+        }
+    });
+
+    xpc_connection_resume(peer);
+}
+
+} // namespace WebKit;
+
+#endif // XPCServiceBootstrapper_Development_h

Added: trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceBootstrapper.h (0 => 140919)


--- trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceBootstrapper.h	                        (rev 0)
+++ trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceBootstrapper.h	2013-01-27 00:40:16 UTC (rev 140919)
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2013 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 XPCServiceBootstrapper_h
+#define XPCServiceBootstrapper_h
+
+#if !defined(WEBKIT_XPC_SERVICE_INITIALIZER)
+#error WEBKIT_XPC_SERVICE_INITIALIZER must be defined.
+#endif
+
+#import <xpc/xpc.h>
+extern "C" mach_port_t xpc_dictionary_copy_mach_send(xpc_object_t, const char*);
+
+// Forward declare the specified initializer.
+extern "C" void WEBKIT_XPC_SERVICE_INITIALIZER(const char* clientIdentifier, xpc_connection_t, mach_port_t serverPort, const char* uiProcessName);
+
+namespace WebKit {
+
+static void XPCServiceEventHandler(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);
+
+                WEBKIT_XPC_SERVICE_INITIALIZER(
+                    xpc_dictionary_get_string(event, "client-identifier"),
+                    peer,
+                    xpc_dictionary_copy_mach_send(event, "server-port"),
+                    xpc_dictionary_get_string(event, "ui-process-name")
+                );
+            }
+        }
+    });
+
+    xpc_connection_resume(peer);
+}
+
+} // namespace WebKit
+
+#endif // XPCServiceBootstrapper_h

Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (140918 => 140919)


--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2013-01-27 00:09:39 UTC (rev 140918)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2013-01-27 00:40:16 UTC (rev 140919)
@@ -799,6 +799,7 @@
 		BC82838C16B45F0700A278FE /* PluginProcessMain.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC82838A16B45EF200A278FE /* PluginProcessMain.mm */; };
 		BC82839416B4608000A278FE /* SharedWorkerProcessMainBootstrapper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC82839216B4607B00A278FE /* SharedWorkerProcessMainBootstrapper.cpp */; };
 		BC82839516B4608300A278FE /* SharedWorkerProcessMain.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC82839316B4607B00A278FE /* SharedWorkerProcessMain.mm */; };
+		BC82839916B48DC000A278FE /* WebContentServiceEntryPoint.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC82839816B48DC000A278FE /* WebContentServiceEntryPoint.mm */; };
 		BC82DF2215BDF42200FC2841 /* com.apple.WebProcess.sb in Resources */ = {isa = PBXBuildFile; fileRef = E1967E37150AB5E200C73169 /* com.apple.WebProcess.sb */; };
 		BC8452A71162C80900CAB9B5 /* DrawingArea.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC8452A51162C80900CAB9B5 /* DrawingArea.cpp */; };
 		BC8452A81162C80900CAB9B5 /* DrawingArea.h in Headers */ = {isa = PBXBuildFile; fileRef = BC8452A61162C80900CAB9B5 /* DrawingArea.h */; };
@@ -928,8 +929,6 @@
 		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 */; };
-		BCDC308B15FD6CD1006B6695 /* WebProcessServiceEntryPoints.mm in Sources */ = {isa = PBXBuildFile; fileRef = BCDC308915FD6CD1006B6695 /* WebProcessServiceEntryPoints.mm */; };
-		BCDC308C15FD6CD1006B6695 /* WebProcessServiceEntryPoints.h in Headers */ = {isa = PBXBuildFile; fileRef = BCDC308A15FD6CD1006B6695 /* WebProcessServiceEntryPoints.h */; };
 		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 */; };
@@ -2098,6 +2097,9 @@
 		BC82839116B4600D00A278FE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
 		BC82839216B4607B00A278FE /* SharedWorkerProcessMainBootstrapper.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SharedWorkerProcessMainBootstrapper.cpp; sourceTree = "<group>"; };
 		BC82839316B4607B00A278FE /* SharedWorkerProcessMain.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SharedWorkerProcessMain.mm; sourceTree = "<group>"; };
+		BC82839616B47EC400A278FE /* XPCServiceBootstrapper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPCServiceBootstrapper.h; sourceTree = "<group>"; };
+		BC82839716B480F600A278FE /* XPCServiceBootstrapper.Development.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPCServiceBootstrapper.Development.h; sourceTree = "<group>"; };
+		BC82839816B48DC000A278FE /* WebContentServiceEntryPoint.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebContentServiceEntryPoint.mm; sourceTree = "<group>"; };
 		BC8452A51162C80900CAB9B5 /* DrawingArea.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DrawingArea.cpp; sourceTree = "<group>"; };
 		BC8452A61162C80900CAB9B5 /* DrawingArea.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DrawingArea.h; sourceTree = "<group>"; };
 		BC84EB1712A7100C0083F2DA /* WebPreferencesMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebPreferencesMac.mm; sourceTree = "<group>"; };
@@ -2228,8 +2230,6 @@
 		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>"; };
-		BCDC308915FD6CD1006B6695 /* WebProcessServiceEntryPoints.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebProcessServiceEntryPoints.mm; sourceTree = "<group>"; };
-		BCDC308A15FD6CD1006B6695 /* WebProcessServiceEntryPoints.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebProcessServiceEntryPoints.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>"; };
@@ -2662,8 +2662,6 @@
 			isa = PBXGroup;
 			children = (
 				BC3065C312592F8900E71278 /* WebProcessMac.mm */,
-				BCDC308A15FD6CD1006B6695 /* WebProcessServiceEntryPoints.h */,
-				BCDC308915FD6CD1006B6695 /* WebProcessServiceEntryPoints.mm */,
 			);
 			path = mac;
 			sourceTree = "<group>";
@@ -4054,6 +4052,8 @@
 		BC82836B16B3587900A278FE /* XPCService */ = {
 			isa = PBXGroup;
 			children = (
+				BC82839616B47EC400A278FE /* XPCServiceBootstrapper.h */,
+				BC82839716B480F600A278FE /* XPCServiceBootstrapper.Development.h */,
 			);
 			name = XPCService;
 			path = mac/XPCService;
@@ -4186,6 +4186,7 @@
 			children = (
 				BCACC43F16B24CAA00B6E092 /* WebContentService */,
 				BCACC44216B24CAA00B6E092 /* WebContentService.Development */,
+				BC82839816B48DC000A278FE /* WebContentServiceEntryPoint.mm */,
 			);
 			name = XPCService;
 			path = mac/XPCService;
@@ -4954,7 +4955,6 @@
 				BC3066BF125A442100E71278 /* WebProcessMessages.h in Headers */,
 				BC032DD510F4389F0058C15A /* WebProcessProxy.h in Headers */,
 				BCEE7AD112817988009827DA /* WebProcessProxyMessages.h in Headers */,
-				BCDC308C15FD6CD1006B6695 /* WebProcessServiceEntryPoints.h in Headers */,
 				511F8A7B138B460900A95F44 /* SecItemShimLibrary.h in Headers */,
 				BCE0E425168B7A280057E66A /* WebProcessSupplement.h in Headers */,
 				512F589D12A8838800629530 /* WebProtectionSpace.h in Headers */,
@@ -5962,7 +5962,6 @@
 				BC111B11112F5E4F00337BAB /* WebProcessProxy.cpp in Sources */,
 				51D130581382F10500351EDD /* WebProcessProxyMac.mm in Sources */,
 				BCEE7AD012817988009827DA /* WebProcessProxyMessageReceiver.cpp in Sources */,
-				BCDC308B15FD6CD1006B6695 /* WebProcessServiceEntryPoints.mm in Sources */,
 				512F589C12A8838800629530 /* WebProtectionSpace.cpp in Sources */,
 				37948403150C350600E52CE9 /* WebRenderLayer.cpp in Sources */,
 				3760881E150413E900FC82C7 /* WebRenderObject.cpp in Sources */,
@@ -6107,6 +6106,7 @@
 				BC82838416B45DA500A278FE /* NetworkProcessMain.mm in Sources */,
 				BC82838C16B45F0700A278FE /* PluginProcessMain.mm in Sources */,
 				BC82839516B4608300A278FE /* SharedWorkerProcessMain.mm in Sources */,
+				BC82839916B48DC000A278FE /* WebContentServiceEntryPoint.mm in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: trunk/Source/WebKit2/WebProcess/EntryPoint/mac/XPCService/WebContentService/WebContentServiceMain.mm (140918 => 140919)


--- trunk/Source/WebKit2/WebProcess/EntryPoint/mac/XPCService/WebContentService/WebContentServiceMain.mm	2013-01-27 00:09:39 UTC (rev 140918)
+++ trunk/Source/WebKit2/WebProcess/EntryPoint/mac/XPCService/WebContentService/WebContentServiceMain.mm	2013-01-27 00:40:16 UTC (rev 140919)
@@ -23,9 +23,13 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#import "WebProcessServiceEntryPoints.h"
+#define WEBKIT_XPC_SERVICE_INITIALIZER initializeWebContentService
+#include "XPCServiceBootstrapper.h"
 
+using namespace WebKit;
+
 int main(int argc, char** argv)
 {
-    return webProcessServiceMain(argc, argv);
+    xpc_main(XPCServiceEventHandler);
+    return 0;
 }

Modified: trunk/Source/WebKit2/WebProcess/EntryPoint/mac/XPCService/WebContentService.Development/WebContentServiceMain.Development.mm (140918 => 140919)


--- trunk/Source/WebKit2/WebProcess/EntryPoint/mac/XPCService/WebContentService.Development/WebContentServiceMain.Development.mm	2013-01-27 00:09:39 UTC (rev 140918)
+++ trunk/Source/WebKit2/WebProcess/EntryPoint/mac/XPCService/WebContentService.Development/WebContentServiceMain.Development.mm	2013-01-27 00:40:16 UTC (rev 140919)
@@ -23,127 +23,13 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#import <AvailabilityMacros.h>
+#define WEBKIT_XPC_SERVICE_INITIALIZER initializeWebContentService
+#include "XPCServiceBootstrapper.Development.h"
 
-#import <crt_externs.h>
-#import <dlfcn.h>
-#import <mach-o/dyld.h>
-#import <spawn.h> 
-#import <stdio.h>
-#import <stdlib.h>
-#import <xpc/xpc.h>
+using namespace WebKit;
 
-extern "C" mach_port_t xpc_dictionary_copy_mach_send(xpc_object_t, const char*);
-
-static void WebProcessServiceForWebKitDevelopmentEventHandler(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"), "re-exec")) {
-                // Setup the posix_spawn attributes.
-                posix_spawnattr_t attr;
-                posix_spawnattr_init(&attr);
-
-                short flags = 0;
-
-                // We just want to set the process state, not actually launch a new process,
-                // so we are going to use the darwin extension to posix_spawn POSIX_SPAWN_SETEXEC
-                // to act like a more full featured exec.
-                flags |= POSIX_SPAWN_SETEXEC;
-
-                // We want our process to receive all signals.
-                sigset_t signalMaskSet;
-                sigemptyset(&signalMaskSet);
-                posix_spawnattr_setsigmask(&attr, &signalMaskSet);
-                flags |= POSIX_SPAWN_SETSIGMASK;
-
-                // Set the architecture.
-                cpu_type_t cpuTypes[] = { (cpu_type_t)xpc_dictionary_get_uint64(event, "architecture") };
-                size_t outCount = 0;
-                posix_spawnattr_setbinpref_np(&attr, 1, cpuTypes, &outCount);
-
-                static const int allowExecutableHeapFlag = 0x2000;
-                if (xpc_dictionary_get_bool(event, "executable-heap"))
-                    flags |= allowExecutableHeapFlag;
-
-                posix_spawnattr_setflags(&attr, flags);
-
-                char path[4 * PATH_MAX];
-                uint32_t pathLength = sizeof(path);
-                _NSGetExecutablePath(path, &pathLength);
-
-                // Setup the command line.
-                char** argv = *_NSGetArgv();
-                const char* programName = argv[0];
-                const char* args[] = { programName, 0 };
-
-                // Setup the environment.
-                xpc_object_t environmentArray = xpc_dictionary_get_value(event, "environment");
-                size_t numberOfEnvironmentVariables = xpc_array_get_count(environmentArray);
-
-                char** environment = (char**)malloc(numberOfEnvironmentVariables * sizeof(char*) + 1);
-                for (size_t i = 0; i < numberOfEnvironmentVariables; ++i) {
-                    const char* string =  xpc_array_get_string(environmentArray, i);
-                    size_t stringLength = strlen(string);
-
-                    char* environmentVariable = (char*)malloc(stringLength + 1);
-                    memcpy(environmentVariable, string, stringLength);
-                    environmentVariable[stringLength] = '\0';
-
-                    environment[i] = environmentVariable;
-                }
-                environment[numberOfEnvironmentVariables] = 0;
-
-                pid_t processIdentifier = 0;
-                posix_spawn(&processIdentifier, path, 0, &attr, const_cast<char**>(args), environment);
-
-                posix_spawnattr_destroy(&attr);
-
-                NSLog(@"Unable to re-exec for path: %s\n", path);
-                exit(EXIT_FAILURE);
-            }
-
-            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 void (*InitializeWebProcessFunction)(const char* clientIdentifer, xpc_connection_t connection, mach_port_t serverPort, const char* uiProcessName);
-                InitializeWebProcessFunction initializeWebProcessFunctionPtr = reinterpret_cast<InitializeWebProcessFunction>(dlsym(frameworkLibrary, "initializeWebProcessForWebProcessServiceForWebKitDevelopment"));
-                if (!initializeWebProcessFunctionPtr) {
-                    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);
-
-                dup2(xpc_dictionary_dup_fd(event, "stdout"), STDOUT_FILENO);
-                dup2(xpc_dictionary_dup_fd(event, "stderr"), STDERR_FILENO);
-
-                initializeWebProcessFunctionPtr(xpc_dictionary_get_string(event, "client-identifier"), peer, xpc_dictionary_copy_mach_send(event, "server-port"), xpc_dictionary_get_string(event, "ui-process-name"));
-            }
-        }
-    });
-
-    xpc_connection_resume(peer);
-}
-
 int main(int argc, char** argv)
 {
-    xpc_main(WebProcessServiceForWebKitDevelopmentEventHandler);
-    return 0;;
+    xpc_main(XPCServiceEventHandler);
+    return 0;
 }

Copied: trunk/Source/WebKit2/WebProcess/EntryPoint/mac/XPCService/WebContentServiceEntryPoint.mm (from rev 140913, trunk/Source/WebKit2/WebProcess/mac/WebProcessServiceEntryPoints.mm) (0 => 140919)


--- trunk/Source/WebKit2/WebProcess/EntryPoint/mac/XPCService/WebContentServiceEntryPoint.mm	                        (rev 0)
+++ trunk/Source/WebKit2/WebProcess/EntryPoint/mac/XPCService/WebContentServiceEntryPoint.mm	2013-01-27 00:40:16 UTC (rev 140919)
@@ -0,0 +1,61 @@
+/*
+ * 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"
+
+#if HAVE(XPC)
+
+#import "EnvironmentUtilities.h"
+#import "WKBase.h"
+#import "WebKit2Initialize.h"
+#import "WebProcess.h"
+#import <WebCore/RunLoop.h>
+#import <stdio.h>
+#import <stdlib.h>
+#import <xpc/xpc.h>
+
+using namespace WebCore;
+using namespace WebKit;
+
+extern "C" WK_EXPORT void initializeWebContentService(const char* clientIdentifier, xpc_connection_t connection, mach_port_t serverPort, const char* uiProcessName);
+
+void initializeWebContentService(const char* clientIdentifier, xpc_connection_t connection, mach_port_t serverPort, const char* uiProcessName)
+{
+    // 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.
+    EnvironmentUtilities::stripValuesEndingWithString("DYLD_INSERT_LIBRARIES", "/SecItemShim.dylib");
+
+    RunLoop::setUseApplicationRunLoopOnMainRunLoop();
+    InitializeWebKit2();
+
+    ChildProcessInitializationParameters parameters;
+    parameters.uiProcessName = uiProcessName;
+    parameters.clientIdentifier = clientIdentifier;
+    parameters.connectionIdentifier = CoreIPC::Connection::Identifier(serverPort, connection);
+
+    WebProcess::shared().initialize(parameters);
+}
+
+#endif // HAVE(XPC)

Deleted: trunk/Source/WebKit2/WebProcess/mac/WebProcessServiceEntryPoints.h (140918 => 140919)


--- trunk/Source/WebKit2/WebProcess/mac/WebProcessServiceEntryPoints.h	2013-01-27 00:09:39 UTC (rev 140918)
+++ trunk/Source/WebKit2/WebProcess/mac/WebProcessServiceEntryPoints.h	2013-01-27 00:40:16 UTC (rev 140919)
@@ -1,52 +0,0 @@
-/*
- * 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 WebProcessServiceEntryPoints_h
-#define WebProcessServiceEntryPoints_h
-
-#if HAVE(XPC)
-
-#include "WKBase.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-// This entry point is used for the installed WebProcessService, which does not
-// need to be re-execed, or mess around with DYLD.
-WK_EXPORT int webProcessServiceMain(int argc, char** argv);
-
-// This entry point is used for the WebProcessServiceForWebKitDevelopment
-// which needs to be re-exec, and can't link directly to WebKit2 requiring
-// some DYLD fiddling.
-WK_EXPORT void initializeWebProcessForWebProcessServiceForWebKitDevelopment(const char* clientIdentifier, xpc_connection_t, mach_port_t serverPort, const char* uiProcessName);
-
-#ifdef __cplusplus
-}; // extern "C"
-#endif
-
-#endif // HAVE(XPC)
-
-#endif // WebProcessServiceEntryPoints_h

Deleted: trunk/Source/WebKit2/WebProcess/mac/WebProcessServiceEntryPoints.mm (140918 => 140919)


--- trunk/Source/WebKit2/WebProcess/mac/WebProcessServiceEntryPoints.mm	2013-01-27 00:09:39 UTC (rev 140918)
+++ trunk/Source/WebKit2/WebProcess/mac/WebProcessServiceEntryPoints.mm	2013-01-27 00:40:16 UTC (rev 140919)
@@ -1,110 +0,0 @@
-/*
- * 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 "WebProcessServiceEntryPoints.h"
-
-#if HAVE(XPC)
-
-#import "EnvironmentUtilities.h"
-#import "WebKit2Initialize.h"
-#import "WebProcess.h"
-#import <WebCore/RunLoop.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 WebProcessServiceEventHandler(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);
-
-                ChildProcessInitializationParameters parameters;
-                parameters.uiProcessName = xpc_dictionary_get_string(event, "ui-process-name");
-                parameters.clientIdentifier = xpc_dictionary_get_string(event, "client-identifier");
-                parameters.connectionIdentifier = xpc_dictionary_copy_mach_send(event, "server-port");
-
-                WebProcess::shared().initialize(parameters);
-            }
-        }
-    });
-
-    xpc_connection_resume(peer);
-}
-
-} // namespace WebKit
-
-using namespace WebCore;
-using namespace WebKit;
-
-int webProcessServiceMain(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.
-    EnvironmentUtilities::stripValuesEndingWithString("DYLD_INSERT_LIBRARIES", "/SecItemShim.dylib");
-
-    RunLoop::setUseApplicationRunLoopOnMainRunLoop();
-    InitializeWebKit2();
-
-    xpc_main(WebProcessServiceEventHandler);
-    return 0;
-}
-
-void initializeWebProcessForWebProcessServiceForWebKitDevelopment(const char* clientIdentifier, xpc_connection_t connection, mach_port_t serverPort, const char* uiProcessName)
-{
-    // 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.
-    EnvironmentUtilities::stripValuesEndingWithString("DYLD_INSERT_LIBRARIES", "/SecItemShim.dylib");
-
-    RunLoop::setUseApplicationRunLoopOnMainRunLoop();
-    InitializeWebKit2();
-
-    ChildProcessInitializationParameters parameters;
-    parameters.uiProcessName = uiProcessName;
-    parameters.clientIdentifier = clientIdentifier;
-    parameters.connectionIdentifier = CoreIPC::Connection::Identifier(serverPort, connection);
-
-    WebProcess::shared().initialize(parameters);
-}
-
-#endif // HAVE(XPC)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to