Bug 1419771 - Introduce DOMPreferences, a thread-safe access to preferences for DOM - part 2 - image bitmap, r=asuth
☠☠ backed out by ccd7b237c433 ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 13 Dec 2017 14:02:44 -0600
changeset 396292 2e263a2519c50359bd6b9663b94d462e5e30249e
parent 396291 b628d9298be89033495ad48372743a0902afab39
child 396293 000c8d5fbc03d656b87b088dfabb57e5d8cd8d0b
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 2 - image bitmap, r=asuth
dom/base/DOMPreferences.cpp
dom/base/DOMPreferences.h
dom/base/nsGlobalWindowInner.cpp
dom/canvas/ImageBitmap.cpp
dom/canvas/ImageBitmap.h
dom/webidl/ImageBitmap.webidl
dom/workers/WorkerPrefs.h
dom/workers/WorkerScope.cpp
--- a/dom/base/DOMPreferences.cpp
+++ b/dom/base/DOMPreferences.cpp
@@ -30,23 +30,25 @@ PREF(DumpEnabled, "browser.dom.window.du
 #else
 /* static */ bool
 DOMPreferences::DumpEnabled()
 {
   return true;
 }
 #endif
 
+PREF(ImageBitmapExtensionsEnabled, "canvas.imagebitmap_extensions.enabled")
+
 #undef PREF
 
 #define PREF_WEBIDL(name)                              \
   /* static */ bool                                    \
   DOMPreferences::name(JSContext* aCx, JSObject* aObj) \
   {                                                    \
     return DOMPreferences::name();                     \
   }
 
-// It will be useful, eventually.
+PREF_WEBIDL(ImageBitmapExtensionsEnabled)
 
 #undef PREF_WEBIDL
 
 } // dom namespace
 } // mozilla namespace
--- a/dom/base/DOMPreferences.h
+++ b/dom/base/DOMPreferences.h
@@ -10,14 +10,18 @@
 namespace mozilla {
 namespace dom {
 
 class DOMPreferences final
 {
 public:
   // 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);
 };
 
 } // dom namespace
 } // mozilla namespace
 
 #endif // mozilla_dom_DOMPreferences_h
--- a/dom/base/nsGlobalWindowInner.cpp
+++ b/dom/base/nsGlobalWindowInner.cpp
@@ -7581,17 +7581,17 @@ nsGlobalWindowInner::CreateImageBitmap(J
 already_AddRefed<mozilla::dom::Promise>
 nsGlobalWindowInner::CreateImageBitmap(JSContext* aCx,
                                        const ImageBitmapSource& aImage,
                                        int32_t aOffset, int32_t aLength,
                                        ImageBitmapFormat aFormat,
                                        const Sequence<ChannelPixelLayout>& aLayout,
                                        ErrorResult& aRv)
 {
-  if (!ImageBitmap::ExtensionsEnabled(aCx)) {
+  if (!DOMPreferences::ImageBitmapExtensionsEnabled()) {
     aRv.Throw(NS_ERROR_TYPE_ERR);
     return nullptr;
   }
   if (aImage.IsArrayBuffer() || aImage.IsArrayBufferView()) {
     return ImageBitmap::Create(this, aImage, aOffset, aLength, aFormat, aLayout,
                                aRv);
   }
   aRv.Throw(NS_ERROR_TYPE_ERR);
--- a/dom/canvas/ImageBitmap.cpp
+++ b/dom/canvas/ImageBitmap.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* 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/. */
 
 #include "mozilla/dom/ImageBitmap.h"
 #include "mozilla/CheckedInt.h"
+#include "mozilla/dom/DOMPreferences.h"
 #include "mozilla/dom/ImageBitmapBinding.h"
 #include "mozilla/dom/Promise.h"
 #include "mozilla/dom/StructuredCloneTags.h"
 #include "mozilla/dom/WorkerPrivate.h"
 #include "mozilla/dom/WorkerRunnable.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/Swizzle.h"
 #include "mozilla/Mutex.h"
@@ -1429,28 +1430,16 @@ ImageBitmap::WriteStructuredClone(JSStru
                                                  true);
   }
   MOZ_ASSERT(dstDataSurface);
   Factory::CopyDataSourceSurface(snapshot, dstDataSurface);
   aClonedSurfaces.AppendElement(dstDataSurface);
   return true;
 }
 
-/*static*/ bool
-ImageBitmap::ExtensionsEnabled(JSContext* aCx, JSObject*)
-{
-  if (NS_IsMainThread()) {
-    return Preferences::GetBool("canvas.imagebitmap_extensions.enabled");
-  } else {
-    WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
-    MOZ_ASSERT(workerPrivate);
-    return workerPrivate->ImageBitmapExtensionsEnabled();
-  }
-}
-
 // ImageBitmap extensions.
 ImageBitmapFormat
 ImageBitmap::FindOptimalFormat(const Optional<Sequence<ImageBitmapFormat>>& aPossibleFormats,
                                ErrorResult& aRv)
 {
   MOZ_ASSERT(mDataWrapper, "No ImageBitmapFormatUtils functionalities.");
 
   ImageBitmapFormat platformFormat = mDataWrapper->GetFormat();
--- a/dom/canvas/ImageBitmap.h
+++ b/dom/canvas/ImageBitmap.h
@@ -147,22 +147,16 @@ public:
                       const nsTArray<RefPtr<gfx::DataSourceSurface>>& aClonedSurfaces,
                       uint32_t aIndex);
 
   static bool
   WriteStructuredClone(JSStructuredCloneWriter* aWriter,
                        nsTArray<RefPtr<gfx::DataSourceSurface>>& aClonedSurfaces,
                        ImageBitmap* aImageBitmap);
 
-  // Mozilla Extensions
-  // aObj is an optional argument that isn't used by ExtensionsEnabled() and
-  // only exists because the bindings layer insists on passing it to us.  All
-  // other consumers of this function should only call it passing one argument.
-  static bool ExtensionsEnabled(JSContext* aCx, JSObject* aObj = nullptr);
-
   friend CreateImageBitmapFromBlob;
   friend CreateImageBitmapFromBlobTask;
   friend CreateImageBitmapFromBlobWorkerTask;
 
   template<typename T>
   friend class MapDataIntoBufferSource;
 
   // Mozilla Extensions
--- a/dom/webidl/ImageBitmap.webidl
+++ b/dom/webidl/ImageBitmap.webidl
@@ -398,15 +398,15 @@ dictionary ChannelPixelLayout {
     required ChannelPixelLayoutDataType dataType;
     required unsigned long              stride;
     required unsigned long              skip;
 };
 
 typedef sequence<ChannelPixelLayout> ImagePixelLayout;
 
 partial interface ImageBitmap {
-    [Throws, Func="mozilla::dom::ImageBitmap::ExtensionsEnabled"]
+    [Throws, Func="mozilla::dom::DOMPreferences::ImageBitmapExtensionsEnabled"]
     ImageBitmapFormat               findOptimalFormat (optional sequence<ImageBitmapFormat> aPossibleFormats);
-    [Throws, Func="mozilla::dom::ImageBitmap::ExtensionsEnabled"]
+    [Throws, Func="mozilla::dom::DOMPreferences::ImageBitmapExtensionsEnabled"]
     long                            mappedDataLength (ImageBitmapFormat aFormat);
-    [Throws, Func="mozilla::dom::ImageBitmap::ExtensionsEnabled"]
+    [Throws, Func="mozilla::dom::DOMPreferences::ImageBitmapExtensionsEnabled"]
     Promise<ImagePixelLayout> mapDataInto (ImageBitmapFormat aFormat, BufferSource aBuffer, long aOffset);
 };
--- 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("canvas.imagebitmap_extensions.enabled", ImageBitmapExtensionsEnabled, IMAGEBITMAP_EXTENSIONS_ENABLED)
 WORKER_SIMPLE_PREF("dom.caches.enabled", DOMCachesEnabled, DOM_CACHES)
 WORKER_SIMPLE_PREF("dom.caches.testing.enabled", DOMCachesTestingEnabled, DOM_CACHES_TESTING)
 WORKER_SIMPLE_PREF("dom.performance.enable_user_timing_logging", PerformanceLoggingEnabled, PERFORMANCE_LOGGING_ENABLED)
 WORKER_SIMPLE_PREF("dom.webnotifications.enabled", DOMWorkerNotificationEnabled, DOM_WORKERNOTIFICATION)
 WORKER_SIMPLE_PREF("dom.webnotifications.serviceworker.enabled", DOMServiceWorkerNotificationEnabled, DOM_SERVICEWORKERNOTIFICATION)
 WORKER_SIMPLE_PREF("dom.webnotifications.requireinteraction.enabled", DOMWorkerNotificationRIEnabled, DOM_WORKERNOTIFICATIONRI)
 WORKER_SIMPLE_PREF("dom.serviceWorkers.enabled", ServiceWorkersEnabled, SERVICEWORKERS_ENABLED)
 WORKER_SIMPLE_PREF("dom.serviceWorkers.testing.enabled", ServiceWorkersTestingEnabled, SERVICEWORKERS_TESTING_ENABLED)
--- a/dom/workers/WorkerScope.cpp
+++ b/dom/workers/WorkerScope.cpp
@@ -475,17 +475,17 @@ WorkerGlobalScope::CreateImageBitmap(JSC
 already_AddRefed<mozilla::dom::Promise>
 WorkerGlobalScope::CreateImageBitmap(JSContext* aCx,
                                      const ImageBitmapSource& aImage,
                                      int32_t aOffset, int32_t aLength,
                                      ImageBitmapFormat aFormat,
                                      const Sequence<ChannelPixelLayout>& aLayout,
                                      ErrorResult& aRv)
 {
-  if (!ImageBitmap::ExtensionsEnabled(aCx)) {
+  if (!DOMPreferences::ImageBitmapExtensionsEnabled()) {
     aRv.Throw(NS_ERROR_TYPE_ERR);
     return nullptr;
   }
 
   if (aImage.IsArrayBuffer() || aImage.IsArrayBufferView()) {
     return ImageBitmap::Create(this, aImage, aOffset, aLength, aFormat, aLayout,
                                aRv);
   } else {