| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008 Apple 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #include "config.h" | 29 #include "config.h" |
| 30 #include "core/html/ImageData.h" | 30 #include "core/html/ImageData.h" |
| 31 | 31 |
| 32 #include "bindings/core/v8/ExceptionState.h" | 32 #include "bindings/core/v8/ExceptionState.h" |
| 33 #include "bindings/core/v8/V8Uint8ClampedArray.h" | 33 #include "bindings/core/v8/V8Uint8ClampedArray.h" |
| 34 #include "core/dom/ExceptionCode.h" | 34 #include "core/dom/ExceptionCode.h" |
| 35 #include "core/frame/ImageBitmap.h" |
| 35 #include "platform/RuntimeEnabledFeatures.h" | 36 #include "platform/RuntimeEnabledFeatures.h" |
| 36 | 37 |
| 37 namespace blink { | 38 namespace blink { |
| 38 | 39 |
| 39 ImageData* ImageData::create(const IntSize& size) | 40 ImageData* ImageData::create(const IntSize& size) |
| 40 { | 41 { |
| 41 Checked<int, RecordOverflow> dataSize = 4; | 42 Checked<int, RecordOverflow> dataSize = 4; |
| 42 dataSize *= size.width(); | 43 dataSize *= size.width(); |
| 43 dataSize *= size.height(); | 44 dataSize *= size.height(); |
| 44 if (dataSize.hasOverflowed() || dataSize.unsafeGet() < 0) | 45 if (dataSize.hasOverflowed() || dataSize.unsafeGet() < 0) |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 return nullptr; | 140 return nullptr; |
| 140 } | 141 } |
| 141 ASSERT(lengthInPixels && width); | 142 ASSERT(lengthInPixels && width); |
| 142 if (height != lengthInPixels / width) { | 143 if (height != lengthInPixels / width) { |
| 143 exceptionState.throwDOMException(IndexSizeError, "The input data byte le
ngth is not equal to (4 * width * height)."); | 144 exceptionState.throwDOMException(IndexSizeError, "The input data byte le
ngth is not equal to (4 * width * height)."); |
| 144 return nullptr; | 145 return nullptr; |
| 145 } | 146 } |
| 146 return new ImageData(IntSize(width, height), data); | 147 return new ImageData(IntSize(width, height), data); |
| 147 } | 148 } |
| 148 | 149 |
| 150 ScriptPromise ImageData::createImageBitmap(ScriptState* scriptState, EventTarget
& eventTarget, int sx, int sy, int sw, int sh, ExceptionState& exceptionState) |
| 151 { |
| 152 if (!sw || !sh) { |
| 153 exceptionState.throwDOMException(IndexSizeError, String::format("The sou
rce %s provided is 0.", sw ? "height" : "width")); |
| 154 return ScriptPromise(); |
| 155 } |
| 156 if (data()->bufferBase()->isNeutered()) { |
| 157 exceptionState.throwDOMException(InvalidStateError, "The source data has
been neutered."); |
| 158 return ScriptPromise(); |
| 159 } |
| 160 return ImageBitmapSource::fulfillImageBitmap(scriptState, ImageBitmap::creat
e(this, IntRect(sx, sy, sw, sh))); |
| 161 } |
| 162 |
| 149 v8::Local<v8::Object> ImageData::associateWithWrapper(v8::Isolate* isolate, cons
t WrapperTypeInfo* wrapperType, v8::Local<v8::Object> wrapper) | 163 v8::Local<v8::Object> ImageData::associateWithWrapper(v8::Isolate* isolate, cons
t WrapperTypeInfo* wrapperType, v8::Local<v8::Object> wrapper) |
| 150 { | 164 { |
| 151 wrapper = ScriptWrappable::associateWithWrapper(isolate, wrapperType, wrappe
r); | 165 wrapper = ScriptWrappable::associateWithWrapper(isolate, wrapperType, wrappe
r); |
| 152 | 166 |
| 153 if (!wrapper.IsEmpty() && m_data.get()) { | 167 if (!wrapper.IsEmpty() && m_data.get()) { |
| 154 // Create a V8 Uint8ClampedArray object and set the "data" property | 168 // Create a V8 Uint8ClampedArray object and set the "data" property |
| 155 // of the ImageData object to the created v8 object, eliminating the | 169 // of the ImageData object to the created v8 object, eliminating the |
| 156 // C++ callback when accessing the "data" property. | 170 // C++ callback when accessing the "data" property. |
| 157 v8::Local<v8::Value> pixelArray = toV8(m_data.get(), wrapper, isolate); | 171 v8::Local<v8::Value> pixelArray = toV8(m_data.get(), wrapper, isolate); |
| 158 if (pixelArray.IsEmpty() || !v8CallBoolean(wrapper->DefineOwnProperty(is
olate->GetCurrentContext(), v8AtomicString(isolate, "data"), pixelArray, v8::Rea
dOnly))) | 172 if (pixelArray.IsEmpty() || !v8CallBoolean(wrapper->DefineOwnProperty(is
olate->GetCurrentContext(), v8AtomicString(isolate, "data"), pixelArray, v8::Rea
dOnly))) |
| 159 return v8::Local<v8::Object>(); | 173 return v8::Local<v8::Object>(); |
| 160 } | 174 } |
| 161 return wrapper; | 175 return wrapper; |
| 162 } | 176 } |
| 163 | 177 |
| 164 ImageData::ImageData(const IntSize& size, PassRefPtr<DOMUint8ClampedArray> byteA
rray) | 178 ImageData::ImageData(const IntSize& size, PassRefPtr<DOMUint8ClampedArray> byteA
rray) |
| 165 : m_size(size) | 179 : m_size(size) |
| 166 , m_data(byteArray) | 180 , m_data(byteArray) |
| 167 { | 181 { |
| 168 ASSERT_WITH_SECURITY_IMPLICATION(static_cast<unsigned>(size.width() * size.h
eight() * 4) <= m_data->length()); | 182 ASSERT_WITH_SECURITY_IMPLICATION(static_cast<unsigned>(size.width() * size.h
eight() * 4) <= m_data->length()); |
| 169 } | 183 } |
| 170 | 184 |
| 171 void ImageData::dispose() | 185 void ImageData::dispose() |
| 172 { | 186 { |
| 173 m_data.clear(); | 187 m_data.clear(); |
| 174 } | 188 } |
| 175 | 189 |
| 176 } // namespace blink | 190 } // namespace blink |
| OLD | NEW |