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