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

Unified Diff: third_party/WebKit/Source/core/imagebitmap/ImageBitmapFactories.cpp

Issue 1901153002: Implement createImageBitmap(SVG) of intrinsic size = 0 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: null check Created 4 years, 8 months 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
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLImageElement.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/imagebitmap/ImageBitmapFactories.cpp
diff --git a/third_party/WebKit/Source/core/imagebitmap/ImageBitmapFactories.cpp b/third_party/WebKit/Source/core/imagebitmap/ImageBitmapFactories.cpp
index a3850f1a03eb158f919ec753d74d8103dddf9ef8..05076748aa427b2072684f01de0b024a5a230bf5 100644
--- a/third_party/WebKit/Source/core/imagebitmap/ImageBitmapFactories.cpp
+++ b/third_party/WebKit/Source/core/imagebitmap/ImageBitmapFactories.cpp
@@ -41,6 +41,7 @@
#include "core/html/HTMLVideoElement.h"
#include "core/html/ImageData.h"
#include "core/imagebitmap/ImageBitmapOptions.h"
+#include "core/svg/graphics/SVGImage.h"
#include "core/workers/WorkerGlobalScope.h"
#include "platform/SharedBuffer.h"
#include "platform/ThreadSafeFunctional.h"
@@ -53,10 +54,23 @@
namespace blink {
-static inline ImageBitmapSource* toImageBitmapSourceInternal(const ImageBitmapSourceUnion& value)
+static inline ImageBitmapSource* toImageBitmapSourceInternal(const ImageBitmapSourceUnion& value, ExceptionState& exceptionState, bool hasCropRect)
{
- if (value.isHTMLImageElement())
- return value.getAsHTMLImageElement();
+ if (value.isHTMLImageElement()) {
+ HTMLImageElement* imageElement = value.getAsHTMLImageElement();
+ if (!imageElement || !imageElement->cachedImage()) {
+ exceptionState.throwDOMException(InvalidStateError, "No image can be retrieved from the provided element.");
+ return nullptr;
+ }
+ if (imageElement->cachedImage()->getImage()->isSVGImage()) {
+ SVGImage* image = toSVGImage(imageElement->cachedImage()->getImage());
+ if (!image->hasIntrinsicDimensions() && !hasCropRect) {
+ exceptionState.throwDOMException(InvalidStateError, "The image element contains an SVG image without intrinsic dimensions.");
+ return nullptr;
+ }
+ }
+ return imageElement;
+ }
if (value.isHTMLVideoElement())
return value.getAsHTMLVideoElement();
if (value.isHTMLCanvasElement())
@@ -75,7 +89,9 @@ ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState,
{
UseCounter::Feature feature = UseCounter::CreateImageBitmap;
UseCounter::count(scriptState->getExecutionContext(), feature);
- ImageBitmapSource* bitmapSourceInternal = toImageBitmapSourceInternal(bitmapSource);
+ ImageBitmapSource* bitmapSourceInternal = toImageBitmapSourceInternal(bitmapSource, exceptionState, false);
+ if (!bitmapSourceInternal)
+ return ScriptPromise();
if (bitmapSourceInternal->isBlob()) {
Blob* blob = static_cast<Blob*>(bitmapSourceInternal);
ImageBitmapLoader* loader = ImageBitmapFactories::ImageBitmapLoader::create(from(eventTarget), IntRect(), options, scriptState);
@@ -92,7 +108,9 @@ ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState,
{
UseCounter::Feature feature = UseCounter::CreateImageBitmap;
UseCounter::count(scriptState->getExecutionContext(), feature);
- ImageBitmapSource* bitmapSourceInternal = toImageBitmapSourceInternal(bitmapSource);
+ ImageBitmapSource* bitmapSourceInternal = toImageBitmapSourceInternal(bitmapSource, exceptionState, true);
+ if (!bitmapSourceInternal)
+ return ScriptPromise();
return createImageBitmap(scriptState, eventTarget, bitmapSourceInternal, sx, sy, sw, sh, options, exceptionState);
}
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLImageElement.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698