Bug 1438211 P3 Implement WorkerGlobalScope::GetOrCreateServiceWorkerRegistration(). r=asuth
authorBen Kelly <ben@wanderview.com>
Fri, 02 Mar 2018 13:02:49 -0800
changeset 407225 658d8694715a
parent 407224 ed7708d7ee69
child 407226 ee87211590b5
push id33596
push userncsoregi@mozilla.com
push dateFri, 09 Mar 2018 00:18:11 +0000
treeherdermozilla-central@31a33fc61956 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1438211
milestone60.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1438211 P3 Implement WorkerGlobalScope::GetOrCreateServiceWorkerRegistration(). r=asuth
dom/workers/WorkerScope.cpp
dom/workers/WorkerScope.h
--- a/dom/workers/WorkerScope.cpp
+++ b/dom/workers/WorkerScope.cpp
@@ -554,16 +554,38 @@ WorkerGlobalScope::GetClientState() cons
 }
 
 Maybe<ServiceWorkerDescriptor>
 WorkerGlobalScope::GetController() const
 {
   return mWorkerPrivate->GetController();
 }
 
+RefPtr<ServiceWorkerRegistration>
+WorkerGlobalScope::GetOrCreateServiceWorkerRegistration(const ServiceWorkerRegistrationDescriptor& aDescriptor)
+{
+  mWorkerPrivate->AssertIsOnWorkerThread();
+  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::CreateForWorker(mWorkerPrivate, aDescriptor);
+  }
+
+  return ref.forget();
+}
+
 DedicatedWorkerGlobalScope::DedicatedWorkerGlobalScope(WorkerPrivate* aWorkerPrivate,
                                                        const nsString& aName)
   : WorkerGlobalScope(aWorkerPrivate)
   , mName(aName)
 {
 }
 
 bool
--- a/dom/workers/WorkerScope.h
+++ b/dom/workers/WorkerScope.h
@@ -29,17 +29,16 @@ class ClientState;
 class Console;
 class Crypto;
 class Function;
 class IDBFactory;
 enum class ImageBitmapFormat : uint8_t;
 class Performance;
 class Promise;
 class RequestOrUSVString;
-class ServiceWorkerRegistration;
 class WorkerLocation;
 class WorkerNavigator;
 class WorkerPrivate;
 enum class CallerType : uint32_t;
 
 namespace cache {
 
 class CacheStorage;
@@ -230,16 +229,19 @@ public:
   Maybe<ClientInfo>
   GetClientInfo() const override;
 
   Maybe<ClientState>
   GetClientState() const;
 
   Maybe<ServiceWorkerDescriptor>
   GetController() const override;
+
+  RefPtr<mozilla::dom::ServiceWorkerRegistration>
+  GetOrCreateServiceWorkerRegistration(const ServiceWorkerRegistrationDescriptor& aDescriptor) override;
 };
 
 class DedicatedWorkerGlobalScope final : public WorkerGlobalScope
 {
   const nsString mName;
 
   ~DedicatedWorkerGlobalScope() { }