Changeset 138981 in webkit
- Timestamp:
- Jan 7, 2013 1:26:01 PM (11 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 1 added
- 9 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r138973 r138981 1 2013-01-05 Sam Weinig <sam@webkit.org> 2 3 Merge child process main functions as much as possible 4 https://bugs.webkit.org/show_bug.cgi?id=106192 5 6 Reviewed by Anders Carlsson. 7 8 To reduce copied code, this merges the Mac main functions for the WebProcess, 9 NetworkProcess, PluginProcess, and SharedWorkerProcess. Since slight variations 10 are needed, it adds a delegate class for hooks into the main function that each 11 process can override if necessary. 12 13 * NetworkProcess/mac/NetworkProcessMainMac.mm: 14 (WebKit::NetworkProcessMain): 15 Remove almost everything with a call to ChildProcessMain with the default delegate. 16 17 * PluginProcess/mac/PluginProcessMac.mm: 18 (WebKit::PluginProcess::platformInitializeProcess): 19 Move defaults registration here from PluginProcessMainMac. 20 21 * PluginProcess/mac/PluginProcessMainMac.mm: 22 (PluginProcessMainDelegate): 23 Add a delegate for the new shared main function that does does PluginProcess 24 specific work. 25 26 (WebKit::PluginProcessMainDelegate::doPreInitializationWork): 27 Move DYLD_INSERT_LIBRARIES removal and createPluginMIMETypesPreferences special mode 28 to this pre-initialization hook. 29 30 (WebKit::PluginProcessMainDelegate::doPostRunWork): 31 Move private temporary and cache directories clean up to this post run hook. 32 33 (WebKit::PluginProcessMain): 34 Call the ChildProcessMain shared main function with the PluginProcess as the process 35 to initialize and PluginProcessMainDelegate as the main delegate. 36 37 * Shared/mac/ChildProcessMain.h: Added. 38 (ChildProcessMainDelegate): 39 ChildProcessMainDelegate is a helper class that process can subclass to hook into 40 the main function. 41 42 (WebKit::ChildProcessMain): 43 Add a single version of the "main" function that uses the ChildProcessMainDelegate to 44 allow processes to hook into it. 45 46 * Shared/mac/ChildProcessMain.mm: 47 (WebKit::ChildProcessMainDelegate::~ChildProcessMainDelegate): 48 (WebKit::ChildProcessMainDelegate::installSignalHandlers): 49 (WebKit::ChildProcessMainDelegate::doPreInitializationWork): 50 (WebKit::ChildProcessMainDelegate::getConnectionIdentifier): 51 (WebKit::ChildProcessMainDelegate::getClientIdentifier): 52 (WebKit::ChildProcessMainDelegate::getClientProcessName): 53 (WebKit::ChildProcessMainDelegate::doPostRunWork): 54 Add default implementations of the delegate hooks, most processes should be able to 55 use the defaults. 56 57 * SharedWorkerProcess/mac/SharedWorkerProcessMainMac.mm: 58 (WebKit::SharedWorkerProcessMain): 59 Remove almost everything with a call to ChildProcessMain with the default delegate. 60 61 * WebKit2.xcodeproj/project.pbxproj: 62 Add new files. 63 64 * WebProcess/mac/WebProcessMainMac.mm: 65 (WebProcessMainDelegate): 66 Add a delegate for the new shared main function that does does WebProcess 67 specific work. 68 69 (WebKit::WebProcessMainDelegate::doPreInitializationWork): 70 Move DYLD_INSERT_LIBRARIES removal to this this pre-initialization hook. 71 72 (WebKit::WebProcessMainDelegate::getConnectionIdentifier): 73 A custom getConnectionIdentifier is necessary for the WebProcess to keep support for having the WebProcess 74 be able to launch the UIProcess (for debugging purposes). 75 76 (WebKit::WebProcessMainDelegate::getClientIdentifier): 77 For the same reasons as about, a custom getClientIdentifier is needed. 78 79 (WebKit::WebProcessMain): 80 Call the ChildProcessMain shared main function with the WebProcess as the process 81 to initialize and WebProcessMainDelegate as the main delegate. 82 1 83 2013-01-07 Simon Fraser <simon.fraser@apple.com> 2 84 -
trunk/Source/WebKit2/NetworkProcess/mac/NetworkProcessMainMac.mm
r138913 r138981 29 29 #if ENABLE(NETWORK_PROCESS) 30 30 31 #import "C ommandLine.h"31 #import "ChildProcessMain.h" 32 32 #import "NetworkProcess.h" 33 #import "WebKit2Initialize.h"34 #import <WebCore/RunLoop.h>35 #import <WebKitSystemInterface.h>36 #import <mach/mach_error.h>37 #import <servers/bootstrap.h>38 #import <stdio.h>39 #import <wtf/MainThread.h>40 #import <wtf/RetainPtr.h>41 #import <wtf/text/CString.h>42 #import <wtf/text/WTFString.h>43 44 #define SHOW_CRASH_REPORTER 145 46 using namespace WebCore;47 33 48 34 namespace WebKit { 49 35 50 // FIXME: There is much code here that is duplicated in WebProcessMainMac.mm, we should add a shared base class where51 // we can put everything.52 53 36 int NetworkProcessMain(const CommandLine& commandLine) 54 37 { 55 String serviceName = commandLine["servicename"]; 56 if (serviceName.isEmpty()) 57 return EXIT_FAILURE; 58 59 // Get the server port. 60 mach_port_t serverPort; 61 kern_return_t kr = bootstrap_look_up(bootstrap_port, serviceName.utf8().data(), &serverPort); 62 if (kr) { 63 WTFLogAlways("bootstrap_look_up result: %s (%x)\n", mach_error_string(kr), kr); 64 return EXIT_FAILURE; 65 } 66 67 String localization = commandLine["localization"]; 68 RetainPtr<CFStringRef> cfLocalization(AdoptCF, CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar*>(localization.characters()), localization.length())); 69 if (cfLocalization) 70 WKSetDefaultLocalization(cfLocalization.get()); 71 72 #if !SHOW_CRASH_REPORTER 73 // Installs signal handlers that exit on a crash so that CrashReporter does not show up. 74 signal(SIGILL, _exit); 75 signal(SIGFPE, _exit); 76 signal(SIGBUS, _exit); 77 signal(SIGSEGV, _exit); 78 #endif 79 80 @autoreleasepool { 81 // FIXME: The Network process should not need to use AppKit, but right now, WebCore::RunLoop depends 82 // on the outer most runloop being an AppKit runloop. 83 [NSApplication sharedApplication]; 84 85 InitializeWebKit2(); 86 87 ChildProcessInitializationParameters parameters; 88 parameters.uiProcessName = commandLine["ui-process-name"]; 89 parameters.clientIdentifier = commandLine["client-identifier"]; 90 parameters.connectionIdentifier = serverPort; 91 92 NetworkProcess::shared().initialize(parameters); 93 } 94 95 RunLoop::run(); 96 97 return 0; 38 return ChildProcessMain<NetworkProcess, ChildProcessMainDelegate>(commandLine); 98 39 } 99 40 -
trunk/Source/WebKit2/PluginProcess/mac/PluginProcessMac.mm
r138913 r138981 282 282 // allowing plug-ins to change the mouse cursor at any time. 283 283 WKEnableSettingCursorWhenInBackground(); 284 285 #if defined(__i386__) 286 NSDictionary *defaults = [[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithBool:YES], @"AppleMagnifiedMode", nil]; 287 [[NSUserDefaults standardUserDefaults] registerDefaults:defaults]; 288 [defaults release]; 289 #endif 284 290 } 285 291 -
trunk/Source/WebKit2/PluginProcess/mac/PluginProcessMainMac.mm
r138913 r138981 29 29 #if ENABLE(PLUGIN_PROCESS) 30 30 31 #import "C ommandLine.h"31 #import "ChildProcessMain.h" 32 32 #import "EnvironmentUtilities.h" 33 33 #import "NetscapePluginModule.h" 34 34 #import "PluginProcess.h" 35 #import "WebKit2Initialize.h"36 #import <Foundation/NSUserDefaults.h>37 #import <WebCore/RunLoop.h>38 #import <WebKitSystemInterface.h>39 #import <mach/mach_error.h>40 #import <servers/bootstrap.h>41 #import <stdio.h>42 #import <wtf/RetainPtr.h>43 #import <wtf/text/CString.h>44 #import <wtf/text/WTFString.h>45 46 #define SHOW_CRASH_REPORTER 147 48 using namespace WebCore;49 35 50 36 namespace WebKit { 51 37 52 // FIXME: There is much code here that is duplicated in WebProcessMainMac.mm, we should add a shared base class where 53 // we can put everything. 38 class PluginProcessMainDelegate : public ChildProcessMainDelegate { 39 public: 40 PluginProcessMainDelegate(const CommandLine& commandLine) 41 : ChildProcessMainDelegate(commandLine) 42 { 43 } 44 45 virtual void doPreInitializationWork() 46 { 47 // Remove the PluginProcess shim from the DYLD_INSERT_LIBRARIES environment variable so any processes 48 // spawned by the PluginProcess don't try to insert the shim and crash. 49 EnvironmentUtilities::stripValuesEndingWithString("DYLD_INSERT_LIBRARIES", "/PluginProcessShim.dylib"); 50 51 // Check if we're being spawned to write a MIME type preferences file. 52 String pluginPath = m_commandLine["createPluginMIMETypesPreferences"]; 53 if (!pluginPath.isEmpty()) { 54 if (!NetscapePluginModule::createPluginMIMETypesPreferences(pluginPath)) 55 exit(EXIT_FAILURE); 56 exit(EXIT_SUCCESS); 57 } 58 } 59 60 virtual void doPostRunWork() 61 { 62 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 63 // If we have private temporary and cache directories, clean them up. 64 if (getenv("DIRHELPER_USER_DIR_SUFFIX")) { 65 char darwinDirectory[PATH_MAX]; 66 if (confstr(_CS_DARWIN_USER_TEMP_DIR, darwinDirectory, sizeof(darwinDirectory))) 67 [[NSFileManager defaultManager] removeItemAtPath:[[NSFileManager defaultManager] stringWithFileSystemRepresentation:darwinDirectory length:strlen(darwinDirectory)] error:nil]; 68 if (confstr(_CS_DARWIN_USER_CACHE_DIR, darwinDirectory, sizeof(darwinDirectory))) 69 [[NSFileManager defaultManager] removeItemAtPath:[[NSFileManager defaultManager] stringWithFileSystemRepresentation:darwinDirectory length:strlen(darwinDirectory)] error:nil]; 70 } 71 #endif 72 } 73 }; 54 74 55 75 int PluginProcessMain(const CommandLine& commandLine) 56 76 { 57 // Remove the PluginProcess shim from the DYLD_INSERT_LIBRARIES environment variable so any processes 58 // spawned by the PluginProcess don't try to insert the shim and crash. 59 EnvironmentUtilities::stripValuesEndingWithString("DYLD_INSERT_LIBRARIES", "/PluginProcessShim.dylib"); 60 61 // Check if we're being spawned to write a MIME type preferences file. 62 String pluginPath = commandLine["createPluginMIMETypesPreferences"]; 63 if (!pluginPath.isEmpty()) { 64 InitializeWebKit2(); 65 66 if (!NetscapePluginModule::createPluginMIMETypesPreferences(pluginPath)) 67 return EXIT_FAILURE; 68 69 return EXIT_SUCCESS; 70 } 71 72 String serviceName = commandLine["servicename"]; 73 if (serviceName.isEmpty()) 74 return EXIT_FAILURE; 75 76 // Get the server port. 77 mach_port_t serverPort; 78 kern_return_t kr = bootstrap_look_up(bootstrap_port, serviceName.utf8().data(), &serverPort); 79 if (kr) { 80 WTFLogAlways("bootstrap_look_up result: %s (%x)\n", mach_error_string(kr), kr); 81 return EXIT_FAILURE; 82 } 83 84 String localization = commandLine["localization"]; 85 if (!localization.isEmpty()) { 86 RetainPtr<CFStringRef> cfLocalization(AdoptCF, CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar*>(localization.characters()), localization.length())); 87 WKSetDefaultLocalization(cfLocalization.get()); 88 } 89 90 #if defined(__i386__) 91 { 92 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 93 94 NSDictionary *defaults = [[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithBool:YES], @"AppleMagnifiedMode", nil]; 95 [[NSUserDefaults standardUserDefaults] registerDefaults:defaults]; 96 [defaults release]; 97 98 [pool drain]; 99 } 100 #endif 101 102 #if !SHOW_CRASH_REPORTER 103 // Installs signal handlers that exit on a crash so that CrashReporter does not show up. 104 signal(SIGILL, _exit); 105 signal(SIGFPE, _exit); 106 signal(SIGBUS, _exit); 107 signal(SIGSEGV, _exit); 108 #endif 109 110 @autoreleasepool { 111 InitializeWebKit2(); 112 113 ChildProcessInitializationParameters parameters; 114 parameters.uiProcessName = commandLine["ui-process-name"]; 115 parameters.clientIdentifier = commandLine["client-identifier"]; 116 parameters.connectionIdentifier = CoreIPC::Connection::Identifier(serverPort); 117 118 PluginProcess::shared().initialize(parameters); 119 120 [NSApplication sharedApplication]; 121 } 122 123 RunLoop::run(); 124 125 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 126 // If we have private temporary and cache directories, clean them up. 127 if (getenv("DIRHELPER_USER_DIR_SUFFIX")) { 128 char darwinDirectory[PATH_MAX]; 129 if (confstr(_CS_DARWIN_USER_TEMP_DIR, darwinDirectory, sizeof(darwinDirectory))) 130 [[NSFileManager defaultManager] removeItemAtPath:[[NSFileManager defaultManager] stringWithFileSystemRepresentation:darwinDirectory length:strlen(darwinDirectory)] error:nil]; 131 if (confstr(_CS_DARWIN_USER_CACHE_DIR, darwinDirectory, sizeof(darwinDirectory))) 132 [[NSFileManager defaultManager] removeItemAtPath:[[NSFileManager defaultManager] stringWithFileSystemRepresentation:darwinDirectory length:strlen(darwinDirectory)] error:nil]; 133 } 134 #endif 135 136 return 0; 77 return ChildProcessMain<PluginProcess, PluginProcessMainDelegate>(commandLine); 137 78 } 138 79 -
trunk/Source/WebKit2/Shared/mac/ChildProcessMain.mm
r138980 r138981 1 1 /* 2 * Copyright (C) 201 2Apple Inc. All rights reserved.2 * Copyright (C) 2013 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 24 24 */ 25 25 26 #i mport"config.h"27 #i mport "NetworkProcessMain.h"26 #include "config.h" 27 #include "ChildProcessMain.h" 28 28 29 #if ENABLE(NETWORK_PROCESS)30 31 #import "CommandLine.h"32 #import "NetworkProcess.h"33 #import "WebKit2Initialize.h"34 #import <WebCore/RunLoop.h>35 #import <WebKitSystemInterface.h>36 29 #import <mach/mach_error.h> 37 30 #import <servers/bootstrap.h> 38 31 #import <stdio.h> 39 #import <wtf/MainThread.h>40 32 #import <wtf/RetainPtr.h> 41 33 #import <wtf/text/CString.h> 42 #import <wtf/text/WTFString.h>43 34 44 35 #define SHOW_CRASH_REPORTER 1 45 36 46 using namespace WebCore;47 48 37 namespace WebKit { 49 38 50 // FIXME: There is much code here that is duplicated in WebProcessMainMac.mm, we should add a shared base class where 51 // we can put everything. 39 ChildProcessMainDelegate::~ChildProcessMainDelegate() 40 { 41 } 52 42 53 int NetworkProcessMain(const CommandLine& commandLine)43 void ChildProcessMainDelegate::installSignalHandlers() 54 44 { 55 String serviceName = commandLine["servicename"];56 if (serviceName.isEmpty())57 return EXIT_FAILURE;58 59 // Get the server port.60 mach_port_t serverPort;61 kern_return_t kr = bootstrap_look_up(bootstrap_port, serviceName.utf8().data(), &serverPort);62 if (kr) {63 WTFLogAlways("bootstrap_look_up result: %s (%x)\n", mach_error_string(kr), kr);64 return EXIT_FAILURE;65 }66 67 String localization = commandLine["localization"];68 RetainPtr<CFStringRef> cfLocalization(AdoptCF, CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar*>(localization.characters()), localization.length()));69 if (cfLocalization)70 WKSetDefaultLocalization(cfLocalization.get());71 72 45 #if !SHOW_CRASH_REPORTER 73 46 // Installs signal handlers that exit on a crash so that CrashReporter does not show up. … … 77 50 signal(SIGSEGV, _exit); 78 51 #endif 52 } 79 53 80 @autoreleasepool { 81 // FIXME: The Network process should not need to use AppKit, but right now, WebCore::RunLoop depends 82 // on the outer most runloop being an AppKit runloop. 83 [NSApplication sharedApplication]; 54 void ChildProcessMainDelegate::doPreInitializationWork() 55 { 56 } 84 57 85 InitializeWebKit2(); 86 87 ChildProcessInitializationParameters parameters; 88 parameters.uiProcessName = commandLine["ui-process-name"]; 89 parameters.clientIdentifier = commandLine["client-identifier"]; 90 parameters.connectionIdentifier = serverPort; 91 92 NetworkProcess::shared().initialize(parameters); 58 bool ChildProcessMainDelegate::getConnectionIdentifier(CoreIPC::Connection::Identifier& identifier) 59 { 60 String serviceName = m_commandLine["servicename"]; 61 if (serviceName.isEmpty()) 62 return false; 63 64 mach_port_t serverPort; 65 kern_return_t kr = bootstrap_look_up(bootstrap_port, serviceName.utf8().data(), &serverPort); 66 if (kr) { 67 WTFLogAlways("bootstrap_look_up result: %s (%x)\n", mach_error_string(kr), kr); 68 return false; 93 69 } 94 70 95 RunLoop::run(); 71 identifier = serverPort; 72 return true; 73 } 96 74 97 return 0; 75 bool ChildProcessMainDelegate::getClientIdentifier(String& clientIdentifier) 76 { 77 clientIdentifier = m_commandLine["client-identifier"]; 78 if (clientIdentifier.isEmpty()) 79 return false; 80 return true; 81 } 82 83 bool ChildProcessMainDelegate::getClientProcessName(String& clientProcessName) 84 { 85 clientProcessName = m_commandLine["ui-process-name"]; 86 if (clientProcessName.isEmpty()) 87 return false; 88 return true; 89 } 90 91 void ChildProcessMainDelegate::doPostRunWork() 92 { 98 93 } 99 94 100 95 } // namespace WebKit 101 102 #endif // ENABLE(NETWORK_PROCESS) -
trunk/Source/WebKit2/SharedWorkerProcess/mac/SharedWorkerProcessMainMac.mm
r138913 r138981 29 29 #if ENABLE(SHARED_WORKER_PROCESS) 30 30 31 #import "CommandLine.h" 32 #import "EnvironmentUtilities.h" 31 #import "ChildProcessMain.h" 33 32 #import "SharedWorkerProcess.h" 34 #import "WebKit2Initialize.h"35 #import <Foundation/NSUserDefaults.h>36 #import <WebCore/RunLoop.h>37 #import <WebKitSystemInterface.h>38 #import <mach/mach_error.h>39 #import <servers/bootstrap.h>40 #import <stdio.h>41 #import <wtf/RetainPtr.h>42 #import <wtf/text/CString.h>43 #import <wtf/text/WTFString.h>44 45 #define SHOW_CRASH_REPORTER 146 47 using namespace WebCore;48 33 49 34 namespace WebKit { 50 35 51 // FIXME: There is much code here that is duplicated in WebProcessMainMac.mm, we should add a shared base class where52 // we can put everything.53 54 36 int SharedWorkerProcessMain(const CommandLine& commandLine) 55 37 { 56 String serviceName = commandLine["servicename"]; 57 if (serviceName.isEmpty()) 58 return EXIT_FAILURE; 59 60 // Get the server port. 61 mach_port_t serverPort; 62 kern_return_t kr = bootstrap_look_up(bootstrap_port, serviceName.utf8().data(), &serverPort); 63 if (kr) { 64 WTFLogAlways("bootstrap_look_up result: %s (%x)\n", mach_error_string(kr), kr); 65 return EXIT_FAILURE; 66 } 67 68 String localization = commandLine["localization"]; 69 if (!localization.isEmpty()) { 70 RetainPtr<CFStringRef> cfLocalization(AdoptCF, CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar*>(localization.characters()), localization.length())); 71 WKSetDefaultLocalization(cfLocalization.get()); 72 } 73 74 #if defined(__i386__) 75 { 76 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 77 78 NSDictionary *defaults = [[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithBool:YES], @"AppleMagnifiedMode", nil]; 79 [[NSUserDefaults standardUserDefaults] registerDefaults:defaults]; 80 [defaults release]; 81 82 [pool drain]; 83 } 84 #endif 85 86 #if !SHOW_CRASH_REPORTER 87 // Installs signal handlers that exit on a crash so that CrashReporter does not show up. 88 signal(SIGILL, _exit); 89 signal(SIGFPE, _exit); 90 signal(SIGBUS, _exit); 91 signal(SIGSEGV, _exit); 92 #endif 93 94 @autoreleasepool { 95 InitializeWebKit2(); 96 97 ChildProcessInitializationParameters parameters; 98 parameters.uiProcessName = commandLine["ui-process-name"]; 99 parameters.clientIdentifier = commandLine["client-identifier"]; 100 parameters.connectionIdentifier = CoreIPC::Connection::Identifier(serverPort); 101 102 SharedWorkerProcess::shared().initialize(parameters); 103 104 [NSApplication sharedApplication]; 105 } 106 107 RunLoop::run(); 108 109 return 0; 38 return ChildProcessMain<SharedWorkerProcess, ChildProcessMainDelegate>(commandLine); 110 39 } 111 40 112 } 41 } // namespace WebKit 113 42 114 43 #endif // ENABLE(SHARED_WORKER_PROCESS) -
trunk/Source/WebKit2/UIProcess/Launcher/mac/EnvironmentVariables.cpp
r136620 r138981 147 147 } 148 148 149 void EnvironmentVariables::dump() 150 { 151 for (size_t i = 0; (*_NSGetEnviron())[i]; i++) 152 printf("%s\n", (*_NSGetEnviron())[i]); 153 154 printf("\n\n\n"); 155 } 156 149 157 } // namespace WebKit -
trunk/Source/WebKit2/UIProcess/Launcher/mac/EnvironmentVariables.h
r136620 r138981 50 50 static const char* preexistingProcessTypeKey(); 51 51 52 static void dump(); 53 52 54 private: 53 55 const char* valueIfVariableHasName(const char* environmentVariable, const char* name) const; -
trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
r138913 r138981 831 831 BC9BA5041697C45300E44616 /* WebKit2Initialize.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC9BA5021697C45300E44616 /* WebKit2Initialize.cpp */; }; 832 832 BC9BA5051697C45300E44616 /* WebKit2Initialize.h in Headers */ = {isa = PBXBuildFile; fileRef = BC9BA5031697C45300E44616 /* WebKit2Initialize.h */; }; 833 BC9BA50816991C3C00E44616 /* ChildProcessMain.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC9BA50616991C3C00E44616 /* ChildProcessMain.mm */; }; 834 BC9BA50916991C3C00E44616 /* ChildProcessMain.h in Headers */ = {isa = PBXBuildFile; fileRef = BC9BA50716991C3C00E44616 /* ChildProcessMain.h */; }; 833 835 BC9FA520160D3B430054DF9A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BC3DE46815A91763008D26FC /* Foundation.framework */; }; 834 836 BC9FA522160D4A0C0054DF9A /* com.apple.WebKit.PluginProcess.sb in Resources */ = {isa = PBXBuildFile; fileRef = E1967E35150AB5D500C73169 /* com.apple.WebKit.PluginProcess.sb */; }; … … 2103 2105 BC9BA5021697C45300E44616 /* WebKit2Initialize.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebKit2Initialize.cpp; sourceTree = "<group>"; }; 2104 2106 BC9BA5031697C45300E44616 /* WebKit2Initialize.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebKit2Initialize.h; sourceTree = "<group>"; }; 2107 BC9BA50616991C3C00E44616 /* ChildProcessMain.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ChildProcessMain.mm; sourceTree = "<group>"; }; 2108 BC9BA50716991C3C00E44616 /* ChildProcessMain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ChildProcessMain.h; sourceTree = "<group>"; }; 2105 2109 BCA0EF7D12331E78007D3CFB /* WebUndoStep.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebUndoStep.h; sourceTree = "<group>"; }; 2106 2110 BCA0EF7E12331E78007D3CFB /* WebUndoStep.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebUndoStep.cpp; sourceTree = "<group>"; }; … … 3838 3842 BCE231C0122C466E00D5C35A /* WebURLRequestMac.mm */, 3839 3843 BC90A1D5122DD66A00CC8C50 /* WebURLResponseMac.mm */, 3844 BC9BA50616991C3C00E44616 /* ChildProcessMain.mm */, 3845 BC9BA50716991C3C00E44616 /* ChildProcessMain.h */, 3840 3846 ); 3841 3847 path = mac; … … 5033 5039 BCF4DE25168FA44800C94AFC /* WebContextSupplement.h in Headers */, 5034 5040 BC9BA5051697C45300E44616 /* WebKit2Initialize.h in Headers */, 5041 BC9BA50916991C3C00E44616 /* ChildProcessMain.h in Headers */, 5035 5042 ); 5036 5043 runOnlyForDeploymentPostprocessing = 0; … … 6007 6014 31A505F91680025500A930EB /* WebContextClient.cpp in Sources */, 6008 6015 BC9BA5041697C45300E44616 /* WebKit2Initialize.cpp in Sources */, 6016 BC9BA50816991C3C00E44616 /* ChildProcessMain.mm in Sources */, 6009 6017 ); 6010 6018 runOnlyForDeploymentPostprocessing = 0; -
trunk/Source/WebKit2/WebProcess/mac/WebProcessMainMac.mm
r138913 r138981 28 28 29 29 #import "CommandLine.h" 30 #import "ChildProcessMain.h" 30 31 #import "EnvironmentUtilities.h" 31 32 #import "EnvironmentVariables.h" 32 33 #import "StringUtilities.h" 33 #import "WebKit2Initialize.h"34 34 #import "WebProcess.h" 35 #import <WebCore/RunLoop.h>36 #import <WebKitSystemInterface.h>37 35 #import <mach/mach_error.h> 38 #import <objc/objc-auto.h>39 36 #import <servers/bootstrap.h> 40 #import <signal.h>41 37 #import <spawn.h> 42 38 #import <stdio.h> 43 #import <sysexits.h>44 #import <unistd.h>45 39 #import <wtf/RetainPtr.h> 46 40 #import <wtf/text/CString.h> … … 49 43 extern "C" kern_return_t bootstrap_register2(mach_port_t, name_t, mach_port_t, uint64_t); 50 44 51 #if USE(APPKIT) 52 @interface NSApplication (WebNSApplicationDetails) 53 -(void)_installAutoreleasePoolsOnCurrentThreadIfNecessary; 54 @end 55 #endif 45 namespace WebKit { 56 46 57 #define SHOW_CRASH_REPORTER 1 47 class WebProcessMainDelegate : public ChildProcessMainDelegate { 48 public: 49 WebProcessMainDelegate(const CommandLine& commandLine) 50 : ChildProcessMainDelegate(commandLine) 51 { 52 } 58 53 59 using namespace WebCore; 54 virtual void doPreInitializationWork() 55 { 56 // Remove the WebProcess shim from the DYLD_INSERT_LIBRARIES environment variable so any processes spawned by 57 // the WebProcess don't try to insert the shim and crash. 58 EnvironmentUtilities::stripValuesEndingWithString("DYLD_INSERT_LIBRARIES", "/WebProcessShim.dylib"); 59 } 60 60 61 namespace WebKit { 61 virtual bool getConnectionIdentifier(CoreIPC::Connection::Identifier& identifier) 62 { 63 String serviceName = m_commandLine["servicename"]; 64 String clientExecutable = m_commandLine["client-executable"]; 65 if (serviceName.isEmpty() && clientExecutable.isEmpty()) 66 return false; 67 68 mach_port_t serverPort; 69 if (clientExecutable.isEmpty()) { 70 kern_return_t kr = bootstrap_look_up(bootstrap_port, serviceName.utf8().data(), &serverPort); 71 if (kr) { 72 WTFLogAlways("bootstrap_look_up result: %s (%x)\n", mach_error_string(kr), kr); 73 return false; 74 } 75 } else { 76 mach_port_name_t publishedService; 77 mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &publishedService); 78 mach_port_insert_right(mach_task_self(), publishedService, publishedService, MACH_MSG_TYPE_MAKE_SEND); 79 // Make it possible to look up. 80 serviceName = String::format("com.apple.WebKit.WebProcess-%d", getpid()); 81 if (kern_return_t kr = bootstrap_register2(bootstrap_port, const_cast<char*>(serviceName.utf8().data()), publishedService, 0)) { 82 WTFLogAlways("Failed to register service name \"%s\". %s (%x)\n", serviceName.utf8().data(), mach_error_string(kr), kr); 83 return false; 84 } 85 86 CString command = clientExecutable.utf8(); 87 const char* args[] = { command.data(), 0 }; 88 89 EnvironmentVariables environmentVariables; 90 environmentVariables.set(EnvironmentVariables::preexistingProcessServiceNameKey(), serviceName.utf8().data()); 91 environmentVariables.set(EnvironmentVariables::preexistingProcessTypeKey(), m_commandLine["type"].utf8().data()); 92 93 posix_spawn_file_actions_t fileActions; 94 posix_spawn_file_actions_init(&fileActions); 95 posix_spawn_file_actions_addinherit_np(&fileActions, STDIN_FILENO); 96 posix_spawn_file_actions_addinherit_np(&fileActions, STDOUT_FILENO); 97 posix_spawn_file_actions_addinherit_np(&fileActions, STDERR_FILENO); 98 99 posix_spawnattr_t attributes; 100 posix_spawnattr_init(&attributes); 101 posix_spawnattr_setflags(&attributes, POSIX_SPAWN_CLOEXEC_DEFAULT | POSIX_SPAWN_SETPGROUP); 102 103 int spawnResult = posix_spawn(0, command.data(), &fileActions, &attributes, const_cast<char**>(args), environmentVariables.environmentPointer()); 104 105 posix_spawnattr_destroy(&attributes); 106 posix_spawn_file_actions_destroy(&fileActions); 107 108 if (spawnResult) 109 return false; 110 111 mach_msg_empty_rcv_t message; 112 if (kern_return_t kr = mach_msg(&message.header, MACH_RCV_MSG, 0, sizeof(message), publishedService, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL)) { 113 WTFLogAlways("Failed to receive port from the UI process. %s (%x)\n", mach_error_string(kr), kr); 114 return false; 115 } 116 117 mach_port_mod_refs(mach_task_self(), publishedService, MACH_PORT_RIGHT_RECEIVE, -1); 118 serverPort = message.header.msgh_remote_port; 119 mach_port_type_t portType; 120 kern_return_t kr = mach_port_type(mach_task_self(), serverPort, &portType); 121 if (kr || !(portType & MACH_PORT_TYPE_SEND)) { 122 WTFLogAlways("Failed to obtain send right for port received from the UI process.\n"); 123 return false; 124 } 125 } 126 127 identifier = serverPort; 128 return true; 129 } 130 131 virtual bool getClientIdentifier(String& clientIdentifier) 132 { 133 String clientExecutable = m_commandLine["client-executable"]; 134 135 if (clientExecutable.isEmpty()) 136 clientIdentifier = m_commandLine["client-identifier"]; 137 else { 138 RetainPtr<NSURL> clientExecutableURL = adoptNS([[NSURL alloc] initFileURLWithPath:nsStringFromWebCoreString(clientExecutable)]); 139 RetainPtr<CFURLRef> clientBundleURL = adoptCF(WKCopyBundleURLForExecutableURL((CFURLRef)clientExecutableURL.get())); 140 RetainPtr<NSBundle> clientBundle = adoptNS([[NSBundle alloc] initWithURL:(NSURL *)clientBundleURL.get()]); 141 clientIdentifier = [clientBundle.get() bundleIdentifier]; 142 } 143 144 if (clientIdentifier.isEmpty()) 145 return false; 146 return true; 147 } 148 }; 62 149 63 150 int WebProcessMain(const CommandLine& commandLine) 64 151 { 65 // Remove the WebProcess shim from the DYLD_INSERT_LIBRARIES environment variable so any processes spawned by 66 // the WebProcess don't try to insert the shim and crash. 67 EnvironmentUtilities::stripValuesEndingWithString("DYLD_INSERT_LIBRARIES", "/WebProcessShim.dylib"); 68 69 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 70 71 String serviceName = commandLine["servicename"]; 72 String clientExecutable; 73 clientExecutable = commandLine["client-executable"]; 74 75 if (serviceName.isEmpty() && clientExecutable.isEmpty()) 76 return EXIT_FAILURE; 77 78 String clientIdentifier; 79 80 // Get the server port. 81 mach_port_t serverPort; 82 if (clientExecutable.isEmpty()) { 83 kern_return_t kr = bootstrap_look_up(bootstrap_port, serviceName.utf8().data(), &serverPort); 84 if (kr) { 85 WTFLogAlways("bootstrap_look_up result: %s (%x)\n", mach_error_string(kr), kr); 86 return 2; 87 } 88 89 clientIdentifier = commandLine["client-identifier"]; 90 if (!clientIdentifier) { 91 WTFLogAlways("No client identifier passed to the WebProcess"); 92 return EXIT_FAILURE; 93 } 94 } else { 95 mach_port_name_t publishedService; 96 mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &publishedService); 97 mach_port_insert_right(mach_task_self(), publishedService, publishedService, MACH_MSG_TYPE_MAKE_SEND); 98 // Make it possible to look up. 99 serviceName = String::format("com.apple.WebKit.WebProcess-%d", getpid()); 100 if (kern_return_t kr = bootstrap_register2(bootstrap_port, const_cast<char*>(serviceName.utf8().data()), publishedService, 0)) { 101 WTFLogAlways("Failed to register service name \"%s\". %s (%x)\n", serviceName.utf8().data(), mach_error_string(kr), kr); 102 return EXIT_FAILURE; 103 } 104 105 CString command = clientExecutable.utf8(); 106 const char* args[] = { command.data(), 0 }; 107 108 EnvironmentVariables environmentVariables; 109 environmentVariables.set(EnvironmentVariables::preexistingProcessServiceNameKey(), serviceName.utf8().data()); 110 environmentVariables.set(EnvironmentVariables::preexistingProcessTypeKey(), commandLine["type"].utf8().data()); 111 112 posix_spawn_file_actions_t fileActions; 113 posix_spawn_file_actions_init(&fileActions); 114 posix_spawn_file_actions_addinherit_np(&fileActions, STDIN_FILENO); 115 posix_spawn_file_actions_addinherit_np(&fileActions, STDOUT_FILENO); 116 posix_spawn_file_actions_addinherit_np(&fileActions, STDERR_FILENO); 117 118 posix_spawnattr_t attributes; 119 posix_spawnattr_init(&attributes); 120 posix_spawnattr_setflags(&attributes, POSIX_SPAWN_CLOEXEC_DEFAULT | POSIX_SPAWN_SETPGROUP); 121 122 int spawnResult = posix_spawn(0, command.data(), &fileActions, &attributes, const_cast<char**>(args), environmentVariables.environmentPointer()); 123 124 posix_spawnattr_destroy(&attributes); 125 posix_spawn_file_actions_destroy(&fileActions); 126 127 if (spawnResult) 128 return 2; 129 130 mach_msg_empty_rcv_t message; 131 if (kern_return_t kr = mach_msg(&message.header, MACH_RCV_MSG, 0, sizeof(message), publishedService, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL)) { 132 WTFLogAlways("Failed to receive port from the UI process. %s (%x)\n", mach_error_string(kr), kr); 133 return EXIT_FAILURE; 134 } 135 136 mach_port_mod_refs(mach_task_self(), publishedService, MACH_PORT_RIGHT_RECEIVE, -1); 137 serverPort = message.header.msgh_remote_port; 138 mach_port_type_t portType; 139 kern_return_t kr = mach_port_type(mach_task_self(), serverPort, &portType); 140 if (kr || !(portType & MACH_PORT_TYPE_SEND)) { 141 WTFLogAlways("Failed to obtain send right for port received from the UI process.\n"); 142 return EXIT_FAILURE; 143 } 144 145 RetainPtr<NSURL> clientExecutableURL = adoptNS([[NSURL alloc] initFileURLWithPath:nsStringFromWebCoreString(clientExecutable)]); 146 RetainPtr<CFURLRef> clientBundleURL = adoptCF(WKCopyBundleURLForExecutableURL((CFURLRef)clientExecutableURL.get())); 147 RetainPtr<NSBundle> clientBundle = adoptNS([[NSBundle alloc] initWithURL:(NSURL *)clientBundleURL.get()]); 148 149 clientIdentifier = [clientBundle.get() bundleIdentifier]; 150 if (!clientIdentifier) { 151 WTFLogAlways("Failed to obtain bundle identifier from the client executable. .\n"); 152 return EXIT_FAILURE; 153 } 154 } 155 156 String localization = commandLine["localization"]; 157 if (!localization.isEmpty()) { 158 RetainPtr<CFStringRef> cfLocalization(AdoptCF, CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar*>(localization.characters()), localization.length())); 159 WKSetDefaultLocalization(cfLocalization.get()); 160 } 161 162 [pool drain]; 163 164 #if !SHOW_CRASH_REPORTER 165 // Installs signal handlers that exit on a crash so that CrashReporter does not show up. 166 signal(SIGILL, _exit); 167 signal(SIGFPE, _exit); 168 signal(SIGBUS, _exit); 169 signal(SIGSEGV, _exit); 170 #endif 171 172 #if USE(APPKIT) 173 // Initialize AppKit. 174 [NSApplication sharedApplication]; 175 176 // Installs autorelease pools on the current CFRunLoop which prevents memory from accumulating between user events. 177 // FIXME: Remove when <rdar://problem/8929426> is fixed. 178 [[NSApplication sharedApplication] _installAutoreleasePoolsOnCurrentThreadIfNecessary]; 179 #endif 180 181 @autoreleasepool { 182 InitializeWebKit2(); 183 184 ChildProcessInitializationParameters parameters; 185 parameters.uiProcessName = commandLine["ui-process-name"]; 186 parameters.clientIdentifier = clientIdentifier; 187 parameters.connectionIdentifier = serverPort; 188 189 WebProcess::shared().initialize(parameters); 190 } 191 192 RunLoop::run(); 193 194 // FIXME: Do more cleanup here. 195 196 return 0; 152 return ChildProcessMain<WebProcess, WebProcessMainDelegate>(commandLine); 197 153 } 198 154
Note: See TracChangeset
for help on using the changeset viewer.