diff options
Diffstat (limited to 'Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp')
-rw-r--r-- | Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp | 450 |
1 files changed, 113 insertions, 337 deletions
diff --git a/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp b/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp index a7d32c36b..c03970ad5 100644 --- a/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp +++ b/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2011, 2012 Apple Inc. All rights reserved. + * Copyright (C) 2010, 2011, 2012, 2015, 2016 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,25 +26,29 @@ #include "config.h" #include "WebPlatformStrategies.h" +#include "BlobRegistryProxy.h" #include "BlockingResponseMap.h" #include "DataReference.h" +#include "HangDetectionDisabler.h" +#include "NetworkConnectionToWebProcessMessages.h" +#include "NetworkProcessConnection.h" #include "NetworkResourceLoadParameters.h" #include "PluginInfoStore.h" #include "SessionTracker.h" -#include "StorageNamespaceImpl.h" -#include "WebContextMessages.h" #include "WebCookieManager.h" #include "WebCoreArgumentCoders.h" #include "WebErrors.h" #include "WebFrame.h" #include "WebFrameLoaderClient.h" -#include "WebFrameNetworkingContext.h" -#include "WebIDBFactoryBackend.h" +#include "WebLoaderStrategy.h" #include "WebPage.h" +#include "WebPasteboardOverrides.h" +#include "WebPasteboardProxyMessages.h" #include "WebProcess.h" #include "WebProcessProxyMessages.h" #include <WebCore/Color.h> -#include <WebCore/IDBFactoryBackendInterface.h> +#include <WebCore/Document.h> +#include <WebCore/DocumentLoader.h> #include <WebCore/LoaderStrategy.h> #include <WebCore/MainFrame.h> #include <WebCore/NetworkStorageSession.h> @@ -53,33 +57,26 @@ #include <WebCore/PageGroup.h> #include <WebCore/PlatformCookieJar.h> #include <WebCore/PlatformPasteboard.h> +#include <WebCore/ProgressTracker.h> #include <WebCore/ResourceError.h> +#include <WebCore/SessionID.h> #include <WebCore/StorageNamespace.h> #include <WebCore/SubframeLoader.h> #include <WebCore/URL.h> #include <wtf/Atomics.h> -#if ENABLE(NETWORK_PROCESS) -#include "BlobRegistryProxy.h" -#include "NetworkConnectionToWebProcessMessages.h" -#include "NetworkProcessConnection.h" -#include "WebResourceLoadScheduler.h" +#if PLATFORM(MAC) +#include "StringUtilities.h" #endif -// FIXME: Remove this #ifdef once we don't need the ability to turn the feature off. -#define ENABLE_UI_PROCESS_STORAGE 1 +#if PLATFORM(GTK) +#include "WebSelectionData.h" +#endif using namespace WebCore; namespace WebKit { -#if ENABLE(NETWORK_PROCESS) -static uint64_t legacySessionID(const NetworkStorageSession &session) -{ - return session.isPrivateBrowsingSession() ? SessionTracker::legacyPrivateSessionID : SessionTracker::defaultSessionID; -} -#endif - void WebPlatformStrategies::initialize() { static NeverDestroyed<WebPlatformStrategies> platformStrategies; @@ -87,10 +84,6 @@ void WebPlatformStrategies::initialize() } WebPlatformStrategies::WebPlatformStrategies() -#if ENABLE(NETSCAPE_PLUGIN_API) - : m_pluginCacheIsPopulated(false) - , m_shouldRefreshPlugins(false) -#endif // ENABLE(NETSCAPE_PLUGIN_API) { } @@ -99,14 +92,9 @@ CookiesStrategy* WebPlatformStrategies::createCookiesStrategy() return this; } -DatabaseStrategy* WebPlatformStrategies::createDatabaseStrategy() -{ - return this; -} - LoaderStrategy* WebPlatformStrategies::createLoaderStrategy() { - return this; + return &WebProcess::singleton().webLoaderStrategy(); } PasteboardStrategy* WebPlatformStrategies::createPasteboardStrategy() @@ -114,467 +102,255 @@ PasteboardStrategy* WebPlatformStrategies::createPasteboardStrategy() return this; } -PluginStrategy* WebPlatformStrategies::createPluginStrategy() -{ - return this; -} - -SharedWorkerStrategy* WebPlatformStrategies::createSharedWorkerStrategy() -{ - return this; -} - -StorageStrategy* WebPlatformStrategies::createStorageStrategy() -{ - return this; -} - -VisitedLinkStrategy* WebPlatformStrategies::createVisitedLinkStrategy() +BlobRegistry* WebPlatformStrategies::createBlobRegistry() { - return this; + return new BlobRegistryProxy; } // CookiesStrategy String WebPlatformStrategies::cookiesForDOM(const NetworkStorageSession& session, const URL& firstParty, const URL& url) { -#if ENABLE(NETWORK_PROCESS) - if (WebProcess::shared().usesNetworkProcess()) { - String result; - if (!WebProcess::shared().networkConnection()->connection()->sendSync(Messages::NetworkConnectionToWebProcess::CookiesForDOM(legacySessionID(session), firstParty, url), Messages::NetworkConnectionToWebProcess::CookiesForDOM::Reply(result), 0)) - return String(); - return result; - } -#endif - - return WebCore::cookiesForDOM(session, firstParty, url); + String result; + if (!WebProcess::singleton().networkConnection().connection().sendSync(Messages::NetworkConnectionToWebProcess::CookiesForDOM(session.sessionID(), firstParty, url), Messages::NetworkConnectionToWebProcess::CookiesForDOM::Reply(result), 0)) + return String(); + return result; } void WebPlatformStrategies::setCookiesFromDOM(const NetworkStorageSession& session, const URL& firstParty, const URL& url, const String& cookieString) { -#if ENABLE(NETWORK_PROCESS) - if (WebProcess::shared().usesNetworkProcess()) { - WebProcess::shared().networkConnection()->connection()->send(Messages::NetworkConnectionToWebProcess::SetCookiesFromDOM(legacySessionID(session), firstParty, url, cookieString), 0); - return; - } -#endif - - WebCore::setCookiesFromDOM(session, firstParty, url, cookieString); + WebProcess::singleton().networkConnection().connection().send(Messages::NetworkConnectionToWebProcess::SetCookiesFromDOM(session.sessionID(), firstParty, url, cookieString), 0); } bool WebPlatformStrategies::cookiesEnabled(const NetworkStorageSession& session, const URL& firstParty, const URL& url) { -#if ENABLE(NETWORK_PROCESS) - if (WebProcess::shared().usesNetworkProcess()) { - bool result; - if (!WebProcess::shared().networkConnection()->connection()->sendSync(Messages::NetworkConnectionToWebProcess::CookiesEnabled(legacySessionID(session), firstParty, url), Messages::NetworkConnectionToWebProcess::CookiesEnabled::Reply(result), 0)) - return false; - return result; - } -#endif - - return WebCore::cookiesEnabled(session, firstParty, url); + bool result; + if (!WebProcess::singleton().networkConnection().connection().sendSync(Messages::NetworkConnectionToWebProcess::CookiesEnabled(session.sessionID(), firstParty, url), Messages::NetworkConnectionToWebProcess::CookiesEnabled::Reply(result), 0)) + return false; + return result; } String WebPlatformStrategies::cookieRequestHeaderFieldValue(const NetworkStorageSession& session, const URL& firstParty, const URL& url) { -#if ENABLE(NETWORK_PROCESS) - if (WebProcess::shared().usesNetworkProcess()) { - String result; - if (!WebProcess::shared().networkConnection()->connection()->sendSync(Messages::NetworkConnectionToWebProcess::CookieRequestHeaderFieldValue(legacySessionID(session), firstParty, url), Messages::NetworkConnectionToWebProcess::CookieRequestHeaderFieldValue::Reply(result), 0)) - return String(); - return result; - } -#endif - - return WebCore::cookieRequestHeaderFieldValue(session, firstParty, url); -} - -bool WebPlatformStrategies::getRawCookies(const NetworkStorageSession& session, const URL& firstParty, const URL& url, Vector<Cookie>& rawCookies) -{ -#if ENABLE(NETWORK_PROCESS) - if (WebProcess::shared().usesNetworkProcess()) { - if (!WebProcess::shared().networkConnection()->connection()->sendSync(Messages::NetworkConnectionToWebProcess::GetRawCookies(legacySessionID(session), firstParty, url), Messages::NetworkConnectionToWebProcess::GetRawCookies::Reply(rawCookies), 0)) - return false; - return true; - } -#endif - - return WebCore::getRawCookies(session, firstParty, url, rawCookies); -} - -void WebPlatformStrategies::deleteCookie(const NetworkStorageSession& session, const URL& url, const String& cookieName) -{ -#if ENABLE(NETWORK_PROCESS) - if (WebProcess::shared().usesNetworkProcess()) { - WebProcess::shared().networkConnection()->connection()->send(Messages::NetworkConnectionToWebProcess::DeleteCookie(legacySessionID(session), url, cookieName), 0); - return; - } -#endif - - WebCore::deleteCookie(session, url, cookieName); -} - -// DatabaseStrategy - -#if ENABLE(SQL_DATABASE) -AbstractDatabaseServer* WebPlatformStrategies::getDatabaseServer() -{ - return DatabaseStrategy::getDatabaseServer(); + return cookieRequestHeaderFieldValue(session.sessionID(), firstParty, url); } -#endif // ENABLE(SQL_DATABASE) -#if ENABLE(INDEXED_DATABASE) -PassRefPtr<IDBFactoryBackendInterface> WebPlatformStrategies::createIDBFactoryBackend(const String& databaseDirectoryIdentifier) +String WebPlatformStrategies::cookieRequestHeaderFieldValue(SessionID sessionID, const URL& firstParty, const URL& url) { -#if !ENABLE(DATABASE_PROCESS) - return DatabaseStrategy::createIDBFactoryBackend(databaseDirectoryIdentifier); -#endif - - return WebIDBFactoryBackend::create(databaseDirectoryIdentifier); + String result; + if (!WebProcess::singleton().networkConnection().connection().sendSync(Messages::NetworkConnectionToWebProcess::CookieRequestHeaderFieldValue(sessionID, firstParty, url), Messages::NetworkConnectionToWebProcess::CookieRequestHeaderFieldValue::Reply(result), 0)) + return String(); + return result; } -#endif // ENABLE(INDEXED_DATABASE) -// LoaderStrategy - -#if ENABLE(NETWORK_PROCESS) -ResourceLoadScheduler* WebPlatformStrategies::resourceLoadScheduler() -{ - static ResourceLoadScheduler* scheduler; - if (!scheduler) { - if (WebProcess::shared().usesNetworkProcess()) - scheduler = &WebProcess::shared().webResourceLoadScheduler(); - else - scheduler = WebCore::resourceLoadScheduler(); - } - - return scheduler; -} - -void WebPlatformStrategies::loadResourceSynchronously(NetworkingContext* context, unsigned long resourceLoadIdentifier, const ResourceRequest& request, StoredCredentials storedCredentials, ClientCredentialPolicy clientCredentialPolicy, ResourceError& error, ResourceResponse& response, Vector<char>& data) -{ - if (!WebProcess::shared().usesNetworkProcess()) { - LoaderStrategy::loadResourceSynchronously(context, resourceLoadIdentifier, request, storedCredentials, clientCredentialPolicy, error, response, data); - return; - } - - WebFrameNetworkingContext* webContext = static_cast<WebFrameNetworkingContext*>(context); - // FIXME: Some entities in WebCore use WebCore's "EmptyFrameLoaderClient" instead of having a proper WebFrameLoaderClient. - // EmptyFrameLoaderClient shouldn't exist and everything should be using a WebFrameLoaderClient, - // but in the meantime we have to make sure not to mis-cast. - WebFrameLoaderClient* webFrameLoaderClient = webContext->webFrameLoaderClient(); - WebFrame* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0; - WebPage* webPage = webFrame ? webFrame->page() : 0; - - NetworkResourceLoadParameters loadParameters; - loadParameters.identifier = resourceLoadIdentifier; - loadParameters.webPageID = webPage ? webPage->pageID() : 0; - loadParameters.webFrameID = webFrame ? webFrame->frameID() : 0; - loadParameters.sessionID = webPage ? webPage->sessionID() : SessionTracker::defaultSessionID; - loadParameters.request = request; - loadParameters.priority = ResourceLoadPriorityHighest; - loadParameters.contentSniffingPolicy = SniffContent; - loadParameters.allowStoredCredentials = storedCredentials; - loadParameters.clientCredentialPolicy = clientCredentialPolicy; - loadParameters.shouldClearReferrerOnHTTPSToHTTPRedirect = context->shouldClearReferrerOnHTTPSToHTTPRedirect(); - - data.resize(0); - - if (!WebProcess::shared().networkConnection()->connection()->sendSync(Messages::NetworkConnectionToWebProcess::PerformSynchronousLoad(loadParameters), Messages::NetworkConnectionToWebProcess::PerformSynchronousLoad::Reply(error, response, data), 0)) { - response = ResourceResponse(); - error = internalError(request.url()); - } -} - -#if ENABLE(BLOB) -BlobRegistry* WebPlatformStrategies::createBlobRegistry() +bool WebPlatformStrategies::getRawCookies(const NetworkStorageSession& session, const URL& firstParty, const URL& url, Vector<Cookie>& rawCookies) { - if (!WebProcess::shared().usesNetworkProcess()) - return LoaderStrategy::createBlobRegistry(); - return new BlobRegistryProxy; + if (!WebProcess::singleton().networkConnection().connection().sendSync(Messages::NetworkConnectionToWebProcess::GetRawCookies(session.sessionID(), firstParty, url), Messages::NetworkConnectionToWebProcess::GetRawCookies::Reply(rawCookies), 0)) + return false; + return true; } -#endif -#endif -// PluginStrategy - -void WebPlatformStrategies::refreshPlugins() +void WebPlatformStrategies::deleteCookie(const NetworkStorageSession& session, const URL& url, const String& cookieName) { -#if ENABLE(NETSCAPE_PLUGIN_API) - m_cachedPlugins.clear(); - m_pluginCacheIsPopulated = false; - m_shouldRefreshPlugins = true; -#endif // ENABLE(NETSCAPE_PLUGIN_API) + WebProcess::singleton().networkConnection().connection().send(Messages::NetworkConnectionToWebProcess::DeleteCookie(session.sessionID(), url, cookieName), 0); } -void WebPlatformStrategies::getPluginInfo(const WebCore::Page* page, Vector<WebCore::PluginInfo>& plugins) +void WebPlatformStrategies::addCookie(const NetworkStorageSession& session, const URL& url, const Cookie& cookie) { -#if ENABLE(NETSCAPE_PLUGIN_API) - populatePluginCache(); - - if (page->mainFrame().loader().subframeLoader().allowPlugins(NotAboutToInstantiatePlugin)) { - plugins = m_cachedPlugins; - return; - } - - plugins = m_cachedApplicationPlugins; -#else - UNUSED_PARAM(page); - UNUSED_PARAM(plugins); -#endif // ENABLE(NETSCAPE_PLUGIN_API) + WebProcess::singleton().networkConnection().connection().send(Messages::NetworkConnectionToWebProcess::AddCookie(session.sessionID(), url, cookie), 0); } -// SharedWorkerStrategy - -bool WebPlatformStrategies::isAvailable() const -{ - // Shared workers do not work across multiple processes, and using network process is tied to multiple secondary process model. - return !WebProcess::shared().usesNetworkProcess(); -} +#if PLATFORM(COCOA) +// PasteboardStrategy -#if ENABLE(NETSCAPE_PLUGIN_API) -void WebPlatformStrategies::populatePluginCache() +void WebPlatformStrategies::getTypes(Vector<String>& types, const String& pasteboardName) { - if (m_pluginCacheIsPopulated) - return; - - ASSERT(m_cachedPlugins.isEmpty()); - - // FIXME: Should we do something in case of error here? - if (!WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebProcessProxy::GetPlugins(m_shouldRefreshPlugins), Messages::WebProcessProxy::GetPlugins::Reply(m_cachedPlugins, m_cachedApplicationPlugins), 0)) + // First check the overrides. + // The purpose of the overrides is to avoid messaging back to the UI process. + // Therefore, if there are any overridden types, we return just those. + types = WebPasteboardOverrides::sharedPasteboardOverrides().overriddenTypes(pasteboardName); + if (!types.isEmpty()) return; - m_shouldRefreshPlugins = false; - m_pluginCacheIsPopulated = true; -} -#endif // ENABLE(NETSCAPE_PLUGIN_API) - -// StorageStrategy - -PassRefPtr<StorageNamespace> WebPlatformStrategies::localStorageNamespace(PageGroup* pageGroup) -{ -#if ENABLE(UI_PROCESS_STORAGE) - return StorageNamespaceImpl::createLocalStorageNamespace(pageGroup); -#else - return StorageStrategy::localStorageNamespace(pageGroup); -#endif -} - -PassRefPtr<StorageNamespace> WebPlatformStrategies::transientLocalStorageNamespace(PageGroup* pageGroup, SecurityOrigin*securityOrigin) -{ -#if ENABLE(UI_PROCESS_STORAGE) - UNUSED_PARAM(securityOrigin); - // FIXME: This could be more clever and made to work across processes. - return StorageStrategy::sessionStorageNamespace(*pageGroup->pages().begin()); -#else - return StorageStrategy::transientLocalStorageNamespace(pageGroup, securityOrigin); -#endif -} - -PassRefPtr<StorageNamespace> WebPlatformStrategies::sessionStorageNamespace(Page* page) -{ -#if ENABLE(UI_PROCESS_STORAGE) - return StorageNamespaceImpl::createSessionStorageNamespace(WebPage::fromCorePage(page)); -#else - return StorageStrategy::sessionStorageNamespace(page); -#endif -} - -// VisitedLinkStrategy - -bool WebPlatformStrategies::isLinkVisited(Page*, LinkHash linkHash, const URL&, const AtomicString&) -{ - return WebProcess::shared().isLinkVisited(linkHash); -} - -void WebPlatformStrategies::addVisitedLink(Page*, LinkHash linkHash) -{ - WebProcess::shared().addVisitedLink(linkHash); + WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::GetPasteboardTypes(pasteboardName), Messages::WebPasteboardProxy::GetPasteboardTypes::Reply(types), 0); } -#if PLATFORM(MAC) -// PasteboardStrategy - -void WebPlatformStrategies::getTypes(Vector<String>& types, const String& pasteboardName) +RefPtr<WebCore::SharedBuffer> WebPlatformStrategies::bufferForType(const String& pasteboardType, const String& pasteboardName) { - WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebContext::GetPasteboardTypes(pasteboardName), - Messages::WebContext::GetPasteboardTypes::Reply(types), 0); -} + // First check the overrides. + Vector<char> overrideBuffer; + if (WebPasteboardOverrides::sharedPasteboardOverrides().getDataForOverride(pasteboardName, pasteboardType, overrideBuffer)) + return SharedBuffer::adoptVector(overrideBuffer); -PassRefPtr<WebCore::SharedBuffer> WebPlatformStrategies::bufferForType(const String& pasteboardType, const String& pasteboardName) -{ + // Fallback to messaging the UI process for native pasteboard content. SharedMemory::Handle handle; uint64_t size = 0; - WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebContext::GetPasteboardBufferForType(pasteboardName, pasteboardType), - Messages::WebContext::GetPasteboardBufferForType::Reply(handle, size), 0); + WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::GetPasteboardBufferForType(pasteboardName, pasteboardType), Messages::WebPasteboardProxy::GetPasteboardBufferForType::Reply(handle, size), 0); if (handle.isNull()) - return 0; - RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::create(handle, SharedMemory::ReadOnly); + return nullptr; + RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::map(handle, SharedMemory::Protection::ReadOnly); return SharedBuffer::create(static_cast<unsigned char *>(sharedMemoryBuffer->data()), size); } void WebPlatformStrategies::getPathnamesForType(Vector<String>& pathnames, const String& pasteboardType, const String& pasteboardName) { - WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebContext::GetPasteboardPathnamesForType(pasteboardName, pasteboardType), - Messages::WebContext::GetPasteboardPathnamesForType::Reply(pathnames), 0); + WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::GetPasteboardPathnamesForType(pasteboardName, pasteboardType), Messages::WebPasteboardProxy::GetPasteboardPathnamesForType::Reply(pathnames), 0); } String WebPlatformStrategies::stringForType(const String& pasteboardType, const String& pasteboardName) { String value; - WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebContext::GetPasteboardStringForType(pasteboardName, pasteboardType), - Messages::WebContext::GetPasteboardStringForType::Reply(value), 0); + WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::GetPasteboardStringForType(pasteboardName, pasteboardType), Messages::WebPasteboardProxy::GetPasteboardStringForType::Reply(value), 0); return value; } long WebPlatformStrategies::copy(const String& fromPasteboard, const String& toPasteboard) { uint64_t newChangeCount; - WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebContext::PasteboardCopy(fromPasteboard, toPasteboard), - Messages::WebContext::PasteboardCopy::Reply(newChangeCount), 0); + WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::PasteboardCopy(fromPasteboard, toPasteboard), Messages::WebPasteboardProxy::PasteboardCopy::Reply(newChangeCount), 0); return newChangeCount; } long WebPlatformStrategies::changeCount(const WTF::String &pasteboardName) { uint64_t changeCount; - WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebContext::GetPasteboardChangeCount(pasteboardName), - Messages::WebContext::GetPasteboardChangeCount::Reply(changeCount), 0); + WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::GetPasteboardChangeCount(pasteboardName), Messages::WebPasteboardProxy::GetPasteboardChangeCount::Reply(changeCount), 0); return changeCount; } String WebPlatformStrategies::uniqueName() { String pasteboardName; - WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebContext::GetPasteboardUniqueName(), - Messages::WebContext::GetPasteboardUniqueName::Reply(pasteboardName), 0); + WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::GetPasteboardUniqueName(), Messages::WebPasteboardProxy::GetPasteboardUniqueName::Reply(pasteboardName), 0); return pasteboardName; } Color WebPlatformStrategies::color(const String& pasteboardName) { Color color; - WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebContext::GetPasteboardColor(pasteboardName), - Messages::WebContext::GetPasteboardColor::Reply(color), 0); + WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::GetPasteboardColor(pasteboardName), Messages::WebPasteboardProxy::GetPasteboardColor::Reply(color), 0); return color; } URL WebPlatformStrategies::url(const String& pasteboardName) { String urlString; - WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebContext::GetPasteboardURL(pasteboardName), - Messages::WebContext::GetPasteboardURL::Reply(urlString), 0); + WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::GetPasteboardURL(pasteboardName), Messages::WebPasteboardProxy::GetPasteboardURL::Reply(urlString), 0); return URL(ParsedURLString, urlString); } long WebPlatformStrategies::addTypes(const Vector<String>& pasteboardTypes, const String& pasteboardName) { uint64_t newChangeCount; - WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebContext::AddPasteboardTypes(pasteboardName, pasteboardTypes), - Messages::WebContext::AddPasteboardTypes::Reply(newChangeCount), 0); + WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::AddPasteboardTypes(pasteboardName, pasteboardTypes), Messages::WebPasteboardProxy::AddPasteboardTypes::Reply(newChangeCount), 0); return newChangeCount; } long WebPlatformStrategies::setTypes(const Vector<String>& pasteboardTypes, const String& pasteboardName) { uint64_t newChangeCount; - WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebContext::SetPasteboardTypes(pasteboardName, pasteboardTypes), - Messages::WebContext::SetPasteboardTypes::Reply(newChangeCount), 0); + WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::SetPasteboardTypes(pasteboardName, pasteboardTypes), Messages::WebPasteboardProxy::SetPasteboardTypes::Reply(newChangeCount), 0); return newChangeCount; } -long WebPlatformStrategies::setBufferForType(PassRefPtr<SharedBuffer> buffer, const String& pasteboardType, const String& pasteboardName) +long WebPlatformStrategies::setBufferForType(SharedBuffer* buffer, const String& pasteboardType, const String& pasteboardName) { SharedMemory::Handle handle; if (buffer) { - RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::create(buffer->size()); - memcpy(sharedMemoryBuffer->data(), buffer->data(), buffer->size()); - sharedMemoryBuffer->createHandle(handle, SharedMemory::ReadOnly); + RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::allocate(buffer->size()); + // FIXME: Null check prevents crashing, but it is not great that we will have empty pasteboard content for this type, + // because we've already set the types. + if (sharedMemoryBuffer) { + memcpy(sharedMemoryBuffer->data(), buffer->data(), buffer->size()); + sharedMemoryBuffer->createHandle(handle, SharedMemory::Protection::ReadOnly); + } } uint64_t newChangeCount; - WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebContext::SetPasteboardBufferForType(pasteboardName, pasteboardType, handle, buffer ? buffer->size() : 0), - Messages::WebContext::SetPasteboardBufferForType::Reply(newChangeCount), 0); + WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::SetPasteboardBufferForType(pasteboardName, pasteboardType, handle, buffer ? buffer->size() : 0), Messages::WebPasteboardProxy::SetPasteboardBufferForType::Reply(newChangeCount), 0); return newChangeCount; } long WebPlatformStrategies::setPathnamesForType(const Vector<String>& pathnames, const String& pasteboardType, const String& pasteboardName) { uint64_t newChangeCount; - WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebContext::SetPasteboardPathnamesForType(pasteboardName, pasteboardType, pathnames), - Messages::WebContext::SetPasteboardPathnamesForType::Reply(newChangeCount), 0); + WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::SetPasteboardPathnamesForType(pasteboardName, pasteboardType, pathnames), Messages::WebPasteboardProxy::SetPasteboardPathnamesForType::Reply(newChangeCount), 0); return newChangeCount; } long WebPlatformStrategies::setStringForType(const String& string, const String& pasteboardType, const String& pasteboardName) { uint64_t newChangeCount; - WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebContext::SetPasteboardStringForType(pasteboardName, pasteboardType, string), - Messages::WebContext::SetPasteboardStringForType::Reply(newChangeCount), 0); + WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::SetPasteboardStringForType(pasteboardName, pasteboardType, string), Messages::WebPasteboardProxy::SetPasteboardStringForType::Reply(newChangeCount), 0); return newChangeCount; } #if PLATFORM(IOS) -void WebPlatformStrategies::writeToPasteboard(const WebCore::PasteboardWebContent& content) +void WebPlatformStrategies::writeToPasteboard(const WebCore::PasteboardWebContent& content, const String& pasteboardName) { - WebProcess::shared().parentProcessConnection()->send(Messages::WebContext::WriteWebContentToPasteboard(content), 0); + WebProcess::singleton().parentProcessConnection()->send(Messages::WebPasteboardProxy::WriteWebContentToPasteboard(content, pasteboardName), 0); } -void WebPlatformStrategies::writeToPasteboard(const WebCore::PasteboardImage& image) +void WebPlatformStrategies::writeToPasteboard(const WebCore::PasteboardImage& image, const String& pasteboardName) { - WebProcess::shared().parentProcessConnection()->send(Messages::WebContext::WriteImageToPasteboard(image), 0); + WebProcess::singleton().parentProcessConnection()->send(Messages::WebPasteboardProxy::WriteImageToPasteboard(image, pasteboardName), 0); } -void WebPlatformStrategies::writeToPasteboard(const String& pasteboardType, const String& text) +void WebPlatformStrategies::writeToPasteboard(const String& pasteboardType, const String& text, const String& pasteboardName) { - WebProcess::shared().parentProcessConnection()->send(Messages::WebContext::WriteStringToPasteboard(pasteboardType, text), 0); + WebProcess::singleton().parentProcessConnection()->send(Messages::WebPasteboardProxy::WriteStringToPasteboard(pasteboardType, text, pasteboardName), 0); } -int WebPlatformStrategies::getPasteboardItemsCount() +int WebPlatformStrategies::getPasteboardItemsCount(const String& pasteboardName) { uint64_t itemsCount; - WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebContext::GetPasteboardItemsCount(), - Messages::WebContext::GetPasteboardItemsCount::Reply(itemsCount), 0); + WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::GetPasteboardItemsCount(pasteboardName), Messages::WebPasteboardProxy::GetPasteboardItemsCount::Reply(itemsCount), 0); return itemsCount; } -PassRefPtr<WebCore::SharedBuffer> WebPlatformStrategies::readBufferFromPasteboard(int index, const String& pasteboardType) +RefPtr<WebCore::SharedBuffer> WebPlatformStrategies::readBufferFromPasteboard(int index, const String& pasteboardType, const String& pasteboardName) { SharedMemory::Handle handle; uint64_t size = 0; - WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebContext::ReadBufferFromPasteboard(index, pasteboardType), - Messages::WebContext::ReadBufferFromPasteboard::Reply(handle, size), 0); + WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::ReadBufferFromPasteboard(index, pasteboardType, pasteboardName), Messages::WebPasteboardProxy::ReadBufferFromPasteboard::Reply(handle, size), 0); if (handle.isNull()) - return 0; - RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::create(handle, SharedMemory::ReadOnly); + return nullptr; + RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::map(handle, SharedMemory::Protection::ReadOnly); return SharedBuffer::create(static_cast<unsigned char *>(sharedMemoryBuffer->data()), size); } -WebCore::URL WebPlatformStrategies::readURLFromPasteboard(int index, const String& pasteboardType) +WebCore::URL WebPlatformStrategies::readURLFromPasteboard(int index, const String& pasteboardType, const String& pasteboardName) { String urlString; - WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebContext::ReadURLFromPasteboard(index, pasteboardType), - Messages::WebContext::ReadURLFromPasteboard::Reply(urlString), 0); + WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::ReadURLFromPasteboard(index, pasteboardType, pasteboardName), Messages::WebPasteboardProxy::ReadURLFromPasteboard::Reply(urlString), 0); return URL(ParsedURLString, urlString); } -String WebPlatformStrategies::readStringFromPasteboard(int index, const String& pasteboardType) +String WebPlatformStrategies::readStringFromPasteboard(int index, const String& pasteboardType, const String& pasteboardName) { String value; - WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebContext::ReadStringFromPasteboard(index, pasteboardType), - Messages::WebContext::ReadStringFromPasteboard::Reply(value), 0); + WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::ReadStringFromPasteboard(index, pasteboardType, pasteboardName), Messages::WebPasteboardProxy::ReadStringFromPasteboard::Reply(value), 0); return value; } +#endif // PLATFORM(IOS) + +#endif // PLATFORM(COCOA) -long WebPlatformStrategies::changeCount() +#if PLATFORM(GTK) +// PasteboardStrategy + +void WebPlatformStrategies::writeToClipboard(const String& pasteboardName, const SelectionData& selection) { - uint64_t changeCount; - WebProcess::shared().parentProcessConnection()->sendSync(Messages::WebContext::GetPasteboardChangeCount(String()), - Messages::WebContext::GetPasteboardChangeCount::Reply(changeCount), 0); - return changeCount; + WebSelectionData selectionData(selection); + WebProcess::singleton().parentProcessConnection()->send(Messages::WebPasteboardProxy::WriteToClipboard(pasteboardName, selectionData), 0); } -#endif +Ref<SelectionData> WebPlatformStrategies::readFromClipboard(const String& pasteboardName) +{ + WebSelectionData selection; + WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::ReadFromClipboard(pasteboardName), Messages::WebPasteboardProxy::ReadFromClipboard::Reply(selection), 0); + return WTFMove(selection.selectionData); +} -#endif +#endif // PLATFORM(GTK) } // namespace WebKit |