| 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 26 matching lines...) Expand all Loading... |
| 37 #include "bindings/v8/ExceptionState.h" | 37 #include "bindings/v8/ExceptionState.h" |
| 38 #include "bindings/v8/ScriptScope.h" | 38 #include "bindings/v8/ScriptScope.h" |
| 39 #include "bindings/v8/ScriptState.h" | 39 #include "bindings/v8/ScriptState.h" |
| 40 #include "core/html/HTMLCanvasElement.h" | 40 #include "core/html/HTMLCanvasElement.h" |
| 41 #include "core/html/HTMLImageElement.h" | 41 #include "core/html/HTMLImageElement.h" |
| 42 #include "core/html/HTMLVideoElement.h" | 42 #include "core/html/HTMLVideoElement.h" |
| 43 #include "core/html/ImageData.h" | 43 #include "core/html/ImageData.h" |
| 44 #include "core/html/canvas/CanvasRenderingContext2D.h" | 44 #include "core/html/canvas/CanvasRenderingContext2D.h" |
| 45 #include "core/page/DOMWindow.h" | 45 #include "core/page/DOMWindow.h" |
| 46 #include "core/page/ImageBitmap.h" | 46 #include "core/page/ImageBitmap.h" |
| 47 #include "platform/SharedBuffer.h" | |
| 48 #include "core/platform/graphics/BitmapImage.h" | 47 #include "core/platform/graphics/BitmapImage.h" |
| 49 #include "core/platform/graphics/ImageSource.h" | 48 #include "core/platform/graphics/ImageSource.h" |
| 50 #include "core/platform/graphics/skia/NativeImageSkia.h" | 49 #include "core/platform/graphics/skia/NativeImageSkia.h" |
| 50 #include "platform/SharedBuffer.h" |
| 51 | 51 |
| 52 namespace WebCore { | 52 namespace WebCore { |
| 53 | 53 |
| 54 static LayoutSize sizeFor(HTMLImageElement* image) | 54 static LayoutSize sizeFor(HTMLImageElement* image) |
| 55 { | 55 { |
| 56 if (ImageResource* cachedImage = image->cachedImage()) | 56 if (ImageResource* cachedImage = image->cachedImage()) |
| 57 return cachedImage->imageSizeForRenderer(image->renderer(), 1.0f); // FI
XME: Not sure about this. | 57 return cachedImage->imageSizeForRenderer(image->renderer(), 1.0f); // FI
XME: Not sure about this. |
| 58 return IntSize(); | 58 return IntSize(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 static IntSize sizeFor(HTMLVideoElement* video) | 61 static IntSize sizeFor(HTMLVideoElement* video) |
| 62 { | 62 { |
| 63 if (MediaPlayer* player = video->player()) | 63 if (MediaPlayer* player = video->player()) |
| 64 return player->naturalSize(); | 64 return player->naturalSize(); |
| 65 return IntSize(); | 65 return IntSize(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 static ScriptPromise fulfillImageBitmap(ScriptExecutionContext* context, PassRef
Ptr<ImageBitmap> imageBitmap) | 68 static ScriptPromise fulfillImageBitmap(ScriptExecutionContext* context, PassRef
Ptr<ImageBitmap> imageBitmap) |
| 69 { | 69 { |
| 70 // Promises must be enabled. | 70 // Promises must be enabled. |
| 71 ASSERT(RuntimeEnabledFeatures::promiseEnabled()); | 71 ASSERT(RuntimeEnabledFeatures::promiseEnabled()); |
| 72 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(conte
xt); | 72 ScriptPromise promise = ScriptPromise::create(context); |
| 73 resolver->fulfill(imageBitmap); | 73 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promi
se, context); |
| 74 return resolver->promise(); | 74 resolver->resolve(imageBitmap); |
| 75 return promise; |
| 75 } | 76 } |
| 76 | 77 |
| 77 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget,
HTMLImageElement* image, ExceptionState& es) | 78 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget,
HTMLImageElement* image, ExceptionState& es) |
| 78 { | 79 { |
| 79 LayoutSize s = sizeFor(image); | 80 LayoutSize s = sizeFor(image); |
| 80 return createImageBitmap(eventTarget, image, 0, 0, s.width(), s.height(), es
); | 81 return createImageBitmap(eventTarget, image, 0, 0, s.width(), s.height(), es
); |
| 81 } | 82 } |
| 82 | 83 |
| 83 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget,
HTMLImageElement* image, int sx, int sy, int sw, int sh, ExceptionState& es) | 84 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget,
HTMLImageElement* image, int sx, int sy, int sw, int sh, ExceptionState& es) |
| 84 { | 85 { |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 196 |
| 196 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget,
Blob* blob, ExceptionState& es) | 197 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget,
Blob* blob, ExceptionState& es) |
| 197 { | 198 { |
| 198 // Promises must be enabled. | 199 // Promises must be enabled. |
| 199 ASSERT(RuntimeEnabledFeatures::promiseEnabled()); | 200 ASSERT(RuntimeEnabledFeatures::promiseEnabled()); |
| 200 | 201 |
| 201 if (!blob) { | 202 if (!blob) { |
| 202 es.throwUninformativeAndGenericDOMException(TypeError); | 203 es.throwUninformativeAndGenericDOMException(TypeError); |
| 203 return ScriptPromise(); | 204 return ScriptPromise(); |
| 204 } | 205 } |
| 205 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(event
Target->scriptExecutionContext()); | 206 ScriptPromise promise = ScriptPromise::create(eventTarget->scriptExecutionCo
ntext()); |
| 207 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promi
se, eventTarget->scriptExecutionContext()); |
| 206 RefPtr<ImageBitmapLoader> loader = ImageBitmapFactories::ImageBitmapLoader::
create(from(eventTarget), resolver, IntRect()); | 208 RefPtr<ImageBitmapLoader> loader = ImageBitmapFactories::ImageBitmapLoader::
create(from(eventTarget), resolver, IntRect()); |
| 207 from(eventTarget)->addLoader(loader); | 209 from(eventTarget)->addLoader(loader); |
| 208 loader->loadBlobAsync(eventTarget->scriptExecutionContext(), blob); | 210 loader->loadBlobAsync(eventTarget->scriptExecutionContext(), blob); |
| 209 return resolver->promise(); | 211 return promise; |
| 210 } | 212 } |
| 211 | 213 |
| 212 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget,
Blob* blob, int sx, int sy, int sw, int sh, ExceptionState& es) | 214 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget,
Blob* blob, int sx, int sy, int sw, int sh, ExceptionState& es) |
| 213 { | 215 { |
| 214 // Promises must be enabled. | 216 // Promises must be enabled. |
| 215 ASSERT(RuntimeEnabledFeatures::promiseEnabled()); | 217 ASSERT(RuntimeEnabledFeatures::promiseEnabled()); |
| 216 | 218 |
| 217 if (!blob) { | 219 if (!blob) { |
| 218 es.throwUninformativeAndGenericDOMException(TypeError); | 220 es.throwUninformativeAndGenericDOMException(TypeError); |
| 219 return ScriptPromise(); | 221 return ScriptPromise(); |
| 220 } | 222 } |
| 221 if (!sw || !sh) { | 223 if (!sw || !sh) { |
| 222 es.throwUninformativeAndGenericDOMException(IndexSizeError); | 224 es.throwUninformativeAndGenericDOMException(IndexSizeError); |
| 223 return ScriptPromise(); | 225 return ScriptPromise(); |
| 224 } | 226 } |
| 225 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(event
Target->scriptExecutionContext()); | 227 ScriptPromise promise = ScriptPromise::create(eventTarget->scriptExecutionCo
ntext()); |
| 228 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promi
se, eventTarget->scriptExecutionContext()); |
| 226 RefPtr<ImageBitmapLoader> loader = ImageBitmapFactories::ImageBitmapLoader::
create(from(eventTarget), resolver, IntRect(sx, sy, sw, sh)); | 229 RefPtr<ImageBitmapLoader> loader = ImageBitmapFactories::ImageBitmapLoader::
create(from(eventTarget), resolver, IntRect(sx, sy, sw, sh)); |
| 227 from(eventTarget)->addLoader(loader); | 230 from(eventTarget)->addLoader(loader); |
| 228 loader->loadBlobAsync(eventTarget->scriptExecutionContext(), blob); | 231 loader->loadBlobAsync(eventTarget->scriptExecutionContext(), blob); |
| 229 return resolver->promise(); | 232 return promise; |
| 230 } | 233 } |
| 231 | 234 |
| 232 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget,
ImageData* data, ExceptionState& es) | 235 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget,
ImageData* data, ExceptionState& es) |
| 233 { | 236 { |
| 234 return createImageBitmap(eventTarget, data, 0, 0, data->width(), data->heigh
t(), es); | 237 return createImageBitmap(eventTarget, data, 0, 0, data->width(), data->heigh
t(), es); |
| 235 } | 238 } |
| 236 | 239 |
| 237 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget,
ImageData* data, int sx, int sy, int sw, int sh, ExceptionState& es) | 240 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget,
ImageData* data, int sx, int sy, int sw, int sh, ExceptionState& es) |
| 238 { | 241 { |
| 239 if (!data) { | 242 if (!data) { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 rejectPromise(); | 349 rejectPromise(); |
| 347 return; | 350 return; |
| 348 } | 351 } |
| 349 if (!m_cropRect.width() && !m_cropRect.height()) { | 352 if (!m_cropRect.width() && !m_cropRect.height()) { |
| 350 // No cropping variant was called. | 353 // No cropping variant was called. |
| 351 m_cropRect = IntRect(IntPoint(), image->size()); | 354 m_cropRect = IntRect(IntPoint(), image->size()); |
| 352 } | 355 } |
| 353 | 356 |
| 354 RefPtr<ImageBitmap> imageBitmap = ImageBitmap::create(image.get(), m_cropRec
t); | 357 RefPtr<ImageBitmap> imageBitmap = ImageBitmap::create(image.get(), m_cropRec
t); |
| 355 ScriptScope scope(m_scriptState); | 358 ScriptScope scope(m_scriptState); |
| 356 m_resolver->fulfill(imageBitmap.release()); | 359 m_resolver->resolve(imageBitmap.release()); |
| 357 m_factory->didFinishLoading(this); | 360 m_factory->didFinishLoading(this); |
| 358 } | 361 } |
| 359 | 362 |
| 360 void ImageBitmapFactories::ImageBitmapLoader::didFail(FileError::ErrorCode) | 363 void ImageBitmapFactories::ImageBitmapLoader::didFail(FileError::ErrorCode) |
| 361 { | 364 { |
| 362 rejectPromise(); | 365 rejectPromise(); |
| 363 } | 366 } |
| 364 | 367 |
| 365 } // namespace WebCore | 368 } // namespace WebCore |
| OLD | NEW |