0adb6a88e0cb4a3aecfec67d038204fcc7a2ae98
[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 "DownloadManager.h"
32 #include "DrawingArea.h"
33 #include "EventDispatcher.h"
34 #include "MessageReceiverMap.h"
35 #include "PluginInfoStore.h"
36 #include "ResourceCachesToClear.h"
37 #include "SandboxExtension.h"
38 #include "SharedMemory.h"
39 #include "TextCheckerState.h"
40 #include "VisitedLinkTable.h"
41 #include "WebConnectionToUIProcess.h"
42 #include "WebGeolocationManager.h"
43 #include "WebIconDatabaseProxy.h"
44 #include "WebPageGroupProxy.h"
45 #include <WebCore/LinkHash.h>
46 #include <wtf/Forward.h>
47 #include <wtf/HashMap.h>
48 #include <wtf/HashSet.h>
49
50 #if USE(SOUP)
51 #include "WebSoupRequestManager.h"
52 #endif
53
54 #if PLATFORM(QT)
55 QT_BEGIN_NAMESPACE
56 class QNetworkAccessManager;
57 QT_END_NAMESPACE
58 #endif
59
60 #if PLATFORM(MAC)
61 #include <dispatch/dispatch.h>
62 #endif
63
64 #if ENABLE(BATTERY_STATUS)
65 #include "WebBatteryManager.h"
66 #endif
67
68 #if ENABLE(NETWORK_INFO)
69 #include "WebNetworkInfoManager.h"
70 #endif
71
72 #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
73 #include "WebNotificationManager.h"
74 #endif
75
76 #if ENABLE(NETWORK_PROCESS)
77 #include "WebResourceLoadScheduler.h"
78 #endif
79
80 #if ENABLE(PLUGIN_PROCESS)
81 #include "PluginProcessConnectionManager.h"
82 #endif
83
84 namespace WebCore {
85     class IntSize;
86     class PageGroup;
87 #if ENABLE(WEB_INTENTS)
88     class PlatformMessagePortChannel;
89 #endif
90     class ResourceRequest;
91     class ResourceResponse;
92 }
93
94 namespace WebKit {
95
96 class InjectedBundle;
97 class WebFrame;
98 class WebPage;
99 struct WebPageCreationParameters;
100 struct WebPageGroupData;
101 struct WebPreferencesStore;
102 struct WebProcessCreationParameters;
103
104 #if ENABLE(NETWORK_PROCESS)
105 class NetworkProcessConnection;
106 #endif
107
108 #if USE(SECURITY_FRAMEWORK)
109 class SecItemResponseData;
110 #endif
111
112 class WebProcess : public ChildProcess, private CoreIPC::Connection::QueueClient, private DownloadManager::Client {
113 public:
114     static WebProcess& shared();
115
116     void initialize(CoreIPC::Connection::Identifier, WebCore::RunLoop*);
117
118     CoreIPC::Connection* connection() const { return m_connection.get(); }
119     WebCore::RunLoop* runLoop() const { return m_runLoop; }
120
121     void addMessageReceiver(CoreIPC::StringReference messageReceiverName, CoreIPC::MessageReceiver*);
122     void addMessageReceiver(CoreIPC::StringReference messageReceiverName, uint64_t destinationID, CoreIPC::MessageReceiver*);
123     void removeMessageReceiver(CoreIPC::StringReference messageReceiverName, uint64_t destinationID);
124
125     WebConnectionToUIProcess* webConnectionToUIProcess() const { return m_webConnection.get(); }
126
127     WebPage* webPage(uint64_t pageID) const;
128     void createWebPage(uint64_t pageID, const WebPageCreationParameters&);
129     void removeWebPage(uint64_t pageID);
130     WebPage* focusedWebPage() const;
131
132 #if ENABLE(WEB_INTENTS) 
133     uint64_t addMessagePortChannel(PassRefPtr<WebCore::PlatformMessagePortChannel>);
134     WebCore::PlatformMessagePortChannel* messagePortChannel(uint64_t);
135     void removeMessagePortChannel(uint64_t);
136 #endif
137
138     InjectedBundle* injectedBundle() const { return m_injectedBundle.get(); }
139
140     bool isSeparateProcess() const;
141
142 #if PLATFORM(MAC)
143     void initializeShim();
144     void initializeSandbox(const String& clientIdentifier);
145
146 #if USE(ACCELERATED_COMPOSITING)
147     mach_port_t compositingRenderServerPort() const { return m_compositingRenderServerPort; }
148 #endif
149 #endif
150     
151     void setShouldTrackVisitedLinks(bool);
152     void addVisitedLink(WebCore::LinkHash);
153     bool isLinkVisited(WebCore::LinkHash) const;
154
155     bool isPlugInAutoStartOrigin(unsigned plugInOriginhash);
156     void addPlugInAutoStartOrigin(const String& pageOrigin, unsigned plugInOriginHash);
157
158     bool fullKeyboardAccessEnabled() const { return m_fullKeyboardAccessEnabled; }
159
160     WebFrame* webFrame(uint64_t) const;
161     void addWebFrame(uint64_t, WebFrame*);
162     void removeWebFrame(uint64_t);
163
164     WebPageGroupProxy* webPageGroup(uint64_t pageGroupID);
165     WebPageGroupProxy* webPageGroup(const WebPageGroupData&);
166 #if PLATFORM(MAC)
167     pid_t presenterApplicationPid() const { return m_presenterApplicationPid; }
168     bool shouldForceScreenFontSubstitution() const { return m_shouldForceScreenFontSubstitution; }
169 #endif
170     
171 #if PLATFORM(QT)
172     QNetworkAccessManager* networkAccessManager() { return m_networkAccessManager; }
173 #endif
174
175     // Text Checking
176     const TextCheckerState& textCheckerState() const { return m_textCheckerState; }
177
178     // Geolocation
179     WebGeolocationManager& geolocationManager() { return m_geolocationManager; }
180
181 #if ENABLE(BATTERY_STATUS)
182     WebBatteryManager& batteryManager() { return m_batteryManager; }
183 #endif
184
185 #if ENABLE(NETWORK_INFO)
186     WebNetworkInfoManager& networkInfoManager() { return m_networkInfoManager; }
187 #endif
188     
189 #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
190     WebNotificationManager& notificationManager() { return m_notificationManager; }
191 #endif
192
193     void clearResourceCaches(ResourceCachesToClear = AllResourceCaches);
194     
195     const String& localStorageDirectory() const { return m_localStorageDirectory; }
196
197 #if ENABLE(PLUGIN_PROCESS)
198     PluginProcessConnectionManager& pluginProcessConnectionManager() { return m_pluginProcessConnectionManager; }
199 #endif
200
201     EventDispatcher& eventDispatcher() { return m_eventDispatcher; }
202
203 #if USE(SOUP)
204     WebSoupRequestManager& soupRequestManager() { return m_soupRequestManager; }
205 #endif
206
207 #if ENABLE(NETWORK_PROCESS)
208     NetworkProcessConnection* networkConnection();
209     void networkProcessConnectionClosed(NetworkProcessConnection*);
210     bool usesNetworkProcess() const { return m_usesNetworkProcess; }
211     WebResourceLoadScheduler& webResourceLoadScheduler() { return m_webResourceLoadScheduler; }
212 #endif
213
214     void setCacheModel(uint32_t);
215
216     void ensurePrivateBrowsingSession();
217     void destroyPrivateBrowsingSession();
218
219     DownloadManager& downloadManager();
220
221 private:
222     WebProcess();
223
224     // DownloadManager::Client.
225     virtual void didCreateDownload() OVERRIDE;
226     virtual void didDestroyDownload() OVERRIDE;
227
228     void initializeWebProcess(const WebProcessCreationParameters&, CoreIPC::MessageDecoder&);
229     void platformInitializeWebProcess(const WebProcessCreationParameters&, CoreIPC::MessageDecoder&);
230     void platformTerminate();
231     void registerURLSchemeAsEmptyDocument(const String&);
232     void registerURLSchemeAsSecure(const String&) const;
233     void setDomainRelaxationForbiddenForURLScheme(const String&) const;
234     void registerURLSchemeAsLocal(const String&) const;
235     void registerURLSchemeAsNoAccess(const String&) const;
236     void registerURLSchemeAsDisplayIsolated(const String&) const;
237     void registerURLSchemeAsCORSEnabled(const String&) const;
238     void setDefaultRequestTimeoutInterval(double);
239     void setAlwaysUsesComplexTextCodePath(bool);
240     void setShouldUseFontSmoothing(bool);
241     void userPreferredLanguagesChanged(const Vector<String>&) const;
242     void fullKeyboardAccessModeChanged(bool fullKeyboardAccessEnabled);
243 #if PLATFORM(WIN)
244     void setShouldPaintNativeControls(bool);
245 #endif
246
247     void setVisitedLinkTable(const SharedMemory::Handle&);
248     void visitedLinkStateChanged(const Vector<WebCore::LinkHash>& linkHashes);
249     void allVisitedLinkStateChanged();
250
251     void didAddPlugInAutoStartOrigin(unsigned plugInOriginHash);
252
253     void platformSetCacheModel(CacheModel);
254     void platformClearResourceCaches(ResourceCachesToClear);
255     void clearApplicationCache();
256
257     void setEnhancedAccessibility(bool);
258     
259 #if !ENABLE(PLUGIN_PROCESS)
260     void getSitesWithPluginData(const Vector<String>& pluginPaths, uint64_t callbackID);
261     void clearPluginSiteData(const Vector<String>& pluginPaths, const Vector<String>& sites, uint64_t flags, uint64_t maxAgeInSeconds, uint64_t callbackID);
262 #endif
263
264 #if ENABLE(NETWORK_PROCESS)
265     void networkProcessCrashed(CoreIPC::Connection*);
266 #endif
267 #if ENABLE(PLUGIN_PROCESS)
268     void pluginProcessCrashed(CoreIPC::Connection*, const String& pluginPath, uint32_t processType);
269 #endif
270
271     void startMemorySampler(const SandboxExtension::Handle&, const String&, const double);
272     void stopMemorySampler();
273
274     void downloadRequest(uint64_t downloadID, uint64_t initiatingPageID, const WebCore::ResourceRequest&);
275     void cancelDownload(uint64_t downloadID);
276 #if PLATFORM(QT)
277     void startTransfer(uint64_t downloadID, const String& destination);
278 #endif
279
280     void setTextCheckerState(const TextCheckerState&);
281     
282     void getWebCoreStatistics(uint64_t callbackID);
283     void garbageCollectJavaScriptObjects();
284     void setJavaScriptGarbageCollectorTimerEnabled(bool flag);
285
286     void postInjectedBundleMessage(const CoreIPC::DataReference& messageData);
287
288 #if USE(SECURITY_FRAMEWORK)
289     void secItemResponse(CoreIPC::Connection*, uint64_t requestID, const SecItemResponseData&);
290 #endif
291
292     // ChildProcess
293     virtual bool shouldTerminate();
294     virtual void terminate();
295
296     // CoreIPC::Connection::Client
297     friend class WebConnectionToUIProcess;
298     virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&);
299     virtual void didReceiveSyncMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&, OwnPtr<CoreIPC::MessageEncoder>&);
300     virtual void didClose(CoreIPC::Connection*);
301     virtual void didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::StringReference messageReceiverName, CoreIPC::StringReference messageName) OVERRIDE;
302 #if PLATFORM(WIN)
303     virtual Vector<HWND> windowsToReceiveSentMessagesWhileWaitingForSyncReply();
304 #endif
305
306     // CoreIPC::Connection::QueueClient
307     virtual void didReceiveMessageOnConnectionWorkQueue(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&, bool& didHandleMessage) OVERRIDE;
308
309     // Implemented in generated WebProcessMessageReceiver.cpp
310     void didReceiveWebProcessMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&);
311     void didReceiveWebProcessMessageOnConnectionWorkQueue(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&, bool& didHandleMessage);
312
313 #if ENABLE(NETSCAPE_PLUGIN_API)
314     void didGetPlugins(CoreIPC::Connection*, uint64_t requestID, const Vector<WebCore::PluginInfo>&);
315 #endif
316
317 #if ENABLE(CUSTOM_PROTOCOLS)
318     void registerSchemeForCustomProtocol(const WTF::String&);
319     void unregisterSchemeForCustomProtocol(const WTF::String&);
320 #endif
321
322     RefPtr<CoreIPC::Connection> m_connection;
323     CoreIPC::MessageReceiverMap m_messageReceiverMap;
324
325     RefPtr<WebConnectionToUIProcess> m_webConnection;
326
327     HashMap<uint64_t, RefPtr<WebPage> > m_pageMap;
328     HashMap<uint64_t, RefPtr<WebPageGroupProxy> > m_pageGroupMap;
329     RefPtr<InjectedBundle> m_injectedBundle;
330
331     EventDispatcher m_eventDispatcher;
332
333     bool m_inDidClose;
334
335     WebCore::RunLoop* m_runLoop;
336
337     // FIXME: The visited link table should not be per process.
338     VisitedLinkTable m_visitedLinkTable;
339     bool m_shouldTrackVisitedLinks;
340
341     HashSet<unsigned> m_plugInAutoStartOrigins;
342
343     bool m_hasSetCacheModel;
344     CacheModel m_cacheModel;
345
346 #if USE(ACCELERATED_COMPOSITING) && PLATFORM(MAC)
347     mach_port_t m_compositingRenderServerPort;
348 #endif
349 #if PLATFORM(MAC)
350     pid_t m_presenterApplicationPid;
351     dispatch_group_t m_clearResourceCachesDispatchGroup;
352     bool m_shouldForceScreenFontSubstitution;
353 #endif
354
355     bool m_fullKeyboardAccessEnabled;
356
357 #if PLATFORM(QT)
358     QNetworkAccessManager* m_networkAccessManager;
359 #endif
360
361     HashMap<uint64_t, WebFrame*> m_frameMap;
362
363 #if ENABLE(WEB_INTENTS)
364     HashMap<uint64_t, RefPtr<WebCore::PlatformMessagePortChannel> > m_messagePortChannels;
365 #endif
366
367     TextCheckerState m_textCheckerState;
368     WebGeolocationManager m_geolocationManager;
369 #if ENABLE(BATTERY_STATUS)
370     WebBatteryManager m_batteryManager;
371 #endif
372 #if ENABLE(NETWORK_INFO)
373     WebNetworkInfoManager m_networkInfoManager;
374 #endif
375 #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
376     WebNotificationManager m_notificationManager;
377 #endif
378     WebIconDatabaseProxy m_iconDatabaseProxy;
379     
380     String m_localStorageDirectory;
381
382 #if ENABLE(NETWORK_PROCESS)
383     void ensureNetworkProcessConnection();
384     RefPtr<NetworkProcessConnection> m_networkProcessConnection;
385     bool m_usesNetworkProcess;
386     WebResourceLoadScheduler m_webResourceLoadScheduler;
387 #endif
388
389 #if ENABLE(PLUGIN_PROCESS)
390     PluginProcessConnectionManager m_pluginProcessConnectionManager;
391 #endif
392
393 #if USE(SOUP)
394     WebSoupRequestManager m_soupRequestManager;
395 #endif
396
397 };
398
399 } // namespace WebKit
400
401 #endif // WebProcess_h