Bug 1438211 P2 Implement nsGlobalWindowInner::GetOrCreateServiceWorkerRegistration(). r=asuth

--HG--
extra : rebase_source : 7fa79752d66f9955f574e49e094cdd7fff512306
This commit is contained in:
Ben Kelly 2018-03-02 13:02:49 -08:00
Родитель 0c368d6063
Коммит 9e928c88fb
4 изменённых файлов: 31 добавлений и 0 удалений

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

@ -6435,6 +6435,28 @@ nsGlobalWindowInner::GetOrCreateServiceWorker(const ServiceWorkerDescriptor& aDe
return ref.forget(); return ref.forget();
} }
RefPtr<ServiceWorkerRegistration>
nsGlobalWindowInner::GetOrCreateServiceWorkerRegistration(const ServiceWorkerRegistrationDescriptor& aDescriptor)
{
MOZ_ASSERT(NS_IsMainThread());
RefPtr<ServiceWorkerRegistration> ref;
ForEachEventTargetObject([&] (DOMEventTargetHelper* aTarget, bool* aDoneOut) {
RefPtr<ServiceWorkerRegistration> swr = do_QueryObject(aTarget);
if (!swr || !swr->MatchesDescriptor(aDescriptor)) {
return;
}
ref = swr.forget();
*aDoneOut = true;
});
if (!ref) {
ref = ServiceWorkerRegistration::CreateForMainThread(this, aDescriptor);
}
return ref.forget();
}
nsresult nsresult
nsGlobalWindowInner::FireDelayedDOMEvents() nsGlobalWindowInner::FireDelayedDOMEvents()
{ {

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

@ -356,6 +356,9 @@ public:
virtual RefPtr<mozilla::dom::ServiceWorker> virtual RefPtr<mozilla::dom::ServiceWorker>
GetOrCreateServiceWorker(const mozilla::dom::ServiceWorkerDescriptor& aDescriptor) override; GetOrCreateServiceWorker(const mozilla::dom::ServiceWorkerDescriptor& aDescriptor) override;
RefPtr<mozilla::dom::ServiceWorkerRegistration>
GetOrCreateServiceWorkerRegistration(const mozilla::dom::ServiceWorkerRegistrationDescriptor& aDescriptor) override;
void NoteCalledRegisterForServiceWorkerScope(const nsACString& aScope); void NoteCalledRegisterForServiceWorkerScope(const nsACString& aScope);
virtual nsresult FireDelayedDOMEvents() override; virtual nsresult FireDelayedDOMEvents() override;

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

@ -30,6 +30,7 @@ NS_IMPL_ADDREF_INHERITED(ServiceWorkerRegistration, DOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(ServiceWorkerRegistration, DOMEventTargetHelper) NS_IMPL_RELEASE_INHERITED(ServiceWorkerRegistration, DOMEventTargetHelper)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ServiceWorkerRegistration) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ServiceWorkerRegistration)
NS_INTERFACE_MAP_ENTRY(ServiceWorkerRegistration)
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper) NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
ServiceWorkerRegistration::ServiceWorkerRegistration(nsIGlobalObject* aGlobal, ServiceWorkerRegistration::ServiceWorkerRegistration(nsIGlobalObject* aGlobal,

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

@ -26,6 +26,9 @@ class PushManager;
class WorkerPrivate; class WorkerPrivate;
class ServiceWorker; class ServiceWorker;
#define NS_DOM_SERVICEWORKERREGISTRATION_IID \
{0x4578a90e, 0xa427, 0x4237, {0x98, 0x4a, 0xbd, 0x98, 0xe4, 0xcd, 0x5f, 0x3a}}
class ServiceWorkerRegistration final : public DOMEventTargetHelper class ServiceWorkerRegistration final : public DOMEventTargetHelper
{ {
public: public:
@ -60,6 +63,7 @@ public:
GetPushManager(JSContext* aCx, ErrorResult& aRv) = 0; GetPushManager(JSContext* aCx, ErrorResult& aRv) = 0;
}; };
NS_DECLARE_STATIC_IID_ACCESSOR(NS_DOM_SERVICEWORKERREGISTRATION_IID)
NS_DECL_ISUPPORTS_INHERITED NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ServiceWorkerRegistration, DOMEventTargetHelper) NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ServiceWorkerRegistration, DOMEventTargetHelper)
@ -133,6 +137,7 @@ private:
RefPtr<PushManager> mPushManager; RefPtr<PushManager> mPushManager;
}; };
NS_DEFINE_STATIC_IID_ACCESSOR(ServiceWorkerRegistration, NS_DOM_SERVICEWORKERREGISTRATION_IID)
} // namespace dom } // namespace dom
} // namespace mozilla } // namespace mozilla