Index: third_party/WebKit/Source/core/html/HTMLImageElement.cpp |
diff --git a/third_party/WebKit/Source/core/html/HTMLImageElement.cpp b/third_party/WebKit/Source/core/html/HTMLImageElement.cpp |
index 2596b9e0d6893f6f9ad411b7bae00ac2b6505a58..41c825d84ca957b1463a538137e5949b0f027cd2 100644 |
--- a/third_party/WebKit/Source/core/html/HTMLImageElement.cpp |
+++ b/third_party/WebKit/Source/core/html/HTMLImageElement.cpp |
@@ -34,6 +34,7 @@ |
#include "core/dom/NodeTraversal.h" |
#include "core/dom/shadow/ShadowRoot.h" |
#include "core/fetch/ImageResource.h" |
+#include "core/frame/ImageBitmap.h" |
#include "core/frame/UseCounter.h" |
#include "core/html/HTMLAnchorElement.h" |
#include "core/html/HTMLCanvasElement.h" |
@@ -676,6 +677,33 @@ void HTMLImageElement::forceReload() const |
imageLoader().updateFromElement(ImageLoader::UpdateForcedReload, m_referrerPolicy); |
} |
+ScriptPromise HTMLImageElement::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, int sx, int sy, int sw, int sh, ExceptionState& exceptionState) |
+{ |
+ ASSERT(eventTarget.toDOMWindow()); |
+ if (!cachedImage()) { |
+ exceptionState.throwDOMException(InvalidStateError, "No image can be retrieved from the provided element."); |
+ return ScriptPromise(); |
+ } |
+ if (cachedImage()->image()->isSVGImage()) { |
+ exceptionState.throwDOMException(InvalidStateError, "The image element contains an SVG image, which is unsupported."); |
+ return ScriptPromise(); |
+ } |
+ if (!sw || !sh) { |
+ exceptionState.throwDOMException(IndexSizeError, String::format("The source %s provided is 0.", sw ? "height" : "width")); |
+ return ScriptPromise(); |
+ } |
+ if (!cachedImage()->image()->currentFrameHasSingleSecurityOrigin()) { |
+ exceptionState.throwSecurityError("The source image contains image data from multiple origins."); |
+ return ScriptPromise(); |
+ } |
+ Document* document = eventTarget.toDOMWindow()->document(); |
+ if (!cachedImage()->passesAccessControlCheck(document->securityOrigin()) && document->securityOrigin()->taintsCanvas(src())) { |
+ exceptionState.throwSecurityError("Cross-origin access to the source image is denied."); |
+ return ScriptPromise(); |
+ } |
+ return ImageBitmapSource::fulfillImageBitmap(scriptState, ImageBitmap::create(this, IntRect(sx, sy, sw, sh))); |
+} |
+ |
void HTMLImageElement::selectSourceURL(ImageLoader::UpdateFromElementBehavior behavior) |
{ |
if (!document().isActive()) |
@@ -775,4 +803,14 @@ bool HTMLImageElement::isOpaque() const |
return image && image->currentFrameKnownToBeOpaque(); |
} |
+IntSize HTMLImageElement::bitmapSourceSize() const |
+{ |
+ ImageResource* image = cachedImage(); |
+ if (!image) |
+ return IntSize(); |
+ LayoutSize lSize = image->imageSize(LayoutObject::shouldRespectImageOrientation(layoutObject()), 1.0f); |
+ ASSERT(lSize.fraction().isZero()); |
+ return IntSize(lSize.width(), lSize.height()); |
+} |
+ |
} |