Skip to content

Commit

Permalink
Put some common code in StorageNamespaceProvider
Browse files Browse the repository at this point in the history
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 18cccab
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 19 deletions.
22 changes: 22 additions & 0 deletions Source/WebCore/ChangeLog
@@ -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.
Expand Down
1 change: 0 additions & 1 deletion Source/WebCore/bindings/js/ScriptController.cpp
Expand Up @@ -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"
Expand Down
10 changes: 1 addition & 9 deletions Source/WebCore/inspector/InspectorDOMStorageAgent.cpp
Expand Up @@ -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>
Expand Down Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions Source/WebCore/page/DOMWindow.cpp
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion Source/WebCore/page/Navigator.cpp
Expand Up @@ -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>
Expand Down
9 changes: 9 additions & 0 deletions Source/WebCore/storage/StorageNamespaceProvider.cpp
Expand Up @@ -26,6 +26,8 @@
#include "config.h"
#include "StorageNamespaceProvider.h"

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

namespace WebCore {
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions Source/WebCore/storage/StorageNamespaceProvider.h
Expand Up @@ -34,8 +34,10 @@

namespace WebCore {

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

class StorageNamespaceProvider : public RefCounted<StorageNamespaceProvider> {
Expand All @@ -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&);
Expand All @@ -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;

Expand Down

0 comments on commit 18cccab

Please sign in to comment.