From cd6213057e944203d04eda13e34a44335667d4bc Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Mon, 2 Mar 2015 14:12:00 +0100 Subject: [PATCH] Bug 940273 - Part 2 - Add a pref to enable Service Worker Cache. r=ehsan --- dom/workers/RuntimeService.cpp | 15 +++++++++++++++ dom/workers/WorkerPrivate.h | 7 +++++++ dom/workers/Workers.h | 1 + modules/libpref/init/all.js | 4 ++++ 4 files changed, 27 insertions(+) diff --git a/dom/workers/RuntimeService.cpp b/dom/workers/RuntimeService.cpp index e9353b3b9145..5fdcdffc1522 100644 --- a/dom/workers/RuntimeService.cpp +++ b/dom/workers/RuntimeService.cpp @@ -156,6 +156,7 @@ static_assert(MAX_WORKERS_PER_DOMAIN >= 1, #endif #define PREF_DOM_FETCH_ENABLED "dom.fetch.enabled" +#define PREF_DOM_CACHES_ENABLED "dom.caches.enabled" #define PREF_WORKERS_LATEST_JS_VERSION "dom.workers.latestJSVersion" #define PREF_INTL_ACCEPT_LANGUAGES "intl.accept_languages" @@ -1778,6 +1779,10 @@ RuntimeService::Init() WorkerPrefChanged, PREF_DOM_FETCH_ENABLED, reinterpret_cast(WORKERPREF_DOM_FETCH))) || + NS_FAILED(Preferences::RegisterCallbackAndCall( + WorkerPrefChanged, + PREF_DOM_CACHES_ENABLED, + reinterpret_cast(WORKERPREF_DOM_CACHES))) || NS_FAILED(Preferences::RegisterCallback(LoadRuntimeOptions, PREF_JS_OPTIONS_PREFIX, nullptr)) || @@ -1967,6 +1972,10 @@ RuntimeService::Cleanup() NS_FAILED(Preferences::UnregisterCallback(LoadRuntimeOptions, PREF_WORKERS_OPTIONS_PREFIX, nullptr)) || + NS_FAILED(Preferences::UnregisterCallback( + WorkerPrefChanged, + PREF_DOM_CACHES_ENABLED, + reinterpret_cast(WORKERPREF_DOM_CACHES))) || NS_FAILED(Preferences::UnregisterCallback( WorkerPrefChanged, PREF_DOM_FETCH_ENABLED, @@ -2561,6 +2570,12 @@ RuntimeService::WorkerPrefChanged(const char* aPrefName, void* aClosure) Preferences::GetBool(PREF_DOM_FETCH_ENABLED, false); } + if (key == WORKERPREF_DOM_CACHES) { + key = WORKERPREF_DOM_CACHES; + sDefaultPreferences[WORKERPREF_DOM_CACHES] = + Preferences::GetBool(PREF_DOM_CACHES_ENABLED, false); + } + // This function should never be registered as a callback for a preference it // does not handle. MOZ_ASSERT(key != WORKERPREF_COUNT); diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h index 9551a466501f..0a99a0728fe8 100644 --- a/dom/workers/WorkerPrivate.h +++ b/dom/workers/WorkerPrivate.h @@ -1180,6 +1180,13 @@ public: return mPreferences[WORKERPREF_DOM_FETCH]; } + bool + DOMCachesEnabled() const + { + AssertIsOnWorkerThread(); + return mPreferences[WORKERPREF_DOM_CACHES]; + } + bool OnLine() const { diff --git a/dom/workers/Workers.h b/dom/workers/Workers.h index 671d9ce6d7b5..a7dc565bd2e3 100644 --- a/dom/workers/Workers.h +++ b/dom/workers/Workers.h @@ -166,6 +166,7 @@ enum WorkerPreference { WORKERPREF_DUMP = 0, // browser.dom.window.dump.enabled WORKERPREF_DOM_FETCH,// dom.fetch.enabled + WORKERPREF_DOM_CACHES, // dom.caches.enabled WORKERPREF_COUNT }; diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 196aa15ba8fc..49c07b5add8f 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -4433,6 +4433,10 @@ pref("camera.control.face_detection.enabled", true); // Fetch API. pref("dom.fetch.enabled", false); + +// SW Cache API +pref("dom.caches.enabled", false); + #ifdef MOZ_WIDGET_GONK // Empirically, this is the value returned by hal::GetTotalSystemMemory() // when Flame's memory is limited to 512MiB. If the camera stack determines