Cancel composition when focused node was changed
[framework/web/webkit-efl.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     class ResourceRequest;
82     class ResourceResponse;
83 }
84
85 namespace WebKit {
86
87 class InjectedBundle;
88 class WebFrame;
89 class WebPage;
90 struct WebPageCreationParameters;
91 struct WebPageGroupData;
92 struct WebPreferencesStore;
93 struct WebProcessCreationParameters;
94
95 #if USE(SECURITY_FRAMEWORK)
96 class SecItemResponseData;
97 class SecKeychainItemResponseData;
98 #endif
99
100 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
101 class PlatformSurfacePoolTizen;
102 #endif
103
104 class WebProcess : public ChildProcess, private CoreIPC::Connection::QueueClient {
105 public:
106     static WebProcess& shared();
107
108     void initialize(CoreIPC::Connection::Identifier, WebCore::RunLoop*);
109
110     CoreIPC::Connection* connection() const { return m_connection->connection(); }
111     WebCore::RunLoop* runLoop() const { return m_runLoop; }
112
113     WebConnectionToUIProcess* webConnectionToUIProcess() const { return m_connection.get(); }
114
115     WebPage* webPage(uint64_t pageID) const;
116     void createWebPage(uint64_t pageID, const WebPageCreationParameters&);
117     void removeWebPage(uint64_t pageID);
118     WebPage* focusedWebPage() const;
119     
120     InjectedBundle* injectedBundle() const { return m_injectedBundle.get(); }
121
122     bool isSeparateProcess() const;
123
124 #if PLATFORM(MAC)
125     void initializeShim();
126
127 #if USE(ACCELERATED_COMPOSITING)
128     mach_port_t compositingRenderServerPort() const { return m_compositingRenderServerPort; }
129 #endif
130 #endif
131     
132     void setShouldTrackVisitedLinks(bool);
133     void addVisitedLink(WebCore::LinkHash);
134     bool isLinkVisited(WebCore::LinkHash) const;
135
136     bool fullKeyboardAccessEnabled() const { return m_fullKeyboardAccessEnabled; }
137
138     WebFrame* webFrame(uint64_t) const;
139     void addWebFrame(uint64_t, WebFrame*);
140     void removeWebFrame(uint64_t);
141
142     WebPageGroupProxy* webPageGroup(uint64_t pageGroupID);
143     WebPageGroupProxy* webPageGroup(const WebPageGroupData&);
144 #if PLATFORM(MAC)
145     pid_t presenterApplicationPid() const { return m_presenterApplicationPid; }
146 #endif 
147     
148 #if PLATFORM(QT)
149     QNetworkAccessManager* networkAccessManager() { return m_networkAccessManager; }
150 #endif
151
152     bool shouldUseCustomRepresentationForResponse(const WebCore::ResourceResponse&) const;
153
154     // Text Checking
155     const TextCheckerState& textCheckerState() const { return m_textCheckerState; }
156
157     // Geolocation
158     WebGeolocationManager& geolocationManager() { return m_geolocationManager; }
159
160 #if ENABLE(BATTERY_STATUS)
161     WebBatteryManager& batteryManager() { return m_batteryManager; }
162 #endif
163
164 #if ENABLE(NETWORK_INFO)
165     WebNetworkInfoManager& networkInfoManager() { return m_networkInfoManager; }
166 #endif
167     
168 #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
169     WebNotificationManager& notificationManager() { return m_notificationManager; }
170 #endif
171
172     void clearResourceCaches(ResourceCachesToClear = AllResourceCaches);
173 #if ENABLE(TIZEN_CACHE_DUMP_SYNC)
174     void dumpResourceCaches();
175     void platformDumpResourceCaches();
176 #endif
177     
178     const String& localStorageDirectory() const { return m_localStorageDirectory; }
179
180 #if ENABLE(PLUGIN_PROCESS)
181     PluginProcessConnectionManager& pluginProcessConnectionManager() { return m_pluginProcessConnectionManager; }
182     bool disablePluginProcessMessageTimeout() const { return m_disablePluginProcessMessageTimeout; }
183 #endif
184
185     EventDispatcher& eventDispatcher() { return m_eventDispatcher; }
186
187 #if USE(SOUP)
188     WebSoupRequestManager& soupRequestManager() { return m_soupRequestManager; }
189 #endif
190
191 #if ENABLE(TIZEN_SOUP_CACHE_DIRECTORY_SET)
192     void setSoupDataDirectory(const String& soupDataDirectory);
193 #endif
194
195 #if ENABLE(TIZEN_WEBKIT2_PROXY)
196     void setProxy(const String& proxyAddress);
197 #endif
198 #if ENABLE(TIZEN_SESSION_REQUEST_CANCEL)
199     void abortSession();
200 #endif
201
202 #if ENABLE(TIZEN_CERTIFICATE_HANDLING)
203     void setCertificateFile(const String&);
204 #endif
205
206 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
207     PlatformSurfacePoolTizen* platformSurfacePool() { return m_platformSurfacePool.get(); }
208     void removePlatformSurfaceFromPool(int platformSurfaceId);
209 #endif
210
211 #if ENABLE(TIZEN_INDEXED_DATABASE)
212     const String& indexedDatabaseDirectory() const { return m_indexedDatabaseDirectory; }
213 #endif
214
215 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
216     class WaitForJavaScriptPopupFinished {
217     public:
218         WaitForJavaScriptPopupFinished(); 
219         ~WaitForJavaScriptPopupFinished(); 
220     };
221     bool isWaitingForJavaScriptPopupFinished();
222 #endif
223
224 #if ENABLE(TIZEN_WEBKIT2_MEMORY_SAVING_MODE)
225     void setMemorySavingMode(bool);
226     bool memorySavingModeEnabled() { return m_memorySavingModeEnabled; }
227 #endif
228
229 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_X_WINDOW)
230     void setXWindow(unsigned);
231 #endif
232
233 #if ENABLE(TIZEN_EXTENSIBLE_API)
234     void setTizenExtensibleAPI(int extensibleAPI, bool enable);
235 #endif
236
237 #if ENABLE(TIZEN_RESET_PATH)
238     void resetStoragePath();
239 #endif
240
241 #if ENABLE(TIZEN_INDEXED_DATABASE)
242     void deleteIndexedDatabaseAll();
243 #endif
244
245 private:
246     WebProcess();
247
248     void initializeWebProcess(const WebProcessCreationParameters&, CoreIPC::ArgumentDecoder*);
249     void platformInitializeWebProcess(const WebProcessCreationParameters&, CoreIPC::ArgumentDecoder*);
250     void platformTerminate();
251     void registerURLSchemeAsEmptyDocument(const String&);
252     void registerURLSchemeAsSecure(const String&) const;
253     void setDomainRelaxationForbiddenForURLScheme(const String&) const;
254     void setDefaultRequestTimeoutInterval(double);
255     void setAlwaysUsesComplexTextCodePath(bool);
256     void setShouldUseFontSmoothing(bool);
257     void userPreferredLanguagesChanged(const Vector<String>&) const;
258     void fullKeyboardAccessModeChanged(bool fullKeyboardAccessEnabled);
259 #if PLATFORM(WIN)
260     void setShouldPaintNativeControls(bool);
261 #endif
262
263     void setVisitedLinkTable(const SharedMemory::Handle&);
264     void visitedLinkStateChanged(const Vector<WebCore::LinkHash>& linkHashes);
265     void allVisitedLinkStateChanged();
266
267     void setCacheModel(uint32_t);
268     void platformSetCacheModel(CacheModel);
269 #if ENABLE(TIZEN_CACHE_CONTROL)
270     void setCacheDisabled(bool);
271     void platformSetCacheDisabled(bool);
272 #endif
273     static void calculateCacheSizes(CacheModel cacheModel, uint64_t memorySize, uint64_t diskFreeSize,
274         unsigned& cacheTotalCapacity, unsigned& cacheMinDeadCapacity, unsigned& cacheMaxDeadCapacity, double& deadDecodedDataDeletionInterval,
275         unsigned& pageCacheCapacity, unsigned long& urlCacheMemoryCapacity, unsigned long& urlCacheDiskCapacity);
276     void platformClearResourceCaches(ResourceCachesToClear);
277     void clearApplicationCache();
278
279     void setEnhancedAccessibility(bool);
280     
281 #if !ENABLE(PLUGIN_PROCESS)
282     void getSitesWithPluginData(const Vector<String>& pluginPaths, uint64_t callbackID);
283     void clearPluginSiteData(const Vector<String>& pluginPaths, const Vector<String>& sites, uint64_t flags, uint64_t maxAgeInSeconds, uint64_t callbackID);
284 #endif
285     
286 #if ENABLE(PLUGIN_PROCESS)
287     void pluginProcessCrashed(CoreIPC::Connection*, const String& pluginPath);
288 #endif
289
290     void startMemorySampler(const SandboxExtension::Handle&, const String&, const double);
291     void stopMemorySampler();
292
293     void downloadRequest(uint64_t downloadID, uint64_t initiatingPageID, const WebCore::ResourceRequest&);
294     void cancelDownload(uint64_t downloadID);
295 #if PLATFORM(QT)
296     void startTransfer(uint64_t downloadID, const String& destination);
297 #endif
298
299     void setTextCheckerState(const TextCheckerState&);
300     
301     void getWebCoreStatistics(uint64_t callbackID);
302     void garbageCollectJavaScriptObjects();
303     void setJavaScriptGarbageCollectorTimerEnabled(bool flag);
304
305 #if USE(SECURITY_FRAMEWORK)
306     void secItemResponse(CoreIPC::Connection*, uint64_t requestID, const SecItemResponseData&);
307     void secKeychainItemResponse(CoreIPC::Connection*, uint64_t requestID, const SecKeychainItemResponseData&);
308 #endif
309
310     // ChildProcess
311     virtual bool shouldTerminate();
312     virtual void terminate();
313
314     // CoreIPC::Connection::Client
315     friend class WebConnectionToUIProcess;
316     virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
317     virtual void didReceiveSyncMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, OwnPtr<CoreIPC::ArgumentEncoder>&);
318     virtual void didClose(CoreIPC::Connection*);
319     virtual void didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::MessageID);
320     virtual void syncMessageSendTimedOut(CoreIPC::Connection*);
321 #if PLATFORM(WIN)
322     virtual Vector<HWND> windowsToReceiveSentMessagesWhileWaitingForSyncReply();
323 #endif
324
325     // CoreIPC::Connection::QueueClient
326     virtual void didReceiveMessageOnConnectionWorkQueue(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, bool& didHandleMessage) OVERRIDE;
327
328     // Implemented in generated WebProcessMessageReceiver.cpp
329     void didReceiveWebProcessMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
330     void didReceiveWebProcessMessageOnConnectionWorkQueue(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, bool& didHandleMessage);
331
332     void didGetPlugins(CoreIPC::Connection*, uint64_t requestID, const Vector<WebCore::PluginInfo>&);
333
334     RefPtr<WebConnectionToUIProcess> m_connection;
335
336     HashMap<uint64_t, RefPtr<WebPage> > m_pageMap;
337     HashMap<uint64_t, RefPtr<WebPageGroupProxy> > m_pageGroupMap;
338     RefPtr<InjectedBundle> m_injectedBundle;
339
340     EventDispatcher m_eventDispatcher;
341
342     bool m_inDidClose;
343
344     WebCore::RunLoop* m_runLoop;
345
346     // FIXME: The visited link table should not be per process.
347     VisitedLinkTable m_visitedLinkTable;
348     bool m_shouldTrackVisitedLinks;
349
350     bool m_hasSetCacheModel;
351     CacheModel m_cacheModel;
352
353 #if USE(ACCELERATED_COMPOSITING) && PLATFORM(MAC)
354     mach_port_t m_compositingRenderServerPort;
355 #endif
356 #if PLATFORM(MAC)
357     pid_t m_presenterApplicationPid;
358     dispatch_group_t m_clearResourceCachesDispatchGroup;
359 #endif
360
361     bool m_fullKeyboardAccessEnabled;
362
363 #if PLATFORM(QT)
364     QNetworkAccessManager* m_networkAccessManager;
365 #endif
366
367     HashMap<uint64_t, WebFrame*> m_frameMap;
368
369     HashSet<String, CaseFoldingHash> m_mimeTypesWithCustomRepresentations;
370
371     TextCheckerState m_textCheckerState;
372     WebGeolocationManager m_geolocationManager;
373 #if ENABLE(BATTERY_STATUS)
374     WebBatteryManager m_batteryManager;
375 #endif
376 #if ENABLE(NETWORK_INFO)
377     WebNetworkInfoManager m_networkInfoManager;
378 #endif
379 #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
380     WebNotificationManager m_notificationManager;
381 #endif
382     WebIconDatabaseProxy m_iconDatabaseProxy;
383     
384     String m_localStorageDirectory;
385
386     RefPtr<SandboxExtension> m_applicationCachePathExtension;
387
388 #if ENABLE(PLUGIN_PROCESS)
389     PluginProcessConnectionManager m_pluginProcessConnectionManager;
390     bool m_disablePluginProcessMessageTimeout;
391 #endif
392 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
393     OwnPtr<PlatformSurfacePoolTizen> m_platformSurfacePool;
394 #endif
395
396 #if ENABLE(TIZEN_INDEXED_DATABASE)
397     String m_indexedDatabaseDirectory;
398 #endif
399
400 #if USE(SOUP)
401     WebSoupRequestManager m_soupRequestManager;
402 #endif
403
404 #if ENABLE(TIZEN_WEBKIT2_ROTATION_WHILE_JAVASCRIPT_POPUP)
405     int m_isWaitingForJavaScriptPopupCount;
406 #endif
407
408 #if ENABLE(TIZEN_WEBKIT2_MEMORY_SAVING_MODE)
409     bool m_memorySavingModeEnabled;
410 #endif
411 };
412
413 } // namespace WebKit
414
415 #endif // WebProcess_h