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.
27 #include "WebContext.h"
29 #include "DownloadProxy.h"
30 #include "ImmutableArray.h"
31 #include "InjectedBundleMessageKinds.h"
33 #include "MutableDictionary.h"
34 #include "SandboxExtension.h"
35 #include "StatisticsData.h"
36 #include "TextChecker.h"
37 #include "WKContextPrivate.h"
38 #include "WebApplicationCacheManagerProxy.h"
39 #include "WebContextMessageKinds.h"
40 #include "WebContextUserMessageCoders.h"
41 #include "WebCookieManagerProxy.h"
42 #include "WebCoreArgumentCoders.h"
43 #include "WebDatabaseManagerProxy.h"
44 #include "WebGeolocationManagerProxy.h"
45 #include "WebIconDatabase.h"
46 #include "WebKeyValueStorageManagerProxy.h"
47 #include "WebMediaCacheManagerProxy.h"
48 #include "WebNotificationManagerProxy.h"
49 #include "WebPluginSiteDataManager.h"
50 #include "WebPageGroup.h"
51 #include "WebMemorySampler.h"
52 #include "WebProcessCreationParameters.h"
53 #include "WebProcessMessages.h"
54 #include "WebProcessProxy.h"
55 #include "WebResourceCacheManagerProxy.h"
56 #include <WebCore/Language.h>
57 #include <WebCore/LinkHash.h>
58 #include <WebCore/Logging.h>
59 #include <WebCore/ResourceRequest.h>
60 #include <WebCore/RunLoop.h>
61 #include <runtime/InitializeThreading.h>
62 #include <wtf/CurrentTime.h>
63 #include <wtf/MainThread.h>
66 #include "BuiltInPDFView.h"
69 #if ENABLE(BATTERY_STATUS)
70 #include "WebBatteryManagerProxy.h"
73 #if ENABLE(NETWORK_INFO)
74 #include "WebNetworkInfoManagerProxy.h"
78 #include "WebSoupRequestManagerProxy.h"
81 #if ENABLE(TIZEN_FILE_SYSTEM)
82 #include "WebLocalFileSystemManagerProxy.h"
86 #include "WebVibrationProxy.h"
90 #include <wtf/RefCountedLeakCounter.h>
93 #define MESSAGE_CHECK(assertion) MESSAGE_CHECK_BASE(assertion, m_process->connection())
94 #define MESSAGE_CHECK_URL(url) MESSAGE_CHECK_BASE(m_process->checkURLReceivedFromWebProcess(url), m_process->connection())
96 using namespace WebCore;
100 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, webContextCounter, ("WebContext"));
102 WebContext* WebContext::sharedProcessContext()
104 JSC::initializeThreading();
105 WTF::initializeMainThread();
106 RunLoop::initializeMainRunLoop();
107 static WebContext* context = adoptRef(new WebContext(ProcessModelSharedSecondaryProcess, String())).leakRef();
111 WebContext* WebContext::sharedThreadContext()
113 RunLoop::initializeMainRunLoop();
114 static WebContext* context = adoptRef(new WebContext(ProcessModelSharedSecondaryThread, String())).leakRef();
118 PassRefPtr<WebContext> WebContext::create(const String& injectedBundlePath)
120 JSC::initializeThreading();
121 WTF::initializeMainThread();
122 RunLoop::initializeMainRunLoop();
123 return adoptRef(new WebContext(ProcessModelSecondaryProcess, injectedBundlePath));
126 static Vector<WebContext*>& contexts()
128 DEFINE_STATIC_LOCAL(Vector<WebContext*>, contexts, ());
133 const Vector<WebContext*>& WebContext::allContexts()
138 WebContext::WebContext(ProcessModel processModel, const String& injectedBundlePath)
139 : m_processModel(processModel)
140 , m_defaultPageGroup(WebPageGroup::create())
141 , m_injectedBundlePath(injectedBundlePath)
142 , m_visitedLinkProvider(this)
143 , m_alwaysUsesComplexTextCodePath(false)
144 , m_shouldUseFontSmoothing(true)
145 , m_cacheModel(CacheModelDocumentViewer)
146 , m_memorySamplerEnabled(false)
147 , m_memorySamplerInterval(1400.0)
148 , m_applicationCacheManagerProxy(WebApplicationCacheManagerProxy::create(this))
149 #if ENABLE(BATTERY_STATUS)
150 , m_batteryManagerProxy(WebBatteryManagerProxy::create(this))
152 , m_cookieManagerProxy(WebCookieManagerProxy::create(this))
153 #if ENABLE(SQL_DATABASE)
154 , m_databaseManagerProxy(WebDatabaseManagerProxy::create(this))
156 , m_geolocationManagerProxy(WebGeolocationManagerProxy::create(this))
157 , m_iconDatabase(WebIconDatabase::create(this))
158 , m_keyValueStorageManagerProxy(WebKeyValueStorageManagerProxy::create(this))
159 #if ENABLE(TIZEN_FILE_SYSTEM)
160 , m_localFileSystemManagerProxy(WebLocalFileSystemManagerProxy::create(this))
162 , m_mediaCacheManagerProxy(WebMediaCacheManagerProxy::create(this))
163 #if ENABLE(NETWORK_INFO)
164 , m_networkInfoManagerProxy(WebNetworkInfoManagerProxy::create(this))
166 , m_notificationManagerProxy(WebNotificationManagerProxy::create(this))
167 , m_pluginSiteDataManager(WebPluginSiteDataManager::create(this))
168 , m_resourceCacheManagerProxy(WebResourceCacheManagerProxy::create(this))
170 , m_soupRequestManagerProxy(WebSoupRequestManagerProxy::create(this))
172 #if ENABLE(VIBRATION)
173 , m_vibrationProxy(WebVibrationProxy::create(this))
176 , m_shouldPaintNativeControls(true)
177 , m_initialHTTPCookieAcceptPolicy(HTTPCookieAcceptPolicyAlways)
179 , m_processTerminationEnabled(true)
180 , m_pluginWorkQueue("com.apple.CoreIPC.PluginQueue")
183 WebKit::initializeLogChannelsIfNecessary();
186 contexts().append(this);
188 addLanguageChangeObserver(this, languageChanged);
191 WebCore::initializeLoggingChannelsIfNecessary();
192 #endif // !LOG_DISABLED
195 webContextCounter.increment();
199 WebContext::~WebContext()
201 m_pluginWorkQueue.invalidate();
203 if (m_process && m_process->isValid())
204 m_process->connection()->removeQueueClient(this);
206 ASSERT(contexts().find(this) != notFound);
207 contexts().remove(contexts().find(this));
209 removeLanguageChangeObserver(this);
211 m_applicationCacheManagerProxy->invalidate();
212 m_applicationCacheManagerProxy->clearContext();
214 #if ENABLE(BATTERY_STATUS)
215 m_batteryManagerProxy->invalidate();
216 m_batteryManagerProxy->clearContext();
219 m_cookieManagerProxy->invalidate();
220 m_cookieManagerProxy->clearContext();
222 #if ENABLE(SQL_DATABASE)
223 m_databaseManagerProxy->invalidate();
224 m_databaseManagerProxy->clearContext();
227 m_geolocationManagerProxy->invalidate();
228 m_geolocationManagerProxy->clearContext();
230 m_iconDatabase->invalidate();
231 m_iconDatabase->clearContext();
233 m_keyValueStorageManagerProxy->invalidate();
234 m_keyValueStorageManagerProxy->clearContext();
236 #if ENABLE(TIZEN_FILE_SYSTEM)
237 m_localFileSystemManagerProxy->invalidate();
238 m_localFileSystemManagerProxy->clearContext();
241 m_mediaCacheManagerProxy->invalidate();
242 m_mediaCacheManagerProxy->clearContext();
244 #if ENABLE(NETWORK_INFO)
245 m_networkInfoManagerProxy->invalidate();
246 m_networkInfoManagerProxy->clearContext();
249 m_notificationManagerProxy->invalidate();
250 m_notificationManagerProxy->clearContext();
252 m_pluginSiteDataManager->invalidate();
253 m_pluginSiteDataManager->clearContext();
255 m_resourceCacheManagerProxy->invalidate();
256 m_resourceCacheManagerProxy->clearContext();
259 m_soupRequestManagerProxy->invalidate();
260 m_soupRequestManagerProxy->clearContext();
263 #if ENABLE(VIBRATION)
264 m_vibrationProxy->invalidate();
265 m_vibrationProxy->clearContext();
268 invalidateCallbackMap(m_dictionaryCallbacks);
270 platformInvalidateContext();
273 webContextCounter.decrement();
277 void WebContext::initializeInjectedBundleClient(const WKContextInjectedBundleClient* client)
279 m_injectedBundleClient.initialize(client);
282 void WebContext::initializeConnectionClient(const WKContextConnectionClient* client)
284 m_connectionClient.initialize(client);
287 void WebContext::initializeHistoryClient(const WKContextHistoryClient* client)
289 m_historyClient.initialize(client);
291 sendToAllProcesses(Messages::WebProcess::SetShouldTrackVisitedLinks(m_historyClient.shouldTrackVisitedLinks()));
294 void WebContext::initializeDownloadClient(const WKContextDownloadClient* client)
296 m_downloadClient.initialize(client);
299 void WebContext::languageChanged(void* context)
301 static_cast<WebContext*>(context)->languageChanged();
304 void WebContext::languageChanged()
306 sendToAllProcesses(Messages::WebProcess::UserPreferredLanguagesChanged(userPreferredLanguages()));
309 void WebContext::fullKeyboardAccessModeChanged(bool fullKeyboardAccessEnabled)
311 sendToAllProcesses(Messages::WebProcess::FullKeyboardAccessModeChanged(fullKeyboardAccessEnabled));
314 void WebContext::ensureWebProcess()
319 m_process = WebProcessProxy::create(this);
321 WebProcessCreationParameters parameters;
323 if (!injectedBundlePath().isEmpty()) {
324 parameters.injectedBundlePath = injectedBundlePath();
325 SandboxExtension::createHandle(parameters.injectedBundlePath, SandboxExtension::ReadOnly, parameters.injectedBundlePathExtensionHandle);
328 parameters.shouldTrackVisitedLinks = m_historyClient.shouldTrackVisitedLinks();
329 parameters.cacheModel = m_cacheModel;
330 parameters.languages = userPreferredLanguages();
331 parameters.applicationCacheDirectory = applicationCacheDirectory();
332 parameters.databaseDirectory = databaseDirectory();
333 #if ENABLE(TIZEN_FILE_SYSTEM)
334 parameters.localFileSystemDirectory = localFileSystemDirectory();
336 parameters.localStorageDirectory = localStorageDirectory();
337 #if ENABLE(TIZEN_INDEXED_DATABASE)
338 parameters.indexedDatabaseDirectory = indexedDatabaseDirectory();
342 parameters.presenterApplicationPid = getpid();
345 copyToVector(m_schemesToRegisterAsEmptyDocument, parameters.urlSchemesRegistererdAsEmptyDocument);
346 copyToVector(m_schemesToRegisterAsSecure, parameters.urlSchemesRegisteredAsSecure);
347 copyToVector(m_schemesToSetDomainRelaxationForbiddenFor, parameters.urlSchemesForWhichDomainRelaxationIsForbidden);
349 parameters.shouldAlwaysUseComplexTextCodePath = m_alwaysUsesComplexTextCodePath;
350 parameters.shouldUseFontSmoothing = m_shouldUseFontSmoothing;
352 parameters.iconDatabaseEnabled = !iconDatabasePath().isEmpty();
354 parameters.textCheckerState = TextChecker::state();
356 parameters.fullKeyboardAccessEnabled = WebProcessProxy::fullKeyboardAccessEnabled();
358 parameters.defaultRequestTimeoutInterval = WebURLRequest::defaultTimeoutInterval();
360 #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
361 m_notificationManagerProxy->populateCopyOfNotificationPermissions(parameters.notificationPermissions);
364 // Add any platform specific parameters
365 platformInitializeWebProcess(parameters);
367 RefPtr<APIObject> injectedBundleInitializationUserData = m_injectedBundleClient.getInjectedBundleInitializationUserData(this);
368 if (!injectedBundleInitializationUserData)
369 injectedBundleInitializationUserData = m_injectedBundleInitializationUserData;
370 m_process->send(Messages::WebProcess::InitializeWebProcess(parameters, WebContextUserMessageEncoder(injectedBundleInitializationUserData.get())), 0);
372 for (size_t i = 0; i != m_pendingMessagesToPostToInjectedBundle.size(); ++i) {
373 pair<String, RefPtr<APIObject> >& message = m_pendingMessagesToPostToInjectedBundle[i];
374 m_process->deprecatedSend(InjectedBundleMessage::PostMessage, 0, CoreIPC::In(message.first, WebContextUserMessageEncoder(message.second.get())));
376 m_pendingMessagesToPostToInjectedBundle.clear();
379 void WebContext::warmInitialProcess()
384 void WebContext::enableProcessTermination()
386 m_processTerminationEnabled = true;
387 if (shouldTerminate(m_process.get()))
388 m_process->terminate();
391 bool WebContext::shouldTerminate(WebProcessProxy* process)
393 // FIXME: Once we support multiple processes per context, this assertion won't hold.
394 ASSERT(process == m_process);
396 if (!m_processTerminationEnabled)
399 if (!m_downloads.isEmpty())
402 if (!m_applicationCacheManagerProxy->shouldTerminate(process))
404 if (!m_cookieManagerProxy->shouldTerminate(process))
406 #if ENABLE(SQL_DATABASE)
407 if (!m_databaseManagerProxy->shouldTerminate(process))
410 if (!m_keyValueStorageManagerProxy->shouldTerminate(process))
412 #if ENABLE(TIZEN_FILE_SYSTEM)
413 if (!m_localFileSystemManagerProxy->shouldTerminate(process))
416 if (!m_mediaCacheManagerProxy->shouldTerminate(process))
418 if (!m_pluginSiteDataManager->shouldTerminate(process))
420 if (!m_resourceCacheManagerProxy->shouldTerminate(process))
426 void WebContext::processDidFinishLaunching(WebProcessProxy* process)
428 // FIXME: Once we support multiple processes per context, this assertion won't hold.
429 ASSERT_UNUSED(process, process == m_process);
431 m_visitedLinkProvider.processDidFinishLaunching();
433 m_process->connection()->addQueueClient(this);
435 // Sometimes the memorySampler gets initialized after process initialization has happened but before the process has finished launching
436 // so check if it needs to be started here
437 if (m_memorySamplerEnabled) {
438 SandboxExtension::Handle sampleLogSandboxHandle;
439 double now = WTF::currentTime();
440 String sampleLogFilePath = String::format("WebProcess%llu", static_cast<unsigned long long>(now));
441 sampleLogFilePath = SandboxExtension::createHandleForTemporaryFile(sampleLogFilePath, SandboxExtension::WriteOnly, sampleLogSandboxHandle);
443 m_process->send(Messages::WebProcess::StartMemorySampler(sampleLogSandboxHandle, sampleLogFilePath, m_memorySamplerInterval), 0);
446 m_connectionClient.didCreateConnection(this, process->webConnection());
449 void WebContext::disconnectProcess(WebProcessProxy* process)
451 // FIXME: Once we support multiple processes per context, this assertion won't hold.
452 ASSERT_UNUSED(process, process == m_process);
454 m_visitedLinkProvider.processDidClose();
456 // Invalidate all outstanding downloads.
457 for (HashMap<uint64_t, RefPtr<DownloadProxy> >::iterator::Values it = m_downloads.begin().values(), end = m_downloads.end().values(); it != end; ++it) {
458 (*it)->processDidClose();
464 m_applicationCacheManagerProxy->invalidate();
465 #if ENABLE(BATTERY_STATUS)
466 m_batteryManagerProxy->invalidate();
468 m_cookieManagerProxy->invalidate();
469 #if ENABLE(SQL_DATABASE)
470 m_databaseManagerProxy->invalidate();
472 m_geolocationManagerProxy->invalidate();
473 m_keyValueStorageManagerProxy->invalidate();
474 #if ENABLE(TIZEN_FILE_SYSTEM)
475 m_localFileSystemManagerProxy->invalidate();
477 m_mediaCacheManagerProxy->invalidate();
478 #if ENABLE(NETWORK_INFO)
479 m_networkInfoManagerProxy->invalidate();
481 m_notificationManagerProxy->invalidate();
482 m_resourceCacheManagerProxy->invalidate();
484 m_soupRequestManagerProxy->invalidate();
486 #if ENABLE(VIBRATION)
487 m_vibrationProxy->invalidate();
490 // When out of process plug-ins are enabled, we don't want to invalidate the plug-in site data
491 // manager just because the web process crashes since it's not involved.
492 #if !ENABLE(PLUGIN_PROCESS)
493 m_pluginSiteDataManager->invalidate();
496 // This can cause the web context to be destroyed.
500 PassRefPtr<WebPageProxy> WebContext::createWebPage(PageClient* pageClient, WebPageGroup* pageGroup)
505 pageGroup = m_defaultPageGroup.get();
507 return m_process->createWebPage(pageClient, this, pageGroup);
510 WebProcessProxy* WebContext::relaunchProcessIfNecessary()
515 return m_process.get();
518 DownloadProxy* WebContext::download(WebPageProxy* initiatingPage, const ResourceRequest& request)
522 DownloadProxy* download = createDownloadProxy();
523 uint64_t initiatingPageID = initiatingPage ? initiatingPage->pageID() : 0;
526 ASSERT(initiatingPage); // Our design does not suppport downloads without a WebPage.
527 initiatingPage->handleDownloadRequest(download);
530 process()->send(Messages::WebProcess::DownloadRequest(download->downloadID(), initiatingPageID, request), 0);
534 void WebContext::postMessageToInjectedBundle(const String& messageName, APIObject* messageBody)
536 if (!m_process || !m_process->canSendMessage()) {
537 m_pendingMessagesToPostToInjectedBundle.append(std::make_pair(messageName, messageBody));
541 // FIXME: We should consider returning false from this function if the messageBody cannot
543 m_process->deprecatedSend(InjectedBundleMessage::PostMessage, 0, CoreIPC::In(messageName, WebContextUserMessageEncoder(messageBody)));
546 // InjectedBundle client
548 void WebContext::didReceiveMessageFromInjectedBundle(const String& messageName, APIObject* messageBody)
550 m_injectedBundleClient.didReceiveMessageFromInjectedBundle(this, messageName, messageBody);
553 void WebContext::didReceiveSynchronousMessageFromInjectedBundle(const String& messageName, APIObject* messageBody, RefPtr<APIObject>& returnData)
555 m_injectedBundleClient.didReceiveSynchronousMessageFromInjectedBundle(this, messageName, messageBody, returnData);
560 void WebContext::didNavigateWithNavigationData(uint64_t pageID, const WebNavigationDataStore& store, uint64_t frameID)
562 WebPageProxy* page = m_process->webPage(pageID);
566 WebFrameProxy* frame = m_process->webFrame(frameID);
567 MESSAGE_CHECK(frame);
568 MESSAGE_CHECK(frame->page() == page);
570 m_historyClient.didNavigateWithNavigationData(this, page, store, frame);
573 void WebContext::didPerformClientRedirect(uint64_t pageID, const String& sourceURLString, const String& destinationURLString, uint64_t frameID)
575 WebPageProxy* page = m_process->webPage(pageID);
579 if (sourceURLString.isEmpty() || destinationURLString.isEmpty())
582 WebFrameProxy* frame = m_process->webFrame(frameID);
583 MESSAGE_CHECK(frame);
584 MESSAGE_CHECK(frame->page() == page);
585 MESSAGE_CHECK_URL(sourceURLString);
586 MESSAGE_CHECK_URL(destinationURLString);
588 m_historyClient.didPerformClientRedirect(this, page, sourceURLString, destinationURLString, frame);
591 void WebContext::didPerformServerRedirect(uint64_t pageID, const String& sourceURLString, const String& destinationURLString, uint64_t frameID)
593 WebPageProxy* page = m_process->webPage(pageID);
597 if (sourceURLString.isEmpty() || destinationURLString.isEmpty())
600 WebFrameProxy* frame = m_process->webFrame(frameID);
601 MESSAGE_CHECK(frame);
602 MESSAGE_CHECK(frame->page() == page);
603 MESSAGE_CHECK_URL(sourceURLString);
604 MESSAGE_CHECK_URL(destinationURLString);
606 m_historyClient.didPerformServerRedirect(this, page, sourceURLString, destinationURLString, frame);
609 void WebContext::didUpdateHistoryTitle(uint64_t pageID, const String& title, const String& url, uint64_t frameID)
611 WebPageProxy* page = m_process->webPage(pageID);
615 WebFrameProxy* frame = m_process->webFrame(frameID);
616 MESSAGE_CHECK(frame);
617 MESSAGE_CHECK(frame->page() == page);
618 MESSAGE_CHECK_URL(url);
620 m_historyClient.didUpdateHistoryTitle(this, page, title, url, frame);
623 void WebContext::populateVisitedLinks()
625 m_historyClient.populateVisitedLinks(this);
628 WebContext::Statistics& WebContext::statistics()
630 static Statistics statistics = Statistics();
635 void WebContext::setAdditionalPluginsDirectory(const String& directory)
637 Vector<String> directories;
638 directories.append(directory);
640 m_pluginInfoStore.setAdditionalPluginsDirectories(directories);
643 void WebContext::setAlwaysUsesComplexTextCodePath(bool alwaysUseComplexText)
645 m_alwaysUsesComplexTextCodePath = alwaysUseComplexText;
646 sendToAllProcesses(Messages::WebProcess::SetAlwaysUsesComplexTextCodePath(alwaysUseComplexText));
649 void WebContext::setShouldUseFontSmoothing(bool useFontSmoothing)
651 m_shouldUseFontSmoothing = useFontSmoothing;
652 sendToAllProcesses(Messages::WebProcess::SetShouldUseFontSmoothing(useFontSmoothing));
655 void WebContext::registerURLSchemeAsEmptyDocument(const String& urlScheme)
657 m_schemesToRegisterAsEmptyDocument.add(urlScheme);
658 sendToAllProcesses(Messages::WebProcess::RegisterURLSchemeAsEmptyDocument(urlScheme));
661 void WebContext::registerURLSchemeAsSecure(const String& urlScheme)
663 m_schemesToRegisterAsSecure.add(urlScheme);
664 sendToAllProcesses(Messages::WebProcess::RegisterURLSchemeAsSecure(urlScheme));
667 void WebContext::setDomainRelaxationForbiddenForURLScheme(const String& urlScheme)
669 m_schemesToSetDomainRelaxationForbiddenFor.add(urlScheme);
670 sendToAllProcesses(Messages::WebProcess::SetDomainRelaxationForbiddenForURLScheme(urlScheme));
673 void WebContext::setCacheModel(CacheModel cacheModel)
675 m_cacheModel = cacheModel;
676 sendToAllProcesses(Messages::WebProcess::SetCacheModel(static_cast<uint32_t>(m_cacheModel)));
679 #if ENABLE(TIZEN_CACHE_CONTROL)
680 void WebContext::setCacheDisabled(bool cacheDisabled)
682 m_cacheDisabled = cacheDisabled;
683 sendToAllProcesses(Messages::WebProcess::SetCacheDisabled(m_cacheDisabled));
687 void WebContext::setDefaultRequestTimeoutInterval(double timeoutInterval)
689 sendToAllProcesses(Messages::WebProcess::SetDefaultRequestTimeoutInterval(timeoutInterval));
692 void WebContext::addVisitedLink(const String& visitedURL)
694 if (visitedURL.isEmpty())
697 LinkHash linkHash = visitedLinkHash(visitedURL.characters(), visitedURL.length());
698 addVisitedLinkHash(linkHash);
701 void WebContext::addVisitedLinkHash(LinkHash linkHash)
703 m_visitedLinkProvider.addVisitedLink(linkHash);
706 void WebContext::sendDidGetPlugins(uint64_t requestID, PassOwnPtr<Vector<PluginInfo> > pluginInfos)
708 ASSERT(isMainThread());
710 OwnPtr<Vector<PluginInfo> > plugins(pluginInfos);
713 // Add built-in PDF last, so that it's not used when a real plug-in is installed.
714 // NOTE: This has to be done on the main thread as it calls localizedString().
715 if (!omitPDFSupport())
716 plugins->append(BuiltInPDFView::pluginInfo());
719 process()->send(Messages::WebProcess::DidGetPlugins(requestID, *plugins), 0);
722 void WebContext::handleGetPlugins(uint64_t requestID, bool refresh)
725 m_pluginInfoStore.refresh();
727 OwnPtr<Vector<PluginInfo> > pluginInfos = adoptPtr(new Vector<PluginInfo>);
729 Vector<PluginModuleInfo> plugins = m_pluginInfoStore.plugins();
730 for (size_t i = 0; i < plugins.size(); ++i)
731 pluginInfos->append(plugins[i].info);
733 // NOTE: We have to pass the PluginInfo vector to the secondary thread via a pointer as otherwise
734 // we'd end up with a deref() race on all the WTF::Strings it contains.
735 RunLoop::main()->dispatch(bind(&WebContext::sendDidGetPlugins, this, requestID, pluginInfos.release()));
738 void WebContext::getPlugins(CoreIPC::Connection*, uint64_t requestID, bool refresh)
740 m_pluginWorkQueue.dispatch(bind(&WebContext::handleGetPlugins, this, requestID, refresh));
743 void WebContext::getPluginPath(const String& mimeType, const String& urlString, String& pluginPath, bool& blocked)
745 MESSAGE_CHECK_URL(urlString);
747 String newMimeType = mimeType.lower();
750 PluginModuleInfo plugin = pluginInfoStore().findPlugin(newMimeType, KURL(KURL(), urlString));
754 if (pluginInfoStore().shouldBlockPlugin(plugin)) {
759 pluginPath = plugin.path;
762 #if !ENABLE(PLUGIN_PROCESS)
763 void WebContext::didGetSitesWithPluginData(const Vector<String>& sites, uint64_t callbackID)
765 m_pluginSiteDataManager->didGetSitesWithData(sites, callbackID);
768 void WebContext::didClearPluginSiteData(uint64_t callbackID)
770 m_pluginSiteDataManager->didClearSiteData(callbackID);
774 DownloadProxy* WebContext::createDownloadProxy()
776 RefPtr<DownloadProxy> downloadProxy = DownloadProxy::create(this);
777 m_downloads.set(downloadProxy->downloadID(), downloadProxy);
778 return downloadProxy.get();
781 void WebContext::downloadFinished(DownloadProxy* downloadProxy)
783 ASSERT(m_downloads.contains(downloadProxy->downloadID()));
785 downloadProxy->invalidate();
786 m_downloads.remove(downloadProxy->downloadID());
789 // FIXME: This is not the ideal place for this function.
790 HashSet<String, CaseFoldingHash> WebContext::pdfAndPostScriptMIMETypes()
792 HashSet<String, CaseFoldingHash> mimeTypes;
794 mimeTypes.add("application/pdf");
795 mimeTypes.add("application/postscript");
796 mimeTypes.add("text/pdf");
801 void WebContext::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments)
803 if (messageID.is<CoreIPC::MessageClassWebContext>()) {
804 didReceiveWebContextMessage(connection, messageID, arguments);
808 if (messageID.is<CoreIPC::MessageClassDownloadProxy>()) {
809 if (DownloadProxy* downloadProxy = m_downloads.get(arguments->destinationID()).get())
810 downloadProxy->didReceiveDownloadProxyMessage(connection, messageID, arguments);
815 if (messageID.is<CoreIPC::MessageClassWebApplicationCacheManagerProxy>()) {
816 m_applicationCacheManagerProxy->didReceiveMessage(connection, messageID, arguments);
820 #if ENABLE(BATTERY_STATUS)
821 if (messageID.is<CoreIPC::MessageClassWebBatteryManagerProxy>()) {
822 m_batteryManagerProxy->didReceiveMessage(connection, messageID, arguments);
827 if (messageID.is<CoreIPC::MessageClassWebCookieManagerProxy>()) {
828 m_cookieManagerProxy->didReceiveMessage(connection, messageID, arguments);
832 #if ENABLE(SQL_DATABASE)
833 if (messageID.is<CoreIPC::MessageClassWebDatabaseManagerProxy>()) {
834 m_databaseManagerProxy->didReceiveWebDatabaseManagerProxyMessage(connection, messageID, arguments);
839 if (messageID.is<CoreIPC::MessageClassWebGeolocationManagerProxy>()) {
840 m_geolocationManagerProxy->didReceiveMessage(connection, messageID, arguments);
844 if (messageID.is<CoreIPC::MessageClassWebIconDatabase>()) {
845 m_iconDatabase->didReceiveMessage(connection, messageID, arguments);
849 if (messageID.is<CoreIPC::MessageClassWebKeyValueStorageManagerProxy>()) {
850 m_keyValueStorageManagerProxy->didReceiveMessage(connection, messageID, arguments);
854 #if ENABLE(TIZEN_FILE_SYSTEM)
855 if (messageID.is<CoreIPC::MessageClassWebLocalFileSystemManagerProxy>()) {
856 m_localFileSystemManagerProxy->didReceiveMessage(connection, messageID, arguments);
861 if (messageID.is<CoreIPC::MessageClassWebMediaCacheManagerProxy>()) {
862 m_mediaCacheManagerProxy->didReceiveMessage(connection, messageID, arguments);
866 #if ENABLE(NETWORK_INFO)
867 if (messageID.is<CoreIPC::MessageClassWebNetworkInfoManagerProxy>()) {
868 m_networkInfoManagerProxy->didReceiveMessage(connection, messageID, arguments);
873 if (messageID.is<CoreIPC::MessageClassWebNotificationManagerProxy>()) {
874 m_notificationManagerProxy->didReceiveMessage(connection, messageID, arguments);
878 if (messageID.is<CoreIPC::MessageClassWebResourceCacheManagerProxy>()) {
879 m_resourceCacheManagerProxy->didReceiveWebResourceCacheManagerProxyMessage(connection, messageID, arguments);
884 if (messageID.is<CoreIPC::MessageClassWebSoupRequestManagerProxy>()) {
885 m_soupRequestManagerProxy->didReceiveMessage(connection, messageID, arguments);
890 #if ENABLE(VIBRATION)
891 if (messageID.is<CoreIPC::MessageClassWebVibrationProxy>()) {
892 m_vibrationProxy->didReceiveMessage(connection, messageID, arguments);
897 switch (messageID.get<WebContextLegacyMessage::Kind>()) {
898 case WebContextLegacyMessage::PostMessage: {
900 RefPtr<APIObject> messageBody;
901 WebContextUserMessageDecoder messageDecoder(messageBody, this);
902 if (!arguments->decode(CoreIPC::Out(messageName, messageDecoder)))
905 didReceiveMessageFromInjectedBundle(messageName, messageBody.get());
908 case WebContextLegacyMessage::PostSynchronousMessage:
909 ASSERT_NOT_REACHED();
912 ASSERT_NOT_REACHED();
915 void WebContext::didReceiveSyncMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments, OwnPtr<CoreIPC::ArgumentEncoder>& reply)
917 if (messageID.is<CoreIPC::MessageClassWebContext>()) {
918 didReceiveSyncWebContextMessage(connection, messageID, arguments, reply);
922 if (messageID.is<CoreIPC::MessageClassDownloadProxy>()) {
923 if (DownloadProxy* downloadProxy = m_downloads.get(arguments->destinationID()).get())
924 downloadProxy->didReceiveSyncDownloadProxyMessage(connection, messageID, arguments, reply);
928 if (messageID.is<CoreIPC::MessageClassWebIconDatabase>()) {
929 m_iconDatabase->didReceiveSyncMessage(connection, messageID, arguments, reply);
933 #if ENABLE(NETWORK_INFO)
934 if (messageID.is<CoreIPC::MessageClassWebNetworkInfoManagerProxy>()) {
935 m_networkInfoManagerProxy->didReceiveSyncMessage(connection, messageID, arguments, reply);
940 switch (messageID.get<WebContextLegacyMessage::Kind>()) {
941 case WebContextLegacyMessage::PostSynchronousMessage: {
942 // FIXME: We should probably encode something in the case that the arguments do not decode correctly.
945 RefPtr<APIObject> messageBody;
946 WebContextUserMessageDecoder messageDecoder(messageBody, this);
947 if (!arguments->decode(CoreIPC::Out(messageName, messageDecoder)))
950 RefPtr<APIObject> returnData;
951 didReceiveSynchronousMessageFromInjectedBundle(messageName, messageBody.get(), returnData);
952 reply->encode(CoreIPC::In(WebContextUserMessageEncoder(returnData.get())));
955 case WebContextLegacyMessage::PostMessage:
956 ASSERT_NOT_REACHED();
960 void WebContext::setEnhancedAccessibility(bool flag)
962 sendToAllProcesses(Messages::WebProcess::SetEnhancedAccessibility(flag));
965 void WebContext::startMemorySampler(const double interval)
967 // For new WebProcesses we will also want to start the Memory Sampler
968 m_memorySamplerEnabled = true;
969 m_memorySamplerInterval = interval;
972 #if ENABLE(MEMORY_SAMPLER)
973 WebMemorySampler::shared()->start(interval);
977 SandboxExtension::Handle sampleLogSandboxHandle;
978 double now = WTF::currentTime();
979 String sampleLogFilePath = String::format("WebProcess%llu", static_cast<unsigned long long>(now));
980 sampleLogFilePath = SandboxExtension::createHandleForTemporaryFile(sampleLogFilePath, SandboxExtension::WriteOnly, sampleLogSandboxHandle);
982 sendToAllProcesses(Messages::WebProcess::StartMemorySampler(sampleLogSandboxHandle, sampleLogFilePath, interval));
985 void WebContext::stopMemorySampler()
988 m_memorySamplerEnabled = false;
991 #if ENABLE(MEMORY_SAMPLER)
992 WebMemorySampler::shared()->stop();
995 sendToAllProcesses(Messages::WebProcess::StopMemorySampler());
998 String WebContext::databaseDirectory() const
1000 if (!m_overrideDatabaseDirectory.isEmpty())
1001 return m_overrideDatabaseDirectory;
1003 return platformDefaultDatabaseDirectory();
1006 void WebContext::setIconDatabasePath(const String& path)
1008 m_overrideIconDatabasePath = path;
1009 m_iconDatabase->setDatabasePath(path);
1012 String WebContext::iconDatabasePath() const
1014 if (!m_overrideIconDatabasePath.isEmpty())
1015 return m_overrideIconDatabasePath;
1017 return platformDefaultIconDatabasePath();
1020 #if ENABLE(TIZEN_FILE_SYSTEM)
1021 String WebContext::localFileSystemDirectory() const
1023 if (!m_overrideLocalFileSystemDirectory.isEmpty())
1024 return m_overrideLocalFileSystemDirectory;
1026 return platformDefaultLocalFileSystemDirectory();
1030 String WebContext::localStorageDirectory() const
1032 if (!m_overrideLocalStorageDirectory.isEmpty())
1033 return m_overrideLocalStorageDirectory;
1035 return platformDefaultLocalStorageDirectory();
1038 #if ENABLE(TIZEN_INDEXED_DATABASE)
1039 String WebContext::indexedDatabaseDirectory() const
1041 if (!m_overrideIndexedDatabaseDirectory.isEmpty())
1042 return m_overrideIndexedDatabaseDirectory;
1044 return platformDefaultIndexedDatabaseDirectory();
1048 void WebContext::setHTTPPipeliningEnabled(bool enabled)
1051 ResourceRequest::setHTTPPipeliningEnabled(enabled);
1055 bool WebContext::httpPipeliningEnabled() const
1058 return ResourceRequest::httpPipeliningEnabled();
1064 void WebContext::getWebCoreStatistics(PassRefPtr<DictionaryCallback> callback)
1067 callback->invalidate();
1071 uint64_t callbackID = callback->callbackID();
1072 m_dictionaryCallbacks.set(callbackID, callback.get());
1073 process()->send(Messages::WebProcess::GetWebCoreStatistics(callbackID), 0);
1076 static PassRefPtr<MutableDictionary> createDictionaryFromHashMap(const HashMap<String, uint64_t>& map)
1078 RefPtr<MutableDictionary> result = MutableDictionary::create();
1079 HashMap<String, uint64_t>::const_iterator end = map.end();
1080 for (HashMap<String, uint64_t>::const_iterator it = map.begin(); it != end; ++it)
1081 result->set(it->first, RefPtr<WebUInt64>(WebUInt64::create(it->second)).get());
1086 void WebContext::didGetWebCoreStatistics(const StatisticsData& statisticsData, uint64_t callbackID)
1088 RefPtr<DictionaryCallback> callback = m_dictionaryCallbacks.take(callbackID);
1090 // FIXME: Log error or assert.
1094 RefPtr<MutableDictionary> statistics = createDictionaryFromHashMap(statisticsData.statisticsNumbers);
1095 statistics->set("JavaScriptProtectedObjectTypeCounts", createDictionaryFromHashMap(statisticsData.javaScriptProtectedObjectTypeCounts).get());
1096 statistics->set("JavaScriptObjectTypeCounts", createDictionaryFromHashMap(statisticsData.javaScriptObjectTypeCounts).get());
1098 size_t cacheStatisticsCount = statisticsData.webCoreCacheStatistics.size();
1099 Vector<RefPtr<APIObject> > cacheStatisticsVector(cacheStatisticsCount);
1100 for (size_t i = 0; i < cacheStatisticsCount; ++i)
1101 cacheStatisticsVector[i] = createDictionaryFromHashMap(statisticsData.webCoreCacheStatistics[i]);
1102 statistics->set("WebCoreCacheStatistics", ImmutableArray::adopt(cacheStatisticsVector).get());
1104 callback->performCallbackWithReturnValue(statistics.get());
1107 void WebContext::garbageCollectJavaScriptObjects()
1109 sendToAllProcesses(Messages::WebProcess::GarbageCollectJavaScriptObjects());
1112 void WebContext::setJavaScriptGarbageCollectorTimerEnabled(bool flag)
1114 sendToAllProcesses(Messages::WebProcess::SetJavaScriptGarbageCollectorTimerEnabled(flag));
1117 void WebContext::didReceiveMessageOnConnectionWorkQueue(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments, bool& didHandleMessage)
1119 if (messageID.is<CoreIPC::MessageClassWebContext>()) {
1120 didReceiveWebContextMessageOnConnectionWorkQueue(connection, messageID, arguments, didHandleMessage);
1125 } // namespace WebKit