| 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 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 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 "bindings/v8/ExceptionMessages.h" | |
| 35 #include "bindings/v8/ExceptionState.h" | 34 #include "bindings/v8/ExceptionState.h" |
| 36 #include "bindings/v8/ScriptScope.h" | 35 #include "bindings/v8/ScriptScope.h" |
| 37 #include "core/fileapi/Blob.h" | 36 #include "core/fileapi/Blob.h" |
| 38 #include "core/html/HTMLCanvasElement.h" | 37 #include "core/html/HTMLCanvasElement.h" |
| 39 #include "core/html/HTMLImageElement.h" | 38 #include "core/html/HTMLImageElement.h" |
| 40 #include "core/html/HTMLVideoElement.h" | 39 #include "core/html/HTMLVideoElement.h" |
| 41 #include "core/html/ImageData.h" | 40 #include "core/html/ImageData.h" |
| 42 #include "core/html/canvas/CanvasRenderingContext2D.h" | 41 #include "core/html/canvas/CanvasRenderingContext2D.h" |
| 43 #include "core/frame/DOMWindow.h" | 42 #include "core/frame/DOMWindow.h" |
| 44 #include "core/frame/ImageBitmap.h" | 43 #include "core/frame/ImageBitmap.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 } | 92 } |
| 94 if (image->cachedImage()->image()->isSVGImage()) { | 93 if (image->cachedImage()->image()->isSVGImage()) { |
| 95 exceptionState.throwUninformativeAndGenericDOMException(InvalidStateErro
r); | 94 exceptionState.throwUninformativeAndGenericDOMException(InvalidStateErro
r); |
| 96 return ScriptPromise(); | 95 return ScriptPromise(); |
| 97 } | 96 } |
| 98 if (!sw || !sh) { | 97 if (!sw || !sh) { |
| 99 exceptionState.throwUninformativeAndGenericDOMException(IndexSizeError); | 98 exceptionState.throwUninformativeAndGenericDOMException(IndexSizeError); |
| 100 return ScriptPromise(); | 99 return ScriptPromise(); |
| 101 } | 100 } |
| 102 if (!image->cachedImage()->image()->currentFrameHasSingleSecurityOrigin()) { | 101 if (!image->cachedImage()->image()->currentFrameHasSingleSecurityOrigin()) { |
| 103 exceptionState.throwSecurityError(ExceptionMessages::failedToExecute("cr
eateImageBitmap", "ImageBitmapFactories", "the source image contains cross-origi
n image data.")); | 102 exceptionState.throwSecurityError("the source image contains cross-origi
n image data."); |
| 104 return ScriptPromise(); | 103 return ScriptPromise(); |
| 105 } | 104 } |
| 106 if (!image->cachedImage()->passesAccessControlCheck(eventTarget->toDOMWindow
()->document()->securityOrigin()) | 105 if (!image->cachedImage()->passesAccessControlCheck(eventTarget->toDOMWindow
()->document()->securityOrigin()) |
| 107 && eventTarget->toDOMWindow()->document()->securityOrigin()->taintsCanvas(im
age->src())) { | 106 && eventTarget->toDOMWindow()->document()->securityOrigin()->taintsCanvas(im
age->src())) { |
| 108 exceptionState.throwSecurityError(ExceptionMessages::failedToExecute("cr
eateImageBitmap", "ImageBitmapFactories", "cross-origin access to the source ima
ge is denied.")); | 107 exceptionState.throwSecurityError("cross-origin access to the source ima
ge is denied."); |
| 109 return ScriptPromise(); | 108 return ScriptPromise(); |
| 110 } | 109 } |
| 111 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 | 110 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 |
| 112 return fulfillImageBitmap(eventTarget->executionContext(), ImageBitmap::crea
te(image, IntRect(sx, sy, sw, sh))); | 111 return fulfillImageBitmap(eventTarget->executionContext(), ImageBitmap::crea
te(image, IntRect(sx, sy, sw, sh))); |
| 113 } | 112 } |
| 114 | 113 |
| 115 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget,
HTMLVideoElement* video, ExceptionState& exceptionState) | 114 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget,
HTMLVideoElement* video, ExceptionState& exceptionState) |
| 116 { | 115 { |
| 117 IntSize s = sizeFor(video); | 116 IntSize s = sizeFor(video); |
| 118 return createImageBitmap(eventTarget, video, 0, 0, s.width(), s.height(), ex
ceptionState); | 117 return createImageBitmap(eventTarget, video, 0, 0, s.width(), s.height(), ex
ceptionState); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 137 } | 136 } |
| 138 if (video->player()->readyState() <= MediaPlayer::HaveMetadata) { | 137 if (video->player()->readyState() <= MediaPlayer::HaveMetadata) { |
| 139 exceptionState.throwUninformativeAndGenericDOMException(InvalidStateErro
r); | 138 exceptionState.throwUninformativeAndGenericDOMException(InvalidStateErro
r); |
| 140 return ScriptPromise(); | 139 return ScriptPromise(); |
| 141 } | 140 } |
| 142 if (!sw || !sh) { | 141 if (!sw || !sh) { |
| 143 exceptionState.throwUninformativeAndGenericDOMException(IndexSizeError); | 142 exceptionState.throwUninformativeAndGenericDOMException(IndexSizeError); |
| 144 return ScriptPromise(); | 143 return ScriptPromise(); |
| 145 } | 144 } |
| 146 if (!video->hasSingleSecurityOrigin()) { | 145 if (!video->hasSingleSecurityOrigin()) { |
| 147 exceptionState.throwSecurityError(ExceptionMessages::failedToExecute("cr
eateImageBitmap", "ImageBitmapFactories", "the source video contains cross-origi
n image data.")); | 146 exceptionState.throwSecurityError("the source video contains cross-origi
n image data."); |
| 148 return ScriptPromise(); | 147 return ScriptPromise(); |
| 149 } | 148 } |
| 150 if (!video->player()->didPassCORSAccessCheck() && eventTarget->toDOMWindow()
->document()->securityOrigin()->taintsCanvas(video->currentSrc())) { | 149 if (!video->player()->didPassCORSAccessCheck() && eventTarget->toDOMWindow()
->document()->securityOrigin()->taintsCanvas(video->currentSrc())) { |
| 151 exceptionState.throwSecurityError(ExceptionMessages::failedToExecute("cr
eateImageBitmap", "ImageBitmapFactories", "cross-origin access to the source vid
eo is denied.")); | 150 exceptionState.throwSecurityError("cross-origin access to the source vid
eo is denied."); |
| 152 return ScriptPromise(); | 151 return ScriptPromise(); |
| 153 } | 152 } |
| 154 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 | 153 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 |
| 155 return fulfillImageBitmap(eventTarget->executionContext(), ImageBitmap::crea
te(video, IntRect(sx, sy, sw, sh))); | 154 return fulfillImageBitmap(eventTarget->executionContext(), ImageBitmap::crea
te(video, IntRect(sx, sy, sw, sh))); |
| 156 } | 155 } |
| 157 | 156 |
| 158 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget,
CanvasRenderingContext2D* context, ExceptionState& exceptionState) | 157 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget,
CanvasRenderingContext2D* context, ExceptionState& exceptionState) |
| 159 { | 158 { |
| 160 return createImageBitmap(eventTarget, context->canvas(), exceptionState); | 159 return createImageBitmap(eventTarget, context->canvas(), exceptionState); |
| 161 } | 160 } |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 m_resolver->resolve(imageBitmap.release()); | 349 m_resolver->resolve(imageBitmap.release()); |
| 351 m_factory->didFinishLoading(this); | 350 m_factory->didFinishLoading(this); |
| 352 } | 351 } |
| 353 | 352 |
| 354 void ImageBitmapFactories::ImageBitmapLoader::didFail(FileError::ErrorCode) | 353 void ImageBitmapFactories::ImageBitmapLoader::didFail(FileError::ErrorCode) |
| 355 { | 354 { |
| 356 rejectPromise(); | 355 rejectPromise(); |
| 357 } | 356 } |
| 358 | 357 |
| 359 } // namespace WebCore | 358 } // namespace WebCore |
| OLD | NEW |