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 ae94760df80dc15558cfd47ca4327036312ba7e1..2599ffcfb877b768e10f7715ef7414a28a4692b5 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,34 @@ void HTMLImageElement::forceReload() const |
imageLoader().updateFromElement(ImageLoader::UpdateForcedReload, m_referrerPolicy); |
} |
+ScriptPromise HTMLImageElement::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, ImageBitmapSource* bitmapSource, int sx, int sy, int sw, int sh, ExceptionState& exceptionState) |
+{ |
+ ASSERT(eventTarget.toDOMWindow()); |
+ HTMLImageElement* image = static_cast<HTMLImageElement*>(bitmapSource); |
+ if (!image->cachedImage()) { |
+ exceptionState.throwDOMException(InvalidStateError, "No image can be retrieved from the provided element."); |
+ return ScriptPromise(); |
+ } |
+ if (image->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 (!image->cachedImage()->image()->currentFrameHasSingleSecurityOrigin()) { |
+ exceptionState.throwSecurityError("The source image contains image data from multiple origins."); |
+ return ScriptPromise(); |
+ } |
+ Document* document = eventTarget.toDOMWindow()->document(); |
+ if (!image->cachedImage()->passesAccessControlCheck(document->securityOrigin()) && document->securityOrigin()->taintsCanvas(image->src())) { |
+ exceptionState.throwSecurityError("Cross-origin access to the source image is denied."); |
+ return ScriptPromise(); |
+ } |
+ return ImageBitmapSource::fulfillImageBitmap(scriptState, ImageBitmap::create(image, IntRect(sx, sy, sw, sh))); |
+} |
+ |
void HTMLImageElement::selectSourceURL(ImageLoader::UpdateFromElementBehavior behavior) |
{ |
if (!document().isActive()) |