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
This commit is contained in:
Nikhil Marathe 2015-03-19 16:39:01 -07:00
parent 17ef920c79
commit 78132f902f
2 changed files with 19 additions and 4 deletions

View File

@ -314,6 +314,7 @@ public:
: mCacheName(aWorkerPrivate->ServiceWorkerCacheName()) : mCacheName(aWorkerPrivate->ServiceWorkerCacheName())
{ {
MOZ_ASSERT(aWorkerPrivate->IsServiceWorker()); MOZ_ASSERT(aWorkerPrivate->IsServiceWorker());
MOZ_ASSERT(aWorkerPrivate->LoadScriptAsPartOfLoadingServiceWorkerScript());
AssertIsOnMainThread(); AssertIsOnMainThread();
} }
@ -645,7 +646,7 @@ private:
} }
if (!mWorkerPrivate->IsServiceWorker() || if (!mWorkerPrivate->IsServiceWorker() ||
mWorkerPrivate->ServiceWorkerCacheName().IsEmpty()) { !mWorkerPrivate->LoadScriptAsPartOfLoadingServiceWorkerScript()) {
for (uint32_t index = 0, len = mLoadInfos.Length(); index < len; for (uint32_t index = 0, len = mLoadInfos.Length(); index < len;
++index) { ++index) {
nsresult rv = LoadScript(index); nsresult rv = LoadScript(index);

View File

@ -487,10 +487,24 @@ public:
{ {
MOZ_ASSERT(IsServiceWorker()); MOZ_ASSERT(IsServiceWorker());
AssertIsOnMainThread(); AssertIsOnMainThread();
return mLoadingWorkerScript ? return mLoadInfo.mServiceWorkerCacheName;
mLoadInfo.mServiceWorkerCacheName : EmptyString();
} }
// 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 void
SetLoadingWorkerScript(bool aLoadingWorkerScript) SetLoadingWorkerScript(bool aLoadingWorkerScript)
{ {