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
This commit is contained in:
Yaron Tausky 2019-12-10 12:12:32 +00:00
parent 760750c1bd
commit 9f6995fc6e
4 changed files with 24 additions and 7 deletions

View File

@ -679,7 +679,7 @@ bool BrowsingContext::CanAccess(BrowsingContext* aTarget,
RefPtr<SessionStorageManager> BrowsingContext::GetSessionStorageManager() {
RefPtr<SessionStorageManager>& manager = Top()->mSessionStorageManager;
if (!manager) {
manager = new SessionStorageManager();
manager = new SessionStorageManager(this);
}
return manager;
}

View File

@ -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<BrowsingContext> aBrowsingContext)
: mBrowsingContext(aBrowsingContext.forget()) {
StorageObserver* observer = StorageObserver::Self();
NS_ASSERTION(
observer,

View File

@ -21,12 +21,18 @@ 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();
@ -55,6 +61,8 @@ class SessionStorageManager final : public nsIDOMSessionStorageManager,
nsClassHashtable<nsCStringHashKey, OriginKeyHashTable> mOATable;
RefPtr<SessionStorageObserver> mObserver;
RefPtr<BrowsingContext> mBrowsingContext;
};
} // namespace dom

View File

@ -241,7 +241,7 @@ nsresult LocalStorageManagerConstructor(nsISupports* aOuter, REFNSIID aIID,
nsresult SessionStorageManagerConstructor(nsISupports* aOuter, REFNSIID aIID,
void** aResult) {
RefPtr<SessionStorageManager> manager = new SessionStorageManager();
RefPtr<SessionStorageManager> manager = new SessionStorageManager(nullptr);
return manager->QueryInterface(aIID, aResult);
}