diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index 788fb5dc1e5c..c8feeec4a511 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,25 @@ +2014-12-16 Anders Carlsson + + 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 Add FeatureCounterKeys.h to the Xcode project. diff --git a/Source/WebCore/bindings/js/ScriptController.cpp b/Source/WebCore/bindings/js/ScriptController.cpp index c99adfdee0b3..702144c66441 100644 --- a/Source/WebCore/bindings/js/ScriptController.cpp +++ b/Source/WebCore/bindings/js/ScriptController.cpp @@ -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" diff --git a/Source/WebCore/inspector/InspectorDOMStorageAgent.cpp b/Source/WebCore/inspector/InspectorDOMStorageAgent.cpp index 41baf0a09a05..d7c5ea30fcd4 100644 --- a/Source/WebCore/inspector/InspectorDOMStorageAgent.cpp +++ b/Source/WebCore/inspector/InspectorDOMStorageAgent.cpp @@ -45,7 +45,6 @@ #include "PageGroup.h" #include "SecurityOrigin.h" #include "Storage.h" -#include "StorageNamespace.h" #include "StorageNamespaceProvider.h" #include "VoidCallback.h" #include @@ -201,14 +200,7 @@ PassRefPtr 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 diff --git a/Source/WebCore/page/DOMWindow.cpp b/Source/WebCore/page/DOMWindow.cpp index 3b83e796b29e..16ab50d45e18 100644 --- a/Source/WebCore/page/DOMWindow.cpp +++ b/Source/WebCore/page/DOMWindow.cpp @@ -856,12 +856,7 @@ Storage* DOMWindow::localStorage(ExceptionCode& ec) const if (!page->settings().localStorageEnabled()) return nullptr; - RefPtr 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 = page->storageNamespaceProvider().localStorageArea(*document); if (!storageArea->canAccessStorage(m_frame)) { ec = SECURITY_ERR; diff --git a/Source/WebCore/page/Navigator.cpp b/Source/WebCore/page/Navigator.cpp index bb2a254cac88..25895bf54154 100644 --- a/Source/WebCore/page/Navigator.cpp +++ b/Source/WebCore/page/Navigator.cpp @@ -37,7 +37,6 @@ #include "ScriptController.h" #include "SecurityOrigin.h" #include "Settings.h" -#include "StorageNamespace.h" #include #include #include diff --git a/Source/WebCore/storage/StorageNamespaceProvider.cpp b/Source/WebCore/storage/StorageNamespaceProvider.cpp index a7844c4e4065..acf373ff1d71 100644 --- a/Source/WebCore/storage/StorageNamespaceProvider.cpp +++ b/Source/WebCore/storage/StorageNamespaceProvider.cpp @@ -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 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) diff --git a/Source/WebCore/storage/StorageNamespaceProvider.h b/Source/WebCore/storage/StorageNamespaceProvider.h index 260ee1086f5c..8391bd4c2e6a 100644 --- a/Source/WebCore/storage/StorageNamespaceProvider.h +++ b/Source/WebCore/storage/StorageNamespaceProvider.h @@ -34,8 +34,10 @@ namespace WebCore { +class Document; class Page; class SecurityOrigin; +class StorageArea; class StorageNamespace; class StorageNamespaceProvider : public RefCounted { @@ -44,8 +46,7 @@ class StorageNamespaceProvider : public RefCounted { virtual ~StorageNamespaceProvider(); virtual RefPtr createSessionStorageNamespace(Page&, unsigned quota) = 0; - StorageNamespace& localStorageNamespace(); - StorageNamespace& transientLocalStorageNamespace(SecurityOrigin&); + RefPtr localStorageArea(Document&); void addPage(Page&); void removePage(Page&); @@ -54,6 +55,9 @@ class StorageNamespaceProvider : public RefCounted { StorageNamespace* optionalLocalStorageNamespace() { return m_localStorageNamespace.get(); } private: + StorageNamespace& localStorageNamespace(); + StorageNamespace& transientLocalStorageNamespace(SecurityOrigin&); + virtual RefPtr createLocalStorageNamespace(unsigned quota) = 0; virtual RefPtr createTransientLocalStorageNamespace(SecurityOrigin&, unsigned quota) = 0;