| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 return adoptRefWillBeNoop(new ImageData(IntSize(width, height))); | 84 return adoptRefWillBeNoop(new ImageData(IntSize(width, height))); |
| 85 } | 85 } |
| 86 | 86 |
| 87 bool ImageData::validateConstructorArguments(DOMUint8ClampedArray* data, unsigne
d width, unsigned& lengthInPixels, ExceptionState& exceptionState) |
| 88 { |
| 89 if (!width) { |
| 90 exceptionState.throwDOMException(IndexSizeError, "The source width is ze
ro or not a number."); |
| 91 return false; |
| 92 } |
| 93 ASSERT(data); |
| 94 unsigned length = data->length(); |
| 95 if (!length) { |
| 96 exceptionState.throwDOMException(IndexSizeError, "The input data has a z
ero byte length."); |
| 97 return false; |
| 98 } |
| 99 if (length % 4) { |
| 100 exceptionState.throwDOMException(IndexSizeError, "The input data byte le
ngth is not a multiple of 4."); |
| 101 return false; |
| 102 } |
| 103 length /= 4; |
| 104 if (length % width) { |
| 105 exceptionState.throwDOMException(IndexSizeError, "The input data byte le
ngth is not a multiple of (4 * width)."); |
| 106 return false; |
| 107 } |
| 108 lengthInPixels = length; |
| 109 return true; |
| 110 } |
| 111 |
| 112 PassRefPtrWillBeRawPtr<ImageData> ImageData::create(DOMUint8ClampedArray* data,
unsigned width, ExceptionState& exceptionState) |
| 113 { |
| 114 if (!RuntimeEnabledFeatures::imageDataConstructorEnabled()) { |
| 115 exceptionState.throwTypeError("Illegal constructor"); |
| 116 return nullptr; |
| 117 } |
| 118 unsigned lengthInPixels = 0; |
| 119 if (!validateConstructorArguments(data, width, lengthInPixels, exceptionStat
e)) { |
| 120 ASSERT(exceptionState.hadException()); |
| 121 return nullptr; |
| 122 } |
| 123 ASSERT(lengthInPixels && width); |
| 124 unsigned height = lengthInPixels / width; |
| 125 return adoptRefWillBeNoop(new ImageData(IntSize(width, height), data)); |
| 126 } |
| 127 |
| 87 PassRefPtrWillBeRawPtr<ImageData> ImageData::create(DOMUint8ClampedArray* data,
unsigned width, unsigned height, ExceptionState& exceptionState) | 128 PassRefPtrWillBeRawPtr<ImageData> ImageData::create(DOMUint8ClampedArray* data,
unsigned width, unsigned height, ExceptionState& exceptionState) |
| 88 { | 129 { |
| 89 if (!RuntimeEnabledFeatures::imageDataConstructorEnabled()) { | 130 if (!RuntimeEnabledFeatures::imageDataConstructorEnabled()) { |
| 90 exceptionState.throwTypeError("Illegal constructor"); | 131 exceptionState.throwTypeError("Illegal constructor"); |
| 91 return nullptr; | 132 return nullptr; |
| 92 } | 133 } |
| 93 if (!data) { | 134 unsigned lengthInPixels = 0; |
| 94 exceptionState.throwTypeError("Expected a Uint8ClampedArray as first arg
ument."); | 135 if (!validateConstructorArguments(data, width, lengthInPixels, exceptionStat
e)) { |
| 136 ASSERT(exceptionState.hadException()); |
| 95 return nullptr; | 137 return nullptr; |
| 96 } | 138 } |
| 97 if (!width) { | 139 ASSERT(lengthInPixels && width); |
| 98 exceptionState.throwDOMException(IndexSizeError, "The source width is ze
ro or not a number."); | 140 if (height != lengthInPixels / width) { |
| 99 return nullptr; | |
| 100 } | |
| 101 | |
| 102 unsigned length = data->length(); | |
| 103 if (!length) { | |
| 104 exceptionState.throwDOMException(IndexSizeError, "The input data has a z
ero byte length."); | |
| 105 return nullptr; | |
| 106 } | |
| 107 if (length % 4) { | |
| 108 exceptionState.throwDOMException(IndexSizeError, "The input data byte le
ngth is not a multiple of 4."); | |
| 109 return nullptr; | |
| 110 } | |
| 111 length /= 4; | |
| 112 if (length % width) { | |
| 113 exceptionState.throwDOMException(IndexSizeError, "The input data byte le
ngth is not a multiple of (4 * width)."); | |
| 114 return nullptr; | |
| 115 } | |
| 116 if (!height) { | |
| 117 height = length / width; | |
| 118 } else if (height != length / width) { | |
| 119 exceptionState.throwDOMException(IndexSizeError, "The input data byte le
ngth is not equal to (4 * width * height)."); | 141 exceptionState.throwDOMException(IndexSizeError, "The input data byte le
ngth is not equal to (4 * width * height)."); |
| 120 return nullptr; | 142 return nullptr; |
| 121 } | 143 } |
| 122 | |
| 123 return adoptRefWillBeNoop(new ImageData(IntSize(width, height), data)); | 144 return adoptRefWillBeNoop(new ImageData(IntSize(width, height), data)); |
| 124 } | 145 } |
| 125 | 146 |
| 126 v8::Handle<v8::Object> ImageData::associateWithWrapper(v8::Isolate* isolate, con
st WrapperTypeInfo* wrapperType, v8::Handle<v8::Object> wrapper) | 147 v8::Handle<v8::Object> ImageData::associateWithWrapper(v8::Isolate* isolate, con
st WrapperTypeInfo* wrapperType, v8::Handle<v8::Object> wrapper) |
| 127 { | 148 { |
| 128 ScriptWrappable::associateWithWrapper(isolate, wrapperType, wrapper); | 149 ScriptWrappable::associateWithWrapper(isolate, wrapperType, wrapper); |
| 129 | 150 |
| 130 if (!wrapper.IsEmpty()) { | 151 if (!wrapper.IsEmpty()) { |
| 131 // Create a V8 Uint8ClampedArray object. | 152 // Create a V8 Uint8ClampedArray object. |
| 132 v8::Handle<v8::Value> pixelArray = toV8(m_data.get(), wrapper, isolate); | 153 v8::Handle<v8::Value> pixelArray = toV8(m_data.get(), wrapper, isolate); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 146 } | 167 } |
| 147 | 168 |
| 148 ImageData::ImageData(const IntSize& size, PassRefPtr<DOMUint8ClampedArray> byteA
rray) | 169 ImageData::ImageData(const IntSize& size, PassRefPtr<DOMUint8ClampedArray> byteA
rray) |
| 149 : m_size(size) | 170 : m_size(size) |
| 150 , m_data(byteArray) | 171 , m_data(byteArray) |
| 151 { | 172 { |
| 152 ASSERT_WITH_SECURITY_IMPLICATION(static_cast<unsigned>(size.width() * size.h
eight() * 4) <= m_data->length()); | 173 ASSERT_WITH_SECURITY_IMPLICATION(static_cast<unsigned>(size.width() * size.h
eight() * 4) <= m_data->length()); |
| 153 } | 174 } |
| 154 | 175 |
| 155 } // namespace blink | 176 } // namespace blink |
| OLD | NEW |