OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013, Google Inc. All rights reserved. | 2 * Copyright (c) 2013, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 23 matching lines...) Expand all Loading... |
34 #include "core/dom/ExecutionContext.h" | 34 #include "core/dom/ExecutionContext.h" |
35 #include "core/fileapi/Blob.h" | 35 #include "core/fileapi/Blob.h" |
36 #include "core/frame/ImageBitmap.h" | 36 #include "core/frame/ImageBitmap.h" |
37 #include "core/frame/LocalDOMWindow.h" | 37 #include "core/frame/LocalDOMWindow.h" |
38 #include "core/frame/UseCounter.h" | 38 #include "core/frame/UseCounter.h" |
39 #include "core/html/HTMLCanvasElement.h" | 39 #include "core/html/HTMLCanvasElement.h" |
40 #include "core/html/HTMLImageElement.h" | 40 #include "core/html/HTMLImageElement.h" |
41 #include "core/html/HTMLVideoElement.h" | 41 #include "core/html/HTMLVideoElement.h" |
42 #include "core/html/ImageData.h" | 42 #include "core/html/ImageData.h" |
43 #include "core/imagebitmap/ImageBitmapOptions.h" | 43 #include "core/imagebitmap/ImageBitmapOptions.h" |
| 44 #include "core/svg/graphics/SVGImage.h" |
44 #include "core/workers/WorkerGlobalScope.h" | 45 #include "core/workers/WorkerGlobalScope.h" |
45 #include "platform/SharedBuffer.h" | 46 #include "platform/SharedBuffer.h" |
46 #include "platform/ThreadSafeFunctional.h" | 47 #include "platform/ThreadSafeFunctional.h" |
47 #include "platform/image-decoders/ImageDecoder.h" | 48 #include "platform/image-decoders/ImageDecoder.h" |
48 #include "platform/threading/BackgroundTaskRunner.h" | 49 #include "platform/threading/BackgroundTaskRunner.h" |
49 #include "public/platform/Platform.h" | 50 #include "public/platform/Platform.h" |
50 #include "public/platform/WebThread.h" | 51 #include "public/platform/WebThread.h" |
51 #include "public/platform/WebTraceLocation.h" | 52 #include "public/platform/WebTraceLocation.h" |
52 #include <v8.h> | 53 #include <v8.h> |
53 | 54 |
54 namespace blink { | 55 namespace blink { |
55 | 56 |
56 static inline ImageBitmapSource* toImageBitmapSourceInternal(const ImageBitmapSo
urceUnion& value) | 57 static inline ImageBitmapSource* toImageBitmapSourceInternal(const ImageBitmapSo
urceUnion& value, ExceptionState& exceptionState, bool hasCropRect) |
57 { | 58 { |
58 if (value.isHTMLImageElement()) | 59 if (value.isHTMLImageElement()) { |
59 return value.getAsHTMLImageElement(); | 60 HTMLImageElement* imageElement = value.getAsHTMLImageElement(); |
| 61 if (!imageElement || !imageElement->cachedImage()) { |
| 62 exceptionState.throwDOMException(InvalidStateError, "No image can be
retrieved from the provided element."); |
| 63 return nullptr; |
| 64 } |
| 65 if (imageElement->cachedImage()->getImage()->isSVGImage()) { |
| 66 SVGImage* image = toSVGImage(imageElement->cachedImage()->getImage()
); |
| 67 if (!image->hasIntrinsicDimensions() && !hasCropRect) { |
| 68 exceptionState.throwDOMException(InvalidStateError, "The image e
lement contains an SVG image without intrinsic dimensions."); |
| 69 return nullptr; |
| 70 } |
| 71 } |
| 72 return imageElement; |
| 73 } |
60 if (value.isHTMLVideoElement()) | 74 if (value.isHTMLVideoElement()) |
61 return value.getAsHTMLVideoElement(); | 75 return value.getAsHTMLVideoElement(); |
62 if (value.isHTMLCanvasElement()) | 76 if (value.isHTMLCanvasElement()) |
63 return value.getAsHTMLCanvasElement(); | 77 return value.getAsHTMLCanvasElement(); |
64 if (value.isBlob()) | 78 if (value.isBlob()) |
65 return value.getAsBlob(); | 79 return value.getAsBlob(); |
66 if (value.isImageData()) | 80 if (value.isImageData()) |
67 return value.getAsImageData(); | 81 return value.getAsImageData(); |
68 if (value.isImageBitmap()) | 82 if (value.isImageBitmap()) |
69 return value.getAsImageBitmap(); | 83 return value.getAsImageBitmap(); |
70 ASSERT_NOT_REACHED(); | 84 ASSERT_NOT_REACHED(); |
71 return nullptr; | 85 return nullptr; |
72 } | 86 } |
73 | 87 |
74 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState,
EventTarget& eventTarget, const ImageBitmapSourceUnion& bitmapSource, const Imag
eBitmapOptions& options, ExceptionState& exceptionState) | 88 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState,
EventTarget& eventTarget, const ImageBitmapSourceUnion& bitmapSource, const Imag
eBitmapOptions& options, ExceptionState& exceptionState) |
75 { | 89 { |
76 UseCounter::Feature feature = UseCounter::CreateImageBitmap; | 90 UseCounter::Feature feature = UseCounter::CreateImageBitmap; |
77 UseCounter::count(scriptState->getExecutionContext(), feature); | 91 UseCounter::count(scriptState->getExecutionContext(), feature); |
78 ImageBitmapSource* bitmapSourceInternal = toImageBitmapSourceInternal(bitmap
Source); | 92 ImageBitmapSource* bitmapSourceInternal = toImageBitmapSourceInternal(bitmap
Source, exceptionState, false); |
| 93 if (!bitmapSourceInternal) |
| 94 return ScriptPromise(); |
79 if (bitmapSourceInternal->isBlob()) { | 95 if (bitmapSourceInternal->isBlob()) { |
80 Blob* blob = static_cast<Blob*>(bitmapSourceInternal); | 96 Blob* blob = static_cast<Blob*>(bitmapSourceInternal); |
81 ImageBitmapLoader* loader = ImageBitmapFactories::ImageBitmapLoader::cre
ate(from(eventTarget), IntRect(), options, scriptState); | 97 ImageBitmapLoader* loader = ImageBitmapFactories::ImageBitmapLoader::cre
ate(from(eventTarget), IntRect(), options, scriptState); |
82 ScriptPromise promise = loader->promise(); | 98 ScriptPromise promise = loader->promise(); |
83 from(eventTarget).addLoader(loader); | 99 from(eventTarget).addLoader(loader); |
84 loader->loadBlobAsync(eventTarget.getExecutionContext(), blob); | 100 loader->loadBlobAsync(eventTarget.getExecutionContext(), blob); |
85 return promise; | 101 return promise; |
86 } | 102 } |
87 IntSize srcSize = bitmapSourceInternal->bitmapSourceSize(); | 103 IntSize srcSize = bitmapSourceInternal->bitmapSourceSize(); |
88 return createImageBitmap(scriptState, eventTarget, bitmapSourceInternal, 0,
0, srcSize.width(), srcSize.height(), options, exceptionState); | 104 return createImageBitmap(scriptState, eventTarget, bitmapSourceInternal, 0,
0, srcSize.width(), srcSize.height(), options, exceptionState); |
89 } | 105 } |
90 | 106 |
91 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState,
EventTarget& eventTarget, const ImageBitmapSourceUnion& bitmapSource, int sx, in
t sy, int sw, int sh, const ImageBitmapOptions& options, ExceptionState& excepti
onState) | 107 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState,
EventTarget& eventTarget, const ImageBitmapSourceUnion& bitmapSource, int sx, in
t sy, int sw, int sh, const ImageBitmapOptions& options, ExceptionState& excepti
onState) |
92 { | 108 { |
93 UseCounter::Feature feature = UseCounter::CreateImageBitmap; | 109 UseCounter::Feature feature = UseCounter::CreateImageBitmap; |
94 UseCounter::count(scriptState->getExecutionContext(), feature); | 110 UseCounter::count(scriptState->getExecutionContext(), feature); |
95 ImageBitmapSource* bitmapSourceInternal = toImageBitmapSourceInternal(bitmap
Source); | 111 ImageBitmapSource* bitmapSourceInternal = toImageBitmapSourceInternal(bitmap
Source, exceptionState, true); |
| 112 if (!bitmapSourceInternal) |
| 113 return ScriptPromise(); |
96 return createImageBitmap(scriptState, eventTarget, bitmapSourceInternal, sx,
sy, sw, sh, options, exceptionState); | 114 return createImageBitmap(scriptState, eventTarget, bitmapSourceInternal, sx,
sy, sw, sh, options, exceptionState); |
97 } | 115 } |
98 | 116 |
99 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState,
EventTarget& eventTarget, ImageBitmapSource* bitmapSource, int sx, int sy, int s
w, int sh, const ImageBitmapOptions& options, ExceptionState& exceptionState) | 117 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState,
EventTarget& eventTarget, ImageBitmapSource* bitmapSource, int sx, int sy, int s
w, int sh, const ImageBitmapOptions& options, ExceptionState& exceptionState) |
100 { | 118 { |
101 if (bitmapSource->isBlob()) { | 119 if (bitmapSource->isBlob()) { |
102 if (!sw || !sh) { | 120 if (!sw || !sh) { |
103 exceptionState.throwDOMException(IndexSizeError, String::format("The
source %s provided is 0.", sw ? "height" : "width")); | 121 exceptionState.throwDOMException(IndexSizeError, String::format("The
source %s provided is 0.", sw ? "height" : "width")); |
104 return ScriptPromise(); | 122 return ScriptPromise(); |
105 } | 123 } |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 m_factory->didFinishLoading(this); | 268 m_factory->didFinishLoading(this); |
251 } | 269 } |
252 | 270 |
253 DEFINE_TRACE(ImageBitmapFactories::ImageBitmapLoader) | 271 DEFINE_TRACE(ImageBitmapFactories::ImageBitmapLoader) |
254 { | 272 { |
255 visitor->trace(m_factory); | 273 visitor->trace(m_factory); |
256 visitor->trace(m_resolver); | 274 visitor->trace(m_resolver); |
257 } | 275 } |
258 | 276 |
259 } // namespace blink | 277 } // namespace blink |
OLD | NEW |