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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 return IntSize(); | 56 return IntSize(); |
| 57 } | 57 } |
| 58 | 58 |
| 59 static IntSize sizeFor(HTMLVideoElement* video) | 59 static IntSize sizeFor(HTMLVideoElement* video) |
| 60 { | 60 { |
| 61 if (MediaPlayer* player = video->player()) | 61 if (MediaPlayer* player = video->player()) |
| 62 return player->naturalSize(); | 62 return player->naturalSize(); |
| 63 return IntSize(); | 63 return IntSize(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 static ScriptPromise fulfillImageBitmap(ExecutionContext* context, PassRefPtrWil lBeRawPtr<ImageBitmap> imageBitmap) | 66 ScriptPromise fulfillImageBitmap(ExecutionContext* context, PassRefPtrWillBeRawP tr<ImageBitmap> imageBitmap) |
|
Stephen White
2014/03/25 16:56:31
Is there a reason this needs to be non-static?
| |
| 67 { | 67 { |
| 68 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(conte xt); | 68 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(conte xt); |
| 69 ScriptPromise promise = resolver->promise(); | 69 ScriptPromise promise = resolver->promise(); |
| 70 resolver->resolve(imageBitmap); | 70 if (imageBitmap) { |
| 71 resolver->resolve(imageBitmap); | |
| 72 } else { | |
| 73 v8::Isolate* isolate = ScriptState::current()->isolate(); | |
| 74 resolver->reject(ScriptValue(v8::Null(isolate), isolate)); | |
| 75 } | |
| 71 return promise; | 76 return promise; |
| 72 } | 77 } |
| 73 | 78 |
| 74 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget& eventTarget, HTMLImageElement* image, ExceptionState& exceptionState) | 79 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget& eventTarget, HTMLImageElement* image, ExceptionState& exceptionState) |
| 75 { | 80 { |
| 76 LayoutSize s = sizeFor(image); | 81 LayoutSize s = sizeFor(image); |
| 77 return createImageBitmap(eventTarget, image, 0, 0, s.width(), s.height(), ex ceptionState); | 82 return createImageBitmap(eventTarget, image, 0, 0, s.width(), s.height(), ex ceptionState); |
| 78 } | 83 } |
| 79 | 84 |
| 80 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget& eventTarget, HTMLImageElement* image, int sx, int sy, int sw, int sh, ExceptionState& excepti onState) | 85 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget& eventTarget, HTMLImageElement* image, int sx, int sy, int sw, int sh, ExceptionState& excepti onState) |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 return ScriptPromise(); | 183 return ScriptPromise(); |
| 179 } | 184 } |
| 180 if (!canvas->originClean()) { | 185 if (!canvas->originClean()) { |
| 181 exceptionState.throwSecurityError("The canvas element provided is tainte d with cross-origin data."); | 186 exceptionState.throwSecurityError("The canvas element provided is tainte d with cross-origin data."); |
| 182 return ScriptPromise(); | 187 return ScriptPromise(); |
| 183 } | 188 } |
| 184 if (!sw || !sh) { | 189 if (!sw || !sh) { |
| 185 exceptionState.throwDOMException(IndexSizeError, String::format("The sou rce %s provided is 0.", sw ? "height" : "width")); | 190 exceptionState.throwDOMException(IndexSizeError, String::format("The sou rce %s provided is 0.", sw ? "height" : "width")); |
| 186 return ScriptPromise(); | 191 return ScriptPromise(); |
| 187 } | 192 } |
| 193 | |
| 188 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 | 194 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 |
| 189 return fulfillImageBitmap(eventTarget.executionContext(), ImageBitmap::creat e(canvas, IntRect(sx, sy, sw, sh))); | 195 return fulfillImageBitmap(eventTarget.executionContext(), canvas->buffer() ? ImageBitmap::create(canvas, IntRect(sx, sy, sw, sh)) : nullptr); |
| 190 } | 196 } |
| 191 | 197 |
| 192 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget& eventTarget, Blob* blob, ExceptionState& exceptionState) | 198 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget& eventTarget, Blob* blob, ExceptionState& exceptionState) |
| 193 { | 199 { |
| 194 if (!blob) { | 200 if (!blob) { |
| 195 exceptionState.throwTypeError("The blob provided is invalid."); | 201 exceptionState.throwTypeError("The blob provided is invalid."); |
| 196 return ScriptPromise(); | 202 return ScriptPromise(); |
| 197 } | 203 } |
| 198 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(event Target.executionContext()); | 204 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(event Target.executionContext()); |
| 199 ScriptPromise promise = resolver->promise(); | 205 ScriptPromise promise = resolver->promise(); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 361 WillBeHeapSupplement<WorkerGlobalScope>::provideTo(object, ImageBitmapFa ctories::supplementName(), adoptPtrWillBeNoop(supplement)); | 367 WillBeHeapSupplement<WorkerGlobalScope>::provideTo(object, ImageBitmapFa ctories::supplementName(), adoptPtrWillBeNoop(supplement)); |
| 362 } | 368 } |
| 363 return *supplement; | 369 return *supplement; |
| 364 } | 370 } |
| 365 | 371 |
| 366 void WorkerGlobalScopeImageBitmapFactories::trace(Visitor*) | 372 void WorkerGlobalScopeImageBitmapFactories::trace(Visitor*) |
| 367 { | 373 { |
| 368 } | 374 } |
| 369 | 375 |
| 370 } // namespace WebCore | 376 } // namespace WebCore |
| OLD | NEW |