Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: Source/modules/imagebitmap/ImageBitmapFactories.cpp

Issue 42883002: Ship DOM/Promises (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@websocket-inspector-ipc
Patch Set: rebase Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/dom/Promise.idl ('k') | Source/platform/RuntimeEnabledFeatures.in » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 "RuntimeEnabledFeatures.h"
35 #include "V8ImageBitmap.h" 34 #include "V8ImageBitmap.h"
36 #include "bindings/v8/ExceptionMessages.h" 35 #include "bindings/v8/ExceptionMessages.h"
37 #include "bindings/v8/ExceptionState.h" 36 #include "bindings/v8/ExceptionState.h"
38 #include "bindings/v8/ScriptScope.h" 37 #include "bindings/v8/ScriptScope.h"
39 #include "bindings/v8/ScriptState.h" 38 #include "bindings/v8/ScriptState.h"
40 #include "core/fileapi/Blob.h" 39 #include "core/fileapi/Blob.h"
41 #include "core/html/HTMLCanvasElement.h" 40 #include "core/html/HTMLCanvasElement.h"
42 #include "core/html/HTMLImageElement.h" 41 #include "core/html/HTMLImageElement.h"
43 #include "core/html/HTMLVideoElement.h" 42 #include "core/html/HTMLVideoElement.h"
44 #include "core/html/ImageData.h" 43 #include "core/html/ImageData.h"
(...skipping 17 matching lines...) Expand all
62 61
63 static IntSize sizeFor(HTMLVideoElement* video) 62 static IntSize sizeFor(HTMLVideoElement* video)
64 { 63 {
65 if (MediaPlayer* player = video->player()) 64 if (MediaPlayer* player = video->player())
66 return player->naturalSize(); 65 return player->naturalSize();
67 return IntSize(); 66 return IntSize();
68 } 67 }
69 68
70 static ScriptPromise fulfillImageBitmap(ExecutionContext* context, PassRefPtr<Im ageBitmap> imageBitmap) 69 static ScriptPromise fulfillImageBitmap(ExecutionContext* context, PassRefPtr<Im ageBitmap> imageBitmap)
71 { 70 {
72 // Promises must be enabled.
73 ASSERT(RuntimeEnabledFeatures::promiseEnabled());
74 ScriptPromise promise = ScriptPromise::createPending(context); 71 ScriptPromise promise = ScriptPromise::createPending(context);
75 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promi se, context); 72 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promi se, context);
76 resolver->resolve(imageBitmap); 73 resolver->resolve(imageBitmap);
77 return promise; 74 return promise;
78 } 75 }
79 76
80 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, HTMLImageElement* image, ExceptionState& es) 77 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, HTMLImageElement* image, ExceptionState& es)
81 { 78 {
82 LayoutSize s = sizeFor(image); 79 LayoutSize s = sizeFor(image);
83 return createImageBitmap(eventTarget, image, 0, 0, s.width(), s.height(), es ); 80 return createImageBitmap(eventTarget, image, 0, 0, s.width(), s.height(), es );
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 if (!sw || !sh) { 188 if (!sw || !sh) {
192 es.throwUninformativeAndGenericDOMException(IndexSizeError); 189 es.throwUninformativeAndGenericDOMException(IndexSizeError);
193 return ScriptPromise(); 190 return ScriptPromise();
194 } 191 }
195 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 192 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082
196 return fulfillImageBitmap(eventTarget->executionContext(), ImageBitmap::crea te(canvas, IntRect(sx, sy, sw, sh))); 193 return fulfillImageBitmap(eventTarget->executionContext(), ImageBitmap::crea te(canvas, IntRect(sx, sy, sw, sh)));
197 } 194 }
198 195
199 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, Blob* blob, ExceptionState& es) 196 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, Blob* blob, ExceptionState& es)
200 { 197 {
201 // Promises must be enabled.
202 ASSERT(RuntimeEnabledFeatures::promiseEnabled());
203
204 if (!blob) { 198 if (!blob) {
205 es.throwUninformativeAndGenericDOMException(TypeError); 199 es.throwUninformativeAndGenericDOMException(TypeError);
206 return ScriptPromise(); 200 return ScriptPromise();
207 } 201 }
208 ScriptPromise promise = ScriptPromise::createPending(eventTarget->executionC ontext()); 202 ScriptPromise promise = ScriptPromise::createPending(eventTarget->executionC ontext());
209 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promi se, eventTarget->executionContext()); 203 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promi se, eventTarget->executionContext());
210 RefPtr<ImageBitmapLoader> loader = ImageBitmapFactories::ImageBitmapLoader:: create(from(eventTarget), resolver, IntRect()); 204 RefPtr<ImageBitmapLoader> loader = ImageBitmapFactories::ImageBitmapLoader:: create(from(eventTarget), resolver, IntRect());
211 from(eventTarget)->addLoader(loader); 205 from(eventTarget)->addLoader(loader);
212 loader->loadBlobAsync(eventTarget->executionContext(), blob); 206 loader->loadBlobAsync(eventTarget->executionContext(), blob);
213 return promise; 207 return promise;
214 } 208 }
215 209
216 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, Blob* blob, int sx, int sy, int sw, int sh, ExceptionState& es) 210 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, Blob* blob, int sx, int sy, int sw, int sh, ExceptionState& es)
217 { 211 {
218 // Promises must be enabled.
219 ASSERT(RuntimeEnabledFeatures::promiseEnabled());
220
221 if (!blob) { 212 if (!blob) {
222 es.throwUninformativeAndGenericDOMException(TypeError); 213 es.throwUninformativeAndGenericDOMException(TypeError);
223 return ScriptPromise(); 214 return ScriptPromise();
224 } 215 }
225 if (!sw || !sh) { 216 if (!sw || !sh) {
226 es.throwUninformativeAndGenericDOMException(IndexSizeError); 217 es.throwUninformativeAndGenericDOMException(IndexSizeError);
227 return ScriptPromise(); 218 return ScriptPromise();
228 } 219 }
229 ScriptPromise promise = ScriptPromise::createPending(eventTarget->executionC ontext()); 220 ScriptPromise promise = ScriptPromise::createPending(eventTarget->executionC ontext());
230 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promi se, eventTarget->executionContext()); 221 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promi se, eventTarget->executionContext());
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 m_resolver->resolve(imageBitmap.release()); 352 m_resolver->resolve(imageBitmap.release());
362 m_factory->didFinishLoading(this); 353 m_factory->didFinishLoading(this);
363 } 354 }
364 355
365 void ImageBitmapFactories::ImageBitmapLoader::didFail(FileError::ErrorCode) 356 void ImageBitmapFactories::ImageBitmapLoader::didFail(FileError::ErrorCode)
366 { 357 {
367 rejectPromise(); 358 rejectPromise();
368 } 359 }
369 360
370 } // namespace WebCore 361 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/Promise.idl ('k') | Source/platform/RuntimeEnabledFeatures.in » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698