[WK2] Make the WebSoupRequestManager a supplement to the WebProcess
[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 "PluginProcessConnectionManager.h"
33 #include "ResourceCachesToClear.h"
34 #include "SandboxExtension.h"
35 #include "SharedMemory.h"
36 #include "TextCheckerState.h"
37 #include "VisitedLinkTable.h"
38 #include <WebCore/LinkHash.h>
39 #include <WebCore/Timer.h>
40 #include <wtf/Forward.h>
41 #include <wtf/HashMap.h>
42 #include <wtf/HashSet.h>
43 #include <wtf/text/AtomicString.h>
44 #include <wtf/text/AtomicStringHash.h>
45
46 #if PLATFORM(QT)
47 QT_BEGIN_NAMESPACE
48 class QNetworkAccessManager;
49 QT_END_NAMESPACE
50 #endif
51
52 #if PLATFORM(MAC)
53 #include <dispatch/dispatch.h>
54 #endif
55
56 namespace WebCore {
57 class PageGroup;
58 class ResourceRequest;
59 struct PluginInfo;
60 }
61
62 namespace WebKit {
63
64 class DownloadManager;
65 class EventDispatcher;
66 class InjectedBundle;
67 class WebConnectionToUIProcess;
68 class WebFrame;
69 class WebIconDatabaseProxy;
70 class WebPage;
71 class WebPageGroupProxy;
72 class WebProcessSupplement;
73 struct WebPageCreationParameters;
74 struct WebPageGroupData;
75 struct WebPreferencesStore;
76 struct WebProcessCreationParameters;
77
78 #if ENABLE(NETWORK_PROCESS)
79 class NetworkProcessConnection;
80 class WebResourceLoadScheduler;
81 #endif
82
83 class WebProcess : public ChildProcess, private DownloadManager::Client {
84 public:
85     static WebProcess& shared();
86
87     template <typename T>
88     T* supplement()
89     {
90         return static_cast<T*>(m_supplements.get(T::supplementName()));
91     }
92
93     template <typename T>
94     void addSupplement()
95     {
96         m_supplements.add(T::supplementName(), adoptPtr<WebProcessSupplement>(new T(this)));
97     }
98
99     WebConnectionToUIProcess* webConnectionToUIProcess() const { return m_webConnection.get(); }
100
101     WebPage* webPage(uint64_t pageID) const;
102     void createWebPage(uint64_t pageID, const WebPageCreationParameters&);
103     void removeWebPage(uint64_t pageID);
104     WebPage* focusedWebPage() const;
105
106     InjectedBundle* injectedBundle() const { return m_injectedBundle.get(); }
107
108 #if PLATFORM(MAC)
109 #if USE(ACCELERATED_COMPOSITING)
110     mach_port_t compositingRenderServerPort() const { return m_compositingRenderServerPort; }
111 #endif
112 #endif
113     
114     void setShouldTrackVisitedLinks(bool);
115     void addVisitedLink(WebCore::LinkHash);
116     bool isLinkVisited(WebCore::LinkHash) const;
117
118     bool shouldPlugInAutoStartFromOrigin(const WebPage*, const String& pageOrigin, const String& pluginOrigin, const String& mimeType);
119     void plugInDidStartFromOrigin(const String& pageOrigin, const String& pluginOrigin, const String& mimeType);
120     void plugInDidReceiveUserInteraction(const String& pageOrigin, const String& pluginOrigin, const String& mimeType);
121
122     bool fullKeyboardAccessEnabled() const { return m_fullKeyboardAccessEnabled; }
123
124     WebFrame* webFrame(uint64_t) const;
125     void addWebFrame(uint64_t, WebFrame*);
126     void removeWebFrame(uint64_t);
127
128     WebPageGroupProxy* webPageGroup(WebCore::PageGroup*);
129     WebPageGroupProxy* webPageGroup(uint64_t pageGroupID);
130     WebPageGroupProxy* webPageGroup(const WebPageGroupData&);
131
132 #if PLATFORM(MAC)
133     pid_t presenterApplicationPid() const { return m_presenterApplicationPid; }
134     bool shouldForceScreenFontSubstitution() const { return m_shouldForceScreenFontSubstitution; }
135 #endif
136     
137     const TextCheckerState& textCheckerState() const { return m_textCheckerState; }
138     DownloadManager& downloadManager();
139
140 #if PLATFORM(QT)
141     QNetworkAccessManager* networkAccessManager() { return m_networkAccessManager; }
142 #endif
143
144     void clearResourceCaches(ResourceCachesToClear = AllResourceCaches);
145     
146 #if ENABLE(PLUGIN_PROCESS)
147     PluginProcessConnectionManager& pluginProcessConnectionManager();
148 #endif
149
150     EventDispatcher& eventDispatcher() { return *m_eventDispatcher; }
151
152 #if ENABLE(NETWORK_PROCESS)
153     NetworkProcessConnection* networkConnection();
154     void networkProcessConnectionClosed(NetworkProcessConnection*);
155     bool usesNetworkProcess() const { return m_usesNetworkProcess; }
156     WebResourceLoadScheduler& webResourceLoadScheduler();
157 #endif
158
159     void setCacheModel(uint32_t);
160
161     void ensurePrivateBrowsingSession();
162     void destroyPrivateBrowsingSession();
163     
164     void pageDidEnterWindow(WebPage*);
165     void pageWillLeaveWindow(WebPage*);
166
167     void nonVisibleProcessCleanupTimerFired(WebCore::Timer<WebProcess>*);
168
169     void updateActivePages();
170
171 private:
172     WebProcess();
173
174     // DownloadManager::Client.
175     virtual void didCreateDownload() OVERRIDE;
176     virtual void didDestroyDownload() OVERRIDE;
177     virtual CoreIPC::Connection* downloadProxyConnection() OVERRIDE;
178     virtual AuthenticationManager& downloadsAuthenticationManager() OVERRIDE;
179
180     void initializeWebProcess(const WebProcessCreationParameters&, CoreIPC::MessageDecoder&);
181     void platformInitializeWebProcess(const WebProcessCreationParameters&, CoreIPC::MessageDecoder&);
182
183     void platformTerminate();
184     void registerURLSchemeAsEmptyDocument(const String&);
185     void registerURLSchemeAsSecure(const String&) const;
186     void setDomainRelaxationForbiddenForURLScheme(const String&) const;
187     void registerURLSchemeAsLocal(const String&) const;
188     void registerURLSchemeAsNoAccess(const String&) const;
189     void registerURLSchemeAsDisplayIsolated(const String&) const;
190     void registerURLSchemeAsCORSEnabled(const String&) const;
191     void setDefaultRequestTimeoutInterval(double);
192     void setAlwaysUsesComplexTextCodePath(bool);
193     void setShouldUseFontSmoothing(bool);
194     void userPreferredLanguagesChanged(const Vector<String>&) const;
195     void fullKeyboardAccessModeChanged(bool fullKeyboardAccessEnabled);
196
197     void setVisitedLinkTable(const SharedMemory::Handle&);
198     void visitedLinkStateChanged(const Vector<WebCore::LinkHash>& linkHashes);
199     void allVisitedLinkStateChanged();
200
201     bool isPlugInAutoStartOriginHash(unsigned plugInOriginHash);
202     void didAddPlugInAutoStartOriginHash(unsigned plugInOriginHash, double expirationTime);
203     void resetPlugInAutoStartOriginHashes(const HashMap<unsigned, double>& hashes);
204
205     void platformSetCacheModel(CacheModel);
206     void platformClearResourceCaches(ResourceCachesToClear);
207     void clearApplicationCache();
208
209     void setEnhancedAccessibility(bool);
210     
211 #if !ENABLE(PLUGIN_PROCESS)
212     void getSitesWithPluginData(const Vector<String>& pluginPaths, uint64_t callbackID);
213     void clearPluginSiteData(const Vector<String>& pluginPaths, const Vector<String>& sites, uint64_t flags, uint64_t maxAgeInSeconds, uint64_t callbackID);
214 #endif
215
216     void startMemorySampler(const SandboxExtension::Handle&, const String&, const double);
217     void stopMemorySampler();
218
219     void downloadRequest(uint64_t downloadID, uint64_t initiatingPageID, const WebCore::ResourceRequest&);
220     void cancelDownload(uint64_t downloadID);
221 #if PLATFORM(QT)
222     void startTransfer(uint64_t downloadID, const String& destination);
223 #endif
224
225     void setTextCheckerState(const TextCheckerState&);
226     
227     void getWebCoreStatistics(uint64_t callbackID);
228     void garbageCollectJavaScriptObjects();
229     void setJavaScriptGarbageCollectorTimerEnabled(bool flag);
230
231 #if USE(SOUP)
232     void setIgnoreTLSErrors(bool);
233 #endif
234
235     void postInjectedBundleMessage(const CoreIPC::DataReference& messageData);
236
237     // ChildProcess
238     virtual void initializeProcess(const ChildProcessInitializationParameters&) OVERRIDE;
239     virtual void initializeProcessName(const ChildProcessInitializationParameters&) OVERRIDE;
240     virtual void initializeSandbox(const ChildProcessInitializationParameters&, SandboxInitializationParameters&) OVERRIDE;
241     virtual void initializeConnection(CoreIPC::Connection*) OVERRIDE;
242     virtual bool shouldTerminate() OVERRIDE;
243     virtual void terminate() OVERRIDE;
244
245     void platformInitializeProcess(const ChildProcessInitializationParameters&);
246
247     // CoreIPC::Connection::Client
248     friend class WebConnectionToUIProcess;
249     virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&);
250     virtual void didReceiveSyncMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&, OwnPtr<CoreIPC::MessageEncoder>&);
251     virtual void didClose(CoreIPC::Connection*);
252     virtual void didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::StringReference messageReceiverName, CoreIPC::StringReference messageName) OVERRIDE;
253
254     // Implemented in generated WebProcessMessageReceiver.cpp
255     void didReceiveWebProcessMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&);
256
257     RefPtr<WebConnectionToUIProcess> m_webConnection;
258
259     HashMap<uint64_t, RefPtr<WebPage>> m_pageMap;
260     HashMap<uint64_t, RefPtr<WebPageGroupProxy>> m_pageGroupMap;
261     RefPtr<InjectedBundle> m_injectedBundle;
262
263     RefPtr<EventDispatcher> m_eventDispatcher;
264
265     bool m_inDidClose;
266
267     // FIXME: The visited link table should not be per process.
268     VisitedLinkTable m_visitedLinkTable;
269     bool m_shouldTrackVisitedLinks;
270
271     HashMap<unsigned, double> m_plugInAutoStartOriginHashes;
272     HashSet<String> m_plugInAutoStartOrigins;
273
274     bool m_hasSetCacheModel;
275     CacheModel m_cacheModel;
276
277 #if USE(ACCELERATED_COMPOSITING) && PLATFORM(MAC)
278     mach_port_t m_compositingRenderServerPort;
279 #endif
280 #if PLATFORM(MAC)
281     pid_t m_presenterApplicationPid;
282     dispatch_group_t m_clearResourceCachesDispatchGroup;
283     bool m_shouldForceScreenFontSubstitution;
284 #endif
285
286     bool m_fullKeyboardAccessEnabled;
287
288 #if PLATFORM(QT)
289     QNetworkAccessManager* m_networkAccessManager;
290 #endif
291
292     HashMap<uint64_t, WebFrame*> m_frameMap;
293
294     typedef HashMap<const char*, OwnPtr<WebProcessSupplement>, PtrHash<const char*>> WebProcessSupplementMap;
295     WebProcessSupplementMap m_supplements;
296
297     TextCheckerState m_textCheckerState;
298
299     WebIconDatabaseProxy* m_iconDatabaseProxy;
300
301 #if ENABLE(NETWORK_PROCESS)
302     void ensureNetworkProcessConnection();
303     RefPtr<NetworkProcessConnection> m_networkProcessConnection;
304     bool m_usesNetworkProcess;
305     WebResourceLoadScheduler* m_webResourceLoadScheduler;
306 #endif
307
308 #if ENABLE(PLUGIN_PROCESS)
309     RefPtr<PluginProcessConnectionManager> m_pluginProcessConnectionManager;
310 #endif
311
312     int m_inWindowPageCount;
313     WebCore::Timer<WebProcess> m_nonVisibleProcessCleanupTimer;
314 };
315
316 } // namespace WebKit
317
318 #endif // WebProcess_h