diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebKit2/WebProcess/Storage/StorageAreaMap.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebKit2/WebProcess/Storage/StorageAreaMap.cpp')
-rw-r--r-- | Source/WebKit2/WebProcess/Storage/StorageAreaMap.cpp | 78 |
1 files changed, 50 insertions, 28 deletions
diff --git a/Source/WebKit2/WebProcess/Storage/StorageAreaMap.cpp b/Source/WebKit2/WebProcess/Storage/StorageAreaMap.cpp index 8d3b6397d..a2650d1b3 100644 --- a/Source/WebKit2/WebProcess/Storage/StorageAreaMap.cpp +++ b/Source/WebKit2/WebProcess/Storage/StorageAreaMap.cpp @@ -26,7 +26,6 @@ #include "config.h" #include "StorageAreaMap.h" -#include "SecurityOriginData.h" #include "StorageAreaImpl.h" #include "StorageAreaMapMessages.h" #include "StorageManagerMessages.h" @@ -35,12 +34,15 @@ #include "WebPageGroupProxy.h" #include "WebProcess.h" #include <WebCore/DOMWindow.h> +#include <WebCore/Document.h> #include <WebCore/MainFrame.h> #include <WebCore/Page.h> #include <WebCore/PageGroup.h> +#include <WebCore/SecurityOriginData.h> #include <WebCore/Storage.h> #include <WebCore/StorageEventDispatcher.h> #include <WebCore/StorageMap.h> +#include <WebCore/StorageType.h> using namespace WebCore; @@ -52,32 +54,52 @@ static uint64_t generateStorageMapID() return ++storageMapID; } -PassRefPtr<StorageAreaMap> StorageAreaMap::create(StorageNamespaceImpl* storageNamespace, PassRefPtr<WebCore::SecurityOrigin> securityOrigin) +Ref<StorageAreaMap> StorageAreaMap::create(StorageNamespaceImpl* storageNamespace, Ref<WebCore::SecurityOrigin>&& securityOrigin) { - return adoptRef(new StorageAreaMap(storageNamespace, securityOrigin)); + return adoptRef(*new StorageAreaMap(storageNamespace, WTFMove(securityOrigin))); } -StorageAreaMap::StorageAreaMap(StorageNamespaceImpl* storageNamespace, PassRefPtr<WebCore::SecurityOrigin> securityOrigin) - : m_storageMapID(generateStorageMapID()) +StorageAreaMap::StorageAreaMap(StorageNamespaceImpl* storageNamespace, Ref<WebCore::SecurityOrigin>&& securityOrigin) + : m_storageNamespace(*storageNamespace) + , m_storageMapID(generateStorageMapID()) , m_storageType(storageNamespace->storageType()) , m_storageNamespaceID(storageNamespace->storageNamespaceID()) , m_quotaInBytes(storageNamespace->quotaInBytes()) - , m_securityOrigin(securityOrigin) + , m_securityOrigin(WTFMove(securityOrigin)) , m_currentSeed(0) , m_hasPendingClear(false) , m_hasPendingGetValues(false) { - if (m_storageType == LocalStorage) - WebProcess::shared().parentProcessConnection()->send(Messages::StorageManager::CreateLocalStorageMap(m_storageMapID, storageNamespace->storageNamespaceID(), SecurityOriginData::fromSecurityOrigin(m_securityOrigin.get())), 0); - else - WebProcess::shared().parentProcessConnection()->send(Messages::StorageManager::CreateSessionStorageMap(m_storageMapID, storageNamespace->storageNamespaceID(), SecurityOriginData::fromSecurityOrigin(m_securityOrigin.get())), 0); - WebProcess::shared().addMessageReceiver(Messages::StorageAreaMap::messageReceiverName(), m_storageMapID, *this); + switch (m_storageType) { + case StorageType::Local: + case StorageType::TransientLocal: + if (SecurityOrigin* topLevelOrigin = storageNamespace->topLevelOrigin()) + WebProcess::singleton().parentProcessConnection()->send(Messages::StorageManager::CreateTransientLocalStorageMap(m_storageMapID, storageNamespace->storageNamespaceID(), SecurityOriginData::fromSecurityOrigin(*topLevelOrigin), SecurityOriginData::fromSecurityOrigin(m_securityOrigin)), 0); + else + WebProcess::singleton().parentProcessConnection()->send(Messages::StorageManager::CreateLocalStorageMap(m_storageMapID, storageNamespace->storageNamespaceID(), SecurityOriginData::fromSecurityOrigin(m_securityOrigin)), 0); + + break; + + case StorageType::Session: + WebProcess::singleton().parentProcessConnection()->send(Messages::StorageManager::CreateSessionStorageMap(m_storageMapID, storageNamespace->storageNamespaceID(), SecurityOriginData::fromSecurityOrigin(m_securityOrigin)), 0); + break; + + case StorageType::EphemeralLocal: + // The UI process is not involved for EphemeralLocal storages. + return; + } + + WebProcess::singleton().addMessageReceiver(Messages::StorageAreaMap::messageReceiverName(), m_storageMapID, *this); } StorageAreaMap::~StorageAreaMap() { - WebProcess::shared().parentProcessConnection()->send(Messages::StorageManager::DestroyStorageMap(m_storageMapID), 0); - WebProcess::shared().removeMessageReceiver(Messages::StorageAreaMap::messageReceiverName(), m_storageMapID); + if (m_storageType != StorageType::EphemeralLocal) { + WebProcess::singleton().parentProcessConnection()->send(Messages::StorageManager::DestroyStorageMap(m_storageMapID), 0); + WebProcess::singleton().removeMessageReceiver(Messages::StorageAreaMap::messageReceiverName(), m_storageMapID); + } + + m_storageNamespace->didDestroyStorageAreaMap(*this); } unsigned StorageAreaMap::length() @@ -118,7 +140,7 @@ void StorageAreaMap::setItem(Frame* sourceFrame, StorageAreaImpl* sourceArea, co m_pendingValueChanges.add(key); - WebProcess::shared().parentProcessConnection()->send(Messages::StorageManager::SetItem(m_storageMapID, sourceArea->storageAreaID(), m_currentSeed, key, value, sourceFrame->document()->url()), 0); + WebProcess::singleton().parentProcessConnection()->send(Messages::StorageManager::SetItem(m_storageMapID, sourceArea->storageAreaID(), m_currentSeed, key, value, sourceFrame->document()->url()), 0); } void StorageAreaMap::removeItem(WebCore::Frame* sourceFrame, StorageAreaImpl* sourceArea, const String& key) @@ -134,7 +156,7 @@ void StorageAreaMap::removeItem(WebCore::Frame* sourceFrame, StorageAreaImpl* so m_pendingValueChanges.add(key); - WebProcess::shared().parentProcessConnection()->send(Messages::StorageManager::RemoveItem(m_storageMapID, sourceArea->storageAreaID(), m_currentSeed, key, sourceFrame->document()->url()), 0); + WebProcess::singleton().parentProcessConnection()->send(Messages::StorageManager::RemoveItem(m_storageMapID, sourceArea->storageAreaID(), m_currentSeed, key, sourceFrame->document()->url()), 0); } void StorageAreaMap::clear(WebCore::Frame* sourceFrame, StorageAreaImpl* sourceArea) @@ -143,7 +165,7 @@ void StorageAreaMap::clear(WebCore::Frame* sourceFrame, StorageAreaImpl* sourceA m_hasPendingClear = true; m_storageMap = StorageMap::create(m_quotaInBytes); - WebProcess::shared().parentProcessConnection()->send(Messages::StorageManager::Clear(m_storageMapID, sourceArea->storageAreaID(), m_currentSeed, sourceFrame->document()->url()), 0); + WebProcess::singleton().parentProcessConnection()->send(Messages::StorageManager::Clear(m_storageMapID, sourceArea->storageAreaID(), m_currentSeed, sourceFrame->document()->url()), 0); } bool StorageAreaMap::contains(const String& key) @@ -172,7 +194,7 @@ void StorageAreaMap::loadValuesIfNeeded() // FIXME: This should use a special sendSync flag to indicate that we don't want to process incoming messages while waiting for a reply. // (This flag does not yet exist). Since loadValuesIfNeeded() ends up being called from within JavaScript code, processing incoming synchronous messages // could lead to weird reentrency bugs otherwise. - WebProcess::shared().parentProcessConnection()->sendSync(Messages::StorageManager::GetValues(m_storageMapID, m_currentSeed), Messages::StorageManager::GetValues::Reply(values), 0); + WebProcess::singleton().parentProcessConnection()->sendSync(Messages::StorageManager::GetValues(m_storageMapID, m_currentSeed), Messages::StorageManager::GetValues::Reply(values), 0); m_storageMap = StorageMap::create(m_quotaInBytes); m_storageMap->importItems(values); @@ -248,7 +270,7 @@ void StorageAreaMap::applyChange(const String& key, const String& newValue) if (!key) { // A null key means clear. - RefPtr<StorageMap> newStorageMap = StorageMap::create(m_quotaInBytes); + auto newStorageMap = StorageMap::create(m_quotaInBytes); // Any changes that were made locally after the clear must still be kept around in the new map. for (auto it = m_pendingValueChanges.begin().keys(), end = m_pendingValueChanges.end().keys(); it != end; ++it) { @@ -264,7 +286,7 @@ void StorageAreaMap::applyChange(const String& key, const String& newValue) newStorageMap->setItemIgnoringQuota(key, oldValue); } - m_storageMap = newStorageMap.release(); + m_storageMap = WTFMove(newStorageMap); return; } @@ -288,7 +310,7 @@ void StorageAreaMap::dispatchStorageEvent(uint64_t sourceStorageAreaID, const St applyChange(key, newValue); } - if (storageType() == SessionStorage) + if (storageType() == StorageType::Session) dispatchSessionStorageEvent(sourceStorageAreaID, key, oldValue, newValue, urlString); else dispatchLocalStorageEvent(sourceStorageAreaID, key, oldValue, newValue, urlString); @@ -301,11 +323,11 @@ void StorageAreaMap::clearCache() void StorageAreaMap::dispatchSessionStorageEvent(uint64_t sourceStorageAreaID, const String& key, const String& oldValue, const String& newValue, const String& urlString) { - ASSERT(storageType() == SessionStorage); + ASSERT(storageType() == StorageType::Session); // Namespace IDs for session storage namespaces are equivalent to web page IDs // so we can get the right page here. - WebPage* webPage = WebProcess::shared().webPage(m_storageNamespaceID); + WebPage* webPage = WebProcess::singleton().webPage(m_storageNamespaceID); if (!webPage) return; @@ -314,7 +336,7 @@ void StorageAreaMap::dispatchSessionStorageEvent(uint64_t sourceStorageAreaID, c Page* page = webPage->corePage(); for (Frame* frame = &page->mainFrame(); frame; frame = frame->tree().traverseNext()) { Document* document = frame->document(); - if (!document->securityOrigin()->equal(m_securityOrigin.get())) + if (!document->securityOrigin().equal(m_securityOrigin.ptr())) continue; Storage* storage = document->domWindow()->optionalSessionStorage(); @@ -330,21 +352,21 @@ void StorageAreaMap::dispatchSessionStorageEvent(uint64_t sourceStorageAreaID, c frames.append(frame); } - StorageEventDispatcher::dispatchLocalStorageEventsToFrames(page->group(), frames, key, oldValue, newValue, urlString, m_securityOrigin.get()); + StorageEventDispatcher::dispatchSessionStorageEventsToFrames(*page, frames, key, oldValue, newValue, urlString, SecurityOriginData::fromSecurityOrigin(m_securityOrigin)); } void StorageAreaMap::dispatchLocalStorageEvent(uint64_t sourceStorageAreaID, const String& key, const String& oldValue, const String& newValue, const String& urlString) { - ASSERT(storageType() == LocalStorage); + ASSERT(isLocalStorage(storageType())); Vector<RefPtr<Frame>> frames; - PageGroup& pageGroup = *WebProcess::shared().webPageGroup(m_storageNamespaceID)->corePageGroup(); + PageGroup& pageGroup = *WebProcess::singleton().webPageGroup(m_storageNamespaceID)->corePageGroup(); const HashSet<Page*>& pages = pageGroup.pages(); for (HashSet<Page*>::const_iterator it = pages.begin(), end = pages.end(); it != end; ++it) { for (Frame* frame = &(*it)->mainFrame(); frame; frame = frame->tree().traverseNext()) { Document* document = frame->document(); - if (!document->securityOrigin()->equal(m_securityOrigin.get())) + if (!document->securityOrigin().equal(m_securityOrigin.ptr())) continue; Storage* storage = document->domWindow()->optionalLocalStorage(); @@ -361,7 +383,7 @@ void StorageAreaMap::dispatchLocalStorageEvent(uint64_t sourceStorageAreaID, con } } - StorageEventDispatcher::dispatchLocalStorageEventsToFrames(pageGroup, frames, key, oldValue, newValue, urlString, m_securityOrigin.get()); + StorageEventDispatcher::dispatchLocalStorageEventsToFrames(pageGroup, frames, key, oldValue, newValue, urlString, SecurityOriginData::fromSecurityOrigin(m_securityOrigin)); } } // namespace WebKit |