2 * Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
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>
47 #if ENABLE(TIZEN_EXTENSIBLE_API)
48 #include <WebCore/TizenExtensibleAPI.h>
54 class WebApplicationCacheManagerProxy;
55 #if ENABLE(BATTERY_STATUS)
56 class WebBatteryManagerProxy;
58 class WebCookieManagerProxy;
59 class WebDatabaseManagerProxy;
60 class WebGeolocationManagerProxy;
61 class WebIconDatabase;
62 class WebKeyValueStorageManagerProxy;
63 #if ENABLE(TIZEN_FILE_SYSTEM)
64 class WebLocalFileSystemManagerProxy;
66 class WebMediaCacheManagerProxy;
67 #if ENABLE(NETWORK_INFO)
68 class WebNetworkInfoManagerProxy;
70 class WebNotificationManagerProxy;
73 class WebResourceCacheManagerProxy;
75 class WebSoupRequestManagerProxy;
78 class WebVibrationProxy;
80 struct StatisticsData;
81 struct WebProcessCreationParameters;
83 typedef GenericCallback<WKDictionaryRef> DictionaryCallback;
85 class WebContext : public APIObject, private CoreIPC::Connection::QueueClient {
87 static const Type APIType = TypeContext;
89 static WebContext* sharedProcessContext();
90 static WebContext* sharedThreadContext();
92 static PassRefPtr<WebContext> create(const String& injectedBundlePath);
93 virtual ~WebContext();
95 static const Vector<WebContext*>& allContexts();
97 void initializeInjectedBundleClient(const WKContextInjectedBundleClient*);
98 void initializeConnectionClient(const WKContextConnectionClient*);
99 void initializeHistoryClient(const WKContextHistoryClient*);
100 void initializeDownloadClient(const WKContextDownloadClient*);
102 ProcessModel processModel() const { return m_processModel; }
103 WebProcessProxy* process() const { return m_process.get(); }
105 template<typename U> bool sendToAllProcesses(const U& message);
106 template<typename U> bool sendToAllProcessesRelaunchingThemIfNecessary(const U& message);
108 void processDidFinishLaunching(WebProcessProxy*);
110 // Disconnect the process from the context.
111 void disconnectProcess(WebProcessProxy*);
113 PassRefPtr<WebPageProxy> createWebPage(PageClient*, WebPageGroup*);
115 WebProcessProxy* relaunchProcessIfNecessary();
117 const String& injectedBundlePath() const { return m_injectedBundlePath; }
119 DownloadProxy* download(WebPageProxy* initiatingPage, const WebCore::ResourceRequest&);
121 void setInjectedBundleInitializationUserData(PassRefPtr<APIObject> userData) { m_injectedBundleInitializationUserData = userData; }
123 void postMessageToInjectedBundle(const String&, APIObject*);
125 // InjectedBundle client
126 void didReceiveMessageFromInjectedBundle(const String&, APIObject*);
127 void didReceiveSynchronousMessageFromInjectedBundle(const String&, APIObject*, RefPtr<APIObject>& returnData);
129 void populateVisitedLinks();
131 void setAdditionalPluginsDirectory(const String&);
133 PluginInfoStore& pluginInfoStore() { return m_pluginInfoStore; }
134 String applicationCacheDirectory();
135 #if ENABLE(TIZEN_APPLICATION_CACHE)
136 void setApplicationCacheDirectory(const String&);
137 String platformDefaultApplicationCacheDirectory() const;
140 void setAlwaysUsesComplexTextCodePath(bool);
141 void setShouldUseFontSmoothing(bool);
143 void registerURLSchemeAsEmptyDocument(const String&);
144 void registerURLSchemeAsSecure(const String&);
145 void setDomainRelaxationForbiddenForURLScheme(const String&);
147 void addVisitedLink(const String&);
148 void addVisitedLinkHash(WebCore::LinkHash);
150 void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
151 void didReceiveSyncMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, OwnPtr<CoreIPC::ArgumentEncoder>&);
153 void setCacheModel(CacheModel);
154 CacheModel cacheModel() const { return m_cacheModel; }
156 #if ENABLE(TIZEN_CACHE_CONTROL)
157 void setCacheDisabled(bool usingCacheData);
158 bool getCacheDisabled() const { return m_cacheDisabled; }
161 void setDefaultRequestTimeoutInterval(double);
163 void startMemorySampler(const double interval);
164 void stopMemorySampler();
167 void setShouldPaintNativeControls(bool);
169 void setInitialHTTPCookieAcceptPolicy(HTTPCookieAcceptPolicy policy) { m_initialHTTPCookieAcceptPolicy = policy; }
171 #if ENABLE(TIZEN_WEBKIT2_PROXY)
172 void setProxy(const String&);
174 #if ENABLE(TIZEN_SESSION_REQUEST_CANCEL)
178 #if ENABLE(TIZEN_CERTIFICATE_HANDLING)
179 void setCertificateFile(const String&);
183 void notifyLowMemory();
186 #if ENABLE(TIZEN_PROCESS_PERMISSION_CONTROL)
187 void setWebProcessExecutablePath(const String& path) { m_webProcessExecutablePath = path; };
188 const String& webProcessExecutablePath() const { return m_webProcessExecutablePath; };
191 #if ENABLE(TIZEN_WEBKIT2_MEMORY_SAVING_MODE)
192 void setMemorySavingMode(bool memorySavingMode);
195 void setEnhancedAccessibility(bool);
198 DownloadProxy* createDownloadProxy();
199 WebDownloadClient& downloadClient() { return m_downloadClient; }
200 void downloadFinished(DownloadProxy*);
202 static HashSet<String, CaseFoldingHash> pdfAndPostScriptMIMETypes();
204 WebApplicationCacheManagerProxy* applicationCacheManagerProxy() const { return m_applicationCacheManagerProxy.get(); }
205 #if ENABLE(BATTERY_STATUS)
206 WebBatteryManagerProxy* batteryManagerProxy() const { return m_batteryManagerProxy.get(); }
208 WebCookieManagerProxy* cookieManagerProxy() const { return m_cookieManagerProxy.get(); }
209 #if ENABLE(SQL_DATABASE)
210 WebDatabaseManagerProxy* databaseManagerProxy() const { return m_databaseManagerProxy.get(); }
212 WebGeolocationManagerProxy* geolocationManagerProxy() const { return m_geolocationManagerProxy.get(); }
213 WebIconDatabase* iconDatabase() const { return m_iconDatabase.get(); }
214 WebKeyValueStorageManagerProxy* keyValueStorageManagerProxy() const { return m_keyValueStorageManagerProxy.get(); }
215 #if ENABLE(TIZEN_FILE_SYSTEM)
216 WebLocalFileSystemManagerProxy* localFileSystemManagerProxy() const { return m_localFileSystemManagerProxy.get(); }
218 WebMediaCacheManagerProxy* mediaCacheManagerProxy() const { return m_mediaCacheManagerProxy.get(); }
219 #if ENABLE(NETWORK_INFO)
220 WebNetworkInfoManagerProxy* networkInfoManagerProxy() const { return m_networkInfoManagerProxy.get(); }
222 WebNotificationManagerProxy* notificationManagerProxy() const { return m_notificationManagerProxy.get(); }
223 WebPluginSiteDataManager* pluginSiteDataManager() const { return m_pluginSiteDataManager.get(); }
224 WebResourceCacheManagerProxy* resourceCacheManagerProxy() const { return m_resourceCacheManagerProxy.get(); }
226 WebSoupRequestManagerProxy* soupRequestManagerProxy() const { return m_soupRequestManagerProxy.get(); }
228 #if ENABLE(VIBRATION)
229 WebVibrationProxy* vibrationProxy() const { return m_vibrationProxy.get(); }
233 unsigned wkViewCount;
234 unsigned wkPageCount;
235 unsigned wkFrameCount;
237 static Statistics& statistics();
239 void setDatabaseDirectory(const String& dir) { m_overrideDatabaseDirectory = dir; }
240 void setIconDatabasePath(const String&);
241 String iconDatabasePath() const;
242 #if ENABLE(TIZEN_FILE_SYSTEM)
243 void setLocalFileSystemDirectory(const String& dir) { m_overrideLocalFileSystemDirectory = dir; }
245 void setLocalStorageDirectory(const String& dir) { m_overrideLocalStorageDirectory = dir; }
246 #if ENABLE(TIZEN_INDEXED_DATABASE)
247 void setIndexedDatabaseDirectory(const String& dir) { m_overrideIndexedDatabaseDirectory = dir; }
250 void ensureWebProcess();
251 void warmInitialProcess();
253 bool shouldTerminate(WebProcessProxy*);
255 void disableProcessTermination() { m_processTerminationEnabled = false; }
256 void enableProcessTermination();
258 // Defaults to false.
259 void setHTTPPipeliningEnabled(bool);
260 bool httpPipeliningEnabled() const;
262 void getWebCoreStatistics(PassRefPtr<DictionaryCallback>);
263 void garbageCollectJavaScriptObjects();
264 void setJavaScriptGarbageCollectorTimerEnabled(bool flag);
267 static bool omitPDFSupport();
270 #if ENABLE(TIZEN_SOUP_COOKIE_CACHE_FOR_WEBKIT2)
271 String soupDataDirectory();
272 void setSoupDataDirectory(const String& path) { m_soupDataDirectory = path; }
273 String platformDefaultSoupDataDirectory();
276 void fullKeyboardAccessModeChanged(bool fullKeyboardAccessEnabled);
278 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_X_WINDOW)
279 void setXWindow(unsigned);
282 #if ENABLE(TIZEN_EXTENSIBLE_API)
283 void setTizenExtensibleAPI(WebCore::ExtensibleAPI extensibleAPI, bool enable);
286 #if ENABLE(TIZEN_RESET_PATH)
287 void resetStoragePath();
290 #if ENABLE(TIZEN_INDEXED_DATABASE)
291 void deleteIndexedDatabaseAll();
295 WebContext(ProcessModel, const String& injectedBundlePath);
297 virtual Type type() const { return APIType; }
299 void platformInitializeWebProcess(WebProcessCreationParameters&);
300 void platformInvalidateContext();
303 void didNavigateWithNavigationData(uint64_t pageID, const WebNavigationDataStore& store, uint64_t frameID);
304 void didPerformClientRedirect(uint64_t pageID, const String& sourceURLString, const String& destinationURLString, uint64_t frameID);
305 void didPerformServerRedirect(uint64_t pageID, const String& sourceURLString, const String& destinationURLString, uint64_t frameID);
306 void didUpdateHistoryTitle(uint64_t pageID, const String& title, const String& url, uint64_t frameID);
309 void getPlugins(CoreIPC::Connection*, uint64_t requestID, bool refresh);
310 void getPluginPath(const String& mimeType, const String& urlString, String& pluginPath, bool& blocked);
311 #if !ENABLE(PLUGIN_PROCESS)
312 void didGetSitesWithPluginData(const Vector<String>& sites, uint64_t callbackID);
313 void didClearPluginSiteData(uint64_t callbackID);
317 void getPasteboardTypes(const String& pasteboardName, Vector<String>& pasteboardTypes);
318 void getPasteboardPathnamesForType(const String& pasteboardName, const String& pasteboardType, Vector<String>& pathnames);
319 void getPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, String&);
320 void getPasteboardBufferForType(const String& pasteboardName, const String& pasteboardType, SharedMemory::Handle&, uint64_t& size);
321 void pasteboardCopy(const String& fromPasteboard, const String& toPasteboard);
322 void getPasteboardChangeCount(const String& pasteboardName, uint64_t& changeCount);
323 void getPasteboardUniqueName(String& pasteboardName);
324 void getPasteboardColor(const String& pasteboardName, WebCore::Color&);
325 void getPasteboardURL(const String& pasteboardName, WTF::String&);
326 void addPasteboardTypes(const String& pasteboardName, const Vector<String>& pasteboardTypes);
327 void setPasteboardTypes(const String& pasteboardName, const Vector<String>& pasteboardTypes);
328 void setPasteboardPathnamesForType(const String& pasteboardName, const String& pasteboardType, const Vector<String>& pathnames);
329 void setPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, const String&);
330 void setPasteboardBufferForType(const String& pasteboardName, const String& pasteboardType, const SharedMemory::Handle&, uint64_t size);
333 void didGetWebCoreStatistics(const StatisticsData&, uint64_t callbackID);
335 // Implemented in generated WebContextMessageReceiver.cpp
336 void didReceiveWebContextMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
337 void didReceiveSyncWebContextMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, OwnPtr<CoreIPC::ArgumentEncoder>&);
338 void didReceiveWebContextMessageOnConnectionWorkQueue(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, bool& didHandleMessage);
340 virtual void didReceiveMessageOnConnectionWorkQueue(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, bool& didHandleMessage) OVERRIDE;
342 static void languageChanged(void* context);
343 void languageChanged();
345 String databaseDirectory() const;
346 String platformDefaultDatabaseDirectory() const;
348 String platformDefaultIconDatabasePath() const;
350 #if ENABLE(TIZEN_FILE_SYSTEM)
351 String localFileSystemDirectory() const;
352 String platformDefaultLocalFileSystemDirectory() const;
355 String localStorageDirectory() const;
356 String platformDefaultLocalStorageDirectory() const;
358 #if ENABLE(TIZEN_INDEXED_DATABASE)
359 String indexedDatabaseDirectory() const;
360 String platformDefaultIndexedDatabaseDirectory() const;
363 void handleGetPlugins(uint64_t requestID, bool refresh);
364 void sendDidGetPlugins(uint64_t requestID, PassOwnPtr<Vector<WebCore::PluginInfo> >);
366 ProcessModel m_processModel;
368 // FIXME: In the future, this should be one or more WebProcessProxies.
369 RefPtr<WebProcessProxy> m_process;
371 RefPtr<WebPageGroup> m_defaultPageGroup;
373 RefPtr<APIObject> m_injectedBundleInitializationUserData;
374 String m_injectedBundlePath;
375 WebContextInjectedBundleClient m_injectedBundleClient;
377 WebContextConnectionClient m_connectionClient;
379 WebHistoryClient m_historyClient;
381 PluginInfoStore m_pluginInfoStore;
382 VisitedLinkProvider m_visitedLinkProvider;
384 HashSet<String> m_schemesToRegisterAsEmptyDocument;
385 HashSet<String> m_schemesToRegisterAsSecure;
386 HashSet<String> m_schemesToSetDomainRelaxationForbiddenFor;
388 bool m_alwaysUsesComplexTextCodePath;
389 bool m_shouldUseFontSmoothing;
391 Vector<pair<String, RefPtr<APIObject> > > m_pendingMessagesToPostToInjectedBundle;
393 CacheModel m_cacheModel;
394 #if ENABLE(TIZEN_CACHE_CONTROL)
395 bool m_cacheDisabled;
397 WebDownloadClient m_downloadClient;
398 HashMap<uint64_t, RefPtr<DownloadProxy> > m_downloads;
400 bool m_memorySamplerEnabled;
401 double m_memorySamplerInterval;
403 RefPtr<WebApplicationCacheManagerProxy> m_applicationCacheManagerProxy;
404 #if ENABLE(BATTERY_STATUS)
405 RefPtr<WebBatteryManagerProxy> m_batteryManagerProxy;
407 RefPtr<WebCookieManagerProxy> m_cookieManagerProxy;
408 #if ENABLE(SQL_DATABASE)
409 RefPtr<WebDatabaseManagerProxy> m_databaseManagerProxy;
411 RefPtr<WebGeolocationManagerProxy> m_geolocationManagerProxy;
412 RefPtr<WebIconDatabase> m_iconDatabase;
413 RefPtr<WebKeyValueStorageManagerProxy> m_keyValueStorageManagerProxy;
414 #if ENABLE(TIZEN_FILE_SYSTEM)
415 RefPtr<WebLocalFileSystemManagerProxy> m_localFileSystemManagerProxy;
417 RefPtr<WebMediaCacheManagerProxy> m_mediaCacheManagerProxy;
418 #if ENABLE(NETWORK_INFO)
419 RefPtr<WebNetworkInfoManagerProxy> m_networkInfoManagerProxy;
421 RefPtr<WebNotificationManagerProxy> m_notificationManagerProxy;
422 RefPtr<WebPluginSiteDataManager> m_pluginSiteDataManager;
423 RefPtr<WebResourceCacheManagerProxy> m_resourceCacheManagerProxy;
425 RefPtr<WebSoupRequestManagerProxy> m_soupRequestManagerProxy;
427 #if ENABLE(VIBRATION)
428 RefPtr<WebVibrationProxy> m_vibrationProxy;
432 bool m_shouldPaintNativeControls;
433 HTTPCookieAcceptPolicy m_initialHTTPCookieAcceptPolicy;
437 RetainPtr<CFTypeRef> m_enhancedAccessibilityObserver;
440 String m_overrideDatabaseDirectory;
441 String m_overrideIconDatabasePath;
442 #if ENABLE(TIZEN_FILE_SYSTEM)
443 String m_overrideLocalFileSystemDirectory;
445 String m_overrideLocalStorageDirectory;
446 #if ENABLE(TIZEN_INDEXED_DATABASE)
447 String m_overrideIndexedDatabaseDirectory;
449 #if ENABLE(TIZEN_WEBKIT2_PROXY)
450 String m_proxyAddress;
453 #if ENABLE(TIZEN_CERTIFICATE_HANDLING)
454 String m_certificateFile;
457 #if ENABLE(TIZEN_SOUP_COOKIE_CACHE_FOR_WEBKIT2)
458 String m_soupDataDirectory;
461 #if ENABLE(TIZEN_PROCESS_PERMISSION_CONTROL)
462 String m_webProcessExecutablePath;
465 bool m_processTerminationEnabled;
467 HashMap<uint64_t, RefPtr<DictionaryCallback> > m_dictionaryCallbacks;
469 WorkQueue m_pluginWorkQueue;
472 template<typename U> inline bool WebContext::sendToAllProcesses(const U& message)
474 if (!m_process || !m_process->canSendMessage())
477 return m_process->send(message, 0);
480 template<typename U> bool WebContext::sendToAllProcessesRelaunchingThemIfNecessary(const U& message)
482 relaunchProcessIfNecessary();
484 return m_process->send(message, 0);
487 } // namespace WebKit
489 #endif // WebContext_h