Chromium Code Reviews| 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 16 matching lines...) Expand all Loading... | |
| 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 "core/page/ImageBitmapFactories.h" | 32 #include "core/page/ImageBitmapFactories.h" |
| 33 | 33 |
| 34 #include "RuntimeEnabledFeatures.h" | 34 #include "RuntimeEnabledFeatures.h" |
| 35 #include "V8ImageBitmap.h" | 35 #include "V8ImageBitmap.h" |
| 36 #include "bindings/v8/ExceptionState.h" | 36 #include "bindings/v8/ExceptionState.h" |
| 37 #include "core/dom/ExceptionCode.h" | 37 #include "bindings/v8/ScriptScope.h" |
| 38 #include "bindings/v8/ScriptState.h" | |
| 38 #include "core/html/HTMLCanvasElement.h" | 39 #include "core/html/HTMLCanvasElement.h" |
| 39 #include "core/html/HTMLImageElement.h" | 40 #include "core/html/HTMLImageElement.h" |
| 40 #include "core/html/HTMLVideoElement.h" | 41 #include "core/html/HTMLVideoElement.h" |
| 41 #include "core/html/ImageData.h" | 42 #include "core/html/ImageData.h" |
| 42 #include "core/html/canvas/CanvasRenderingContext2D.h" | 43 #include "core/html/canvas/CanvasRenderingContext2D.h" |
| 43 #include "core/page/DOMWindow.h" | 44 #include "core/page/DOMWindow.h" |
| 44 #include "core/page/ImageBitmap.h" | 45 #include "core/page/ImageBitmap.h" |
| 46 #include "core/platform/SharedBuffer.h" | |
| 47 #include "core/platform/graphics/BitmapImage.h" | |
| 48 #include "core/platform/graphics/ImageSource.h" | |
| 49 #include "core/platform/graphics/skia/NativeImageSkia.h" | |
| 45 | 50 |
| 46 namespace WebCore { | 51 namespace WebCore { |
| 47 | 52 |
| 48 namespace ImageBitmapFactories { | |
| 49 | |
| 50 static LayoutSize sizeFor(HTMLImageElement* image) | 53 static LayoutSize sizeFor(HTMLImageElement* image) |
| 51 { | 54 { |
| 52 if (CachedImage* cachedImage = image->cachedImage()) | 55 if (CachedImage* cachedImage = image->cachedImage()) |
| 53 return cachedImage->imageSizeForRenderer(image->renderer(), 1.0f); // FI XME: Not sure about this. | 56 return cachedImage->imageSizeForRenderer(image->renderer(), 1.0f); // FI XME: Not sure about this. |
| 54 return IntSize(); | 57 return IntSize(); |
| 55 } | 58 } |
| 56 | 59 |
| 57 static IntSize sizeFor(HTMLVideoElement* video) | 60 static IntSize sizeFor(HTMLVideoElement* video) |
| 58 { | 61 { |
| 59 if (MediaPlayer* player = video->player()) | 62 if (MediaPlayer* player = video->player()) |
| 60 return player->naturalSize(); | 63 return player->naturalSize(); |
| 61 return IntSize(); | 64 return IntSize(); |
| 62 } | 65 } |
| 63 | 66 |
| 64 static ScriptObject resolveImageBitmap(PassRefPtr<ImageBitmap> imageBitmap) | 67 static ScriptObject fulfillImageBitmap(ScriptExecutionContext* context, PassRefP tr<ImageBitmap> imageBitmap) |
| 65 { | 68 { |
| 66 // Promises must be enabled. | 69 // Promises must be enabled. |
| 67 ASSERT(RuntimeEnabledFeatures::promiseEnabled()); | 70 ASSERT(RuntimeEnabledFeatures::promiseEnabled()); |
| 68 | 71 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(conte xt); |
| 69 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(); | |
| 70 resolver->fulfill(imageBitmap); | 72 resolver->fulfill(imageBitmap); |
| 71 return resolver->promise(); | 73 return resolver->promise(); |
| 72 } | 74 } |
| 73 | 75 |
| 74 ScriptObject createImageBitmap(EventTarget* eventTarget, HTMLImageElement* image , ExceptionState& es) | 76 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, H TMLImageElement* image, ExceptionState& es) |
| 75 { | 77 { |
| 76 LayoutSize s = sizeFor(image); | 78 LayoutSize s = sizeFor(image); |
| 77 return createImageBitmap(eventTarget, image, 0, 0, s.width(), s.height(), es ); | 79 return createImageBitmap(eventTarget, image, 0, 0, s.width(), s.height(), es ); |
| 78 } | 80 } |
| 79 | 81 |
| 80 ScriptObject createImageBitmap(EventTarget* eventTarget, HTMLImageElement* image , int sx, int sy, int sw, int sh, ExceptionState& es) | 82 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, H TMLImageElement* image, int sx, int sy, int sw, int sh, ExceptionState& es) |
| 81 { | 83 { |
| 82 if (!image) { | 84 if (!image) { |
| 83 es.throwTypeError(); | 85 es.throwTypeError(); |
| 84 return ScriptObject(); | 86 return ScriptObject(); |
| 85 } | 87 } |
| 86 if (!image->cachedImage()) { | 88 if (!image->cachedImage()) { |
| 87 es.throwDOMException(InvalidStateError); | 89 es.throwDOMException(InvalidStateError); |
| 88 return ScriptObject(); | 90 return ScriptObject(); |
| 89 } | 91 } |
| 90 if (image->cachedImage()->image()->isSVGImage()) { | 92 if (image->cachedImage()->image()->isSVGImage()) { |
| 91 es.throwDOMException(InvalidStateError); | 93 es.throwDOMException(InvalidStateError); |
| 92 return ScriptObject(); | 94 return ScriptObject(); |
| 93 } | 95 } |
| 94 if (!sw || !sh) { | 96 if (!sw || !sh) { |
| 95 es.throwDOMException(IndexSizeError); | 97 es.throwDOMException(IndexSizeError); |
| 96 return ScriptObject(); | 98 return ScriptObject(); |
| 97 } | 99 } |
| 98 if (!image->cachedImage()->image()->hasSingleSecurityOrigin()) { | 100 if (!image->cachedImage()->image()->hasSingleSecurityOrigin()) { |
| 99 es.throwDOMException(SecurityError); | 101 es.throwDOMException(SecurityError); |
| 100 return ScriptObject(); | 102 return ScriptObject(); |
| 101 } | 103 } |
| 102 if (!image->cachedImage()->passesAccessControlCheck(eventTarget->toDOMWindow ()->document()->securityOrigin()) | 104 if (!image->cachedImage()->passesAccessControlCheck(eventTarget->toDOMWindow ()->document()->securityOrigin()) |
| 103 && eventTarget->toDOMWindow()->document()->securityOrigin()->taintsCanvas(im age->src())) { | 105 && eventTarget->toDOMWindow()->document()->securityOrigin()->taintsCanvas(im age->src())) { |
| 104 es.throwDOMException(SecurityError); | 106 es.throwDOMException(SecurityError); |
| 105 return ScriptObject(); | 107 return ScriptObject(); |
| 106 } | 108 } |
| 107 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 | 109 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 |
| 108 return resolveImageBitmap(ImageBitmap::create(image, IntRect(sx, sy, sw, sh) )); | 110 return fulfillImageBitmap(eventTarget->scriptExecutionContext(), ImageBitmap ::create(image, IntRect(sx, sy, sw, sh))); |
| 109 } | 111 } |
| 110 | 112 |
| 111 ScriptObject createImageBitmap(EventTarget* eventTarget, HTMLVideoElement* video , ExceptionState& es) | 113 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, H TMLVideoElement* video, ExceptionState& es) |
| 112 { | 114 { |
| 113 IntSize s = sizeFor(video); | 115 IntSize s = sizeFor(video); |
| 114 return createImageBitmap(eventTarget, video, 0, 0, s.width(), s.height(), es ); | 116 return createImageBitmap(eventTarget, video, 0, 0, s.width(), s.height(), es ); |
| 115 } | 117 } |
| 116 | 118 |
| 117 ScriptObject createImageBitmap(EventTarget* eventTarget, HTMLVideoElement* video , int sx, int sy, int sw, int sh, ExceptionState& es) | 119 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, H TMLVideoElement* video, int sx, int sy, int sw, int sh, ExceptionState& es) |
| 118 { | 120 { |
| 119 if (!video) { | 121 if (!video) { |
| 120 es.throwTypeError(); | 122 es.throwTypeError(); |
| 121 return ScriptObject(); | 123 return ScriptObject(); |
| 122 } | 124 } |
| 123 if (!video->player()) { | 125 if (!video->player()) { |
| 124 es.throwDOMException(InvalidStateError); | 126 es.throwDOMException(InvalidStateError); |
| 125 return ScriptObject(); | 127 return ScriptObject(); |
| 126 } | 128 } |
| 127 if (video->networkState() == HTMLMediaElement::NETWORK_EMPTY) { | 129 if (video->networkState() == HTMLMediaElement::NETWORK_EMPTY) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 138 } | 140 } |
| 139 if (!video->hasSingleSecurityOrigin()) { | 141 if (!video->hasSingleSecurityOrigin()) { |
| 140 es.throwDOMException(SecurityError); | 142 es.throwDOMException(SecurityError); |
| 141 return ScriptObject(); | 143 return ScriptObject(); |
| 142 } | 144 } |
| 143 if (!video->player()->didPassCORSAccessCheck() && eventTarget->toDOMWindow() ->document()->securityOrigin()->taintsCanvas(video->currentSrc())) { | 145 if (!video->player()->didPassCORSAccessCheck() && eventTarget->toDOMWindow() ->document()->securityOrigin()->taintsCanvas(video->currentSrc())) { |
| 144 es.throwDOMException(SecurityError); | 146 es.throwDOMException(SecurityError); |
| 145 return ScriptObject(); | 147 return ScriptObject(); |
| 146 } | 148 } |
| 147 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 | 149 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 |
| 148 return resolveImageBitmap(ImageBitmap::create(video, IntRect(sx, sy, sw, sh) )); | 150 return fulfillImageBitmap(eventTarget->scriptExecutionContext(), ImageBitmap ::create(video, IntRect(sx, sy, sw, sh))); |
| 149 } | 151 } |
| 150 | 152 |
| 151 ScriptObject createImageBitmap(EventTarget* eventTarget, CanvasRenderingContext2 D* context, ExceptionState& es) | 153 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, C anvasRenderingContext2D* context, ExceptionState& es) |
| 152 { | 154 { |
| 153 return createImageBitmap(eventTarget, context->canvas(), es); | 155 return createImageBitmap(eventTarget, context->canvas(), es); |
| 154 } | 156 } |
| 155 | 157 |
| 156 ScriptObject createImageBitmap(EventTarget* eventTarget, CanvasRenderingContext2 D* context, int sx, int sy, int sw, int sh, ExceptionState& es) | 158 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, C anvasRenderingContext2D* context, int sx, int sy, int sw, int sh, ExceptionState & es) |
| 157 { | 159 { |
| 158 return createImageBitmap(eventTarget, context->canvas(), sx, sy, sw, sh, es) ; | 160 return createImageBitmap(eventTarget, context->canvas(), sx, sy, sw, sh, es) ; |
| 159 } | 161 } |
| 160 | 162 |
| 161 ScriptObject createImageBitmap(EventTarget* eventTarget, HTMLCanvasElement* canv as, ExceptionState& es) | 163 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, H TMLCanvasElement* canvas, ExceptionState& es) |
| 162 { | 164 { |
| 163 return createImageBitmap(eventTarget, canvas, 0, 0, canvas->width(), canvas- >height(), es); | 165 return createImageBitmap(eventTarget, canvas, 0, 0, canvas->width(), canvas- >height(), es); |
| 164 } | 166 } |
| 165 | 167 |
| 166 ScriptObject createImageBitmap(EventTarget* eventTarget, HTMLCanvasElement* canv as, int sx, int sy, int sw, int sh, ExceptionState& es) | 168 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, H TMLCanvasElement* canvas, int sx, int sy, int sw, int sh, ExceptionState& es) |
| 167 { | 169 { |
| 168 if (!canvas) { | 170 if (!canvas) { |
| 169 es.throwTypeError(); | 171 es.throwTypeError(); |
| 170 return ScriptObject(); | 172 return ScriptObject(); |
| 171 } | 173 } |
| 172 if (!canvas->originClean()) { | 174 if (!canvas->originClean()) { |
| 173 es.throwDOMException(InvalidStateError); | 175 es.throwDOMException(InvalidStateError); |
| 174 return ScriptObject(); | 176 return ScriptObject(); |
| 175 } | 177 } |
| 176 if (!sw || !sh) { | 178 if (!sw || !sh) { |
| 177 es.throwDOMException(IndexSizeError); | 179 es.throwDOMException(IndexSizeError); |
| 178 return ScriptObject(); | 180 return ScriptObject(); |
| 179 } | 181 } |
| 180 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 | 182 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 |
| 181 return resolveImageBitmap(ImageBitmap::create(canvas, IntRect(sx, sy, sw, sh ))); | 183 return fulfillImageBitmap(eventTarget->scriptExecutionContext(), ImageBitmap ::create(canvas, IntRect(sx, sy, sw, sh))); |
| 182 } | 184 } |
| 183 | 185 |
| 184 ScriptObject createImageBitmap(EventTarget* eventTarget, ImageData* data, Except ionState& es) | 186 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, B lob* blob, ExceptionState& es) |
| 187 { | |
| 188 // Promises must be enabled. | |
| 189 ASSERT(RuntimeEnabledFeatures::promiseEnabled()); | |
| 190 | |
| 191 if (!blob) { | |
| 192 es.throwDOMException(TypeError); | |
| 193 return ScriptObject(); | |
| 194 } | |
| 195 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(event Target->scriptExecutionContext()); | |
| 196 RefPtr<ImageBitmapLoader> loader = ImageBitmapFactories::ImageBitmapLoader:: create(eventTarget->toDOMWindow(), resolver, 0); | |
| 197 eventTarget->toDOMWindow()->didStartLoading(loader); | |
| 198 loader->loadBlobAsync(eventTarget->scriptExecutionContext(), blob); | |
| 199 return resolver->promise(); | |
| 200 } | |
| 201 | |
| 202 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, B lob* blob, int sx, int sy, int sw, int sh, ExceptionState& es) | |
| 203 { | |
| 204 // Promises must be enabled. | |
| 205 ASSERT(RuntimeEnabledFeatures::promiseEnabled()); | |
| 206 | |
| 207 if (!blob) { | |
| 208 es.throwDOMException(TypeError); | |
| 209 return ScriptObject(); | |
| 210 } | |
| 211 if (!sw || !sh) { | |
| 212 es.throwDOMException(IndexSizeError); | |
| 213 return ScriptObject(); | |
| 214 } | |
| 215 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(event Target->scriptExecutionContext()); | |
| 216 IntRect* cropRect = new IntRect(sx, sy, sw, sh); | |
| 217 RefPtr<ImageBitmapLoader> loader = ImageBitmapFactories::ImageBitmapLoader:: create(eventTarget->toDOMWindow(), resolver, cropRect); | |
| 218 loader->loadBlobAsync(eventTarget->scriptExecutionContext(), blob); | |
| 219 return resolver->promise(); | |
| 220 } | |
| 221 | |
| 222 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, I mageData* data, ExceptionState& es) | |
| 185 { | 223 { |
| 186 return createImageBitmap(eventTarget, data, 0, 0, data->width(), data->heigh t(), es); | 224 return createImageBitmap(eventTarget, data, 0, 0, data->width(), data->heigh t(), es); |
| 187 } | 225 } |
| 188 | 226 |
| 189 ScriptObject createImageBitmap(EventTarget* eventTarget, ImageData* data, int sx , int sy, int sw, int sh, ExceptionState& es) | 227 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, I mageData* data, int sx, int sy, int sw, int sh, ExceptionState& es) |
| 190 { | 228 { |
| 191 if (!data) { | 229 if (!data) { |
| 192 es.throwTypeError(); | 230 es.throwTypeError(); |
| 193 return ScriptObject(); | 231 return ScriptObject(); |
| 194 } | 232 } |
| 195 if (!sw || !sh) { | 233 if (!sw || !sh) { |
| 196 es.throwDOMException(IndexSizeError); | 234 es.throwDOMException(IndexSizeError); |
| 197 return ScriptObject(); | 235 return ScriptObject(); |
| 198 } | 236 } |
| 199 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 | 237 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 |
| 200 return resolveImageBitmap(ImageBitmap::create(data, IntRect(sx, sy, sw, sh)) ); | 238 return fulfillImageBitmap(eventTarget->scriptExecutionContext(), ImageBitmap ::create(data, IntRect(sx, sy, sw, sh))); |
| 201 } | 239 } |
| 202 | 240 |
| 203 ScriptObject createImageBitmap(EventTarget* eventTarget, ImageBitmap* bitmap, Ex ceptionState& es) | 241 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, I mageBitmap* bitmap, ExceptionState& es) |
| 204 { | 242 { |
| 205 return createImageBitmap(eventTarget, bitmap, 0, 0, bitmap->width(), bitmap- >height(), es); | 243 return createImageBitmap(eventTarget, bitmap, 0, 0, bitmap->width(), bitmap- >height(), es); |
| 206 } | 244 } |
| 207 | 245 |
| 208 ScriptObject createImageBitmap(EventTarget* eventTarget, ImageBitmap* bitmap, in t sx, int sy, int sw, int sh, ExceptionState& es) | 246 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, I mageBitmap* bitmap, int sx, int sy, int sw, int sh, ExceptionState& es) |
| 209 { | 247 { |
| 210 if (!bitmap) { | 248 if (!bitmap) { |
| 211 es.throwTypeError(); | 249 es.throwTypeError(); |
| 212 return ScriptObject(); | 250 return ScriptObject(); |
| 213 } | 251 } |
| 214 if (!sw || !sh) { | 252 if (!sw || !sh) { |
| 215 es.throwDOMException(IndexSizeError); | 253 es.throwDOMException(IndexSizeError); |
| 216 return ScriptObject(); | 254 return ScriptObject(); |
| 217 } | 255 } |
| 218 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 | 256 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 |
| 219 return resolveImageBitmap(ImageBitmap::create(bitmap, IntRect(sx, sy, sw, sh ))); | 257 return fulfillImageBitmap(eventTarget->scriptExecutionContext(), ImageBitmap ::create(bitmap, IntRect(sx, sy, sw, sh))); |
| 220 } | 258 } |
| 221 | 259 |
| 222 } // namespace ImageBitmapFactories | 260 void ImageBitmapFactories::didStartLoading(PassRefPtr<ImageBitmapLoader> loader) |
| 261 { | |
| 262 m_pendingLoaders.add(loader); | |
| 263 } | |
| 264 | |
| 265 void ImageBitmapFactories::didFinishLoading(PassRefPtr<ImageBitmapLoader> loader ) | |
| 266 { | |
| 267 ASSERT(m_pendingLoaders.contains(loader)); | |
| 268 m_pendingLoaders.remove(loader); | |
| 269 } | |
| 270 | |
| 271 ImageBitmapFactories::ImageBitmapLoader::ImageBitmapLoader(ImageBitmapFactories* factory, PassRefPtr<ScriptPromiseResolver> resolver, IntRect* cropRect) | |
| 272 : m_loader(FileReaderLoader::ReadAsArrayBuffer, this) | |
| 273 , m_scriptState(ScriptState::current()) | |
| 274 , m_factory(factory) | |
| 275 , m_resolver(resolver) | |
| 276 , m_cropRect(cropRect) | |
| 277 { | |
| 278 } | |
| 279 | |
| 280 void ImageBitmapFactories::ImageBitmapLoader::loadBlobAsync(ScriptExecutionConte xt* context, Blob* blob) | |
| 281 { | |
| 282 m_factory->didStartLoading(this); | |
| 283 m_loader.start(context, *blob); | |
| 284 } | |
| 285 | |
| 286 void ImageBitmapFactories::ImageBitmapLoader::rejectPromise() | |
| 287 { | |
| 288 ScriptScope scope(m_scriptState); | |
| 289 RefPtr<ImageBitmap> nullImageBitmap; | |
|
do-not-use
2013/08/12 15:15:59
It looks like we don't really need this variable.
| |
| 290 m_resolver->reject(nullImageBitmap.release()); | |
| 291 m_factory->didFinishLoading(this); | |
| 292 } | |
| 293 | |
| 294 void ImageBitmapFactories::ImageBitmapLoader::didFinishLoading() | |
| 295 { | |
| 296 if (!m_loader.arrayBufferResult()) { | |
| 297 rejectPromise(); | |
| 298 return; | |
| 299 } | |
| 300 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create((char*)m_loader.arr ayBufferResult()->data(), m_loader.arrayBufferResult()->byteLength()); | |
| 301 | |
| 302 OwnPtr<ImageSource> source = adoptPtr(new ImageSource()); | |
| 303 source->setData(sharedBuffer.get(), true); | |
| 304 RefPtr<NativeImageSkia> imageSkia = source->createFrameAtIndex(0); | |
| 305 if (!imageSkia) { | |
| 306 rejectPromise(); | |
| 307 return; | |
| 308 } | |
| 309 RefPtr<Image> image = BitmapImage::create(imageSkia); | |
| 310 | |
| 311 if (!m_cropRect) | |
| 312 m_cropRect = new IntRect(image->rect()); | |
| 313 if (!m_cropRect->width() || !m_cropRect->height()) { | |
| 314 rejectPromise(); | |
| 315 return; | |
| 316 } | |
| 317 | |
| 318 RefPtr<ImageBitmap> imageBitmap = ImageBitmap::create(image.get(), *m_cropRe ct); | |
| 319 ScriptScope scope(m_scriptState); | |
| 320 m_resolver->fulfill(imageBitmap.release()); | |
| 321 m_factory->didFinishLoading(this); | |
| 322 } | |
| 323 | |
| 324 void ImageBitmapFactories::ImageBitmapLoader::didFail(FileError::ErrorCode) | |
| 325 { | |
| 326 rejectPromise(); | |
| 327 } | |
| 328 | |
| 223 } // namespace WebCore | 329 } // namespace WebCore |
| OLD | NEW |