Home | History | Annotate | Download | only in mac
      1 /*
      2  * Copyright (C) 2010, 2011 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 "config.h"
     27 #import "PluginProcessMain.h"
     28 
     29 #if ENABLE(PLUGIN_PROCESS)
     30 
     31 #import "CommandLine.h"
     32 #import "PluginProcess.h"
     33 #import "RunLoop.h"
     34 #import <WebKitSystemInterface.h>
     35 #import <runtime/InitializeThreading.h>
     36 #import <servers/bootstrap.h>
     37 #import <wtf/RetainPtr.h>
     38 #import <wtf/text/CString.h>
     39 #import <wtf/text/WTFString.h>
     40 
     41 // FIXME: We should be doing this another way.
     42 extern "C" kern_return_t bootstrap_look_up2(mach_port_t, const name_t, mach_port_t*, pid_t, uint64_t);
     43 
     44 #define SHOW_CRASH_REPORTER 1
     45 
     46 namespace WebKit {
     47 
     48 // FIXME: There is much code here that is duplicated in WebProcessMainMac.mm, we should add a shared base class where
     49 // we can put everything.
     50 
     51 int PluginProcessMain(const CommandLine& commandLine)
     52 {
     53     // Unset DYLD_INSERT_LIBRARIES. We don't want our plug-in process shim to be loaded
     54     // by any child processes that the plug-in may launch.
     55     unsetenv("DYLD_INSERT_LIBRARIES");
     56 
     57     String serviceName = commandLine["servicename"];
     58     if (serviceName.isEmpty())
     59         return EXIT_FAILURE;
     60 
     61     // Get the server port.
     62     mach_port_t serverPort;
     63     kern_return_t kr = bootstrap_look_up2(bootstrap_port, serviceName.utf8().data(), &serverPort, 0, 0);
     64     if (kr) {
     65         printf("bootstrap_look_up2 result: %x", kr);
     66         return EXIT_FAILURE;
     67     }
     68 
     69     String localization = commandLine["localization"];
     70     RetainPtr<CFStringRef> cfLocalization(AdoptCF, CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar*>(localization.characters()), localization.length()));
     71     if (cfLocalization)
     72         WKSetDefaultLocalization(cfLocalization.get());
     73 
     74 #if !SHOW_CRASH_REPORTER
     75     // Installs signal handlers that exit on a crash so that CrashReporter does not show up.
     76     signal(SIGILL, _exit);
     77     signal(SIGFPE, _exit);
     78     signal(SIGBUS, _exit);
     79     signal(SIGSEGV, _exit);
     80 #endif
     81 
     82     // FIXME: It would be better to proxy set cursor calls over to the UI process instead of
     83     // allowing plug-ins to change the mouse cursor at any time.
     84     WKEnableSettingCursorWhenInBackground();
     85 
     86     JSC::initializeThreading();
     87     WTF::initializeMainThread();
     88     RunLoop::initializeMainRunLoop();
     89 
     90     // Initialize the shim.
     91     PluginProcess::shared().initializeShim();
     92 
     93     // Initialize the plug-in process connection.
     94     PluginProcess::shared().initialize(serverPort, RunLoop::main());
     95 
     96     [NSApplication sharedApplication];
     97 
     98     RunLoop::run();
     99 
    100     return 0;
    101 }
    102 
    103 }
    104 
    105 #endif // ENABLE(PLUGIN_PROCESS)
    106