UPDATE: 1002570-swc-props
authorNikhil Marathe <nsm.nikhil@gmail.com>
Fri, 11 Jul 2014 17:03:46 -0700
changeset 1100 9024986f644e8f58a51839019775f2fc2f0af1ac
parent 1099 9ccc8ddf1d762296e842c0f1b3599f92a4c76d77
child 1101 8f8677c1e4ca608292c4ea5d6716a1535ea58c3c
push id32
push usernsm.nikhil@gmail.com
push dateThu, 24 Jul 2014 00:32:46 +0000
bugs1002570
UPDATE: 1002570-swc-props dom/interfaces/base/nsIServiceWorkerManager.idl | 8 +++++++- dom/workers/ServiceWorkerManager.cpp | 5 +++-- dom/workers/ServiceWorkerManager.h | 6 ++++++ 3 files changed, 16 insertions(+), 3 deletions(-) qparent: f0b558b85933 qtip: 86887777c403 top: 1002570-swc-props
1002570-swc-props
series
--- a/1002570-swc-props
+++ b/1002570-swc-props
@@ -1,25 +1,42 @@
 # HG changeset patch
-# Parent 0a6207d260f81ed6b3a7e31c02bff611d4afae60
+# 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
-@@ -20,15 +20,21 @@ interface nsIServiceWorkerManager : nsIS
-   [noscript] void MaybeStartControlling(in nsIDocument aDoc);
+@@ -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;
  
-   [noscript] void MaybeStopControlling(in nsIDocument aDoc);
+-[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);
@@ -302,17 +319,17 @@ diff --git a/dom/workers/ServiceWorkerCo
  } // 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
-@@ -560,16 +560,17 @@ ServiceWorkerManager::Update(ServiceWork
+@@ -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;
@@ -320,17 +337,17 @@ diff --git a/dom/workers/ServiceWorkerMa
    }
  
    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 =
-@@ -767,16 +768,18 @@ public:
+@@ -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;
@@ -339,17 +356,17 @@ diff --git a/dom/workers/ServiceWorkerMa
      return NS_OK;
    }
  };
  
  /*
   * Used to handle InstallEvent::waitUntil() and proceed with installation.
   */
  class FinishInstallHandler MOZ_FINAL : public PromiseNativeHandler
-@@ -988,28 +991,30 @@ private:
+@@ -991,28 +994,30 @@ private:
  };
  
  void
  ServiceWorkerManager::Install(ServiceWorkerRegistration* aRegistration,
                                ServiceWorkerInfo* aServiceWorkerInfo)
  {
    AssertIsOnMainThread();
    aRegistration->mInstallingWorker = aServiceWorkerInfo;
@@ -370,43 +387,43 @@ diff --git a/dom/workers/ServiceWorkerMa
      return;
    }
  
    nsRefPtr<InstallEventRunnable> r =
      new InstallEventRunnable(serviceWorker->GetWorkerPrivate(), handle);
  
    AutoSafeJSContext cx;
    r->Dispatch(cx);
-@@ -1043,22 +1048,23 @@ public:
+@@ -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 6-7 of the algorithm.
+     // 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,
-@@ -1087,16 +1093,17 @@ ServiceWorkerManager::FinishInstall(Serv
+                                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();
@@ -414,18 +431,18 @@ diff --git a/dom/workers/ServiceWorkerMa
  
    // 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()) {
-@@ -1478,16 +1485,96 @@ ServiceWorkerManager::FireEventOnService
-         ErrorEvent::Constructor(target, NS_LITERAL_STRING("error"), aInit);
+@@ -1461,16 +1468,96 @@ ServiceWorkerManager::FireEventOnService
+ 
        event->SetTrusted(true);
        target->DispatchDOMEvent(nullptr, event, nullptr, nullptr);
      }
    }
  }
  
  NS_IMETHODIMP
 +ServiceWorkerManager::GetServiceWorkerForWindow(nsIDOMWindow* aWindow,
@@ -511,17 +528,17 @@ diff --git a/dom/workers/ServiceWorkerMa
  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);
-@@ -1525,9 +1612,39 @@ ServiceWorkerManager::CreateServiceWorke
+@@ -1508,9 +1595,39 @@ ServiceWorkerManager::CreateServiceWorke
    if (NS_WARN_IF(NS_FAILED(rv))) {
      return rv;
    }
  
    serviceWorker.forget(aServiceWorker);
    return NS_OK;
  }
  
@@ -573,59 +590,21 @@ diff --git a/dom/workers/ServiceWorkerMa
 +  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
  {
-   friend class AutoServiceWorkerRegistrationCounter;
    uint32_t mControlledDocumentsCounter;
  
    virtual ~ServiceWorkerRegistration();
-@@ -157,29 +163,36 @@ public:
-   IsControllingDocuments()
-   {
-     return mControlledDocumentsCounter > 0;
-   }
- };
  
- class AutoServiceWorkerRegistrationCounter
- {
--  ServiceWorkerRegistration* mRegistration;
-+  nsRefPtr<ServiceWorkerRegistration> mRegistration;
- 
- public:
-   AutoServiceWorkerRegistrationCounter(ServiceWorkerRegistration* aRegistration)
-     : mRegistration(aRegistration)
-   {
-     ++mRegistration->mControlledDocumentsCounter;
-   }
- 
-   ~AutoServiceWorkerRegistrationCounter()
-   {
-     --mRegistration->mControlledDocumentsCounter;
-   }
-+
-+  already_AddRefed<ServiceWorkerRegistration>
-+  GetRegistration()
-+  {
-+    nsRefPtr<ServiceWorkerRegistration> ref = mRegistration;
-+    return ref.forget();
-+  }
- };
- 
- #define NS_SERVICEWORKERMANAGER_IMPL_IID                 \
- { /* f4f8755a-69ca-46e8-a65d-775745535990 */             \
-   0xf4f8755a,                                            \
-   0x69ca,                                                \
-   0x46e8,                                                \
-   { 0xa6, 0x5d, 0x77, 0x57, 0x45, 0x53, 0x59, 0x90 }     \
-@@ -190,16 +203,17 @@ public:
+@@ -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;
@@ -633,17 +612,17 @@ diff --git a/dom/workers/ServiceWorkerMa
    friend class ServiceWorkerUpdateInstance;
  
  public:
    NS_DECL_ISUPPORTS
    NS_DECL_NSISERVICEWORKERMANAGER
    NS_DECLARE_STATIC_IID_ACCESSOR(NS_SERVICEWORKERMANAGER_IMPL_IID)
  
    static ServiceWorkerManager* FactoryCreate()
-@@ -329,16 +343,24 @@ private:
+@@ -323,16 +330,24 @@ private:
    GetDomainInfo(nsIDocument* aDoc);
  
    ServiceWorkerDomainInfo*
    GetDomainInfo(nsIURI* aURI);
  
    ServiceWorkerDomainInfo*
    GetDomainInfo(const nsCString& aURL);
  
--- a/series
+++ b/series
@@ -1,10 +1,10 @@
+1002570-swc-props
 foojsapi
-1002570-swc-props
 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
 857464-push-webpages