Chromium Code Reviews| 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 27 matching lines...) Expand all Loading... | |
| 38 #include "core/fileapi/Blob.h" | 38 #include "core/fileapi/Blob.h" |
| 39 #include "core/frame/ImageBitmap.h" | 39 #include "core/frame/ImageBitmap.h" |
| 40 #include "core/frame/LocalDOMWindow.h" | 40 #include "core/frame/LocalDOMWindow.h" |
| 41 #include "core/frame/UseCounter.h" | 41 #include "core/frame/UseCounter.h" |
| 42 #include "core/html/HTMLCanvasElement.h" | 42 #include "core/html/HTMLCanvasElement.h" |
| 43 #include "core/html/HTMLImageElement.h" | 43 #include "core/html/HTMLImageElement.h" |
| 44 #include "core/html/HTMLVideoElement.h" | 44 #include "core/html/HTMLVideoElement.h" |
| 45 #include "core/html/ImageData.h" | 45 #include "core/html/ImageData.h" |
| 46 #include "core/imagebitmap/ImageBitmapOptions.h" | 46 #include "core/imagebitmap/ImageBitmapOptions.h" |
| 47 #include "core/offscreencanvas/OffscreenCanvas.h" | 47 #include "core/offscreencanvas/OffscreenCanvas.h" |
| 48 #include "core/svg/SVGImageElement.h" | |
| 48 #include "core/svg/graphics/SVGImage.h" | 49 #include "core/svg/graphics/SVGImage.h" |
| 49 #include "core/workers/WorkerGlobalScope.h" | 50 #include "core/workers/WorkerGlobalScope.h" |
| 50 #include "platform/CrossThreadFunctional.h" | 51 #include "platform/CrossThreadFunctional.h" |
| 51 #include "platform/SharedBuffer.h" | 52 #include "platform/SharedBuffer.h" |
| 52 #include "platform/image-decoders/ImageDecoder.h" | 53 #include "platform/image-decoders/ImageDecoder.h" |
| 53 #include "platform/threading/BackgroundTaskRunner.h" | 54 #include "platform/threading/BackgroundTaskRunner.h" |
| 54 #include "public/platform/Platform.h" | 55 #include "public/platform/Platform.h" |
| 55 #include "public/platform/WebThread.h" | 56 #include "public/platform/WebThread.h" |
| 56 #include "public/platform/WebTraceLocation.h" | 57 #include "public/platform/WebTraceLocation.h" |
| 57 #include "v8/include/v8.h" | 58 #include "v8/include/v8.h" |
| 58 | 59 |
| 59 namespace blink { | 60 namespace blink { |
| 60 | 61 |
| 61 static inline ImageBitmapSource* toImageBitmapSourceInternal( | 62 static inline ImageBitmapSource* toImageBitmapSourceInternal( |
| 62 const ImageBitmapSourceUnion& value, | 63 const ImageBitmapSourceUnion& value, |
| 63 ExceptionState& exceptionState, | 64 ExceptionState* exceptionState, |
|
fs
2017/04/06 20:27:54
Was this required by anything now?
fserb
2017/04/06 21:03:49
It isn't. Lint was complaining that it should be e
fs
2017/04/06 21:11:27
What Lint was that? (ExceptionState& is pretty muc
fserb
2017/04/07 18:36:28
done.
| |
| 64 const ImageBitmapOptions& options, | 65 const ImageBitmapOptions& options, |
| 65 bool hasCropRect) { | 66 bool hasCropRect) { |
| 67 HTMLAndSVGImageElementSource* imageElement = nullptr; | |
| 66 if (value.isHTMLImageElement()) { | 68 if (value.isHTMLImageElement()) { |
| 67 HTMLImageElement* imageElement = value.getAsHTMLImageElement(); | 69 if (!(imageElement = value.getAsHTMLImageElement())) |
| 68 if (!imageElement || !imageElement->cachedImage()) { | 70 return nullptr; |
| 69 exceptionState.throwDOMException( | 71 } else if (value.isSVGImageElement()) { |
| 72 if (!(imageElement = value.getAsSVGImageElement())) | |
| 73 return nullptr; | |
| 74 } | |
| 75 if (imageElement) { | |
| 76 if (!imageElement->cachedImage()) { | |
| 77 exceptionState->throwDOMException( | |
| 70 InvalidStateError, | 78 InvalidStateError, |
| 71 "No image can be retrieved from the provided element."); | 79 "No image can be retrieved from the provided element."); |
| 72 return nullptr; | 80 return nullptr; |
| 73 } | 81 } |
| 74 if (imageElement->cachedImage()->getImage()->isSVGImage()) { | 82 if (imageElement->cachedImage()->getImage()->isSVGImage()) { |
| 75 SVGImage* image = toSVGImage(imageElement->cachedImage()->getImage()); | 83 SVGImage* image = toSVGImage(imageElement->cachedImage()->getImage()); |
| 76 if (!image->hasIntrinsicDimensions() && | 84 if (!image->hasIntrinsicDimensions() && |
| 77 (!hasCropRect && | 85 (!hasCropRect && |
| 78 (!options.hasResizeWidth() || !options.hasResizeHeight()))) { | 86 (!options.hasResizeWidth() || !options.hasResizeHeight()))) { |
| 79 exceptionState.throwDOMException( | 87 exceptionState->throwDOMException( |
| 80 InvalidStateError, | 88 InvalidStateError, |
| 81 "The image element contains an SVG image without intrinsic " | 89 "The image element contains an SVG image without intrinsic " |
| 82 "dimensions, and no resize options or crop region are specified."); | 90 "dimensions, and no resize options or crop region are specified."); |
| 83 return nullptr; | 91 return nullptr; |
| 84 } | 92 } |
| 85 } | 93 } |
| 86 return imageElement; | 94 return imageElement; |
| 87 } | 95 } |
| 88 if (value.isHTMLVideoElement()) | 96 if (value.isHTMLVideoElement()) |
| 89 return value.getAsHTMLVideoElement(); | 97 return value.getAsHTMLVideoElement(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 } | 132 } |
| 125 | 133 |
| 126 ScriptPromise ImageBitmapFactories::createImageBitmap( | 134 ScriptPromise ImageBitmapFactories::createImageBitmap( |
| 127 ScriptState* scriptState, | 135 ScriptState* scriptState, |
| 128 EventTarget& eventTarget, | 136 EventTarget& eventTarget, |
| 129 const ImageBitmapSourceUnion& bitmapSource, | 137 const ImageBitmapSourceUnion& bitmapSource, |
| 130 const ImageBitmapOptions& options, | 138 const ImageBitmapOptions& options, |
| 131 ExceptionState& exceptionState) { | 139 ExceptionState& exceptionState) { |
| 132 UseCounter::Feature feature = UseCounter::CreateImageBitmap; | 140 UseCounter::Feature feature = UseCounter::CreateImageBitmap; |
| 133 UseCounter::count(scriptState->getExecutionContext(), feature); | 141 UseCounter::count(scriptState->getExecutionContext(), feature); |
| 134 ImageBitmapSource* bitmapSourceInternal = | 142 ImageBitmapSource* bitmapSourceInternal = toImageBitmapSourceInternal( |
| 135 toImageBitmapSourceInternal(bitmapSource, exceptionState, options, false); | 143 bitmapSource, &exceptionState, options, false); |
| 136 if (!bitmapSourceInternal) | 144 if (!bitmapSourceInternal) |
| 137 return ScriptPromise(); | 145 return ScriptPromise(); |
| 138 return createImageBitmap(scriptState, eventTarget, bitmapSourceInternal, | 146 return createImageBitmap(scriptState, eventTarget, bitmapSourceInternal, |
| 139 Optional<IntRect>(), options, exceptionState); | 147 Optional<IntRect>(), options, exceptionState); |
| 140 } | 148 } |
| 141 | 149 |
| 142 ScriptPromise ImageBitmapFactories::createImageBitmap( | 150 ScriptPromise ImageBitmapFactories::createImageBitmap( |
| 143 ScriptState* scriptState, | 151 ScriptState* scriptState, |
| 144 EventTarget& eventTarget, | 152 EventTarget& eventTarget, |
| 145 const ImageBitmapSourceUnion& bitmapSource, | 153 const ImageBitmapSourceUnion& bitmapSource, |
| 146 int sx, | 154 int sx, |
| 147 int sy, | 155 int sy, |
| 148 int sw, | 156 int sw, |
| 149 int sh, | 157 int sh, |
| 150 const ImageBitmapOptions& options, | 158 const ImageBitmapOptions& options, |
| 151 ExceptionState& exceptionState) { | 159 ExceptionState& exceptionState) { |
| 152 UseCounter::Feature feature = UseCounter::CreateImageBitmap; | 160 UseCounter::Feature feature = UseCounter::CreateImageBitmap; |
| 153 UseCounter::count(scriptState->getExecutionContext(), feature); | 161 UseCounter::count(scriptState->getExecutionContext(), feature); |
| 154 ImageBitmapSource* bitmapSourceInternal = | 162 ImageBitmapSource* bitmapSourceInternal = |
| 155 toImageBitmapSourceInternal(bitmapSource, exceptionState, options, true); | 163 toImageBitmapSourceInternal(bitmapSource, &exceptionState, options, true); |
| 156 if (!bitmapSourceInternal) | 164 if (!bitmapSourceInternal) |
| 157 return ScriptPromise(); | 165 return ScriptPromise(); |
| 158 Optional<IntRect> cropRect = IntRect(sx, sy, sw, sh); | 166 Optional<IntRect> cropRect = IntRect(sx, sy, sw, sh); |
| 159 return createImageBitmap(scriptState, eventTarget, bitmapSourceInternal, | 167 return createImageBitmap(scriptState, eventTarget, bitmapSourceInternal, |
| 160 cropRect, options, exceptionState); | 168 cropRect, options, exceptionState); |
| 161 } | 169 } |
| 162 | 170 |
| 163 ScriptPromise ImageBitmapFactories::createImageBitmap( | 171 ScriptPromise ImageBitmapFactories::createImageBitmap( |
| 164 ScriptState* scriptState, | 172 ScriptState* scriptState, |
| 165 EventTarget& eventTarget, | 173 EventTarget& eventTarget, |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 313 } | 321 } |
| 314 m_factory->didFinishLoading(this); | 322 m_factory->didFinishLoading(this); |
| 315 } | 323 } |
| 316 | 324 |
| 317 DEFINE_TRACE(ImageBitmapFactories::ImageBitmapLoader) { | 325 DEFINE_TRACE(ImageBitmapFactories::ImageBitmapLoader) { |
| 318 visitor->trace(m_factory); | 326 visitor->trace(m_factory); |
| 319 visitor->trace(m_resolver); | 327 visitor->trace(m_resolver); |
| 320 } | 328 } |
| 321 | 329 |
| 322 } // namespace blink | 330 } // namespace blink |
| OLD | NEW |