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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 return IntSize(); | 57 return IntSize(); |
58 } | 58 } |
59 | 59 |
60 static IntSize sizeFor(HTMLVideoElement* video) | 60 static IntSize sizeFor(HTMLVideoElement* video) |
61 { | 61 { |
62 if (MediaPlayer* player = video->player()) | 62 if (MediaPlayer* player = video->player()) |
63 return player->naturalSize(); | 63 return player->naturalSize(); |
64 return IntSize(); | 64 return IntSize(); |
65 } | 65 } |
66 | 66 |
67 static ScriptObject fulfillImageBitmap(ScriptExecutionContext* context, PassRefP
tr<ImageBitmap> imageBitmap) | 67 static ScriptPromise fulfillImageBitmap(ScriptExecutionContext* context, PassRef
Ptr<ImageBitmap> imageBitmap) |
68 { | 68 { |
69 // Promises must be enabled. | 69 // Promises must be enabled. |
70 ASSERT(RuntimeEnabledFeatures::promiseEnabled()); | 70 ASSERT(RuntimeEnabledFeatures::promiseEnabled()); |
71 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(conte
xt); | 71 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(conte
xt); |
72 resolver->fulfill(imageBitmap); | 72 resolver->fulfill(imageBitmap); |
73 return resolver->promise(); | 73 return resolver->promise(); |
74 } | 74 } |
75 | 75 |
76 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, H
TMLImageElement* image, ExceptionState& es) | 76 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget,
HTMLImageElement* image, ExceptionState& es) |
77 { | 77 { |
78 LayoutSize s = sizeFor(image); | 78 LayoutSize s = sizeFor(image); |
79 return createImageBitmap(eventTarget, image, 0, 0, s.width(), s.height(), es
); | 79 return createImageBitmap(eventTarget, image, 0, 0, s.width(), s.height(), es
); |
80 } | 80 } |
81 | 81 |
82 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, H
TMLImageElement* image, int sx, int sy, int sw, int sh, ExceptionState& es) | 82 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget,
HTMLImageElement* image, int sx, int sy, int sw, int sh, ExceptionState& es) |
83 { | 83 { |
84 // This variant does not work in worker threads. | 84 // This variant does not work in worker threads. |
85 ASSERT(eventTarget->toDOMWindow()); | 85 ASSERT(eventTarget->toDOMWindow()); |
86 | 86 |
87 if (!image) { | 87 if (!image) { |
88 es.throwTypeError(); | 88 es.throwTypeError(); |
89 return ScriptObject(); | 89 return ScriptPromise(); |
90 } | 90 } |
91 if (!image->cachedImage()) { | 91 if (!image->cachedImage()) { |
92 es.throwDOMException(InvalidStateError); | 92 es.throwDOMException(InvalidStateError); |
93 return ScriptObject(); | 93 return ScriptPromise(); |
94 } | 94 } |
95 if (image->cachedImage()->image()->isSVGImage()) { | 95 if (image->cachedImage()->image()->isSVGImage()) { |
96 es.throwDOMException(InvalidStateError); | 96 es.throwDOMException(InvalidStateError); |
97 return ScriptObject(); | 97 return ScriptPromise(); |
98 } | 98 } |
99 if (!sw || !sh) { | 99 if (!sw || !sh) { |
100 es.throwDOMException(IndexSizeError); | 100 es.throwDOMException(IndexSizeError); |
101 return ScriptObject(); | 101 return ScriptPromise(); |
102 } | 102 } |
103 if (!image->cachedImage()->image()->currentFrameHasSingleSecurityOrigin()) { | 103 if (!image->cachedImage()->image()->currentFrameHasSingleSecurityOrigin()) { |
104 es.throwDOMException(SecurityError); | 104 es.throwDOMException(SecurityError); |
105 return ScriptObject(); | 105 return ScriptPromise(); |
106 } | 106 } |
107 if (!image->cachedImage()->passesAccessControlCheck(eventTarget->toDOMWindow
()->document()->securityOrigin()) | 107 if (!image->cachedImage()->passesAccessControlCheck(eventTarget->toDOMWindow
()->document()->securityOrigin()) |
108 && eventTarget->toDOMWindow()->document()->securityOrigin()->taintsCanvas(im
age->src())) { | 108 && eventTarget->toDOMWindow()->document()->securityOrigin()->taintsCanvas(im
age->src())) { |
109 es.throwDOMException(SecurityError); | 109 es.throwDOMException(SecurityError); |
110 return ScriptObject(); | 110 return ScriptPromise(); |
111 } | 111 } |
112 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 | 112 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 |
113 return fulfillImageBitmap(eventTarget->scriptExecutionContext(), ImageBitmap
::create(image, IntRect(sx, sy, sw, sh))); | 113 return fulfillImageBitmap(eventTarget->scriptExecutionContext(), ImageBitmap
::create(image, IntRect(sx, sy, sw, sh))); |
114 } | 114 } |
115 | 115 |
116 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, H
TMLVideoElement* video, ExceptionState& es) | 116 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget,
HTMLVideoElement* video, ExceptionState& es) |
117 { | 117 { |
118 IntSize s = sizeFor(video); | 118 IntSize s = sizeFor(video); |
119 return createImageBitmap(eventTarget, video, 0, 0, s.width(), s.height(), es
); | 119 return createImageBitmap(eventTarget, video, 0, 0, s.width(), s.height(), es
); |
120 } | 120 } |
121 | 121 |
122 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, H
TMLVideoElement* video, int sx, int sy, int sw, int sh, ExceptionState& es) | 122 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget,
HTMLVideoElement* video, int sx, int sy, int sw, int sh, ExceptionState& es) |
123 { | 123 { |
124 // This variant does not work in worker threads. | 124 // This variant does not work in worker threads. |
125 ASSERT(eventTarget->toDOMWindow()); | 125 ASSERT(eventTarget->toDOMWindow()); |
126 | 126 |
127 if (!video) { | 127 if (!video) { |
128 es.throwTypeError(); | 128 es.throwTypeError(); |
129 return ScriptObject(); | 129 return ScriptPromise(); |
130 } | 130 } |
131 if (!video->player()) { | 131 if (!video->player()) { |
132 es.throwDOMException(InvalidStateError); | 132 es.throwDOMException(InvalidStateError); |
133 return ScriptObject(); | 133 return ScriptPromise(); |
134 } | 134 } |
135 if (video->networkState() == HTMLMediaElement::NETWORK_EMPTY) { | 135 if (video->networkState() == HTMLMediaElement::NETWORK_EMPTY) { |
136 es.throwDOMException(InvalidStateError); | 136 es.throwDOMException(InvalidStateError); |
137 return ScriptObject(); | 137 return ScriptPromise(); |
138 } | 138 } |
139 if (video->player()->readyState() <= MediaPlayer::HaveMetadata) { | 139 if (video->player()->readyState() <= MediaPlayer::HaveMetadata) { |
140 es.throwDOMException(InvalidStateError); | 140 es.throwDOMException(InvalidStateError); |
141 return ScriptObject(); | 141 return ScriptPromise(); |
142 } | 142 } |
143 if (!sw || !sh) { | 143 if (!sw || !sh) { |
144 es.throwDOMException(IndexSizeError); | 144 es.throwDOMException(IndexSizeError); |
145 return ScriptObject(); | 145 return ScriptPromise(); |
146 } | 146 } |
147 if (!video->hasSingleSecurityOrigin()) { | 147 if (!video->hasSingleSecurityOrigin()) { |
148 es.throwDOMException(SecurityError); | 148 es.throwDOMException(SecurityError); |
149 return ScriptObject(); | 149 return ScriptPromise(); |
150 } | 150 } |
151 if (!video->player()->didPassCORSAccessCheck() && eventTarget->toDOMWindow()
->document()->securityOrigin()->taintsCanvas(video->currentSrc())) { | 151 if (!video->player()->didPassCORSAccessCheck() && eventTarget->toDOMWindow()
->document()->securityOrigin()->taintsCanvas(video->currentSrc())) { |
152 es.throwDOMException(SecurityError); | 152 es.throwDOMException(SecurityError); |
153 return ScriptObject(); | 153 return ScriptPromise(); |
154 } | 154 } |
155 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 | 155 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 |
156 return fulfillImageBitmap(eventTarget->scriptExecutionContext(), ImageBitmap
::create(video, IntRect(sx, sy, sw, sh))); | 156 return fulfillImageBitmap(eventTarget->scriptExecutionContext(), ImageBitmap
::create(video, IntRect(sx, sy, sw, sh))); |
157 } | 157 } |
158 | 158 |
159 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, C
anvasRenderingContext2D* context, ExceptionState& es) | 159 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget,
CanvasRenderingContext2D* context, ExceptionState& es) |
160 { | 160 { |
161 return createImageBitmap(eventTarget, context->canvas(), es); | 161 return createImageBitmap(eventTarget, context->canvas(), es); |
162 } | 162 } |
163 | 163 |
164 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, C
anvasRenderingContext2D* context, int sx, int sy, int sw, int sh, ExceptionState
& es) | 164 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget,
CanvasRenderingContext2D* context, int sx, int sy, int sw, int sh, ExceptionStat
e& es) |
165 { | 165 { |
166 return createImageBitmap(eventTarget, context->canvas(), sx, sy, sw, sh, es)
; | 166 return createImageBitmap(eventTarget, context->canvas(), sx, sy, sw, sh, es)
; |
167 } | 167 } |
168 | 168 |
169 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, H
TMLCanvasElement* canvas, ExceptionState& es) | 169 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget,
HTMLCanvasElement* canvas, ExceptionState& es) |
170 { | 170 { |
171 return createImageBitmap(eventTarget, canvas, 0, 0, canvas->width(), canvas-
>height(), es); | 171 return createImageBitmap(eventTarget, canvas, 0, 0, canvas->width(), canvas-
>height(), es); |
172 } | 172 } |
173 | 173 |
174 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, H
TMLCanvasElement* canvas, int sx, int sy, int sw, int sh, ExceptionState& es) | 174 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget,
HTMLCanvasElement* canvas, int sx, int sy, int sw, int sh, ExceptionState& es) |
175 { | 175 { |
176 // This variant does not work in worker threads. | 176 // This variant does not work in worker threads. |
177 ASSERT(eventTarget->toDOMWindow()); | 177 ASSERT(eventTarget->toDOMWindow()); |
178 | 178 |
179 if (!canvas) { | 179 if (!canvas) { |
180 es.throwTypeError(); | 180 es.throwTypeError(); |
181 return ScriptObject(); | 181 return ScriptPromise(); |
182 } | 182 } |
183 if (!canvas->originClean()) { | 183 if (!canvas->originClean()) { |
184 es.throwDOMException(InvalidStateError); | 184 es.throwDOMException(InvalidStateError); |
185 return ScriptObject(); | 185 return ScriptPromise(); |
186 } | 186 } |
187 if (!sw || !sh) { | 187 if (!sw || !sh) { |
188 es.throwDOMException(IndexSizeError); | 188 es.throwDOMException(IndexSizeError); |
189 return ScriptObject(); | 189 return ScriptPromise(); |
190 } | 190 } |
191 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 | 191 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 |
192 return fulfillImageBitmap(eventTarget->scriptExecutionContext(), ImageBitmap
::create(canvas, IntRect(sx, sy, sw, sh))); | 192 return fulfillImageBitmap(eventTarget->scriptExecutionContext(), ImageBitmap
::create(canvas, IntRect(sx, sy, sw, sh))); |
193 } | 193 } |
194 | 194 |
195 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, B
lob* blob, ExceptionState& es) | 195 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget,
Blob* blob, ExceptionState& es) |
196 { | 196 { |
197 // Promises must be enabled. | 197 // Promises must be enabled. |
198 ASSERT(RuntimeEnabledFeatures::promiseEnabled()); | 198 ASSERT(RuntimeEnabledFeatures::promiseEnabled()); |
199 | 199 |
200 if (!blob) { | 200 if (!blob) { |
201 es.throwDOMException(TypeError); | 201 es.throwDOMException(TypeError); |
202 return ScriptObject(); | 202 return ScriptPromise(); |
203 } | 203 } |
204 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(event
Target->scriptExecutionContext()); | 204 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(event
Target->scriptExecutionContext()); |
205 RefPtr<ImageBitmapLoader> loader = ImageBitmapFactories::ImageBitmapLoader::
create(from(eventTarget), resolver, IntRect()); | 205 RefPtr<ImageBitmapLoader> loader = ImageBitmapFactories::ImageBitmapLoader::
create(from(eventTarget), resolver, IntRect()); |
206 from(eventTarget)->addLoader(loader); | 206 from(eventTarget)->addLoader(loader); |
207 loader->loadBlobAsync(eventTarget->scriptExecutionContext(), blob); | 207 loader->loadBlobAsync(eventTarget->scriptExecutionContext(), blob); |
208 return resolver->promise(); | 208 return resolver->promise(); |
209 } | 209 } |
210 | 210 |
211 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, B
lob* blob, int sx, int sy, int sw, int sh, ExceptionState& es) | 211 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget,
Blob* blob, int sx, int sy, int sw, int sh, ExceptionState& es) |
212 { | 212 { |
213 // Promises must be enabled. | 213 // Promises must be enabled. |
214 ASSERT(RuntimeEnabledFeatures::promiseEnabled()); | 214 ASSERT(RuntimeEnabledFeatures::promiseEnabled()); |
215 | 215 |
216 if (!blob) { | 216 if (!blob) { |
217 es.throwDOMException(TypeError); | 217 es.throwDOMException(TypeError); |
218 return ScriptObject(); | 218 return ScriptPromise(); |
219 } | 219 } |
220 if (!sw || !sh) { | 220 if (!sw || !sh) { |
221 es.throwDOMException(IndexSizeError); | 221 es.throwDOMException(IndexSizeError); |
222 return ScriptObject(); | 222 return ScriptPromise(); |
223 } | 223 } |
224 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(event
Target->scriptExecutionContext()); | 224 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(event
Target->scriptExecutionContext()); |
225 RefPtr<ImageBitmapLoader> loader = ImageBitmapFactories::ImageBitmapLoader::
create(from(eventTarget), resolver, IntRect(sx, sy, sw, sh)); | 225 RefPtr<ImageBitmapLoader> loader = ImageBitmapFactories::ImageBitmapLoader::
create(from(eventTarget), resolver, IntRect(sx, sy, sw, sh)); |
226 from(eventTarget)->addLoader(loader); | 226 from(eventTarget)->addLoader(loader); |
227 loader->loadBlobAsync(eventTarget->scriptExecutionContext(), blob); | 227 loader->loadBlobAsync(eventTarget->scriptExecutionContext(), blob); |
228 return resolver->promise(); | 228 return resolver->promise(); |
229 } | 229 } |
230 | 230 |
231 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, I
mageData* data, ExceptionState& es) | 231 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget,
ImageData* data, ExceptionState& es) |
232 { | 232 { |
233 return createImageBitmap(eventTarget, data, 0, 0, data->width(), data->heigh
t(), es); | 233 return createImageBitmap(eventTarget, data, 0, 0, data->width(), data->heigh
t(), es); |
234 } | 234 } |
235 | 235 |
236 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, I
mageData* data, int sx, int sy, int sw, int sh, ExceptionState& es) | 236 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget,
ImageData* data, int sx, int sy, int sw, int sh, ExceptionState& es) |
237 { | 237 { |
238 if (!data) { | 238 if (!data) { |
239 es.throwTypeError(); | 239 es.throwTypeError(); |
240 return ScriptObject(); | 240 return ScriptPromise(); |
241 } | 241 } |
242 if (!sw || !sh) { | 242 if (!sw || !sh) { |
243 es.throwDOMException(IndexSizeError); | 243 es.throwDOMException(IndexSizeError); |
244 return ScriptObject(); | 244 return ScriptPromise(); |
245 } | 245 } |
246 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 | 246 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 |
247 return fulfillImageBitmap(eventTarget->scriptExecutionContext(), ImageBitmap
::create(data, IntRect(sx, sy, sw, sh))); | 247 return fulfillImageBitmap(eventTarget->scriptExecutionContext(), ImageBitmap
::create(data, IntRect(sx, sy, sw, sh))); |
248 } | 248 } |
249 | 249 |
250 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, I
mageBitmap* bitmap, ExceptionState& es) | 250 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget,
ImageBitmap* bitmap, ExceptionState& es) |
251 { | 251 { |
252 return createImageBitmap(eventTarget, bitmap, 0, 0, bitmap->width(), bitmap-
>height(), es); | 252 return createImageBitmap(eventTarget, bitmap, 0, 0, bitmap->width(), bitmap-
>height(), es); |
253 } | 253 } |
254 | 254 |
255 ScriptObject ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget, I
mageBitmap* bitmap, int sx, int sy, int sw, int sh, ExceptionState& es) | 255 ScriptPromise ImageBitmapFactories::createImageBitmap(EventTarget* eventTarget,
ImageBitmap* bitmap, int sx, int sy, int sw, int sh, ExceptionState& es) |
256 { | 256 { |
257 if (!bitmap) { | 257 if (!bitmap) { |
258 es.throwTypeError(); | 258 es.throwTypeError(); |
259 return ScriptObject(); | 259 return ScriptPromise(); |
260 } | 260 } |
261 if (!sw || !sh) { | 261 if (!sw || !sh) { |
262 es.throwDOMException(IndexSizeError); | 262 es.throwDOMException(IndexSizeError); |
263 return ScriptObject(); | 263 return ScriptPromise(); |
264 } | 264 } |
265 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 | 265 // FIXME: make ImageBitmap creation asynchronous crbug.com/258082 |
266 return fulfillImageBitmap(eventTarget->scriptExecutionContext(), ImageBitmap
::create(bitmap, IntRect(sx, sy, sw, sh))); | 266 return fulfillImageBitmap(eventTarget->scriptExecutionContext(), ImageBitmap
::create(bitmap, IntRect(sx, sy, sw, sh))); |
267 } | 267 } |
268 | 268 |
269 const char* ImageBitmapFactories::supplementName() | 269 const char* ImageBitmapFactories::supplementName() |
270 { | 270 { |
271 return "ImageBitmapFactories"; | 271 return "ImageBitmapFactories"; |
272 } | 272 } |
273 | 273 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 m_resolver->fulfill(imageBitmap.release()); | 354 m_resolver->fulfill(imageBitmap.release()); |
355 m_factory->didFinishLoading(this); | 355 m_factory->didFinishLoading(this); |
356 } | 356 } |
357 | 357 |
358 void ImageBitmapFactories::ImageBitmapLoader::didFail(FileError::ErrorCode) | 358 void ImageBitmapFactories::ImageBitmapLoader::didFail(FileError::ErrorCode) |
359 { | 359 { |
360 rejectPromise(); | 360 rejectPromise(); |
361 } | 361 } |
362 | 362 |
363 } // namespace WebCore | 363 } // namespace WebCore |
OLD | NEW |