Chromium Code Reviews| 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..5bcc887ee4ad79c91db703e9654842ec6e014657 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()) |
| @@ -775,4 +804,13 @@ 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); |
|
davve
2015/11/27 11:19:43
Since multiplier is 1 and last argument to imageSi
xidachen
2015/11/27 19:00:25
Done.
|
| + return IntSize(lSize.width(), lSize.height()); |
| +} |
| + |
| } |