DELETE: 1 patches - 931249-caching1
authorNikhil Marathe <nsm.nikhil@gmail.com>
Wed, 23 Jul 2014 17:32:55 -0700
changeset 1109 f399569a6fddf0a9ed8793676892322e6c5e3c34
parent 1108 57c5c4c43a7bd6dc92f3531b194e1626633c4685
child 1110 4438fd9f3ae866a06620808ce596d1b50a330ead
push id32
push usernsm.nikhil@gmail.com
push dateThu, 24 Jul 2014 00:32:46 +0000
bugs931249
DELETE: 1 patches - 931249-caching1 DELETE: 931249-caching1 qparent: 666e5e6b3abf qtip: 666e5e6b3abf top: (none)
931249-caching1
series
deleted file mode 100644
--- a/931249-caching1
+++ /dev/null
@@ -1,1782 +0,0 @@
-# HG changeset patch
-# Parent 0c04d8c992591a2452294e1dd48b348c370d18c2
-# User Nikhil Marathe <nsm.nikhil@gmail.com>
-Bug 931249 - Appcache caching. r=honzab,bent
-
-diff --git a/dom/workers/RuntimeService.cpp b/dom/workers/RuntimeService.cpp
---- a/dom/workers/RuntimeService.cpp
-+++ b/dom/workers/RuntimeService.cpp
-@@ -2082,105 +2082,130 @@ RuntimeService::ResumeWorkersForWindow(n
- nsresult
- RuntimeService::CreateSharedWorker(const GlobalObject& aGlobal,
-                                    const nsAString& aScriptURL,
-                                    const nsACString& aName,
-                                    SharedWorker** aSharedWorker)
- {
-   return CreateSharedWorkerInternal(aGlobal, aScriptURL, aName,
-                                     WorkerTypeShared,
-+                                    /* doesn't matter, not used for shared
-+                                     * workers. */
-+                                    ServiceWorkerLoadTypeNoUpdate,
-                                     aSharedWorker);
- }
- 
- nsresult
- RuntimeService::CreateServiceWorker(const GlobalObject& aGlobal,
-                                     const nsAString& aScriptURL,
-                                     const nsACString& aScope,
-+                                    ServiceWorkerLoadType aLoadType,
-                                     ServiceWorker** aServiceWorker)
- {
-   nsresult rv;
-   nsRefPtr<SharedWorker> sharedWorker;
-   rv = CreateSharedWorkerInternal(aGlobal, aScriptURL, aScope,
-                                   WorkerTypeService,
-+                                  aLoadType,
-                                   getter_AddRefs(sharedWorker));
- 
-   nsRefPtr<ServiceWorker> serviceWorker =
-     static_cast<ServiceWorker*>(sharedWorker.get());
- 
-   serviceWorker->mURL = aScriptURL;
-   serviceWorker->mScope = NS_ConvertUTF8toUTF16(aScope);
- 
-   serviceWorker.forget(aServiceWorker);
-   return rv;
- }
- 
- nsresult
--RuntimeService::CreateSharedWorkerInternal(const GlobalObject& aGlobal,
--                                   const nsAString& aScriptURL,
--                                   const nsACString& aName,
--                                   WorkerType aType,
--                                   SharedWorker** aSharedWorker)
-+RuntimeService::CreateServiceWorker(JSContext* aCx,
-+                                    const nsAString& aScriptURL,
-+                                    const nsACString& aScope,
-+                                    WorkerPrivate::LoadInfo aLoadInfo,
-+                                    ServiceWorkerLoadType aLoadType,
-+                                    ServiceWorker** aServiceWorker)
-+{
-+  nsresult rv;
-+  nsRefPtr<SharedWorker> sharedWorker;
-+  rv = CreateSharedWorkerFromLoadInfo(aCx, aScriptURL, aScope, WorkerTypeService,
-+                                      aLoadInfo, aLoadType,
-+                                      getter_AddRefs(sharedWorker));
-+
-+  nsRefPtr<ServiceWorker> serviceWorker =
-+    static_cast<ServiceWorker*>(sharedWorker.get());
-+
-+  serviceWorker->mURL = aScriptURL;
-+  serviceWorker->mScope = NS_ConvertUTF8toUTF16(aScope);
-+
-+  serviceWorker.forget(aServiceWorker);
-+  return rv;
-+}
-+
-+nsresult
-+RuntimeService::CreateSharedWorkerFromLoadInfo(JSContext* aCx,
-+                                               const nsAString& aScriptURL,
-+                                               const nsACString& aName,
-+                                               WorkerType aType,
-+                                               WorkerPrivate::LoadInfo aLoadInfo,
-+                                               ServiceWorkerLoadType aLoadType,
-+                                               SharedWorker** aSharedWorker)
- {
-   AssertIsOnMainThread();
- 
--  nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.GetAsSupports());
--  MOZ_ASSERT(window);
--
--  JSContext* cx = aGlobal.GetContext();
--
--  WorkerPrivate::LoadInfo loadInfo;
--  nsresult rv = WorkerPrivate::GetLoadInfo(cx, window, nullptr, aScriptURL,
--                                           aType,
--                                           false, &loadInfo);
--  NS_ENSURE_SUCCESS(rv, rv);
--
--  MOZ_ASSERT(loadInfo.mResolvedScriptURI);
--
--  nsCString scriptSpec;
--  rv = loadInfo.mResolvedScriptURI->GetSpec(scriptSpec);
--  NS_ENSURE_SUCCESS(rv, rv);
-+  MOZ_ASSERT(aLoadInfo.mResolvedScriptURI);
-+
-+  if (aLoadType == ServiceWorkerLoadTypeUpdate) {
-+    aLoadInfo.mUpdateServiceWorker = true;
-+  }
- 
-   nsRefPtr<WorkerPrivate> workerPrivate;
-   {
-     MutexAutoLock lock(mMutex);
- 
-     WorkerDomainInfo* domainInfo;
-     SharedWorkerInfo* sharedWorkerInfo;
- 
-+    nsCString scriptSpec;
-+    nsresult rv = aLoadInfo.mResolvedScriptURI->GetSpec(scriptSpec);
-+    NS_ENSURE_SUCCESS(rv, rv);
-+
-     nsAutoCString key;
-     GenerateSharedWorkerKey(scriptSpec, aName, key);
- 
--    if (mDomainMap.Get(loadInfo.mDomain, &domainInfo) &&
-+    if (mDomainMap.Get(aLoadInfo.mDomain, &domainInfo) &&
-         domainInfo->mSharedWorkerInfos.Get(key, &sharedWorkerInfo)) {
-       workerPrivate = sharedWorkerInfo->mWorkerPrivate;
-     }
-   }
- 
-   bool created = false;
- 
-   if (!workerPrivate) {
-     ErrorResult rv;
-     workerPrivate =
--      WorkerPrivate::Constructor(aGlobal, aScriptURL, false,
--                                 aType, aName, &loadInfo, rv);
-+      WorkerPrivate::Constructor(aCx, aScriptURL, false,
-+                                 aType, aName, &aLoadInfo, rv);
-     NS_ENSURE_TRUE(workerPrivate, rv.ErrorCode());
- 
-     created = true;
-   }
- 
-+  nsCOMPtr<nsPIDOMWindow> window = aLoadInfo.mWindow;
-   nsRefPtr<SharedWorker> sharedWorker;
-   if (workerPrivate->IsSharedWorker()) {
-     sharedWorker = new SharedWorker(window, workerPrivate);
-   } else if (workerPrivate->IsServiceWorker()) {
-     sharedWorker = new ServiceWorker(window, workerPrivate);
-   } else {
-     MOZ_CRASH("Expected SharedWorker or ServiceWorker!");
-   }
- 
--  if (!workerPrivate->RegisterSharedWorker(cx, sharedWorker)) {
-+  if (!workerPrivate->RegisterSharedWorker(aCx, sharedWorker)) {
-     NS_WARNING("Worker is unreachable, this shouldn't happen!");
-     sharedWorker->Close();
-     return NS_ERROR_FAILURE;
-   }
- 
-   // This is normally handled in RegisterWorker, but that wasn't called if the
-   // worker already existed.
-   if (!created) {
-@@ -2194,16 +2219,41 @@ RuntimeService::CreateSharedWorkerIntern
-       windowArray->AppendElement(workerPrivate);
-     }
-   }
- 
-   sharedWorker.forget(aSharedWorker);
-   return NS_OK;
- }
- 
-+nsresult
-+RuntimeService::CreateSharedWorkerInternal(const GlobalObject& aGlobal,
-+                                   const nsAString& aScriptURL,
-+                                   const nsACString& aName,
-+                                   WorkerType aType,
-+                                   ServiceWorkerLoadType aLoadType,
-+                                   SharedWorker** aSharedWorker)
-+{
-+  AssertIsOnMainThread();
-+
-+  nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.GetAsSupports());
-+  MOZ_ASSERT(window);
-+
-+  JSContext* cx = aGlobal.GetContext();
-+
-+  WorkerPrivate::LoadInfo loadInfo;
-+  nsresult rv = WorkerPrivate::GetLoadInfo(cx, window, nullptr, aScriptURL,
-+                                           aType,
-+                                           false, &loadInfo);
-+  NS_ENSURE_SUCCESS(rv, rv);
-+
-+  return CreateSharedWorkerFromLoadInfo(cx, aScriptURL, aName, aType,
-+                                        loadInfo, aLoadType, aSharedWorker);
-+}
-+
- void
- RuntimeService::ForgetSharedWorker(WorkerPrivate* aWorkerPrivate)
- {
-   AssertIsOnMainThread();
-   MOZ_ASSERT(aWorkerPrivate);
-   MOZ_ASSERT(aWorkerPrivate->IsSharedWorker() || aWorkerPrivate->IsServiceWorker());
- 
-   MutexAutoLock lock(mMutex);
-diff --git a/dom/workers/RuntimeService.h b/dom/workers/RuntimeService.h
---- a/dom/workers/RuntimeService.h
-+++ b/dom/workers/RuntimeService.h
-@@ -11,16 +11,17 @@
- 
- #include "nsIObserver.h"
- 
- #include "mozilla/TimeStamp.h"
- #include "mozilla/dom/BindingDeclarations.h"
- #include "nsClassHashtable.h"
- #include "nsHashKeys.h"
- #include "nsTArray.h"
-+#include "WorkerPrivate.h"
- 
- class nsIRunnable;
- class nsIThread;
- class nsITimer;
- class nsPIDOMWindow;
- 
- BEGIN_WORKERS_NAMESPACE
- 
-@@ -148,18 +149,36 @@ public:
-                      const nsAString& aScriptURL,
-                      const nsACString& aName,
-                      SharedWorker** aSharedWorker);
- 
-   nsresult
-   CreateServiceWorker(const GlobalObject& aGlobal,
-                       const nsAString& aScriptURL,
-                       const nsACString& aScope,
-+                      ServiceWorkerLoadType aLoadType,
-                       ServiceWorker** aServiceWorker);
- 
-+  nsresult
-+  CreateServiceWorker(JSContext* aCx,
-+                      const nsAString& aScriptURL,
-+                      const nsACString& aScope,
-+                      WorkerPrivate::LoadInfo aLoadInfo,
-+                      ServiceWorkerLoadType aLoadType,
-+                      ServiceWorker** aServiceWorker);
-+
-+  nsresult
-+  CreateSharedWorkerFromLoadInfo(JSContext* aCx,
-+                                 const nsAString& aScriptURL,
-+                                 const nsACString& aName,
-+                                 WorkerType aType,
-+                                 WorkerPrivate::LoadInfo aLoadInfo,
-+                                 ServiceWorkerLoadType aLoadType,
-+                                 SharedWorker** aSharedWorker);
-+
-   void
-   ForgetSharedWorker(WorkerPrivate* aWorkerPrivate);
- 
-   const NavigatorProperties&
-   GetNavigatorProperties() const
-   {
-     return mNavigatorProperties;
-   }
-@@ -287,14 +306,15 @@ private:
-   static void
-   JSVersionChanged(const char* aPrefName, void* aClosure);
- 
-   nsresult
-   CreateSharedWorkerInternal(const GlobalObject& aGlobal,
-                              const nsAString& aScriptURL,
-                              const nsACString& aName,
-                              WorkerType aType,
-+                             ServiceWorkerLoadType aLoadType,
-                              SharedWorker** aSharedWorker);
- };
- 
- END_WORKERS_NAMESPACE
- 
- #endif /* mozilla_dom_workers_runtimeservice_h__ */
-diff --git a/dom/workers/ScriptLoader.cpp b/dom/workers/ScriptLoader.cpp
---- a/dom/workers/ScriptLoader.cpp
-+++ b/dom/workers/ScriptLoader.cpp
-@@ -1,15 +1,18 @@
- /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
- /* This Source Code Form is subject to the terms of the Mozilla Public
-  * 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 "ScriptLoader.h"
- 
-+#include "nsIApplicationCache.h"
-+#include "nsIApplicationCacheChannel.h"
-+#include "nsIApplicationCacheService.h"
- #include "nsICachingChannel.h"
- #include "nsIChannel.h"
- #include "nsIChannelPolicy.h"
- #include "nsIContentPolicy.h"
- #include "nsIContentSecurityPolicy.h"
- #include "nsIHttpChannel.h"
- #include "nsIIOService.h"
- #include "nsIProtocolHandler.h"
-@@ -53,17 +56,17 @@ nsresult
- ChannelFromScriptURL(nsIPrincipal* principal,
-                      nsIURI* baseURI,
-                      nsIDocument* parentDoc,
-                      nsILoadGroup* loadGroup,
-                      nsIIOService* ios,
-                      nsIScriptSecurityManager* secMan,
-                      const nsAString& aScriptURL,
-                      bool aIsWorkerScript,
--                     bool aForceCacheFetch,
-+                     uint32_t aAdditionalFlags,
-                      bool aIsServiceWorker,
-                      nsIChannel** aChannel)
- {
-   AssertIsOnMainThread();
- 
-   nsresult rv;
-   nsCOMPtr<nsIURI> uri;
-   rv = nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(uri),
-@@ -122,23 +125,18 @@ ChannelFromScriptURL(nsIPrincipal* princ
- 
-     rv = channelPolicy->SetContentSecurityPolicy(csp);
-     NS_ENSURE_SUCCESS(rv, rv);
- 
-     rv = channelPolicy->SetLoadType(nsIContentPolicy::TYPE_SCRIPT);
-     NS_ENSURE_SUCCESS(rv, rv);
-   }
- 
--  uint32_t flags = nsIRequest::LOAD_NORMAL | nsIChannel::LOAD_CLASSIFY_URI;
--
--  if (aForceCacheFetch) {
--    flags |= nsIRequest::INHIBIT_CACHING |
--             nsIRequest::LOAD_FROM_CACHE |
--             nsICachingChannel::LOAD_ONLY_FROM_CACHE;
--  }
-+  uint32_t flags = nsIRequest::LOAD_NORMAL | nsIChannel::LOAD_CLASSIFY_URI |
-+                   aAdditionalFlags;
- 
-   nsCOMPtr<nsIChannel> channel;
-   rv = NS_NewChannel(getter_AddRefs(channel), uri, ios, loadGroup, nullptr,
-                      flags, channelPolicy);
-   NS_ENSURE_SUCCESS(rv, rv);
- 
-   if (!aIsServiceWorker && parentDoc) {
-     channel = parentDoc->InterceptFetch(channel);
-@@ -163,18 +161,64 @@ struct ScriptLoadInfo
- 
-   nsString mURL;
-   nsCOMPtr<nsIChannel> mChannel;
-   nsString mScriptText;
- 
-   nsresult mLoadResult;
-   bool mExecutionScheduled;
-   bool mExecutionResult;
-+  bool mIsFromCache;
- };
- 
-+class CacheStatusObservingStreamLoader : public nsIStreamLoader
-+{
-+public:
-+  NS_DECL_ISUPPORTS
-+  NS_FORWARD_NSISTREAMLOADER(mLoader->)
-+  NS_DECL_NSIREQUESTOBSERVER
-+  NS_FORWARD_NSISTREAMLISTENER(mLoader->)
-+
-+  CacheStatusObservingStreamLoader(nsIStreamLoader* aLoader, ScriptLoadInfo& aLoadInfo)
-+    : mLoader(aLoader), mLoadInfo(aLoadInfo)
-+  {
-+  }
-+
-+  virtual ~CacheStatusObservingStreamLoader()
-+  { }
-+
-+private:
-+  nsCOMPtr<nsIStreamLoader> mLoader;
-+  ScriptLoadInfo& mLoadInfo;
-+};
-+
-+NS_IMPL_ISUPPORTS3(CacheStatusObservingStreamLoader, nsIStreamLoader,
-+                   nsIRequestObserver, nsIStreamListener);
-+
-+NS_IMETHODIMP
-+CacheStatusObservingStreamLoader::OnStartRequest(nsIRequest* aRequest,
-+                                                 nsISupports* aContext)
-+{
-+  nsCOMPtr<nsICacheInfoChannel> cacheInfoChan = do_QueryInterface(aRequest);
-+  if (cacheInfoChan) {
-+    nsresult rv = cacheInfoChan->IsFromCache(&mLoadInfo.mIsFromCache);
-+    NS_WARN_IF(NS_FAILED(rv));
-+  }
-+
-+  return mLoader->OnStartRequest(aRequest, aContext);
-+}
-+
-+NS_IMETHODIMP
-+CacheStatusObservingStreamLoader::OnStopRequest(nsIRequest* aRequest,
-+                                                nsISupports* aContext,
-+                                                nsresult aStatus)
-+{
-+  return mLoader->OnStopRequest(aRequest, aContext, aStatus);
-+}
-+
- class ScriptLoaderRunnable;
- 
- class ScriptExecutorRunnable MOZ_FINAL : public MainThreadWorkerSyncRunnable
- {
-   ScriptLoaderRunnable& mScriptLoader;
-   uint32_t mFirstIndex;
-   uint32_t mLastIndex;
- 
-@@ -266,16 +310,28 @@ private:
-     }
- 
-     ScriptLoadInfo& loadInfo = mLoadInfos[index];
- 
-     loadInfo.mLoadResult = OnStreamCompleteInternal(aLoader, aContext, aStatus,
-                                                     aStringLen, aString,
-                                                     loadInfo);
- 
-+    if (mIsWorkerScript && mWorkerPrivate->IsServiceWorker()) {
-+      ServiceWorkerManager* swm = ServiceWorkerManager::GetInstance();
-+      // Whether we updated or not, this worker should keep running, because,
-+      // in case of no update, SWM will create ServiceWorker instances for this
-+      // worker, in case of update SWM will create ServiceWorker instances for
-+      // this 'new' worker.
-+      swm->FinishFetch(NS_ConvertUTF16toUTF8(loadInfo.mURL),
-+                       mWorkerPrivate->SharedWorkerName(),
-+                       NS_SUCCEEDED(loadInfo.mLoadResult),
-+                       !loadInfo.mIsFromCache);
-+    }
-+
-     ExecuteFinishedScripts();
- 
-     return NS_OK;
-   }
- 
-   virtual bool
-   Notify(JSContext* aCx, Status aStatus) MOZ_OVERRIDE
-   {
-@@ -377,24 +433,31 @@ private:
- 
-     nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
-     NS_ASSERTION(secMan, "This should never be null!");
- 
-     for (uint32_t index = 0; index < mLoadInfos.Length(); index++) {
-       ScriptLoadInfo& loadInfo = mLoadInfos[index];
-       nsresult& rv = loadInfo.mLoadResult;
- 
--      // FIXME(nsm): Toggle fetch from cache only once ServiceWorkerFetcher
--      // starts writing to cache.
-+      uint32_t additionalFlags = 0;
-+      if (mWorkerPrivate->IsServiceWorker()) {
-+        if (mWorkerPrivate->UpdateServiceWorker()) {
-+          additionalFlags |= nsIRequest::LOAD_BYPASS_CACHE;
-+        } else {
-+          additionalFlags |= nsICachingChannel::LOAD_ONLY_FROM_CACHE;
-+        }
-+      }
-+
-       if (!channel) {
-         rv = ChannelFromScriptURL(principal, baseURI, parentDoc, loadGroup, ios,
-                                   secMan, loadInfo.mURL, mIsWorkerScript,
--                                                false,
--                                                mWorkerPrivate->IsServiceWorker(),
--                                                getter_AddRefs(channel));
-+                                  additionalFlags,
-+                                  mWorkerPrivate->IsServiceWorker(),
-+                                  getter_AddRefs(channel));
-         if (NS_FAILED(rv)) {
-           return rv;
-         }
-       }
- 
-       // We need to know which index we're on in OnStreamComplete so we know
-       // where to put the result.
-       nsCOMPtr<nsISupportsPRUint32> indexSupports =
-@@ -405,17 +468,53 @@ private:
-       NS_ENSURE_SUCCESS(rv, rv);
- 
-       // We don't care about progress so just use the simple stream loader for
-       // OnStreamComplete notification only.
-       nsCOMPtr<nsIStreamLoader> loader;
-       rv = NS_NewStreamLoader(getter_AddRefs(loader), this);
-       NS_ENSURE_SUCCESS(rv, rv);
- 
--      rv = channel->AsyncOpen(loader, indexSupports);
-+      nsCOMPtr<nsIStreamLoader> cacheObservingLoader;
-+      if (mWorkerPrivate->IsServiceWorker() && mWorkerPrivate->UpdateServiceWorker()) {
-+        cacheObservingLoader = new CacheStatusObservingStreamLoader(loader, loadInfo);
-+      } else {
-+        cacheObservingLoader = loader;
-+      }
-+
-+      // This will ensure the script is always cached.
-+      // FIXME: Should recurse to importScripts.
-+      if (mWorkerPrivate->IsServiceWorker()) {
-+        nsCOMPtr<nsIApplicationCacheService> appCacheService = do_GetService(NS_APPLICATIONCACHESERVICE_CONTRACTID, &rv);
-+        NS_ENSURE_SUCCESS(rv, rv);
-+
-+        MOZ_ASSERT(mWorkerPrivate->GetResolvedScriptURI());
-+        nsCString appCacheGroupID;
-+        rv = appCacheService->BuildGroupIDForApp(mWorkerPrivate->GetResolvedScriptURI(), 0, false, appCacheGroupID);
-+        NS_ENSURE_SUCCESS(rv, rv);
-+
-+        nsCOMPtr<nsIApplicationCache> activeCache;
-+        rv = appCacheService->GetActiveCache(appCacheGroupID, getter_AddRefs(activeCache));
-+        if (NS_FAILED(rv) || !activeCache) {
-+          rv = appCacheService->CreateApplicationCache(appCacheGroupID, getter_AddRefs(activeCache));
-+          activeCache->Activate();
-+          NS_ENSURE_SUCCESS(rv, rv);
-+        }
-+
-+        nsCOMPtr<nsIApplicationCacheChannel> appCacheChan = do_QueryInterface(channel);
-+
-+        appCacheChan->SetChooseApplicationCache(true);
-+        if (mWorkerPrivate->UpdateServiceWorker()) {
-+          appCacheChan->SetApplicationCacheForWrite(activeCache);
-+        } else {
-+          appCacheChan->SetApplicationCache(activeCache);
-+        }
-+      }
-+
-+      rv = channel->AsyncOpen(cacheObservingLoader, indexSupports);
-       NS_ENSURE_SUCCESS(rv, rv);
- 
-       loadInfo.mChannel.swap(channel);
-     }
- 
-     return NS_OK;
-   }
- 
-@@ -450,16 +549,20 @@ private:
- 
-     nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(request);
-     if (httpChannel) {
-       bool requestSucceeded;
-       rv = httpChannel->GetRequestSucceeded(&requestSucceeded);
-       NS_ENSURE_SUCCESS(rv, rv);
- 
-       if (!requestSucceeded) {
-+        if (mIsWorkerScript &&
-+            mWorkerPrivate->IsServiceWorker() &&
-+            mWorkerPrivate->UpdateServiceWorker()) {
-+        }
-         return NS_ERROR_NOT_AVAILABLE;
-       }
-     }
- 
-     // May be null.
-     nsIDocument* parentDoc = mWorkerPrivate->GetDocument();
- 
-     // Use the regular nsScriptLoader for this grunt work! Should be just fine
-diff --git a/dom/workers/ServiceWorkerManager.cpp b/dom/workers/ServiceWorkerManager.cpp
---- a/dom/workers/ServiceWorkerManager.cpp
-+++ b/dom/workers/ServiceWorkerManager.cpp
-@@ -48,17 +48,16 @@
- #include "nsTArray.h"
- #include "nsXPCOM.h"
- 
- #include "ServiceWorkerContainer.h"
- #include "RuntimeService.h"
- #include "ServiceWorker.h"
- #include "ServiceWorkerEvents.h"
- #include "ServiceWorkerRunnables.h"
--#include "ServiceWorkerUtil.h"
- #include "WorkerInlines.h"
- #include "WorkerPrivate.h"
- #include "WorkerRunnable.h"
- #include "WorkerScope.h"
- 
- using namespace mozilla;
- using namespace mozilla::dom;
- 
-@@ -443,17 +442,16 @@ ServiceWorkerManager::~ServiceWorkerMana
- {
-   mDomainMap.EnumerateRead(CleanupServiceWorkerInformation, nullptr);
-   mDomainMap.Clear();
- }
- 
- NS_IMETHODIMP
- ServiceWorkerManager::Observe(nsISupports* aSubject, const char* aTopic, const char16_t* aData)
- {
--  fprintf(stderr, "NSM got browser-ui-startup-complete\n");
-   LoadEntries();
-   return NS_OK;
- }
- 
- void
- ServiceWorkerManager::LoadEntries()
- {
-   // Nobody should be using ServiceWorker yet.
-@@ -553,16 +551,17 @@ ServiceWorkerManager::Register(nsIDOMWin
-       return NS_OK;
-     }
- 
-     nsRefPtr<ServiceWorker> serviceWorker;
-     nsresult rv =
-       CreateServiceWorkerForWindow(window,
-                                    registration->mScriptSpec,
-                                    registration->mScope,
-+                                   ServiceWorkerLoadTypeNoUpdate,
-                                    getter_AddRefs(serviceWorker));
- 
-     if (NS_WARN_IF(NS_FAILED(rv))) {
-       return NS_ERROR_FAILURE;
-     }
- 
-     promise->MaybeResolve(serviceWorker);
-     promise.forget(aPromise);
-@@ -595,25 +594,35 @@ ServiceWorkerManager::Register(nsIDOMWin
- 
- NS_IMETHODIMP
- ServiceWorkerManager::Update(ServiceWorkerRegistration* aRegistration,
-                              nsPIDOMWindow* aWindow)
- {
-   // FIXME(nsm): If we don't need to fetch & install, resolve promise and skip
-   // this.
-   // FIXME(nsm): Force cache update if > 1 day.
--
--  nsRefPtr<ServiceWorkerFetcher> fetcher = new ServiceWorkerFetcher();
--  nsresult rv = fetcher->asyncFetch(this, aRegistration, aWindow);
--  if (NS_WARN_IF(NS_FAILED(rv))) {
--    RejectRegisterPromises(aRegistration->mScriptSpec, rv);
--    return rv;
-+  // FIXME(nsm): Make sure an instance of this worker isn't already running.
-+  fprintf(stderr, "\n\nNSM beginning update for %s\n\n", aRegistration->mScriptSpec.get());
-+  nsRefPtr<ServiceWorker> serviceWorker;
-+  if (aWindow) {
-+    nsresult rv = CreateServiceWorkerForWindow(aWindow,
-+                                               aRegistration->mScriptSpec,
-+                                               aRegistration->mScope,
-+                                               ServiceWorkerLoadTypeUpdate,
-+                                               getter_AddRefs(serviceWorker));
-+    if (NS_WARN_IF(NS_FAILED(rv))) {
-+      RejectRegisterPromises(aRegistration->mScriptSpec, rv);
-+      return rv;
-+    }
-+  } else {
-+    // FIXME(nsm): Non-window branch.
-+    MOZ_CRASH("Not implemented!");
-   }
- 
--  mBeingFetched.Put(aRegistration->mScriptSpec, fetcher);
-+  MOZ_ASSERT(serviceWorker);
-   return NS_OK;
- }
- 
- // If we return an error, ServiceWorkerContainer will reject the Promise.
- NS_IMETHODIMP
- ServiceWorkerManager::Unregister(nsIDOMWindow* aWindow, const nsAString& aScope,
-                                  nsISupports** aPromise)
- {
-@@ -678,16 +687,17 @@ ServiceWorkerManager::Unregister(nsIDOMW
-   }
- 
-   // FIXME(nsm): Does a queuedWorker get "deactivate"?
- 
-   nsRefPtr<ServiceWorker> serviceWorker;
-   rv = CreateServiceWorkerForWindow(window,
-                                     registration->mCurrentWorker->mScriptSpec,
-                                     registration->mScope,
-+                                    ServiceWorkerLoadTypeNoUpdate,
-                                     getter_AddRefs(serviceWorker));
- 
-   if (NS_WARN_IF(NS_FAILED(rv))) {
-     return rv;
-   }
- 
-   AutoSafeJSContext cx;
-   nsRefPtr<WorkerRunnable> r =
-@@ -703,45 +713,44 @@ ServiceWorkerManager::Unregister(nsIDOMW
-   domainInfo->mServiceWorkerRegistrations.Remove(registration->mScope);
-   SaveEntries();
-   return NS_OK;
- }
- 
- NS_IMETHODIMP
- ServiceWorkerManager::GetDocumentController(nsIDocument* aDoc, nsISupports** aServiceWorker)
- {
--    fprintf(stderr, "\n\n\n\n\n NSM CALL FOR CHECK \n\n\n\n");
-   // FIXME(nsm): There may not always be a running service worker.
-   // In addition, we usually want to create a shell ServiceWorker, with no
-   // backing WorkerPrivate, and instantiate the worker only on requests or
-   // postMessage. And be willing to kill it again fast.
-   MOZ_ASSERT(NS_IsMainThread());
-   MOZ_ASSERT(aDoc);
- 
-   ServiceWorkerRegistration* registration = nullptr;
-   if (!FindPossibleController(aDoc, &registration)) {
-     return NS_ERROR_NOT_AVAILABLE;
-   }
- 
-   if (!registration->mCurrentWorker) {
--    fprintf(stderr, "\n\n\n\n NSM Complaining because not current!\n\n\n");
-     return NS_ERROR_NOT_AVAILABLE;
-   }
- 
-   if (!registration->mCurrentWorker->mControlledDocuments.Contains(aDoc)) {
-     return NS_ERROR_NOT_AVAILABLE;
-   }
- 
-   // FIXME(nsm): Check activating status.
- 
-   nsRefPtr<ServiceWorker> serviceWorker;
-   nsresult rv =
-     CreateServiceWorkerForDocument(aDoc,
-                                    registration->mScriptSpec,
-                                    registration->mScope,
-+                                   ServiceWorkerLoadTypeNoUpdate,
-                                    getter_AddRefs(serviceWorker));
- 
-   if (NS_WARN_IF(NS_FAILED(rv))) {
-     return rv;
-   }
- 
-   serviceWorker.forget(aServiceWorker);
-   return NS_OK;
-@@ -766,17 +775,19 @@ ServiceWorkerManager::FetchAndParseError
-                                          uint32_t aColumnNumber,
-                                          uint32_t aFlags,
-                                          uint32_t aErrorNumber)
- {
-   AssertIsOnMainThread();
-   // FIXME(nsm): Bug 983497 Fire error on relevant ServiceWorkerContainers.
-   nsAutoPtr<nsTArray<nsTWeakRef<Promise>>> entry;
-   mRegisterPromises.RemoveAndForget(aURL, entry);
--  MOZ_ASSERT(entry);
-+  if (!entry) {
-+    return;
-+  }
- 
-   nsCOMPtr<nsIScriptError> errorObject =
-     do_CreateInstance("@mozilla.org/scripterror;1");
-   if (NS_WARN_IF(!errorObject)) {
-     return;
-   }
- 
-   nsresult rv = errorObject->Init(aMessage, aFilename, aLine,
-@@ -799,17 +810,19 @@ ServiceWorkerManager::FetchAndParseError
-       item->MaybeReject(errorObject);
-     }
-   }
- }
- 
- void
- ServiceWorkerManager::ResolveRegisterPromises(ServiceWorkerRegistration* aRegistration)
- {
--  ResolveRegisterPromises(aRegistration->mScriptSpec, aRegistration->mScope);
-+  ServiceWorkerInfo* newest = aRegistration->Newest();
-+  MOZ_ASSERT(newest);
-+  ResolveRegisterPromises(newest->mScriptSpec, aRegistration->mScope);
- }
- 
- void
- ServiceWorkerManager::ResolveRegisterPromises(const nsACString& aScriptSpec, const nsACString& aScope)
- {
-   nsAutoPtr<nsTArray<nsTWeakRef<Promise>>> entry;
-   mRegisterPromises.RemoveAndForget(aScriptSpec, entry);
-   if (!entry) {
-@@ -832,16 +845,17 @@ ServiceWorkerManager::ResolveRegisterPro
-       JSAutoCompartment ac(cx, global);
- 
-       GlobalObject domGlobal(cx, global);
- 
-       nsRefPtr<ServiceWorker> serviceWorker;
-       nsresult rv = rs->CreateServiceWorker(domGlobal,
-                                             NS_ConvertUTF8toUTF16(aScriptSpec),
-                                             aScope,
-+                                            ServiceWorkerLoadTypeNoUpdate,
-                                             getter_AddRefs(serviceWorker));
-       if (NS_WARN_IF(NS_FAILED(rv))) {
-         // Since ServiceWorkerContainer is only exposed to windows we can be
-         // certain about this cast.
-         nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(go);
-         MOZ_ASSERT(window);
-         nsRefPtr<DOMError> domError = new DOMError(window, NS_ERROR_FAILURE);
-         pendingPromise->MaybeReject(domError);
-@@ -856,79 +870,86 @@ ServiceWorkerManager::ResolveRegisterPro
- void
- ServiceWorkerManager::RejectRegisterPromises(const nsACString& aScriptSpec,
-                                              nsresult aResult)
- {
-   AssertIsOnMainThread();
- 
-   nsAutoPtr<nsTArray<nsTWeakRef<Promise>>> entry;
-   mRegisterPromises.RemoveAndForget(aScriptSpec, entry);
--  MOZ_ASSERT(entry);
-+  if (!entry) {
-+    return;
-+  }
- 
-   for (uint32_t i = 0; i < entry->Length(); ++i) {
-     nsTWeakRef<Promise>& pendingPromise = entry->ElementAt(i);
-     if (pendingPromise) {
-       // Since ServiceWorkerContainer is only exposed to windows we can be
-       // certain about this cast.
-       nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(pendingPromise->GetParentObject());
-       MOZ_ASSERT(window);
-       nsRefPtr<DOMError> domError = new DOMError(window, aResult);
-       pendingPromise->MaybeReject(domError);
-     }
-   }
- }
- 
- // Must NS_Free() aString
- void
--ServiceWorkerManager::FinishFetch(ServiceWorkerFetcher* aFetcher,
--                                  nsresult aStatus, uint32_t aStringLen,
--                                  const uint8_t* aString)
-+ServiceWorkerManager::FinishFetch(const nsACString& aScriptSpec, const nsACString& aScope,
-+                                  bool aFetchSucceeded, bool aUpdated)
- {
-   AssertIsOnMainThread();
- 
--  MOZ_ASSERT(aFetcher);
--
--  nsRefPtr<ServiceWorkerFetcher> kungFuDeathGrip = aFetcher;
--  mBeingFetched.Remove(aFetcher->mRegistration->mScriptSpec);
--
--  if (NS_FAILED(aStatus)) {
--    RejectRegisterPromises(aFetcher->mRegistration->mScriptSpec,
-+  if (!aFetchSucceeded) {
-+    RejectRegisterPromises(aScriptSpec,
-                            NS_ERROR_DOM_NETWORK_ERR);
-     return;
-   }
- 
--  // FIXME(nsm): Check byte wise
--  // FIXME(nsm): Cache aString so ScriptLoader uses it.
-+  ServiceWorkerDomainInfo* domainInfo = GetDomainInfoForURL(aScriptSpec);
-+  MOZ_ASSERT(domainInfo);
- 
--  nsRefPtr<ServiceWorker> worker;
--  nsresult rv = CreateServiceWorkerForWindow(aFetcher->mWindow,
--                                             aFetcher->mRegistration->mScriptSpec,
--                                             aFetcher->mRegistration->mScope,
--                                             getter_AddRefs(worker));
-+  ServiceWorkerRegistration* registration =
-+    domainInfo->mServiceWorkerRegistrations.Get(aScope);
-+  MOZ_ASSERT(registration);
-+
-+  if (registration->Newest() && !aUpdated) {
-+    // We actually have to check byte equality with newest worker and not the
-+    // cached script :(
-+    ResolveRegisterPromises(registration);
-+    return;
-+  }
-+
-+  nsRefPtr<ServiceWorker> serviceWorker;
-+  nsresult rv = CreateServiceWorkerForURLAndScope(aScriptSpec,
-+                                             aScope,
-+                                             ServiceWorkerLoadTypeNoUpdate,
-+                                             getter_AddRefs(serviceWorker));
- 
-   if (NS_WARN_IF(NS_FAILED(rv))) {
--    RejectRegisterPromises(aFetcher->mRegistration->mScriptSpec, rv);
-+    RejectRegisterPromises(aScriptSpec, rv);
-     return;
-   }
- 
-   // If parse succeeds, promises will be resolved with this worker, otherwise
-   // they'll be rejected by error handler.
-   // We don't pass the instance of ServiceWorker because each Promise will need
-   // to create one in it's own window.
-   nsRefPtr<WorkerRunnable> r =
--    new ResolvePromisesOnWorkerParseRunnable(worker->GetWorkerPrivate(),
--                                             aFetcher->mRegistration->mScope);
-+    new ResolvePromisesOnWorkerParseRunnable(serviceWorker->GetWorkerPrivate(), aScope);
-+
-   AutoSafeJSContext cx;
-   if (!r->Dispatch(cx)) {
--    RejectRegisterPromises(aFetcher->mRegistration->mScriptSpec,
-+    RejectRegisterPromises(aScriptSpec,
-                            NS_ERROR_DOM_INVALID_STATE_ERR);
-     return;
-   }
- 
--  Install(aFetcher->mRegistration, worker);
-+  Install(registration, serviceWorker->GetWorkerPrivate());
- }
- 
- NS_IMETHODIMP
- ServiceWorkerManager::FireEventOnServiceWorkerContainers(
-   ServiceWorkerRegistration* aRegistration,
-   ServiceWorkerManager::FireEventFunc aFunc)
- {
-   ServiceWorkerDomainInfo* domainInfo =
-@@ -959,30 +980,28 @@ ServiceWorkerManager::FireEventOnService
-       (this->*aFunc)(target);
-     }
-   }
-   return NS_OK;
- }
- 
- void
- ServiceWorkerManager::Install(ServiceWorkerRegistration* aRegistration,
--                              ServiceWorker* aServiceWorker)
-+                              WorkerPrivate* aWorkerPrivate)
- {
-   if (!aRegistration->mQueuedWorker) {
-     // FIXME(nsm): Clean up queued worker.
-   }
- 
-   FireEventOnServiceWorkerContainers(aRegistration,
-                                      &ServiceWorkerManager::FireInstallEvent);
- 
-   // FIXME(nsm): Bug 982787
-   AutoSafeJSContext cx;
--  nsRefPtr<WorkerRunnable> r =
--    new InstallEventRunnable(aServiceWorker->GetWorkerPrivate(),
--                             aRegistration->mScope);
-+  nsRefPtr<WorkerRunnable> r = new InstallEventRunnable(aWorkerPrivate, aRegistration->mScope);
-   if (!r->Dispatch(cx)) {
-     MOZ_CRASH("Could not dispatch InstallEventRunnable!");
-     return;
-   }
- }
- 
- void
- ServiceWorkerManager::FinishInstall(const nsACString& aDomain,
-@@ -1003,18 +1022,16 @@ ServiceWorkerManager::FinishInstall(cons
-     // FIXME(nsm):
-     MOZ_CRASH("Implement me");
-   }
- 
-   // We can finally queue it up for documents to look up.
-   AddScope(domainInfo->mOrderedScopes, registration->mScope);
- 
-   registration->mQueuedWorker = new ServiceWorkerInfo(registration->mScriptSpec);
--  fprintf(stderr, "\n\n\n\n NSM Queued so don't complain!\n\n\n");
--
-   FireEventOnServiceWorkerContainers(registration,
-                                      &ServiceWorkerManager::FireInstallEndEvent);
-   // FIXME(nsm): Bug 983499, Bug 983497 Fire "installend" on global scope.
-   // FIXME(nsm): Bug 982711. If any handler calls replace, do stuff.
- 
-   SaveEntries();
- 
-   if (!registration->IsControllingDocuments()) {
-@@ -1034,25 +1051,27 @@ ServiceWorkerManager::Activate(ServiceWo
-   nsAutoPtr<ServiceWorkerInfo> exitingWorker = aRegistration->mCurrentWorker;
- 
-   // FIXME(nsm): Deal with current worker cleanup.
- 
-   aRegistration->mCurrentWorker = activatingWorker;
- 
-   // XXXnsm, I'm not sure how this worker's lifetime will go w/o an associated
-   // ServiceWorker or RuntimeService table entries.
--  nsRefPtr<WorkerPrivate> worker = CreateServiceWorkerForRegistration(aRegistration);
-+  nsRefPtr<ServiceWorker> serviceWorker;
-+  nsresult rv =
-+    CreateServiceWorkerForRegistration(aRegistration, getter_AddRefs(serviceWorker));
- 
--  if (NS_WARN_IF(!worker)) {
-+  if (NS_WARN_IF(NS_FAILED(rv))) {
-     // FIXME(nsm): Bug 983497 Fire "error" on relevant NSWs.
-     return;
-   }
- 
-   nsRefPtr<ActivateEventRunnable> r =
--    new ActivateEventRunnable(worker,
-+    new ActivateEventRunnable(serviceWorker->GetWorkerPrivate(),
-                               aRegistration->mScope);
- 
-   AutoSafeJSContext cx;
-   if (!r->Dispatch(cx)) {
-     MOZ_CRASH("Could not dispatch ActivateEventRunnable!");
-     return;
-   }
- 
-@@ -1087,16 +1106,17 @@ ServiceWorkerManager::FinishActivate(con
- 
-   SaveEntries();
- }
- 
- NS_IMETHODIMP
- ServiceWorkerManager::CreateServiceWorkerForWindow(nsPIDOMWindow* aWindow,
-                                                    const nsACString& aScriptSpec,
-                                                    const nsACString& aScope,
-+                                                   ServiceWorkerLoadType aLoadType,
-                                                    ServiceWorker** aServiceWorker)
- {
-   AssertIsOnMainThread();
-   MOZ_ASSERT(aWindow);
- 
-   RuntimeService* rs = RuntimeService::GetOrCreateService();
-   nsRefPtr<ServiceWorker> serviceWorker;
- 
-@@ -1105,30 +1125,32 @@ ServiceWorkerManager::CreateServiceWorke
-   AutoSafeJSContext cx;
-   JS::Rooted<JSObject*> jsGlobal(cx, sgo->GetGlobalJSObject());
-   JSAutoCompartment ac(cx, jsGlobal);
- 
-   GlobalObject global(cx, jsGlobal);
-   nsresult rv = rs->CreateServiceWorker(global,
-                                         NS_ConvertUTF8toUTF16(aScriptSpec),
-                                         aScope,
-+                                        aLoadType,
-                                         getter_AddRefs(serviceWorker));
- 
-   if (NS_WARN_IF(NS_FAILED(rv))) {
-     return rv;
-   }
- 
-   serviceWorker.forget(aServiceWorker);
-   return rv;
- }
- 
- NS_IMETHODIMP
- ServiceWorkerManager::CreateServiceWorkerForDocument(nsIDocument* aDoc,
-                                                      const nsACString& aScriptSpec,
-                                                      const nsACString& aScope,
-+                                                     ServiceWorkerLoadType aLoadType,
-                                                      ServiceWorker** aServiceWorker)
- {
-   MOZ_ASSERT(aDoc);
- 
-   RuntimeService* rs = RuntimeService::GetOrCreateService();
-   nsRefPtr<ServiceWorker> serviceWorker;
- 
-   nsCOMPtr<nsIGlobalObject> sgo = aDoc->GetScopeObject();
-@@ -1136,91 +1158,95 @@ ServiceWorkerManager::CreateServiceWorke
-   AutoSafeJSContext cx;
-   JS::Rooted<JSObject*> jsGlobal(cx, sgo->GetGlobalJSObject());
-   JSAutoCompartment ac(cx, jsGlobal);
- 
-   GlobalObject global(cx, jsGlobal);
-   nsresult rv = rs->CreateServiceWorker(global,
-                                         NS_ConvertUTF8toUTF16(aScriptSpec),
-                                         aScope,
-+                                        aLoadType,
-                                         getter_AddRefs(serviceWorker));
- 
-   if (NS_WARN_IF(NS_FAILED(rv))) {
-     return rv;
-   }
- 
-   serviceWorker.forget(aServiceWorker);
-   return rv;
- }
- 
- // XXXnsm, at some point we'll need to create current or queued or scriptspec.
- // FIXME(nsm): Rename to indicate temporariness of this worker.
--already_AddRefed<WorkerPrivate>
--ServiceWorkerManager::CreateServiceWorkerForRegistration(ServiceWorkerRegistration* aRegistration)
-+// FIXME(nsm): Use Newest() worker?
-+NS_IMETHODIMP
-+ServiceWorkerManager::CreateServiceWorkerForRegistration(ServiceWorkerRegistration* aRegistration, ServiceWorker** aServiceWorker)
- {
-   AssertIsOnMainThread();
-   MOZ_ASSERT(aRegistration);
- 
-+  return CreateServiceWorkerForURLAndScope(aRegistration->mScriptSpec,
-+                                           aRegistration->mScope,
-+                                           ServiceWorkerLoadTypeNoUpdate,
-+                                           aServiceWorker);
-+}
-+
-+NS_IMETHODIMP
-+ServiceWorkerManager::CreateServiceWorkerForURLAndScope(const nsACString& aScriptSpec,
-+                                                        const nsACString& aScope,
-+                                                        ServiceWorkerLoadType aLoadType,
-+                                                        ServiceWorker** aServiceWorker)
-+{
-   WorkerPrivate::LoadInfo info;
--  nsresult rv = NS_NewURI(getter_AddRefs(info.mBaseURI), aRegistration->mScriptSpec, nullptr, nullptr);
-+  nsresult rv = NS_NewURI(getter_AddRefs(info.mBaseURI), aScriptSpec, nullptr, nullptr);
-   if (NS_WARN_IF(NS_FAILED(rv))) {
--    return nullptr;
-+    return rv;
-   }
- 
-   info.mResolvedScriptURI = info.mBaseURI;
- 
-   rv = info.mBaseURI->GetHost(info.mDomain);
-   if (NS_WARN_IF(NS_FAILED(rv))) {
--    return nullptr;
-+    return rv;
-   }
- 
-   // FIXME(nsm): Create correct principal based on app-ness.
-   nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
-   rv = ssm->GetNoAppCodebasePrincipal(info.mBaseURI, getter_AddRefs(info.mPrincipal));
-   if (NS_WARN_IF(NS_FAILED(rv))) {
--    return nullptr;
-+    return rv;
-   }
- 
-   AutoSafeJSContext cx;
-   ErrorResult error;
- 
--  nsCOMPtr<nsIUUIDGenerator> uuidGen = do_GetService("@mozilla.org/uuid-generator;1");
--  MOZ_ASSERT(uuidGen);
-+  RuntimeService* rs = RuntimeService::GetOrCreateService();
-+  MOZ_ASSERT(rs);
- 
--  nsID id;
--  rv = uuidGen->GenerateUUIDInPlace(&id);
--  char buffer[NSID_LENGTH];
--  id.ToProvidedString(buffer);
--
--  nsCString name;
--  name.AssignASCII(buffer);
--
--  nsRefPtr<WorkerPrivate> worker =
--    WorkerPrivate::Constructor(cx,
--                               NS_ConvertUTF8toUTF16(aRegistration->mScriptSpec),
--                               false /* aIsChromeWorker */, WorkerTypeService,
--                               name, &info, error);
-+  rv = rs->CreateServiceWorker(cx, NS_ConvertUTF8toUTF16(aScriptSpec), aScope,
-+                               info, aLoadType, aServiceWorker);
- 
-   if (NS_WARN_IF(error.Failed())) {
--    return nullptr;
-+    return error.ErrorCode();
-   }
- 
--  return worker.forget();
-+  return NS_OK;
- }
- 
- bool
- ServiceWorkerManager::FindPossibleController(ServiceWorkerDomainInfo* aDomainInfo, nsIURI* aURI, ServiceWorkerRegistration** aInfo)
- {
-   MOZ_ASSERT(aDomainInfo);
-   MOZ_ASSERT(aURI);
-   nsCString path;
-   aURI->GetPath(path);
- 
-   nsCString scope = FindScopeForPath(aDomainInfo->mOrderedScopes, path);
-   if (scope.IsEmpty()) {
-+    NS_WARNING("Empty Scope!");
-     return false;
-   }
- 
-   ServiceWorkerRegistration* registration;
-   if (!aDomainInfo->mServiceWorkerRegistrations.Get(scope, &registration)) {
-       NS_WARNING("No registration found in the domain registrations!");
-     // FIXME(nsm): Is this possible?
-     return false;
-@@ -1248,34 +1274,19 @@ ServiceWorkerManager::FindPossibleContro
-   }
- 
-   return FindPossibleController(domainInfo, aURI, aInfo);
- }
- 
- bool
- ServiceWorkerManager::FindPossibleController(nsIDocument* aDoc, ServiceWorkerRegistration** aInfo)
- {
--  MOZ_ASSERT(aDoc);
--  nsCString domain;
--  nsIPrincipal* nodePrincipal = aDoc->NodePrincipal();
--  MOZ_ASSERT(nodePrincipal);
--  nsresult rv = nodePrincipal->GetBaseDomain(domain);
--  if (NS_WARN_IF(NS_FAILED(rv))) {
--    return false;
--  }
--
--  ServiceWorkerDomainInfo* domainInfo;
--  if (!mDomainMap.Get(domain, &domainInfo)) {
--    fprintf(stderr, "NSM FindPossibleController no information found for domain \"%s\"\n", domain.get());
--    return false;
--  }
--
-   nsCOMPtr<nsIURI> uri = aDoc->GetDocumentURIObject();
- 
--  return FindPossibleController(domainInfo, uri, aInfo);
-+  return FindPossibleController(uri, aInfo);
- }
- 
- NS_IMETHODIMP
- ServiceWorkerManager::MaybeStartControlling(nsIDocument* aDoc)
- {
-   MOZ_ASSERT(NS_IsMainThread());
-   MOZ_ASSERT(aDoc);
- 
-@@ -1420,17 +1431,17 @@ ServiceWorkerManager::GetDomainInfoForUR
-   if (NS_WARN_IF(NS_FAILED(rv))) {
-     return nullptr;
-   }
- 
-   return mDomainMap.Get(domain);
- }
- 
- ServiceWorkerManager::ServiceWorkerDomainInfo*
--ServiceWorkerManager::GetDomainInfoForURL(const nsCString& aURL)
-+ServiceWorkerManager::GetDomainInfoForURL(const nsACString& aURL)
- {
-   AssertIsOnMainThread();
-   nsCOMPtr<nsIURI> uri;
-   nsresult rv = NS_NewURI(getter_AddRefs(uri), aURL, nullptr, nullptr);
-   if (NS_WARN_IF(NS_FAILED(rv))) {
-     return nullptr;
-   }
- 
-@@ -1867,16 +1878,17 @@ ServiceWorkerManager::SendFetchEvent(nsI
-   }
- 
-   // FIXME(nsm): If activating, wait.
- 
-   nsRefPtr<ServiceWorker> serviceWorker;
-   nsresult rv = CreateServiceWorkerForDocument(aOriginator,
-                                                current->mScriptSpec,
-                                                registration->mScope,
-+                                               ServiceWorkerLoadTypeNoUpdate,
-                                                getter_AddRefs(serviceWorker));
-   if (NS_WARN_IF(NS_FAILED(rv))) {
-     return NS_ERROR_FAILURE;
-   }
- 
-   MOZ_ASSERT(serviceWorker);
- 
-   // FIXME(nsm): If the fetch is for the service worker, pass through.
-@@ -1923,46 +1935,50 @@ ServiceWorkerManager::SendNavigationEven
-   MOZ_ASSERT(registration);
-   ServiceWorkerInfo* current = registration->mCurrentWorker;
-   if (!current) {
-     return NS_ERROR_NOT_AVAILABLE;
-   }
- 
-   // FIXME(nsm): If activating, wait.
- 
--  nsRefPtr<WorkerPrivate> worker =
--    CreateServiceWorkerForRegistration(registration);
--  if (!worker) {
--    return NS_ERROR_FAILURE;
-+  nsRefPtr<ServiceWorker> serviceWorker;
-+  rv =
-+    CreateServiceWorkerForRegistration(registration,
-+                                       getter_AddRefs(serviceWorker));
-+  if (NS_WARN_IF(NS_FAILED(rv))) {
-+    return rv;
-   }
- 
--  MOZ_ASSERT(worker);
-+  MOZ_ASSERT(serviceWorker);
- 
-   // FIXME(nsm): If the fetch is for the service worker, pass through.
-   nsMainThreadPtrHandle<nsIAlternateSourceChannel> mainThreadChannel =
-     new nsMainThreadPtrHolder<nsIAlternateSourceChannel>(aChannel);
- 
-   nsRefPtr<FetchEventRunnable> fetch =
--    new FetchEventRunnable(worker, nullptr,
-+    new FetchEventRunnable(serviceWorker->GetWorkerPrivate(), nullptr,
-                            mainThreadChannel, true, true);
- 
-   AutoSafeJSContext cx;
-   if (!fetch->Dispatch(cx)) {
-     return NS_ERROR_FAILURE;
-   }
-   return NS_OK;
- }
- 
- NS_IMETHODIMP
- ServiceWorkerManager::IsControlled(nsIDocument* aDoc, bool* aControlled)
- {
-   MOZ_ASSERT(NS_IsMainThread());
- 
-   ServiceWorkerRegistration* registration;
-   *aControlled = FindPossibleController(aDoc, &registration);
-+  // FIXME(nsm): Also check mControlledDocuments because the document may have
-+  // been loaded before the SW was registered..
-   return NS_OK;
- }
- 
- NS_IMETHODIMP
- ServiceWorkerManager::IsControlledURI(nsIURI* aURI, bool* aControlled)
- {
-   MOZ_ASSERT(NS_IsMainThread());
- 
-@@ -1973,38 +1989,26 @@ ServiceWorkerManager::IsControlledURI(ns
- 
- // Testing only.
- NS_IMETHODIMP
- ServiceWorkerManager::GetControllingWorkerScriptURLForPath(nsIDocument* aDoc,
-                                                            const nsAString& aPath,
-                                                            nsAString& aScriptURL)
- {
-   MOZ_ASSERT(aDoc);
--  nsCString domain;
--  nsIPrincipal* nodePrincipal = aDoc->NodePrincipal();
--  MOZ_ASSERT(nodePrincipal);
--  nsresult rv = nodePrincipal->GetBaseDomain(domain);
--  if (NS_WARN_IF(NS_FAILED(rv))) {
--    return rv;
--  }
--
--  ServiceWorkerDomainInfo* domainInfo;
--  if (!mDomainMap.Get(domain, &domainInfo)) {
--    fprintf(stderr, "NSM FindPossibleController no information found for domain %s\n", domain.get());
--    return NS_ERROR_FAILURE;
--  }
- 
-   nsCOMPtr<nsIURI> uri;
--  rv = NS_NewURI(getter_AddRefs(uri), aPath, nullptr, aDoc->GetDocumentURI());
-+  nsresult rv =
-+    NS_NewURI(getter_AddRefs(uri), aPath, nullptr, aDoc->GetDocumentURI());
-   if (NS_WARN_IF(NS_FAILED(rv))) {
-     return rv;
-   }
- 
-   ServiceWorkerRegistration *registration;
--  if (!FindPossibleController(domainInfo, uri, &registration)) {
-+  if (!FindPossibleController(uri, &registration)) {
-     return NS_ERROR_FAILURE;
-   }
- 
-   MOZ_ASSERT(registration);
-   aScriptURL = NS_ConvertUTF8toUTF16(registration->mScriptSpec);
-   return NS_OK;
- }
- 
-diff --git a/dom/workers/ServiceWorkerManager.h b/dom/workers/ServiceWorkerManager.h
---- a/dom/workers/ServiceWorkerManager.h
-+++ b/dom/workers/ServiceWorkerManager.h
-@@ -135,19 +135,16 @@ public:
- 
-   // FIXME(nsm): What do we do if a page calls for register("/foo_worker.js", { scope: "/*"
-   // }) and then another page calls register("/bar_worker.js", { scope: "/*" })
-   // while the install is in progress. The async install steps for register
-   // bar_worker.js could finish before foo_worker.js, but bar_worker still has
-   // to be the winning controller.
-   // FIXME(nsm): Move this into per domain?
- 
--  // URL to fetcher.
--  nsRefPtrHashtable<nsCStringHashKey, ServiceWorkerFetcher> mBeingFetched;
--
-   // the Promise's are the return value of `register()` and will be
-   // resolved/rejected based on the fetch/parse/install.
-   // Indexed by script URL sent in for register().
-   nsClassHashtable<nsCStringHashKey, nsTArray<nsTWeakRef<Promise>>> mRegisterPromises;
- 
-   nsresult
-   CreateServiceWorkerInternal(JSContext* aCx,
-                               nsPIDOMWindow* aWindow,
-@@ -169,19 +166,18 @@ public:
- 
-   void
-   ResolveRegisterPromises(const nsACString& aScriptSpec, const nsACString& aScope);
- 
-   void
-   RejectRegisterPromises(const nsACString& aScriptSpec, nsresult aResult);
- 
-   void
--  FinishFetch(ServiceWorkerFetcher* aFetcher,
--              nsresult aStatus, uint32_t aStringLen,
--              const uint8_t* aString);
-+  FinishFetch(const nsACString& aScriptSpec, const nsACString& aScope,
-+              bool aFetchSucceeded, bool aUpdated);
- 
-   void
-   FinishInstall(const nsACString& aDomain, const nsACString& aScriptSpec);
- 
-   void
-   FinishActivate(const nsACString& aDomain, const nsACString& aScriptSpec);
- 
-   static ServiceWorkerManager* GetInstance();
-@@ -190,17 +186,17 @@ private:
-   ServiceWorkerManager();
-   ~ServiceWorkerManager();
- 
-   NS_IMETHOD
-   Update(ServiceWorkerRegistration* aRegistration, nsPIDOMWindow* aWindow);
- 
-   void
-   Install(ServiceWorkerRegistration* aRegistration,
--          ServiceWorker* aServiceWorker);
-+          WorkerPrivate* aWorkerPrivate);
- 
-   void
-   Activate(ServiceWorkerRegistration* aRegistration);
- 
-   static bool CleanedScope(const nsACString& aInputScope,
-                            nsCString& cleanedScope);
- 
-   void
-@@ -208,29 +204,38 @@ private:
- 
-   nsCString
-   FindScopeForPath(nsTArray<nsCString>& aList, const nsACString& aPath);
- 
-   void
-   RemoveScope(nsTArray<nsCString>& aList, const nsACString& aScope);
- 
-   NS_IMETHODIMP
-+  CreateServiceWorkerForURLAndScope(const nsACString& aScriptSpec,
-+                                    const nsACString& aScope,
-+                                    ServiceWorkerLoadType aLoadType,
-+                                    ServiceWorker** aServiceWorker);
-+
-+  NS_IMETHODIMP
-   CreateServiceWorkerForWindow(nsPIDOMWindow* aWindow,
-                                const nsACString& aScriptSpec,
-                                const nsACString& aScope,
-+                               ServiceWorkerLoadType aLoadType,
-                                ServiceWorker** aServiceWorker);
- 
-   NS_IMETHOD
-   CreateServiceWorkerForDocument(nsIDocument* aDoc,
-                                  const nsACString& aScriptSpec,
-                                  const nsACString& aScope,
-+                                 ServiceWorkerLoadType aLoadType,
-                                  ServiceWorker** aServiceWorker);
- 
--  already_AddRefed<WorkerPrivate>
--  CreateServiceWorkerForRegistration(ServiceWorkerRegistration* aRegistration);
-+  NS_IMETHOD
-+  CreateServiceWorkerForRegistration(ServiceWorkerRegistration* aRegistration,
-+                                     ServiceWorker** aServiceWorker);
- 
-   NS_IMETHOD
-   FireEventOnServiceWorkerContainers(ServiceWorkerRegistration* aRegistration,
-                                      FireEventFunc aFunc);
- 
-   bool
-   FireInstallEvent(EventTarget* aEventTarget);
- 
-@@ -242,34 +247,30 @@ private:
- 
-   bool
-   FireActivateEndEvent(EventTarget* aEventTarget);
- 
-   ServiceWorkerDomainInfo*
-   GetDomainInfoForURI(nsIURI* aPageURI);
- 
-   ServiceWorkerDomainInfo*
--  GetDomainInfoForURL(const nsCString& aURL);
-+  GetDomainInfoForURL(const nsACString& aURL);
- 
-   bool
-   FindPossibleController(ServiceWorkerDomainInfo* aDomainInfo, nsIURI* aURI,
-                          ServiceWorkerRegistration** aInfo);
- 
-   bool
-   FindPossibleController(nsIURI* aURI, ServiceWorkerRegistration** aInfo);
- 
-   // Finds a candidate to control aDoc. True if found, false on errors or not
-   // found.
-   bool
-   FindPossibleController(nsIDocument* aDoc, ServiceWorkerRegistration** aInfo);
- 
--  // Used to stop controlling a document.
--  bool
--  FindControllingWorkerInfo(nsIDocument* aDoc, ServiceWorkerRegistration** aInfo);
--
-   static PLDHashOperator
-   CleanupServiceWorkerInformation(const nsACString& aDomain,
-                                   ServiceWorkerDomainInfo* aDomainInfo,
-                                   void *aUnused);
- 
-   void
-   LoadEntries();
- 
-diff --git a/dom/workers/ServiceWorkerUtil.cpp b/dom/workers/ServiceWorkerUtil.cpp
-deleted file mode 100644
---- a/dom/workers/ServiceWorkerUtil.cpp
-+++ /dev/null
-@@ -1,146 +0,0 @@
--/* This Source Code Form is subject to the terms of the Mozilla Public
-- * 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 "ServiceWorkerUtil.h"
--
--#include "nsIChannel.h"
--#include "nsIContentPolicy.h"
--#include "nsIDocument.h"
--#include "nsIIOService.h"
--#include "nsIURI.h"
--
--#include "nsContentPolicyUtils.h"
--#include "nsNetUtil.h"
--#include "nsNetCID.h"
--#include "ServiceWorkerManager.h"
--
--BEGIN_WORKERS_NAMESPACE
--
--NS_IMETHODIMP
--ServiceWorkerFetcher::asyncFetch(ServiceWorkerManager* aManager,
--                                 ServiceWorkerRegistration* aRegistration,
--                                 nsPIDOMWindow* aWindow)
--{
--  NS_ENSURE_ARG_POINTER(aManager);
--  NS_ENSURE_ARG_POINTER(aRegistration);
--  NS_ENSURE_ARG_POINTER(aWindow);
--
--#ifdef DEBUG
--  // Strictly a one time use class!
--  MOZ_ASSERT(!mUsed);
--  mUsed = true;
--#endif
--
--  mRegistration = aRegistration;
--  mServiceWorkerManager = aManager;
--  mWindow = aWindow;
--
--  nsCOMPtr<nsIDocument> doc = aWindow->GetExtantDoc();
--  if (!doc) {
--    NS_WARNING("No document!");
--    return NS_ERROR_FAILURE;
--  }
--
--  nsCOMPtr<nsILoadGroup> loadGroup = doc->GetDocumentLoadGroup();
--
--  nsCOMPtr<nsIIOService> ios(do_GetIOService());
--
--  nsresult rv;
--  nsCOMPtr<nsIURI> uri;
--  rv = nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(uri), NS_ConvertUTF8toUTF16(aRegistration->mScriptSpec), doc, nullptr);
--  if (NS_FAILED(rv)) {
--    return NS_ERROR_DOM_SYNTAX_ERR;
--  }
--
--  {
--    nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
--    int16_t shouldLoad = nsIContentPolicy::ACCEPT;
--    rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_SCRIPT, uri,
--                                   doc->NodePrincipal(), doc,
--                                   NS_LITERAL_CSTRING("text/javascript"),
--                                   nullptr, &shouldLoad,
--                                   nsContentUtils::GetContentPolicy(),
--                                   secMan);
--
--    if (NS_FAILED(rv) || NS_CP_REJECTED(shouldLoad)) {
--      if (NS_FAILED(rv) || shouldLoad != nsIContentPolicy::REJECT_TYPE) {
--        return rv = NS_ERROR_CONTENT_BLOCKED;
--      }
--      return rv = NS_ERROR_CONTENT_BLOCKED_SHOW_ALT;
--    }
--  }
--
--  nsCString scheme;
--  rv = uri->GetScheme(scheme);
--  if (NS_WARN_IF(NS_FAILED(rv))) {
--    return rv;
--  }
--
--  // We pass true as the 3rd argument to checkMayLoad here.
--  // This allows workers in sandboxed documents to load data URLs
--  // (and other URLs that inherit their principal from their
--  // creator.)
--  rv = doc->NodePrincipal()->CheckMayLoad(uri, false, true);
--  if (NS_WARN_IF(NS_FAILED(rv))) {
--    return NS_ERROR_DOM_SECURITY_ERR;
--  }
--
--  // FIXME(nsm): Verify CSP.
--
--  uint32_t flags = nsIRequest::INHIBIT_CACHING | nsIRequest::LOAD_BYPASS_CACHE;
--
--  nsCOMPtr<nsIChannel> channel;
--  rv = NS_NewChannel(getter_AddRefs(channel), uri, ios, loadGroup, nullptr,
--                     flags, nullptr);
--  if (NS_WARN_IF(NS_FAILED(rv))) {
--    return rv;
--  }
--
--  nsCOMPtr<nsIStreamLoader> loader;
--  rv = NS_NewStreamLoader(getter_AddRefs(loader), this);
--  if (NS_WARN_IF(NS_FAILED(rv))) {
--    return rv;
--  }
--
--  return channel->AsyncOpen(loader, nullptr);
--}
--
--NS_IMETHODIMP
--ServiceWorkerFetcher::OnStreamComplete(nsIStreamLoader* aLoader, nsISupports* aContext,
--                                       nsresult aStatus, uint32_t aStringLen,
--                                       const uint8_t* aString)
--{
--  fprintf(stderr, "NSM download done %d bytes\n", aStringLen);
--
--  // If we get a 404 or something, indicate failure to SWM.
--  nsCOMPtr<nsIRequest> request;
--  nsresult rv = aLoader->GetRequest(getter_AddRefs(request));
--  if (NS_WARN_IF(NS_FAILED(rv))) {
--    mServiceWorkerManager->FinishFetch(this, rv, 0, nullptr);
--    return NS_OK;
--  }
--
--  nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(request);
--  if (httpChannel) {
--    bool requestSucceeded;
--    rv = httpChannel->GetRequestSucceeded(&requestSucceeded);
--    if (NS_WARN_IF(NS_FAILED(rv))) {
--      mServiceWorkerManager->FinishFetch(this, rv, 0, nullptr);
--      return NS_OK;
--    }
--
--    if (requestSucceeded) {
--      mServiceWorkerManager->FinishFetch(this, aStatus, aStringLen, aString);
--    } else {
--      mServiceWorkerManager->FinishFetch(this, NS_ERROR_NOT_AVAILABLE,
--                                         aStringLen, aString);
--    }
--  }
--
--  return NS_OK;
--}
--
--NS_IMPL_ISUPPORTS1(ServiceWorkerFetcher, nsIStreamLoaderObserver);
--
--END_WORKERS_NAMESPACE
-diff --git a/dom/workers/ServiceWorkerUtil.h b/dom/workers/ServiceWorkerUtil.h
-deleted file mode 100644
---- a/dom/workers/ServiceWorkerUtil.h
-+++ /dev/null
-@@ -1,54 +0,0 @@
--/* This Source Code Form is subject to the terms of the Mozilla Public
-- * 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/. */
--
--#ifndef mozilla_dom_workers_serviceworkerutil_h
--#define mozilla_dom_workers_serviceworkerutil_h
--
--// Local include only.
--#include "nsIStreamLoader.h"
--
--#include "nsCOMPtr.h"
--
--#include "Workers.h"
--
--class nsIDocument;
--
--BEGIN_WORKERS_NAMESPACE
--
--class ServiceWorkerManager;
--class ServiceWorkerRegistration;
--
--class ServiceWorkerFetcher MOZ_FINAL : public nsIStreamLoaderObserver
--{
--  // Static global instance, so kept alive.
--  ServiceWorkerManager* mServiceWorkerManager;
--
--  // Owned by SWM's hashtable. Don't touch.
--  ServiceWorkerRegistration* mRegistration;
--
--  nsCOMPtr<nsPIDOMWindow> mWindow;
--
--  DebugOnly<bool> mUsed;
--public:
--  NS_DECL_ISUPPORTS
--  NS_DECL_NSISTREAMLOADEROBSERVER
--
--  friend class ServiceWorkerManager;
--
--  ServiceWorkerFetcher()
--    : mServiceWorkerManager(nullptr), mRegistration(nullptr)
--#ifdef DEBUG
--    , mUsed(false)
--#endif
--  { }
--
--  virtual ~ServiceWorkerFetcher()
--  { }
--
--  NS_IMETHOD asyncFetch(ServiceWorkerManager* aManager, ServiceWorkerRegistration* aRegistration, nsPIDOMWindow* aWindow);
--};
--
--END_WORKERS_NAMESPACE
--
--#endif // mozilla_dom_workers_serviceworkerutil_h
-diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h
---- a/dom/workers/WorkerPrivate.h
-+++ b/dom/workers/WorkerPrivate.h
-@@ -148,21 +148,23 @@ public:
-     nsCString mDomain;
- 
-     bool mEvalAllowed;
-     bool mReportCSPViolations;
-     bool mXHRParamsAllowed;
-     bool mPrincipalIsSystem;
-     bool mIsInPrivilegedApp;
-     bool mIsInCertifiedApp;
-+    bool mUpdateServiceWorker;
- 
-     LoadInfo()
-     : mEvalAllowed(false), mReportCSPViolations(false),
-       mXHRParamsAllowed(false), mPrincipalIsSystem(false),
--      mIsInPrivilegedApp(false), mIsInCertifiedApp(false)
-+      mIsInPrivilegedApp(false), mIsInCertifiedApp(false),
-+      mUpdateServiceWorker(false)
-     { }
- 
-     void
-     StealFrom(LoadInfo& aOther)
-     {
-       MOZ_ASSERT(!mBaseURI);
-       aOther.mBaseURI.swap(mBaseURI);
- 
-@@ -186,16 +188,17 @@ public:
- 
-       mDomain = aOther.mDomain;
-       mEvalAllowed = aOther.mEvalAllowed;
-       mReportCSPViolations = aOther.mReportCSPViolations;
-       mXHRParamsAllowed = aOther.mXHRParamsAllowed;
-       mPrincipalIsSystem = aOther.mPrincipalIsSystem;
-       mIsInPrivilegedApp = aOther.mIsInPrivilegedApp;
-       mIsInCertifiedApp = aOther.mIsInCertifiedApp;
-+      mUpdateServiceWorker = aOther.mUpdateServiceWorker;
-     }
-   };
- 
- protected:
-   typedef mozilla::ErrorResult ErrorResult;
- 
-   SharedMutex mMutex;
-   mozilla::CondVar mCondVar;
-@@ -599,16 +602,23 @@ public:
-   }
- 
-   void
-   SetXHRParamsAllowed(bool aAllowed)
-   {
-     mLoadInfo.mXHRParamsAllowed = aAllowed;
-   }
- 
-+  bool
-+  UpdateServiceWorker()
-+  {
-+    MOZ_ASSERT(IsServiceWorker());
-+    return mLoadInfo.mUpdateServiceWorker;
-+  }
-+
-   LocationInfo&
-   GetLocationInfo()
-   {
-     return mLocationInfo;
-   }
- 
-   void
-   CopyJSSettings(JSSettings& aSettings)
-diff --git a/dom/workers/Workers.h b/dom/workers/Workers.h
---- a/dom/workers/Workers.h
-+++ b/dom/workers/Workers.h
-@@ -171,16 +171,22 @@ enum WorkerType
- };
- 
- enum WorkerPreference
- {
-   WORKERPREF_DUMP = 0, // browser.dom.window.dump.enabled
-   WORKERPREF_COUNT
- };
- 
-+enum ServiceWorkerLoadType
-+{
-+  ServiceWorkerLoadTypeNoUpdate = 0, // always load from offline cache. Only for ServiceWorker.
-+  ServiceWorkerLoadTypeUpdate // always load from network. Only for ServiceWorker.
-+};
-+
- // All of these are implemented in RuntimeService.cpp
- bool
- ResolveWorkerClasses(JSContext* aCx, JS::Handle<JSObject*> aObj, JS::Handle<jsid> aId,
-                      unsigned aFlags, JS::MutableHandle<JSObject*> aObjp);
- 
- void
- CancelWorkersForWindow(nsPIDOMWindow* aWindow);
- 
-diff --git a/dom/workers/moz.build b/dom/workers/moz.build
---- a/dom/workers/moz.build
-+++ b/dom/workers/moz.build
-@@ -52,17 +52,16 @@ SOURCES += [
-     'Principal.cpp',
-     'RegisterBindings.cpp',
-     'RuntimeService.cpp',
-     'ScriptLoader.cpp',
-     'ServiceWorker.cpp',
-     'ServiceWorkerContainer.cpp',
-     'ServiceWorkerEvents.cpp',
-     'ServiceWorkerManager.cpp',
--    'ServiceWorkerUtil.cpp',
-     'SharedWorker.cpp',
-     'URL.cpp',
-     'WorkerPrivate.cpp',
-     'WorkerRunnable.cpp',
-     'WorkerScope.cpp',
-     'XMLHttpRequest.cpp',
-     'XMLHttpRequestUpload.cpp',
- ]
--- a/series
+++ b/series
@@ -11,17 +11,16 @@ sw-push-mix
 903441-navigation-event
 903441-setup-request
 903441-intercepts
 903441-sw-nointercept
 foo
 898524-cache
 sw-install-tests2
 sw-more-install-tests
-931249-caching1
 943704-importscripts
 939636-toolkit
 939636-browser
 939636-testing
 939636-dom
 939636-promiseglobal
 939636-promisejsm
 promise-nsresult