Bug 1419771 - Introduce DOMPreferences, a thread-safe access to preferences for DOM - part 14 - Request Context enabled, r=asuth
☠☠ backed out by ccd7b237c433 ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 13 Dec 2017 14:02:46 -0600
changeset 396304 7e77a00fa8b51c1a053ef6a0f3158883ed0324cb
parent 396303 5f6df771459a9c08bd8dba480ef1d8e1d57e8342
child 396305 1397a6bbb4460fa7b1d4da88cabdcd128dbd1ec9
push id56975
push userdluca@mozilla.com
push dateThu, 14 Dec 2017 09:59:07 +0000
treeherderautoland@16bcfaad13e1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1419771
milestone59.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 1419771 - Introduce DOMPreferences, a thread-safe access to preferences for DOM - part 14 - Request Context enabled, r=asuth
dom/base/DOMPreferences.cpp
dom/base/DOMPreferences.h
dom/fetch/Request.cpp
dom/fetch/Request.h
dom/webidl/Request.webidl
dom/workers/WorkerPrefs.h
--- a/dom/base/DOMPreferences.cpp
+++ b/dom/base/DOMPreferences.cpp
@@ -43,16 +43,17 @@ PREF(NotificationEnabled, "dom.webnotifi
 PREF(NotificationEnabledInServiceWorkers, "dom.webnotifications.serviceworker.enabled")
 PREF(NotificationRIEnabled, "dom.webnotifications.requireinteraction.enabled")
 PREF(ServiceWorkersEnabled, "dom.serviceWorkers.enabled")
 PREF(ServiceWorkersTestingEnabled, "dom.serviceWorkers.testing.enabled")
 PREF(StorageManagerEnabled, "dom.storageManager.enabled")
 PREF(PromiseRejectionEventsEnabled, "dom.promise_rejection_events.enabled")
 PREF(PushEnabled, "dom.push.enabled")
 PREF(StreamsEnabled, "dom.streams.enabled")
+PREF(RequestContextEnabled, "dom.requestcontext.enabled")
 
 #undef PREF
 
 #define PREF_WEBIDL(name)                              \
   /* static */ bool                                    \
   DOMPreferences::name(JSContext* aCx, JSObject* aObj) \
   {                                                    \
     return DOMPreferences::name();                     \
@@ -62,13 +63,14 @@ PREF_WEBIDL(ImageBitmapExtensionsEnabled
 PREF_WEBIDL(DOMCachesEnabled)
 PREF_WEBIDL(NotificationEnabledInServiceWorkers)
 PREF_WEBIDL(NotificationRIEnabled)
 PREF_WEBIDL(ServiceWorkersEnabled)
 PREF_WEBIDL(StorageManagerEnabled)
 PREF_WEBIDL(PromiseRejectionEventsEnabled)
 PREF_WEBIDL(PushEnabled)
 PREF_WEBIDL(StreamsEnabled)
+PREF_WEBIDL(RequestContextEnabled)
 
 #undef PREF_WEBIDL
 
 } // dom namespace
 } // mozilla namespace
--- a/dom/base/DOMPreferences.h
+++ b/dom/base/DOMPreferences.h
@@ -62,14 +62,18 @@ public:
 
   // Returns true if the dom.push.enabled pref is set.
   static bool PushEnabled();
   static bool PushEnabled(JSContext* aCx, JSObject* aObj);
 
   // Returns true if the dom.streams.enabled pref is set.
   static bool StreamsEnabled();
   static bool StreamsEnabled(JSContext* aCx, JSObject* aObj);
+
+  // Returns true if the dom.requestcontext.enabled pref is set.
+  static bool RequestContextEnabled();
+  static bool RequestContextEnabled(JSContext* aCx, JSObject* aObj);
 };
 
 } // dom namespace
 } // mozilla namespace
 
 #endif // mozilla_dom_DOMPreferences_h
--- a/dom/fetch/Request.cpp
+++ b/dom/fetch/Request.cpp
@@ -72,35 +72,16 @@ Request::Request(nsIGlobalObject* aOwner
     }
   }
 }
 
 Request::~Request()
 {
 }
 
-// static
-bool
-Request::RequestContextEnabled(JSContext* aCx, JSObject* aObj)
-{
-  if (NS_IsMainThread()) {
-    return Preferences::GetBool("dom.requestcontext.enabled", false);
-  }
-
-  using namespace workers;
-
-  // Otherwise, check the pref via the WorkerPrivate
-  WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
-  if (!workerPrivate) {
-    return false;
-  }
-
-  return workerPrivate->RequestContextEnabled();
-}
-
 already_AddRefed<InternalRequest>
 Request::GetInternalRequest()
 {
   RefPtr<InternalRequest> r = mRequest;
   return r.forget();
 }
 
 namespace {
--- a/dom/fetch/Request.h
+++ b/dom/fetch/Request.h
@@ -30,19 +30,16 @@ class Request final : public nsISupports
 {
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Request)
 
 public:
   Request(nsIGlobalObject* aOwner, InternalRequest* aRequest,
           AbortSignal* aSignal);
 
-  static bool
-  RequestContextEnabled(JSContext* aCx, JSObject* aObj);
-
   JSObject*
   WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override
   {
     return RequestBinding::Wrap(aCx, this, aGivenProto);
   }
 
   void
   GetUrl(nsAString& aUrl) const
--- a/dom/webidl/Request.webidl
+++ b/dom/webidl/Request.webidl
@@ -12,17 +12,17 @@ typedef unsigned long nsContentPolicyTyp
 
 [Constructor(RequestInfo input, optional RequestInit init),
  Exposed=(Window,Worker)]
 interface Request {
   readonly attribute ByteString method;
   readonly attribute USVString url;
   [SameObject] readonly attribute Headers headers;
 
-  [Func="mozilla::dom::Request::RequestContextEnabled"]
+  [Func="mozilla::dom::DOMPreferences::RequestContextEnabled"]
   readonly attribute RequestContext context;
   readonly attribute USVString referrer;
   readonly attribute ReferrerPolicy referrerPolicy;
   readonly attribute RequestMode mode;
   readonly attribute RequestCredentials credentials;
   readonly attribute RequestCache cache;
   readonly attribute RequestRedirect redirect;
   readonly attribute DOMString integrity;
--- a/dom/workers/WorkerPrefs.h
+++ b/dom/workers/WorkerPrefs.h
@@ -16,17 +16,16 @@
 //     macro in Workers.h.
 //   * The name of the function that updates the new value of a pref.
 //
 //   WORKER_PREF("foo.bar", UpdaterFunction)
 //
 //   * First argument is the name of the pref.
 //   * The name of the function that updates the new value of a pref.
 
-WORKER_SIMPLE_PREF("dom.requestcontext.enabled", RequestContextEnabled, REQUESTCONTEXT_ENABLED)
 WORKER_SIMPLE_PREF("gfx.offscreencanvas.enabled", OffscreenCanvasEnabled, OFFSCREENCANVAS_ENABLED)
 WORKER_SIMPLE_PREF("dom.webkitBlink.dirPicker.enabled", WebkitBlinkDirectoryPickerEnabled, DOM_WEBKITBLINK_DIRPICKER_WEBKITBLINK)
 WORKER_SIMPLE_PREF("dom.netinfo.enabled", NetworkInformationEnabled, NETWORKINFORMATION_ENABLED)
 WORKER_SIMPLE_PREF("dom.fetchObserver.enabled", FetchObserverEnabled, FETCHOBSERVER_ENABLED)
 WORKER_SIMPLE_PREF("privacy.resistFingerprinting", ResistFingerprintingEnabled, RESISTFINGERPRINTING_ENABLED)
 WORKER_SIMPLE_PREF("devtools.enabled", DevToolsEnabled, DEVTOOLS_ENABLED)
 WORKER_PREF("intl.accept_languages", PrefLanguagesChanged)
 WORKER_PREF("general.appname.override", AppNameOverrideChanged)