Bug 1322316 - Split SessionStorage and LocalStorage implementation - part 6 - Implementation of IsForkOf(), r=asuth
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 17 May 2017 07:01:14 +0200
changeset 358635 6937455b609899c63f7aa9c77f5b8fa7df213127
parent 358634 fc8021ded92b04ded69778a7b1f2857bb7f61741
child 358636 647d36b541ccd0d2a9021c7c5d9da507b3c9b1cc
push id90362
push useramarchesini@mozilla.com
push dateWed, 17 May 2017 05:03:33 +0000
treeherdermozilla-inbound@2f47ba116b42 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1322316
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1322316 - Split SessionStorage and LocalStorage implementation - part 6 - Implementation of IsForkOf(), r=asuth
dom/base/nsGlobalWindow.cpp
dom/storage/LocalStorage.cpp
dom/storage/LocalStorage.h
dom/storage/LocalStorageManager.cpp
dom/storage/SessionStorage.cpp
dom/storage/SessionStorage.h
dom/storage/SessionStorageManager.cpp
dom/storage/Storage.h
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -12,16 +12,17 @@
 
 // Local Includes
 #include "Navigator.h"
 #include "nsContentSecurityManager.h"
 #include "nsScreen.h"
 #include "nsHistory.h"
 #include "nsDOMNavigationTiming.h"
 #include "nsIDOMStorageManager.h"
+#include "mozilla/dom/LocalStorage.h"
 #include "mozilla/dom/Storage.h"
 #include "mozilla/dom/IdleRequest.h"
 #include "mozilla/dom/Performance.h"
 #include "mozilla/dom/StorageEvent.h"
 #include "mozilla/dom/StorageEventBinding.h"
 #include "mozilla/dom/Timeout.h"
 #include "mozilla/dom/TimeoutHandler.h"
 #include "mozilla/dom/TimeoutManager.h"
@@ -12265,23 +12266,27 @@ nsGlobalWindow::CloneStorageEvent(const 
 
   // If null, this is a localStorage event received by IPC.
   if (!storageArea) {
     storage = GetLocalStorage(aRv);
     if (aRv.Failed() || !storage) {
       return nullptr;
     }
 
+    MOZ_ASSERT(storage->Type() == Storage::eLocalStorage);
+    RefPtr<LocalStorage> localStorage =
+      static_cast<LocalStorage*>(storage.get());
+
     // We must apply the current change to the 'local' localStorage.
-    storage->ApplyEvent(aEvent);
-  } else if (storageArea->GetType() == Storage::LocalStorage) {
+    localStorage->ApplyEvent(aEvent);
+  } else if (storageArea->Type() == Storage::eSessionStorage) {
+    storage = GetSessionStorage(aRv);
+  } else {
+    MOZ_ASSERT(storageArea->Type() == Storage::eLocalStorage);
     storage = GetLocalStorage(aRv);
-  } else {
-    MOZ_ASSERT(storageArea->GetType() == Storage::SessionStorage);
-    storage = GetSessionStorage(aRv);
   }
 
   if (aRv.Failed() || !storage) {
     return nullptr;
   }
 
   MOZ_ASSERT(storage);
   MOZ_ASSERT_IF(storageArea, storage->IsForkOf(storageArea));
--- a/dom/storage/LocalStorage.cpp
+++ b/dom/storage/LocalStorage.cpp
@@ -284,10 +284,21 @@ LocalStorage::GetSupportedNames(nsTArray
     // return just an empty array
     aKeys.Clear();
     return;
   }
 
   mCache->GetKeys(this, aKeys);
 }
 
+bool
+LocalStorage::IsForkOf(const Storage* aOther) const
+{
+  MOZ_ASSERT(aOther);
+  if (aOther->Type() != eLocalStorage) {
+    return false;
+  }
+
+  return mCache == static_cast<const LocalStorage*>(aOther)->mCache;
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/dom/storage/LocalStorage.h
+++ b/dom/storage/LocalStorage.h
@@ -40,16 +40,18 @@ public:
 
   LocalStorage(nsPIDOMWindowInner* aWindow,
                LocalStorageManager* aManager,
                StorageCache* aCache,
                const nsAString& aDocumentURI,
                nsIPrincipal* aPrincipal,
                bool aIsPrivate);
 
+  bool IsForkOf(const Storage* aOther) const override;
+
   // WebIDL
 
   int64_t GetOriginQuotaUsage() const override;
 
   uint32_t GetLength(nsIPrincipal& aSubjectPrincipal,
                      ErrorResult& aRv) override;
 
   void Key(uint32_t aIndex, nsAString& aResult,
@@ -71,22 +73,16 @@ public:
                   ErrorResult& aRv) override;
 
   void Clear(nsIPrincipal& aSubjectPrincipal,
              ErrorResult& aRv) override;
 
   bool IsPrivate() const { return mIsPrivate; }
   bool IsSessionOnly() const override { return mIsSessionOnly; }
 
-  bool IsForkOf(const LocalStorage* aOther) const
-  {
-    MOZ_ASSERT(aOther);
-    return mCache == aOther->mCache;
-  }
-
   // aStorage can be null if this method is called by ContentChild.
   //
   // aImmediateDispatch is for use by (main-thread) IPC code so that PContent
   // ordering can be maintained.  Without this, the event would be enqueued and
   // run in a future turn of the event loop, potentially allowing other PContent
   // Recv* methods to trigger script that wants to assume our localstorage
   // changes have already been applied.  This is the case for message manager
   // messages which are used by ContentTask testing logic and webextensions.
--- a/dom/storage/LocalStorageManager.cpp
+++ b/dom/storage/LocalStorageManager.cpp
@@ -213,18 +213,18 @@ LocalStorageManager::GetStorageInternal(
                                         const nsAString& aDocumentURI,
                                         bool aPrivate,
                                         nsIDOMStorage** aRetval)
 {
   nsAutoCString originAttrSuffix;
   nsAutoCString originKey;
 
   nsresult rv = GenerateOriginKey(aPrincipal, originAttrSuffix, originKey);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+  if (NS_FAILED(rv)) {
+    return NS_ERROR_NOT_AVAILABLE;
   }
 
   RefPtr<StorageCache> cache = GetCache(originAttrSuffix, originKey);
 
   // Get or create a cache for the given scope
   if (!cache) {
     if (aCreateMode == CreateMode::UseIfExistsNeverCreate) {
       *aRetval = nullptr;
--- a/dom/storage/SessionStorage.cpp
+++ b/dom/storage/SessionStorage.cpp
@@ -195,16 +195,27 @@ void
 SessionStorage::BroadcastChangeNotification(const nsAString& aKey,
                                             const nsAString& aOldValue,
                                             const nsAString& aNewValue)
 {
   NotifyChange(this, Principal(), aKey, aOldValue, aNewValue, u"sessionStorage",
                mDocumentURI, mIsPrivate, false);
 }
 
+bool
+SessionStorage::IsForkOf(const Storage* aOther) const
+{
+  MOZ_ASSERT(aOther);
+  if (aOther->Type() != eSessionStorage) {
+    return false;
+  }
+
+  return mCache == static_cast<const SessionStorage*>(aOther)->mCache;
+}
+
 // ----------------------------------------------------------------------------
 // SessionStorageCache
 // ----------------------------------------------------------------------------
 
 SessionStorageCache::SessionStorageCache()
   : mOriginQuotaUsage(0)
 {}
 
--- a/dom/storage/SessionStorage.h
+++ b/dom/storage/SessionStorage.h
@@ -37,16 +37,18 @@ public:
 
   SessionStorageCache* Cache() const { return mCache; }
 
   already_AddRefed<SessionStorage>
   Clone() const;
 
   int64_t GetOriginQuotaUsage() const override;
 
+  bool IsForkOf(const Storage* aStorage) const override;
+
   // WebIDL
   uint32_t GetLength(nsIPrincipal& aSubjectPrincipal,
                      ErrorResult& aRv) override;
 
   void Key(uint32_t aIndex, nsAString& aResult,
            nsIPrincipal& aSubjectPrincipal,
            ErrorResult& aRv) override;
 
--- a/dom/storage/SessionStorageManager.cpp
+++ b/dom/storage/SessionStorageManager.cpp
@@ -34,18 +34,18 @@ SessionStorageManager::CreateStorage(moz
                                      nsIPrincipal* aPrincipal,
                                      const nsAString& aDocumentURI,
                                      bool aPrivate,
                                      nsIDOMStorage** aRetval)
 {
   nsAutoCString originKey;
   nsAutoCString originAttributes;
   nsresult rv = GenerateOriginKey(aPrincipal, originAttributes, originKey);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+  if (NS_FAILED(rv)) {
+    return NS_ERROR_NOT_AVAILABLE;
   }
 
   OriginKeyHashTable* table;
   if (!mOATable.Get(originAttributes, &table)) {
     table = new OriginKeyHashTable();
     mOATable.Put(originAttributes, table);
   }
 
--- a/dom/storage/Storage.h
+++ b/dom/storage/Storage.h
@@ -34,16 +34,18 @@ public:
 
   enum StorageType {
     eSessionStorage,
     eLocalStorage,
   };
 
   virtual StorageType Type() const = 0;
 
+  virtual bool IsForkOf(const Storage* aStorage) const = 0;
+
   virtual int64_t GetOriginQuotaUsage() const = 0;
 
   virtual bool CanAccess(nsIPrincipal* aPrincipal);
 
   nsIPrincipal*
   Principal() const
   {
     return mPrincipal;