Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(450)

Unified Diff: third_party/WebKit/Source/core/html/HTMLImageElement.cpp

Issue 1455763002: Use union type in ImageBitmapFactories.idl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Using polymophism in ImageBitmapSource Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..f551568541126312c6beef37e2725b5d02b7da97 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);
}
+PassRefPtrWillBeRawPtr<ImageBitmap> HTMLImageElement::createImageBitmap(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 nullptr;
+ }
+ if (image->cachedImage()->image()->isSVGImage()) {
+ exceptionState.throwDOMException(InvalidStateError, "The image element contains an SVG image, which is unsupported.");
+ return nullptr;
+ }
+ if (!sw || !sh) {
+ exceptionState.throwDOMException(IndexSizeError, String::format("The source %s provided is 0.", sw ? "height" : "width"));
+ return nullptr;
+ }
+ if (!image->cachedImage()->image()->currentFrameHasSingleSecurityOrigin()) {
+ exceptionState.throwSecurityError("The source image contains image data from multiple origins.");
+ return nullptr;
+ }
+ 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 nullptr;
+ }
+ return ImageBitmap::create(image, IntRect(sx, sy, sw, sh));
+}
+
void HTMLImageElement::selectSourceURL(ImageLoader::UpdateFromElementBehavior behavior)
{
if (!document().isActive())

Powered by Google App Engine
This is Rietveld 408576698