initial import
[vuplus_webkit] / 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 "ResourceCachesToClear.h"
33 #include "SandboxExtension.h"
34 #include "SharedMemory.h"
35 #include "TextCheckerState.h"
36 #include "VisitedLinkTable.h"
37 #include "WebGeolocationManager.h"
38 #include "WebIconDatabaseProxy.h"
39 #include "WebPageGroupProxy.h"
40 #include <WebCore/LinkHash.h>
41 #include <wtf/Forward.h>
42 #include <wtf/HashMap.h>
43 #include <wtf/HashSet.h>
44
45 #if PLATFORM(QT)
46 class QNetworkAccessManager;
47 #endif
48
49 #if ENABLE(PLUGIN_PROCESS)
50 #include "PluginProcessConnectionManager.h"
51 #endif
52
53 namespace WebCore {
54     class IntSize;
55     class PageGroup;
56     class ResourceRequest;
57     class ResourceResponse;
58 }
59
60 namespace WebKit {
61
62 class InjectedBundle;
63 class WebFrame;
64 class WebPage;
65 struct WebPageCreationParameters;
66 struct WebPageGroupData;
67 struct WebPreferencesStore;
68 struct WebProcessCreationParameters;
69
70 class WebProcess : public ChildProcess, private CoreIPC::Connection::QueueClient {
71 public:
72     static WebProcess& shared();
73
74     void initialize(CoreIPC::Connection::Identifier, RunLoop*);
75
76     CoreIPC::Connection* connection() const { return m_connection.get(); }
77     RunLoop* runLoop() const { return m_runLoop; }
78
79     WebPage* webPage(uint64_t pageID) const;
80     void createWebPage(uint64_t pageID, const WebPageCreationParameters&);
81     void removeWebPage(uint64_t pageID);
82     WebPage* focusedWebPage() const;
83     
84     InjectedBundle* injectedBundle() const { return m_injectedBundle.get(); }
85
86     bool isSeparateProcess() const;
87
88 #if PLATFORM(MAC)
89     void initializeShim();
90
91 #if USE(ACCELERATED_COMPOSITING)
92     mach_port_t compositingRenderServerPort() const { return m_compositingRenderServerPort; }
93 #endif
94 #endif
95     
96     void addVisitedLink(WebCore::LinkHash);
97     bool isLinkVisited(WebCore::LinkHash) const;
98
99     bool fullKeyboardAccessEnabled();
100
101     WebFrame* webFrame(uint64_t) const;
102     void addWebFrame(uint64_t, WebFrame*);
103     void removeWebFrame(uint64_t);
104
105     WebPageGroupProxy* webPageGroup(uint64_t pageGroupID);
106     WebPageGroupProxy* webPageGroup(const WebPageGroupData&);
107 #if PLATFORM(MAC)
108     pid_t presenterApplicationPid() const { return m_presenterApplicationPid; }
109 #endif 
110     
111 #if PLATFORM(QT)
112     QNetworkAccessManager* networkAccessManager() { return m_networkAccessManager; }
113 #endif
114
115     bool shouldUseCustomRepresentationForResponse(const WebCore::ResourceResponse&) const;
116
117     // Text Checking
118     const TextCheckerState& textCheckerState() const { return m_textCheckerState; }
119
120     // Geolocation
121     WebGeolocationManager& geolocationManager() { return m_geolocationManager; }
122
123     void clearResourceCaches(ResourceCachesToClear = AllResourceCaches);
124     
125     const String& localStorageDirectory() const { return m_localStorageDirectory; }
126
127 #if ENABLE(PLUGIN_PROCESS)
128     PluginProcessConnectionManager& pluginProcessConnectionManager() { return m_pluginProcessConnectionManager; }
129     bool disablePluginProcessMessageTimeout() const { return m_disablePluginProcessMessageTimeout; }
130 #endif
131
132 private:
133     WebProcess();
134
135     void initializeWebProcess(const WebProcessCreationParameters&, CoreIPC::ArgumentDecoder*);
136     void platformInitializeWebProcess(const WebProcessCreationParameters&, CoreIPC::ArgumentDecoder*);
137     void platformTerminate();
138     void setShouldTrackVisitedLinks(bool);
139     void registerURLSchemeAsEmptyDocument(const String&);
140     void registerURLSchemeAsSecure(const String&) const;
141     void setDomainRelaxationForbiddenForURLScheme(const String&) const;
142     void setDefaultRequestTimeoutInterval(double);
143     void setAlwaysUsesComplexTextCodePath(bool);
144     void languageChanged(const String&) const;
145 #if PLATFORM(WIN)
146     void setShouldPaintNativeControls(bool);
147 #endif
148
149     void setVisitedLinkTable(const SharedMemory::Handle&);
150     void visitedLinkStateChanged(const Vector<WebCore::LinkHash>& linkHashes);
151     void allVisitedLinkStateChanged();
152
153     void setCacheModel(uint32_t);
154     void platformSetCacheModel(CacheModel);
155     static void calculateCacheSizes(CacheModel cacheModel, uint64_t memorySize, uint64_t diskFreeSize,
156         unsigned& cacheTotalCapacity, unsigned& cacheMinDeadCapacity, unsigned& cacheMaxDeadCapacity, double& deadDecodedDataDeletionInterval,
157         unsigned& pageCacheCapacity, unsigned long& urlCacheMemoryCapacity, unsigned long& urlCacheDiskCapacity);
158     void platformClearResourceCaches(ResourceCachesToClear);
159     void clearApplicationCache();
160
161     void setEnhancedAccessibility(bool);
162     
163 #if !ENABLE(PLUGIN_PROCESS)
164     void getSitesWithPluginData(const Vector<String>& pluginPaths, uint64_t callbackID);
165     void clearPluginSiteData(const Vector<String>& pluginPaths, const Vector<String>& sites, uint64_t flags, uint64_t maxAgeInSeconds, uint64_t callbackID);
166 #endif
167     
168 #if ENABLE(PLUGIN_PROCESS)
169     void pluginProcessCrashed(const String& pluginPath);
170 #endif
171
172     void startMemorySampler(const SandboxExtension::Handle&, const String&, const double);
173     void stopMemorySampler();
174
175     void downloadRequest(uint64_t downloadID, uint64_t initiatingPageID, const WebCore::ResourceRequest&);
176     void cancelDownload(uint64_t downloadID);
177
178     void setTextCheckerState(const TextCheckerState&);
179     
180     void getWebCoreStatistics(uint64_t callbackID);
181     void garbageCollectJavaScriptObjects();
182
183     // ChildProcess
184     virtual bool shouldTerminate();
185     virtual void terminate();
186
187     // CoreIPC::Connection::Client
188     virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
189     virtual void didReceiveSyncMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, OwnPtr<CoreIPC::ArgumentEncoder>&);
190     virtual void didClose(CoreIPC::Connection*);
191     virtual void didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::MessageID);
192     virtual void syncMessageSendTimedOut(CoreIPC::Connection*);
193
194     // CoreIPC::Connection::QueueClient
195     virtual bool willProcessMessageOnClientRunLoop(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
196
197 #if PLATFORM(WIN)
198     Vector<HWND> windowsToReceiveSentMessagesWhileWaitingForSyncReply();
199 #endif
200
201     // Implemented in generated WebProcessMessageReceiver.cpp
202     bool willProcessWebProcessMessageOnClientRunLoop(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
203     void didReceiveWebProcessMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
204
205     RefPtr<CoreIPC::Connection> m_connection;
206     HashMap<uint64_t, RefPtr<WebPage> > m_pageMap;
207     HashMap<uint64_t, RefPtr<WebPageGroupProxy> > m_pageGroupMap;
208     RefPtr<InjectedBundle> m_injectedBundle;
209
210     bool m_inDidClose;
211
212     RunLoop* m_runLoop;
213
214     // FIXME: The visited link table should not be per process.
215     VisitedLinkTable m_visitedLinkTable;
216
217     bool m_hasSetCacheModel;
218     CacheModel m_cacheModel;
219
220 #if USE(ACCELERATED_COMPOSITING) && PLATFORM(MAC)
221     mach_port_t m_compositingRenderServerPort;
222 #endif
223 #if PLATFORM(MAC)
224     pid_t m_presenterApplicationPid;
225 #endif
226
227 #if PLATFORM(QT)
228     QNetworkAccessManager* m_networkAccessManager;
229 #endif
230
231     HashMap<uint64_t, WebFrame*> m_frameMap;
232
233     HashSet<String, CaseFoldingHash> m_mimeTypesWithCustomRepresentations;
234
235     TextCheckerState m_textCheckerState;
236     WebGeolocationManager m_geolocationManager;
237     WebIconDatabaseProxy m_iconDatabaseProxy;
238     
239     String m_localStorageDirectory;
240
241 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
242     RefPtr<SandboxExtension> m_applicationCachePathExtension;
243 #endif
244
245 #if ENABLE(PLUGIN_PROCESS)
246     PluginProcessConnectionManager m_pluginProcessConnectionManager;
247     bool m_disablePluginProcessMessageTimeout;
248 #endif
249
250 };
251
252 } // namespace WebKit
253
254 #endif // WebProcess_h