Switch to entering the sandbox directly from main(), rather than waiting for the...
[WebKit-https.git] / Source / WebKit2 / WebProcess / WebProcess.h
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 #ifndef WebProcess_h
27 #define WebProcess_h
28
29 #include "CacheModel.h"
30 #include "ChildProcess.h"
31 #include "DrawingArea.h"
32 #include "EventDispatcher.h"
33 #include "PluginInfoStore.h"
34 #include "ResourceCachesToClear.h"
35 #include "SandboxExtension.h"
36 #include "SharedMemory.h"
37 #include "TextCheckerState.h"
38 #include "VisitedLinkTable.h"
39 #include "WebConnectionToUIProcess.h"
40 #include "WebGeolocationManager.h"
41 #include "WebIconDatabaseProxy.h"
42 #include "WebPageGroupProxy.h"
43 #include <WebCore/LinkHash.h>
44 #include <wtf/Forward.h>
45 #include <wtf/HashMap.h>
46 #include <wtf/HashSet.h>
47
48 #if USE(SOUP)
49 #include "WebSoupRequestManager.h"
50 #endif
51
52 #if PLATFORM(QT)
53 QT_BEGIN_NAMESPACE
54 class QNetworkAccessManager;
55 QT_END_NAMESPACE
56 #endif
57
58 #if PLATFORM(MAC)
59 #include <dispatch/dispatch.h>
60 #endif
61
62 #if ENABLE(BATTERY_STATUS)
63 #include "WebBatteryManager.h"
64 #endif
65
66 #if ENABLE(NETWORK_INFO)
67 #include "WebNetworkInfoManager.h"
68 #endif
69
70 #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
71 #include "WebNotificationManager.h"
72 #endif
73
74 #if ENABLE(PLUGIN_PROCESS)
75 #include "PluginProcessConnectionManager.h"
76 #endif
77
78 namespace WebCore {
79     class IntSize;
80     class PageGroup;
81 #if ENABLE(WEB_INTENTS)
82     class PlatformMessagePortChannel;
83 #endif
84     class ResourceRequest;
85     class ResourceResponse;
86 }
87
88 namespace WebKit {
89
90 class InjectedBundle;
91 class WebFrame;
92 class WebPage;
93 struct WebPageCreationParameters;
94 struct WebPageGroupData;
95 struct WebPreferencesStore;
96 struct WebProcessCreationParameters;
97
98 #if USE(SECURITY_FRAMEWORK)
99 class SecItemResponseData;
100 class SecKeychainItemResponseData;
101 #endif
102
103 class WebProcess : public ChildProcess, private CoreIPC::Connection::QueueClient {
104 public:
105     static WebProcess& shared();
106
107     void initialize(CoreIPC::Connection::Identifier, WebCore::RunLoop*);
108
109     CoreIPC::Connection* connection() const { return m_connection->connection(); }
110     WebCore::RunLoop* runLoop() const { return m_runLoop; }
111
112     WebConnectionToUIProcess* webConnectionToUIProcess() const { return m_connection.get(); }
113
114     WebPage* webPage(uint64_t pageID) const;
115     void createWebPage(uint64_t pageID, const WebPageCreationParameters&);
116     void removeWebPage(uint64_t pageID);
117     WebPage* focusedWebPage() const;
118
119 #if ENABLE(WEB_INTENTS) 
120     uint64_t addMessagePortChannel(PassRefPtr<WebCore::PlatformMessagePortChannel>);
121     WebCore::PlatformMessagePortChannel* messagePortChannel(uint64_t);
122     void removeMessagePortChannel(uint64_t);
123 #endif
124
125     InjectedBundle* injectedBundle() const { return m_injectedBundle.get(); }
126
127     bool isSeparateProcess() const;
128
129 #if PLATFORM(MAC)
130     void initializeShim();
131     void initializeSandbox(const String& clientIdentifier);
132
133 #if USE(ACCELERATED_COMPOSITING)
134     mach_port_t compositingRenderServerPort() const { return m_compositingRenderServerPort; }
135 #endif
136 #endif
137     
138     void setShouldTrackVisitedLinks(bool);
139     void addVisitedLink(WebCore::LinkHash);
140     bool isLinkVisited(WebCore::LinkHash) const;
141
142     bool fullKeyboardAccessEnabled() const { return m_fullKeyboardAccessEnabled; }
143
144     WebFrame* webFrame(uint64_t) const;
145     void addWebFrame(uint64_t, WebFrame*);
146     void removeWebFrame(uint64_t);
147
148     WebPageGroupProxy* webPageGroup(uint64_t pageGroupID);
149     WebPageGroupProxy* webPageGroup(const WebPageGroupData&);
150 #if PLATFORM(MAC)
151     pid_t presenterApplicationPid() const { return m_presenterApplicationPid; }
152 #endif 
153     
154 #if PLATFORM(QT)
155     QNetworkAccessManager* networkAccessManager() { return m_networkAccessManager; }
156 #endif
157
158     bool shouldUseCustomRepresentationForResponse(const WebCore::ResourceResponse&) const;
159
160     // Text Checking
161     const TextCheckerState& textCheckerState() const { return m_textCheckerState; }
162
163     // Geolocation
164     WebGeolocationManager& geolocationManager() { return m_geolocationManager; }
165
166 #if ENABLE(BATTERY_STATUS)
167     WebBatteryManager& batteryManager() { return m_batteryManager; }
168 #endif
169
170 #if ENABLE(NETWORK_INFO)
171     WebNetworkInfoManager& networkInfoManager() { return m_networkInfoManager; }
172 #endif
173     
174 #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
175     WebNotificationManager& notificationManager() { return m_notificationManager; }
176 #endif
177
178     void clearResourceCaches(ResourceCachesToClear = AllResourceCaches);
179     
180     const String& localStorageDirectory() const { return m_localStorageDirectory; }
181
182 #if ENABLE(PLUGIN_PROCESS)
183     PluginProcessConnectionManager& pluginProcessConnectionManager() { return m_pluginProcessConnectionManager; }
184     bool disablePluginProcessMessageTimeout() const { return m_disablePluginProcessMessageTimeout; }
185 #endif
186
187     EventDispatcher& eventDispatcher() { return m_eventDispatcher; }
188
189 #if USE(SOUP)
190     WebSoupRequestManager& soupRequestManager() { return m_soupRequestManager; }
191 #endif
192
193 private:
194     WebProcess();
195
196     void initializeWebProcess(const WebProcessCreationParameters&, CoreIPC::ArgumentDecoder*);
197     void platformInitializeWebProcess(const WebProcessCreationParameters&, CoreIPC::ArgumentDecoder*);
198     void platformTerminate();
199     void registerURLSchemeAsEmptyDocument(const String&);
200     void registerURLSchemeAsSecure(const String&) const;
201     void setDomainRelaxationForbiddenForURLScheme(const String&) const;
202     void setDefaultRequestTimeoutInterval(double);
203     void setAlwaysUsesComplexTextCodePath(bool);
204     void setShouldUseFontSmoothing(bool);
205     void userPreferredLanguagesChanged(const Vector<String>&) const;
206     void fullKeyboardAccessModeChanged(bool fullKeyboardAccessEnabled);
207 #if PLATFORM(WIN)
208     void setShouldPaintNativeControls(bool);
209 #endif
210
211     void setVisitedLinkTable(const SharedMemory::Handle&);
212     void visitedLinkStateChanged(const Vector<WebCore::LinkHash>& linkHashes);
213     void allVisitedLinkStateChanged();
214
215     void setCacheModel(uint32_t);
216     void platformSetCacheModel(CacheModel);
217     static void calculateCacheSizes(CacheModel cacheModel, uint64_t memorySize, uint64_t diskFreeSize,
218         unsigned& cacheTotalCapacity, unsigned& cacheMinDeadCapacity, unsigned& cacheMaxDeadCapacity, double& deadDecodedDataDeletionInterval,
219         unsigned& pageCacheCapacity, unsigned long& urlCacheMemoryCapacity, unsigned long& urlCacheDiskCapacity);
220     void platformClearResourceCaches(ResourceCachesToClear);
221     void clearApplicationCache();
222
223     void setEnhancedAccessibility(bool);
224     
225 #if !ENABLE(PLUGIN_PROCESS)
226     void getSitesWithPluginData(const Vector<String>& pluginPaths, uint64_t callbackID);
227     void clearPluginSiteData(const Vector<String>& pluginPaths, const Vector<String>& sites, uint64_t flags, uint64_t maxAgeInSeconds, uint64_t callbackID);
228 #endif
229     
230 #if ENABLE(PLUGIN_PROCESS)
231     void pluginProcessCrashed(CoreIPC::Connection*, const String& pluginPath);
232 #endif
233
234     void startMemorySampler(const SandboxExtension::Handle&, const String&, const double);
235     void stopMemorySampler();
236
237     void downloadRequest(uint64_t downloadID, uint64_t initiatingPageID, const WebCore::ResourceRequest&);
238     void cancelDownload(uint64_t downloadID);
239 #if PLATFORM(QT)
240     void startTransfer(uint64_t downloadID, const String& destination);
241 #endif
242
243     void setTextCheckerState(const TextCheckerState&);
244     
245     void getWebCoreStatistics(uint64_t callbackID);
246     void garbageCollectJavaScriptObjects();
247     void setJavaScriptGarbageCollectorTimerEnabled(bool flag);
248
249 #if USE(SECURITY_FRAMEWORK)
250     void secItemResponse(CoreIPC::Connection*, uint64_t requestID, const SecItemResponseData&);
251     void secKeychainItemResponse(CoreIPC::Connection*, uint64_t requestID, const SecKeychainItemResponseData&);
252 #endif
253
254     // ChildProcess
255     virtual bool shouldTerminate();
256     virtual void terminate();
257
258     // CoreIPC::Connection::Client
259     friend class WebConnectionToUIProcess;
260     virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
261     virtual void didReceiveSyncMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, OwnPtr<CoreIPC::ArgumentEncoder>&);
262     virtual void didClose(CoreIPC::Connection*);
263     virtual void didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::MessageID);
264     virtual void syncMessageSendTimedOut(CoreIPC::Connection*);
265 #if PLATFORM(WIN)
266     virtual Vector<HWND> windowsToReceiveSentMessagesWhileWaitingForSyncReply();
267 #endif
268
269     // CoreIPC::Connection::QueueClient
270     virtual void didReceiveMessageOnConnectionWorkQueue(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, bool& didHandleMessage) OVERRIDE;
271
272     // Implemented in generated WebProcessMessageReceiver.cpp
273     void didReceiveWebProcessMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
274     void didReceiveWebProcessMessageOnConnectionWorkQueue(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, bool& didHandleMessage);
275
276     void didGetPlugins(CoreIPC::Connection*, uint64_t requestID, const Vector<WebCore::PluginInfo>&);
277
278     RefPtr<WebConnectionToUIProcess> m_connection;
279
280     HashMap<uint64_t, RefPtr<WebPage> > m_pageMap;
281     HashMap<uint64_t, RefPtr<WebPageGroupProxy> > m_pageGroupMap;
282     RefPtr<InjectedBundle> m_injectedBundle;
283
284     EventDispatcher m_eventDispatcher;
285
286     bool m_inDidClose;
287
288     WebCore::RunLoop* m_runLoop;
289
290     // FIXME: The visited link table should not be per process.
291     VisitedLinkTable m_visitedLinkTable;
292     bool m_shouldTrackVisitedLinks;
293
294     bool m_hasSetCacheModel;
295     CacheModel m_cacheModel;
296
297 #if USE(ACCELERATED_COMPOSITING) && PLATFORM(MAC)
298     mach_port_t m_compositingRenderServerPort;
299 #endif
300 #if PLATFORM(MAC)
301     pid_t m_presenterApplicationPid;
302     dispatch_group_t m_clearResourceCachesDispatchGroup;
303 #endif
304
305     bool m_fullKeyboardAccessEnabled;
306
307 #if PLATFORM(QT)
308     QNetworkAccessManager* m_networkAccessManager;
309 #endif
310
311     HashMap<uint64_t, WebFrame*> m_frameMap;
312
313 #if ENABLE(WEB_INTENTS)
314     HashMap<uint64_t, RefPtr<WebCore::PlatformMessagePortChannel> > m_messagePortChannels;
315 #endif
316
317     HashSet<String, CaseFoldingHash> m_mimeTypesWithCustomRepresentations;
318
319     TextCheckerState m_textCheckerState;
320     WebGeolocationManager m_geolocationManager;
321 #if ENABLE(BATTERY_STATUS)
322     WebBatteryManager m_batteryManager;
323 #endif
324 #if ENABLE(NETWORK_INFO)
325     WebNetworkInfoManager m_networkInfoManager;
326 #endif
327 #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
328     WebNotificationManager m_notificationManager;
329 #endif
330     WebIconDatabaseProxy m_iconDatabaseProxy;
331     
332     String m_localStorageDirectory;
333
334 #if ENABLE(PLUGIN_PROCESS)
335     PluginProcessConnectionManager m_pluginProcessConnectionManager;
336     bool m_disablePluginProcessMessageTimeout;
337 #endif
338
339 #if USE(SOUP)
340     WebSoupRequestManager m_soupRequestManager;
341 #endif
342
343 };
344
345 } // namespace WebKit
346
347 #endif // WebProcess_h