Chromium Code Reviews| 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 12 matching lines...) Expand all Loading... | |
| 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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/custom/V8Uint8ClampedArrayCustom.h" | 33 #include "bindings/core/v8/V8Uint8ClampedArray.h" |
| 34 #include "core/dom/ExceptionCode.h" | 34 #include "core/dom/ExceptionCode.h" |
| 35 #include "platform/RuntimeEnabledFeatures.h" | 35 #include "platform/RuntimeEnabledFeatures.h" |
| 36 | 36 |
| 37 namespace blink { | 37 namespace blink { |
| 38 | 38 |
| 39 PassRefPtrWillBeRawPtr<ImageData> ImageData::create(const IntSize& size) | 39 PassRefPtrWillBeRawPtr<ImageData> ImageData::create(const IntSize& size) |
| 40 { | 40 { |
| 41 Checked<int, RecordOverflow> dataSize = 4; | 41 Checked<int, RecordOverflow> dataSize = 4; |
| 42 dataSize *= size.width(); | 42 dataSize *= size.width(); |
| 43 dataSize *= size.height(); | 43 dataSize *= size.height(); |
| 44 if (dataSize.hasOverflowed()) | 44 if (dataSize.hasOverflowed()) |
| 45 return nullptr; | 45 return nullptr; |
| 46 | 46 |
| 47 return adoptRefWillBeNoop(new ImageData(size)); | 47 return adoptRefWillBeNoop(new ImageData(size)); |
| 48 } | 48 } |
| 49 | 49 |
| 50 PassRefPtrWillBeRawPtr<ImageData> ImageData::create(const IntSize& size, PassRef Ptr<Uint8ClampedArray> byteArray) | 50 PassRefPtrWillBeRawPtr<ImageData> ImageData::create(const IntSize& size, PassRef Ptr<Uint8ClampedArray> byteArray) |
| 51 { | 51 { |
| 52 Checked<int, RecordOverflow> dataSize = 4; | 52 Checked<int, RecordOverflow> dataSize = 4; |
| 53 dataSize *= size.width(); | 53 dataSize *= size.width(); |
| 54 dataSize *= size.height(); | 54 dataSize *= size.height(); |
| 55 if (dataSize.hasOverflowed()) | 55 if (dataSize.hasOverflowed()) |
| 56 return nullptr; | 56 return nullptr; |
| 57 | 57 |
| 58 if (dataSize.unsafeGet() < 0 | 58 if (dataSize.unsafeGet() < 0 |
| 59 || static_cast<unsigned>(dataSize.unsafeGet()) > byteArray->length()) | 59 || static_cast<unsigned>(dataSize.unsafeGet()) > byteArray->length()) |
| 60 return nullptr; | 60 return nullptr; |
| 61 | 61 |
| 62 return adoptRefWillBeNoop(new ImageData(size, byteArray)); | 62 return adoptRefWillBeNoop(new ImageData(size, DOMUint8ClampedArray::create(b yteArray))); |
|
haraken
2014/10/14 15:11:19
I have the same question as before :)
I want to u
| |
| 63 } | 63 } |
| 64 | 64 |
| 65 PassRefPtrWillBeRawPtr<ImageData> ImageData::create(unsigned width, unsigned hei ght, ExceptionState& exceptionState) | 65 PassRefPtrWillBeRawPtr<ImageData> ImageData::create(unsigned width, unsigned hei ght, ExceptionState& exceptionState) |
| 66 { | 66 { |
| 67 if (!RuntimeEnabledFeatures::imageDataConstructorEnabled()) { | 67 if (!RuntimeEnabledFeatures::imageDataConstructorEnabled()) { |
| 68 exceptionState.throwTypeError("Illegal constructor"); | 68 exceptionState.throwTypeError("Illegal constructor"); |
| 69 return nullptr; | 69 return nullptr; |
| 70 } | 70 } |
| 71 if (!width || !height) { | 71 if (!width || !height) { |
| 72 exceptionState.throwDOMException(IndexSizeError, String::format("The sou rce %s is zero or not a number.", width ? "height" : "width")); | 72 exceptionState.throwDOMException(IndexSizeError, String::format("The sou rce %s is zero or not a number.", width ? "height" : "width")); |
| 73 return nullptr; | 73 return nullptr; |
| 74 } | 74 } |
| 75 | 75 |
| 76 Checked<unsigned, RecordOverflow> dataSize = 4; | 76 Checked<unsigned, RecordOverflow> dataSize = 4; |
| 77 dataSize *= width; | 77 dataSize *= width; |
| 78 dataSize *= height; | 78 dataSize *= height; |
| 79 if (dataSize.hasOverflowed()) { | 79 if (dataSize.hasOverflowed()) { |
| 80 exceptionState.throwDOMException(IndexSizeError, "The requested image si ze exceeds the supported range."); | 80 exceptionState.throwDOMException(IndexSizeError, "The requested image si ze exceeds the supported range."); |
| 81 return nullptr; | 81 return nullptr; |
| 82 } | 82 } |
| 83 | 83 |
| 84 RefPtrWillBeRawPtr<ImageData> imageData = adoptRefWillBeNoop(new ImageData(I ntSize(width, height))); | 84 RefPtrWillBeRawPtr<ImageData> imageData = adoptRefWillBeNoop(new ImageData(I ntSize(width, height))); |
| 85 imageData->data()->zeroFill(); | 85 imageData->data()->zeroFill(); |
| 86 return imageData.release(); | 86 return imageData.release(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 PassRefPtrWillBeRawPtr<ImageData> ImageData::create(Uint8ClampedArray* data, uns igned width, unsigned height, ExceptionState& exceptionState) | 89 PassRefPtrWillBeRawPtr<ImageData> ImageData::create(DOMUint8ClampedArray* data, unsigned width, unsigned height, ExceptionState& exceptionState) |
| 90 { | 90 { |
| 91 if (!RuntimeEnabledFeatures::imageDataConstructorEnabled()) { | 91 if (!RuntimeEnabledFeatures::imageDataConstructorEnabled()) { |
| 92 exceptionState.throwTypeError("Illegal constructor"); | 92 exceptionState.throwTypeError("Illegal constructor"); |
| 93 return nullptr; | 93 return nullptr; |
| 94 } | 94 } |
| 95 if (!data) { | 95 if (!data) { |
| 96 exceptionState.throwTypeError("Expected a Uint8ClampedArray as first arg ument."); | 96 exceptionState.throwTypeError("Expected a Uint8ClampedArray as first arg ument."); |
| 97 return nullptr; | 97 return nullptr; |
| 98 } | 98 } |
| 99 if (!width) { | 99 if (!width) { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 124 | 124 |
| 125 return adoptRefWillBeNoop(new ImageData(IntSize(width, height), data)); | 125 return adoptRefWillBeNoop(new ImageData(IntSize(width, height), data)); |
| 126 } | 126 } |
| 127 | 127 |
| 128 v8::Handle<v8::Object> ImageData::associateWithWrapper(const WrapperTypeInfo* wr apperType, v8::Handle<v8::Object> wrapper, v8::Isolate* isolate) | 128 v8::Handle<v8::Object> ImageData::associateWithWrapper(const WrapperTypeInfo* wr apperType, v8::Handle<v8::Object> wrapper, v8::Isolate* isolate) |
| 129 { | 129 { |
| 130 ScriptWrappable::associateWithWrapper(wrapperType, wrapper, isolate); | 130 ScriptWrappable::associateWithWrapper(wrapperType, wrapper, isolate); |
| 131 | 131 |
| 132 if (!wrapper.IsEmpty()) { | 132 if (!wrapper.IsEmpty()) { |
| 133 // Create a V8 Uint8ClampedArray object. | 133 // Create a V8 Uint8ClampedArray object. |
| 134 v8::Handle<v8::Value> pixelArray = toV8(data(), wrapper, isolate); | 134 v8::Handle<v8::Value> pixelArray = toV8(m_data.get(), wrapper, isolate); |
| 135 // Set the "data" property of the ImageData object to | 135 // Set the "data" property of the ImageData object to |
| 136 // the created v8 object, eliminating the C++ callback | 136 // the created v8 object, eliminating the C++ callback |
| 137 // when accessing the "data" property. | 137 // when accessing the "data" property. |
| 138 if (!pixelArray.IsEmpty()) | 138 if (!pixelArray.IsEmpty()) |
| 139 wrapper->ForceSet(v8AtomicString(isolate, "data"), pixelArray, v8::R eadOnly); | 139 wrapper->ForceSet(v8AtomicString(isolate, "data"), pixelArray, v8::R eadOnly); |
| 140 } | 140 } |
| 141 return wrapper; | 141 return wrapper; |
| 142 } | 142 } |
| 143 | 143 |
| 144 ImageData::ImageData(const IntSize& size) | 144 ImageData::ImageData(const IntSize& size) |
| 145 : m_size(size) | 145 : m_size(size) |
| 146 , m_data(Uint8ClampedArray::create(size.width() * size.height() * 4)) | 146 , m_data(DOMUint8ClampedArray::create(size.width() * size.height() * 4)) |
| 147 { | 147 { |
| 148 } | 148 } |
| 149 | 149 |
| 150 ImageData::ImageData(const IntSize& size, PassRefPtr<Uint8ClampedArray> byteArra y) | 150 ImageData::ImageData(const IntSize& size, PassRefPtr<DOMUint8ClampedArray> byteA rray) |
| 151 : m_size(size) | 151 : m_size(size) |
| 152 , m_data(byteArray) | 152 , m_data(byteArray) |
| 153 { | 153 { |
| 154 ASSERT_WITH_SECURITY_IMPLICATION(static_cast<unsigned>(size.width() * size.h eight() * 4) <= m_data->length()); | 154 ASSERT_WITH_SECURITY_IMPLICATION(static_cast<unsigned>(size.width() * size.h eight() * 4) <= m_data->length()); |
| 155 } | 155 } |
| 156 | 156 |
| 157 } // namespace blink | 157 } // namespace blink |
| OLD | NEW |