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

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

Issue 22906002: Implement ImageBitmapFactories as a supplementary module. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Keep IDL implements statement. Created 7 years, 4 months 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 | Annotate | Revision Log
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 11 matching lines...) Expand all
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
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 "core/page/ImageBitmapFactories.h" 32 #include "modules/imagebitmap/ImageBitmapFactories.h"
do-not-use 2013/08/12 18:43:59 Someone needs to comment about the move to modules
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 "core/dom/ExceptionCode.h"
38 #include "core/html/HTMLCanvasElement.h" 38 #include "core/html/HTMLCanvasElement.h"
39 #include "core/html/HTMLImageElement.h" 39 #include "core/html/HTMLImageElement.h"
40 #include "core/html/HTMLVideoElement.h" 40 #include "core/html/HTMLVideoElement.h"
41 #include "core/html/ImageData.h" 41 #include "core/html/ImageData.h"
42 #include "core/html/canvas/CanvasRenderingContext2D.h" 42 #include "core/html/canvas/CanvasRenderingContext2D.h"
43 #include "core/page/DOMWindow.h" 43 #include "core/page/DOMWindow.h"
44 #include "core/page/ImageBitmap.h" 44 #include "core/page/ImageBitmap.h"
45 45
46 namespace WebCore { 46 namespace WebCore {
47 47
48 namespace ImageBitmapFactories { 48 ImageBitmapFactories::ImageBitmapFactories(DOMWindow* window)
do-not-use 2013/08/12 18:43:59 If we stop subclassing DOMWindowProperty then we n
49 : DOMWindowProperty(window->frame())
50 {
51 }
49 52
50 static LayoutSize sizeFor(HTMLImageElement* image) 53 static LayoutSize sizeFor(HTMLImageElement* image)
51 { 54 {
52 if (ImageResource* cachedImage = image->cachedImage()) 55 if (ImageResource* 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 resolveImageBitmap(PassRefPtr<ImageBitmap> imageBitmap)
65 { 68 {
66 // Promises must be enabled. 69 // Promises must be enabled.
67 ASSERT(RuntimeEnabledFeatures::promiseEnabled()); 70 ASSERT(RuntimeEnabledFeatures::promiseEnabled());
68 71
69 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(); 72 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create();
70 resolver->fulfill(imageBitmap); 73 resolver->fulfill(imageBitmap);
71 return resolver->promise(); 74 return resolver->promise();
72 } 75 }
73 76
74 ScriptObject createImageBitmap(EventTarget* eventTarget, HTMLImageElement* image , ExceptionState& es) 77 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, H TMLImageElement* image, ExceptionState& es)
75 { 78 {
76 LayoutSize s = sizeFor(image); 79 LayoutSize s = sizeFor(image);
77 return createImageBitmap(eventTarget, image, 0, 0, s.width(), s.height(), es ); 80 return createImageBitmap(eventTarget, image, 0, 0, s.width(), s.height(), es );
78 } 81 }
79 82
80 ScriptObject createImageBitmap(EventTarget* eventTarget, HTMLImageElement* image , int sx, int sy, int sw, int sh, ExceptionState& es) 83 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, H TMLImageElement* image, int sx, int sy, int sw, int sh, ExceptionState& es)
81 { 84 {
82 if (!image) { 85 if (!image) {
83 es.throwTypeError(); 86 es.throwTypeError();
84 return ScriptObject(); 87 return ScriptObject();
85 } 88 }
86 if (!image->cachedImage()) { 89 if (!image->cachedImage()) {
87 es.throwDOMException(InvalidStateError); 90 es.throwDOMException(InvalidStateError);
88 return ScriptObject(); 91 return ScriptObject();
89 } 92 }
90 if (image->cachedImage()->image()->isSVGImage()) { 93 if (image->cachedImage()->image()->isSVGImage()) {
(...skipping 10 matching lines...) Expand all
101 } 104 }
102 if (!image->cachedImage()->passesAccessControlCheck(eventTarget->toDOMWindow ()->document()->securityOrigin()) 105 if (!image->cachedImage()->passesAccessControlCheck(eventTarget->toDOMWindow ()->document()->securityOrigin())
103 && eventTarget->toDOMWindow()->document()->securityOrigin()->taintsCanvas(im age->src())) { 106 && eventTarget->toDOMWindow()->document()->securityOrigin()->taintsCanvas(im age->src())) {
104 es.throwDOMException(SecurityError); 107 es.throwDOMException(SecurityError);
105 return ScriptObject(); 108 return ScriptObject();
106 } 109 }
107 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 110 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082
108 return resolveImageBitmap(ImageBitmap::create(image, IntRect(sx, sy, sw, sh) )); 111 return resolveImageBitmap(ImageBitmap::create(image, IntRect(sx, sy, sw, sh) ));
109 } 112 }
110 113
111 ScriptObject createImageBitmap(EventTarget* eventTarget, HTMLVideoElement* video , ExceptionState& es) 114 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, H TMLVideoElement* video, ExceptionState& es)
112 { 115 {
113 IntSize s = sizeFor(video); 116 IntSize s = sizeFor(video);
114 return createImageBitmap(eventTarget, video, 0, 0, s.width(), s.height(), es ); 117 return createImageBitmap(eventTarget, video, 0, 0, s.width(), s.height(), es );
115 } 118 }
116 119
117 ScriptObject createImageBitmap(EventTarget* eventTarget, HTMLVideoElement* video , int sx, int sy, int sw, int sh, ExceptionState& es) 120 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, H TMLVideoElement* video, int sx, int sy, int sw, int sh, ExceptionState& es)
118 { 121 {
119 if (!video) { 122 if (!video) {
120 es.throwTypeError(); 123 es.throwTypeError();
121 return ScriptObject(); 124 return ScriptObject();
122 } 125 }
123 if (!video->player()) { 126 if (!video->player()) {
124 es.throwDOMException(InvalidStateError); 127 es.throwDOMException(InvalidStateError);
125 return ScriptObject(); 128 return ScriptObject();
126 } 129 }
127 if (video->networkState() == HTMLMediaElement::NETWORK_EMPTY) { 130 if (video->networkState() == HTMLMediaElement::NETWORK_EMPTY) {
(...skipping 13 matching lines...) Expand all
141 return ScriptObject(); 144 return ScriptObject();
142 } 145 }
143 if (!video->player()->didPassCORSAccessCheck() && eventTarget->toDOMWindow() ->document()->securityOrigin()->taintsCanvas(video->currentSrc())) { 146 if (!video->player()->didPassCORSAccessCheck() && eventTarget->toDOMWindow() ->document()->securityOrigin()->taintsCanvas(video->currentSrc())) {
144 es.throwDOMException(SecurityError); 147 es.throwDOMException(SecurityError);
145 return ScriptObject(); 148 return ScriptObject();
146 } 149 }
147 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 150 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082
148 return resolveImageBitmap(ImageBitmap::create(video, IntRect(sx, sy, sw, sh) )); 151 return resolveImageBitmap(ImageBitmap::create(video, IntRect(sx, sy, sw, sh) ));
149 } 152 }
150 153
151 ScriptObject createImageBitmap(EventTarget* eventTarget, CanvasRenderingContext2 D* context, ExceptionState& es) 154 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, C anvasRenderingContext2D* context, ExceptionState& es)
152 { 155 {
153 return createImageBitmap(eventTarget, context->canvas(), es); 156 return createImageBitmap(eventTarget, context->canvas(), es);
154 } 157 }
155 158
156 ScriptObject createImageBitmap(EventTarget* eventTarget, CanvasRenderingContext2 D* context, int sx, int sy, int sw, int sh, ExceptionState& es) 159 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, C anvasRenderingContext2D* context, int sx, int sy, int sw, int sh, ExceptionState & es)
157 { 160 {
158 return createImageBitmap(eventTarget, context->canvas(), sx, sy, sw, sh, es) ; 161 return createImageBitmap(eventTarget, context->canvas(), sx, sy, sw, sh, es) ;
159 } 162 }
160 163
161 ScriptObject createImageBitmap(EventTarget* eventTarget, HTMLCanvasElement* canv as, ExceptionState& es) 164 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, H TMLCanvasElement* canvas, ExceptionState& es)
162 { 165 {
163 return createImageBitmap(eventTarget, canvas, 0, 0, canvas->width(), canvas- >height(), es); 166 return createImageBitmap(eventTarget, canvas, 0, 0, canvas->width(), canvas- >height(), es);
164 } 167 }
165 168
166 ScriptObject createImageBitmap(EventTarget* eventTarget, HTMLCanvasElement* canv as, int sx, int sy, int sw, int sh, ExceptionState& es) 169 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, H TMLCanvasElement* canvas, int sx, int sy, int sw, int sh, ExceptionState& es)
167 { 170 {
168 if (!canvas) { 171 if (!canvas) {
169 es.throwTypeError(); 172 es.throwTypeError();
170 return ScriptObject(); 173 return ScriptObject();
171 } 174 }
172 if (!canvas->originClean()) { 175 if (!canvas->originClean()) {
173 es.throwDOMException(InvalidStateError); 176 es.throwDOMException(InvalidStateError);
174 return ScriptObject(); 177 return ScriptObject();
175 } 178 }
176 if (!sw || !sh) { 179 if (!sw || !sh) {
177 es.throwDOMException(IndexSizeError); 180 es.throwDOMException(IndexSizeError);
178 return ScriptObject(); 181 return ScriptObject();
179 } 182 }
180 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 183 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082
181 return resolveImageBitmap(ImageBitmap::create(canvas, IntRect(sx, sy, sw, sh ))); 184 return resolveImageBitmap(ImageBitmap::create(canvas, IntRect(sx, sy, sw, sh )));
182 } 185 }
183 186
184 ScriptObject createImageBitmap(EventTarget* eventTarget, ImageData* data, Except ionState& es) 187 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, I mageData* data, ExceptionState& es)
185 { 188 {
186 return createImageBitmap(eventTarget, data, 0, 0, data->width(), data->heigh t(), es); 189 return createImageBitmap(eventTarget, data, 0, 0, data->width(), data->heigh t(), es);
187 } 190 }
188 191
189 ScriptObject createImageBitmap(EventTarget* eventTarget, ImageData* data, int sx , int sy, int sw, int sh, ExceptionState& es) 192 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, I mageData* data, int sx, int sy, int sw, int sh, ExceptionState& es)
190 { 193 {
191 if (!data) { 194 if (!data) {
192 es.throwTypeError(); 195 es.throwTypeError();
193 return ScriptObject(); 196 return ScriptObject();
194 } 197 }
195 if (!sw || !sh) { 198 if (!sw || !sh) {
196 es.throwDOMException(IndexSizeError); 199 es.throwDOMException(IndexSizeError);
197 return ScriptObject(); 200 return ScriptObject();
198 } 201 }
199 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 202 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082
200 return resolveImageBitmap(ImageBitmap::create(data, IntRect(sx, sy, sw, sh)) ); 203 return resolveImageBitmap(ImageBitmap::create(data, IntRect(sx, sy, sw, sh)) );
201 } 204 }
202 205
203 ScriptObject createImageBitmap(EventTarget* eventTarget, ImageBitmap* bitmap, Ex ceptionState& es) 206 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, I mageBitmap* bitmap, ExceptionState& es)
204 { 207 {
205 return createImageBitmap(eventTarget, bitmap, 0, 0, bitmap->width(), bitmap- >height(), es); 208 return createImageBitmap(eventTarget, bitmap, 0, 0, bitmap->width(), bitmap- >height(), es);
206 } 209 }
207 210
208 ScriptObject createImageBitmap(EventTarget* eventTarget, ImageBitmap* bitmap, in t sx, int sy, int sw, int sh, ExceptionState& es) 211 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, I mageBitmap* bitmap, int sx, int sy, int sw, int sh, ExceptionState& es)
209 { 212 {
210 if (!bitmap) { 213 if (!bitmap) {
211 es.throwTypeError(); 214 es.throwTypeError();
212 return ScriptObject(); 215 return ScriptObject();
213 } 216 }
214 if (!sw || !sh) { 217 if (!sw || !sh) {
215 es.throwDOMException(IndexSizeError); 218 es.throwDOMException(IndexSizeError);
216 return ScriptObject(); 219 return ScriptObject();
217 } 220 }
218 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 221 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082
219 return resolveImageBitmap(ImageBitmap::create(bitmap, IntRect(sx, sy, sw, sh ))); 222 return resolveImageBitmap(ImageBitmap::create(bitmap, IntRect(sx, sy, sw, sh )));
220 } 223 }
221 224
222 } // namespace ImageBitmapFactories 225 const char* ImageBitmapFactories::supplementName()
226 {
227 return "ImageBitmapFactories";
228 }
229
230 ImageBitmapFactories* ImageBitmapFactories::from(DOMWindow* window)
231 {
232 ImageBitmapFactories* supplement = static_cast<ImageBitmapFactories*>(Supple ment<DOMWindow>::from(window, supplementName()));
233 if (!supplement) {
234 supplement = new ImageBitmapFactories(window);
235 provideTo(window, supplementName(), adoptPtr(supplement));
236 }
237 return supplement;
238 }
239
223 } // namespace WebCore 240 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698