зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1728326 - Add GetRegistrationForAddonPrincipal to nsIServiceWorkerManager. r=asuth
This patch introduces a new getRegistrationForAddonPrincipal to nsIServiceWorkerManager. This method is similar to the existing getRegistrationForPrincipal but: - similarly to registerForAddonPrincipal it only gets the extension principal as its only input parameter. - unlike getRegistrationForPrincipal, it doesn't throw if the registration has not been found (e.g. because it was already unregistered when the method was called). Differential Revision: https://phabricator.services.mozilla.com/D124702
This commit is contained in:
Родитель
60bb3c8c86
Коммит
3455869b8b
|
@ -216,6 +216,14 @@ interface nsIServiceWorkerManager : nsISupports
|
|||
[implicit_jscontext]
|
||||
Promise registerForAddonPrincipal(in nsIPrincipal aPrincipal);
|
||||
|
||||
/**
|
||||
* Get an extension background service worker registration for a
|
||||
* given extension principal, return an nsIServiceWorkerRegistrationInfo
|
||||
* if one exists (or null if no registration has been found).
|
||||
*/
|
||||
void getRegistrationForAddonPrincipal(in nsIPrincipal aPrincipal,
|
||||
[optional, retval] out nsIServiceWorkerRegistrationInfo regInfo);
|
||||
|
||||
/**
|
||||
* Unregister an existing ServiceWorker registration for `aScope`.
|
||||
* It keeps aCallback alive until the operation is concluded.
|
||||
|
|
|
@ -2740,6 +2740,41 @@ ServiceWorkerManager::RegisterForAddonPrincipal(nsIPrincipal* aPrincipal,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ServiceWorkerManager::GetRegistrationForAddonPrincipal(
|
||||
nsIPrincipal* aPrincipal, nsIServiceWorkerRegistrationInfo** aInfo) {
|
||||
MOZ_ASSERT(aPrincipal);
|
||||
|
||||
MOZ_ASSERT(aPrincipal);
|
||||
auto* addonPolicy = BasePrincipal::Cast(aPrincipal)->AddonPolicy();
|
||||
if (!addonPolicy) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsCString scope;
|
||||
auto result = addonPolicy->GetURL(u""_ns);
|
||||
if (result.isOk()) {
|
||||
scope.Assign(NS_ConvertUTF16toUTF8(result.unwrap()));
|
||||
} else {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIURI> scopeURI;
|
||||
nsresult rv = NS_NewURI(getter_AddRefs(scopeURI), scope);
|
||||
if (NS_FAILED(rv)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
RefPtr<ServiceWorkerRegistrationInfo> info =
|
||||
GetServiceWorkerRegistrationInfo(aPrincipal, scopeURI);
|
||||
if (!info) {
|
||||
aInfo = nullptr;
|
||||
return NS_OK;
|
||||
}
|
||||
info.forget(aInfo);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ServiceWorkerManager::GetRegistrationByPrincipal(
|
||||
nsIPrincipal* aPrincipal, const nsAString& aScope,
|
||||
|
|
Загрузка…
Ссылка в новой задаче