| 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" | |
| 42 #include "bindings/core/v8/V8MessagePort.h" | 41 #include "bindings/core/v8/V8MessagePort.h" |
| 43 #include "bindings/core/v8/V8SharedArrayBuffer.h" | 42 #include "bindings/core/v8/V8SharedArrayBuffer.h" |
| 44 #include "core/dom/ExceptionCode.h" | 43 #include "core/dom/ExceptionCode.h" |
| 45 #include "platform/SharedBuffer.h" | 44 #include "platform/SharedBuffer.h" |
| 46 #include "platform/blob/BlobData.h" | 45 #include "platform/blob/BlobData.h" |
| 47 #include "platform/heap/Handle.h" | 46 #include "platform/heap/Handle.h" |
| 48 #include "wtf/Assertions.h" | 47 #include "wtf/Assertions.h" |
| 49 #include "wtf/ByteOrder.h" | 48 #include "wtf/ByteOrder.h" |
| 50 #include "wtf/Vector.h" | 49 #include "wtf/Vector.h" |
| 51 #include "wtf/text/StringBuffer.h" | 50 #include "wtf/text/StringBuffer.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 if (!wrapper.IsEmpty()) | 94 if (!wrapper.IsEmpty()) |
| 96 buffers.append(v8::Local<v8::ArrayBuffer>::Cast(wrapper)); | 95 buffers.append(v8::Local<v8::ArrayBuffer>::Cast(wrapper)); |
| 97 } | 96 } |
| 98 } else { | 97 } else { |
| 99 v8::Local<v8::Object> wrapper = DOMWrapperWorld::current(isolate).domDat
aStore().get(object, isolate); | 98 v8::Local<v8::Object> wrapper = DOMWrapperWorld::current(isolate).domDat
aStore().get(object, isolate); |
| 100 if (!wrapper.IsEmpty()) | 99 if (!wrapper.IsEmpty()) |
| 101 buffers.append(v8::Local<v8::ArrayBuffer>::Cast(wrapper)); | 100 buffers.append(v8::Local<v8::ArrayBuffer>::Cast(wrapper)); |
| 102 } | 101 } |
| 103 } | 102 } |
| 104 | 103 |
| 105 PassOwnPtrWillBeRawPtr<ImageBitmapArray> SerializedScriptValue::createImageBitma
ps(v8::Isolate* isolate, ImageBitmapArray& imageBitmaps, ExceptionState& excepti
onState) | |
| 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 OwnPtrWillBeRawPtr<ImageBitmapArray> contents = adoptPtrWillBeNoop(new Image
BitmapArray(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(); | |
| 123 } | |
| 124 | |
| 125 return contents.release(); | |
| 126 } | |
| 127 | |
| 128 PassOwnPtr<SerializedScriptValue::ArrayBufferContentsArray> SerializedScriptValu
e::createArrayBuffers(v8::Isolate* isolate, ArrayBufferArray& arrayBuffers, Exce
ptionState& exceptionState) | 104 PassOwnPtr<SerializedScriptValue::ArrayBufferContentsArray> SerializedScriptValu
e::createArrayBuffers(v8::Isolate* isolate, ArrayBufferArray& arrayBuffers, Exce
ptionState& exceptionState) |
| 129 { | 105 { |
| 130 ASSERT(arrayBuffers.size()); | 106 ASSERT(arrayBuffers.size()); |
| 131 | 107 |
| 132 for (size_t i = 0; i < arrayBuffers.size(); i++) { | 108 for (size_t i = 0; i < arrayBuffers.size(); i++) { |
| 133 if (arrayBuffers[i]->isNeutered()) { | 109 if (arrayBuffers[i]->isNeutered()) { |
| 134 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at ind
ex " + String::number(i) + " is already neutered."); | 110 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at ind
ex " + String::number(i) + " is already neutered."); |
| 135 return nullptr; | 111 return nullptr; |
| 136 } | 112 } |
| 137 } | 113 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 150 exceptionState.throwDOMException(DataCloneError, "SharedArrayBuf
fer at index " + String::number(i) + " could not be transferred."); | 126 exceptionState.throwDOMException(DataCloneError, "SharedArrayBuf
fer at index " + String::number(i) + " could not be transferred."); |
| 151 return nullptr; | 127 return nullptr; |
| 152 } | 128 } |
| 153 } else { | 129 } else { |
| 154 Vector<v8::Local<v8::ArrayBuffer>, 4> bufferHandles; | 130 Vector<v8::Local<v8::ArrayBuffer>, 4> bufferHandles; |
| 155 v8::HandleScope handleScope(isolate); | 131 v8::HandleScope handleScope(isolate); |
| 156 acculumateArrayBuffersForAllWorlds(isolate, static_pointer_cast<DOMA
rrayBuffer>(arrayBuffers[i]).get(), bufferHandles); | 132 acculumateArrayBuffersForAllWorlds(isolate, static_pointer_cast<DOMA
rrayBuffer>(arrayBuffers[i]).get(), bufferHandles); |
| 157 bool isNeuterable = true; | 133 bool isNeuterable = true; |
| 158 for (size_t j = 0; j < bufferHandles.size(); j++) | 134 for (size_t j = 0; j < bufferHandles.size(); j++) |
| 159 isNeuterable &= bufferHandles[j]->IsNeuterable(); | 135 isNeuterable &= bufferHandles[j]->IsNeuterable(); |
| 136 |
| 160 RefPtr<DOMArrayBufferBase> toTransfer = arrayBuffers[i]; | 137 RefPtr<DOMArrayBufferBase> toTransfer = arrayBuffers[i]; |
| 161 if (!isNeuterable) | 138 if (!isNeuterable) |
| 162 toTransfer = DOMArrayBuffer::create(arrayBuffers[i]->buffer()); | 139 toTransfer = DOMArrayBuffer::create(arrayBuffers[i]->buffer()); |
| 163 bool result = toTransfer->transfer(contents->at(i)); | 140 bool result = toTransfer->transfer(contents->at(i)); |
| 164 if (!result) { | 141 if (!result) { |
| 165 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at
index " + String::number(i) + " could not be transferred."); | 142 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at
index " + String::number(i) + " could not be transferred."); |
| 166 return nullptr; | 143 return nullptr; |
| 167 } | 144 } |
| 168 | 145 |
| 169 if (isNeuterable) | 146 if (isNeuterable) |
| 170 for (size_t j = 0; j < bufferHandles.size(); j++) | 147 for (size_t j = 0; j < bufferHandles.size(); j++) |
| 171 bufferHandles[j]->Neuter(); | 148 bufferHandles[j]->Neuter(); |
| 172 } | 149 } |
| 150 |
| 173 } | 151 } |
| 174 | 152 |
| 175 return contents.release(); | 153 return contents.release(); |
| 176 } | 154 } |
| 177 | 155 |
| 178 SerializedScriptValue::SerializedScriptValue(const String& wireData) | 156 SerializedScriptValue::SerializedScriptValue(const String& wireData) |
| 179 : m_externallyAllocatedMemory(0) | 157 : m_externallyAllocatedMemory(0) |
| 180 { | 158 { |
| 181 m_data = wireData.isolatedCopy(); | 159 m_data = wireData.isolatedCopy(); |
| 182 } | 160 } |
| 183 | 161 |
| 184 v8::Local<v8::Value> SerializedScriptValue::deserialize(MessagePortArray* messag
ePorts) | 162 v8::Local<v8::Value> SerializedScriptValue::deserialize(MessagePortArray* messag
ePorts) |
| 185 { | 163 { |
| 186 return deserialize(v8::Isolate::GetCurrent(), messagePorts, 0); | 164 return deserialize(v8::Isolate::GetCurrent(), messagePorts, 0); |
| 187 } | 165 } |
| 188 | 166 |
| 189 v8::Local<v8::Value> SerializedScriptValue::deserialize(v8::Isolate* isolate, Me
ssagePortArray* messagePorts, const WebBlobInfoArray* blobInfo) | 167 v8::Local<v8::Value> SerializedScriptValue::deserialize(v8::Isolate* isolate, Me
ssagePortArray* messagePorts, const WebBlobInfoArray* blobInfo) |
| 190 { | 168 { |
| 191 return SerializedScriptValueFactory::instance().deserialize(this, isolate, m
essagePorts, blobInfo); | 169 return SerializedScriptValueFactory::instance().deserialize(this, isolate, m
essagePorts, blobInfo); |
| 192 } | 170 } |
| 193 | 171 |
| 194 bool SerializedScriptValue::extractTransferables(v8::Isolate* isolate, v8::Local
<v8::Value> value, int argumentIndex, MessagePortArray& ports, ArrayBufferArray&
arrayBuffers, ImageBitmapArray& imageBitmaps, ExceptionState& exceptionState) | 172 bool SerializedScriptValue::extractTransferables(v8::Isolate* isolate, v8::Local
<v8::Value> value, int argumentIndex, MessagePortArray& ports, ArrayBufferArray&
arrayBuffers, ExceptionState& exceptionState) |
| 195 { | 173 { |
| 196 if (isUndefinedOrNull(value)) { | 174 if (isUndefinedOrNull(value)) { |
| 197 ports.resize(0); | 175 ports.resize(0); |
| 198 arrayBuffers.resize(0); | 176 arrayBuffers.resize(0); |
| 199 imageBitmaps.resize(0); | |
| 200 return true; | 177 return true; |
| 201 } | 178 } |
| 202 | 179 |
| 203 uint32_t length = 0; | 180 uint32_t length = 0; |
| 204 if (value->IsArray()) { | 181 if (value->IsArray()) { |
| 205 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(value); | 182 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(value); |
| 206 length = array->Length(); | 183 length = array->Length(); |
| 207 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { | 184 } else if (!toV8Sequence(value, length, isolate, exceptionState)) { |
| 208 if (!exceptionState.hadException()) | 185 if (!exceptionState.hadException()) |
| 209 exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgum
entOrValue(argumentIndex + 1)); | 186 exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgum
entOrValue(argumentIndex + 1)); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 238 return false; | 215 return false; |
| 239 } | 216 } |
| 240 arrayBuffers.append(arrayBuffer.release()); | 217 arrayBuffers.append(arrayBuffer.release()); |
| 241 } else if (V8SharedArrayBuffer::hasInstance(transferrable, isolate)) { | 218 } else if (V8SharedArrayBuffer::hasInstance(transferrable, isolate)) { |
| 242 RefPtr<DOMSharedArrayBuffer> sharedArrayBuffer = V8SharedArrayBuffer
::toImpl(v8::Local<v8::Object>::Cast(transferrable)); | 219 RefPtr<DOMSharedArrayBuffer> sharedArrayBuffer = V8SharedArrayBuffer
::toImpl(v8::Local<v8::Object>::Cast(transferrable)); |
| 243 if (arrayBuffers.contains(sharedArrayBuffer)) { | 220 if (arrayBuffers.contains(sharedArrayBuffer)) { |
| 244 exceptionState.throwDOMException(DataCloneError, "SharedArrayBuf
fer at index " + String::number(i) + " is a duplicate of an earlier SharedArrayB
uffer."); | 221 exceptionState.throwDOMException(DataCloneError, "SharedArrayBuf
fer at index " + String::number(i) + " is a duplicate of an earlier SharedArrayB
uffer."); |
| 245 return false; | 222 return false; |
| 246 } | 223 } |
| 247 arrayBuffers.append(sharedArrayBuffer.release()); | 224 arrayBuffers.append(sharedArrayBuffer.release()); |
| 248 } else if (V8ImageBitmap::hasInstance(transferrable, isolate)) { | |
| 249 RefPtrWillBeRawPtr<ImageBitmap> imageBitmap = V8ImageBitmap::toImpl(
v8::Local<v8::Object>::Cast(transferrable)); | |
| 250 if (imageBitmaps.contains(imageBitmap)) { | |
| 251 exceptionState.throwDOMException(DataCloneError, "ImageBitmap at
index " + String::number(i) + " is a duplicate of an earlier ImageBitmap."); | |
| 252 return false; | |
| 253 } | |
| 254 imageBitmaps.append(imageBitmap.release()); | |
| 255 } else { | 225 } else { |
| 256 exceptionState.throwTypeError("Value at index " + String::number(i)
+ " does not have a transferable type."); | 226 exceptionState.throwTypeError("Value at index " + String::number(i)
+ " does not have a transferable type."); |
| 257 return false; | 227 return false; |
| 258 } | 228 } |
| 259 } | 229 } |
| 260 return true; | 230 return true; |
| 261 } | 231 } |
| 262 | 232 |
| 263 void SerializedScriptValue::registerMemoryAllocatedWithCurrentScriptContext() | 233 void SerializedScriptValue::registerMemoryAllocatedWithCurrentScriptContext() |
| 264 { | 234 { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 282 ASSERT(v8::Isolate::GetCurrent()); | 252 ASSERT(v8::Isolate::GetCurrent()); |
| 283 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte
rnallyAllocatedMemory); | 253 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte
rnallyAllocatedMemory); |
| 284 } | 254 } |
| 285 } | 255 } |
| 286 | 256 |
| 287 void SerializedScriptValue::transferArrayBuffers(v8::Isolate* isolate, ArrayBuff
erArray& arrayBuffers, ExceptionState& exceptionState) | 257 void SerializedScriptValue::transferArrayBuffers(v8::Isolate* isolate, ArrayBuff
erArray& arrayBuffers, ExceptionState& exceptionState) |
| 288 { | 258 { |
| 289 m_arrayBufferContentsArray = createArrayBuffers(isolate, arrayBuffers, excep
tionState); | 259 m_arrayBufferContentsArray = createArrayBuffers(isolate, arrayBuffers, excep
tionState); |
| 290 } | 260 } |
| 291 | 261 |
| 292 void SerializedScriptValue::transferImageBitmaps(v8::Isolate* isolate, ImageBitm
apArray& imageBitmaps, ExceptionState& exceptionState) | |
| 293 { | |
| 294 m_imageBitmapsArray = createImageBitmaps(isolate, imageBitmaps, exceptionSta
te); | |
| 295 } | |
| 296 | |
| 297 } // namespace blink | 262 } // namespace blink |
| OLD | NEW |