FINISHED
authorNikhil Marathe <nsm.nikhil@gmail.com>
Fri, 11 Jul 2014 17:18:16 -0700
changeset 1102 2ea513e98ab245d479e6b4a2bf6a6e3fbe85b8b8
parent 1101 8f8677c1e4ca608292c4ea5d6716a1535ea58c3c
child 1103 3e505e3ac2b279fcc039bb9080b42115e9e43c32
push id32
push usernsm.nikhil@gmail.com
push dateThu, 24 Jul 2014 00:32:46 +0000
FINISHED qparent: 2b2cb0c672dd qtip: 2b2cb0c672dd top: (none)
1002570-swc-props
series
deleted file mode 100644
--- a/1002570-swc-props
+++ /dev/null
@@ -1,791 +0,0 @@
-# HG changeset patch
-# Parent f0b558b859334b547dc622e822e4253c9ec8da10
-# User Nikhil Marathe <nsm.nikhil@gmail.com>
-Bug 1002570 - Return valid ServiceWorker instances for .installing, .waiting and .active. r=ehsan
-
-diff --git a/dom/interfaces/base/nsIServiceWorkerManager.idl b/dom/interfaces/base/nsIServiceWorkerManager.idl
---- a/dom/interfaces/base/nsIServiceWorkerManager.idl
-+++ b/dom/interfaces/base/nsIServiceWorkerManager.idl
-@@ -3,31 +3,37 @@
-  * License, v. 2.0. If a copy of the MPL was not distributed with this
-  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
- 
- #include "domstubs.idl"
- 
- interface nsIDocument;
- interface nsIURI;
- 
--[uuid(6117cdf1-cb10-42a3-9901-4f1bab7ffa4d)]
-+[uuid(cc539f1e-1ce6-4af5-bf94-195b30bde010)]
- interface nsIServiceWorkerManager : nsISupports
- {
-   // Returns a Promise
-   nsISupports register(in nsIDOMWindow aWindow, in DOMString aScope, in DOMString aScriptURI);
- 
-   // Returns a Promise
-   nsISupports unregister(in nsIDOMWindow aWindow, in DOMString aScope);
- 
-   // aTarget MUST be a ServiceWorkerContainer.
-   [noscript] void AddContainerEventListener(in nsIURI aPageURI, in nsIDOMEventTarget aTarget);
-   [noscript] void RemoveContainerEventListener(in nsIURI aPageURI, in nsIDOMEventTarget aTarget);
- 
-   [noscript] void MaybeStartControlling(in nsIDocument aDoc);
-   [noscript] void MaybeStopControlling(in nsIDocument aDoc);
- 
-+  // Returns a ServiceWorker
-+  [noscript] nsISupports GetInstalling(in nsIDOMWindow aWindow);
-+  [noscript] nsISupports GetWaiting(in nsIDOMWindow aWindow);
-+  [noscript] nsISupports GetActive(in nsIDOMWindow aWindow);
-+  [noscript] nsISupports GetDocumentController(in nsIDOMWindow aWindow);
-+
-   // Testing
-   DOMString getScopeForUrl(in DOMString path);
- };
- 
- %{ C++
- #define SERVICEWORKERMANAGER_CONTRACTID "@mozilla.org/serviceworkers/manager;1"
- %}
-diff --git a/dom/workers/ServiceWorkerContainer.cpp b/dom/workers/ServiceWorkerContainer.cpp
---- a/dom/workers/ServiceWorkerContainer.cpp
-+++ b/dom/workers/ServiceWorkerContainer.cpp
-@@ -12,28 +12,43 @@
- 
- #include "nsCycleCollectionParticipant.h"
- #include "nsServiceManagerUtils.h"
- 
- #include "mozilla/dom/Promise.h"
- #include "mozilla/dom/ServiceWorkerContainerBinding.h"
- #include "mozilla/dom/workers/bindings/ServiceWorker.h"
- 
-+#include "ServiceWorker.h"
-+#include "ServiceWorkerManager.h"
-+
- namespace mozilla {
- namespace dom {
- namespace workers {
- 
- NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ServiceWorkerContainer)
- NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
- 
- NS_IMPL_ADDREF_INHERITED(ServiceWorkerContainer, DOMEventTargetHelper)
- NS_IMPL_RELEASE_INHERITED(ServiceWorkerContainer, DOMEventTargetHelper)
- 
- NS_IMPL_CYCLE_COLLECTION_INHERITED(ServiceWorkerContainer, DOMEventTargetHelper, mWindow)
- 
-+ServiceWorkerContainer::ServiceWorkerContainer(nsPIDOMWindow* aWindow)
-+  : mWindow(aWindow)
-+{
-+  SetIsDOMBinding();
-+  StartListeningForEvents();
-+}
-+
-+ServiceWorkerContainer::~ServiceWorkerContainer()
-+{
-+  StopListeningForEvents();
-+}
-+
- JSObject*
- ServiceWorkerContainer::WrapObject(JSContext* aCx)
- {
-   return ServiceWorkerContainerBinding::Wrap(aCx, this);
- }
- 
- already_AddRefed<Promise>
- ServiceWorkerContainer::Register(const nsAString& aScriptURL,
-@@ -80,39 +95,67 @@ ServiceWorkerContainer::Unregister(const
-   nsRefPtr<Promise> ret = static_cast<Promise*>(promise.get());
-   MOZ_ASSERT(ret);
-   return ret.forget();
- }
- 
- already_AddRefed<workers::ServiceWorker>
- ServiceWorkerContainer::GetInstalling()
- {
--  // FIXME(nsm): Bug 1002570
--  return nullptr;
-+  if (!mInstallingWorker) {
-+    mInstallingWorker = GetWorkerReference(INSTALLING_WORKER);
-+  }
-+
-+  nsRefPtr<ServiceWorker> ret = mInstallingWorker;
-+  return ret.forget();
- }
- 
- already_AddRefed<workers::ServiceWorker>
- ServiceWorkerContainer::GetWaiting()
- {
--  // FIXME(nsm): Bug 1002570
--  return nullptr;
-+  if (!mWaitingWorker) {
-+    mWaitingWorker = GetWorkerReference(WAITING_WORKER);
-+  }
-+
-+  nsRefPtr<ServiceWorker> ret = mWaitingWorker;
-+  return ret.forget();
- }
- 
- already_AddRefed<workers::ServiceWorker>
- ServiceWorkerContainer::GetActive()
- {
--  // FIXME(nsm): Bug 1002570
--  return nullptr;
-+  if (!mActiveWorker) {
-+    mActiveWorker = GetWorkerReference(ACTIVE_WORKER);
-+  }
-+
-+  nsRefPtr<ServiceWorker> ret = mActiveWorker;
-+  return ret.forget();
- }
- 
- already_AddRefed<workers::ServiceWorker>
- ServiceWorkerContainer::GetController()
- {
--  // FIXME(nsm): Bug 1002570
--  return nullptr;
-+  if (!mControllerWorker) {
-+    nsresult rv;
-+    nsCOMPtr<nsIServiceWorkerManager> swm = do_GetService(SERVICEWORKERMANAGER_CONTRACTID, &rv);
-+    if (NS_WARN_IF(NS_FAILED(rv))) {
-+      return nullptr;
-+    }
-+
-+    nsCOMPtr<nsISupports> serviceWorker;
-+    rv = swm->GetDocumentController(mWindow, getter_AddRefs(serviceWorker));
-+    if (NS_WARN_IF(NS_FAILED(rv))) {
-+      return nullptr;
-+    }
-+
-+    mControllerWorker = static_cast<ServiceWorker*>(serviceWorker.get());
-+  }
-+
-+  nsRefPtr<ServiceWorker> ref = mControllerWorker;
-+  return ref.forget();
- }
- 
- already_AddRefed<Promise>
- ServiceWorkerContainer::GetAll(ErrorResult& aRv)
- {
-   // FIXME(nsm): Bug 1002571
-   aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
-   return nullptr;
-@@ -142,16 +185,64 @@ void
- ServiceWorkerContainer::StopListeningForEvents()
- {
-   nsCOMPtr<nsIServiceWorkerManager> swm = do_GetService(SERVICEWORKERMANAGER_CONTRACTID);
-   if (swm) {
-     swm->RemoveContainerEventListener(mWindow->GetDocumentURI(), this);
-   }
- }
- 
-+void
-+ServiceWorkerContainer::InvalidateWorkerReference(uint32_t aWhichOnes)
-+{
-+  if (aWhichOnes & INSTALLING_WORKER) {
-+    mInstallingWorker = nullptr;
-+  }
-+
-+  if (aWhichOnes & WAITING_WORKER) {
-+    mWaitingWorker = nullptr;
-+  }
-+
-+  if (aWhichOnes & ACTIVE_WORKER) {
-+    mActiveWorker = nullptr;
-+  }
-+}
-+
-+already_AddRefed<workers::ServiceWorker>
-+ServiceWorkerContainer::GetWorkerReference(uint32_t aWhichOne)
-+{
-+  nsresult rv;
-+  nsCOMPtr<nsIServiceWorkerManager> swm = do_GetService(SERVICEWORKERMANAGER_CONTRACTID, &rv);
-+  if (NS_WARN_IF(NS_FAILED(rv))) {
-+    return nullptr;
-+  }
-+
-+  nsCOMPtr<nsISupports> serviceWorker;
-+  switch(aWhichOne) {
-+    case INSTALLING_WORKER:
-+      rv = swm->GetInstalling(mWindow, getter_AddRefs(serviceWorker));
-+      break;
-+    case WAITING_WORKER:
-+      rv = swm->GetWaiting(mWindow, getter_AddRefs(serviceWorker));
-+      break;
-+    case ACTIVE_WORKER:
-+      rv = swm->GetActive(mWindow, getter_AddRefs(serviceWorker));
-+      break;
-+    default:
-+      MOZ_CRASH("Invalid enum value");
-+  }
-+
-+  if (NS_WARN_IF(NS_FAILED(rv))) {
-+    return nullptr;
-+  }
-+
-+  nsRefPtr<ServiceWorker> ref = static_cast<ServiceWorker*>(serviceWorker.get());
-+  return ref.forget();
-+}
-+
- // Testing only.
- already_AddRefed<Promise>
- ServiceWorkerContainer::ClearAllServiceWorkerData(ErrorResult& aRv)
- {
-   aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
-   return nullptr;
- }
- 
-diff --git a/dom/workers/ServiceWorkerContainer.h b/dom/workers/ServiceWorkerContainer.h
---- a/dom/workers/ServiceWorkerContainer.h
-+++ b/dom/workers/ServiceWorkerContainer.h
-@@ -28,22 +28,17 @@ public:
-   NS_DECL_ISUPPORTS_INHERITED
-   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ServiceWorkerContainer, DOMEventTargetHelper)
- 
-   IMPL_EVENT_HANDLER(updatefound)
-   IMPL_EVENT_HANDLER(controllerchange)
-   IMPL_EVENT_HANDLER(reloadpage)
-   IMPL_EVENT_HANDLER(error)
- 
--  explicit ServiceWorkerContainer(nsPIDOMWindow* aWindow)
--    : mWindow(aWindow)
--  {
--    SetIsDOMBinding();
--    StartListeningForEvents();
--  }
-+  explicit ServiceWorkerContainer(nsPIDOMWindow* aWindow);
- 
-   nsPIDOMWindow*
-   GetParentObject() const
-   {
-     return mWindow;
-   }
- 
-   JSObject*
-@@ -76,41 +71,56 @@ public:
-   Ready();
- 
-   nsIURI*
-   GetDocumentURI() const
-   {
-     return mWindow->GetDocumentURI();
-   }
- 
-+  void
-+  InvalidateWorkerReference(uint32_t aWhichOnes);
-+
-+  already_AddRefed<workers::ServiceWorker>
-+  GetWorkerReference(uint32_t aWhichOne);
-+
-   // Testing only.
-   already_AddRefed<Promise>
-   ClearAllServiceWorkerData(ErrorResult& aRv);
- 
-   // Testing only.
-   void
-   GetScopeForUrl(const nsAString& aUrl, nsString& aScope, ErrorResult& aRv);
- 
-   // Testing only.
-   void
-   GetControllingWorkerScriptURLForPath(const nsAString& aPath,
-                                        nsString& aScriptURL,
-                                        ErrorResult& aRv);
- private:
--  ~ServiceWorkerContainer()
--  {
--    StopListeningForEvents();
--  }
-+  ~ServiceWorkerContainer();
- 
-   void
-   StartListeningForEvents();
- 
-   void
-   StopListeningForEvents();
- 
-   nsCOMPtr<nsPIDOMWindow> mWindow;
-+
-+  // The following properties are cached here to ensure JS equality is satisfied
-+  // instead of acquiring a new worker instance from the ServiceWorkerManager
-+  // for every access. A null value is considered a cache miss.
-+  // These three may change to a new worker at any time.
-+  nsRefPtr<ServiceWorker> mInstallingWorker;
-+  nsRefPtr<ServiceWorker> mWaitingWorker;
-+  nsRefPtr<ServiceWorker> mActiveWorker;
-+  // This only changes when a worker hijacks everything in its scope by calling
-+  // replace().
-+  // FIXME(nsm): Bug 982711. Provide API to let SWM invalidate this.
-+  nsRefPtr<ServiceWorker> mControllerWorker;
- };
- 
- } // namespace workers
- } // namespace dom
- } // namespace mozilla
- 
- #endif /* mozilla_dom_workers_serviceworkercontainer_h__ */
-diff --git a/dom/workers/ServiceWorkerManager.cpp b/dom/workers/ServiceWorkerManager.cpp
---- a/dom/workers/ServiceWorkerManager.cpp
-+++ b/dom/workers/ServiceWorkerManager.cpp
-@@ -563,16 +563,17 @@ ServiceWorkerManager::Update(ServiceWork
-   if (aRegistration->mInstallingWorker) {
-     // FIXME(nsm): Terminate the worker. We still haven't figured out worker
-     // instance ownership when not associated with a window, so let's wait on
-     // this.
-     // FIXME(nsm): We should be setting the state on the actual worker
-     // instance.
-     // FIXME(nsm): Fire "statechange" on installing worker instance.
-     aRegistration->mInstallingWorker = nullptr;
-+    InvalidateServiceWorkerContainerWorker(aRegistration, INSTALLING_WORKER);
-   }
- 
-   aRegistration->mUpdatePromise = new UpdatePromise();
-   // FIXME(nsm): Bug 931249. If we don't need to fetch & install, resolve
-   // promise and skip this.
-   // FIXME(nsm): Bug 931249. Force cache update if > 1 day.
- 
-   aRegistration->mUpdateInstance =
-@@ -770,16 +771,18 @@ public:
- 
-   NS_IMETHOD
-   Run() MOZ_OVERRIDE
-   {
-     AssertIsOnMainThread();
-     // FIXME(nsm): Change installing worker state to redundant.
-     // FIXME(nsm): Fire statechange.
-     mRegistration->mInstallingWorker = nullptr;
-+    nsRefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
-+    swm->InvalidateServiceWorkerContainerWorker(mRegistration, INSTALLING_WORKER);
-     return NS_OK;
-   }
- };
- 
- /*
-  * Used to handle InstallEvent::waitUntil() and proceed with installation.
-  */
- class FinishInstallHandler MOZ_FINAL : public PromiseNativeHandler
-@@ -991,28 +994,30 @@ private:
- };
- 
- void
- ServiceWorkerManager::Install(ServiceWorkerRegistration* aRegistration,
-                               ServiceWorkerInfo* aServiceWorkerInfo)
- {
-   AssertIsOnMainThread();
-   aRegistration->mInstallingWorker = aServiceWorkerInfo;
-+  InvalidateServiceWorkerContainerWorker(aRegistration, INSTALLING_WORKER);
- 
-   nsMainThreadPtrHandle<ServiceWorkerRegistration> handle =
-     new nsMainThreadPtrHolder<ServiceWorkerRegistration>(aRegistration);
- 
-   nsRefPtr<ServiceWorker> serviceWorker;
-   nsresult rv =
-     CreateServiceWorker(aServiceWorkerInfo->GetScriptSpec(),
-                         aRegistration->mScope,
-                         getter_AddRefs(serviceWorker));
- 
-   if (NS_WARN_IF(NS_FAILED(rv))) {
-     aRegistration->mInstallingWorker = nullptr;
-+    // We don't need to invalidate here since the upper one will have done it.
-     return;
-   }
- 
-   nsRefPtr<InstallEventRunnable> r =
-     new InstallEventRunnable(serviceWorker->GetWorkerPrivate(), handle);
- 
-   AutoSafeJSContext cx;
-   r->Dispatch(cx);
-@@ -1046,22 +1051,23 @@ public:
- 
-   NS_IMETHODIMP
-   Run() MOZ_OVERRIDE
-   {
-     if (mRegistration->mCurrentWorker) {
-       // FIXME(nsm). Steps 3.1-3.4 of the algorithm.
-     }
- 
-+    nsRefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
-+
-     mRegistration->mCurrentWorker = mRegistration->mWaitingWorker.forget();
-+    swm->InvalidateServiceWorkerContainerWorker(mRegistration, ACTIVE_WORKER | WAITING_WORKER);
- 
-     // FIXME(nsm): Steps 7 of the algorithm.
- 
--    nsRefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
--
-     swm->FireEventOnServiceWorkerContainers(mRegistration,
-                                             NS_LITERAL_STRING("controllerchange"));
- 
-     nsRefPtr<ServiceWorker> serviceWorker;
-     nsresult rv =
-       swm->CreateServiceWorker(mRegistration->mCurrentWorker->GetScriptSpec(),
-                                mRegistration->mScope,
-                                getter_AddRefs(serviceWorker));
-@@ -1089,16 +1095,17 @@ ServiceWorkerManager::FinishInstall(Serv
- {
-   AssertIsOnMainThread();
- 
-   if (aRegistration->mWaitingWorker) {
-     // FIXME(nsm): Actually update the state of active ServiceWorker instances.
-   }
- 
-   aRegistration->mWaitingWorker = aRegistration->mInstallingWorker.forget();
-+  InvalidateServiceWorkerContainerWorker(aRegistration, WAITING_WORKER | INSTALLING_WORKER);
- 
-   // FIXME(nsm): Actually update state of active ServiceWorker instances to
-   // installed.
-   // FIXME(nsm): Fire statechange on the instances.
- 
-   // FIXME(nsm): Handle replace().
- 
-   if (!aRegistration->IsControllingDocuments()) {
-@@ -1461,16 +1468,92 @@ ServiceWorkerManager::FireEventOnService
- 
-       event->SetTrusted(true);
-       target->DispatchDOMEvent(nullptr, event, nullptr, nullptr);
-     }
-   }
- }
- 
- NS_IMETHODIMP
-+ServiceWorkerManager::GetServiceWorkerForWindow(nsIDOMWindow* aWindow,
-+                                                WhichServiceWorker aWhichWorker,
-+                                                nsISupports** aServiceWorker)
-+{
-+  nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aWindow);
-+  if (!window || !window->GetExtantDoc()) {
-+    return NS_ERROR_FAILURE;
-+  }
-+
-+  nsCOMPtr<nsIDocument> doc = window->GetExtantDoc();
-+
-+  ServiceWorkerDomainInfo* domainInfo = GetDomainInfo(doc);
-+  if (!domainInfo) {
-+    return NS_ERROR_FAILURE;
-+  }
-+
-+  nsRefPtr<ServiceWorkerRegistration> registration;
-+  if (!domainInfo->mControlledDocuments.Get(doc, getter_AddRefs(registration))) {
-+    return NS_ERROR_FAILURE;
-+  }
-+
-+  nsRefPtr<ServiceWorkerInfo> info;
-+  if (aWhichWorker == INSTALLING_WORKER) {
-+    info = registration->mInstallingWorker;
-+  } else if (aWhichWorker == WAITING_WORKER) {
-+    info = registration->mWaitingWorker;
-+  } else if (aWhichWorker == ACTIVE_WORKER) {
-+    info = registration->mCurrentWorker;
-+  } else {
-+    MOZ_CRASH("Invalid worker type");
-+  }
-+
-+  if (!info) {
-+    return NS_ERROR_DOM_NOT_FOUND_ERR;
-+  }
-+
-+  nsRefPtr<ServiceWorker> serviceWorker;
-+  nsresult rv = CreateServiceWorkerForWindow(window,
-+                                             info->GetScriptSpec(),
-+                                             registration->mScope,
-+                                             getter_AddRefs(serviceWorker));
-+  if (NS_WARN_IF(NS_FAILED(rv))) {
-+    return rv;
-+  }
-+
-+  serviceWorker.forget(aServiceWorker);
-+  return NS_OK;
-+}
-+
-+NS_IMETHODIMP
-+ServiceWorkerManager::GetInstalling(nsIDOMWindow* aWindow,
-+                                    nsISupports** aServiceWorker)
-+{
-+  return GetServiceWorkerForWindow(aWindow, INSTALLING_WORKER, aServiceWorker);
-+}
-+
-+NS_IMETHODIMP
-+ServiceWorkerManager::GetWaiting(nsIDOMWindow* aWindow,
-+                                 nsISupports** aServiceWorker)
-+{
-+  return GetServiceWorkerForWindow(aWindow, WAITING_WORKER, aServiceWorker);
-+}
-+
-+NS_IMETHODIMP
-+ServiceWorkerManager::GetActive(nsIDOMWindow* aWindow, nsISupports** aServiceWorker)
-+{
-+  return GetServiceWorkerForWindow(aWindow, ACTIVE_WORKER, aServiceWorker);
-+}
-+
-+NS_IMETHODIMP
-+ServiceWorkerManager::GetDocumentController(nsIDOMWindow* aWindow, nsISupports** aServiceWorker)
-+{
-+  return GetServiceWorkerForWindow(aWindow, ACTIVE_WORKER, aServiceWorker);
-+}
-+
-+NS_IMETHODIMP
- ServiceWorkerManager::CreateServiceWorker(const nsACString& aScriptSpec,
-                                           const nsACString& aScope,
-                                           ServiceWorker** aServiceWorker)
- {
-   AssertIsOnMainThread();
- 
-   WorkerPrivate::LoadInfo info;
-   nsresult rv = NS_NewURI(getter_AddRefs(info.mBaseURI), aScriptSpec, nullptr, nullptr);
-@@ -1508,9 +1591,39 @@ ServiceWorkerManager::CreateServiceWorke
-   if (NS_WARN_IF(NS_FAILED(rv))) {
-     return rv;
-   }
- 
-   serviceWorker.forget(aServiceWorker);
-   return NS_OK;
- }
- 
-+void
-+ServiceWorkerManager::InvalidateServiceWorkerContainerWorker(ServiceWorkerRegistration* aRegistration,
-+                                                             uint32_t aWhichOnes)
-+{
-+  ServiceWorkerDomainInfo* domainInfo =
-+    GetDomainInfo(aRegistration->mScriptSpec);
-+
-+  if (domainInfo) {
-+    for (uint32_t i = 0; i < domainInfo->mServiceWorkerContainers.Length(); ++i) {
-+      ServiceWorkerContainer* target =
-+        domainInfo->mServiceWorkerContainers[i];
-+
-+      nsIURI* targetURI = target->GetDocumentURI();
-+      nsCString path;
-+      nsresult rv = targetURI->GetSpec(path);
-+      if (NS_WARN_IF(NS_FAILED(rv))) {
-+        continue;
-+      }
-+
-+      nsCString scope = FindScopeForPath(domainInfo->mOrderedScopes, path);
-+      if (scope.IsEmpty() ||
-+          !scope.Equals(aRegistration->mScope)) {
-+        continue;
-+      }
-+
-+      target->InvalidateWorkerReference(aWhichOnes);
-+    }
-+  }
-+}
-+
- END_WORKERS_NAMESPACE
-diff --git a/dom/workers/ServiceWorkerManager.h b/dom/workers/ServiceWorkerManager.h
---- a/dom/workers/ServiceWorkerManager.h
-+++ b/dom/workers/ServiceWorkerManager.h
-@@ -89,16 +89,22 @@ public:
-     return mScriptSpec;
-   }
- 
-   explicit ServiceWorkerInfo(const nsACString& aScriptSpec)
-     : mScriptSpec(aScriptSpec)
-   { }
- };
- 
-+enum WhichServiceWorker {
-+  INSTALLING_WORKER = 1,
-+  WAITING_WORKER    = 2,
-+  ACTIVE_WORKER     = 4
-+};
-+
- // Needs to inherit from nsISupports because NS_ProxyRelease() does not support
- // non-ISupports classes.
- class ServiceWorkerRegistration MOZ_FINAL : public nsISupports
- {
-   uint32_t mControlledDocumentsCounter;
- 
-   virtual ~ServiceWorkerRegistration();
- 
-@@ -184,16 +190,17 @@ public:
-  * installation, querying and event dispatch of ServiceWorkers for all the
-  * origins in the process.
-  */
- class ServiceWorkerManager MOZ_FINAL : public nsIServiceWorkerManager
- {
-   friend class ActivationRunnable;
-   friend class RegisterRunnable;
-   friend class CallInstallRunnable;
-+  friend class CancelServiceWorkerInstallationRunnable;
-   friend class ServiceWorkerUpdateInstance;
- 
- public:
-   NS_DECL_ISUPPORTS
-   NS_DECL_NSISERVICEWORKERMANAGER
-   NS_DECLARE_STATIC_IID_ACCESSOR(NS_SERVICEWORKERMANAGER_IMPL_IID)
- 
-   static ServiceWorkerManager* FactoryCreate()
-@@ -323,16 +330,24 @@ private:
-   GetDomainInfo(nsIDocument* aDoc);
- 
-   ServiceWorkerDomainInfo*
-   GetDomainInfo(nsIURI* aURI);
- 
-   ServiceWorkerDomainInfo*
-   GetDomainInfo(const nsCString& aURL);
- 
-+  NS_IMETHODIMP
-+  GetServiceWorkerForWindow(nsIDOMWindow* aWindow,
-+                            WhichServiceWorker aWhichWorker,
-+                            nsISupports** aServiceWorker);
-+
-+  void
-+  InvalidateServiceWorkerContainerWorker(ServiceWorkerRegistration* aRegistration, uint32_t aWhichOnes);
-+
-   already_AddRefed<ServiceWorkerRegistration>
-   GetServiceWorkerRegistration(nsPIDOMWindow* aWindow);
- 
-   already_AddRefed<ServiceWorkerRegistration>
-   GetServiceWorkerRegistration(nsIDocument* aDoc);
- 
-   already_AddRefed<ServiceWorkerRegistration>
-   GetServiceWorkerRegistration(nsIURI* aURI);
-diff --git a/dom/workers/test/serviceworkers/mochitest.ini b/dom/workers/test/serviceworkers/mochitest.ini
---- a/dom/workers/test/serviceworkers/mochitest.ini
-+++ b/dom/workers/test/serviceworkers/mochitest.ini
-@@ -1,12 +1,13 @@
- [DEFAULT]
- support-files =
-   worker.js
-   worker2.js
-   worker3.js
-   parse_error_worker.js
-   install_event_worker.js
-+  simpleregister/index.html
- 
- [test_installation_simple.html]
- [test_install_event.html]
- [test_navigator.html]
- [test_scopes.html]
-diff --git a/dom/workers/test/serviceworkers/simpleregister/index.html b/dom/workers/test/serviceworkers/simpleregister/index.html
-new file mode 100644
---- /dev/null
-+++ b/dom/workers/test/serviceworkers/simpleregister/index.html
-@@ -0,0 +1,11 @@
-+<html>
-+  <head></head>
-+  <body>
-+      <script type="text/javascript">
-+          navigator.serviceWorker.onupdatefound = function(e) {
-+            window.parent.postMessage("updatefound", "*");
-+          }
-+          window.parent.postMessage("ready", "*");
-+      </script>
-+  </body>
-+</html>
-diff --git a/dom/workers/test/serviceworkers/test_install_event.html b/dom/workers/test/serviceworkers/test_install_event.html
---- a/dom/workers/test/serviceworkers/test_install_event.html
-+++ b/dom/workers/test/serviceworkers/test_install_event.html
-@@ -11,22 +11,22 @@
- </head>
- <body>
- <p id="display"></p>
- <div id="content" style="display: none"></div>
- <pre id="test"></pre>
- <script class="testbody" type="text/javascript">
- 
-   function simpleRegister() {
--    var p = navigator.serviceWorker.register("worker.js");
-+    var p = navigator.serviceWorker.register("worker.js", { scope: "test_install_event/*" });
-     return p;
-   }
- 
-   function nextRegister() {
--    var p = navigator.serviceWorker.register("install_event_worker.js");
-+    var p = navigator.serviceWorker.register("install_event_worker.js", { scope: "test_install_event/*" });
-     todo(false, "Check for onupdatefound event");
-     return p;
-   }
- 
-   function runTest() {
-     simpleRegister()
-       .then(nextRegister)
-       .then(function() {
-diff --git a/dom/workers/test/serviceworkers/test_installation_simple.html b/dom/workers/test/serviceworkers/test_installation_simple.html
---- a/dom/workers/test/serviceworkers/test_installation_simple.html
-+++ b/dom/workers/test/serviceworkers/test_installation_simple.html
-@@ -11,17 +11,17 @@
- </head>
- <body>
- <p id="display"></p>
- <div id="content" style="display: none"></div>
- <pre id="test"></pre>
- <script class="testbody" type="text/javascript">
- 
-   function simpleRegister() {
--    var p = navigator.serviceWorker.register("worker.js");
-+    var p = navigator.serviceWorker.register("worker.js", { scope: "simpleregister/*" });
-     ok(p instanceof Promise, "register() should return a Promise");
-     return Promise.resolve();
-   }
- 
-   function sameOriginWorker() {
-     p = navigator.serviceWorker.register("http://some-other-origin/worker.js");
-     return p.then(function(w) {
-       ok(false, "Worker from different origin should fail");
-@@ -103,25 +103,39 @@
-     info("NSM " + e.name);
-       ok(e instanceof Error, "Registration should fail with parse error");
-     });
-   }
- 
-   // FIXME(nsm): test for parse error when Update step doesn't happen (directly from register).
- 
-   function updatefound() {
--    var p = navigator.serviceWorker.register("worker.js");
-+    var frame = document.createElement("iframe");
-+    frame.setAttribute("id", "simpleregister-frame");
-+    frame.setAttribute("src", new URL("simpleregister/index.html", document.baseURI).href);
-+    document.body.appendChild(frame);
-+    var resolve, reject;
-+    var p = new Promise(function(res, rej) {
-+      resolve = res;
-+      reject = rej;
-+    });
- 
--    return new Promise(function(resolve, reject) {
--      navigator.serviceWorker.onupdatefound = function(e) {
--        ok(true, "Got updatefound event");
--        navigator.serviceWorker.onupdatefound = null;
-+    function continueTest() {
-+      navigator.serviceWorker.register("worker2.js", { scope: "simpleregister/*" });
-+    }
-+
-+    window.onmessage = function(e) {
-+      if (e.data == "ready") {
-+        continueTest();
-+      } else if (e.data == "updatefound") {
-+        window.onmessage = null;
-         resolve();
-       }
--    });
-+    }
-+    return p;
-   }
- 
-   function runTest() {
-     simpleRegister()
-       .then(sameOriginWorker)
-       .then(sameOriginScope)
-       .then(httpsOnly)
-       .then(realWorker)
-diff --git a/dom/workers/test/serviceworkers/test_navigator.html b/dom/workers/test/serviceworkers/test_navigator.html
---- a/dom/workers/test/serviceworkers/test_navigator.html
-+++ b/dom/workers/test/serviceworkers/test_navigator.html
-@@ -19,17 +19,17 @@
-     ok(navigator.serviceWorker, "navigator.serviceWorker should exist when ServiceWorkers are enabled.");
-     ok(typeof navigator.serviceWorker.register === "function", "navigator.serviceWorker.register() should be a function.");
-     ok(typeof navigator.serviceWorker.unregister === "function", "navigator.serviceWorker.unregister() should be a function.");
-     ok(typeof navigator.serviceWorker.getAll === "function", "navigator.serviceWorker.getAll() should be a function.");
-     ok(navigator.serviceWorker.ready instanceof Promise, "navigator.serviceWorker.ready should be a Promise.");
-     ok(navigator.serviceWorker.installing === null, "There should be no installing worker for an uncontrolled scope.");
-     ok(navigator.serviceWorker.waiting === null, "There should be no waiting worker for an uncontrolled scope.");
-     ok(navigator.serviceWorker.active === null, "There should be no active worker for an uncontrolled scope.");
--    ok(navigator.serviceWorker.controller === null, "There should be no active worker for an uncontrolled document.");
-+    ok(navigator.serviceWorker.controller === null, "There should be no controller worker for an uncontrolled document.");
-   }
- 
-   SimpleTest.waitForExplicitFinish();
- 
-   SpecialPowers.pushPrefEnv({"set": [
-     ["dom.serviceWorkers.enabled", true]
-   ]}, function() {
-     checkEnabled();
--- a/series
+++ b/series
@@ -1,9 +1,8 @@
-1002570-swc-props
 foojsapi
 1011268-swm-unregister
 sw-instance-events-and-state-2
 sw-instance-events-and-state
 903441-stuff
 898524-1-nowhite
 898524-2-nowhite
 857464-push-prefs