| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 { | 81 { |
| 82 LayoutSize s = sizeFor(image); | 82 LayoutSize s = sizeFor(image); |
| 83 return createImageBitmap(eventTarget, image, 0, 0, s.width(), s.height(), ex
ceptionState); | 83 return createImageBitmap(eventTarget, image, 0, 0, s.width(), s.height(), ex
ceptionState); |
| 84 } | 84 } |
| 85 | 85 |
| 86 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget& eventTarget,
HTMLImageElement* image, int sx, int sy, int sw, int sh, ExceptionState& excepti
onState) | 86 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget& eventTarget,
HTMLImageElement* image, int sx, int sy, int sw, int sh, ExceptionState& excepti
onState) |
| 87 { | 87 { |
| 88 // This variant does not work in worker threads. | 88 // This variant does not work in worker threads. |
| 89 ASSERT(eventTarget.toDOMWindow()); | 89 ASSERT(eventTarget.toDOMWindow()); |
| 90 | 90 |
| 91 if (!image) { | |
| 92 exceptionState.throwTypeError("The image element provided is invalid."); | |
| 93 return ScriptPromise(); | |
| 94 } | |
| 95 if (!image->cachedImage()) { | 91 if (!image->cachedImage()) { |
| 96 exceptionState.throwDOMException(InvalidStateError, "No image can be ret
rieved from the provided element."); | 92 exceptionState.throwDOMException(InvalidStateError, "No image can be ret
rieved from the provided element."); |
| 97 return ScriptPromise(); | 93 return ScriptPromise(); |
| 98 } | 94 } |
| 99 if (image->cachedImage()->image()->isSVGImage()) { | 95 if (image->cachedImage()->image()->isSVGImage()) { |
| 100 exceptionState.throwDOMException(InvalidStateError, "The image element c
ontains an SVG image, which is unsupported."); | 96 exceptionState.throwDOMException(InvalidStateError, "The image element c
ontains an SVG image, which is unsupported."); |
| 101 return ScriptPromise(); | 97 return ScriptPromise(); |
| 102 } | 98 } |
| 103 if (!sw || !sh) { | 99 if (!sw || !sh) { |
| 104 exceptionState.throwDOMException(IndexSizeError, String::format("The sou
rce %s provided is 0.", sw ? "height" : "width")); | 100 exceptionState.throwDOMException(IndexSizeError, String::format("The sou
rce %s provided is 0.", sw ? "height" : "width")); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 120 { | 116 { |
| 121 IntSize s = sizeFor(video); | 117 IntSize s = sizeFor(video); |
| 122 return createImageBitmap(eventTarget, video, 0, 0, s.width(), s.height(), ex
ceptionState); | 118 return createImageBitmap(eventTarget, video, 0, 0, s.width(), s.height(), ex
ceptionState); |
| 123 } | 119 } |
| 124 | 120 |
| 125 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget& eventTarget,
HTMLVideoElement* video, int sx, int sy, int sw, int sh, ExceptionState& excepti
onState) | 121 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget& eventTarget,
HTMLVideoElement* video, int sx, int sy, int sw, int sh, ExceptionState& excepti
onState) |
| 126 { | 122 { |
| 127 // This variant does not work in worker threads. | 123 // This variant does not work in worker threads. |
| 128 ASSERT(eventTarget.toDOMWindow()); | 124 ASSERT(eventTarget.toDOMWindow()); |
| 129 | 125 |
| 130 if (!video) { | |
| 131 exceptionState.throwTypeError("The video element provided is invalid."); | |
| 132 return ScriptPromise(); | |
| 133 } | |
| 134 if (!video->player()) { | 126 if (!video->player()) { |
| 135 exceptionState.throwDOMException(InvalidStateError, "No player can be re
trieved from the provided video element."); | 127 exceptionState.throwDOMException(InvalidStateError, "No player can be re
trieved from the provided video element."); |
| 136 return ScriptPromise(); | 128 return ScriptPromise(); |
| 137 } | 129 } |
| 138 if (video->networkState() == HTMLMediaElement::NETWORK_EMPTY) { | 130 if (video->networkState() == HTMLMediaElement::NETWORK_EMPTY) { |
| 139 exceptionState.throwDOMException(InvalidStateError, "The provided elemen
t has not retrieved data."); | 131 exceptionState.throwDOMException(InvalidStateError, "The provided elemen
t has not retrieved data."); |
| 140 return ScriptPromise(); | 132 return ScriptPromise(); |
| 141 } | 133 } |
| 142 if (video->player()->readyState() <= MediaPlayer::HaveMetadata) { | 134 if (video->player()->readyState() <= MediaPlayer::HaveMetadata) { |
| 143 exceptionState.throwDOMException(InvalidStateError, "The provided elemen
t's player has no current data."); | 135 exceptionState.throwDOMException(InvalidStateError, "The provided elemen
t's player has no current data."); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 172 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget& eventTarget,
HTMLCanvasElement* canvas, ExceptionState& exceptionState) | 164 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget& eventTarget,
HTMLCanvasElement* canvas, ExceptionState& exceptionState) |
| 173 { | 165 { |
| 174 return createImageBitmap(eventTarget, canvas, 0, 0, canvas->width(), canvas-
>height(), exceptionState); | 166 return createImageBitmap(eventTarget, canvas, 0, 0, canvas->width(), canvas-
>height(), exceptionState); |
| 175 } | 167 } |
| 176 | 168 |
| 177 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget& eventTarget,
HTMLCanvasElement* canvas, int sx, int sy, int sw, int sh, ExceptionState& excep
tionState) | 169 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget& eventTarget,
HTMLCanvasElement* canvas, int sx, int sy, int sw, int sh, ExceptionState& excep
tionState) |
| 178 { | 170 { |
| 179 // This variant does not work in worker threads. | 171 // This variant does not work in worker threads. |
| 180 ASSERT(eventTarget.toDOMWindow()); | 172 ASSERT(eventTarget.toDOMWindow()); |
| 181 | 173 |
| 182 if (!canvas) { | |
| 183 exceptionState.throwTypeError("The canvas element provided is invalid.")
; | |
| 184 return ScriptPromise(); | |
| 185 } | |
| 186 if (!canvas->originClean()) { | 174 if (!canvas->originClean()) { |
| 187 exceptionState.throwSecurityError("The canvas element provided is tainte
d with cross-origin data."); | 175 exceptionState.throwSecurityError("The canvas element provided is tainte
d with cross-origin data."); |
| 188 return ScriptPromise(); | 176 return ScriptPromise(); |
| 189 } | 177 } |
| 190 if (!sw || !sh) { | 178 if (!sw || !sh) { |
| 191 exceptionState.throwDOMException(IndexSizeError, String::format("The sou
rce %s provided is 0.", sw ? "height" : "width")); | 179 exceptionState.throwDOMException(IndexSizeError, String::format("The sou
rce %s provided is 0.", sw ? "height" : "width")); |
| 192 return ScriptPromise(); | 180 return ScriptPromise(); |
| 193 } | 181 } |
| 194 | 182 |
| 195 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 | 183 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 |
| 196 return fulfillImageBitmap(eventTarget.executionContext(), canvas->buffer() ?
ImageBitmap::create(canvas, IntRect(sx, sy, sw, sh)) : nullptr); | 184 return fulfillImageBitmap(eventTarget.executionContext(), canvas->buffer() ?
ImageBitmap::create(canvas, IntRect(sx, sy, sw, sh)) : nullptr); |
| 197 } | 185 } |
| 198 | 186 |
| 199 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget& eventTarget,
Blob* blob, ExceptionState& exceptionState) | 187 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget& eventTarget,
Blob* blob, ExceptionState& exceptionState) |
| 200 { | 188 { |
| 201 if (!blob) { | |
| 202 exceptionState.throwTypeError("The blob provided is invalid."); | |
| 203 return ScriptPromise(); | |
| 204 } | |
| 205 RefPtr<ImageBitmapLoader> loader = ImageBitmapFactories::ImageBitmapLoader::
create(from(eventTarget), eventTarget.executionContext(), IntRect()); | 189 RefPtr<ImageBitmapLoader> loader = ImageBitmapFactories::ImageBitmapLoader::
create(from(eventTarget), eventTarget.executionContext(), IntRect()); |
| 206 ScriptPromise promise = loader->promise(); | 190 ScriptPromise promise = loader->promise(); |
| 207 from(eventTarget).addLoader(loader); | 191 from(eventTarget).addLoader(loader); |
| 208 loader->loadBlobAsync(eventTarget.executionContext(), blob); | 192 loader->loadBlobAsync(eventTarget.executionContext(), blob); |
| 209 return promise; | 193 return promise; |
| 210 } | 194 } |
| 211 | 195 |
| 212 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget& eventTarget,
Blob* blob, int sx, int sy, int sw, int sh, ExceptionState& exceptionState) | 196 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget& eventTarget,
Blob* blob, int sx, int sy, int sw, int sh, ExceptionState& exceptionState) |
| 213 { | 197 { |
| 214 if (!blob) { | |
| 215 exceptionState.throwTypeError("The blob provided is invalid."); | |
| 216 return ScriptPromise(); | |
| 217 } | |
| 218 if (!sw || !sh) { | 198 if (!sw || !sh) { |
| 219 exceptionState.throwDOMException(IndexSizeError, String::format("The sou
rce %s provided is 0.", sw ? "height" : "width")); | 199 exceptionState.throwDOMException(IndexSizeError, String::format("The sou
rce %s provided is 0.", sw ? "height" : "width")); |
| 220 return ScriptPromise(); | 200 return ScriptPromise(); |
| 221 } | 201 } |
| 222 RefPtr<ImageBitmapLoader> loader = ImageBitmapFactories::ImageBitmapLoader::
create(from(eventTarget), eventTarget.executionContext(), IntRect(sx, sy, sw, sh
)); | 202 RefPtr<ImageBitmapLoader> loader = ImageBitmapFactories::ImageBitmapLoader::
create(from(eventTarget), eventTarget.executionContext(), IntRect(sx, sy, sw, sh
)); |
| 223 ScriptPromise promise = loader->promise(); | 203 ScriptPromise promise = loader->promise(); |
| 224 from(eventTarget).addLoader(loader); | 204 from(eventTarget).addLoader(loader); |
| 225 loader->loadBlobAsync(eventTarget.executionContext(), blob); | 205 loader->loadBlobAsync(eventTarget.executionContext(), blob); |
| 226 return promise; | 206 return promise; |
| 227 } | 207 } |
| 228 | 208 |
| 229 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget& eventTarget,
ImageData* data, ExceptionState& exceptionState) | 209 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget& eventTarget,
ImageData* data, ExceptionState& exceptionState) |
| 230 { | 210 { |
| 231 return createImageBitmap(eventTarget, data, 0, 0, data->width(), data->heigh
t(), exceptionState); | 211 return createImageBitmap(eventTarget, data, 0, 0, data->width(), data->heigh
t(), exceptionState); |
| 232 } | 212 } |
| 233 | 213 |
| 234 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget& eventTarget,
ImageData* data, int sx, int sy, int sw, int sh, ExceptionState& exceptionState) | 214 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget& eventTarget,
ImageData* data, int sx, int sy, int sw, int sh, ExceptionState& exceptionState) |
| 235 { | 215 { |
| 236 if (!data) { | |
| 237 exceptionState.throwTypeError("The ImageData provided is invalid."); | |
| 238 return ScriptPromise(); | |
| 239 } | |
| 240 if (!sw || !sh) { | 216 if (!sw || !sh) { |
| 241 exceptionState.throwDOMException(IndexSizeError, String::format("The sou
rce %s provided is 0.", sw ? "height" : "width")); | 217 exceptionState.throwDOMException(IndexSizeError, String::format("The sou
rce %s provided is 0.", sw ? "height" : "width")); |
| 242 return ScriptPromise(); | 218 return ScriptPromise(); |
| 243 } | 219 } |
| 244 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 | 220 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 |
| 245 return fulfillImageBitmap(eventTarget.executionContext(), ImageBitmap::creat
e(data, IntRect(sx, sy, sw, sh))); | 221 return fulfillImageBitmap(eventTarget.executionContext(), ImageBitmap::creat
e(data, IntRect(sx, sy, sw, sh))); |
| 246 } | 222 } |
| 247 | 223 |
| 248 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget& eventTarget,
ImageBitmap* bitmap, ExceptionState& exceptionState) | 224 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget& eventTarget,
ImageBitmap* bitmap, ExceptionState& exceptionState) |
| 249 { | 225 { |
| 250 return createImageBitmap(eventTarget, bitmap, 0, 0, bitmap->width(), bitmap-
>height(), exceptionState); | 226 return createImageBitmap(eventTarget, bitmap, 0, 0, bitmap->width(), bitmap-
>height(), exceptionState); |
| 251 } | 227 } |
| 252 | 228 |
| 253 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget& eventTarget,
ImageBitmap* bitmap, int sx, int sy, int sw, int sh, ExceptionState& exceptionSt
ate) | 229 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget& eventTarget,
ImageBitmap* bitmap, int sx, int sy, int sw, int sh, ExceptionState& exceptionSt
ate) |
| 254 { | 230 { |
| 255 if (!bitmap) { | |
| 256 exceptionState.throwTypeError("The ImageBitmap provided is invalid."); | |
| 257 return ScriptPromise(); | |
| 258 } | |
| 259 if (!sw || !sh) { | 231 if (!sw || !sh) { |
| 260 exceptionState.throwDOMException(IndexSizeError, String::format("The sou
rce %s provided is 0.", sw ? "height" : "width")); | 232 exceptionState.throwDOMException(IndexSizeError, String::format("The sou
rce %s provided is 0.", sw ? "height" : "width")); |
| 261 return ScriptPromise(); | 233 return ScriptPromise(); |
| 262 } | 234 } |
| 263 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 | 235 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 |
| 264 return fulfillImageBitmap(eventTarget.executionContext(), ImageBitmap::creat
e(bitmap, IntRect(sx, sy, sw, sh))); | 236 return fulfillImageBitmap(eventTarget.executionContext(), ImageBitmap::creat
e(bitmap, IntRect(sx, sy, sw, sh))); |
| 265 } | 237 } |
| 266 | 238 |
| 267 const char* ImageBitmapFactories::supplementName() | 239 const char* ImageBitmapFactories::supplementName() |
| 268 { | 240 { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 m_resolver->resolve(imageBitmap.release()); | 321 m_resolver->resolve(imageBitmap.release()); |
| 350 m_factory->didFinishLoading(this); | 322 m_factory->didFinishLoading(this); |
| 351 } | 323 } |
| 352 | 324 |
| 353 void ImageBitmapFactories::ImageBitmapLoader::didFail(FileError::ErrorCode) | 325 void ImageBitmapFactories::ImageBitmapLoader::didFail(FileError::ErrorCode) |
| 354 { | 326 { |
| 355 rejectPromise(); | 327 rejectPromise(); |
| 356 } | 328 } |
| 357 | 329 |
| 358 } // namespace WebCore | 330 } // namespace WebCore |
| OLD | NEW |