Bug 1593246 - Part 2: Give SessionStorageManager a reference to BrowsingContext r=sg
authorYaron Tausky <ytausky@mozilla.com>
Tue, 10 Dec 2019 12:12:32 +0000
changeset 506307 c11ce752a12ef6db0e2422858fe2b00471a9ed9b
parent 506306 433fd567ff921e36c9a42bddc2959e95004a716b
child 506308 44fb598d3ad83467805f960e973a6757c125ea5a
push id36902
push useraciure@mozilla.com
push dateWed, 11 Dec 2019 03:34:51 +0000
treeherdermozilla-central@7635669b8d72 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssg
bugs1593246
milestone73.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 1593246 - Part 2: Give SessionStorageManager a reference to BrowsingContext r=sg This reference is necessary when sending session storage data for all browsing context to the parent process. Note that it entails making SessionStorageManager a cycle collection participant, since adding this reference creates a cycle. Differential Revision: https://phabricator.services.mozilla.com/D55659
docshell/base/BrowsingContext.cpp
dom/storage/SessionStorageManager.cpp
dom/storage/SessionStorageManager.h
layout/build/nsLayoutModule.cpp
--- a/docshell/base/BrowsingContext.cpp
+++ b/docshell/base/BrowsingContext.cpp
@@ -674,17 +674,17 @@ bool BrowsingContext::CanAccess(Browsing
   }
 
   return false;
 }
 
 RefPtr<SessionStorageManager> BrowsingContext::GetSessionStorageManager() {
   RefPtr<SessionStorageManager>& manager = Top()->mSessionStorageManager;
   if (!manager) {
-    manager = new SessionStorageManager();
+    manager = new SessionStorageManager(this);
   }
   return manager;
 }
 
 BrowsingContext::~BrowsingContext() {
   MOZ_DIAGNOSTIC_ASSERT(!mParent || !mParent->mChildren.Contains(this));
   MOZ_DIAGNOSTIC_ASSERT(!mGroup || !mGroup->Toplevels().Contains(this));
   MOZ_DIAGNOSTIC_ASSERT(!mGroup || !mGroup->IsContextCached(this));
--- a/dom/storage/SessionStorageManager.cpp
+++ b/dom/storage/SessionStorageManager.cpp
@@ -12,20 +12,29 @@
 #include "SessionStorageObserver.h"
 #include "StorageUtils.h"
 
 namespace mozilla {
 namespace dom {
 
 using namespace StorageUtils;
 
-NS_IMPL_ISUPPORTS(SessionStorageManager, nsIDOMStorageManager,
-                  nsIDOMSessionStorageManager)
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SessionStorageManager)
+  NS_INTERFACE_MAP_ENTRY(nsISupports)
+  NS_INTERFACE_MAP_ENTRY(nsIDOMStorageManager)
+  NS_INTERFACE_MAP_ENTRY(nsIDOMSessionStorageManager)
+NS_INTERFACE_MAP_END
 
-SessionStorageManager::SessionStorageManager() {
+NS_IMPL_CYCLE_COLLECTION(SessionStorageManager, mBrowsingContext)
+NS_IMPL_CYCLE_COLLECTING_ADDREF(SessionStorageManager)
+NS_IMPL_CYCLE_COLLECTING_RELEASE(SessionStorageManager)
+
+SessionStorageManager::SessionStorageManager(
+    RefPtr<BrowsingContext> aBrowsingContext)
+    : mBrowsingContext(aBrowsingContext.forget()) {
   StorageObserver* observer = StorageObserver::Self();
   NS_ASSERTION(
       observer,
       "No StorageObserver, cannot observe private data delete notifications!");
 
   if (observer) {
     observer->AddSink(this);
   }
--- a/dom/storage/SessionStorageManager.h
+++ b/dom/storage/SessionStorageManager.h
@@ -16,22 +16,28 @@ namespace mozilla {
 namespace dom {
 
 class SessionStorageCache;
 class SessionStorageObserver;
 
 class SessionStorageManager final : public nsIDOMSessionStorageManager,
                                     public StorageObserverSink {
  public:
-  SessionStorageManager();
+  explicit SessionStorageManager(RefPtr<BrowsingContext> aBrowsingContext);
 
-  NS_DECL_ISUPPORTS
+  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_NSIDOMSTORAGEMANAGER
   NS_DECL_NSIDOMSESSIONSTORAGEMANAGER
 
+  NS_DECL_CYCLE_COLLECTION_CLASS(SessionStorageManager)
+
+  RefPtr<BrowsingContext> GetBrowsingContext() const {
+    return mBrowsingContext;
+  }
+
  private:
   ~SessionStorageManager();
 
   // StorageObserverSink, handler to various chrome clearing notification
   nsresult Observe(const char* aTopic,
                    const nsAString& aOriginAttributesPattern,
                    const nsACString& aOriginScope) override;
 
@@ -50,14 +56,16 @@ class SessionStorageManager final : publ
                                         SessionStorageCache* aCloneFrom,
                                         RefPtr<SessionStorageCache>* aRetVal);
 
   typedef nsRefPtrHashtable<nsCStringHashKey, SessionStorageCache>
       OriginKeyHashTable;
   nsClassHashtable<nsCStringHashKey, OriginKeyHashTable> mOATable;
 
   RefPtr<SessionStorageObserver> mObserver;
+
+  RefPtr<BrowsingContext> mBrowsingContext;
 };
 
 }  // namespace dom
 }  // namespace mozilla
 
 #endif  // mozilla_dom_SessionStorageManager_h
--- a/layout/build/nsLayoutModule.cpp
+++ b/layout/build/nsLayoutModule.cpp
@@ -236,17 +236,17 @@ nsresult LocalStorageManagerConstructor(
   }
 
   RefPtr<LocalStorageManager> manager = new LocalStorageManager();
   return manager->QueryInterface(aIID, aResult);
 }
 
 nsresult SessionStorageManagerConstructor(nsISupports* aOuter, REFNSIID aIID,
                                           void** aResult) {
-  RefPtr<SessionStorageManager> manager = new SessionStorageManager();
+  RefPtr<SessionStorageManager> manager = new SessionStorageManager(nullptr);
   return manager->QueryInterface(aIID, aResult);
 }
 
 static const mozilla::Module::CategoryEntry kLayoutCategories[] = {
     // clang-format off
   { "clear-origin-attributes-data", "QuotaManagerService", "service," QUOTAMANAGER_SERVICE_CONTRACTID },
     {nullptr}
     // clang-format on