225b6f037f973ab71a0d38e9306fc33292b06a46
[framework/web/webkit-efl.git] / Source / WebKit2 / PluginProcess / efl / PluginProcessMainEfl.cpp
1 /*
2  * Copyright (C) 2011 Igalia S.L.
3  * Copyright (C) 2011 Apple Inc.
4  * Copyright (C) 2011 Samsung Electronics
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
19  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
25  * THE POSSIBILITY OF SUCH DAMAGE.
26  */
27
28 #include "config.h"
29 #include "PluginProcessMainEfl.h"
30
31 #include "PluginProcess.h"
32 #include <Ecore.h>
33 #include <Ecore_X.h>
34 #include <WebCore/RunLoop.h>
35 #include <runtime/InitializeThreading.h>
36 #include <wtf/MainThread.h>
37
38 #if defined(XP_UNIX)
39 #include <X11/Xlib.h>
40 #endif
41
42 #if ENABLE(TIZEN_SCAN_PLUGIN)
43 #include "NetscapePlugin.h"
44 #endif // ENABLE(TIZEN_SCAN_PLUGIN)
45
46 #if ENABLE(TIZEN_PROCESS_PERMISSION_CONTROL)
47 #include "ProcessSmackLabel.h"
48 #endif
49
50 using namespace WebCore;
51
52 namespace WebKit {
53
54 #if defined(XP_UNIX)
55 static int webkiteflXError(Display* xdisplay, XErrorEvent* error)
56 {
57     char errorMessage[64];
58     XGetErrorText(xdisplay, error->error_code, errorMessage, 63);
59     printf("The program received an X Window System error.\n"
60               "This probably reflects a bug in a browser plugin.\n"
61               "The error was '%s'.\n"
62               "  (Details: serial %ld error_code %d request_code %d minor_code %d)\n",
63               errorMessage,
64               error->serial, error->error_code,
65               error->request_code, error->minor_code);
66     return 0;
67 }
68 #endif
69
70 WK_EXPORT int PluginProcessMainEfl(int argc, char* argv[])
71 {
72 #if ENABLE(TIZEN_SCAN_PLUGIN)
73     ASSERT(argc == 2 || argc == 3);
74     bool scanPlugin = !strcmp(argv[1], "-scanPlugin");
75     ASSERT(argc == 2 || (argc == 3 && scanPlugin));
76 #else
77     ASSERT(argc == 2);
78 #endif // ENABLE(TIZEN_SCAN_PLUGIN)
79
80 #if ENABLE(TIZEN_PROCESS_PERMISSION_CONTROL)
81     // check process smack label
82     if (!changeProcessSmackLabel("/usr/bin/PluginProcess", argv[0])) {
83         TIZEN_LOGI("failed to change smack label");
84         return 1;
85     }
86
87     // drop CAP_MAC_ADMIN capability
88     if (!dropProcessCapability()) {
89         TIZEN_LOGI("failed to drop CAP_MAC_ADMIN");
90         return 1;
91     }
92 #endif
93     if (!eina_init())
94         return 1;
95
96     if (!ecore_x_init(0))
97         return 1;
98
99     JSC::initializeThreading();
100     WTF::initializeMainThread();
101 #if !LOG_DISABLED && ENABLE(TIZEN_LOG)
102     WebCore::initializeLoggingChannelsIfNecessary();
103 #endif
104
105 #if ENABLE(TIZEN_SCAN_PLUGIN)
106     if (scanPlugin) {
107 #if ENABLE(TIZEN_LOG)
108         TIZEN_LOGI("[Plugins] scan plugin");
109 #endif
110         String pluginPath(argv[2]);
111         if (!NetscapePluginModule::scanPlugin(pluginPath))
112             return 1;
113         return 0;
114     }
115 #endif // ENABLE(TIZEN_SCAN_PLUGIN)
116
117     RunLoop::initializeMainRunLoop();
118
119 #if defined(XP_UNIX)
120     XSetErrorHandler(webkiteflXError);
121 #endif
122
123     int socket = atoi(argv[1]);
124     WebKit::PluginProcess::shared().initialize(socket, RunLoop::main());
125     RunLoop::run();
126
127     return 0;
128 }
129
130 } // namespace WebKit