| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 #include "public/platform/Platform.h" | 49 #include "public/platform/Platform.h" |
| 50 #include "public/platform/WebThread.h" | 50 #include "public/platform/WebThread.h" |
| 51 #include "public/platform/WebTraceLocation.h" | 51 #include "public/platform/WebTraceLocation.h" |
| 52 #include <v8.h> | 52 #include <v8.h> |
| 53 | 53 |
| 54 namespace blink { | 54 namespace blink { |
| 55 | 55 |
| 56 static inline ImageBitmapSource* toImageBitmapSourceInternal(const ImageBitmapSo
urceUnion& value) | 56 static inline ImageBitmapSource* toImageBitmapSourceInternal(const ImageBitmapSo
urceUnion& value) |
| 57 { | 57 { |
| 58 if (value.isHTMLImageElement()) | 58 if (value.isHTMLImageElement()) |
| 59 return value.getAsHTMLImageElement().get(); | 59 return value.getAsHTMLImageElement(); |
| 60 if (value.isHTMLVideoElement()) | 60 if (value.isHTMLVideoElement()) |
| 61 return value.getAsHTMLVideoElement().get(); | 61 return value.getAsHTMLVideoElement(); |
| 62 if (value.isHTMLCanvasElement()) | 62 if (value.isHTMLCanvasElement()) |
| 63 return value.getAsHTMLCanvasElement().get(); | 63 return value.getAsHTMLCanvasElement(); |
| 64 if (value.isBlob()) | 64 if (value.isBlob()) |
| 65 return value.getAsBlob(); | 65 return value.getAsBlob(); |
| 66 if (value.isImageData()) | 66 if (value.isImageData()) |
| 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(); |
| 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 ImageBitmapOptions options; | 76 ImageBitmapOptions options; |
| 77 return createImageBitmap(scriptState, eventTarget, bitmapSource, options, ex
ceptionState); | 77 return createImageBitmap(scriptState, eventTarget, bitmapSource, options, ex
ceptionState); |
| 78 } | 78 } |
| 79 | 79 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 if (LocalDOMWindow* window = eventTarget.toDOMWindow()) | 132 if (LocalDOMWindow* window = eventTarget.toDOMWindow()) |
| 133 return fromInternal(*window); | 133 return fromInternal(*window); |
| 134 | 134 |
| 135 ASSERT(eventTarget.executionContext()->isWorkerGlobalScope()); | 135 ASSERT(eventTarget.executionContext()->isWorkerGlobalScope()); |
| 136 return ImageBitmapFactories::fromInternal(*toWorkerGlobalScope(eventTarget.e
xecutionContext())); | 136 return ImageBitmapFactories::fromInternal(*toWorkerGlobalScope(eventTarget.e
xecutionContext())); |
| 137 } | 137 } |
| 138 | 138 |
| 139 template<class GlobalObject> | 139 template<class GlobalObject> |
| 140 ImageBitmapFactories& ImageBitmapFactories::fromInternal(GlobalObject& object) | 140 ImageBitmapFactories& ImageBitmapFactories::fromInternal(GlobalObject& object) |
| 141 { | 141 { |
| 142 ImageBitmapFactories* supplement = static_cast<ImageBitmapFactories*>(WillBe
HeapSupplement<GlobalObject>::from(object, supplementName())); | 142 ImageBitmapFactories* supplement = static_cast<ImageBitmapFactories*>(HeapSu
pplement<GlobalObject>::from(object, supplementName())); |
| 143 if (!supplement) { | 143 if (!supplement) { |
| 144 supplement = new ImageBitmapFactories(); | 144 supplement = new ImageBitmapFactories(); |
| 145 WillBeHeapSupplement<GlobalObject>::provideTo(object, supplementName(),
adoptPtrWillBeNoop(supplement)); | 145 HeapSupplement<GlobalObject>::provideTo(object, supplementName(), (suppl
ement)); |
| 146 } | 146 } |
| 147 return *supplement; | 147 return *supplement; |
| 148 } | 148 } |
| 149 | 149 |
| 150 void ImageBitmapFactories::addLoader(ImageBitmapLoader* loader) | 150 void ImageBitmapFactories::addLoader(ImageBitmapLoader* loader) |
| 151 { | 151 { |
| 152 m_pendingLoaders.add(loader); | 152 m_pendingLoaders.add(loader); |
| 153 } | 153 } |
| 154 | 154 |
| 155 void ImageBitmapFactories::didFinishLoading(ImageBitmapLoader* loader) | 155 void ImageBitmapFactories::didFinishLoading(ImageBitmapLoader* loader) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 168 } | 168 } |
| 169 | 169 |
| 170 void ImageBitmapFactories::ImageBitmapLoader::loadBlobAsync(ExecutionContext* co
ntext, Blob* blob) | 170 void ImageBitmapFactories::ImageBitmapLoader::loadBlobAsync(ExecutionContext* co
ntext, Blob* blob) |
| 171 { | 171 { |
| 172 m_loader.start(context, blob->blobDataHandle()); | 172 m_loader.start(context, blob->blobDataHandle()); |
| 173 } | 173 } |
| 174 | 174 |
| 175 DEFINE_TRACE(ImageBitmapFactories) | 175 DEFINE_TRACE(ImageBitmapFactories) |
| 176 { | 176 { |
| 177 visitor->trace(m_pendingLoaders); | 177 visitor->trace(m_pendingLoaders); |
| 178 WillBeHeapSupplement<LocalDOMWindow>::trace(visitor); | 178 HeapSupplement<LocalDOMWindow>::trace(visitor); |
| 179 WillBeHeapSupplement<WorkerGlobalScope>::trace(visitor); | 179 HeapSupplement<WorkerGlobalScope>::trace(visitor); |
| 180 } | 180 } |
| 181 | 181 |
| 182 void ImageBitmapFactories::ImageBitmapLoader::rejectPromise() | 182 void ImageBitmapFactories::ImageBitmapLoader::rejectPromise() |
| 183 { | 183 { |
| 184 m_resolver->reject(ScriptValue(m_resolver->scriptState(), v8::Null(m_resolve
r->scriptState()->isolate()))); | 184 m_resolver->reject(ScriptValue(m_resolver->scriptState(), v8::Null(m_resolve
r->scriptState()->isolate()))); |
| 185 m_factory->didFinishLoading(this); | 185 m_factory->didFinishLoading(this); |
| 186 } | 186 } |
| 187 | 187 |
| 188 void ImageBitmapFactories::ImageBitmapLoader::didFinishLoading() | 188 void ImageBitmapFactories::ImageBitmapLoader::didFinishLoading() |
| 189 { | 189 { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 return; | 230 return; |
| 231 } | 231 } |
| 232 | 232 |
| 233 RefPtr<StaticBitmapImage> image = StaticBitmapImage::create(frame); | 233 RefPtr<StaticBitmapImage> image = StaticBitmapImage::create(frame); |
| 234 image->setOriginClean(true); | 234 image->setOriginClean(true); |
| 235 if (!m_cropRect.width() && !m_cropRect.height()) { | 235 if (!m_cropRect.width() && !m_cropRect.height()) { |
| 236 // No cropping variant was called. | 236 // No cropping variant was called. |
| 237 m_cropRect = IntRect(IntPoint(), image->size()); | 237 m_cropRect = IntRect(IntPoint(), image->size()); |
| 238 } | 238 } |
| 239 | 239 |
| 240 RefPtrWillBeRawPtr<ImageBitmap> imageBitmap = ImageBitmap::create(image, m_c
ropRect, m_options); | 240 RawPtr<ImageBitmap> imageBitmap = ImageBitmap::create(image, m_cropRect, m_o
ptions); |
| 241 m_resolver->resolve(imageBitmap.release()); | 241 m_resolver->resolve(imageBitmap.release()); |
| 242 m_factory->didFinishLoading(this); | 242 m_factory->didFinishLoading(this); |
| 243 } | 243 } |
| 244 | 244 |
| 245 DEFINE_TRACE(ImageBitmapFactories::ImageBitmapLoader) | 245 DEFINE_TRACE(ImageBitmapFactories::ImageBitmapLoader) |
| 246 { | 246 { |
| 247 visitor->trace(m_factory); | 247 visitor->trace(m_factory); |
| 248 visitor->trace(m_resolver); | 248 visitor->trace(m_resolver); |
| 249 } | 249 } |
| 250 | 250 |
| 251 } // namespace blink | 251 } // namespace blink |
| OLD | NEW |