From 78132f902f0409fbf9f17f2c5e71a53ddcb57829 Mon Sep 17 00:00:00 2001 From: Nikhil Marathe Date: Thu, 19 Mar 2015 16:39:01 -0700 Subject: [PATCH] Bug 931249 - Patch 8 - Provide direct getter to the fact that we are loading a worker instead of relying on cache name. r=khuey --HG-- extra : rebase_source : ad85e2de17f562449f041fcb66a061a319da45f0 --- dom/workers/ScriptLoader.cpp | 3 ++- dom/workers/WorkerPrivate.h | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/dom/workers/ScriptLoader.cpp b/dom/workers/ScriptLoader.cpp index 6ff8f2670f7d..cafc20e64012 100644 --- a/dom/workers/ScriptLoader.cpp +++ b/dom/workers/ScriptLoader.cpp @@ -314,6 +314,7 @@ public: : mCacheName(aWorkerPrivate->ServiceWorkerCacheName()) { MOZ_ASSERT(aWorkerPrivate->IsServiceWorker()); + MOZ_ASSERT(aWorkerPrivate->LoadScriptAsPartOfLoadingServiceWorkerScript()); AssertIsOnMainThread(); } @@ -645,7 +646,7 @@ private: } if (!mWorkerPrivate->IsServiceWorker() || - mWorkerPrivate->ServiceWorkerCacheName().IsEmpty()) { + !mWorkerPrivate->LoadScriptAsPartOfLoadingServiceWorkerScript()) { for (uint32_t index = 0, len = mLoadInfos.Length(); index < len; ++index) { nsresult rv = LoadScript(index); diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h index 374e1b006bee..acf7d87edffe 100644 --- a/dom/workers/WorkerPrivate.h +++ b/dom/workers/WorkerPrivate.h @@ -487,10 +487,24 @@ public: { MOZ_ASSERT(IsServiceWorker()); AssertIsOnMainThread(); - return mLoadingWorkerScript ? - mLoadInfo.mServiceWorkerCacheName : EmptyString(); + return mLoadInfo.mServiceWorkerCacheName; } - + + // This is used to handle importScripts(). When the worker is first loaded + // and executed, it happens in a sync loop. At this point it sets + // mLoadingWorkerScript to true. importScripts() calls that occur during the + // execution run in nested sync loops and so this continues to return true, + // leading to these scripts being cached offline. + // mLoadingWorkerScript is set to false when the top level loop ends. + // importScripts() in function calls or event handlers are always fetched + // from the network. + bool + LoadScriptAsPartOfLoadingServiceWorkerScript() + { + MOZ_ASSERT(IsServiceWorker()); + return mLoadingWorkerScript; + } + void SetLoadingWorkerScript(bool aLoadingWorkerScript) {