OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 20 matching lines...) Expand all Loading... | |
31 #include "config.h" | 31 #include "config.h" |
32 #include "bindings/core/v8/SerializedScriptValue.h" | 32 #include "bindings/core/v8/SerializedScriptValue.h" |
33 | 33 |
34 #include "bindings/core/v8/DOMDataStore.h" | 34 #include "bindings/core/v8/DOMDataStore.h" |
35 #include "bindings/core/v8/DOMWrapperWorld.h" | 35 #include "bindings/core/v8/DOMWrapperWorld.h" |
36 #include "bindings/core/v8/ExceptionState.h" | 36 #include "bindings/core/v8/ExceptionState.h" |
37 #include "bindings/core/v8/ScriptState.h" | 37 #include "bindings/core/v8/ScriptState.h" |
38 #include "bindings/core/v8/ScriptValueSerializer.h" | 38 #include "bindings/core/v8/ScriptValueSerializer.h" |
39 #include "bindings/core/v8/SerializedScriptValueFactory.h" | 39 #include "bindings/core/v8/SerializedScriptValueFactory.h" |
40 #include "bindings/core/v8/V8ArrayBuffer.h" | 40 #include "bindings/core/v8/V8ArrayBuffer.h" |
41 #include "bindings/core/v8/V8ImageBitmap.h" | |
41 #include "bindings/core/v8/V8MessagePort.h" | 42 #include "bindings/core/v8/V8MessagePort.h" |
42 #include "bindings/core/v8/V8SharedArrayBuffer.h" | 43 #include "bindings/core/v8/V8SharedArrayBuffer.h" |
43 #include "core/dom/ExceptionCode.h" | 44 #include "core/dom/ExceptionCode.h" |
44 #include "platform/SharedBuffer.h" | 45 #include "platform/SharedBuffer.h" |
45 #include "platform/blob/BlobData.h" | 46 #include "platform/blob/BlobData.h" |
46 #include "platform/heap/Handle.h" | 47 #include "platform/heap/Handle.h" |
47 #include "wtf/Assertions.h" | 48 #include "wtf/Assertions.h" |
48 #include "wtf/ByteOrder.h" | 49 #include "wtf/ByteOrder.h" |
49 #include "wtf/Vector.h" | 50 #include "wtf/Vector.h" |
50 #include "wtf/text/StringBuffer.h" | 51 #include "wtf/text/StringBuffer.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 if (!wrapper.IsEmpty()) | 95 if (!wrapper.IsEmpty()) |
95 buffers.append(v8::Local<v8::ArrayBuffer>::Cast(wrapper)); | 96 buffers.append(v8::Local<v8::ArrayBuffer>::Cast(wrapper)); |
96 } | 97 } |
97 } else { | 98 } else { |
98 v8::Local<v8::Object> wrapper = DOMWrapperWorld::current(isolate).domDat aStore().get(object, isolate); | 99 v8::Local<v8::Object> wrapper = DOMWrapperWorld::current(isolate).domDat aStore().get(object, isolate); |
99 if (!wrapper.IsEmpty()) | 100 if (!wrapper.IsEmpty()) |
100 buffers.append(v8::Local<v8::ArrayBuffer>::Cast(wrapper)); | 101 buffers.append(v8::Local<v8::ArrayBuffer>::Cast(wrapper)); |
101 } | 102 } |
102 } | 103 } |
103 | 104 |
105 PassOwnPtr<SerializedScriptValue::ImageBitmapContentsArray> SerializedScriptValu e::createImageBitmaps(v8::Isolate* isolate, ImageBitmapArray& imageBitmaps, Exce ptionState& exceptionState) | |
106 { | |
107 ASSERT(imageBitmaps.size()); | |
108 | |
109 for (size_t i = 0; i < imageBitmaps.size(); i++) { | |
110 if (imageBitmaps[i]->isNeutered()) { | |
111 exceptionState.throwDOMException(DataCloneError, "ImageBitmap at ind ex " + String::number(i) + " is already neutered."); | |
112 return nullptr; | |
113 } | |
114 } | |
115 | |
116 OwnPtr<ImageBitmapContentsArray> contents = adoptPtr(new ImageBitmapContents Array(imageBitmaps.size())); | |
117 WillBeHeapHashSet<RawPtrWillBeMember<ImageBitmap>> visited; | |
118 int validIdx = 0; | |
119 for (size_t i = 0; i < imageBitmaps.size(); i++) { | |
sof
2015/11/16 19:22:34
The code here works fine, but I wonder if we can s
xidachen
2015/11/16 20:15:50
Thank you for the comments. I think you made a goo
| |
120 if (visited.contains(imageBitmaps[i].get())) | |
121 continue; | |
122 visited.add(imageBitmaps[i].get()); | |
123 contents->at(validIdx++) = imageBitmaps[i]->transfer(); | |
124 } | |
125 contents.get()->remove(validIdx, imageBitmaps.size()-validIdx); | |
126 return contents.release(); | |
127 } | |
128 | |
129 | |
104 PassOwnPtr<SerializedScriptValue::ArrayBufferContentsArray> SerializedScriptValu e::createArrayBuffers(v8::Isolate* isolate, ArrayBufferArray& arrayBuffers, Exce ptionState& exceptionState) | 130 PassOwnPtr<SerializedScriptValue::ArrayBufferContentsArray> SerializedScriptValu e::createArrayBuffers(v8::Isolate* isolate, ArrayBufferArray& arrayBuffers, Exce ptionState& exceptionState) |
105 { | 131 { |
106 ASSERT(arrayBuffers.size()); | 132 ASSERT(arrayBuffers.size()); |
107 | 133 |
108 for (size_t i = 0; i < arrayBuffers.size(); i++) { | 134 for (size_t i = 0; i < arrayBuffers.size(); i++) { |
109 if (arrayBuffers[i]->isNeutered()) { | 135 if (arrayBuffers[i]->isNeutered()) { |
110 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at ind ex " + String::number(i) + " is already neutered."); | 136 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at ind ex " + String::number(i) + " is already neutered."); |
111 return nullptr; | 137 return nullptr; |
112 } | 138 } |
113 } | 139 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 v8::Local<v8::Value> SerializedScriptValue::deserialize(MessagePortArray* messag ePorts) | 188 v8::Local<v8::Value> SerializedScriptValue::deserialize(MessagePortArray* messag ePorts) |
163 { | 189 { |
164 return deserialize(v8::Isolate::GetCurrent(), messagePorts, 0); | 190 return deserialize(v8::Isolate::GetCurrent(), messagePorts, 0); |
165 } | 191 } |
166 | 192 |
167 v8::Local<v8::Value> SerializedScriptValue::deserialize(v8::Isolate* isolate, Me ssagePortArray* messagePorts, const WebBlobInfoArray* blobInfo) | 193 v8::Local<v8::Value> SerializedScriptValue::deserialize(v8::Isolate* isolate, Me ssagePortArray* messagePorts, const WebBlobInfoArray* blobInfo) |
168 { | 194 { |
169 return SerializedScriptValueFactory::instance().deserialize(this, isolate, m essagePorts, blobInfo); | 195 return SerializedScriptValueFactory::instance().deserialize(this, isolate, m essagePorts, blobInfo); |
170 } | 196 } |
171 | 197 |
172 bool SerializedScriptValue::extractTransferables(v8::Isolate* isolate, v8::Local <v8::Value> value, int argumentIndex, MessagePortArray& ports, ArrayBufferArray& arrayBuffers, ExceptionState& exceptionState) | 198 bool SerializedScriptValue::extractTransferables(v8::Isolate* isolate, v8::Local <v8::Value> value, int argumentIndex, MessagePortArray& ports, ArrayBufferArray& arrayBuffers, ImageBitmapArray& imageBitmaps, ExceptionState& exceptionState) |
173 { | 199 { |
174 if (isUndefinedOrNull(value)) { | 200 if (isUndefinedOrNull(value)) { |
175 ports.resize(0); | 201 ports.resize(0); |
176 arrayBuffers.resize(0); | 202 arrayBuffers.resize(0); |
203 imageBitmaps.resize(0); | |
177 return true; | 204 return true; |
178 } | 205 } |
179 | 206 |
180 uint32_t length = 0; | 207 uint32_t length = 0; |
181 if (value->IsArray()) { | 208 if (value->IsArray()) { |
182 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(value); | 209 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(value); |
183 length = array->Length(); | 210 length = array->Length(); |
184 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { | 211 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { |
185 if (!exceptionState.hadException()) | 212 if (!exceptionState.hadException()) |
186 exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgum entOrValue(argumentIndex + 1)); | 213 exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgum entOrValue(argumentIndex + 1)); |
(...skipping 28 matching lines...) Expand all Loading... | |
215 return false; | 242 return false; |
216 } | 243 } |
217 arrayBuffers.append(arrayBuffer.release()); | 244 arrayBuffers.append(arrayBuffer.release()); |
218 } else if (V8SharedArrayBuffer::hasInstance(transferrable, isolate)) { | 245 } else if (V8SharedArrayBuffer::hasInstance(transferrable, isolate)) { |
219 RefPtr<DOMSharedArrayBuffer> sharedArrayBuffer = V8SharedArrayBuffer ::toImpl(v8::Local<v8::Object>::Cast(transferrable)); | 246 RefPtr<DOMSharedArrayBuffer> sharedArrayBuffer = V8SharedArrayBuffer ::toImpl(v8::Local<v8::Object>::Cast(transferrable)); |
220 if (arrayBuffers.contains(sharedArrayBuffer)) { | 247 if (arrayBuffers.contains(sharedArrayBuffer)) { |
221 exceptionState.throwDOMException(DataCloneError, "SharedArrayBuf fer at index " + String::number(i) + " is a duplicate of an earlier SharedArrayB uffer."); | 248 exceptionState.throwDOMException(DataCloneError, "SharedArrayBuf fer at index " + String::number(i) + " is a duplicate of an earlier SharedArrayB uffer."); |
222 return false; | 249 return false; |
223 } | 250 } |
224 arrayBuffers.append(sharedArrayBuffer.release()); | 251 arrayBuffers.append(sharedArrayBuffer.release()); |
252 } else if (V8ImageBitmap::hasInstance(transferrable, isolate)) { | |
253 RefPtrWillBeRawPtr<ImageBitmap> imageBitmap = V8ImageBitmap::toImpl( v8::Local<v8::Object>::Cast(transferrable)); | |
254 if (imageBitmaps.contains(imageBitmap)) { | |
255 exceptionState.throwDOMException(DataCloneError, "ImageBitmap at index " + String::number(i) + " is a duplicate of an earlier ImageBitmap."); | |
256 return false; | |
257 } | |
258 imageBitmaps.append(imageBitmap.release()); | |
225 } else { | 259 } else { |
226 exceptionState.throwTypeError("Value at index " + String::number(i) + " does not have a transferable type."); | 260 exceptionState.throwTypeError("Value at index " + String::number(i) + " does not have a transferable type."); |
227 return false; | 261 return false; |
228 } | 262 } |
229 } | 263 } |
230 return true; | 264 return true; |
231 } | 265 } |
232 | 266 |
233 void SerializedScriptValue::registerMemoryAllocatedWithCurrentScriptContext() | 267 void SerializedScriptValue::registerMemoryAllocatedWithCurrentScriptContext() |
234 { | 268 { |
(...skipping 17 matching lines...) Expand all Loading... | |
252 ASSERT(v8::Isolate::GetCurrent()); | 286 ASSERT(v8::Isolate::GetCurrent()); |
253 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte rnallyAllocatedMemory); | 287 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte rnallyAllocatedMemory); |
254 } | 288 } |
255 } | 289 } |
256 | 290 |
257 void SerializedScriptValue::transferArrayBuffers(v8::Isolate* isolate, ArrayBuff erArray& arrayBuffers, ExceptionState& exceptionState) | 291 void SerializedScriptValue::transferArrayBuffers(v8::Isolate* isolate, ArrayBuff erArray& arrayBuffers, ExceptionState& exceptionState) |
258 { | 292 { |
259 m_arrayBufferContentsArray = createArrayBuffers(isolate, arrayBuffers, excep tionState); | 293 m_arrayBufferContentsArray = createArrayBuffers(isolate, arrayBuffers, excep tionState); |
260 } | 294 } |
261 | 295 |
296 void SerializedScriptValue::transferImageBitmaps(v8::Isolate* isolate, ImageBitm apArray& imageBitmaps, ExceptionState& exceptionState) | |
297 { | |
298 m_imageBitmapContentsArray = createImageBitmaps(isolate, imageBitmaps, excep tionState); | |
299 } | |
300 | |
262 } // namespace blink | 301 } // namespace blink |
OLD | NEW |