WebKit2/WebProcess/mac/WebProcessMainMac.mm
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 /*
       
     2  * Copyright (C) 2010 Apple Inc. All rights reserved.
       
     3  *
       
     4  * Redistribution and use in source and binary forms, with or without
       
     5  * modification, are permitted provided that the following conditions
       
     6  * are met:
       
     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.
       
    12  *
       
    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.
       
    24  */
       
    25 
       
    26 #import "WebProcessMain.h"
       
    27 
       
    28 #import "CommandLine.h"
       
    29 #import "RunLoop.h"
       
    30 #import "WebProcess.h"
       
    31 #import "WebSystemInterface.h"
       
    32 #import <WebKit2/WKView.h>
       
    33 #import <objc/objc-auto.h>
       
    34 #import <runtime/InitializeThreading.h>
       
    35 #import <servers/bootstrap.h>
       
    36 #import <signal.h>
       
    37 #import <stdio.h>
       
    38 #import <sysexits.h>
       
    39 #import <unistd.h>
       
    40 #import <wtf/Threading.h>
       
    41 
       
    42 #if ENABLE(WEB_PROCESS_SANDBOX)
       
    43 #import <sandbox.h>
       
    44 #endif
       
    45 
       
    46 // FIXME: We should be doing this another way.
       
    47 extern "C" kern_return_t bootstrap_look_up2(mach_port_t, const name_t, mach_port_t*, pid_t, uint64_t);
       
    48 
       
    49 #define SHOW_CRASH_REPORTER 1
       
    50 
       
    51 using namespace WebCore;
       
    52 
       
    53 namespace WebKit {
       
    54 
       
    55 int WebProcessMain(CommandLine*)
       
    56 {
       
    57     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
       
    58 
       
    59 #if ENABLE(WEB_PROCESS_SANDBOX)
       
    60     char* errorBuf;
       
    61     const char* frameworkPath = [[[NSBundle bundleForClass:[WKView class]] bundlePath] UTF8String];
       
    62     const char* profilePath = [[[NSBundle mainBundle] pathForResource:@"com.apple.WebProcess" ofType:@"sb"] UTF8String];
       
    63     const char* const sandboxParam[] = { "webkit2_framework_path", frameworkPath, NULL };
       
    64 
       
    65     if (sandbox_init_with_parameters(profilePath, SANDBOX_NAMED_EXTERNAL, sandboxParam, &errorBuf)) {
       
    66         fprintf(stderr, "WebProcess: couldn't initialize sandbox profile [%s] with framework path [%s]: %s\n", profilePath, frameworkPath, errorBuf);
       
    67         exit(EX_NOPERM);
       
    68     }
       
    69 #endif
       
    70 
       
    71     mach_port_t serverPort;
       
    72     kern_return_t kr = bootstrap_look_up2(bootstrap_port, "com.apple.WebKit.WebProcess", &serverPort, getppid(), /* BOOTSTRAP_PER_PID_SERVICE */ 1);
       
    73     if (kr) {
       
    74         printf("bootstrap_look_up2 result: %x", kr);
       
    75         return 2;
       
    76     }
       
    77     
       
    78 
       
    79 #if !SHOW_CRASH_REPORTER
       
    80     // Installs signal handlers that exit on a crash so that CrashReporter does not show up.
       
    81     signal(SIGILL, _exit);
       
    82     signal(SIGFPE, _exit);
       
    83     signal(SIGBUS, _exit);
       
    84     signal(SIGSEGV, _exit);
       
    85 #endif
       
    86 
       
    87     InitWebCoreSystemInterface();
       
    88     JSC::initializeThreading();
       
    89     WTF::initializeMainThread();
       
    90     RunLoop::initializeMainRunLoop();
       
    91 
       
    92     // Create the connection.
       
    93     WebProcess::shared().initialize(serverPort, RunLoop::main());
       
    94     
       
    95     [pool drain];
       
    96 
       
    97      // Initialize AppKit.
       
    98     [NSApplication sharedApplication];
       
    99 
       
   100     RunLoop::run();
       
   101 
       
   102     // FIXME: Do more cleanup here.
       
   103 
       
   104     return 0;
       
   105 }
       
   106 
       
   107 } // namespace WebKit
       
   108