| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 | 93 |
| 94 return new ImageData(IntSize(width, height), byteArray); | 94 return new ImageData(IntSize(width, height), byteArray); |
| 95 } | 95 } |
| 96 | 96 |
| 97 bool ImageData::validateConstructorArguments(DOMUint8ClampedArray* data, unsigne
d width, unsigned& lengthInPixels, ExceptionState& exceptionState) | 97 bool ImageData::validateConstructorArguments(DOMUint8ClampedArray* data, unsigne
d width, unsigned& lengthInPixels, ExceptionState& exceptionState) |
| 98 { | 98 { |
| 99 if (!width) { | 99 if (!width) { |
| 100 exceptionState.throwDOMException(IndexSizeError, "The source width is ze
ro or not a number."); | 100 exceptionState.throwDOMException(IndexSizeError, "The source width is ze
ro or not a number."); |
| 101 return false; | 101 return false; |
| 102 } | 102 } |
| 103 ASSERT(data); | 103 DCHECK(data); |
| 104 unsigned length = data->length(); | 104 unsigned length = data->length(); |
| 105 if (!length) { | 105 if (!length) { |
| 106 exceptionState.throwDOMException(IndexSizeError, "The input data has a z
ero byte length."); | 106 exceptionState.throwDOMException(IndexSizeError, "The input data has a z
ero byte length."); |
| 107 return false; | 107 return false; |
| 108 } | 108 } |
| 109 if (length % 4) { | 109 if (length % 4) { |
| 110 exceptionState.throwDOMException(IndexSizeError, "The input data byte le
ngth is not a multiple of 4."); | 110 exceptionState.throwDOMException(IndexSizeError, "The input data byte le
ngth is not a multiple of 4."); |
| 111 return false; | 111 return false; |
| 112 } | 112 } |
| 113 length /= 4; | 113 length /= 4; |
| 114 if (length % width) { | 114 if (length % width) { |
| 115 exceptionState.throwDOMException(IndexSizeError, "The input data byte le
ngth is not a multiple of (4 * width)."); | 115 exceptionState.throwDOMException(IndexSizeError, "The input data byte le
ngth is not a multiple of (4 * width)."); |
| 116 return false; | 116 return false; |
| 117 } | 117 } |
| 118 lengthInPixels = length; | 118 lengthInPixels = length; |
| 119 return true; | 119 return true; |
| 120 } | 120 } |
| 121 | 121 |
| 122 ImageData* ImageData::create(DOMUint8ClampedArray* data, unsigned width, Excepti
onState& exceptionState) | 122 ImageData* ImageData::create(DOMUint8ClampedArray* data, unsigned width, Excepti
onState& exceptionState) |
| 123 { | 123 { |
| 124 unsigned lengthInPixels = 0; | 124 unsigned lengthInPixels = 0; |
| 125 if (!validateConstructorArguments(data, width, lengthInPixels, exceptionStat
e)) { | 125 if (!validateConstructorArguments(data, width, lengthInPixels, exceptionStat
e)) { |
| 126 ASSERT(exceptionState.hadException()); | 126 DCHECK(exceptionState.hadException()); |
| 127 return nullptr; | 127 return nullptr; |
| 128 } | 128 } |
| 129 ASSERT(lengthInPixels && width); | 129 DCHECK_GT(lengthInPixels, 0u); |
| 130 DCHECK_GT(width, 0u); |
| 130 unsigned height = lengthInPixels / width; | 131 unsigned height = lengthInPixels / width; |
| 131 return new ImageData(IntSize(width, height), data); | 132 return new ImageData(IntSize(width, height), data); |
| 132 } | 133 } |
| 133 | 134 |
| 134 ImageData* ImageData::create(DOMUint8ClampedArray* data, unsigned width, unsigne
d height, ExceptionState& exceptionState) | 135 ImageData* ImageData::create(DOMUint8ClampedArray* data, unsigned width, unsigne
d height, ExceptionState& exceptionState) |
| 135 { | 136 { |
| 136 unsigned lengthInPixels = 0; | 137 unsigned lengthInPixels = 0; |
| 137 if (!validateConstructorArguments(data, width, lengthInPixels, exceptionStat
e)) { | 138 if (!validateConstructorArguments(data, width, lengthInPixels, exceptionStat
e)) { |
| 138 ASSERT(exceptionState.hadException()); | 139 DCHECK(exceptionState.hadException()); |
| 139 return nullptr; | 140 return nullptr; |
| 140 } | 141 } |
| 141 ASSERT(lengthInPixels && width); | 142 DCHECK_GT(lengthInPixels, 0u); |
| 143 DCHECK_GT(width, 0u); |
| 142 if (height != lengthInPixels / width) { | 144 if (height != lengthInPixels / width) { |
| 143 exceptionState.throwDOMException(IndexSizeError, "The input data byte le
ngth is not equal to (4 * width * height)."); | 145 exceptionState.throwDOMException(IndexSizeError, "The input data byte le
ngth is not equal to (4 * width * height)."); |
| 144 return nullptr; | 146 return nullptr; |
| 145 } | 147 } |
| 146 return new ImageData(IntSize(width, height), data); | 148 return new ImageData(IntSize(width, height), data); |
| 147 } | 149 } |
| 148 | 150 |
| 149 ScriptPromise ImageData::createImageBitmap(ScriptState* scriptState, EventTarget
& eventTarget, Optional<IntRect> cropRect, const ImageBitmapOptions& options, Ex
ceptionState& exceptionState) | 151 ScriptPromise ImageData::createImageBitmap(ScriptState* scriptState, EventTarget
& eventTarget, Optional<IntRect> cropRect, const ImageBitmapOptions& options, Ex
ceptionState& exceptionState) |
| 150 { | 152 { |
| 151 if ((cropRect && !ImageBitmap::isSourceSizeValid(cropRect->width(), cropRect
->height(), exceptionState)) | 153 if ((cropRect && !ImageBitmap::isSourceSizeValid(cropRect->width(), cropRect
->height(), exceptionState)) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 172 if (pixelArray.IsEmpty() || !v8CallBoolean(wrapper->DefineOwnProperty(is
olate->GetCurrentContext(), v8AtomicString(isolate, "data"), pixelArray, v8::Rea
dOnly))) | 174 if (pixelArray.IsEmpty() || !v8CallBoolean(wrapper->DefineOwnProperty(is
olate->GetCurrentContext(), v8AtomicString(isolate, "data"), pixelArray, v8::Rea
dOnly))) |
| 173 return v8::Local<v8::Object>(); | 175 return v8::Local<v8::Object>(); |
| 174 } | 176 } |
| 175 return wrapper; | 177 return wrapper; |
| 176 } | 178 } |
| 177 | 179 |
| 178 ImageData::ImageData(const IntSize& size, DOMUint8ClampedArray* byteArray) | 180 ImageData::ImageData(const IntSize& size, DOMUint8ClampedArray* byteArray) |
| 179 : m_size(size) | 181 : m_size(size) |
| 180 , m_data(byteArray) | 182 , m_data(byteArray) |
| 181 { | 183 { |
| 182 ASSERT(size.width() >= 0 && size.height() >= 0); | 184 DCHECK_GE(size.width(), 0); |
| 183 ASSERT_WITH_SECURITY_IMPLICATION(static_cast<unsigned>(size.width() * size.h
eight() * 4) <= m_data->length()); | 185 DCHECK_GE(size.height(), 0); |
| 186 SECURITY_CHECK(static_cast<unsigned>(size.width() * size.height() * 4) <= m_
data->length()); |
| 184 } | 187 } |
| 185 | 188 |
| 186 } // namespace blink | 189 } // namespace blink |
| OLD | NEW |