Bug 1462772 P1 Add a fallible nsIGlobalObject::GetServiceWorkerRegistration() method. r=mrbkap

This commit is contained in:
Ben Kelly 2018-07-02 07:44:18 -07:00
Родитель 1dad6a26ea
Коммит 083c06c238
6 изменённых файлов: 36 добавлений и 6 удалений

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

@ -6411,8 +6411,8 @@ nsGlobalWindowInner::GetOrCreateServiceWorker(const ServiceWorkerDescriptor& aDe
return ref.forget();
}
RefPtr<ServiceWorkerRegistration>
nsGlobalWindowInner::GetOrCreateServiceWorkerRegistration(const ServiceWorkerRegistrationDescriptor& aDescriptor)
RefPtr<mozilla::dom::ServiceWorkerRegistration>
nsGlobalWindowInner::GetServiceWorkerRegistration(const mozilla::dom::ServiceWorkerRegistrationDescriptor& aDescriptor) const
{
MOZ_ASSERT(NS_IsMainThread());
RefPtr<ServiceWorkerRegistration> ref;
@ -6425,11 +6425,17 @@ nsGlobalWindowInner::GetOrCreateServiceWorkerRegistration(const ServiceWorkerReg
ref = swr.forget();
*aDoneOut = true;
});
return ref.forget();
}
RefPtr<ServiceWorkerRegistration>
nsGlobalWindowInner::GetOrCreateServiceWorkerRegistration(const ServiceWorkerRegistrationDescriptor& aDescriptor)
{
MOZ_ASSERT(NS_IsMainThread());
RefPtr<ServiceWorkerRegistration> ref = GetServiceWorkerRegistration(aDescriptor);
if (!ref) {
ref = ServiceWorkerRegistration::CreateForMainThread(this, aDescriptor);
}
return ref.forget();
}

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

@ -360,6 +360,9 @@ public:
virtual RefPtr<mozilla::dom::ServiceWorker>
GetOrCreateServiceWorker(const mozilla::dom::ServiceWorkerDescriptor& aDescriptor) override;
RefPtr<mozilla::dom::ServiceWorkerRegistration>
GetServiceWorkerRegistration(const mozilla::dom::ServiceWorkerRegistrationDescriptor& aDescriptor) const override;
RefPtr<mozilla::dom::ServiceWorkerRegistration>
GetOrCreateServiceWorkerRegistration(const mozilla::dom::ServiceWorkerRegistrationDescriptor& aDescriptor) override;

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

@ -207,6 +207,13 @@ nsIGlobalObject::GetOrCreateServiceWorker(const ServiceWorkerDescriptor& aDescri
return nullptr;
}
RefPtr<ServiceWorkerRegistration>
nsIGlobalObject::GetServiceWorkerRegistration(const mozilla::dom::ServiceWorkerRegistrationDescriptor& aDescriptor) const
{
MOZ_DIAGNOSTIC_ASSERT(false, "this global should not have any service workers");
return nullptr;
}
RefPtr<ServiceWorkerRegistration>
nsIGlobalObject::GetOrCreateServiceWorkerRegistration(const ServiceWorkerRegistrationDescriptor& aDescriptor)
{

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

@ -120,6 +120,11 @@ public:
virtual RefPtr<mozilla::dom::ServiceWorker>
GetOrCreateServiceWorker(const mozilla::dom::ServiceWorkerDescriptor& aDescriptor);
// Get the DOM object for the given descriptor or return nullptr if it does
// not exist.
virtual RefPtr<mozilla::dom::ServiceWorkerRegistration>
GetServiceWorkerRegistration(const mozilla::dom::ServiceWorkerRegistrationDescriptor& aDescriptor) const;
// Get the DOM object for the given descriptor or attempt to create one.
// Creation can still fail and return nullptr during shutdown, etc.
virtual RefPtr<mozilla::dom::ServiceWorkerRegistration>

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

@ -557,8 +557,8 @@ WorkerGlobalScope::GetController() const
return mWorkerPrivate->GetController();
}
RefPtr<ServiceWorkerRegistration>
WorkerGlobalScope::GetOrCreateServiceWorkerRegistration(const ServiceWorkerRegistrationDescriptor& aDescriptor)
RefPtr<mozilla::dom::ServiceWorkerRegistration>
WorkerGlobalScope::GetServiceWorkerRegistration(const ServiceWorkerRegistrationDescriptor& aDescriptor) const
{
mWorkerPrivate->AssertIsOnWorkerThread();
RefPtr<ServiceWorkerRegistration> ref;
@ -571,12 +571,18 @@ WorkerGlobalScope::GetOrCreateServiceWorkerRegistration(const ServiceWorkerRegis
ref = swr.forget();
*aDoneOut = true;
});
return ref.forget();
}
RefPtr<ServiceWorkerRegistration>
WorkerGlobalScope::GetOrCreateServiceWorkerRegistration(const ServiceWorkerRegistrationDescriptor& aDescriptor)
{
mWorkerPrivate->AssertIsOnWorkerThread();
RefPtr<ServiceWorkerRegistration> ref = GetServiceWorkerRegistration(aDescriptor);
if (!ref) {
ref = ServiceWorkerRegistration::CreateForWorker(mWorkerPrivate, this,
aDescriptor);
}
return ref.forget();
}

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

@ -239,6 +239,9 @@ public:
Maybe<ServiceWorkerDescriptor>
GetController() const override;
RefPtr<mozilla::dom::ServiceWorkerRegistration>
GetServiceWorkerRegistration(const ServiceWorkerRegistrationDescriptor& aDescriptor) const override;
RefPtr<mozilla::dom::ServiceWorkerRegistration>
GetOrCreateServiceWorkerRegistration(const ServiceWorkerRegistrationDescriptor& aDescriptor) override;
};