Chromium Code Reviews| 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 for (size_t i = 0; i < imageBitmaps.size(); i++) { | |
| 119 if (visited.contains(imageBitmaps[i].get())) | |
| 120 continue; | |
| 121 visited.add(imageBitmaps[i].get()); | |
| 122 contents->at(i) = imageBitmaps[i]->transfer(); | |
|
sof
2015/11/09 12:25:54
Could you explain why holes are kept in the ImageB
xidachen
2015/11/16 18:00:51
Thank you for pointing it out, this is an excellen
| |
| 123 } | |
| 124 return contents.release(); | |
| 125 } | |
| 126 | |
| 127 | |
| 104 PassOwnPtr<SerializedScriptValue::ArrayBufferContentsArray> SerializedScriptValu e::createArrayBuffers(v8::Isolate* isolate, ArrayBufferArray& arrayBuffers, Exce ptionState& exceptionState) | 128 PassOwnPtr<SerializedScriptValue::ArrayBufferContentsArray> SerializedScriptValu e::createArrayBuffers(v8::Isolate* isolate, ArrayBufferArray& arrayBuffers, Exce ptionState& exceptionState) |
| 105 { | 129 { |
| 106 ASSERT(arrayBuffers.size()); | 130 ASSERT(arrayBuffers.size()); |
| 107 | 131 |
| 108 for (size_t i = 0; i < arrayBuffers.size(); i++) { | 132 for (size_t i = 0; i < arrayBuffers.size(); i++) { |
| 109 if (arrayBuffers[i]->isNeutered()) { | 133 if (arrayBuffers[i]->isNeutered()) { |
| 110 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at ind ex " + String::number(i) + " is already neutered."); | 134 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at ind ex " + String::number(i) + " is already neutered."); |
| 111 return nullptr; | 135 return nullptr; |
| 112 } | 136 } |
| 113 } | 137 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 v8::Local<v8::Value> SerializedScriptValue::deserialize(MessagePortArray* messag ePorts) | 186 v8::Local<v8::Value> SerializedScriptValue::deserialize(MessagePortArray* messag ePorts) |
| 163 { | 187 { |
| 164 return deserialize(v8::Isolate::GetCurrent(), messagePorts, 0); | 188 return deserialize(v8::Isolate::GetCurrent(), messagePorts, 0); |
| 165 } | 189 } |
| 166 | 190 |
| 167 v8::Local<v8::Value> SerializedScriptValue::deserialize(v8::Isolate* isolate, Me ssagePortArray* messagePorts, const WebBlobInfoArray* blobInfo) | 191 v8::Local<v8::Value> SerializedScriptValue::deserialize(v8::Isolate* isolate, Me ssagePortArray* messagePorts, const WebBlobInfoArray* blobInfo) |
| 168 { | 192 { |
| 169 return SerializedScriptValueFactory::instance().deserialize(this, isolate, m essagePorts, blobInfo); | 193 return SerializedScriptValueFactory::instance().deserialize(this, isolate, m essagePorts, blobInfo); |
| 170 } | 194 } |
| 171 | 195 |
| 172 bool SerializedScriptValue::extractTransferables(v8::Isolate* isolate, v8::Local <v8::Value> value, int argumentIndex, MessagePortArray& ports, ArrayBufferArray& arrayBuffers, ExceptionState& exceptionState) | 196 bool SerializedScriptValue::extractTransferables(v8::Isolate* isolate, v8::Local <v8::Value> value, int argumentIndex, MessagePortArray& ports, ArrayBufferArray& arrayBuffers, ImageBitmapArray& imageBitmaps, ExceptionState& exceptionState) |
| 173 { | 197 { |
| 174 if (isUndefinedOrNull(value)) { | 198 if (isUndefinedOrNull(value)) { |
| 175 ports.resize(0); | 199 ports.resize(0); |
| 176 arrayBuffers.resize(0); | 200 arrayBuffers.resize(0); |
| 201 imageBitmaps.resize(0); | |
| 177 return true; | 202 return true; |
| 178 } | 203 } |
| 179 | 204 |
| 180 uint32_t length = 0; | 205 uint32_t length = 0; |
| 181 if (value->IsArray()) { | 206 if (value->IsArray()) { |
| 182 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(value); | 207 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(value); |
| 183 length = array->Length(); | 208 length = array->Length(); |
| 184 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { | 209 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { |
| 185 if (!exceptionState.hadException()) | 210 if (!exceptionState.hadException()) |
| 186 exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgum entOrValue(argumentIndex + 1)); | 211 exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgum entOrValue(argumentIndex + 1)); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 215 return false; | 240 return false; |
| 216 } | 241 } |
| 217 arrayBuffers.append(arrayBuffer.release()); | 242 arrayBuffers.append(arrayBuffer.release()); |
| 218 } else if (V8SharedArrayBuffer::hasInstance(transferrable, isolate)) { | 243 } else if (V8SharedArrayBuffer::hasInstance(transferrable, isolate)) { |
| 219 RefPtr<DOMSharedArrayBuffer> sharedArrayBuffer = V8SharedArrayBuffer ::toImpl(v8::Local<v8::Object>::Cast(transferrable)); | 244 RefPtr<DOMSharedArrayBuffer> sharedArrayBuffer = V8SharedArrayBuffer ::toImpl(v8::Local<v8::Object>::Cast(transferrable)); |
| 220 if (arrayBuffers.contains(sharedArrayBuffer)) { | 245 if (arrayBuffers.contains(sharedArrayBuffer)) { |
| 221 exceptionState.throwDOMException(DataCloneError, "SharedArrayBuf fer at index " + String::number(i) + " is a duplicate of an earlier SharedArrayB uffer."); | 246 exceptionState.throwDOMException(DataCloneError, "SharedArrayBuf fer at index " + String::number(i) + " is a duplicate of an earlier SharedArrayB uffer."); |
| 222 return false; | 247 return false; |
| 223 } | 248 } |
| 224 arrayBuffers.append(sharedArrayBuffer.release()); | 249 arrayBuffers.append(sharedArrayBuffer.release()); |
| 250 } else if (V8ImageBitmap::hasInstance(transferrable, isolate)) { | |
| 251 RefPtrWillBeRawPtr<ImageBitmap> imageBitmap = V8ImageBitmap::toImpl( v8::Local<v8::Object>::Cast(transferrable)); | |
| 252 if (imageBitmaps.contains(imageBitmap)) { | |
| 253 exceptionState.throwDOMException(DataCloneError, "ImageBitmap at index " + String::number(i) + " is a duplicate of an earlier ImageBitmap."); | |
| 254 return false; | |
| 255 } | |
| 256 imageBitmaps.append(imageBitmap.release()); | |
| 225 } else { | 257 } else { |
| 226 exceptionState.throwTypeError("Value at index " + String::number(i) + " does not have a transferable type."); | 258 exceptionState.throwTypeError("Value at index " + String::number(i) + " does not have a transferable type."); |
| 227 return false; | 259 return false; |
| 228 } | 260 } |
| 229 } | 261 } |
| 230 return true; | 262 return true; |
| 231 } | 263 } |
| 232 | 264 |
| 233 void SerializedScriptValue::registerMemoryAllocatedWithCurrentScriptContext() | 265 void SerializedScriptValue::registerMemoryAllocatedWithCurrentScriptContext() |
| 234 { | 266 { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 252 ASSERT(v8::Isolate::GetCurrent()); | 284 ASSERT(v8::Isolate::GetCurrent()); |
| 253 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte rnallyAllocatedMemory); | 285 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte rnallyAllocatedMemory); |
| 254 } | 286 } |
| 255 } | 287 } |
| 256 | 288 |
| 257 void SerializedScriptValue::transferArrayBuffers(v8::Isolate* isolate, ArrayBuff erArray& arrayBuffers, ExceptionState& exceptionState) | 289 void SerializedScriptValue::transferArrayBuffers(v8::Isolate* isolate, ArrayBuff erArray& arrayBuffers, ExceptionState& exceptionState) |
| 258 { | 290 { |
| 259 m_arrayBufferContentsArray = createArrayBuffers(isolate, arrayBuffers, excep tionState); | 291 m_arrayBufferContentsArray = createArrayBuffers(isolate, arrayBuffers, excep tionState); |
| 260 } | 292 } |
| 261 | 293 |
| 294 void SerializedScriptValue::transferImageBitmaps(v8::Isolate* isolate, ImageBitm apArray& imageBitmaps, ExceptionState& exceptionState) | |
| 295 { | |
| 296 m_imageBitmapContentsArray = createImageBitmaps(isolate, imageBitmaps, excep tionState); | |
| 297 } | |
| 298 | |
| 262 } // namespace blink | 299 } // namespace blink |
| OLD | NEW |