From 9e928c88fbf48734d43b091e59dd557300720cc1 Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Fri, 2 Mar 2018 13:02:49 -0800 Subject: [PATCH] Bug 1438211 P2 Implement nsGlobalWindowInner::GetOrCreateServiceWorkerRegistration(). r=asuth --HG-- extra : rebase_source : 7fa79752d66f9955f574e49e094cdd7fff512306 --- dom/base/nsGlobalWindowInner.cpp | 22 +++++++++++++++++++ dom/base/nsGlobalWindowInner.h | 3 +++ .../ServiceWorkerRegistration.cpp | 1 + .../ServiceWorkerRegistration.h | 5 +++++ 4 files changed, 31 insertions(+) diff --git a/dom/base/nsGlobalWindowInner.cpp b/dom/base/nsGlobalWindowInner.cpp index 6fd687f6a802..2e43cb89daf1 100644 --- a/dom/base/nsGlobalWindowInner.cpp +++ b/dom/base/nsGlobalWindowInner.cpp @@ -6435,6 +6435,28 @@ nsGlobalWindowInner::GetOrCreateServiceWorker(const ServiceWorkerDescriptor& aDe return ref.forget(); } +RefPtr +nsGlobalWindowInner::GetOrCreateServiceWorkerRegistration(const ServiceWorkerRegistrationDescriptor& aDescriptor) +{ + MOZ_ASSERT(NS_IsMainThread()); + RefPtr ref; + ForEachEventTargetObject([&] (DOMEventTargetHelper* aTarget, bool* aDoneOut) { + RefPtr 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 nsGlobalWindowInner::FireDelayedDOMEvents() { diff --git a/dom/base/nsGlobalWindowInner.h b/dom/base/nsGlobalWindowInner.h index 476b9f2eec6d..9c53e35a68df 100644 --- a/dom/base/nsGlobalWindowInner.h +++ b/dom/base/nsGlobalWindowInner.h @@ -356,6 +356,9 @@ public: virtual RefPtr GetOrCreateServiceWorker(const mozilla::dom::ServiceWorkerDescriptor& aDescriptor) override; + RefPtr + GetOrCreateServiceWorkerRegistration(const mozilla::dom::ServiceWorkerRegistrationDescriptor& aDescriptor) override; + void NoteCalledRegisterForServiceWorkerScope(const nsACString& aScope); virtual nsresult FireDelayedDOMEvents() override; diff --git a/dom/serviceworkers/ServiceWorkerRegistration.cpp b/dom/serviceworkers/ServiceWorkerRegistration.cpp index 5bf80da097ec..2ca8bf0a717a 100644 --- a/dom/serviceworkers/ServiceWorkerRegistration.cpp +++ b/dom/serviceworkers/ServiceWorkerRegistration.cpp @@ -30,6 +30,7 @@ NS_IMPL_ADDREF_INHERITED(ServiceWorkerRegistration, DOMEventTargetHelper) NS_IMPL_RELEASE_INHERITED(ServiceWorkerRegistration, DOMEventTargetHelper) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ServiceWorkerRegistration) + NS_INTERFACE_MAP_ENTRY(ServiceWorkerRegistration) NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper) ServiceWorkerRegistration::ServiceWorkerRegistration(nsIGlobalObject* aGlobal, diff --git a/dom/serviceworkers/ServiceWorkerRegistration.h b/dom/serviceworkers/ServiceWorkerRegistration.h index 2dd1497ef261..81fc2ce6b258 100644 --- a/dom/serviceworkers/ServiceWorkerRegistration.h +++ b/dom/serviceworkers/ServiceWorkerRegistration.h @@ -26,6 +26,9 @@ class PushManager; class WorkerPrivate; class ServiceWorker; +#define NS_DOM_SERVICEWORKERREGISTRATION_IID \ + {0x4578a90e, 0xa427, 0x4237, {0x98, 0x4a, 0xbd, 0x98, 0xe4, 0xcd, 0x5f, 0x3a}} + class ServiceWorkerRegistration final : public DOMEventTargetHelper { public: @@ -60,6 +63,7 @@ public: GetPushManager(JSContext* aCx, ErrorResult& aRv) = 0; }; + NS_DECLARE_STATIC_IID_ACCESSOR(NS_DOM_SERVICEWORKERREGISTRATION_IID) NS_DECL_ISUPPORTS_INHERITED NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ServiceWorkerRegistration, DOMEventTargetHelper) @@ -133,6 +137,7 @@ private: RefPtr mPushManager; }; +NS_DEFINE_STATIC_IID_ACCESSOR(ServiceWorkerRegistration, NS_DOM_SERVICEWORKERREGISTRATION_IID) } // namespace dom } // namespace mozilla