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

Side by Side Diff: third_party/WebKit/Source/core/imagebitmap/ImageBitmapFactories.cpp

Issue 1455763002: Use union type in ImageBitmapFactories.idl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: better argument passing Created 5 years 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
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 14 matching lines...) Expand all
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 "core/imagebitmap/ImageBitmapFactories.h" 32 #include "core/imagebitmap/ImageBitmapFactories.h"
33 33
34 #include "bindings/core/v8/ExceptionState.h" 34 #include "bindings/core/v8/ExceptionState.h"
35 #include "bindings/core/v8/ScriptPromiseResolver.h"
36 #include "core/dom/ExecutionContext.h" 35 #include "core/dom/ExecutionContext.h"
37 #include "core/fileapi/Blob.h" 36 #include "core/fileapi/Blob.h"
38 #include "core/frame/ImageBitmap.h" 37 #include "core/frame/ImageBitmap.h"
39 #include "core/frame/LocalDOMWindow.h" 38 #include "core/frame/LocalDOMWindow.h"
39 #include "core/html/HTMLCanvasElement.h"
40 #include "core/html/HTMLImageElement.h"
41 #include "core/html/HTMLVideoElement.h"
40 #include "core/html/ImageData.h" 42 #include "core/html/ImageData.h"
41 #include "core/workers/WorkerGlobalScope.h" 43 #include "core/workers/WorkerGlobalScope.h"
42 #include "platform/SharedBuffer.h" 44 #include "platform/SharedBuffer.h"
43 #include "platform/graphics/ImageSource.h" 45 #include "platform/graphics/ImageSource.h"
44 #include "platform/graphics/StaticBitmapImage.h"
45 #include "public/platform/WebSize.h"
46 #include "third_party/skia/include/core/SkImage.h"
47 #include <v8.h> 46 #include <v8.h>
48 47
49 namespace blink { 48 namespace blink {
50 49
51 static ScriptPromise fulfillImageBitmap(ScriptState* scriptState, PassRefPtrWill BeRawPtr<ImageBitmap> imageBitmap) 50 static inline ImageBitmapSource* toImageBitmapSourceInternal(const ImageBitmapSo urceUnion& value)
52 { 51 {
53 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 52 if (value.isHTMLImageElement())
54 ScriptPromise promise = resolver->promise(); 53 return value.getAsHTMLImageElement().get();
55 if (imageBitmap) { 54 if (value.isHTMLVideoElement())
56 resolver->resolve(imageBitmap); 55 return value.getAsHTMLVideoElement().get();
57 } else { 56 if (value.isHTMLCanvasElement())
58 resolver->reject(ScriptValue(scriptState, v8::Null(scriptState->isolate( )))); 57 return value.getAsHTMLCanvasElement().get();
59 } 58 if (value.isBlob())
60 return promise; 59 return value.getAsBlob();
60 if (value.isImageData())
61 return value.getAsImageData();
62 if (value.isImageBitmap())
63 return value.getAsImageBitmap().get();
64 ASSERT_NOT_REACHED();
65 return nullptr;
61 } 66 }
62 67
63 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, Blob* blob, ExceptionState& exceptionState) 68 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, const ImageBitmapSourceUnion& bitmapSource, ExceptionS tate& exceptionState)
64 { 69 {
65 ImageBitmapLoader* loader = ImageBitmapFactories::ImageBitmapLoader::create( from(eventTarget), IntRect(), scriptState); 70 ImageBitmapSource* bitmapSourceInternal = toImageBitmapSourceInternal(bitmap Source);
66 ScriptPromise promise = loader->promise(); 71 if (bitmapSourceInternal->isBlob()) {
67 from(eventTarget).addLoader(loader); 72 Blob* blob = static_cast<Blob*>(bitmapSourceInternal);
68 loader->loadBlobAsync(eventTarget.executionContext(), blob); 73 ImageBitmapLoader* loader = ImageBitmapFactories::ImageBitmapLoader::cre ate(from(eventTarget), IntRect(), scriptState);
69 return promise; 74 ScriptPromise promise = loader->promise();
75 from(eventTarget).addLoader(loader);
76 loader->loadBlobAsync(eventTarget.executionContext(), blob);
77 return promise;
78 }
79 IntSize srcSize = bitmapSourceInternal->bitmapSourceSize();
80 return createImageBitmap(scriptState, eventTarget, bitmapSourceInternal, 0, 0, srcSize.width(), srcSize.height(), exceptionState);
70 } 81 }
71 82
72 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, Blob* blob, int sx, int sy, int sw, int sh, ExceptionS tate& exceptionState) 83 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, const ImageBitmapSourceUnion& bitmapSource, int sx, in t sy, int sw, int sh, ExceptionState& exceptionState)
73 { 84 {
74 if (!sw || !sh) { 85 ImageBitmapSource* bitmapSourceInternal = toImageBitmapSourceInternal(bitmap Source);
75 exceptionState.throwDOMException(IndexSizeError, String::format("The sou rce %s provided is 0.", sw ? "height" : "width")); 86 return createImageBitmap(scriptState, eventTarget, bitmapSourceInternal, sx, sy, sw, sh, exceptionState);
76 return ScriptPromise();
77 }
78 ImageBitmapLoader* loader = ImageBitmapFactories::ImageBitmapLoader::create( from(eventTarget), IntRect(sx, sy, sw, sh), scriptState);
79 ScriptPromise promise = loader->promise();
80 from(eventTarget).addLoader(loader);
81 loader->loadBlobAsync(eventTarget.executionContext(), blob);
82 return promise;
83 } 87 }
84 88
85 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, ImageData* data, ExceptionState& exceptionState) 89 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, ImageBitmapSource* bitmapSource, int sx, int sy, int s w, int sh, ExceptionState& exceptionState)
86 { 90 {
87 return createImageBitmap(scriptState, eventTarget, data, 0, 0, data->width() , data->height(), exceptionState); 91 if (bitmapSource->isBlob()) {
88 } 92 if (!sw || !sh) {
93 exceptionState.throwDOMException(IndexSizeError, String::format("The source %s provided is 0.", sw ? "height" : "width"));
94 return ScriptPromise();
95 }
96 Blob* blob = static_cast<Blob*>(bitmapSource);
97 ImageBitmapLoader* loader = ImageBitmapFactories::ImageBitmapLoader::cre ate(from(eventTarget), IntRect(sx, sy, sw, sh), scriptState);
98 ScriptPromise promise = loader->promise();
99 from(eventTarget).addLoader(loader);
100 loader->loadBlobAsync(eventTarget.executionContext(), blob);
101 return promise;
102 }
89 103
90 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, ImageData* data, int sx, int sy, int sw, int sh, Excep tionState& exceptionState) 104 return bitmapSource->createImageBitmap(scriptState, eventTarget, sx, sy, sw, sh, exceptionState);
91 {
92 if (!sw || !sh) {
93 exceptionState.throwDOMException(IndexSizeError, String::format("The sou rce %s provided is 0.", sw ? "height" : "width"));
94 return ScriptPromise();
95 }
96 if (data->data()->bufferBase()->isNeutered()) {
97 exceptionState.throwDOMException(InvalidStateError, "The source data has been neutered.");
98 return ScriptPromise();
99 }
100 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082
101 return fulfillImageBitmap(scriptState, ImageBitmap::create(data, IntRect(sx, sy, sw, sh)));
102 }
103
104 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, ImageBitmap* bitmap, ExceptionState& exceptionState)
105 {
106 return createImageBitmap(scriptState, eventTarget, bitmap, 0, 0, bitmap->wid th(), bitmap->height(), exceptionState);
107 }
108
109 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, ImageBitmap* bitmap, int sx, int sy, int sw, int sh, E xceptionState& exceptionState)
110 {
111 if (!sw || !sh) {
112 exceptionState.throwDOMException(IndexSizeError, String::format("The sou rce %s provided is 0.", sw ? "height" : "width"));
113 return ScriptPromise();
114 }
115 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082
116 return fulfillImageBitmap(scriptState, ImageBitmap::create(bitmap, IntRect(s x, sy, sw, sh)));
117 } 105 }
118 106
119 const char* ImageBitmapFactories::supplementName() 107 const char* ImageBitmapFactories::supplementName()
120 { 108 {
121 return "ImageBitmapFactories"; 109 return "ImageBitmapFactories";
122 } 110 }
123 111
124 ImageBitmapFactories& ImageBitmapFactories::from(EventTarget& eventTarget) 112 ImageBitmapFactories& ImageBitmapFactories::from(EventTarget& eventTarget)
125 { 113 {
126 if (LocalDOMWindow* window = eventTarget.toDOMWindow()) 114 if (LocalDOMWindow* window = eventTarget.toDOMWindow())
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 rejectPromise(); 200 rejectPromise();
213 } 201 }
214 202
215 DEFINE_TRACE(ImageBitmapFactories::ImageBitmapLoader) 203 DEFINE_TRACE(ImageBitmapFactories::ImageBitmapLoader)
216 { 204 {
217 visitor->trace(m_factory); 205 visitor->trace(m_factory);
218 visitor->trace(m_resolver); 206 visitor->trace(m_resolver);
219 } 207 }
220 208
221 } // namespace blink 209 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698