Merge "[CherryPick] [EFL][Qt][WK2] Fixed position elements are not always fixed"...
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / WebContext.h
1 /*
2  * Copyright (C) 2010, 2011 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 WebContext_h
27 #define WebContext_h
28
29 #include "APIObject.h"
30 #include "GenericCallback.h"
31 #include "PluginInfoStore.h"
32 #include "ProcessModel.h"
33 #include "VisitedLinkProvider.h"
34 #include "WebContextInjectedBundleClient.h"
35 #include "WebContextConnectionClient.h"
36 #include "WebDownloadClient.h"
37 #include "WebHistoryClient.h"
38 #include "WebProcessProxy.h"
39 #include <WebCore/LinkHash.h>
40 #include <wtf/Forward.h>
41 #include <wtf/HashSet.h>
42 #include <wtf/PassRefPtr.h>
43 #include <wtf/RefPtr.h>
44 #include <wtf/text/StringHash.h>
45 #include <wtf/text/WTFString.h>
46
47 #if ENABLE(TIZEN_EXTENSIBLE_API)
48 #include <WebCore/TizenExtensibleAPI.h>
49 #endif
50
51 namespace WebKit {
52
53 class DownloadProxy;
54 class WebApplicationCacheManagerProxy;
55 #if ENABLE(BATTERY_STATUS)
56 class WebBatteryManagerProxy;
57 #endif
58 class WebCookieManagerProxy;
59 class WebDatabaseManagerProxy;
60 class WebGeolocationManagerProxy;
61 class WebIconDatabase;
62 class WebKeyValueStorageManagerProxy;
63 #if ENABLE(TIZEN_FILE_SYSTEM)
64 class WebLocalFileSystemManagerProxy;
65 #endif
66 class WebMediaCacheManagerProxy;
67 #if ENABLE(NETWORK_INFO)
68 class WebNetworkInfoManagerProxy;
69 #endif
70 class WebNotificationManagerProxy;
71 class WebPageGroup;
72 class WebPageProxy;
73 class WebResourceCacheManagerProxy;
74 #if USE(SOUP)
75 class WebSoupRequestManagerProxy;
76 #endif
77 #if ENABLE(VIBRATION)
78 class WebVibrationProxy;
79 #endif
80 struct StatisticsData;
81 struct WebProcessCreationParameters;
82     
83 typedef GenericCallback<WKDictionaryRef> DictionaryCallback;
84
85 class WebContext : public APIObject, private CoreIPC::Connection::QueueClient {
86 public:
87     static const Type APIType = TypeContext;
88
89     static WebContext* sharedProcessContext();
90     static WebContext* sharedThreadContext();
91
92     static PassRefPtr<WebContext> create(const String& injectedBundlePath);
93     virtual ~WebContext();
94
95     static const Vector<WebContext*>& allContexts();
96
97     void initializeInjectedBundleClient(const WKContextInjectedBundleClient*);
98     void initializeConnectionClient(const WKContextConnectionClient*);
99     void initializeHistoryClient(const WKContextHistoryClient*);
100     void initializeDownloadClient(const WKContextDownloadClient*);
101
102     ProcessModel processModel() const { return m_processModel; }
103     WebProcessProxy* process() const { return m_process.get(); }
104
105     template<typename U> bool sendToAllProcesses(const U& message);
106     template<typename U> bool sendToAllProcessesRelaunchingThemIfNecessary(const U& message);
107     
108     void processDidFinishLaunching(WebProcessProxy*);
109
110     // Disconnect the process from the context.
111     void disconnectProcess(WebProcessProxy*);
112
113     PassRefPtr<WebPageProxy> createWebPage(PageClient*, WebPageGroup*);
114
115     WebProcessProxy* relaunchProcessIfNecessary();
116
117     const String& injectedBundlePath() const { return m_injectedBundlePath; }
118
119     DownloadProxy* download(WebPageProxy* initiatingPage, const WebCore::ResourceRequest&);
120
121     void setInjectedBundleInitializationUserData(PassRefPtr<APIObject> userData) { m_injectedBundleInitializationUserData = userData; }
122
123     void postMessageToInjectedBundle(const String&, APIObject*);
124
125     // InjectedBundle client
126     void didReceiveMessageFromInjectedBundle(const String&, APIObject*);
127     void didReceiveSynchronousMessageFromInjectedBundle(const String&, APIObject*, RefPtr<APIObject>& returnData);
128
129     void populateVisitedLinks();
130     
131     void setAdditionalPluginsDirectory(const String&);
132
133     PluginInfoStore& pluginInfoStore() { return m_pluginInfoStore; }
134     String applicationCacheDirectory();
135 #if ENABLE(TIZEN_APPLICATION_CACHE)
136     void setApplicationCacheDirectory(const String&);
137     String platformDefaultApplicationCacheDirectory() const;
138 #endif
139
140     void setAlwaysUsesComplexTextCodePath(bool);
141     void setShouldUseFontSmoothing(bool);
142     
143     void registerURLSchemeAsEmptyDocument(const String&);
144     void registerURLSchemeAsSecure(const String&);
145     void setDomainRelaxationForbiddenForURLScheme(const String&);
146
147     void addVisitedLink(const String&);
148     void addVisitedLinkHash(WebCore::LinkHash);
149
150     void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
151     void didReceiveSyncMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, OwnPtr<CoreIPC::ArgumentEncoder>&);
152
153     void setCacheModel(CacheModel);
154     CacheModel cacheModel() const { return m_cacheModel; }
155
156 #if ENABLE(TIZEN_CACHE_CONTROL)
157     void setCacheDisabled(bool usingCacheData);
158     bool getCacheDisabled() const { return m_cacheDisabled; }
159 #endif
160
161     void setDefaultRequestTimeoutInterval(double);
162
163     void startMemorySampler(const double interval);
164     void stopMemorySampler();
165
166 #if PLATFORM(WIN)
167     void setShouldPaintNativeControls(bool);
168
169     void setInitialHTTPCookieAcceptPolicy(HTTPCookieAcceptPolicy policy) { m_initialHTTPCookieAcceptPolicy = policy; }
170 #endif
171 #if ENABLE(TIZEN_WEBKIT2_PROXY)
172     void setProxy(const String&);
173 #endif
174 #if ENABLE(TIZEN_SESSION_REQUEST_CANCEL)
175     void abortSession();
176 #endif
177
178 #if ENABLE(TIZEN_CERTIFICATE_HANDLING)
179     void setCertificateFile(const String&);
180 #endif
181
182 #if PLATFORM(EFL)
183     void notifyLowMemory();
184 #endif
185 #if ENABLE(TIZEN_WEBKIT2_MEMORY_SAVING_MODE)
186     void setMemorySavingMode(bool memorySavingMode);
187 #endif
188
189     void setEnhancedAccessibility(bool);
190     
191     // Downloads.
192     DownloadProxy* createDownloadProxy();
193     WebDownloadClient& downloadClient() { return m_downloadClient; }
194     void downloadFinished(DownloadProxy*);
195
196     static HashSet<String, CaseFoldingHash> pdfAndPostScriptMIMETypes();
197
198     WebApplicationCacheManagerProxy* applicationCacheManagerProxy() const { return m_applicationCacheManagerProxy.get(); }
199 #if ENABLE(BATTERY_STATUS)
200     WebBatteryManagerProxy* batteryManagerProxy() const { return m_batteryManagerProxy.get(); }
201 #endif
202     WebCookieManagerProxy* cookieManagerProxy() const { return m_cookieManagerProxy.get(); }
203 #if ENABLE(SQL_DATABASE)
204     WebDatabaseManagerProxy* databaseManagerProxy() const { return m_databaseManagerProxy.get(); }
205 #endif
206     WebGeolocationManagerProxy* geolocationManagerProxy() const { return m_geolocationManagerProxy.get(); }
207     WebIconDatabase* iconDatabase() const { return m_iconDatabase.get(); }
208     WebKeyValueStorageManagerProxy* keyValueStorageManagerProxy() const { return m_keyValueStorageManagerProxy.get(); }
209 #if ENABLE(TIZEN_FILE_SYSTEM)
210     WebLocalFileSystemManagerProxy* localFileSystemManagerProxy() const { return m_localFileSystemManagerProxy.get(); }
211 #endif
212     WebMediaCacheManagerProxy* mediaCacheManagerProxy() const { return m_mediaCacheManagerProxy.get(); }
213 #if ENABLE(NETWORK_INFO)
214     WebNetworkInfoManagerProxy* networkInfoManagerProxy() const { return m_networkInfoManagerProxy.get(); }
215 #endif
216     WebNotificationManagerProxy* notificationManagerProxy() const { return m_notificationManagerProxy.get(); }
217     WebPluginSiteDataManager* pluginSiteDataManager() const { return m_pluginSiteDataManager.get(); }
218     WebResourceCacheManagerProxy* resourceCacheManagerProxy() const { return m_resourceCacheManagerProxy.get(); }
219 #if USE(SOUP)
220     WebSoupRequestManagerProxy* soupRequestManagerProxy() const { return m_soupRequestManagerProxy.get(); }
221 #endif
222 #if ENABLE(VIBRATION)
223     WebVibrationProxy* vibrationProxy() const { return m_vibrationProxy.get(); }
224 #endif
225
226     struct Statistics {
227         unsigned wkViewCount;
228         unsigned wkPageCount;
229         unsigned wkFrameCount;
230     };
231     static Statistics& statistics();    
232
233     void setDatabaseDirectory(const String& dir) { m_overrideDatabaseDirectory = dir; }
234     void setIconDatabasePath(const String&);
235     String iconDatabasePath() const;
236 #if ENABLE(TIZEN_FILE_SYSTEM)
237     void setLocalFileSystemDirectory(const String& dir) { m_overrideLocalFileSystemDirectory = dir; }
238 #endif
239     void setLocalStorageDirectory(const String& dir) { m_overrideLocalStorageDirectory = dir; }
240 #if ENABLE(TIZEN_INDEXED_DATABASE)
241     void setIndexedDatabaseDirectory(const String& dir) { m_overrideIndexedDatabaseDirectory = dir; }
242 #endif
243
244     void ensureWebProcess();
245     void warmInitialProcess();
246
247     bool shouldTerminate(WebProcessProxy*);
248
249     void disableProcessTermination() { m_processTerminationEnabled = false; }
250     void enableProcessTermination();
251
252     // Defaults to false.
253     void setHTTPPipeliningEnabled(bool);
254     bool httpPipeliningEnabled() const;
255     
256     void getWebCoreStatistics(PassRefPtr<DictionaryCallback>);
257     void garbageCollectJavaScriptObjects();
258     void setJavaScriptGarbageCollectorTimerEnabled(bool flag);
259
260 #if PLATFORM(MAC)
261     static bool omitPDFSupport();
262 #endif
263
264 #if ENABLE(TIZEN_SOUP_COOKIE_CACHE_FOR_WEBKIT2)
265     String soupDataDirectory();
266     void setSoupDataDirectory(const String& path) { m_soupDataDirectory = path; }
267     String platformDefaultSoupDataDirectory();
268 #endif
269
270     void fullKeyboardAccessModeChanged(bool fullKeyboardAccessEnabled);
271
272 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_X_WINDOW)
273     void setXWindow(unsigned);
274 #endif
275
276 #if ENABLE(TIZEN_EXTENSIBLE_API)
277     void setTizenExtensibleAPI(WebCore::ExtensibleAPI extensibleAPI, bool enable);
278 #endif
279
280 #if ENABLE(TIZEN_RESET_PATH)
281     void resetStoragePath();
282 #endif
283
284 #if ENABLE(TIZEN_INDEXED_DATABASE)
285     void deleteIndexedDatabaseAll();
286 #endif
287
288 private:
289     WebContext(ProcessModel, const String& injectedBundlePath);
290
291     virtual Type type() const { return APIType; }
292
293     void platformInitializeWebProcess(WebProcessCreationParameters&);
294     void platformInvalidateContext();
295     
296     // History client
297     void didNavigateWithNavigationData(uint64_t pageID, const WebNavigationDataStore& store, uint64_t frameID);
298     void didPerformClientRedirect(uint64_t pageID, const String& sourceURLString, const String& destinationURLString, uint64_t frameID);
299     void didPerformServerRedirect(uint64_t pageID, const String& sourceURLString, const String& destinationURLString, uint64_t frameID);
300     void didUpdateHistoryTitle(uint64_t pageID, const String& title, const String& url, uint64_t frameID);
301
302     // Plugins
303     void getPlugins(CoreIPC::Connection*, uint64_t requestID, bool refresh);
304     void getPluginPath(const String& mimeType, const String& urlString, String& pluginPath, bool& blocked);
305 #if !ENABLE(PLUGIN_PROCESS)
306     void didGetSitesWithPluginData(const Vector<String>& sites, uint64_t callbackID);
307     void didClearPluginSiteData(uint64_t callbackID);
308 #endif
309
310 #if PLATFORM(MAC)
311     void getPasteboardTypes(const String& pasteboardName, Vector<String>& pasteboardTypes);
312     void getPasteboardPathnamesForType(const String& pasteboardName, const String& pasteboardType, Vector<String>& pathnames);
313     void getPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, String&);
314     void getPasteboardBufferForType(const String& pasteboardName, const String& pasteboardType, SharedMemory::Handle&, uint64_t& size);
315     void pasteboardCopy(const String& fromPasteboard, const String& toPasteboard);
316     void getPasteboardChangeCount(const String& pasteboardName, uint64_t& changeCount);
317     void getPasteboardUniqueName(String& pasteboardName);
318     void getPasteboardColor(const String& pasteboardName, WebCore::Color&);
319     void getPasteboardURL(const String& pasteboardName, WTF::String&);
320     void addPasteboardTypes(const String& pasteboardName, const Vector<String>& pasteboardTypes);
321     void setPasteboardTypes(const String& pasteboardName, const Vector<String>& pasteboardTypes);
322     void setPasteboardPathnamesForType(const String& pasteboardName, const String& pasteboardType, const Vector<String>& pathnames);
323     void setPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, const String&);
324     void setPasteboardBufferForType(const String& pasteboardName, const String& pasteboardType, const SharedMemory::Handle&, uint64_t size);
325 #endif
326
327     void didGetWebCoreStatistics(const StatisticsData&, uint64_t callbackID);
328         
329     // Implemented in generated WebContextMessageReceiver.cpp
330     void didReceiveWebContextMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
331     void didReceiveSyncWebContextMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, OwnPtr<CoreIPC::ArgumentEncoder>&);
332     void didReceiveWebContextMessageOnConnectionWorkQueue(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, bool& didHandleMessage);
333
334     virtual void didReceiveMessageOnConnectionWorkQueue(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, bool& didHandleMessage) OVERRIDE;
335
336     static void languageChanged(void* context);
337     void languageChanged();
338
339     String databaseDirectory() const;
340     String platformDefaultDatabaseDirectory() const;
341
342     String platformDefaultIconDatabasePath() const;
343
344 #if ENABLE(TIZEN_FILE_SYSTEM)
345     String localFileSystemDirectory() const;
346     String platformDefaultLocalFileSystemDirectory() const;
347 #endif
348
349     String localStorageDirectory() const;
350     String platformDefaultLocalStorageDirectory() const;
351
352 #if ENABLE(TIZEN_INDEXED_DATABASE)
353     String indexedDatabaseDirectory() const;
354     String platformDefaultIndexedDatabaseDirectory() const;
355 #endif
356
357     void handleGetPlugins(uint64_t requestID, bool refresh);
358     void sendDidGetPlugins(uint64_t requestID, PassOwnPtr<Vector<WebCore::PluginInfo> >);
359
360     ProcessModel m_processModel;
361     
362     // FIXME: In the future, this should be one or more WebProcessProxies.
363     RefPtr<WebProcessProxy> m_process;
364
365     RefPtr<WebPageGroup> m_defaultPageGroup;
366
367     RefPtr<APIObject> m_injectedBundleInitializationUserData;
368     String m_injectedBundlePath;
369     WebContextInjectedBundleClient m_injectedBundleClient;
370
371     WebContextConnectionClient m_connectionClient;
372     
373     WebHistoryClient m_historyClient;
374
375     PluginInfoStore m_pluginInfoStore;
376     VisitedLinkProvider m_visitedLinkProvider;
377         
378     HashSet<String> m_schemesToRegisterAsEmptyDocument;
379     HashSet<String> m_schemesToRegisterAsSecure;
380     HashSet<String> m_schemesToSetDomainRelaxationForbiddenFor;
381
382     bool m_alwaysUsesComplexTextCodePath;
383     bool m_shouldUseFontSmoothing;
384
385     Vector<pair<String, RefPtr<APIObject> > > m_pendingMessagesToPostToInjectedBundle;
386
387     CacheModel m_cacheModel;
388 #if ENABLE(TIZEN_CACHE_CONTROL)
389     bool m_cacheDisabled;
390 #endif
391     WebDownloadClient m_downloadClient;
392     HashMap<uint64_t, RefPtr<DownloadProxy> > m_downloads;
393     
394     bool m_memorySamplerEnabled;
395     double m_memorySamplerInterval;
396
397     RefPtr<WebApplicationCacheManagerProxy> m_applicationCacheManagerProxy;
398 #if ENABLE(BATTERY_STATUS)
399     RefPtr<WebBatteryManagerProxy> m_batteryManagerProxy;
400 #endif
401     RefPtr<WebCookieManagerProxy> m_cookieManagerProxy;
402 #if ENABLE(SQL_DATABASE)
403     RefPtr<WebDatabaseManagerProxy> m_databaseManagerProxy;
404 #endif
405     RefPtr<WebGeolocationManagerProxy> m_geolocationManagerProxy;
406     RefPtr<WebIconDatabase> m_iconDatabase;
407     RefPtr<WebKeyValueStorageManagerProxy> m_keyValueStorageManagerProxy;
408 #if ENABLE(TIZEN_FILE_SYSTEM)
409     RefPtr<WebLocalFileSystemManagerProxy> m_localFileSystemManagerProxy;
410 #endif
411     RefPtr<WebMediaCacheManagerProxy> m_mediaCacheManagerProxy;
412 #if ENABLE(NETWORK_INFO)
413     RefPtr<WebNetworkInfoManagerProxy> m_networkInfoManagerProxy;
414 #endif
415     RefPtr<WebNotificationManagerProxy> m_notificationManagerProxy;
416     RefPtr<WebPluginSiteDataManager> m_pluginSiteDataManager;
417     RefPtr<WebResourceCacheManagerProxy> m_resourceCacheManagerProxy;
418 #if USE(SOUP)
419     RefPtr<WebSoupRequestManagerProxy> m_soupRequestManagerProxy;
420 #endif
421 #if ENABLE(VIBRATION)
422     RefPtr<WebVibrationProxy> m_vibrationProxy;
423 #endif
424
425 #if PLATFORM(WIN)
426     bool m_shouldPaintNativeControls;
427     HTTPCookieAcceptPolicy m_initialHTTPCookieAcceptPolicy;
428 #endif
429
430 #if PLATFORM(MAC)
431     RetainPtr<CFTypeRef> m_enhancedAccessibilityObserver;
432 #endif
433
434     String m_overrideDatabaseDirectory;
435     String m_overrideIconDatabasePath;
436 #if ENABLE(TIZEN_FILE_SYSTEM)
437     String m_overrideLocalFileSystemDirectory;
438 #endif
439     String m_overrideLocalStorageDirectory;
440 #if ENABLE(TIZEN_INDEXED_DATABASE)
441     String m_overrideIndexedDatabaseDirectory;
442 #endif
443 #if ENABLE(TIZEN_WEBKIT2_PROXY)
444     String m_proxyAddress;
445 #endif
446
447 #if ENABLE(TIZEN_CERTIFICATE_HANDLING)
448     String m_certificateFile;
449 #endif
450
451 #if ENABLE(TIZEN_SOUP_COOKIE_CACHE_FOR_WEBKIT2)
452     String m_soupDataDirectory;
453 #endif
454
455     bool m_processTerminationEnabled;
456
457     HashMap<uint64_t, RefPtr<DictionaryCallback> > m_dictionaryCallbacks;
458
459     WorkQueue m_pluginWorkQueue;
460 };
461
462 template<typename U> inline bool WebContext::sendToAllProcesses(const U& message)
463 {
464     if (!m_process || !m_process->canSendMessage())
465         return false;
466
467     return m_process->send(message, 0);
468 }
469
470 template<typename U> bool WebContext::sendToAllProcessesRelaunchingThemIfNecessary(const U& message)
471 {
472     relaunchProcessIfNecessary();
473
474     return m_process->send(message, 0);
475 }
476
477 } // namespace WebKit
478
479 #endif // WebContext_h