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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 if (!height) { | 118 if (!height) { |
119 height = length / width; | 119 height = length / width; |
120 } else if (height != length / width) { | 120 } else if (height != length / width) { |
121 exceptionState.throwDOMException(IndexSizeError, "The input data byte le
ngth is not equal to (4 * width * height)."); | 121 exceptionState.throwDOMException(IndexSizeError, "The input data byte le
ngth is not equal to (4 * width * height)."); |
122 return nullptr; | 122 return nullptr; |
123 } | 123 } |
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::wrap(v8::Handle<v8::Object> creationContext, v
8::Isolate* isolate) | |
129 { | |
130 v8::Handle<v8::Object> wrapper = ScriptWrappable::wrap(creationContext, isol
ate); | |
131 return associateWithWrapperInternal(wrapper, creationContext, isolate); | |
132 } | |
133 | |
134 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) |
135 { | 129 { |
136 ScriptWrappable::associateWithWrapper(wrapperType, wrapper, isolate); | 130 ScriptWrappable::associateWithWrapper(wrapperType, wrapper, isolate); |
137 return associateWithWrapperInternal(wrapper, wrapper, isolate); | |
138 } | |
139 | 131 |
140 v8::Handle<v8::Object> ImageData::associateWithWrapperInternal(v8::Handle<v8::Ob
ject> wrapper, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) | |
141 { | |
142 if (!wrapper.IsEmpty()) { | 132 if (!wrapper.IsEmpty()) { |
143 // Create a V8 Uint8ClampedArray object. | 133 // Create a V8 Uint8ClampedArray object. |
144 v8::Handle<v8::Value> pixelArray = toV8(data(), creationContext, isolate
); | 134 v8::Handle<v8::Value> pixelArray = toV8(data(), wrapper, isolate); |
145 // Set the "data" property of the ImageData object to | 135 // Set the "data" property of the ImageData object to |
146 // the created v8 object, eliminating the C++ callback | 136 // the created v8 object, eliminating the C++ callback |
147 // when accessing the "data" property. | 137 // when accessing the "data" property. |
148 if (!pixelArray.IsEmpty()) | 138 if (!pixelArray.IsEmpty()) |
149 wrapper->ForceSet(v8AtomicString(isolate, "data"), pixelArray, v8::R
eadOnly); | 139 wrapper->ForceSet(v8AtomicString(isolate, "data"), pixelArray, v8::R
eadOnly); |
150 } | 140 } |
151 return wrapper; | 141 return wrapper; |
152 } | 142 } |
153 | 143 |
154 ImageData::ImageData(const IntSize& size) | 144 ImageData::ImageData(const IntSize& size) |
155 : m_size(size) | 145 : m_size(size) |
156 , m_data(Uint8ClampedArray::create(size.width() * size.height() * 4)) | 146 , m_data(Uint8ClampedArray::create(size.width() * size.height() * 4)) |
157 { | 147 { |
158 } | 148 } |
159 | 149 |
160 ImageData::ImageData(const IntSize& size, PassRefPtr<Uint8ClampedArray> byteArra
y) | 150 ImageData::ImageData(const IntSize& size, PassRefPtr<Uint8ClampedArray> byteArra
y) |
161 : m_size(size) | 151 : m_size(size) |
162 , m_data(byteArray) | 152 , m_data(byteArray) |
163 { | 153 { |
164 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()); |
165 } | 155 } |
166 | 156 |
167 } | 157 } // namespace blink |
OLD | NEW |