Bug 1419771 - Introduce DOMPreferences, a thread-safe access to preferences for DOM - part 18 - FetchObserver API enabled, r=asuth
☠☠ backed out by ccd7b237c433 ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 13 Dec 2017 14:02:46 -0600
changeset 396283 9f40cc12d6c67d9264f28add6bd6b25562fbeaa0
parent 396282 f500a61f564cc349cc75a2ec8b12f2d54c1465a2
child 396284 4b52904694f40be316835a479e70c9a78982eafd
push id33087
push userdluca@mozilla.com
push dateThu, 14 Dec 2017 09:54:55 +0000
treeherdermozilla-central@8062887ff0d9 [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 18 - FetchObserver API enabled, r=asuth
dom/base/DOMPreferences.cpp
dom/base/DOMPreferences.h
dom/fetch/FetchObserver.cpp
dom/fetch/FetchObserver.h
dom/webidl/FetchObserver.webidl
dom/webidl/Request.webidl
dom/workers/WorkerPrefs.h
--- a/dom/base/DOMPreferences.cpp
+++ b/dom/base/DOMPreferences.cpp
@@ -47,16 +47,17 @@ PREF(ServiceWorkersTestingEnabled, "dom.
 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")
 PREF(OffscreenCanvasEnabled, "gfx.offscreencanvas.enabled")
 PREF(WebkitBlinkDirectoryPickerEnabled, "dom.webkitBlink.dirPicker.enabled")
 PREF(NetworkInformationEnabled, "dom.netinfo.enabled")
+PREF(FetchObserverEnabled, "dom.fetchObserver.enabled")
 
 #undef PREF
 
 #define PREF_WEBIDL(name)                              \
   /* static */ bool                                    \
   DOMPreferences::name(JSContext* aCx, JSObject* aObj) \
   {                                                    \
     return DOMPreferences::name();                     \
@@ -70,13 +71,14 @@ PREF_WEBIDL(ServiceWorkersEnabled)
 PREF_WEBIDL(StorageManagerEnabled)
 PREF_WEBIDL(PromiseRejectionEventsEnabled)
 PREF_WEBIDL(PushEnabled)
 PREF_WEBIDL(StreamsEnabled)
 PREF_WEBIDL(RequestContextEnabled)
 PREF_WEBIDL(OffscreenCanvasEnabled)
 PREF_WEBIDL(WebkitBlinkDirectoryPickerEnabled)
 PREF_WEBIDL(NetworkInformationEnabled)
+PREF_WEBIDL(FetchObserverEnabled)
 
 #undef PREF_WEBIDL
 
 } // dom namespace
 } // mozilla namespace
--- a/dom/base/DOMPreferences.h
+++ b/dom/base/DOMPreferences.h
@@ -78,14 +78,18 @@ public:
 
   // Returns true if the dom.webkitBlink.dirPicker.enabled pref is set.
   static bool WebkitBlinkDirectoryPickerEnabled();
   static bool WebkitBlinkDirectoryPickerEnabled(JSContext* aCx, JSObject* aObj);
 
   // Returns true if the dom.netinfo.enabled pref is set.
   static bool NetworkInformationEnabled();
   static bool NetworkInformationEnabled(JSContext* aCx, JSObject* aObj);
+
+  // Returns true if the dom.fetchObserver.enabled pref is set.
+  static bool FetchObserverEnabled();
+  static bool FetchObserverEnabled(JSContext* aCx, JSObject* aObj);
 };
 
 } // dom namespace
 } // mozilla namespace
 
 #endif // mozilla_dom_DOMPreferences_h
--- a/dom/fetch/FetchObserver.cpp
+++ b/dom/fetch/FetchObserver.cpp
@@ -21,34 +21,16 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_IN
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FetchObserver)
 NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
 
 NS_IMPL_ADDREF_INHERITED(FetchObserver, DOMEventTargetHelper)
 NS_IMPL_RELEASE_INHERITED(FetchObserver, DOMEventTargetHelper)
 
-/* static */ bool
-FetchObserver::IsEnabled(JSContext* aCx, JSObject* aGlobal)
-{
-  if (NS_IsMainThread()) {
-    return Preferences::GetBool("dom.fetchObserver.enabled", false);
-  }
-
-  using namespace workers;
-
-  // Otherwise, check the pref via the WorkerPrivate
-  WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
-  if (!workerPrivate) {
-    return false;
-  }
-
-  return workerPrivate->FetchObserverEnabled();
-}
-
 FetchObserver::FetchObserver(nsIGlobalObject* aGlobal,
                              AbortSignal* aSignal)
   : DOMEventTargetHelper(aGlobal)
   , mState(FetchState::Requesting)
 {
   if (aSignal) {
     Follow(aSignal);
   }
--- a/dom/fetch/FetchObserver.h
+++ b/dom/fetch/FetchObserver.h
@@ -16,19 +16,16 @@ namespace dom {
 
 class FetchObserver final : public DOMEventTargetHelper
                           , public AbortFollower
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FetchObserver, DOMEventTargetHelper)
 
-  static bool
-  IsEnabled(JSContext* aCx, JSObject* aGlobal);
-
   FetchObserver(nsIGlobalObject* aGlobal, AbortSignal* aSignal);
 
   JSObject*
   WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 
   FetchState
   State() const;
 
--- a/dom/webidl/FetchObserver.webidl
+++ b/dom/webidl/FetchObserver.webidl
@@ -11,17 +11,17 @@ callback interface ObserverCallback {
 enum FetchState {
   // Pending states
   "requesting", "responding",
   // Final states
   "aborted", "errored", "complete"
 };
 
 [Exposed=(Window,Worker),
- Func="FetchObserver::IsEnabled"]
+ Func="mozilla::dom::DOMPreferences::FetchObserverEnabled"]
 interface FetchObserver : EventTarget {
   readonly attribute FetchState state;
 
   // Events
   attribute EventHandler onstatechange;
   attribute EventHandler onrequestprogress;
   attribute EventHandler onresponseprogress;
 };
--- a/dom/webidl/Request.webidl
+++ b/dom/webidl/Request.webidl
@@ -56,17 +56,17 @@ dictionary RequestInit {
   RequestRedirect redirect;
   DOMString integrity;
 
   [ChromeOnly]
   boolean mozErrors;
 
   AbortSignal? signal;
 
-  [Func="FetchObserver::IsEnabled"]
+  [Func="mozilla::dom::DOMPreferences::FetchObserverEnabled"]
   ObserverCallback observe;
 };
 
 // Gecko currently does not ship RequestContext, so please don't use it in IDL
 // that is exposed to script.
 enum RequestContext {
   "audio", "beacon", "cspreport", "download", "embed", "eventsource", "favicon", "fetch",
   "font", "form", "frame", "hyperlink", "iframe", "image", "imageset", "import",
--- 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.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)
 WORKER_PREF("general.appversion.override", AppVersionOverrideChanged)
 WORKER_PREF("general.platform.override", PlatformOverrideChanged)
 #ifdef JS_GC_ZEAL
 WORKER_PREF("dom.workers.options.gcZeal", LoadGCZealOptions)