| 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 ASSERT(lengthInPixels && width); | 141 ASSERT(lengthInPixels && width); |
| 142 if (height != lengthInPixels / width) { | 142 if (height != lengthInPixels / width) { |
| 143 exceptionState.throwDOMException(IndexSizeError, "The input data byte le
ngth is not equal to (4 * width * height)."); | 143 exceptionState.throwDOMException(IndexSizeError, "The input data byte le
ngth is not equal to (4 * width * height)."); |
| 144 return nullptr; | 144 return nullptr; |
| 145 } | 145 } |
| 146 return new ImageData(IntSize(width, height), data); | 146 return new ImageData(IntSize(width, height), data); |
| 147 } | 147 } |
| 148 | 148 |
| 149 ScriptPromise ImageData::createImageBitmap(ScriptState* scriptState, EventTarget
& eventTarget, int sx, int sy, int sw, int sh, const ImageBitmapOptions& options
, ExceptionState& exceptionState) | 149 ScriptPromise ImageData::createImageBitmap(ScriptState* scriptState, EventTarget
& eventTarget, int sx, int sy, int sw, int sh, const ImageBitmapOptions& options
, ExceptionState& exceptionState) |
| 150 { | 150 { |
| 151 if (!sw || !sh) { | 151 if (!ImageBitmap::isSWSHValid(sw, sh, exceptionState)) |
| 152 exceptionState.throwDOMException(IndexSizeError, String::format("The sou
rce %s provided is 0.", sw ? "height" : "width")); | |
| 153 return ScriptPromise(); | 152 return ScriptPromise(); |
| 154 } | |
| 155 if (data()->bufferBase()->isNeutered()) { | 153 if (data()->bufferBase()->isNeutered()) { |
| 156 exceptionState.throwDOMException(InvalidStateError, "The source data has
been neutered."); | 154 exceptionState.throwDOMException(InvalidStateError, "The source data has
been neutered."); |
| 157 return ScriptPromise(); | 155 return ScriptPromise(); |
| 158 } | 156 } |
| 157 if (!ImageBitmap::isResizeOptionValid(options, exceptionState)) |
| 158 return ScriptPromise(); |
| 159 return ImageBitmapSource::fulfillImageBitmap(scriptState, ImageBitmap::creat
e(this, IntRect(sx, sy, sw, sh), options)); | 159 return ImageBitmapSource::fulfillImageBitmap(scriptState, ImageBitmap::creat
e(this, IntRect(sx, sy, sw, sh), options)); |
| 160 } | 160 } |
| 161 | 161 |
| 162 v8::Local<v8::Object> ImageData::associateWithWrapper(v8::Isolate* isolate, cons
t WrapperTypeInfo* wrapperType, v8::Local<v8::Object> wrapper) | 162 v8::Local<v8::Object> ImageData::associateWithWrapper(v8::Isolate* isolate, cons
t WrapperTypeInfo* wrapperType, v8::Local<v8::Object> wrapper) |
| 163 { | 163 { |
| 164 wrapper = ScriptWrappable::associateWithWrapper(isolate, wrapperType, wrappe
r); | 164 wrapper = ScriptWrappable::associateWithWrapper(isolate, wrapperType, wrappe
r); |
| 165 | 165 |
| 166 if (!wrapper.IsEmpty() && m_data.get()) { | 166 if (!wrapper.IsEmpty() && m_data.get()) { |
| 167 // Create a V8 Uint8ClampedArray object and set the "data" property | 167 // Create a V8 Uint8ClampedArray object and set the "data" property |
| 168 // of the ImageData object to the created v8 object, eliminating the | 168 // of the ImageData object to the created v8 object, eliminating the |
| 169 // C++ callback when accessing the "data" property. | 169 // C++ callback when accessing the "data" property. |
| 170 v8::Local<v8::Value> pixelArray = toV8(m_data.get(), wrapper, isolate); | 170 v8::Local<v8::Value> pixelArray = toV8(m_data.get(), wrapper, isolate); |
| 171 if (pixelArray.IsEmpty() || !v8CallBoolean(wrapper->DefineOwnProperty(is
olate->GetCurrentContext(), v8AtomicString(isolate, "data"), pixelArray, v8::Rea
dOnly))) | 171 if (pixelArray.IsEmpty() || !v8CallBoolean(wrapper->DefineOwnProperty(is
olate->GetCurrentContext(), v8AtomicString(isolate, "data"), pixelArray, v8::Rea
dOnly))) |
| 172 return v8::Local<v8::Object>(); | 172 return v8::Local<v8::Object>(); |
| 173 } | 173 } |
| 174 return wrapper; | 174 return wrapper; |
| 175 } | 175 } |
| 176 | 176 |
| 177 ImageData::ImageData(const IntSize& size, DOMUint8ClampedArray* byteArray) | 177 ImageData::ImageData(const IntSize& size, DOMUint8ClampedArray* byteArray) |
| 178 : m_size(size) | 178 : m_size(size) |
| 179 , m_data(byteArray) | 179 , m_data(byteArray) |
| 180 { | 180 { |
| 181 ASSERT(size.width() >= 0 && size.height() >= 0); | 181 ASSERT(size.width() >= 0 && size.height() >= 0); |
| 182 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()); |
| 183 } | 183 } |
| 184 | 184 |
| 185 } // namespace blink | 185 } // namespace blink |
| OLD | NEW |