Bug 1216697 - Unship Request.cache until the implementation is finished; r=bzbarsky
authorEhsan Akhgari <ehsan@mozilla.com>
Fri, 23 Oct 2015 10:25:03 -0400
changeset 304524 f4bed10ca33fd918a8c668e50e70c3b12ef4379c
parent 304523 1ca90786e46d5dcd9ced892ddf6c223676cd4550
child 304525 88b02bfcc8c760175cade1ae211e49d0a21349a4
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs1216697
milestone44.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 1216697 - Unship Request.cache until the implementation is finished; r=bzbarsky
dom/fetch/Request.cpp
dom/fetch/Request.h
dom/tests/mochitest/fetch/fetch_test_framework.js
dom/tests/mochitest/fetch/mochitest.ini
dom/tests/mochitest/fetch/sw_reroute.js
dom/tests/mochitest/fetch/test_request_cache.html
dom/webidl/Request.webidl
dom/workers/RuntimeService.cpp
dom/workers/WorkerPrivate.h
dom/workers/Workers.h
modules/libpref/init/all.js
--- a/dom/fetch/Request.cpp
+++ b/dom/fetch/Request.cpp
@@ -59,16 +59,35 @@ Request::RequestContextEnabled(JSContext
   WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
   if (!workerPrivate) {
     return false;
   }
 
   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<InternalRequest>
 Request::GetInternalRequest()
 {
   RefPtr<InternalRequest> r = mRequest;
   return r.forget();
 }
 
 namespace {
--- a/dom/fetch/Request.h
+++ b/dom/fetch/Request.h
@@ -31,16 +31,18 @@ class Request final : public nsISupports
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Request)
 
 public:
   Request(nsIGlobalObject* aOwner, InternalRequest* aRequest);
 
   static bool
   RequestContextEnabled(JSContext* aCx, JSObject* aObj);
+  static bool
+  RequestCacheEnabled(JSContext* aCx, JSObject* aObj);
 
   JSObject*
   WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override
   {
     return RequestBinding::Wrap(aCx, this, aGivenProto);
   }
 
   void
--- a/dom/tests/mochitest/fetch/fetch_test_framework.js
+++ b/dom/tests/mochitest/fetch/fetch_test_framework.js
@@ -2,17 +2,18 @@ function testScript(script) {
   // reroute.html should have set this variable if a service worker is present!
   if (!("isSWPresent" in window)) {
     window.isSWPresent = false;
   }
 
   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]]
       }, resolve);
     });
   }
 
   function workerTest() {
--- a/dom/tests/mochitest/fetch/mochitest.ini
+++ b/dom/tests/mochitest/fetch/mochitest.ini
@@ -31,14 +31,15 @@ skip-if = buildapp == 'b2g' # Bug 113768
 [test_fetch_cors.html]
 skip-if = buildapp == 'b2g' || (toolkit == 'android' && debug) # Bug 1210552 && 1210282
 [test_fetch_cors_sw_reroute.html]
 skip-if = buildapp == 'b2g' || (toolkit == 'android' && debug) # Bug 1137683 && 1210282
 [test_formdataparsing.html]
 [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
 [test_response.html]
 [test_response_sw_reroute.html]
 skip-if = buildapp == 'b2g' # Bug 1137683
--- a/dom/tests/mochitest/fetch/sw_reroute.js
+++ b/dom/tests/mochitest/fetch/sw_reroute.js
@@ -5,17 +5,18 @@ function testScript(script) {
     gRegistration = registration;
 
     var iframe = document.createElement("iframe");
     iframe.src = "reroute.html?" + script.replace(".js", "");
     document.body.appendChild(iframe);
   }
 
   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]]
   }, function() {
     navigator.serviceWorker.ready.then(setupSW);
     navigator.serviceWorker.register("reroute.js", {scope: "/"});
   });
 }
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/fetch/test_request_cache.html
@@ -0,0 +1,19 @@
+<!--
+  Any copyright is dedicated to the Public Domain.
+  http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Make sure that Request.cache is not exposed by default</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<script>
+var req = new Request("");
+ok(!("cache" in req), "Request.cache should not be exposed by default");
+</script>
+</body>
+</html>
+
--- a/dom/webidl/Request.webidl
+++ b/dom/webidl/Request.webidl
@@ -17,16 +17,17 @@ interface Request {
   readonly attribute USVString url;
   [SameObject] readonly attribute Headers headers;
 
   [Func="mozilla::dom::Request::RequestContextEnabled"]
   readonly attribute RequestContext context;
   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;
 
   [Throws,
    NewObject] Request clone();
 
   // Bug 1124638 - Allow chrome callers to set the context.
   [ChromeOnly]
--- a/dom/workers/RuntimeService.cpp
+++ b/dom/workers/RuntimeService.cpp
@@ -164,16 +164,17 @@ static_assert(MAX_WORKERS_PER_DOMAIN >= 
 #define PREF_DOM_SERVICEWORKERNOTIFICATION_ENABLED  "dom.webnotifications.serviceworker.enabled"
 #define PREF_WORKERS_LATEST_JS_VERSION "dom.workers.latestJSVersion"
 #define PREF_INTL_ACCEPT_LANGUAGES     "intl.accept_languages"
 #define PREF_SERVICEWORKERS_ENABLED    "dom.serviceWorkers.enabled"
 #define PREF_SERVICEWORKERS_TESTING_ENABLED "dom.serviceWorkers.testing.enabled"
 #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"
 
 namespace {
 
 const uint32_t kNoIndex = uint32_t(-1);
 
 const JS::ContextOptions kRequiredContextOptions =
@@ -1957,16 +1958,20 @@ RuntimeService::Init()
                                   PREF_SERVICEWORKERS_TESTING_ENABLED,
                                   reinterpret_cast<void *>(WORKERPREF_SERVICEWORKERS_TESTING))) ||
       NS_FAILED(Preferences::RegisterCallbackAndCall(
                                   WorkerPrefChanged,
                                   PREF_PUSH_ENABLED,
                                   reinterpret_cast<void *>(WORKERPREF_PUSH))) ||
       NS_FAILED(Preferences::RegisterCallbackAndCall(
                                   WorkerPrefChanged,
+                                  PREF_REQUESTCACHE_ENABLED,
+                                  reinterpret_cast<void *>(WORKERPREF_REQUESTCACHE))) ||
+      NS_FAILED(Preferences::RegisterCallbackAndCall(
+                                  WorkerPrefChanged,
                                   PREF_REQUESTCONTEXT_ENABLED,
                                   reinterpret_cast<void *>(WORKERPREF_REQUESTCONTEXT))) ||
       NS_FAILED(Preferences::RegisterCallbackAndCall(
                                   WorkerPrefChanged,
                                   PREF_OFFSCREENCANVAS_ENABLED,
                                   reinterpret_cast<void *>(WORKERPREF_OFFSCREENCANVAS))) ||
       NS_FAILED(Preferences::RegisterCallback(LoadRuntimeOptions,
                                               PREF_JS_OPTIONS_PREFIX,
@@ -2200,16 +2205,20 @@ RuntimeService::Cleanup()
                                   PREF_DOM_SERVICEWORKERNOTIFICATION_ENABLED,
                                   reinterpret_cast<void *>(WORKERPREF_DOM_SERVICEWORKERNOTIFICATION))) ||
         NS_FAILED(Preferences::UnregisterCallback(
                                   WorkerPrefChanged,
                                   PREF_PUSH_ENABLED,
                                   reinterpret_cast<void *>(WORKERPREF_PUSH))) ||
         NS_FAILED(Preferences::UnregisterCallback(
                                   WorkerPrefChanged,
+                                  PREF_REQUESTCACHE_ENABLED,
+                                  reinterpret_cast<void *>(WORKERPREF_REQUESTCACHE))) ||
+        NS_FAILED(Preferences::UnregisterCallback(
+                                  WorkerPrefChanged,
                                   PREF_REQUESTCONTEXT_ENABLED,
                                   reinterpret_cast<void *>(WORKERPREF_REQUESTCONTEXT))) ||
         NS_FAILED(Preferences::UnregisterCallback(
                                   WorkerPrefChanged,
                                   PREF_OFFSCREENCANVAS_ENABLED,
                                   reinterpret_cast<void *>(WORKERPREF_OFFSCREENCANVAS))) ||
 #if DUMP_CONTROLLED_BY_PREF
         NS_FAILED(Preferences::UnregisterCallback(
@@ -2783,16 +2792,17 @@ RuntimeService::WorkerPrefChanged(const 
 #ifdef DUMP_CONTROLLED_BY_PREF
     case WORKERPREF_DUMP:
 #endif
     case WORKERPREF_INTERCEPTION_ENABLED:
     case WORKERPREF_INTERCEPTION_OPAQUE_ENABLED:
     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);
       break;
 
     default:
       MOZ_ASSERT_UNREACHABLE("Invalid pref key");
       break;
--- a/dom/workers/WorkerPrivate.h
+++ b/dom/workers/WorkerPrivate.h
@@ -1303,16 +1303,23 @@ public:
   bool
   PushEnabled() const
   {
     AssertIsOnWorkerThread();
     return mPreferences[WORKERPREF_PUSH];
   }
 
   bool
+  RequestCacheEnabled() const
+  {
+    AssertIsOnWorkerThread();
+    return mPreferences[WORKERPREF_REQUESTCACHE];
+  }
+
+  bool
   RequestContextEnabled() const
   {
     AssertIsOnWorkerThread();
     return mPreferences[WORKERPREF_REQUESTCONTEXT];
   }
 
   bool
   OffscreenCanvasEnabled() const
--- a/dom/workers/Workers.h
+++ b/dom/workers/Workers.h
@@ -203,16 +203,17 @@ enum WorkerPreference
   WORKERPREF_INTERCEPTION_ENABLED, // dom.serviceWorkers.interception.enabled
   WORKERPREF_DOM_WORKERNOTIFICATION, // dom.webnotifications.workers.enabled
   WORKERPREF_DOM_SERVICEWORKERNOTIFICATION, // dom.webnotifications.serviceworker.enabled
   WORKERPREF_DOM_CACHES_TESTING, // dom.caches.testing.enabled
   WORKERPREF_SERVICEWORKERS_TESTING, // dom.serviceWorkers.testing.enabled
   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
 };
 
 // Implemented in WorkerPrivate.cpp
 
 struct WorkerLoadInfo
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -5093,16 +5093,19 @@ pref("memory.report_concurrency", 1);
 #else
 // Desktop probably doesn't have swapped-out children like that.
 pref("memory.report_concurrency", 10);
 #endif
 
 // 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);
 
 pref("dom.mozKillSwitch.enabled", false);
 
 pref("toolkit.pageThumbs.screenSizeDivisor", 7);
 pref("toolkit.pageThumbs.minWidth", 0);
 pref("toolkit.pageThumbs.minHeight", 0);