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 15 matching lines...) Expand all Loading... |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "modules/imagebitmap/ImageBitmapFactories.h" | 32 #include "modules/imagebitmap/ImageBitmapFactories.h" |
33 | 33 |
34 #include "RuntimeEnabledFeatures.h" | 34 #include "RuntimeEnabledFeatures.h" |
35 #include "V8ImageBitmap.h" | 35 #include "V8ImageBitmap.h" |
| 36 #include "bindings/v8/ExceptionMessages.h" |
36 #include "bindings/v8/ExceptionState.h" | 37 #include "bindings/v8/ExceptionState.h" |
37 #include "bindings/v8/ScriptScope.h" | 38 #include "bindings/v8/ScriptScope.h" |
38 #include "bindings/v8/ScriptState.h" | 39 #include "bindings/v8/ScriptState.h" |
39 #include "core/html/HTMLCanvasElement.h" | 40 #include "core/html/HTMLCanvasElement.h" |
40 #include "core/html/HTMLImageElement.h" | 41 #include "core/html/HTMLImageElement.h" |
41 #include "core/html/HTMLVideoElement.h" | 42 #include "core/html/HTMLVideoElement.h" |
42 #include "core/html/ImageData.h" | 43 #include "core/html/ImageData.h" |
43 #include "core/html/canvas/CanvasRenderingContext2D.h" | 44 #include "core/html/canvas/CanvasRenderingContext2D.h" |
44 #include "core/page/DOMWindow.h" | 45 #include "core/page/DOMWindow.h" |
45 #include "core/page/ImageBitmap.h" | 46 #include "core/page/ImageBitmap.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 } | 95 } |
95 if (image->cachedImage()->image()->isSVGImage()) { | 96 if (image->cachedImage()->image()->isSVGImage()) { |
96 es.throwDOMException(InvalidStateError); | 97 es.throwDOMException(InvalidStateError); |
97 return ScriptObject(); | 98 return ScriptObject(); |
98 } | 99 } |
99 if (!sw || !sh) { | 100 if (!sw || !sh) { |
100 es.throwDOMException(IndexSizeError); | 101 es.throwDOMException(IndexSizeError); |
101 return ScriptObject(); | 102 return ScriptObject(); |
102 } | 103 } |
103 if (!image->cachedImage()->image()->hasSingleSecurityOrigin()) { | 104 if (!image->cachedImage()->image()->hasSingleSecurityOrigin()) { |
104 es.throwDOMException(SecurityError); | 105 es.throwSecurityError(ExceptionMessages::failedToExecute("createImageBit
map", "ImageBitmapFactories", "the source image contains cross-origin image data
.")); |
105 return ScriptObject(); | 106 return ScriptObject(); |
106 } | 107 } |
107 if (!image->cachedImage()->passesAccessControlCheck(eventTarget->toDOMWindow
()->document()->securityOrigin()) | 108 if (!image->cachedImage()->passesAccessControlCheck(eventTarget->toDOMWindow
()->document()->securityOrigin()) |
108 && eventTarget->toDOMWindow()->document()->securityOrigin()->taintsCanvas(im
age->src())) { | 109 && eventTarget->toDOMWindow()->document()->securityOrigin()->taintsCanvas(im
age->src())) { |
109 es.throwDOMException(SecurityError); | 110 es.throwSecurityError(ExceptionMessages::failedToExecute("createImageBit
map", "ImageBitmapFactories", "cross-origin access to the source image is denied
.")); |
110 return ScriptObject(); | 111 return ScriptObject(); |
111 } | 112 } |
112 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 | 113 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 |
113 return fulfillImageBitmap(eventTarget->scriptExecutionContext(), ImageBitmap
::create(image, IntRect(sx, sy, sw, sh))); | 114 return fulfillImageBitmap(eventTarget->scriptExecutionContext(), ImageBitmap
::create(image, IntRect(sx, sy, sw, sh))); |
114 } | 115 } |
115 | 116 |
116 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, H
TMLVideoElement* video, ExceptionState& es) | 117 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, H
TMLVideoElement* video, ExceptionState& es) |
117 { | 118 { |
118 IntSize s = sizeFor(video); | 119 IntSize s = sizeFor(video); |
119 return createImageBitmap(eventTarget, video, 0, 0, s.width(), s.height(), es
); | 120 return createImageBitmap(eventTarget, video, 0, 0, s.width(), s.height(), es
); |
(...skipping 18 matching lines...) Expand all Loading... |
138 } | 139 } |
139 if (video->player()->readyState() <= MediaPlayer::HaveMetadata) { | 140 if (video->player()->readyState() <= MediaPlayer::HaveMetadata) { |
140 es.throwDOMException(InvalidStateError); | 141 es.throwDOMException(InvalidStateError); |
141 return ScriptObject(); | 142 return ScriptObject(); |
142 } | 143 } |
143 if (!sw || !sh) { | 144 if (!sw || !sh) { |
144 es.throwDOMException(IndexSizeError); | 145 es.throwDOMException(IndexSizeError); |
145 return ScriptObject(); | 146 return ScriptObject(); |
146 } | 147 } |
147 if (!video->hasSingleSecurityOrigin()) { | 148 if (!video->hasSingleSecurityOrigin()) { |
148 es.throwDOMException(SecurityError); | 149 es.throwSecurityError(ExceptionMessages::failedToExecute("createImageBit
map", "ImageBitmapFactories", "the source video contains cross-origin image data
.")); |
149 return ScriptObject(); | 150 return ScriptObject(); |
150 } | 151 } |
151 if (!video->player()->didPassCORSAccessCheck() && eventTarget->toDOMWindow()
->document()->securityOrigin()->taintsCanvas(video->currentSrc())) { | 152 if (!video->player()->didPassCORSAccessCheck() && eventTarget->toDOMWindow()
->document()->securityOrigin()->taintsCanvas(video->currentSrc())) { |
152 es.throwDOMException(SecurityError); | 153 es.throwSecurityError(ExceptionMessages::failedToExecute("createImageBit
map", "ImageBitmapFactories", "cross-origin access to the source video is denied
.")); |
153 return ScriptObject(); | 154 return ScriptObject(); |
154 } | 155 } |
155 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 | 156 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 |
156 return fulfillImageBitmap(eventTarget->scriptExecutionContext(), ImageBitmap
::create(video, IntRect(sx, sy, sw, sh))); | 157 return fulfillImageBitmap(eventTarget->scriptExecutionContext(), ImageBitmap
::create(video, IntRect(sx, sy, sw, sh))); |
157 } | 158 } |
158 | 159 |
159 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, C
anvasRenderingContext2D* context, ExceptionState& es) | 160 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, C
anvasRenderingContext2D* context, ExceptionState& es) |
160 { | 161 { |
161 return createImageBitmap(eventTarget, context->canvas(), es); | 162 return createImageBitmap(eventTarget, context->canvas(), es); |
162 } | 163 } |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 m_resolver->fulfill(imageBitmap.release()); | 355 m_resolver->fulfill(imageBitmap.release()); |
355 m_factory->didFinishLoading(this); | 356 m_factory->didFinishLoading(this); |
356 } | 357 } |
357 | 358 |
358 void ImageBitmapFactories::ImageBitmapLoader::didFail(FileError::ErrorCode) | 359 void ImageBitmapFactories::ImageBitmapLoader::didFail(FileError::ErrorCode) |
359 { | 360 { |
360 rejectPromise(); | 361 rejectPromise(); |
361 } | 362 } |
362 | 363 |
363 } // namespace WebCore | 364 } // namespace WebCore |
OLD | NEW |