1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
|
/*
* Copyright (C) 2010, 2011, 2012 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef WebContext_h
#define WebContext_h
#include "APIObject.h"
#include "GenericCallback.h"
#include "MessageReceiver.h"
#include "MessageReceiverMap.h"
#include "PluginInfoStore.h"
#include "ProcessModel.h"
#include "VisitedLinkProvider.h"
#include "WebContextConnectionClient.h"
#include "WebContextInjectedBundleClient.h"
#include "WebDownloadClient.h"
#include "WebHistoryClient.h"
#include "WebProcessProxy.h"
#include <WebCore/LinkHash.h>
#include <wtf/Forward.h>
#include <wtf/HashSet.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefPtr.h>
#include <wtf/text/StringHash.h>
#include <wtf/text/WTFString.h>
namespace WebKit {
class DownloadProxy;
class WebApplicationCacheManagerProxy;
#if ENABLE(BATTERY_STATUS)
class WebBatteryManagerProxy;
#endif
class WebCookieManagerProxy;
class WebDatabaseManagerProxy;
class WebGeolocationManagerProxy;
class WebIconDatabase;
class WebKeyValueStorageManagerProxy;
class WebMediaCacheManagerProxy;
#if ENABLE(NETWORK_INFO)
class WebNetworkInfoManagerProxy;
#endif
class WebNotificationManagerProxy;
class WebPageGroup;
class WebPageProxy;
class WebResourceCacheManagerProxy;
#if USE(SOUP)
class WebSoupRequestManagerProxy;
#endif
struct StatisticsData;
struct WebProcessCreationParameters;
typedef GenericCallback<WKDictionaryRef> DictionaryCallback;
#if PLATFORM(MAC)
extern NSString *SchemeForCustomProtocolRegisteredNotificationName;
extern NSString *SchemeForCustomProtocolUnregisteredNotificationName;
#endif
class WebContext : public APIObject, private CoreIPC::MessageReceiver {
public:
static const Type APIType = TypeContext;
static PassRefPtr<WebContext> create(const String& injectedBundlePath);
virtual ~WebContext();
static const Vector<WebContext*>& allContexts();
void addMessageReceiver(CoreIPC::StringReference messageReceiverName, CoreIPC::MessageReceiver*);
void addMessageReceiver(CoreIPC::StringReference messageReceiverName, uint64_t destinationID, CoreIPC::MessageReceiver*);
void removeMessageReceiver(CoreIPC::StringReference messageReceiverName, uint64_t destinationID);
bool dispatchMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&);
bool dispatchSyncMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&, OwnPtr<CoreIPC::MessageEncoder>&);
void initializeInjectedBundleClient(const WKContextInjectedBundleClient*);
void initializeConnectionClient(const WKContextConnectionClient*);
void initializeHistoryClient(const WKContextHistoryClient*);
void initializeDownloadClient(const WKContextDownloadClient*);
void setProcessModel(ProcessModel); // Can only be called when there are no processes running.
ProcessModel processModel() const { return m_processModel; }
// FIXME (Multi-WebProcess): Remove. No code should assume that there is a shared process.
WebProcessProxy* deprecatedSharedProcess();
template<typename U> void sendToAllProcesses(const U& message);
template<typename U> void sendToAllProcessesRelaunchingThemIfNecessary(const U& message);
void processDidFinishLaunching(WebProcessProxy*);
// Disconnect the process from the context.
void disconnectProcess(WebProcessProxy*);
PassRefPtr<WebPageProxy> createWebPage(PageClient*, WebPageGroup*, WebPageProxy* relatedPage = 0);
const String& injectedBundlePath() const { return m_injectedBundlePath; }
DownloadProxy* download(WebPageProxy* initiatingPage, const WebCore::ResourceRequest&);
void setInjectedBundleInitializationUserData(PassRefPtr<APIObject> userData) { m_injectedBundleInitializationUserData = userData; }
void postMessageToInjectedBundle(const String&, APIObject*);
// InjectedBundle client
void didReceiveMessageFromInjectedBundle(const String&, APIObject*);
void didReceiveSynchronousMessageFromInjectedBundle(const String&, APIObject*, RefPtr<APIObject>& returnData);
void populateVisitedLinks();
#if ENABLE(NETSCAPE_PLUGIN_API)
void setAdditionalPluginsDirectory(const String&);
PluginInfoStore& pluginInfoStore() { return m_pluginInfoStore; }
#endif
String applicationCacheDirectory();
void setAlwaysUsesComplexTextCodePath(bool);
void setShouldUseFontSmoothing(bool);
void registerURLSchemeAsEmptyDocument(const String&);
void registerURLSchemeAsSecure(const String&);
void setDomainRelaxationForbiddenForURLScheme(const String&);
void registerURLSchemeAsLocal(const String&);
void registerURLSchemeAsNoAccess(const String&);
void registerURLSchemeAsDisplayIsolated(const String&);
void registerURLSchemeAsCORSEnabled(const String&);
void addVisitedLink(const String&);
void addVisitedLinkHash(WebCore::LinkHash);
// MessageReceiver.
virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&) OVERRIDE;
virtual void didReceiveSyncMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&, OwnPtr<CoreIPC::MessageEncoder>&) OVERRIDE;
void setCacheModel(CacheModel);
CacheModel cacheModel() const { return m_cacheModel; }
void setDefaultRequestTimeoutInterval(double);
void startMemorySampler(const double interval);
void stopMemorySampler();
#if PLATFORM(WIN)
void setShouldPaintNativeControls(bool);
void setInitialHTTPCookieAcceptPolicy(HTTPCookieAcceptPolicy policy) { m_initialHTTPCookieAcceptPolicy = policy; }
#endif
void setEnhancedAccessibility(bool);
// Downloads.
DownloadProxy* createDownloadProxy();
WebDownloadClient& downloadClient() { return m_downloadClient; }
void downloadFinished(DownloadProxy*);
WebHistoryClient& historyClient() { return m_historyClient; }
static HashSet<String, CaseFoldingHash> pdfAndPostScriptMIMETypes();
WebApplicationCacheManagerProxy* applicationCacheManagerProxy() const { return m_applicationCacheManagerProxy.get(); }
#if ENABLE(BATTERY_STATUS)
WebBatteryManagerProxy* batteryManagerProxy() const { return m_batteryManagerProxy.get(); }
#endif
WebCookieManagerProxy* cookieManagerProxy() const { return m_cookieManagerProxy.get(); }
#if ENABLE(SQL_DATABASE)
WebDatabaseManagerProxy* databaseManagerProxy() const { return m_databaseManagerProxy.get(); }
#endif
WebGeolocationManagerProxy* geolocationManagerProxy() const { return m_geolocationManagerProxy.get(); }
WebIconDatabase* iconDatabase() const { return m_iconDatabase.get(); }
WebKeyValueStorageManagerProxy* keyValueStorageManagerProxy() const { return m_keyValueStorageManagerProxy.get(); }
WebMediaCacheManagerProxy* mediaCacheManagerProxy() const { return m_mediaCacheManagerProxy.get(); }
#if ENABLE(NETWORK_INFO)
WebNetworkInfoManagerProxy* networkInfoManagerProxy() const { return m_networkInfoManagerProxy.get(); }
#endif
WebNotificationManagerProxy* notificationManagerProxy() const { return m_notificationManagerProxy.get(); }
#if ENABLE(NETSCAPE_PLUGIN_API)
WebPluginSiteDataManager* pluginSiteDataManager() const { return m_pluginSiteDataManager.get(); }
#endif
WebResourceCacheManagerProxy* resourceCacheManagerProxy() const { return m_resourceCacheManagerProxy.get(); }
#if USE(SOUP)
WebSoupRequestManagerProxy* soupRequestManagerProxy() const { return m_soupRequestManagerProxy.get(); }
#endif
struct Statistics {
unsigned wkViewCount;
unsigned wkPageCount;
unsigned wkFrameCount;
};
static Statistics& statistics();
void setDatabaseDirectory(const String& dir) { m_overrideDatabaseDirectory = dir; }
void setIconDatabasePath(const String&);
String iconDatabasePath() const;
void setLocalStorageDirectory(const String& dir) { m_overrideLocalStorageDirectory = dir; }
void setDiskCacheDirectory(const String& dir) { m_overrideDiskCacheDirectory = dir; }
void setCookieStorageDirectory(const String& dir) { m_overrideCookieStorageDirectory = dir; }
WebProcessProxy* ensureSharedWebProcess();
PassRefPtr<WebProcessProxy> createNewWebProcess();
void warmInitialProcess();
bool shouldTerminate(WebProcessProxy*);
void disableProcessTermination() { m_processTerminationEnabled = false; }
void enableProcessTermination();
// Defaults to false.
void setHTTPPipeliningEnabled(bool);
bool httpPipeliningEnabled() const;
void getWebCoreStatistics(PassRefPtr<DictionaryCallback>);
void garbageCollectJavaScriptObjects();
void setJavaScriptGarbageCollectorTimerEnabled(bool flag);
#if PLATFORM(MAC)
static bool omitPDFSupport();
#endif
void fullKeyboardAccessModeChanged(bool fullKeyboardAccessEnabled);
void textCheckerStateChanged();
void setUsesNetworkProcess(bool);
#if PLATFORM(MAC)
static bool applicationIsOccluded() { return s_applicationIsOccluded; }
#endif
private:
WebContext(ProcessModel, const String& injectedBundlePath);
virtual Type type() const { return APIType; }
void platformInitializeWebProcess(WebProcessCreationParameters&);
void platformInvalidateContext();
#if PLATFORM(MAC)
void getPasteboardTypes(const String& pasteboardName, Vector<String>& pasteboardTypes);
void getPasteboardPathnamesForType(const String& pasteboardName, const String& pasteboardType, Vector<String>& pathnames);
void getPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, String&);
void getPasteboardBufferForType(const String& pasteboardName, const String& pasteboardType, SharedMemory::Handle&, uint64_t& size);
void pasteboardCopy(const String& fromPasteboard, const String& toPasteboard);
void getPasteboardChangeCount(const String& pasteboardName, uint64_t& changeCount);
void getPasteboardUniqueName(String& pasteboardName);
void getPasteboardColor(const String& pasteboardName, WebCore::Color&);
void getPasteboardURL(const String& pasteboardName, WTF::String&);
void addPasteboardTypes(const String& pasteboardName, const Vector<String>& pasteboardTypes);
void setPasteboardTypes(const String& pasteboardName, const Vector<String>& pasteboardTypes);
void setPasteboardPathnamesForType(const String& pasteboardName, const String& pasteboardType, const Vector<String>& pathnames);
void setPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, const String&);
void setPasteboardBufferForType(const String& pasteboardName, const String& pasteboardType, const SharedMemory::Handle&, uint64_t size);
#endif
#if !PLATFORM(MAC)
// FIXME: This a dummy message, to avoid breaking the build for platforms that don't require
// any synchronous messages, and should be removed when <rdar://problem/8775115> is fixed.
void dummy(bool&);
#endif
void didGetWebCoreStatistics(const StatisticsData&, uint64_t callbackID);
// Implemented in generated WebContextMessageReceiver.cpp
void didReceiveWebContextMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&);
void didReceiveSyncWebContextMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::MessageDecoder&, OwnPtr<CoreIPC::MessageEncoder>&);
static void languageChanged(void* context);
void languageChanged();
String databaseDirectory() const;
String platformDefaultDatabaseDirectory() const;
String platformDefaultIconDatabasePath() const;
String localStorageDirectory() const;
String platformDefaultLocalStorageDirectory() const;
String diskCacheDirectory() const;
String platformDefaultDiskCacheDirectory() const;
String cookieStorageDirectory() const;
String platformDefaultCookieStorageDirectory() const;
#if PLATFORM(MAC)
static void applicationBecameVisible(uint32_t, void*, uint32_t, void*, uint32_t);
static void applicationBecameOccluded(uint32_t, void*, uint32_t, void*, uint32_t);
static void initializeProcessSuppressionSupport();
static void registerOcclusionNotificationHandlers();
#endif
ProcessModel m_processModel;
Vector<RefPtr<WebProcessProxy> > m_processes;
bool m_haveInitialEmptyProcess;
RefPtr<WebPageGroup> m_defaultPageGroup;
RefPtr<APIObject> m_injectedBundleInitializationUserData;
String m_injectedBundlePath;
WebContextInjectedBundleClient m_injectedBundleClient;
WebContextConnectionClient m_connectionClient;
WebHistoryClient m_historyClient;
#if ENABLE(NETSCAPE_PLUGIN_API)
PluginInfoStore m_pluginInfoStore;
#endif
VisitedLinkProvider m_visitedLinkProvider;
HashSet<String> m_schemesToRegisterAsEmptyDocument;
HashSet<String> m_schemesToRegisterAsSecure;
HashSet<String> m_schemesToSetDomainRelaxationForbiddenFor;
HashSet<String> m_schemesToRegisterAsLocal;
HashSet<String> m_schemesToRegisterAsNoAccess;
HashSet<String> m_schemesToRegisterAsDisplayIsolated;
HashSet<String> m_schemesToRegisterAsCORSEnabled;
bool m_alwaysUsesComplexTextCodePath;
bool m_shouldUseFontSmoothing;
// Messages that were posted before any pages were created.
// The client should use initialization messages instead, so that a restarted process would get the same state.
Vector<pair<String, RefPtr<APIObject> > > m_messagesToInjectedBundlePostedToEmptyContext;
CacheModel m_cacheModel;
WebDownloadClient m_downloadClient;
HashMap<uint64_t, RefPtr<DownloadProxy> > m_downloads;
bool m_memorySamplerEnabled;
double m_memorySamplerInterval;
RefPtr<WebApplicationCacheManagerProxy> m_applicationCacheManagerProxy;
#if ENABLE(BATTERY_STATUS)
RefPtr<WebBatteryManagerProxy> m_batteryManagerProxy;
#endif
RefPtr<WebCookieManagerProxy> m_cookieManagerProxy;
#if ENABLE(SQL_DATABASE)
RefPtr<WebDatabaseManagerProxy> m_databaseManagerProxy;
#endif
RefPtr<WebGeolocationManagerProxy> m_geolocationManagerProxy;
RefPtr<WebIconDatabase> m_iconDatabase;
RefPtr<WebKeyValueStorageManagerProxy> m_keyValueStorageManagerProxy;
RefPtr<WebMediaCacheManagerProxy> m_mediaCacheManagerProxy;
#if ENABLE(NETWORK_INFO)
RefPtr<WebNetworkInfoManagerProxy> m_networkInfoManagerProxy;
#endif
RefPtr<WebNotificationManagerProxy> m_notificationManagerProxy;
#if ENABLE(NETSCAPE_PLUGIN_API)
RefPtr<WebPluginSiteDataManager> m_pluginSiteDataManager;
#endif
RefPtr<WebResourceCacheManagerProxy> m_resourceCacheManagerProxy;
#if USE(SOUP)
RefPtr<WebSoupRequestManagerProxy> m_soupRequestManagerProxy;
#endif
#if PLATFORM(WIN)
bool m_shouldPaintNativeControls;
HTTPCookieAcceptPolicy m_initialHTTPCookieAcceptPolicy;
#endif
#if PLATFORM(MAC)
RetainPtr<CFTypeRef> m_enhancedAccessibilityObserver;
RetainPtr<CFTypeRef> m_customSchemeRegisteredObserver;
RetainPtr<CFTypeRef> m_customSchemeUnregisteredObserver;
#endif
String m_overrideDatabaseDirectory;
String m_overrideIconDatabasePath;
String m_overrideLocalStorageDirectory;
String m_overrideDiskCacheDirectory;
String m_overrideCookieStorageDirectory;
bool m_processTerminationEnabled;
#if ENABLE(NETWORK_PROCESS)
bool m_usesNetworkProcess;
#endif
HashMap<uint64_t, RefPtr<DictionaryCallback> > m_dictionaryCallbacks;
CoreIPC::MessageReceiverMap m_messageReceiverMap;
#if PLATFORM(MAC)
static bool s_applicationIsOccluded;
#endif
};
template<typename U> inline void WebContext::sendToAllProcesses(const U& message)
{
size_t processCount = m_processes.size();
for (size_t i = 0; i < processCount; ++i) {
WebProcessProxy* process = m_processes[i].get();
if (process->canSendMessage())
process->send(message, 0);
}
}
template<typename U> void WebContext::sendToAllProcessesRelaunchingThemIfNecessary(const U& message)
{
// FIXME (Multi-WebProcess): WebContext doesn't track processes that have exited, so it cannot relaunch these. Perhaps this functionality won't be needed in this mode.
if (m_processModel == ProcessModelSharedSecondaryProcess)
ensureSharedWebProcess();
sendToAllProcesses(message);
}
} // namespace WebKit
#endif // WebContext_h
|