Changeset 128021 in webkit


Ignore:
Timestamp:
Sep 10, 2012 12:05:28 AM (12 years ago)
Author:
weinig@apple.com
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.

Location:
trunk/Source/WebKit2
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r128006 r128021  
     12012-09-09  Sam Weinig  <sam@webkit.org>
     2
     3        Simplify WebKit2 XPC service backend now that I know it doesn't need to soft link WebKit2.framework
     4        https://bugs.webkit.org/show_bug.cgi?id=96228
     5
     6        Reviewed by Dan Bernstein.
     7
     8        We soft link the non-XPC service WebProcess backend to the WebKit2 framework to
     9        ensure that we can close all the necessary file descriptors at launch, without
     10        fear that we will be closing one we open while initializing WebKit2 or one of its
     11        dependencies. Since we don't need to close file descriptors in the XPC service
     12        backend, we don't need to soft link! While here, also do some cleanup and code
     13        sharing.
     14
     15        * UIProcess/Launcher/mac/ProcessLauncherMac.mm:
     16        (WebKit::launchXPCService):
     17        We don't need to send the framework executable path anymore (it was used for the
     18        soft linking), but we do need the client identifier.
     19       
     20        * WebKit2.xcodeproj/project.pbxproj:
     21        Add new files. Link the XPC service to WebKit2.framework.
     22
     23        * WebKit2Service/MainMacService.mm:
     24        Now that we don't have to soft link, just make this a stub that calls immediately
     25        into the WebKit2 framework.
     26       
     27        * WebProcess/mac/WebProcessInitialization.h: Added.
     28        * WebProcess/mac/WebProcessInitialization.mm: Added.
     29        (WebKit::InitializeWebProcess):
     30        Move initialization that is common between the XPC and non-XPC backends here.
     31
     32        * WebProcess/mac/WebProcessMainMac.mm:
     33        (WebKit::WebProcessMain):
     34        Remove XPC backend related code. Use new shared InitializeWebProcess function.
     35
     36        * WebProcess/mac/WebProcessXPCServiceMain.h: Added.
     37        * WebProcess/mac/WebProcessXPCServiceMain.mm: Added.
     38        (WebKit::WebKit2ServiceEventHandler):
     39        (WebProcessXPCServiceMain):
     40        Move XPC service backend initialization here.
     41
    1422012-09-09  Emil A Eklund  <eae@chromium.org>
    243
  • trunk/Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm

    r128003 r128021  
    106106    mach_port_insert_right(mach_task_self(), listeningPort, listeningPort, MACH_MSG_TYPE_MAKE_SEND);
    107107
     108    NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
     109    CString clientIdentifier = bundleIdentifier ? String([[NSBundle mainBundle] bundleIdentifier]).utf8() : *_NSGetProgname();
     110
    108111    xpc_object_t bootStrapMessage = xpc_dictionary_create(0, 0, 0);
    109112    xpc_dictionary_set_string(bootStrapMessage, "message-name", "bootstrap");
    110     xpc_dictionary_set_string(bootStrapMessage, "framework-executable-path", [[[NSBundle bundleWithIdentifier:@"com.apple.WebKit2"] executablePath] fileSystemRepresentation]);
    111113    xpc_dictionary_set_mach_send(bootStrapMessage, "server-port", listeningPort);
     114    xpc_dictionary_set_string(bootStrapMessage, "client-identifier", clientIdentifier.data());
    112115
    113116    that->ref();
  • trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj

    r126549 r128021  
    582582                BC33E0D112408E8600360F3F /* InjectedBundleRangeHandle.h in Headers */ = {isa = PBXBuildFile; fileRef = BC33E0CF12408E8600360F3F /* InjectedBundleRangeHandle.h */; };
    583583                BC33E0D212408E8600360F3F /* InjectedBundleRangeHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC33E0D012408E8600360F3F /* InjectedBundleRangeHandle.cpp */; };
    584                 BC3DE46915A91763008D26FC /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BC3DE46815A91763008D26FC /* Foundation.framework */; };
    585584                BC3DE47215A91764008D26FC /* MainMacService.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC3DE47115A91764008D26FC /* MainMacService.mm */; };
    586585                BC4075F3124FF0270068F20A /* WKArray.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC4075D7124FF0270068F20A /* WKArray.cpp */; };
     
    797796                BCD598AD112B7FDF00EC8C23 /* WebPreferencesStore.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCD598AB112B7FDF00EC8C23 /* WebPreferencesStore.cpp */; };
    798797                BCDB86C11200FB97007254BE /* WebURL.h in Headers */ = {isa = PBXBuildFile; fileRef = BCDB86C01200FB97007254BE /* WebURL.h */; };
     798                BCDC308715FD6A8B006B6695 /* WebProcessInitialization.mm in Sources */ = {isa = PBXBuildFile; fileRef = BCDC308515FD6A8B006B6695 /* WebProcessInitialization.mm */; };
     799                BCDC308815FD6A8B006B6695 /* WebProcessInitialization.h in Headers */ = {isa = PBXBuildFile; fileRef = BCDC308615FD6A8B006B6695 /* WebProcessInitialization.h */; };
     800                BCDC308B15FD6CD1006B6695 /* WebProcessXPCServiceMain.mm in Sources */ = {isa = PBXBuildFile; fileRef = BCDC308915FD6CD1006B6695 /* WebProcessXPCServiceMain.mm */; };
     801                BCDC308C15FD6CD1006B6695 /* WebProcessXPCServiceMain.h in Headers */ = {isa = PBXBuildFile; fileRef = BCDC308A15FD6CD1006B6695 /* WebProcessXPCServiceMain.h */; };
     802                BCDC308E15FDB9A7006B6695 /* WebKit2.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* WebKit2.framework */; };
    799803                BCDDB317124EBD130048D13C /* WKBase.h in Headers */ = {isa = PBXBuildFile; fileRef = BCDDB316124EBD130048D13C /* WKBase.h */; settings = {ATTRIBUTES = (Public, ); }; };
    800804                BCDDB32B124EC2AB0048D13C /* WKSharedAPICast.h in Headers */ = {isa = PBXBuildFile; fileRef = BCDDB32A124EC2AB0048D13C /* WKSharedAPICast.h */; };
     
    18741878                BCD598AB112B7FDF00EC8C23 /* WebPreferencesStore.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebPreferencesStore.cpp; sourceTree = "<group>"; };
    18751879                BCDB86C01200FB97007254BE /* WebURL.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebURL.h; sourceTree = "<group>"; };
     1880                BCDC308515FD6A8B006B6695 /* WebProcessInitialization.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebProcessInitialization.mm; sourceTree = "<group>"; };
     1881                BCDC308615FD6A8B006B6695 /* WebProcessInitialization.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebProcessInitialization.h; sourceTree = "<group>"; };
     1882                BCDC308915FD6CD1006B6695 /* WebProcessXPCServiceMain.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebProcessXPCServiceMain.mm; sourceTree = "<group>"; };
     1883                BCDC308A15FD6CD1006B6695 /* WebProcessXPCServiceMain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebProcessXPCServiceMain.h; sourceTree = "<group>"; };
    18761884                BCDDB316124EBD130048D13C /* WKBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKBase.h; sourceTree = "<group>"; };
    18771885                BCDDB32A124EC2AB0048D13C /* WKSharedAPICast.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKSharedAPICast.h; sourceTree = "<group>"; };
     
    20642072                        runOnlyForDeploymentPostprocessing = 0;
    20652073                };
    2066                 BC3DE46315A91763008D26FC /* Frameworks */ = {
     2074                BCDC308D15FDB99A006B6695 /* Frameworks */ = {
    20672075                        isa = PBXFrameworksBuildPhase;
    20682076                        buildActionMask = 2147483647;
    20692077                        files = (
    2070                                 BC3DE46915A91763008D26FC /* Foundation.framework in Frameworks */,
     2078                                BCDC308E15FDB9A7006B6695 /* WebKit2.framework in Frameworks */,
    20712079                        );
    20722080                        runOnlyForDeploymentPostprocessing = 0;
     
    22652273                                511F8A7D138B46FE00A95F44 /* SecItemShimMethods.h */,
    22662274                                511F8A7E138B46FE00A95F44 /* SecItemShimMethods.mm */,
     2275                                BCDC308615FD6A8B006B6695 /* WebProcessInitialization.h */,
     2276                                BCDC308515FD6A8B006B6695 /* WebProcessInitialization.mm */,
    22672277                                BC3065C312592F8900E71278 /* WebProcessMac.mm */,
    22682278                                1A6FA01D11E1526300DB1371 /* WebProcessMainMac.mm */,
    22692279                                511F8A77138B460900A95F44 /* WebProcessShim.h */,
    22702280                                511F8A78138B460900A95F44 /* WebProcessShim.mm */,
     2281                                BCDC308A15FD6CD1006B6695 /* WebProcessXPCServiceMain.h */,
     2282                                BCDC308915FD6CD1006B6695 /* WebProcessXPCServiceMain.mm */,
    22712283                        );
    22722284                        path = mac;
     
    42404252                                3F87B9C0158940D80090FF62 /* WebColorChooserProxy.h in Headers */,
    42414253                                BC59548915C7868500FD1E3E /* WebKit2.h in Headers */,
     4254                                BCDC308815FD6A8B006B6695 /* WebProcessInitialization.h in Headers */,
     4255                                BCDC308C15FD6CD1006B6695 /* WebProcessXPCServiceMain.h in Headers */,
    42424256                        );
    42434257                        runOnlyForDeploymentPostprocessing = 0;
     
    43324346                        buildPhases = (
    43334347                                BC3DE46215A91763008D26FC /* Sources */,
    4334                                 BC3DE46315A91763008D26FC /* Frameworks */,
     4348                                BCDC308D15FDB99A006B6695 /* Frameworks */,
    43354349                                BC3DE46415A91763008D26FC /* Resources */,
    43364350                        );
     
    50305044                                3F87B9BD158940120090FF62 /* WebColorChooser.cpp in Sources */,
    50315045                                CD67D30E15C08F9A00843ADF /* InjectedBundlePageDiagnosticLoggingClient.cpp in Sources */,
     5046                                BCDC308715FD6A8B006B6695 /* WebProcessInitialization.mm in Sources */,
     5047                                BCDC308B15FD6CD1006B6695 /* WebProcessXPCServiceMain.mm in Sources */,
    50325048                        );
    50335049                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/Source/WebKit2/WebKit2Service/MainMacService.mm

    r125358 r128021  
    2424 */
    2525
    26 #include <AvailabilityMacros.h>
     26#import <AvailabilityMacros.h>
    2727
    2828#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
    2929
    30 #include <dlfcn.h>
    31 #include <stdio.h>
    32 #include <stdlib.h>
    33 #include <xpc/xpc.h>
    34 
    35 extern "C" mach_port_t xpc_dictionary_copy_mach_send(xpc_object_t, const char*);
    36 
    37 static void WebKit2ServiceEventHandler(xpc_connection_t peer)
    38 {
    39     xpc_connection_set_target_queue(peer, dispatch_get_main_queue());
    40     xpc_connection_set_event_handler(peer, ^(xpc_object_t event) {
    41         xpc_type_t type = xpc_get_type(event);
    42         if (type == XPC_TYPE_ERROR) {
    43             if (event == XPC_ERROR_CONNECTION_INVALID || event == XPC_ERROR_TERMINATION_IMMINENT) {
    44                 // FIXME: Handle this case more gracefully.
    45                 exit(EXIT_FAILURE);
    46             }
    47         } else {
    48             assert(type == XPC_TYPE_DICTIONARY);
    49 
    50             if (!strcmp(xpc_dictionary_get_string(event, "message-name"), "bootstrap")) {
    51                 static void* frameworkLibrary = dlopen(xpc_dictionary_get_string(event, "framework-executable-path"), RTLD_NOW);
    52                 if (!frameworkLibrary) {
    53                     NSLog(@"Unable to load WebKit2.framework: %s\n", dlerror());
    54                     exit(EXIT_FAILURE);
    55                 }
    56 
    57                 typedef int (*WebKitMainFunction)(xpc_connection_t connection, mach_port_t serverPort);
    58                 WebKitMainFunction webKitMainXPC = reinterpret_cast<WebKitMainFunction>(dlsym(frameworkLibrary, "WebKitMainXPC"));
    59                 if (!webKitMainXPC) {
    60                     NSLog(@"Unable to find entry point in WebKit2.framework: %s\n", dlerror());
    61                     exit(EXIT_FAILURE);
    62                 }
    63 
    64                 xpc_object_t reply = xpc_dictionary_create_reply(event);
    65                 xpc_dictionary_set_string(reply, "message-name", "process-finished-launching");
    66                 xpc_connection_send_message(xpc_dictionary_get_remote_connection(event), reply);
    67                 xpc_release(reply);
    68 
    69                 webKitMainXPC(peer, xpc_dictionary_copy_mach_send(event, "server-port"));
    70             }
    71         }
    72     });
    73 
    74     xpc_connection_resume(peer);
    75 }
     30#import "WebProcessXPCServiceMain.h"
    7631
    7732int main(int argc, char** argv)
    7833{
    79     xpc_main(WebKit2ServiceEventHandler);
    80     return 0;
     34    return WebProcessXPCServiceMain(argc, argv);
    8135}
    8236
  • trunk/Source/WebKit2/WebProcess/mac/WebProcessMainMac.mm

    r128003 r128021  
    3232#import "StringUtilities.h"
    3333#import "WebProcess.h"
    34 #import "WebSystemInterface.h"
     34#import "WebProcessInitialization.h"
    3535#import <WebCore/RunLoop.h>
    3636#import <WebKitSystemInterface.h>
    3737#import <mach/mach_error.h>
    3838#import <objc/objc-auto.h>
    39 #import <runtime/InitializeThreading.h>
    4039#import <servers/bootstrap.h>
    4140#import <signal.h>
     
    4443#import <sysexits.h>
    4544#import <unistd.h>
    46 #import <wtf/MainThread.h>
    4745#import <wtf/RetainPtr.h>
    4846#import <wtf/text/CString.h>
    49 #import <wtf/text/StringBuilder.h>
    50 
    51 #if HAVE(XPC)
    52 #import <xpc/xpc.h>
    53 #endif
     47#import <wtf/text/WTFString.h>
    5448
    5549#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
     
    6761using namespace WebCore;
    6862
    69 #if HAVE(XPC)
    7063namespace WebKit {
    71 int WebProcessMainXPC(xpc_connection_t xpcConnection, mach_port_t serverPort);
    72 }
    73 
    74 extern "C" WK_EXPORT int WebKitMainXPC(xpc_connection_t xpcConnection, mach_port_t serverPort);
    75 
    76 int WebKitMainXPC(xpc_connection_t xpcConnection, mach_port_t serverPort)
    77 {
    78     ASSERT(!objc_collectingEnabled());
    79 
    80     return WebKit::WebProcessMainXPC(xpcConnection, serverPort);
    81 }
    82 #endif
    83 
    84 namespace WebKit {
    85 
    86 #if HAVE(XPC)
    87 
    88 int WebProcessMainXPC(xpc_connection_t xpcConnection, mach_port_t serverPort)
    89 {
    90     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    91 
    92     InitWebCoreSystemInterface();
    93     JSC::initializeThreading();
    94     WTF::initializeMainThread();
    95     RunLoop::initializeMainRunLoop();
    96 
    97     // FIXME: Make the shim work.
    98     WebProcess::shared().initializeShim();
    99     // FIXME: Pass the client identifier here.
    100     WebProcess::shared().initializeSandbox(String());
    101     WebProcess::shared().initialize(CoreIPC::Connection::Identifier(serverPort, xpcConnection), RunLoop::main());
    102 
    103     WKAXRegisterRemoteApp();
    104 
    105     [pool drain];
    106 
    107     return 0;
    108 }
    109 #endif
    11064
    11165int WebProcessMain(const CommandLine& commandLine)
     
    212166        WKSetDefaultLocalization(cfLocalization.get());
    213167
     168    [pool drain];
     169
    214170#if !SHOW_CRASH_REPORTER
    215171    // Installs signal handlers that exit on a crash so that CrashReporter does not show up.
     
    219175    signal(SIGSEGV, _exit);
    220176#endif
    221 
    222     InitWebCoreSystemInterface();
    223     JSC::initializeThreading();
    224     WTF::initializeMainThread();
    225     RunLoop::initializeMainRunLoop();
    226177
    227178#if USE(APPKIT)
     
    234185#endif
    235186
    236     WebProcess::shared().initializeShim();
    237     WebProcess::shared().initializeSandbox(clientIdentifier);
    238     WebProcess::shared().initialize(CoreIPC::Connection::Identifier(serverPort), RunLoop::main());
    239 
    240     WKAXRegisterRemoteApp();
    241 
    242     [pool drain];
     187    InitializeWebProcess(clientIdentifier, CoreIPC::Connection::Identifier(serverPort));
    243188
    244189    RunLoop::run();
Note: See TracChangeset for help on using the changeset viewer.