Bug 1535913 - Part 2: Hold a keepalive for extension BCGs in WebExtensionPolicy, r=kmag

Differential Revision: https://phabricator.services.mozilla.com/D114889
This commit is contained in:
Nika Layzell
2021-05-19 17:17:35 +00:00
parent 74a720dfe6
commit 1af647666c
4 changed files with 45 additions and 9 deletions

View File

@@ -309,8 +309,9 @@ bool WebExtensionPolicy::Enable() {
}
if (XRE_IsParentProcess()) {
// Reserve a BrowsingContextGroup ID for use by this WebExtensionPolicy.
mBrowsingContextGroupId = nsContentUtils::GenerateBrowsingContextId();
// Reserve a BrowsingContextGroup for use by this WebExtensionPolicy.
RefPtr<BrowsingContextGroup> group = BrowsingContextGroup::Create();
mBrowsingContextGroup = group->MakeKeepAlivePtr();
}
Unused << Proto()->SetSubstitution(MozExtensionHostname(), mBaseURI);
@@ -327,6 +328,12 @@ bool WebExtensionPolicy::Disable() {
return false;
}
if (XRE_IsParentProcess()) {
// Clear our BrowsingContextGroup reference. A new instance will be created
// when the extension is next activated.
mBrowsingContextGroup = nullptr;
}
Unused << Proto()->SetSubstitution(MozExtensionHostname(), nullptr);
mActive = false;
@@ -570,7 +577,7 @@ void WebExtensionPolicy::GetReadyPromise(
uint64_t WebExtensionPolicy::GetBrowsingContextGroupId() const {
MOZ_ASSERT(XRE_IsParentProcess() && mActive);
return mBrowsingContextGroupId;
return mBrowsingContextGroup ? mBrowsingContextGroup->Id() : 0;
}
uint64_t WebExtensionPolicy::GetBrowsingContextGroupId(ErrorResult& aRv) {
@@ -583,11 +590,9 @@ uint64_t WebExtensionPolicy::GetBrowsingContextGroupId(ErrorResult& aRv) {
return 0;
}
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_WEAK_PTR(WebExtensionPolicy, mParent,
mLocalizeCallback,
mHostPermissions,
mWebAccessibleResources,
mContentScripts)
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_WEAK_PTR(
WebExtensionPolicy, mParent, mBrowsingContextGroup, mLocalizeCallback,
mHostPermissions, mWebAccessibleResources, mContentScripts)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WebExtensionPolicy)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY