Use SecurityOriginData more consistently in Service Worker code
[WebKit-https.git] / Source / WebCore / storage / StorageNamespaceProvider.cpp
index a7844c4..69c1b33 100644 (file)
 #include "config.h"
 #include "StorageNamespaceProvider.h"
 
+#include "Document.h"
+#include "Page.h"
+#include "SecurityOriginData.h"
+#include "StorageArea.h"
 #include "StorageNamespace.h"
 
 namespace WebCore {
@@ -56,6 +60,27 @@ void StorageNamespaceProvider::removePage(Page& page)
     m_pages.remove(&page);
 }
 
+RefPtr<StorageArea> StorageNamespaceProvider::localStorageArea(Document& document)
+{
+    // This StorageNamespaceProvider was retrieved from the Document's Page,
+    // so the Document had better still actually have a Page.
+    ASSERT(document.page());
+
+    bool ephemeral = document.page()->usesEphemeralSession();
+    bool transient = !document.securityOrigin().canAccessLocalStorage(&document.topOrigin());
+
+    RefPtr<StorageNamespace> storageNamespace;
+
+    if (transient)
+        storageNamespace = &transientLocalStorageNamespace(document.topOrigin());
+    else if (ephemeral)
+        storageNamespace = document.page()->ephemeralLocalStorage();
+    else
+        storageNamespace = &localStorageNamespace();
+
+    return storageNamespace->storageArea(document.securityOrigin().data());
+}
+
 StorageNamespace& StorageNamespaceProvider::localStorageNamespace()
 {
     if (!m_localStorageNamespace)