diff --git a/dom/fetch/Request.cpp b/dom/fetch/Request.cpp index d5fe048b7fa..f65b885e0b8 100644 --- a/dom/fetch/Request.cpp +++ b/dom/fetch/Request.cpp @@ -64,6 +64,25 @@ Request::RequestContextEnabled(JSContext* aCx, JSObject* aObj) return workerPrivate->RequestContextEnabled(); } +// static +bool +Request::RequestCacheEnabled(JSContext* aCx, JSObject* aObj) +{ + if (NS_IsMainThread()) { + return Preferences::GetBool("dom.requestcache.enabled", false); + } + + using namespace workers; + + // Otherwise, check the pref via the WorkerPrivate + WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx); + if (!workerPrivate) { + return false; + } + + return workerPrivate->RequestCacheEnabled(); +} + already_AddRefed Request::GetInternalRequest() { diff --git a/dom/fetch/Request.h b/dom/fetch/Request.h index b3a5fa279eb..5679a065a40 100644 --- a/dom/fetch/Request.h +++ b/dom/fetch/Request.h @@ -36,6 +36,8 @@ public: static bool RequestContextEnabled(JSContext* aCx, JSObject* aObj); + static bool + RequestCacheEnabled(JSContext* aCx, JSObject* aObj); JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override diff --git a/dom/tests/mochitest/fetch/fetch_test_framework.js b/dom/tests/mochitest/fetch/fetch_test_framework.js index d1f1a262a5e..02ba4ae72a5 100644 --- a/dom/tests/mochitest/fetch/fetch_test_framework.js +++ b/dom/tests/mochitest/fetch/fetch_test_framework.js @@ -7,7 +7,8 @@ function testScript(script) { function setupPrefs() { return new Promise(function(resolve, reject) { SpecialPowers.pushPrefEnv({ - "set": [["dom.requestcontext.enabled", true], + "set": [["dom.requestcache.enabled", true], + ["dom.requestcontext.enabled", true], ["dom.serviceWorkers.enabled", true], ["dom.serviceWorkers.testing.enabled", true], ["dom.serviceWorkers.exemptFromPerDomainMax", true]] diff --git a/dom/tests/mochitest/fetch/mochitest.ini b/dom/tests/mochitest/fetch/mochitest.ini index 901586eb546..dc01a18aa0d 100644 --- a/dom/tests/mochitest/fetch/mochitest.ini +++ b/dom/tests/mochitest/fetch/mochitest.ini @@ -36,6 +36,7 @@ skip-if = buildapp == 'b2g' || (toolkit == 'android' && debug) # Bug 1137683 && [test_formdataparsing_sw_reroute.html] skip-if = buildapp == 'b2g' # Bug 1137683 [test_request.html] +[test_request_cache.html] [test_request_context.html] [test_request_sw_reroute.html] skip-if = buildapp == 'b2g' # Bug 1137683 diff --git a/dom/tests/mochitest/fetch/sw_reroute.js b/dom/tests/mochitest/fetch/sw_reroute.js index 07f623cc0b9..0525258c6ce 100644 --- a/dom/tests/mochitest/fetch/sw_reroute.js +++ b/dom/tests/mochitest/fetch/sw_reroute.js @@ -10,7 +10,8 @@ function testScript(script) { } SpecialPowers.pushPrefEnv({ - "set": [["dom.serviceWorkers.enabled", true], + "set": [["dom.requestcache.enabled", true], + ["dom.serviceWorkers.enabled", true], ["dom.serviceWorkers.interception.opaque.enabled", true], ["dom.serviceWorkers.testing.enabled", true], ["dom.serviceWorkers.exemptFromPerDomainMax", true]] diff --git a/dom/tests/mochitest/fetch/test_request_cache.html b/dom/tests/mochitest/fetch/test_request_cache.html new file mode 100644 index 00000000000..3f48a690cba --- /dev/null +++ b/dom/tests/mochitest/fetch/test_request_cache.html @@ -0,0 +1,19 @@ + + + + + Make sure that Request.cache is not exposed by default + + + + + + + + diff --git a/dom/webidl/Request.webidl b/dom/webidl/Request.webidl index e0c51b3f147..1ab355f3ac0 100644 --- a/dom/webidl/Request.webidl +++ b/dom/webidl/Request.webidl @@ -22,6 +22,7 @@ interface Request { readonly attribute DOMString referrer; readonly attribute RequestMode mode; readonly attribute RequestCredentials credentials; + [Func="mozilla::dom::Request::RequestCacheEnabled"] readonly attribute RequestCache cache; readonly attribute RequestRedirect redirect; diff --git a/dom/workers/RuntimeService.cpp b/dom/workers/RuntimeService.cpp index a48d28c6701..bd31f5d6507 100644 --- a/dom/workers/RuntimeService.cpp +++ b/dom/workers/RuntimeService.cpp @@ -169,6 +169,7 @@ static_assert(MAX_WORKERS_PER_DOMAIN >= 1, #define PREF_INTERCEPTION_ENABLED "dom.serviceWorkers.interception.enabled" #define PREF_INTERCEPTION_OPAQUE_ENABLED "dom.serviceWorkers.interception.opaque.enabled" #define PREF_PUSH_ENABLED "dom.push.enabled" +#define PREF_REQUESTCACHE_ENABLED "dom.requestcache.enabled" #define PREF_REQUESTCONTEXT_ENABLED "dom.requestcontext.enabled" #define PREF_OFFSCREENCANVAS_ENABLED "gfx.offscreencanvas.enabled" @@ -1960,6 +1961,10 @@ RuntimeService::Init() WorkerPrefChanged, PREF_PUSH_ENABLED, reinterpret_cast(WORKERPREF_PUSH))) || + NS_FAILED(Preferences::RegisterCallbackAndCall( + WorkerPrefChanged, + PREF_REQUESTCACHE_ENABLED, + reinterpret_cast(WORKERPREF_REQUESTCACHE))) || NS_FAILED(Preferences::RegisterCallbackAndCall( WorkerPrefChanged, PREF_REQUESTCONTEXT_ENABLED, @@ -2203,6 +2208,10 @@ RuntimeService::Cleanup() WorkerPrefChanged, PREF_PUSH_ENABLED, reinterpret_cast(WORKERPREF_PUSH))) || + NS_FAILED(Preferences::UnregisterCallback( + WorkerPrefChanged, + PREF_REQUESTCACHE_ENABLED, + reinterpret_cast(WORKERPREF_REQUESTCACHE))) || NS_FAILED(Preferences::UnregisterCallback( WorkerPrefChanged, PREF_REQUESTCONTEXT_ENABLED, @@ -2788,6 +2797,7 @@ RuntimeService::WorkerPrefChanged(const char* aPrefName, void* aClosure) case WORKERPREF_SERVICEWORKERS: case WORKERPREF_SERVICEWORKERS_TESTING: case WORKERPREF_PUSH: + case WORKERPREF_REQUESTCACHE: case WORKERPREF_REQUESTCONTEXT: case WORKERPREF_OFFSCREENCANVAS: sDefaultPreferences[key] = Preferences::GetBool(aPrefName, false); diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h index d18649171cb..13dccfc1d5e 100644 --- a/dom/workers/WorkerPrivate.h +++ b/dom/workers/WorkerPrivate.h @@ -1307,6 +1307,13 @@ public: return mPreferences[WORKERPREF_PUSH]; } + bool + RequestCacheEnabled() const + { + AssertIsOnWorkerThread(); + return mPreferences[WORKERPREF_REQUESTCACHE]; + } + bool RequestContextEnabled() const { diff --git a/dom/workers/Workers.h b/dom/workers/Workers.h index 9a6a4bcce69..422687fbe0b 100644 --- a/dom/workers/Workers.h +++ b/dom/workers/Workers.h @@ -208,6 +208,7 @@ enum WorkerPreference WORKERPREF_INTERCEPTION_OPAQUE_ENABLED, // dom.serviceWorkers.interception.opaque.enabled WORKERPREF_PERFORMANCE_LOGGING_ENABLED, // dom.performance.enable_user_timing_logging WORKERPREF_PUSH, // dom.push.enabled + WORKERPREF_REQUESTCACHE, // dom.requestcache.enabled WORKERPREF_REQUESTCONTEXT, // dom.requestcontext.enabled WORKERPREF_OFFSCREENCANVAS, // gfx.offscreencanvas.enabled WORKERPREF_COUNT diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 836f56abe59..28d1d59c7ae 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -5098,6 +5098,9 @@ pref("memory.report_concurrency", 10); // Add Mozilla AudioChannel APIs. pref("media.useAudioChannelAPI", false); +// Expose Request.cache. Currently disabled since the implementation is incomplete. +pref("dom.requestcache.enabled", false); + // Expose Request.context. Currently disabled since the spec is in flux. pref("dom.requestcontext.enabled", false);