Bug 1419771 - Introduce DOMPrefs, a thread-safe access to preferences for DOM - part 22 - DOMPrefs initialized at startup, r=asuth
authorAndrea Marchesini <amarchesini@mozilla.com>
Mon, 08 Jan 2018 14:05:07 +0100
changeset 449993 92324d3a0edfbf21050df048f66ff231fb9a30bf
parent 449992 0c9c890371bd8bcd240ca2b574edcb60ec5a5f9d
child 449994 a44f7f0fa313cbdb2a75fd16ca267bfa8d2de80b
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [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 DOMPrefs, a thread-safe access to preferences for DOM - part 22 - DOMPrefs initialized at startup, r=asuth
dom/base/DOMPrefs.cpp
dom/base/DOMPrefs.h
dom/base/DOMPrefsInternal.h
dom/base/moz.build
dom/ipc/ContentChild.cpp
layout/build/nsLayoutStatics.cpp
layout/style/nsDOMCSSAttrDeclaration.h
--- a/dom/base/DOMPrefs.cpp
+++ b/dom/base/DOMPrefs.cpp
@@ -6,80 +6,64 @@
 
 #include "DOMPrefs.h"
 #include "mozilla/Atomics.h"
 #include "mozilla/Preferences.h"
 
 namespace mozilla {
 namespace dom {
 
-#define PREF(name, pref)                                             \
+void
+DOMPrefs::Initialize()
+{
+  MOZ_ASSERT(NS_IsMainThread());
+
+  // Let's cache all the values on the main-thread.
+#if !(defined(DEBUG) || defined(MOZ_ENABLE_JS_DUMP))
+  DOMPrefs::DumpEnabled();
+#endif
+
+#define DOM_PREF(name, pref) DOMPrefs::name();
+#define DOM_WEBIDL_PREF(name)
+
+#include "DOMPrefsInternal.h"
+
+#undef DOM_PREF
+#undef DOM_WEBIDL_PREF
+}
+
+#define DOM_PREF(name, pref)                                         \
   /* static */ bool                                                  \
   DOMPrefs::name()                                                   \
   {                                                                  \
     static bool initialized = false;                                 \
     static Atomic<bool> cachedValue;                                 \
     if (!initialized) {                                              \
       initialized = true;                                            \
       Preferences::AddAtomicBoolVarCache(&cachedValue, pref, false); \
     }                                                                \
     return cachedValue;                                              \
   }
 
+#define DOM_WEBIDL_PREF(name)                    \
+  /* static */ bool                              \
+  DOMPrefs::name(JSContext* aCx, JSObject* aObj) \
+  {                                              \
+    return DOMPrefs::name();                     \
+  }
+
 #if !(defined(DEBUG) || defined(MOZ_ENABLE_JS_DUMP))
-PREF(DumpEnabled, "browser.dom.window.dump.enabled")
+DOM_PREF(DumpEnabled, "browser.dom.window.dump.enabled")
 #else
 /* static */ bool
 DOMPrefs::DumpEnabled()
 {
   return true;
 }
 #endif
 
-PREF(ImageBitmapExtensionsEnabled, "canvas.imagebitmap_extensions.enabled")
-PREF(DOMCachesEnabled, "dom.caches.enabled")
-PREF(DOMCachesTestingEnabled, "dom.caches.testing.enabled")
-PREF(PerformanceLoggingEnabled, "dom.performance.enable_user_timing_logging")
-PREF(NotificationEnabled, "dom.webnotifications.enabled")
-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")
-PREF(OffscreenCanvasEnabled, "gfx.offscreencanvas.enabled")
-PREF(WebkitBlinkDirectoryPickerEnabled, "dom.webkitBlink.dirPicker.enabled")
-PREF(NetworkInformationEnabled, "dom.netinfo.enabled")
-PREF(FetchObserverEnabled, "dom.fetchObserver.enabled")
-PREF(ResistFingerprintingEnabled, "privacy.resistFingerprinting")
-PREF(DevToolsEnabled, "devtools.enabled")
-
-#undef PREF
+#include "DOMPrefsInternal.h"
 
-#define PREF_WEBIDL(name)                        \
-  /* static */ bool                              \
-  DOMPrefs::name(JSContext* aCx, JSObject* aObj) \
-  {                                              \
-    return DOMPrefs::name();                     \
-  }
-
-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)
-PREF_WEBIDL(OffscreenCanvasEnabled)
-PREF_WEBIDL(WebkitBlinkDirectoryPickerEnabled)
-PREF_WEBIDL(NetworkInformationEnabled)
-PREF_WEBIDL(FetchObserverEnabled)
-
-#undef PREF_WEBIDL
+#undef DOM_PREF
+#undef DOM_WEBIDL_PREF
 
 } // dom namespace
 } // mozilla namespace
--- a/dom/base/DOMPrefs.h
+++ b/dom/base/DOMPrefs.h
@@ -8,94 +8,27 @@
 #define mozilla_dom_DOMPrefs_h
 
 namespace mozilla {
 namespace dom {
 
 class DOMPrefs final
 {
 public:
+  // This must be called on the main-thread.
+  static void Initialize();
+
   // Returns true if the browser.dom.window.dump.enabled pref is set.
   static bool DumpEnabled();
 
-  // Returns true if the canvas.imagebitmap_extensions.enabled pref is set.
-  static bool ImageBitmapExtensionsEnabled();
-  static bool ImageBitmapExtensionsEnabled(JSContext* aCx, JSObject* aObj);
-
-  // Returns true if the dom.caches.enabled pref is set.
-  static bool DOMCachesEnabled();
-  static bool DOMCachesEnabled(JSContext* aCx, JSObject* aObj);
-
-  // Returns true if the dom.caches.testing.enabled pref is set.
-  static bool DOMCachesTestingEnabled();
-
-  // Returns true if the dom.performance.enable_user_timing_logging pref is set.
-  static bool PerformanceLoggingEnabled();
-
-  // Returns true if the dom.webnotifications.enabled pref is set.
-  // Note that you should use NotificationEnabledInServiceWorkers if you need to
-  // enable Notification API for ServiceWorkers
-  static bool NotificationEnabled();
-
-  // Returns true if the dom.webnotifications.serviceworker.enabled pref is set.
-  static bool NotificationEnabledInServiceWorkers();
-  static bool NotificationEnabledInServiceWorkers(JSContext* aCx,
-                                                  JSObject* aObj);
-
-  // Returns true if the dom.webnotifications.requireinteraction.enabled pref is
-  // set.
-  static bool NotificationRIEnabled();
-  static bool NotificationRIEnabled(JSContext* aCx, JSObject* aObj);
-
-  // Returns true if the dom.serviceWorkers.enabled pref is set.
-  static bool ServiceWorkersEnabled();
-  static bool ServiceWorkersEnabled(JSContext* aCx, JSObject* aObj);
-
-  // Returns true if the dom.serviceWorkers.testing.enabled pref is set.
-  static bool ServiceWorkersTestingEnabled();
+#define DOM_PREF(name, pref) static bool name();
+#define DOM_WEBIDL_PREF(name) static bool name(JSContext* aCx, JSObject* aObj);
 
-  // Returns true if the dom.storageManager.enabled pref is set.
-  static bool StorageManagerEnabled();
-  static bool StorageManagerEnabled(JSContext* aCx, JSObject* aObj);
-
-  // Returns true if the dom.promise_rejection_events.enabled pref is set.
-  static bool PromiseRejectionEventsEnabled();
-  static bool PromiseRejectionEventsEnabled(JSContext* aCx, JSObject* aObj);
-
-  // 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);
+#include "DOMPrefsInternal.h"
 
-  // Returns true if the gfx.offscreencanvas.enabled pref is set.
-  static bool OffscreenCanvasEnabled();
-  static bool OffscreenCanvasEnabled(JSContext* aCx, JSObject* aObj);
-
-  // 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);
-
-  // Returns true if the privacy.resistFingerprinting pref is set.
-  static bool ResistFingerprintingEnabled();
-
-  // Returns true if the devtools.enabled pref is set.
-  static bool DevToolsEnabled();
+#undef DOM_PREF
+#undef DOM_WEBIDL_PREF
 };
 
 } // dom namespace
 } // mozilla namespace
 
 #endif // mozilla_dom_DOMPrefs_h
new file mode 100644
--- /dev/null
+++ b/dom/base/DOMPrefsInternal.h
@@ -0,0 +1,56 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// This is the list of the preferences that are exposed to workers and
+// main-thread in DOM.
+// The format is as follows:
+//
+//   DOM_PREF(FooBar, "foo.bar")
+//
+//   * First argument is the name of the getter function.  This defines a
+//     DOMPrefs::FooBar()
+//   * The second argument is the name of the pref.
+// 
+//   DOM_WEBIDL_PREF(FooBar)
+//
+//   * This defines DOMPrefs::FooBar(JSContext* aCx, JSObject* aObj);
+//     This is allows the use of DOMPrefs in WebIDL files.
+
+DOM_PREF(ImageBitmapExtensionsEnabled, "canvas.imagebitmap_extensions.enabled")
+DOM_PREF(DOMCachesEnabled, "dom.caches.enabled")
+DOM_PREF(DOMCachesTestingEnabled, "dom.caches.testing.enabled")
+DOM_PREF(PerformanceLoggingEnabled, "dom.performance.enable_user_timing_logging")
+DOM_PREF(NotificationEnabled, "dom.webnotifications.enabled")
+DOM_PREF(NotificationEnabledInServiceWorkers, "dom.webnotifications.serviceworker.enabled")
+DOM_PREF(NotificationRIEnabled, "dom.webnotifications.requireinteraction.enabled")
+DOM_PREF(ServiceWorkersEnabled, "dom.serviceWorkers.enabled")
+DOM_PREF(ServiceWorkersTestingEnabled, "dom.serviceWorkers.testing.enabled")
+DOM_PREF(StorageManagerEnabled, "dom.storageManager.enabled")
+DOM_PREF(PromiseRejectionEventsEnabled, "dom.promise_rejection_events.enabled")
+DOM_PREF(PushEnabled, "dom.push.enabled")
+DOM_PREF(StreamsEnabled, "dom.streams.enabled")
+DOM_PREF(RequestContextEnabled, "dom.requestcontext.enabled")
+DOM_PREF(OffscreenCanvasEnabled, "gfx.offscreencanvas.enabled")
+DOM_PREF(WebkitBlinkDirectoryPickerEnabled, "dom.webkitBlink.dirPicker.enabled")
+DOM_PREF(NetworkInformationEnabled, "dom.netinfo.enabled")
+DOM_PREF(FetchObserverEnabled, "dom.fetchObserver.enabled")
+DOM_PREF(ResistFingerprintingEnabled, "privacy.resistFingerprinting")
+DOM_PREF(DevToolsEnabled, "devtools.enabled")
+
+DOM_WEBIDL_PREF(ImageBitmapExtensionsEnabled)
+DOM_WEBIDL_PREF(DOMCachesEnabled)
+DOM_WEBIDL_PREF(NotificationEnabledInServiceWorkers)
+DOM_WEBIDL_PREF(NotificationRIEnabled)
+DOM_WEBIDL_PREF(ServiceWorkersEnabled)
+DOM_WEBIDL_PREF(StorageManagerEnabled)
+DOM_WEBIDL_PREF(PromiseRejectionEventsEnabled)
+DOM_WEBIDL_PREF(PushEnabled)
+DOM_WEBIDL_PREF(StreamsEnabled)
+DOM_WEBIDL_PREF(RequestContextEnabled)
+DOM_WEBIDL_PREF(OffscreenCanvasEnabled)
+DOM_WEBIDL_PREF(WebkitBlinkDirectoryPickerEnabled)
+DOM_WEBIDL_PREF(NetworkInformationEnabled)
+DOM_WEBIDL_PREF(FetchObserverEnabled)
--- a/dom/base/moz.build
+++ b/dom/base/moz.build
@@ -168,16 +168,17 @@ EXPORTS.mozilla.dom += [
     'DOMError.h',
     'DOMException.h',
     'DOMImplementation.h',
     'DOMIntersectionObserver.h',
     'DOMMatrix.h',
     'DOMParser.h',
     'DOMPoint.h',
     'DOMPrefs.h',
+    'DOMPrefsInternal.h',
     'DOMQuad.h',
     'DOMRect.h',
     'DOMRequest.h',
     'DOMStringList.h',
     'DOMTokenListSupportedTokens.h',
     'Element.h',
     'ElementInlines.h',
     'EventSource.h',
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -21,16 +21,17 @@
 #include "mozilla/Unused.h"
 #include "mozilla/TelemetryIPC.h"
 #include "mozilla/devtools/HeapSnapshotTempFileHelperChild.h"
 #include "mozilla/docshell/OfflineCacheUpdateChild.h"
 #include "mozilla/dom/ClientManager.h"
 #include "mozilla/dom/ClientOpenWindowOpActors.h"
 #include "mozilla/dom/ContentBridgeChild.h"
 #include "mozilla/dom/ContentBridgeParent.h"
+#include "mozilla/dom/DOMPrefs.h"
 #include "mozilla/dom/VideoDecoderManagerChild.h"
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/dom/DataTransfer.h"
 #include "mozilla/dom/DocGroup.h"
 #include "mozilla/dom/ExternalHelperAppChild.h"
 #include "mozilla/dom/FileCreatorHelper.h"
 #include "mozilla/dom/GetFilesHelper.h"
 #include "mozilla/dom/IPCBlobUtils.h"
@@ -1223,16 +1224,18 @@ ContentChild::InitXPCOM(const XPCOMInitD
   mozilla::dom::time::InitializeDateCacheCleaner();
 
   GfxInfoBase::SetFeatureStatus(aXPCOMInit.gfxFeatureStatus());
 
   DataStorage::SetCachedStorageEntries(aXPCOMInit.dataStorage());
 
   // Set the dynamic scalar definitions for this process.
   TelemetryIPC::AddDynamicScalarDefinitions(aXPCOMInit.dynamicScalarDefs());
+
+  DOMPrefs::Initialize();
 }
 
 mozilla::ipc::IPCResult
 ContentChild::RecvRequestMemoryReport(const uint32_t& aGeneration,
                                       const bool& aAnonymize,
                                       const bool& aMinimizeMemoryUsage,
                                       const MaybeFileDesc& aDMDFile)
 {
--- a/layout/build/nsLayoutStatics.cpp
+++ b/layout/build/nsLayoutStatics.cpp
@@ -314,16 +314,23 @@ nsLayoutStatics::Initialize()
   // On Android, we instantiate it when constructing AndroidBridge.
   MediaPrefs::GetSingleton();
 #endif
 
   // This must be initialized on the main-thread.
   mozilla::dom::IPCBlobInputStreamStorage::Initialize();
 
   mozilla::dom::U2FTokenManager::Initialize();
+
+  if (XRE_IsParentProcess()) {
+    // On content process we initialize DOMPrefs when PContentChild is fully
+    // initialized.
+    mozilla::dom::DOMPrefs::Initialize();
+  }
+
   return NS_OK;
 }
 
 void
 nsLayoutStatics::Shutdown()
 {
   // Don't need to shutdown nsWindowMemoryReporter, that will be done by the
   // memory reporter manager.
--- a/layout/style/nsDOMCSSAttrDeclaration.h
+++ b/layout/style/nsDOMCSSAttrDeclaration.h
@@ -10,16 +10,17 @@
 #define nsDOMCSSAttributeDeclaration_h
 
 #include "mozilla/Attributes.h"
 #include "nsDOMCSSDeclaration.h"
 
 
 namespace mozilla {
 namespace dom {
+class DomGroup;
 class Element;
 } // namespace dom
 } // namespace mozilla
 
 class nsDOMCSSAttributeDeclaration final : public nsDOMCSSDeclaration
 {
 public:
   typedef mozilla::dom::Element Element;
@@ -34,17 +35,17 @@ public:
   virtual mozilla::DeclarationBlock* GetCSSDeclaration(Operation aOperation) override;
   virtual void GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv,
                                         nsIPrincipal* aSubjectPrincipal) override;
   nsDOMCSSDeclaration::ServoCSSParsingEnvironment
   GetServoCSSParsingEnvironment(nsIPrincipal* aSubjectPrincipal) const final;
   NS_IMETHOD GetParentRule(nsIDOMCSSRule **aParent) override;
 
   virtual nsINode* GetParentObject() override;
-  virtual DocGroup* GetDocGroup() const override;
+  virtual mozilla::dom::DocGroup* GetDocGroup() const override;
 
   NS_IMETHOD SetPropertyValue(const nsCSSPropertyID aPropID,
                               const nsAString& aValue,
                               nsIPrincipal* aSubjectPrincipal) override;
 
 protected:
   ~nsDOMCSSAttributeDeclaration();