From 84efbc6ccdfb47cfa437ad01a9e944a6c7f99a0f Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Mon, 10 Sep 2018 20:36:14 +0200 Subject: [PATCH] Bug 1489844 - Port DOMPrefs to StaticPrefs - part 1 - canvas_imagebitmap_extensions_enabled, r=ehsan --- dom/base/DOMPrefs.cpp | 12 ++++++++++++ dom/base/DOMPrefs.h | 2 ++ dom/base/DOMPrefsInternal.h | 3 +-- dom/base/nsGlobalWindowInner.cpp | 3 ++- dom/webidl/ImageBitmap.webidl | 6 +++--- dom/workers/WorkerScope.cpp | 3 ++- modules/libpref/init/StaticPrefList.h | 7 +++++++ modules/libpref/init/all.js | 3 --- 8 files changed, 29 insertions(+), 10 deletions(-) diff --git a/dom/base/DOMPrefs.cpp b/dom/base/DOMPrefs.cpp index ccbb3b389742..551ef5752c35 100644 --- a/dom/base/DOMPrefs.cpp +++ b/dom/base/DOMPrefs.cpp @@ -24,12 +24,14 @@ DOMPrefs::Initialize() #define DOM_PREF(name, pref) DOMPrefs::name(); #define DOM_WEBIDL_PREF(name) +#define DOM_WEBIDL_PREF2(name) #define DOM_UINT32_PREF(name, pref, defaultValue) DOMPrefs::name(); #include "DOMPrefsInternal.h" #undef DOM_PREF #undef DOM_WEBIDL_PREF +#undef DOM_WEBIDL_PREF2 #undef DOM_UINT32_PREF } @@ -53,6 +55,15 @@ DOMPrefs::Initialize() return DOMPrefs::name(); \ } +// TODO: this is going to be renamed DOM_WEBIDL_PREF in the last patch. +#define DOM_WEBIDL_PREF2(name) \ + /* static */ bool \ + DOMPrefs::name(JSContext* aCx, JSObject* aObj) \ + { \ + return StaticPrefs::name(); \ + } + + #define DOM_UINT32_PREF(name, pref, defaultValue) \ /* static */ uint32_t \ DOMPrefs::name() \ @@ -86,6 +97,7 @@ DOMPrefs::SchedulerTimingEnabled() #undef DOM_PREF #undef DOM_WEBIDL_PREF +#undef DOM_WEBIDL_PREF2 #undef DOM_UINT32_PREF } // dom namespace diff --git a/dom/base/DOMPrefs.h b/dom/base/DOMPrefs.h index c781ceadebdc..2f89b9c04de8 100644 --- a/dom/base/DOMPrefs.h +++ b/dom/base/DOMPrefs.h @@ -24,12 +24,14 @@ public: #define DOM_PREF(name, pref) static bool name(); #define DOM_WEBIDL_PREF(name) static bool name(JSContext* aCx, JSObject* aObj); +#define DOM_WEBIDL_PREF2(name) static bool name(JSContext* aCx, JSObject* aObj); #define DOM_UINT32_PREF(name, pref, defaultValue) static uint32_t name(); #include "DOMPrefsInternal.h" #undef DOM_PREF #undef DOM_WEBIDL_PREF +#undef DOM_WEBIDL_PREF2 #undef DOM_UINT32_PREF }; diff --git a/dom/base/DOMPrefsInternal.h b/dom/base/DOMPrefsInternal.h index 81bbc404ae1e..7a2bed256715 100644 --- a/dom/base/DOMPrefsInternal.h +++ b/dom/base/DOMPrefsInternal.h @@ -19,7 +19,6 @@ // * 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") @@ -45,7 +44,7 @@ DOM_PREF(IndexedDBStorageOptionsEnabled, "dom.indexedDB.storageOption.enabled") DOM_PREF(BinASTEncodingEnabled, "dom.script_loader.binast_encoding.enabled") #endif -DOM_WEBIDL_PREF(ImageBitmapExtensionsEnabled) +DOM_WEBIDL_PREF2(canvas_imagebitmap_extensions_enabled) DOM_WEBIDL_PREF(DOMCachesEnabled) DOM_WEBIDL_PREF(NotificationEnabledInServiceWorkers) DOM_WEBIDL_PREF(NotificationRIEnabled) diff --git a/dom/base/nsGlobalWindowInner.cpp b/dom/base/nsGlobalWindowInner.cpp index b6c79e7004b7..29ffc8408dce 100644 --- a/dom/base/nsGlobalWindowInner.cpp +++ b/dom/base/nsGlobalWindowInner.cpp @@ -101,6 +101,7 @@ #include "PostMessageEvent.h" #include "mozilla/dom/DocGroup.h" #include "mozilla/dom/TabGroup.h" +#include "mozilla/StaticPrefs.h" // Interfaces Needed #include "nsIFrame.h" @@ -7725,7 +7726,7 @@ nsGlobalWindowInner::CreateImageBitmap(JSContext* aCx, const Sequence& aLayout, ErrorResult& aRv) { - if (!DOMPrefs::ImageBitmapExtensionsEnabled()) { + if (!StaticPrefs::canvas_imagebitmap_extensions_enabled()) { aRv.Throw(NS_ERROR_TYPE_ERR); return nullptr; } diff --git a/dom/webidl/ImageBitmap.webidl b/dom/webidl/ImageBitmap.webidl index 40948a2e39e2..abc800e21d89 100644 --- a/dom/webidl/ImageBitmap.webidl +++ b/dom/webidl/ImageBitmap.webidl @@ -403,10 +403,10 @@ dictionary ChannelPixelLayout { typedef sequence ImagePixelLayout; partial interface ImageBitmap { - [Throws, Func="mozilla::dom::DOMPrefs::ImageBitmapExtensionsEnabled"] + [Throws, Func="mozilla::dom::DOMPrefs::canvas_imagebitmap_extensions_enabled"] ImageBitmapFormat findOptimalFormat (optional sequence aPossibleFormats); - [Throws, Func="mozilla::dom::DOMPrefs::ImageBitmapExtensionsEnabled"] + [Throws, Func="mozilla::dom::DOMPrefs::canvas_imagebitmap_extensions_enabled"] long mappedDataLength (ImageBitmapFormat aFormat); - [Throws, Func="mozilla::dom::DOMPrefs::ImageBitmapExtensionsEnabled"] + [Throws, Func="mozilla::dom::DOMPrefs::canvas_imagebitmap_extensions_enabled"] Promise mapDataInto (ImageBitmapFormat aFormat, BufferSource aBuffer, long aOffset); }; diff --git a/dom/workers/WorkerScope.cpp b/dom/workers/WorkerScope.cpp index c46fd01cd3f3..c1d68b01241f 100644 --- a/dom/workers/WorkerScope.cpp +++ b/dom/workers/WorkerScope.cpp @@ -32,6 +32,7 @@ #include "mozilla/dom/WorkerNavigator.h" #include "mozilla/dom/cache/CacheStorage.h" #include "mozilla/Services.h" +#include "mozilla/StaticPrefs.h" #include "nsServiceManagerUtils.h" #include "nsIDocument.h" @@ -504,7 +505,7 @@ WorkerGlobalScope::CreateImageBitmap(JSContext* aCx, const Sequence& aLayout, ErrorResult& aRv) { - if (!DOMPrefs::ImageBitmapExtensionsEnabled()) { + if (!StaticPrefs::canvas_imagebitmap_extensions_enabled()) { aRv.Throw(NS_ERROR_TYPE_ERR); return nullptr; } diff --git a/modules/libpref/init/StaticPrefList.h b/modules/libpref/init/StaticPrefList.h index 09355ddb8181..189828060266 100644 --- a/modules/libpref/init/StaticPrefList.h +++ b/modules/libpref/init/StaticPrefList.h @@ -202,6 +202,13 @@ VARCACHE_PREF( uint32_t, 5000 ) +// Disable the ImageBitmap-extensions for now. +VARCACHE_PREF( + "canvas.imagebitmap_extensions.enabled", + canvas_imagebitmap_extensions_enabled, + RelaxedAtomicBool, false +) + //--------------------------------------------------------------------------- // Clear-Site-Data prefs //--------------------------------------------------------------------------- diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 6d855191b1f2..5e060ace2b64 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -968,9 +968,6 @@ pref("canvas.filters.enabled", true); pref("canvas.path.enabled", true); pref("canvas.capturestream.enabled", true); -// Disable the ImageBitmap-extensions for now. -pref("canvas.imagebitmap_extensions.enabled", false); - // We want the ability to forcibly disable platform a11y, because // some non-a11y-related components attempt to bring it up. See bug // 538530 for details about Windows; we have a pref here that allows it