Skip to content

Commit

Permalink
Bug 1593246 - Part 2: Give SessionStorageManager a reference to Brows…
Browse files Browse the repository at this point in the history
…ingContext 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
  • Loading branch information
ytausky committed Dec 10, 2019
1 parent c422dbf commit 2eedf23
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docshell/base/BrowsingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
17 changes: 13 additions & 4 deletions dom/storage/SessionStorageManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,19 @@ namespace dom {

using namespace StorageUtils;

NS_IMPL_ISUPPORTS(SessionStorageManager, nsIDOMStorageManager,
nsIDOMSessionStorageManager)

SessionStorageManager::SessionStorageManager() {
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

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,
Expand Down
12 changes: 10 additions & 2 deletions dom/storage/SessionStorageManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -55,6 +61,8 @@ class SessionStorageManager final : public nsIDOMSessionStorageManager,
nsClassHashtable<nsCStringHashKey, OriginKeyHashTable> mOATable;

RefPtr<SessionStorageObserver> mObserver;

RefPtr<BrowsingContext> mBrowsingContext;
};

} // namespace dom
Expand Down
2 changes: 1 addition & 1 deletion layout/build/nsLayoutModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 2eedf23

Please sign in to comment.