Skip to content
Permalink
Browse files
Put some common code in StorageNamespaceProvider
https://bugs.webkit.org/show_bug.cgi?id=139682

Reviewed by Tim Horton.

We have code in two places that gets the local storage area from a given document,
choosing either the local storage namespace or the transient local storage namespace.
Move it to StorageNamespaceProvider::localStorageArea.

* bindings/js/ScriptController.cpp:
* inspector/InspectorDOMStorageAgent.cpp:
(WebCore::InspectorDOMStorageAgent::findStorageArea):
* page/DOMWindow.cpp:
(WebCore::DOMWindow::localStorage):
* page/Navigator.cpp:
* storage/StorageNamespaceProvider.cpp:
(WebCore::StorageNamespaceProvider::localStorageArea):
(WebCore::StorageNamespaceProvider::localStorageNamespace):
* storage/StorageNamespaceProvider.h:

Canonical link: https://commits.webkit.org/157573@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@177365 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Anders Carlsson committed Dec 16, 2014
1 parent aac46b1 commit 18cccabf6a8f5440384133f573abb9481326c3a2
@@ -1,3 +1,25 @@
2014-12-16 Anders Carlsson <andersca@apple.com>

Put some common code in StorageNamespaceProvider
https://bugs.webkit.org/show_bug.cgi?id=139682

Reviewed by Tim Horton.

We have code in two places that gets the local storage area from a given document,
choosing either the local storage namespace or the transient local storage namespace.
Move it to StorageNamespaceProvider::localStorageArea.

* bindings/js/ScriptController.cpp:
* inspector/InspectorDOMStorageAgent.cpp:
(WebCore::InspectorDOMStorageAgent::findStorageArea):
* page/DOMWindow.cpp:
(WebCore::DOMWindow::localStorage):
* page/Navigator.cpp:
* storage/StorageNamespaceProvider.cpp:
(WebCore::StorageNamespaceProvider::localStorageArea):
(WebCore::StorageNamespaceProvider::localStorageNamespace):
* storage/StorageNamespaceProvider.h:

2014-12-16 Anders Carlsson <andersca@apple.com>

Add FeatureCounterKeys.h to the Xcode project.
@@ -43,7 +43,6 @@
#include "ScriptSourceCode.h"
#include "ScriptableDocumentParser.h"
#include "Settings.h"
#include "StorageNamespace.h"
#include "UserGestureIndicator.h"
#include "WebCoreJSClientData.h"
#include "npruntime_impl.h"
@@ -45,7 +45,6 @@
#include "PageGroup.h"
#include "SecurityOrigin.h"
#include "Storage.h"
#include "StorageNamespace.h"
#include "StorageNamespaceProvider.h"
#include "VoidCallback.h"
#include <inspector/InspectorFrontendDispatchers.h>
@@ -201,14 +200,7 @@ PassRefPtr<StorageArea> InspectorDOMStorageAgent::findStorageArea(ErrorString& e
return nullptr;
}

Page* page = m_pageAgent->page();
Document* document = targetFrame->document();
if (isLocalStorage) {
if (document->securityOrigin()->canAccessLocalStorage(document->topOrigin()))
return page->storageNamespaceProvider().localStorageNamespace().storageArea(document->securityOrigin());
return page->storageNamespaceProvider().transientLocalStorageNamespace(*document->topOrigin()).storageArea(document->securityOrigin());
}
return page->sessionStorage()->storageArea(document->securityOrigin());
return m_pageAgent->page()->storageNamespaceProvider().localStorageArea(*targetFrame->document());
}

} // namespace WebCore
@@ -856,12 +856,7 @@ Storage* DOMWindow::localStorage(ExceptionCode& ec) const
if (!page->settings().localStorageEnabled())
return nullptr;

RefPtr<StorageArea> storageArea;

if (document->securityOrigin()->canAccessLocalStorage(document->topOrigin()))
storageArea = page->storageNamespaceProvider().localStorageNamespace().storageArea(document->securityOrigin());
else
storageArea = page->storageNamespaceProvider().transientLocalStorageNamespace(*document->topOrigin()).storageArea(document->securityOrigin());
RefPtr<StorageArea> storageArea = page->storageNamespaceProvider().localStorageArea(*document);

if (!storageArea->canAccessStorage(m_frame)) {
ec = SECURITY_ERR;
@@ -37,7 +37,6 @@
#include "ScriptController.h"
#include "SecurityOrigin.h"
#include "Settings.h"
#include "StorageNamespace.h"
#include <wtf/HashSet.h>
#include <wtf/NumberOfCores.h>
#include <wtf/StdLibExtras.h>
@@ -26,6 +26,8 @@
#include "config.h"
#include "StorageNamespaceProvider.h"

#include "Document.h"
#include "StorageArea.h"
#include "StorageNamespace.h"

namespace WebCore {
@@ -56,6 +58,13 @@ void StorageNamespaceProvider::removePage(Page& page)
m_pages.remove(&page);
}

RefPtr<StorageArea> StorageNamespaceProvider::localStorageArea(Document& document)
{
auto& storageNamespace = document.securityOrigin()->canAccessLocalStorage(document.topOrigin()) ? localStorageNamespace() : transientLocalStorageNamespace(*document.topOrigin());

return storageNamespace.storageArea(document.securityOrigin());
}

StorageNamespace& StorageNamespaceProvider::localStorageNamespace()
{
if (!m_localStorageNamespace)
@@ -34,8 +34,10 @@

namespace WebCore {

class Document;
class Page;
class SecurityOrigin;
class StorageArea;
class StorageNamespace;

class StorageNamespaceProvider : public RefCounted<StorageNamespaceProvider> {
@@ -44,8 +46,7 @@ class StorageNamespaceProvider : public RefCounted<StorageNamespaceProvider> {
virtual ~StorageNamespaceProvider();

virtual RefPtr<StorageNamespace> createSessionStorageNamespace(Page&, unsigned quota) = 0;
StorageNamespace& localStorageNamespace();
StorageNamespace& transientLocalStorageNamespace(SecurityOrigin&);
RefPtr<StorageArea> localStorageArea(Document&);

void addPage(Page&);
void removePage(Page&);
@@ -54,6 +55,9 @@ class StorageNamespaceProvider : public RefCounted<StorageNamespaceProvider> {
StorageNamespace* optionalLocalStorageNamespace() { return m_localStorageNamespace.get(); }

private:
StorageNamespace& localStorageNamespace();
StorageNamespace& transientLocalStorageNamespace(SecurityOrigin&);

virtual RefPtr<StorageNamespace> createLocalStorageNamespace(unsigned quota) = 0;
virtual RefPtr<StorageNamespace> createTransientLocalStorageNamespace(SecurityOrigin&, unsigned quota) = 0;

0 comments on commit 18cccab

Please sign in to comment.