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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 return value.getAsImageData(); | 67 return value.getAsImageData(); |
68 if (value.isImageBitmap()) | 68 if (value.isImageBitmap()) |
69 return value.getAsImageBitmap().get(); | 69 return value.getAsImageBitmap().get(); |
70 ASSERT_NOT_REACHED(); | 70 ASSERT_NOT_REACHED(); |
71 return nullptr; | 71 return nullptr; |
72 } | 72 } |
73 | 73 |
74 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState,
EventTarget& eventTarget, const ImageBitmapSourceUnion& bitmapSource, ExceptionS
tate& exceptionState) | 74 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState,
EventTarget& eventTarget, const ImageBitmapSourceUnion& bitmapSource, ExceptionS
tate& exceptionState) |
75 { | 75 { |
76 UseCounter::Feature feature = UseCounter::CreateImageBitmap; | 76 UseCounter::Feature feature = UseCounter::CreateImageBitmap; |
77 UseCounter::count(scriptState->executionContext(), feature); | 77 UseCounter::count(scriptState->getExecutionContext(), feature); |
78 ImageBitmapOptions options; | 78 ImageBitmapOptions options; |
79 return createImageBitmap(scriptState, eventTarget, bitmapSource, options, ex
ceptionState); | 79 return createImageBitmap(scriptState, eventTarget, bitmapSource, options, ex
ceptionState); |
80 } | 80 } |
81 | 81 |
82 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState,
EventTarget& eventTarget, const ImageBitmapSourceUnion& bitmapSource, const Imag
eBitmapOptions& options, ExceptionState& exceptionState) | 82 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState,
EventTarget& eventTarget, const ImageBitmapSourceUnion& bitmapSource, const Imag
eBitmapOptions& options, ExceptionState& exceptionState) |
83 { | 83 { |
84 ImageBitmapSource* bitmapSourceInternal = toImageBitmapSourceInternal(bitmap
Source); | 84 ImageBitmapSource* bitmapSourceInternal = toImageBitmapSourceInternal(bitmap
Source); |
85 if (bitmapSourceInternal->isBlob()) { | 85 if (bitmapSourceInternal->isBlob()) { |
86 Blob* blob = static_cast<Blob*>(bitmapSourceInternal); | 86 Blob* blob = static_cast<Blob*>(bitmapSourceInternal); |
87 ImageBitmapLoader* loader = ImageBitmapFactories::ImageBitmapLoader::cre
ate(from(eventTarget), IntRect(), options, scriptState); | 87 ImageBitmapLoader* loader = ImageBitmapFactories::ImageBitmapLoader::cre
ate(from(eventTarget), IntRect(), options, scriptState); |
88 ScriptPromise promise = loader->promise(); | 88 ScriptPromise promise = loader->promise(); |
89 from(eventTarget).addLoader(loader); | 89 from(eventTarget).addLoader(loader); |
90 loader->loadBlobAsync(eventTarget.executionContext(), blob); | 90 loader->loadBlobAsync(eventTarget.getExecutionContext(), blob); |
91 return promise; | 91 return promise; |
92 } | 92 } |
93 IntSize srcSize = bitmapSourceInternal->bitmapSourceSize(); | 93 IntSize srcSize = bitmapSourceInternal->bitmapSourceSize(); |
94 return createImageBitmap(scriptState, eventTarget, bitmapSourceInternal, 0,
0, srcSize.width(), srcSize.height(), options, exceptionState); | 94 return createImageBitmap(scriptState, eventTarget, bitmapSourceInternal, 0,
0, srcSize.width(), srcSize.height(), options, exceptionState); |
95 } | 95 } |
96 | 96 |
97 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState,
EventTarget& eventTarget, const ImageBitmapSourceUnion& bitmapSource, int sx, in
t sy, int sw, int sh, ExceptionState& exceptionState) | 97 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState,
EventTarget& eventTarget, const ImageBitmapSourceUnion& bitmapSource, int sx, in
t sy, int sw, int sh, ExceptionState& exceptionState) |
98 { | 98 { |
99 UseCounter::Feature feature = UseCounter::CreateImageBitmap; | 99 UseCounter::Feature feature = UseCounter::CreateImageBitmap; |
100 UseCounter::count(scriptState->executionContext(), feature); | 100 UseCounter::count(scriptState->getExecutionContext(), feature); |
101 ImageBitmapOptions options; | 101 ImageBitmapOptions options; |
102 return createImageBitmap(scriptState, eventTarget, bitmapSource, sx, sy, sw,
sh, options, exceptionState); | 102 return createImageBitmap(scriptState, eventTarget, bitmapSource, sx, sy, sw,
sh, options, exceptionState); |
103 } | 103 } |
104 | 104 |
105 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState,
EventTarget& eventTarget, const ImageBitmapSourceUnion& bitmapSource, int sx, in
t sy, int sw, int sh, const ImageBitmapOptions& options, ExceptionState& excepti
onState) | 105 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState,
EventTarget& eventTarget, const ImageBitmapSourceUnion& bitmapSource, int sx, in
t sy, int sw, int sh, const ImageBitmapOptions& options, ExceptionState& excepti
onState) |
106 { | 106 { |
107 ImageBitmapSource* bitmapSourceInternal = toImageBitmapSourceInternal(bitmap
Source); | 107 ImageBitmapSource* bitmapSourceInternal = toImageBitmapSourceInternal(bitmap
Source); |
108 return createImageBitmap(scriptState, eventTarget, bitmapSourceInternal, sx,
sy, sw, sh, options, exceptionState); | 108 return createImageBitmap(scriptState, eventTarget, bitmapSourceInternal, sx,
sy, sw, sh, options, exceptionState); |
109 } | 109 } |
110 | 110 |
111 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState,
EventTarget& eventTarget, ImageBitmapSource* bitmapSource, int sx, int sy, int s
w, int sh, const ImageBitmapOptions& options, ExceptionState& exceptionState) | 111 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState,
EventTarget& eventTarget, ImageBitmapSource* bitmapSource, int sx, int sy, int s
w, int sh, const ImageBitmapOptions& options, ExceptionState& exceptionState) |
112 { | 112 { |
113 if (bitmapSource->isBlob()) { | 113 if (bitmapSource->isBlob()) { |
114 if (!sw || !sh) { | 114 if (!sw || !sh) { |
115 exceptionState.throwDOMException(IndexSizeError, String::format("The
source %s provided is 0.", sw ? "height" : "width")); | 115 exceptionState.throwDOMException(IndexSizeError, String::format("The
source %s provided is 0.", sw ? "height" : "width")); |
116 return ScriptPromise(); | 116 return ScriptPromise(); |
117 } | 117 } |
118 Blob* blob = static_cast<Blob*>(bitmapSource); | 118 Blob* blob = static_cast<Blob*>(bitmapSource); |
119 ImageBitmapLoader* loader = ImageBitmapFactories::ImageBitmapLoader::cre
ate(from(eventTarget), IntRect(sx, sy, sw, sh), options, scriptState); | 119 ImageBitmapLoader* loader = ImageBitmapFactories::ImageBitmapLoader::cre
ate(from(eventTarget), IntRect(sx, sy, sw, sh), options, scriptState); |
120 ScriptPromise promise = loader->promise(); | 120 ScriptPromise promise = loader->promise(); |
121 from(eventTarget).addLoader(loader); | 121 from(eventTarget).addLoader(loader); |
122 loader->loadBlobAsync(eventTarget.executionContext(), blob); | 122 loader->loadBlobAsync(eventTarget.getExecutionContext(), blob); |
123 return promise; | 123 return promise; |
124 } | 124 } |
125 | 125 |
126 return bitmapSource->createImageBitmap(scriptState, eventTarget, sx, sy, sw,
sh, options, exceptionState); | 126 return bitmapSource->createImageBitmap(scriptState, eventTarget, sx, sy, sw,
sh, options, exceptionState); |
127 } | 127 } |
128 | 128 |
129 const char* ImageBitmapFactories::supplementName() | 129 const char* ImageBitmapFactories::supplementName() |
130 { | 130 { |
131 return "ImageBitmapFactories"; | 131 return "ImageBitmapFactories"; |
132 } | 132 } |
133 | 133 |
134 ImageBitmapFactories& ImageBitmapFactories::from(EventTarget& eventTarget) | 134 ImageBitmapFactories& ImageBitmapFactories::from(EventTarget& eventTarget) |
135 { | 135 { |
136 if (LocalDOMWindow* window = eventTarget.toDOMWindow()) | 136 if (LocalDOMWindow* window = eventTarget.toDOMWindow()) |
137 return fromInternal(*window); | 137 return fromInternal(*window); |
138 | 138 |
139 ASSERT(eventTarget.executionContext()->isWorkerGlobalScope()); | 139 ASSERT(eventTarget.getExecutionContext()->isWorkerGlobalScope()); |
140 return ImageBitmapFactories::fromInternal(*toWorkerGlobalScope(eventTarget.e
xecutionContext())); | 140 return ImageBitmapFactories::fromInternal(*toWorkerGlobalScope(eventTarget.g
etExecutionContext())); |
141 } | 141 } |
142 | 142 |
143 template<class GlobalObject> | 143 template<class GlobalObject> |
144 ImageBitmapFactories& ImageBitmapFactories::fromInternal(GlobalObject& object) | 144 ImageBitmapFactories& ImageBitmapFactories::fromInternal(GlobalObject& object) |
145 { | 145 { |
146 ImageBitmapFactories* supplement = static_cast<ImageBitmapFactories*>(WillBe
HeapSupplement<GlobalObject>::from(object, supplementName())); | 146 ImageBitmapFactories* supplement = static_cast<ImageBitmapFactories*>(WillBe
HeapSupplement<GlobalObject>::from(object, supplementName())); |
147 if (!supplement) { | 147 if (!supplement) { |
148 supplement = new ImageBitmapFactories(); | 148 supplement = new ImageBitmapFactories(); |
149 WillBeHeapSupplement<GlobalObject>::provideTo(object, supplementName(),
adoptPtrWillBeNoop(supplement)); | 149 WillBeHeapSupplement<GlobalObject>::provideTo(object, supplementName(),
adoptPtrWillBeNoop(supplement)); |
150 } | 150 } |
(...skipping 27 matching lines...) Expand all Loading... |
178 | 178 |
179 DEFINE_TRACE(ImageBitmapFactories) | 179 DEFINE_TRACE(ImageBitmapFactories) |
180 { | 180 { |
181 visitor->trace(m_pendingLoaders); | 181 visitor->trace(m_pendingLoaders); |
182 WillBeHeapSupplement<LocalDOMWindow>::trace(visitor); | 182 WillBeHeapSupplement<LocalDOMWindow>::trace(visitor); |
183 WillBeHeapSupplement<WorkerGlobalScope>::trace(visitor); | 183 WillBeHeapSupplement<WorkerGlobalScope>::trace(visitor); |
184 } | 184 } |
185 | 185 |
186 void ImageBitmapFactories::ImageBitmapLoader::rejectPromise() | 186 void ImageBitmapFactories::ImageBitmapLoader::rejectPromise() |
187 { | 187 { |
188 m_resolver->reject(ScriptValue(m_resolver->scriptState(), v8::Null(m_resolve
r->scriptState()->isolate()))); | 188 m_resolver->reject(ScriptValue(m_resolver->getScriptState(), v8::Null(m_reso
lver->getScriptState()->isolate()))); |
189 m_factory->didFinishLoading(this); | 189 m_factory->didFinishLoading(this); |
190 } | 190 } |
191 | 191 |
192 void ImageBitmapFactories::ImageBitmapLoader::didFinishLoading() | 192 void ImageBitmapFactories::ImageBitmapLoader::didFinishLoading() |
193 { | 193 { |
194 if (!m_loader.arrayBufferResult()) { | 194 if (!m_loader.arrayBufferResult()) { |
195 rejectPromise(); | 195 rejectPromise(); |
196 return; | 196 return; |
197 } | 197 } |
198 scheduleAsyncImageBitmapDecoding(); | 198 scheduleAsyncImageBitmapDecoding(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 m_factory->didFinishLoading(this); | 258 m_factory->didFinishLoading(this); |
259 } | 259 } |
260 | 260 |
261 DEFINE_TRACE(ImageBitmapFactories::ImageBitmapLoader) | 261 DEFINE_TRACE(ImageBitmapFactories::ImageBitmapLoader) |
262 { | 262 { |
263 visitor->trace(m_factory); | 263 visitor->trace(m_factory); |
264 visitor->trace(m_resolver); | 264 visitor->trace(m_resolver); |
265 } | 265 } |
266 | 266 |
267 } // namespace blink | 267 } // namespace blink |
OLD | NEW |