Bug 1500768 - Support SVG images in HTMLImageElements, r=jwatt
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 25 Oct 2018 14:55:06 +0200
changeset 491278 2e9cdd9ff7b6bdc6e7add0ae187166f59d9ad177
parent 491277 e81ad7034716854a48a3d04a0b53b4b63956b77d
child 491279 908a0972c1b529a90e9bee5055f83c86b06a0bb2
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersjwatt
bugs1500768
milestone65.0a1
Bug 1500768 - Support SVG images in HTMLImageElements, r=jwatt
dom/canvas/ImageBitmap.cpp
testing/web-platform/meta/2dcontext/imagebitmap/createImageBitmap-drawImage.html.ini
testing/web-platform/meta/2dcontext/imagebitmap/createImageBitmap-invalid-args.html.ini
testing/web-platform/meta/2dcontext/imagebitmap/createImageBitmap-transfer.html.ini
--- a/dom/canvas/ImageBitmap.cpp
+++ b/dom/canvas/ImageBitmap.cpp
@@ -471,58 +471,32 @@ CheckSecurityForElements(const nsLayoutU
  */
 template<class ElementType>
 static already_AddRefed<SourceSurface>
 GetSurfaceFromElement(nsIGlobalObject* aGlobal, ElementType& aElement, ErrorResult& aRv)
 {
   nsLayoutUtils::SurfaceFromElementResult res =
     nsLayoutUtils::SurfaceFromElement(&aElement, nsLayoutUtils::SFE_WANT_FIRST_FRAME_IF_IMAGE);
 
+  RefPtr<SourceSurface> surface = res.GetSourceSurface();
+  if (NS_WARN_IF(!surface)) {
+    aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
+    return nullptr;
+  }
+
+
   // check origin-clean
   if (!CheckSecurityForElements(res)) {
     aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
     return nullptr;
   }
 
-  RefPtr<SourceSurface> surface = res.GetSourceSurface();
-
-  if (NS_WARN_IF(!surface)) {
-    aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
-    return nullptr;
-  }
-
   return surface.forget();
 }
 
-/*
- * The specification doesn't allow to create an ImegeBitmap from a vector image.
- * This function is used to check if the given Image Element contains a
- * raster image.
- */
-template<class ElementType>
-static bool
-HasRasterImage(ElementType& aImageEl)
-{
-  nsresult rv;
-
-  nsCOMPtr<imgIRequest> imgRequest;
-  rv = aImageEl.GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
-                           getter_AddRefs(imgRequest));
-  if (NS_SUCCEEDED(rv) && imgRequest) {
-    nsCOMPtr<imgIContainer> imgContainer;
-    rv = imgRequest->GetImage(getter_AddRefs(imgContainer));
-    if (NS_SUCCEEDED(rv) && imgContainer &&
-        imgContainer->GetType() == imgIContainer::TYPE_RASTER) {
-      return true;
-    }
-  }
-
-  return false;
-}
-
 ImageBitmap::ImageBitmap(nsIGlobalObject* aGlobal, layers::Image* aData,
                          gfxAlphaType aAlphaType)
   : mParent(aGlobal)
   , mData(aData)
   , mSurface(nullptr)
   , mDataWrapper(new ImageUtils(mData))
   , mPictureRect(0, 0, aData->GetSize().width, aData->GetSize().height)
   , mAlphaType(aAlphaType)
@@ -856,22 +830,16 @@ ImageBitmap::CreateInternal(nsIGlobalObj
                             const Maybe<IntRect>& aCropRect, ErrorResult& aRv)
 {
   // Check if the image element is completely available or not.
   if (!aImageEl.Complete()) {
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return nullptr;
   }
 
-  // Check if the image element is a bitmap (e.g. it's a vector graphic) or not.
-  if (!HasRasterImage(aImageEl)) {
-    aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
-    return nullptr;
-  }
-
   // Get the SourceSurface out from the image element and then do security
   // checking.
   RefPtr<SourceSurface> surface = GetSurfaceFromElement(aGlobal, aImageEl, aRv);
 
   if (NS_WARN_IF(aRv.Failed())) {
     return nullptr;
   }
 
--- a/testing/web-platform/meta/2dcontext/imagebitmap/createImageBitmap-drawImage.html.ini
+++ b/testing/web-platform/meta/2dcontext/imagebitmap/createImageBitmap-drawImage.html.ini
@@ -3,28 +3,16 @@
     expected: FAIL
 
   [createImageBitmap from an OffscreenCanvas with negative sw/sh, and drawImage on the created ImageBitmap]
     expected: FAIL
 
   [createImageBitmap from a Blob with negative sw/sh, and drawImage on the created ImageBitmap]
     expected: FAIL
 
-  [createImageBitmap from a vector HTMLImageElement, and drawImage on the created ImageBitmap]
-    expected: FAIL
-
-  [createImageBitmap from a vector HTMLImageElement with negative sw/sh, and drawImage on the created ImageBitmap]
-    expected: FAIL
-
-  [createImageBitmap from a vector SVGImageElement, and drawImage on the created ImageBitmap]
-    expected: FAIL
-
-  [createImageBitmap from a vector SVGImageElement with negative sw/sh, and drawImage on the created ImageBitmap]
-    expected: FAIL
-
   [createImageBitmap from an HTMLCanvasElement scaled down, and drawImage on the created ImageBitmap]
     expected: FAIL
 
   [createImageBitmap from an HTMLCanvasElement scaled up, and drawImage on the created ImageBitmap]
     expected: FAIL
 
   [createImageBitmap from an HTMLCanvasElement resized, and drawImage on the created ImageBitmap]
     expected: FAIL
--- a/testing/web-platform/meta/2dcontext/imagebitmap/createImageBitmap-invalid-args.html.ini
+++ b/testing/web-platform/meta/2dcontext/imagebitmap/createImageBitmap-invalid-args.html.ini
@@ -6,16 +6,11 @@
     expected: FAIL
 
   [createImageBitmap with an OffscreenCanvas source and oversized (unallocatable) crop region]
     expected: FAIL
 
   [createImageBitmap with an invalid OffscreenCanvas source.]
     expected: FAIL
 
-  [createImageBitmap with a broken image source.]
-    expected: FAIL
-
-  [createImageBitmap with an available but undecodable image source.]
-    expected: FAIL
   [createImageBitmap with CanvasRenderingContext2D image source.]
     expected: FAIL
 
--- a/testing/web-platform/meta/2dcontext/imagebitmap/createImageBitmap-transfer.html.ini
+++ b/testing/web-platform/meta/2dcontext/imagebitmap/createImageBitmap-transfer.html.ini
@@ -1,10 +1,4 @@
 [createImageBitmap-transfer.html]
-  [Transfer ImageBitmap created from a vector HTMLImageElement]
-    expected: FAIL
-
-  [Transfer ImageBitmap created from a vector SVGImageElement]
-    expected: FAIL
-
   [Transfer ImageBitmap created from an OffscreenCanvas]
     expected: FAIL