| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "bindings/core/v8/ScriptValueSerializer.h" | 5 #include "bindings/core/v8/ScriptValueSerializer.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/Transferables.h" | 7 #include "bindings/core/v8/Transferables.h" |
| 8 #include "bindings/core/v8/V8ArrayBuffer.h" | 8 #include "bindings/core/v8/V8ArrayBuffer.h" |
| 9 #include "bindings/core/v8/V8ArrayBufferView.h" | 9 #include "bindings/core/v8/V8ArrayBufferView.h" |
| 10 #include "bindings/core/v8/V8Blob.h" | 10 #include "bindings/core/v8/V8Blob.h" |
| (...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1142 const File* file = fileList->item(i); | 1142 const File* file = fileList->item(i); |
| 1143 if (file->isClosed()) | 1143 if (file->isClosed()) |
| 1144 return handleError( | 1144 return handleError( |
| 1145 Status::DataCloneError, | 1145 Status::DataCloneError, |
| 1146 "A File object has been closed, and could therefore not be cloned.", | 1146 "A File object has been closed, and could therefore not be cloned.", |
| 1147 next); | 1147 next); |
| 1148 m_blobDataHandles->set(file->uuid(), file->blobDataHandle()); | 1148 m_blobDataHandles->set(file->uuid(), file->blobDataHandle()); |
| 1149 if (appendFileInfo(file, &blobIndex)) { | 1149 if (appendFileInfo(file, &blobIndex)) { |
| 1150 ASSERT(!i || blobIndex > 0); | 1150 ASSERT(!i || blobIndex > 0); |
| 1151 ASSERT(blobIndex >= 0); | 1151 ASSERT(blobIndex >= 0); |
| 1152 blobIndices.append(blobIndex); | 1152 blobIndices.push_back(blobIndex); |
| 1153 } | 1153 } |
| 1154 } | 1154 } |
| 1155 if (!blobIndices.isEmpty()) | 1155 if (!blobIndices.isEmpty()) |
| 1156 m_writer.writeFileListIndex(blobIndices); | 1156 m_writer.writeFileListIndex(blobIndices); |
| 1157 else | 1157 else |
| 1158 m_writer.writeFileList(*fileList); | 1158 m_writer.writeFileList(*fileList); |
| 1159 return nullptr; | 1159 return nullptr; |
| 1160 } | 1160 } |
| 1161 | 1161 |
| 1162 void ScriptValueSerializer::writeImageData(v8::Local<v8::Value> value) { | 1162 void ScriptValueSerializer::writeImageData(v8::Local<v8::Value> value) { |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1390 m_objectPool.set(object, objectReference); | 1390 m_objectPool.set(object, objectReference); |
| 1391 } | 1391 } |
| 1392 | 1392 |
| 1393 bool ScriptValueSerializer::appendBlobInfo(const String& uuid, | 1393 bool ScriptValueSerializer::appendBlobInfo(const String& uuid, |
| 1394 const String& type, | 1394 const String& type, |
| 1395 unsigned long long size, | 1395 unsigned long long size, |
| 1396 int* index) { | 1396 int* index) { |
| 1397 if (!m_blobInfo) | 1397 if (!m_blobInfo) |
| 1398 return false; | 1398 return false; |
| 1399 *index = m_blobInfo->size(); | 1399 *index = m_blobInfo->size(); |
| 1400 m_blobInfo->append(WebBlobInfo(uuid, type, size)); | 1400 m_blobInfo->push_back(WebBlobInfo(uuid, type, size)); |
| 1401 return true; | 1401 return true; |
| 1402 } | 1402 } |
| 1403 | 1403 |
| 1404 bool ScriptValueSerializer::appendFileInfo(const File* file, int* index) { | 1404 bool ScriptValueSerializer::appendFileInfo(const File* file, int* index) { |
| 1405 if (!m_blobInfo) | 1405 if (!m_blobInfo) |
| 1406 return false; | 1406 return false; |
| 1407 | 1407 |
| 1408 long long size = -1; | 1408 long long size = -1; |
| 1409 double lastModifiedMS = invalidFileTime(); | 1409 double lastModifiedMS = invalidFileTime(); |
| 1410 file->captureSnapshot(size, lastModifiedMS); | 1410 file->captureSnapshot(size, lastModifiedMS); |
| 1411 *index = m_blobInfo->size(); | 1411 *index = m_blobInfo->size(); |
| 1412 // FIXME: transition WebBlobInfo.lastModified to be milliseconds-based also. | 1412 // FIXME: transition WebBlobInfo.lastModified to be milliseconds-based also. |
| 1413 double lastModified = lastModifiedMS / msPerSecond; | 1413 double lastModified = lastModifiedMS / msPerSecond; |
| 1414 m_blobInfo->append(WebBlobInfo(file->uuid(), file->path(), file->name(), | 1414 m_blobInfo->push_back(WebBlobInfo(file->uuid(), file->path(), file->name(), |
| 1415 file->type(), lastModified, size)); | 1415 file->type(), lastModified, size)); |
| 1416 return true; | 1416 return true; |
| 1417 } | 1417 } |
| 1418 | 1418 |
| 1419 bool SerializedScriptValueReader::read(v8::Local<v8::Value>* value, | 1419 bool SerializedScriptValueReader::read(v8::Local<v8::Value>* value, |
| 1420 ScriptValueDeserializer& deserializer) { | 1420 ScriptValueDeserializer& deserializer) { |
| 1421 SerializationTag tag; | 1421 SerializationTag tag; |
| 1422 if (!readTag(&tag)) | 1422 if (!readTag(&tag)) |
| 1423 return false; | 1423 return false; |
| 1424 return readWithTag(tag, value, deserializer); | 1424 return readWithTag(tag, value, deserializer); |
| 1425 } | 1425 } |
| (...skipping 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2468 if (set->Add(context, key).IsEmpty()) | 2468 if (set->Add(context, key).IsEmpty()) |
| 2469 return false; | 2469 return false; |
| 2470 } | 2470 } |
| 2471 pop(length); | 2471 pop(length); |
| 2472 *value = set; | 2472 *value = set; |
| 2473 return true; | 2473 return true; |
| 2474 } | 2474 } |
| 2475 | 2475 |
| 2476 void ScriptValueDeserializer::pushObjectReference( | 2476 void ScriptValueDeserializer::pushObjectReference( |
| 2477 const v8::Local<v8::Value>& object) { | 2477 const v8::Local<v8::Value>& object) { |
| 2478 m_objectPool.append(object); | 2478 m_objectPool.push_back(object); |
| 2479 } | 2479 } |
| 2480 | 2480 |
| 2481 bool ScriptValueDeserializer::tryGetTransferredMessagePort( | 2481 bool ScriptValueDeserializer::tryGetTransferredMessagePort( |
| 2482 uint32_t index, | 2482 uint32_t index, |
| 2483 v8::Local<v8::Value>* object) { | 2483 v8::Local<v8::Value>* object) { |
| 2484 if (!m_transferredMessagePorts) | 2484 if (!m_transferredMessagePorts) |
| 2485 return false; | 2485 return false; |
| 2486 if (index >= m_transferredMessagePorts->size()) | 2486 if (index >= m_transferredMessagePorts->size()) |
| 2487 return false; | 2487 return false; |
| 2488 v8::Local<v8::Object> creationContext = | 2488 v8::Local<v8::Object> creationContext = |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2634 } | 2634 } |
| 2635 | 2635 |
| 2636 v8::Local<v8::Value> ScriptValueDeserializer::element(unsigned index) { | 2636 v8::Local<v8::Value> ScriptValueDeserializer::element(unsigned index) { |
| 2637 SECURITY_DCHECK(index < m_stack.size()); | 2637 SECURITY_DCHECK(index < m_stack.size()); |
| 2638 return m_stack[index]; | 2638 return m_stack[index]; |
| 2639 } | 2639 } |
| 2640 | 2640 |
| 2641 void ScriptValueDeserializer::openComposite( | 2641 void ScriptValueDeserializer::openComposite( |
| 2642 const v8::Local<v8::Value>& object) { | 2642 const v8::Local<v8::Value>& object) { |
| 2643 uint32_t newObjectReference = m_objectPool.size(); | 2643 uint32_t newObjectReference = m_objectPool.size(); |
| 2644 m_openCompositeReferenceStack.append(newObjectReference); | 2644 m_openCompositeReferenceStack.push_back(newObjectReference); |
| 2645 m_objectPool.append(object); | 2645 m_objectPool.push_back(object); |
| 2646 } | 2646 } |
| 2647 | 2647 |
| 2648 bool ScriptValueDeserializer::closeComposite(v8::Local<v8::Value>* object) { | 2648 bool ScriptValueDeserializer::closeComposite(v8::Local<v8::Value>* object) { |
| 2649 if (!m_openCompositeReferenceStack.size()) | 2649 if (!m_openCompositeReferenceStack.size()) |
| 2650 return false; | 2650 return false; |
| 2651 uint32_t objectReference = | 2651 uint32_t objectReference = |
| 2652 m_openCompositeReferenceStack[m_openCompositeReferenceStack.size() - 1]; | 2652 m_openCompositeReferenceStack[m_openCompositeReferenceStack.size() - 1]; |
| 2653 m_openCompositeReferenceStack.shrink(m_openCompositeReferenceStack.size() - | 2653 m_openCompositeReferenceStack.shrink(m_openCompositeReferenceStack.size() - |
| 2654 1); | 2654 1); |
| 2655 if (objectReference >= m_objectPool.size()) | 2655 if (objectReference >= m_objectPool.size()) |
| 2656 return false; | 2656 return false; |
| 2657 *object = m_objectPool[objectReference]; | 2657 *object = m_objectPool[objectReference]; |
| 2658 return true; | 2658 return true; |
| 2659 } | 2659 } |
| 2660 | 2660 |
| 2661 } // namespace blink | 2661 } // namespace blink |
| OLD | NEW |