Bug 1465670 P1 Make importScripts() called in a service worker script after install throw NetworkError. r=asuth
authorBen Kelly <ben@wanderview.com>
Tue, 05 Jun 2018 10:49:11 -0700
changeset 421351 ef1dd76af6f97b337a219e119e874f49b278aea6
parent 421350 2628bc75afae2cec4756c3808f395872e5eb8806
child 421352 9eb69a99a087f43cf043235ffd3c4bd6799a33b3
push id104035
push userbkelly@mozilla.com
push dateTue, 05 Jun 2018 17:49:21 +0000
treeherdermozilla-inbound@c8103e36d8cf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1465670
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1465670 P1 Make importScripts() called in a service worker script after install throw NetworkError. r=asuth
dom/workers/ScriptLoader.cpp
--- a/dom/workers/ScriptLoader.cpp
+++ b/dom/workers/ScriptLoader.cpp
@@ -404,17 +404,16 @@ class CacheCreator final : public Promis
 public:
   NS_DECL_ISUPPORTS
 
   explicit CacheCreator(WorkerPrivate* aWorkerPrivate)
     : mCacheName(aWorkerPrivate->ServiceWorkerCacheName())
     , mOriginAttributes(aWorkerPrivate->GetOriginAttributes())
   {
     MOZ_ASSERT(aWorkerPrivate->IsServiceWorker());
-    MOZ_ASSERT(aWorkerPrivate->LoadScriptAsPartOfLoadingServiceWorkerScript());
     AssertIsOnMainThread();
   }
 
   void
   AddLoader(CacheScriptLoader* aLoader)
   {
     AssertIsOnMainThread();
     MOZ_ASSERT(!mCacheStorage);
@@ -832,16 +831,22 @@ private:
   }
 
   bool
   IsMainWorkerScript() const
   {
     return mIsMainScript && mWorkerScriptType == WorkerScript;
   }
 
+  bool
+  IsDebuggerScript() const
+  {
+    return mWorkerScriptType == DebuggerScript;
+  }
+
   void
   CancelMainThreadWithBindingAborted()
   {
     CancelMainThread(NS_BINDING_ABORTED);
   }
 
   void
   CancelMainThread(nsresult aCancelResult)
@@ -907,18 +912,17 @@ private:
   RunInternal()
   {
     AssertIsOnMainThread();
 
     if (IsMainWorkerScript() && mWorkerPrivate->IsServiceWorker()) {
       mWorkerPrivate->SetLoadingWorkerScript(true);
     }
 
-    if (!mWorkerPrivate->IsServiceWorker() ||
-        !mWorkerPrivate->LoadScriptAsPartOfLoadingServiceWorkerScript()) {
+    if (!mWorkerPrivate->IsServiceWorker() || IsDebuggerScript()) {
       for (uint32_t index = 0, len = mLoadInfos.Length(); index < len;
            ++index) {
         nsresult rv = LoadScript(index);
         if (NS_WARN_IF(NS_FAILED(rv))) {
           LoadingFinished(index, rv);
           return rv;
         }
       }
@@ -1784,19 +1788,22 @@ CacheScriptLoader::ResolvedCallback(JSCo
 
   // The ServiceWorkerScriptCache will store data for any scripts it
   // it knows about.  This is always at least the top level script.
   // Depending on if a previous version of the service worker has
   // been installed or not it may also know about importScripts().  We
   // must handle loading and offlining new importScripts() here, however.
   if (aValue.isUndefined()) {
     // If this is the main script or we're not loading a new service worker
-    // then this is an error.  The storage was probably wiped without
-    // removing the service worker registration.
-    if (NS_WARN_IF(mIsWorkerScript || mState != ServiceWorkerState::Parsed)) {
+    // then this is an error.  This can happen for internal reasons, like
+    // storage was probably wiped without removing the service worker
+    // registration.  It can also happen for exposed reasons like the
+    // service worker script calling importScripts() after install.
+    if (NS_WARN_IF(mIsWorkerScript || (mState != ServiceWorkerState::Parsed &&
+                                       mState != ServiceWorkerState::Installing))) {
       Fail(NS_ERROR_DOM_INVALID_STATE_ERR);
       return;
     }
 
     mLoadInfo.mCacheStatus = ScriptLoadInfo::ToBeCached;
     rv = mRunnable->LoadScript(mIndex);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       Fail(rv);