Bug 1794657 - Part 2: Remove the main-thread-only host map from ExtensionPolicyService, r=kmag

We're still holding strong references to the WebExtensionPolicy objects through
the `mExtensions` map, so we don't need to worry about the policy instances
dying earlier after this change.

Differential Revision: https://phabricator.services.mozilla.com/D159087
This commit is contained in:
Nika Layzell 2022-10-14 14:20:35 +00:00
Родитель ef09e660f9
Коммит 4a8b70385d
2 изменённых файлов: 9 добавлений и 11 удалений

Просмотреть файл

@ -155,6 +155,13 @@ WebExtensionPolicy* ExtensionPolicyService::GetByURL(const URLInfo& aURL) {
return nullptr;
}
WebExtensionPolicy* ExtensionPolicyService::GetByHost(
const nsACString& aHost) const {
AssertIsOnMainThread();
RefPtr<WebExtensionPolicyCore> core = GetCoreByHost(aHost);
return core ? core->GetMainThreadPolicy() : nullptr;
}
void ExtensionPolicyService::GetAll(
nsTArray<RefPtr<WebExtensionPolicy>>& aResult) {
AppendToArray(aResult, mExtensions.Values());
@ -170,8 +177,6 @@ bool ExtensionPolicyService::RegisterExtension(WebExtensionPolicy& aPolicy) {
}
mExtensions.InsertOrUpdate(aPolicy.Id(), RefPtr{&aPolicy});
mExtensionHosts.InsertOrUpdate(aPolicy.MozExtensionHostname(),
RefPtr{&aPolicy});
{
StaticAutoWriteLock lock(sCoreByHostLock);
@ -190,7 +195,6 @@ bool ExtensionPolicyService::UnregisterExtension(WebExtensionPolicy& aPolicy) {
}
mExtensions.Remove(aPolicy.Id());
mExtensionHosts.Remove(aPolicy.MozExtensionHostname());
{
StaticAutoWriteLock lock(sCoreByHostLock);
@ -665,8 +669,7 @@ nsresult ExtensionPolicyService::ExtensionURIToAddonId(nsIURI* aURI,
return NS_OK;
}
NS_IMPL_CYCLE_COLLECTION(ExtensionPolicyService, mExtensions, mExtensionHosts,
mObservers)
NS_IMPL_CYCLE_COLLECTION(ExtensionPolicyService, mExtensions, mObservers)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ExtensionPolicyService)
NS_INTERFACE_MAP_ENTRY(nsIAddonPolicyService)

Просмотреть файл

@ -77,11 +77,7 @@ class ExtensionPolicyService final : public nsIAddonPolicyService,
WebExtensionPolicy* GetByURL(const extensions::URLInfo& aURL);
WebExtensionPolicy* GetByHost(const nsACString& aHost) const {
nsAutoCString host;
ToLowerCase(aHost, host);
return mExtensionHosts.GetWeak(host);
}
WebExtensionPolicy* GetByHost(const nsACString& aHost) const;
void GetAll(nsTArray<RefPtr<WebExtensionPolicy>>& aResult);
@ -119,7 +115,6 @@ class ExtensionPolicyService final : public nsIAddonPolicyService,
const nsTArray<RefPtr<extensions::WebExtensionContentScript>>& aScripts);
nsRefPtrHashtable<nsPtrHashKey<const nsAtom>, WebExtensionPolicy> mExtensions;
nsRefPtrHashtable<nsCStringHashKey, WebExtensionPolicy> mExtensionHosts;
nsRefPtrHashtable<nsPtrHashKey<const extensions::DocumentObserver>,
extensions::DocumentObserver>