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 11 matching lines...) Expand all Loading... | |
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" |
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 { | |
49 | |
50 static LayoutSize sizeFor(HTMLImageElement* image) | 48 static LayoutSize sizeFor(HTMLImageElement* image) |
51 { | 49 { |
52 if (ImageResource* cachedImage = image->cachedImage()) | 50 if (ImageResource* cachedImage = image->cachedImage()) |
53 return cachedImage->imageSizeForRenderer(image->renderer(), 1.0f); // FI XME: Not sure about this. | 51 return cachedImage->imageSizeForRenderer(image->renderer(), 1.0f); // FI XME: Not sure about this. |
54 return IntSize(); | 52 return IntSize(); |
55 } | 53 } |
56 | 54 |
57 static IntSize sizeFor(HTMLVideoElement* video) | 55 static IntSize sizeFor(HTMLVideoElement* video) |
58 { | 56 { |
59 if (MediaPlayer* player = video->player()) | 57 if (MediaPlayer* player = video->player()) |
60 return player->naturalSize(); | 58 return player->naturalSize(); |
61 return IntSize(); | 59 return IntSize(); |
62 } | 60 } |
63 | 61 |
64 static ScriptObject resolveImageBitmap(PassRefPtr<ImageBitmap> imageBitmap) | 62 static ScriptObject resolveImageBitmap(PassRefPtr<ImageBitmap> imageBitmap) |
65 { | 63 { |
66 // Promises must be enabled. | 64 // Promises must be enabled. |
67 ASSERT(RuntimeEnabledFeatures::promiseEnabled()); | 65 ASSERT(RuntimeEnabledFeatures::promiseEnabled()); |
68 | 66 |
69 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(); | 67 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(); |
70 resolver->fulfill(imageBitmap); | 68 resolver->fulfill(imageBitmap); |
71 return resolver->promise(); | 69 return resolver->promise(); |
72 } | 70 } |
73 | 71 |
74 ScriptObject createImageBitmap(EventTarget* eventTarget, HTMLImageElement* image , ExceptionState& es) | 72 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, H TMLImageElement* image, ExceptionState& es) |
75 { | 73 { |
76 LayoutSize s = sizeFor(image); | 74 LayoutSize s = sizeFor(image); |
77 return createImageBitmap(eventTarget, image, 0, 0, s.width(), s.height(), es ); | 75 return createImageBitmap(eventTarget, image, 0, 0, s.width(), s.height(), es ); |
78 } | 76 } |
79 | 77 |
80 ScriptObject createImageBitmap(EventTarget* eventTarget, HTMLImageElement* image , int sx, int sy, int sw, int sh, ExceptionState& es) | 78 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, H TMLImageElement* image, int sx, int sy, int sw, int sh, ExceptionState& es) |
81 { | 79 { |
82 if (!image) { | 80 if (!image) { |
83 es.throwTypeError(); | 81 es.throwTypeError(); |
84 return ScriptObject(); | 82 return ScriptObject(); |
85 } | 83 } |
86 if (!image->cachedImage()) { | 84 if (!image->cachedImage()) { |
87 es.throwDOMException(InvalidStateError); | 85 es.throwDOMException(InvalidStateError); |
88 return ScriptObject(); | 86 return ScriptObject(); |
89 } | 87 } |
90 if (image->cachedImage()->image()->isSVGImage()) { | 88 if (image->cachedImage()->image()->isSVGImage()) { |
(...skipping 10 matching lines...) Expand all Loading... | |
101 } | 99 } |
102 if (!image->cachedImage()->passesAccessControlCheck(eventTarget->toDOMWindow ()->document()->securityOrigin()) | 100 if (!image->cachedImage()->passesAccessControlCheck(eventTarget->toDOMWindow ()->document()->securityOrigin()) |
103 && eventTarget->toDOMWindow()->document()->securityOrigin()->taintsCanvas(im age->src())) { | 101 && eventTarget->toDOMWindow()->document()->securityOrigin()->taintsCanvas(im age->src())) { |
104 es.throwDOMException(SecurityError); | 102 es.throwDOMException(SecurityError); |
105 return ScriptObject(); | 103 return ScriptObject(); |
106 } | 104 } |
107 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 | 105 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 |
108 return resolveImageBitmap(ImageBitmap::create(image, IntRect(sx, sy, sw, sh) )); | 106 return resolveImageBitmap(ImageBitmap::create(image, IntRect(sx, sy, sw, sh) )); |
109 } | 107 } |
110 | 108 |
111 ScriptObject createImageBitmap(EventTarget* eventTarget, HTMLVideoElement* video , ExceptionState& es) | 109 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, H TMLVideoElement* video, ExceptionState& es) |
112 { | 110 { |
113 IntSize s = sizeFor(video); | 111 IntSize s = sizeFor(video); |
114 return createImageBitmap(eventTarget, video, 0, 0, s.width(), s.height(), es ); | 112 return createImageBitmap(eventTarget, video, 0, 0, s.width(), s.height(), es ); |
115 } | 113 } |
116 | 114 |
117 ScriptObject createImageBitmap(EventTarget* eventTarget, HTMLVideoElement* video , int sx, int sy, int sw, int sh, ExceptionState& es) | 115 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, H TMLVideoElement* video, int sx, int sy, int sw, int sh, ExceptionState& es) |
118 { | 116 { |
119 if (!video) { | 117 if (!video) { |
120 es.throwTypeError(); | 118 es.throwTypeError(); |
121 return ScriptObject(); | 119 return ScriptObject(); |
122 } | 120 } |
123 if (!video->player()) { | 121 if (!video->player()) { |
124 es.throwDOMException(InvalidStateError); | 122 es.throwDOMException(InvalidStateError); |
125 return ScriptObject(); | 123 return ScriptObject(); |
126 } | 124 } |
127 if (video->networkState() == HTMLMediaElement::NETWORK_EMPTY) { | 125 if (video->networkState() == HTMLMediaElement::NETWORK_EMPTY) { |
(...skipping 13 matching lines...) Expand all Loading... | |
141 return ScriptObject(); | 139 return ScriptObject(); |
142 } | 140 } |
143 if (!video->player()->didPassCORSAccessCheck() && eventTarget->toDOMWindow() ->document()->securityOrigin()->taintsCanvas(video->currentSrc())) { | 141 if (!video->player()->didPassCORSAccessCheck() && eventTarget->toDOMWindow() ->document()->securityOrigin()->taintsCanvas(video->currentSrc())) { |
144 es.throwDOMException(SecurityError); | 142 es.throwDOMException(SecurityError); |
145 return ScriptObject(); | 143 return ScriptObject(); |
146 } | 144 } |
147 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 | 145 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 |
148 return resolveImageBitmap(ImageBitmap::create(video, IntRect(sx, sy, sw, sh) )); | 146 return resolveImageBitmap(ImageBitmap::create(video, IntRect(sx, sy, sw, sh) )); |
149 } | 147 } |
150 | 148 |
151 ScriptObject createImageBitmap(EventTarget* eventTarget, CanvasRenderingContext2 D* context, ExceptionState& es) | 149 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, C anvasRenderingContext2D* context, ExceptionState& es) |
152 { | 150 { |
153 return createImageBitmap(eventTarget, context->canvas(), es); | 151 return createImageBitmap(eventTarget, context->canvas(), es); |
154 } | 152 } |
155 | 153 |
156 ScriptObject createImageBitmap(EventTarget* eventTarget, CanvasRenderingContext2 D* context, int sx, int sy, int sw, int sh, ExceptionState& es) | 154 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, C anvasRenderingContext2D* context, int sx, int sy, int sw, int sh, ExceptionState & es) |
157 { | 155 { |
158 return createImageBitmap(eventTarget, context->canvas(), sx, sy, sw, sh, es) ; | 156 return createImageBitmap(eventTarget, context->canvas(), sx, sy, sw, sh, es) ; |
159 } | 157 } |
160 | 158 |
161 ScriptObject createImageBitmap(EventTarget* eventTarget, HTMLCanvasElement* canv as, ExceptionState& es) | 159 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, H TMLCanvasElement* canvas, ExceptionState& es) |
162 { | 160 { |
163 return createImageBitmap(eventTarget, canvas, 0, 0, canvas->width(), canvas- >height(), es); | 161 return createImageBitmap(eventTarget, canvas, 0, 0, canvas->width(), canvas- >height(), es); |
164 } | 162 } |
165 | 163 |
166 ScriptObject createImageBitmap(EventTarget* eventTarget, HTMLCanvasElement* canv as, int sx, int sy, int sw, int sh, ExceptionState& es) | 164 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, H TMLCanvasElement* canvas, int sx, int sy, int sw, int sh, ExceptionState& es) |
167 { | 165 { |
168 if (!canvas) { | 166 if (!canvas) { |
169 es.throwTypeError(); | 167 es.throwTypeError(); |
170 return ScriptObject(); | 168 return ScriptObject(); |
171 } | 169 } |
172 if (!canvas->originClean()) { | 170 if (!canvas->originClean()) { |
173 es.throwDOMException(InvalidStateError); | 171 es.throwDOMException(InvalidStateError); |
174 return ScriptObject(); | 172 return ScriptObject(); |
175 } | 173 } |
176 if (!sw || !sh) { | 174 if (!sw || !sh) { |
177 es.throwDOMException(IndexSizeError); | 175 es.throwDOMException(IndexSizeError); |
178 return ScriptObject(); | 176 return ScriptObject(); |
179 } | 177 } |
180 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 | 178 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 |
181 return resolveImageBitmap(ImageBitmap::create(canvas, IntRect(sx, sy, sw, sh ))); | 179 return resolveImageBitmap(ImageBitmap::create(canvas, IntRect(sx, sy, sw, sh ))); |
182 } | 180 } |
183 | 181 |
184 ScriptObject createImageBitmap(EventTarget* eventTarget, ImageData* data, Except ionState& es) | 182 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, I mageData* data, ExceptionState& es) |
185 { | 183 { |
186 return createImageBitmap(eventTarget, data, 0, 0, data->width(), data->heigh t(), es); | 184 return createImageBitmap(eventTarget, data, 0, 0, data->width(), data->heigh t(), es); |
187 } | 185 } |
188 | 186 |
189 ScriptObject createImageBitmap(EventTarget* eventTarget, ImageData* data, int sx , int sy, int sw, int sh, ExceptionState& es) | 187 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, I mageData* data, int sx, int sy, int sw, int sh, ExceptionState& es) |
190 { | 188 { |
191 if (!data) { | 189 if (!data) { |
192 es.throwTypeError(); | 190 es.throwTypeError(); |
193 return ScriptObject(); | 191 return ScriptObject(); |
194 } | 192 } |
195 if (!sw || !sh) { | 193 if (!sw || !sh) { |
196 es.throwDOMException(IndexSizeError); | 194 es.throwDOMException(IndexSizeError); |
197 return ScriptObject(); | 195 return ScriptObject(); |
198 } | 196 } |
199 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 | 197 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 |
200 return resolveImageBitmap(ImageBitmap::create(data, IntRect(sx, sy, sw, sh)) ); | 198 return resolveImageBitmap(ImageBitmap::create(data, IntRect(sx, sy, sw, sh)) ); |
201 } | 199 } |
202 | 200 |
203 ScriptObject createImageBitmap(EventTarget* eventTarget, ImageBitmap* bitmap, Ex ceptionState& es) | 201 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, I mageBitmap* bitmap, ExceptionState& es) |
204 { | 202 { |
205 return createImageBitmap(eventTarget, bitmap, 0, 0, bitmap->width(), bitmap- >height(), es); | 203 return createImageBitmap(eventTarget, bitmap, 0, 0, bitmap->width(), bitmap- >height(), es); |
206 } | 204 } |
207 | 205 |
208 ScriptObject createImageBitmap(EventTarget* eventTarget, ImageBitmap* bitmap, in t sx, int sy, int sw, int sh, ExceptionState& es) | 206 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, I mageBitmap* bitmap, int sx, int sy, int sw, int sh, ExceptionState& es) |
209 { | 207 { |
210 if (!bitmap) { | 208 if (!bitmap) { |
211 es.throwTypeError(); | 209 es.throwTypeError(); |
212 return ScriptObject(); | 210 return ScriptObject(); |
213 } | 211 } |
214 if (!sw || !sh) { | 212 if (!sw || !sh) { |
215 es.throwDOMException(IndexSizeError); | 213 es.throwDOMException(IndexSizeError); |
216 return ScriptObject(); | 214 return ScriptObject(); |
217 } | 215 } |
218 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 | 216 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 |
219 return resolveImageBitmap(ImageBitmap::create(bitmap, IntRect(sx, sy, sw, sh ))); | 217 return resolveImageBitmap(ImageBitmap::create(bitmap, IntRect(sx, sy, sw, sh ))); |
220 } | 218 } |
221 | 219 |
222 } // namespace ImageBitmapFactories | 220 const char* ImageBitmapFactories::supplementName() |
221 { | |
222 return "ImageBitmapFactories"; | |
223 } | |
224 | |
225 ImageBitmapFactories* ImageBitmapFactories::from(DOMWindow* window) | |
abarth-chromium
2013/08/12 20:35:59
I don't see any callers of this function. You sho
| |
226 { | |
227 ImageBitmapFactories* supplement = static_cast<ImageBitmapFactories*>(Supple ment<DOMWindow>::from(window, supplementName())); | |
228 if (!supplement) { | |
229 supplement = new ImageBitmapFactories(); | |
230 provideTo(window, supplementName(), adoptPtr(supplement)); | |
231 } | |
232 return supplement; | |
233 } | |
234 | |
223 } // namespace WebCore | 235 } // namespace WebCore |
OLD | NEW |