2 * Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
27 #import "WebProcessMain.h"
29 #import "CommandLine.h"
30 #import "EnvironmentUtilities.h"
32 #import "WebProcess.h"
33 #import "WebSystemInterface.h"
34 #import <WebKit2/WKView.h>
35 #import <WebKitSystemInterface.h>
36 #import <objc/objc-auto.h>
37 #import <runtime/InitializeThreading.h>
38 #import <servers/bootstrap.h>
43 #import <wtf/RetainPtr.h>
44 #import <wtf/MainThread.h>
45 #import <wtf/text/CString.h>
46 #import <wtf/text/StringBuilder.h>
48 // FIXME: We should be doing this another way.
49 extern "C" kern_return_t bootstrap_look_up2(mach_port_t, const name_t, mach_port_t*, pid_t, uint64_t);
51 @interface NSApplication (WebNSApplicationDetails)
52 -(void)_installAutoreleasePoolsOnCurrentThreadIfNecessary;
55 #define SHOW_CRASH_REPORTER 1
57 using namespace WebCore;
61 int WebProcessMain(const CommandLine& commandLine)
63 #ifdef BUILDING_ON_SNOW_LEOPARD
64 // Remove the WebProcess shim from the DYLD_INSERT_LIBRARIES environment variable so any processes spawned by
65 // the WebProcess don't try to insert the shim and crash.
66 EnvironmentUtilities::stripValuesEndingWithString("DYLD_INSERT_LIBRARIES", "/WebProcessShim.dylib");
69 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
71 String serviceName = commandLine["servicename"];
72 if (serviceName.isEmpty())
75 // Get the server port.
76 mach_port_t serverPort;
77 kern_return_t kr = bootstrap_look_up2(bootstrap_port, serviceName.utf8().data(), &serverPort, 0, 0);
79 printf("bootstrap_look_up2 result: %x", kr);
83 String localization = commandLine["localization"];
84 RetainPtr<CFStringRef> cfLocalization(AdoptCF, CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar*>(localization.characters()), localization.length()));
86 WKSetDefaultLocalization(cfLocalization.get());
88 #if !SHOW_CRASH_REPORTER
89 // Installs signal handlers that exit on a crash so that CrashReporter does not show up.
90 signal(SIGILL, _exit);
91 signal(SIGFPE, _exit);
92 signal(SIGBUS, _exit);
93 signal(SIGSEGV, _exit);
96 InitWebCoreSystemInterface();
97 JSC::initializeThreading();
98 WTF::initializeMainThread();
99 RunLoop::initializeMainRunLoop();
101 // Initialize the shim.
102 WebProcess::shared().initializeShim();
104 // Create the connection.
105 WebProcess::shared().initialize(serverPort, RunLoop::main());
109 // Initialize AppKit.
110 [NSApplication sharedApplication];
112 // Installs autorelease pools on the current CFRunLoop which prevents memory from accumulating between user events.
113 // FIXME: Remove when <rdar://problem/8929426> is fixed.
114 [[NSApplication sharedApplication] _installAutoreleasePoolsOnCurrentThreadIfNecessary];
116 WKAXRegisterRemoteApp();
120 // FIXME: Do more cleanup here.
125 } // namespace WebKit