| 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 28 matching lines...) Expand all Loading... |
| 39 namespace blink { | 39 namespace blink { |
| 40 | 40 |
| 41 ImageData* ImageData::create(const IntSize& size) | 41 ImageData* ImageData::create(const IntSize& size) |
| 42 { | 42 { |
| 43 CheckedNumeric<int> dataSize = 4; | 43 CheckedNumeric<int> dataSize = 4; |
| 44 dataSize *= size.width(); | 44 dataSize *= size.width(); |
| 45 dataSize *= size.height(); | 45 dataSize *= size.height(); |
| 46 if (!dataSize.IsValid() || dataSize.ValueOrDie() < 0) | 46 if (!dataSize.IsValid() || dataSize.ValueOrDie() < 0) |
| 47 return nullptr; | 47 return nullptr; |
| 48 | 48 |
| 49 DOMUint8ClampedArray* byteArray = DOMUint8ClampedArray::createOrNull(dataSiz
e.ValueOrDie()); | 49 RefPtr<DOMUint8ClampedArray> byteArray = DOMUint8ClampedArray::createOrNull(
dataSize.ValueOrDie()); |
| 50 if (!byteArray) | 50 if (!byteArray) |
| 51 return nullptr; | 51 return nullptr; |
| 52 | 52 |
| 53 return new ImageData(size, byteArray); | 53 return new ImageData(size, byteArray.release()); |
| 54 } | 54 } |
| 55 | 55 |
| 56 ImageData* ImageData::create(const IntSize& size, DOMUint8ClampedArray* byteArra
y) | 56 ImageData* ImageData::create(const IntSize& size, PassRefPtr<DOMUint8ClampedArra
y> byteArray) |
| 57 { | 57 { |
| 58 CheckedNumeric<int> dataSize = 4; | 58 CheckedNumeric<int> dataSize = 4; |
| 59 dataSize *= size.width(); | 59 dataSize *= size.width(); |
| 60 dataSize *= size.height(); | 60 dataSize *= size.height(); |
| 61 if (!dataSize.IsValid()) | 61 if (!dataSize.IsValid()) |
| 62 return nullptr; | 62 return nullptr; |
| 63 | 63 |
| 64 if (dataSize.ValueOrDie() < 0 | 64 if (dataSize.ValueOrDie() < 0 |
| 65 || static_cast<unsigned>(dataSize.ValueOrDie()) > byteArray->length()) | 65 || static_cast<unsigned>(dataSize.ValueOrDie()) > byteArray->length()) |
| 66 return nullptr; | 66 return nullptr; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 78 CheckedNumeric<unsigned> dataSize = 4; | 78 CheckedNumeric<unsigned> dataSize = 4; |
| 79 dataSize *= width; | 79 dataSize *= width; |
| 80 dataSize *= height; | 80 dataSize *= height; |
| 81 if (!dataSize.IsValid() | 81 if (!dataSize.IsValid() |
| 82 || static_cast<int>(width) < 0 | 82 || static_cast<int>(width) < 0 |
| 83 || static_cast<int>(height) < 0) { | 83 || static_cast<int>(height) < 0) { |
| 84 exceptionState.throwDOMException(IndexSizeError, "The requested image si
ze exceeds the supported range."); | 84 exceptionState.throwDOMException(IndexSizeError, "The requested image si
ze exceeds the supported range."); |
| 85 return nullptr; | 85 return nullptr; |
| 86 } | 86 } |
| 87 | 87 |
| 88 DOMUint8ClampedArray* byteArray = DOMUint8ClampedArray::createOrNull(dataSiz
e.ValueOrDie()); | 88 RefPtr<DOMUint8ClampedArray> byteArray = DOMUint8ClampedArray::createOrNull(
dataSize.ValueOrDie()); |
| 89 if (!byteArray) { | 89 if (!byteArray) { |
| 90 exceptionState.throwDOMException(V8GeneralError, "Out of memory at Image
Data creation"); | 90 exceptionState.throwDOMException(V8GeneralError, "Out of memory at Image
Data creation"); |
| 91 return nullptr; | 91 return nullptr; |
| 92 } | 92 } |
| 93 | 93 |
| 94 return new ImageData(IntSize(width, height), byteArray); | 94 return new ImageData(IntSize(width, height), byteArray.release()); |
| 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 ASSERT(data); |
| 104 unsigned length = data->length(); | 104 unsigned length = data->length(); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, PassRefPtr<DOMUint8ClampedArray> byteA
rray) |
| 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 void ImageData::dispose() | 185 void ImageData::dispose() |
| 186 { | 186 { |
| 187 m_data.clear(); | 187 m_data.clear(); |
| 188 } | 188 } |
| 189 | 189 |
| 190 } // namespace blink | 190 } // namespace blink |
| OLD | NEW |