From 9f6995fc6ebe8e0dba547432186b066ca40e791a Mon Sep 17 00:00:00 2001 From: Yaron Tausky Date: Tue, 10 Dec 2019 12:12:32 +0000 Subject: [PATCH] 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 --HG-- extra : moz-landing-system : lando --- docshell/base/BrowsingContext.cpp | 2 +- dom/storage/SessionStorageManager.cpp | 15 ++++++++++++--- dom/storage/SessionStorageManager.h | 12 ++++++++++-- layout/build/nsLayoutModule.cpp | 2 +- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/docshell/base/BrowsingContext.cpp b/docshell/base/BrowsingContext.cpp index b84f96d2c08a..fc9385113937 100644 --- a/docshell/base/BrowsingContext.cpp +++ b/docshell/base/BrowsingContext.cpp @@ -679,7 +679,7 @@ bool BrowsingContext::CanAccess(BrowsingContext* aTarget, RefPtr BrowsingContext::GetSessionStorageManager() { RefPtr& manager = Top()->mSessionStorageManager; if (!manager) { - manager = new SessionStorageManager(); + manager = new SessionStorageManager(this); } return manager; } diff --git a/dom/storage/SessionStorageManager.cpp b/dom/storage/SessionStorageManager.cpp index c31a93407a35..4e03eb880508 100644 --- a/dom/storage/SessionStorageManager.cpp +++ b/dom/storage/SessionStorageManager.cpp @@ -17,10 +17,19 @@ 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 aBrowsingContext) + : mBrowsingContext(aBrowsingContext.forget()) { StorageObserver* observer = StorageObserver::Self(); NS_ASSERTION( observer, diff --git a/dom/storage/SessionStorageManager.h b/dom/storage/SessionStorageManager.h index 6eb27bbf24e0..b53ed015c5c5 100644 --- a/dom/storage/SessionStorageManager.h +++ b/dom/storage/SessionStorageManager.h @@ -21,12 +21,18 @@ class SessionStorageObserver; class SessionStorageManager final : public nsIDOMSessionStorageManager, public StorageObserverSink { public: - SessionStorageManager(); + explicit SessionStorageManager(RefPtr aBrowsingContext); - NS_DECL_ISUPPORTS + NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_NSIDOMSTORAGEMANAGER NS_DECL_NSIDOMSESSIONSTORAGEMANAGER + NS_DECL_CYCLE_COLLECTION_CLASS(SessionStorageManager) + + RefPtr GetBrowsingContext() const { + return mBrowsingContext; + } + private: ~SessionStorageManager(); @@ -55,6 +61,8 @@ class SessionStorageManager final : public nsIDOMSessionStorageManager, nsClassHashtable mOATable; RefPtr mObserver; + + RefPtr mBrowsingContext; }; } // namespace dom diff --git a/layout/build/nsLayoutModule.cpp b/layout/build/nsLayoutModule.cpp index 55f6f99e6471..d4ed4eb92020 100644 --- a/layout/build/nsLayoutModule.cpp +++ b/layout/build/nsLayoutModule.cpp @@ -241,7 +241,7 @@ nsresult LocalStorageManagerConstructor(nsISupports* aOuter, REFNSIID aIID, nsresult SessionStorageManagerConstructor(nsISupports* aOuter, REFNSIID aIID, void** aResult) { - RefPtr manager = new SessionStorageManager(); + RefPtr manager = new SessionStorageManager(nullptr); return manager->QueryInterface(aIID, aResult); }