8d608265def2b8e558b998522e8ccd3a2a54d6e8
[framework/web/webkit-efl.git] / Source / WebKit2 / WebProcess / efl / WebProcessMainEfl.cpp
1 /*
2  * Copyright (C) 2011 Samsung Electronics. 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 #include "config.h"
27 #include "WebProcessMainEfl.h"
28
29 #include "ProxyResolverSoup.h"
30 #include "WKBase.h"
31 #include <Ecore.h>
32 #include <Ecore_File.h>
33 #include <WebCore/ResourceHandle.h>
34 #include <WebCore/RunLoop.h>
35 #include <WebKit2/WebProcess.h>
36 #include <runtime/InitializeThreading.h>
37 #include <unistd.h>
38 #include <wtf/MainThread.h>
39
40 #ifdef HAVE_ECORE_X
41 #include <Ecore_X.h>
42 #endif
43
44 #if USE(ACCELERATED_COMPOSITING)
45 #include "WebGraphicsLayer.h"
46 #endif
47
48 #if ENABLE(TIZEN_NATIVE_MEMORY_SNAPSHOT)
49 #include "WebPage.h"
50 #endif
51
52 #if ENABLE(TIZEN_USE_STACKPOINTER_AT_WEBPROCESS_STARTUP)
53 #include "wtf/WTFThreadData.h"
54 #endif
55
56 #if ENABLE(TIZEN_PROCESS_PERMISSION_CONTROL)
57 #include "ProcessSmackLabel.h"
58 #endif
59
60 using namespace WebCore;
61
62 namespace WebKit {
63
64 #if ENABLE(TIZEN_NATIVE_MEMORY_SNAPSHOT)
65 void webkit_memory_dump_cb(void* data, Ecore_File_Monitor* monitor, Ecore_File_Event event, const char* path)
66 {
67     if (event == ECORE_FILE_EVENT_MODIFIED)
68         dumpMemorySnapshot();
69 }
70 #endif
71
72 WK_EXPORT int WebProcessMainEfl(int argc, char* argv[])
73 {
74     // WebProcess should be launched with an option.
75     if (argc != 2)
76         return 1;
77
78 #if ENABLE(TIZEN_PROCESS_PERMISSION_CONTROL)
79     // change process smack label
80     if (!changeProcessSmackLabel("/usr/bin/WebProcess", argv[0])) {
81         TIZEN_LOGI("failed to change smack label");
82         return 1;
83     }
84     // drop CAP_MAC_ADMIN capability
85     if (!dropProcessCapability()) {
86         TIZEN_LOGI("failed to drop CAP_MAC_ADMIN");
87         return 1;
88     }
89 #endif
90
91     if (!eina_init())
92         return 1;
93
94     if (!ecore_init()) {
95         // Could not init ecore.
96         eina_shutdown();
97         return 1;
98     }
99
100     if (!ecore_x_init(0)) {
101         // Could not init ecore_x.
102         // PlatformScreenEfl and systemBeep() functions
103         // depend on ecore_x functionality.
104         ecore_shutdown();
105         eina_shutdown();
106         return 1;
107     }
108
109     if (!ecore_file_init()) {
110         ecore_x_shutdown();
111         ecore_shutdown();
112         eina_shutdown();
113         return 1;
114     }
115
116 #if ENABLE(TIZEN_USE_STACKPOINTER_AT_WEBPROCESS_STARTUP)
117     void* dummy;
118     wtfThreadData().setJsStackOrigin(&dummy);
119 #endif
120
121 #if ENABLE(GLIB_SUPPORT)
122     g_type_init();
123
124     if (!ecore_main_loop_glib_integrate())
125         return 1;
126 #endif
127
128     JSC::initializeThreading();
129     WTF::initializeMainThread();
130
131     RunLoop::initializeMainRunLoop();
132
133     SoupSession* session = WebCore::ResourceHandle::defaultSession();
134     const char* httpProxy = getenv("http_proxy");
135     if (httpProxy) {
136         const char* noProxy = getenv("no_proxy");
137         SoupProxyURIResolver* resolverEfl = soupProxyResolverWkNew(httpProxy, noProxy);
138         soup_session_add_feature(session, SOUP_SESSION_FEATURE(resolverEfl));
139         g_object_unref(resolverEfl);
140     }
141
142 #if ENABLE(TIZEN_NATIVE_MEMORY_SNAPSHOT)
143     const char* isMemorySnapshot = getenv("TIZEN_MEMORY_SNAPSHOT");
144     if (isMemorySnapshot && isMemorySnapshot[0] != '0')
145         ecore_file_monitor_add("/tmp/webkit_memory_dump", webkit_memory_dump_cb, NULL);
146 #endif
147
148 #if USE(ACCELERATED_COMPOSITING)
149     WebCore::WebGraphicsLayer::initFactory();
150 #endif
151
152     int socket = atoi(argv[1]);
153     WebProcess::shared().initialize(socket, RunLoop::main());
154     RunLoop::run();
155
156     ecore_file_shutdown();
157     ecore_x_shutdown();
158     ecore_shutdown();
159     eina_shutdown();
160
161     return 0;
162
163 }
164
165 } // namespace WebKit