| Index: WebCore/bindings/v8/SerializedScriptValue.cpp
|
| ===================================================================
|
| --- WebCore/bindings/v8/SerializedScriptValue.cpp (revision 140218)
|
| +++ WebCore/bindings/v8/SerializedScriptValue.cpp (working copy)
|
| @@ -431,7 +431,7 @@
|
| doWriteUint32(length);
|
| for (unsigned i = 0; i < length; ++i) {
|
| doWriteWebCoreString(fileList.item(i)->path());
|
| - doWriteWebCoreString(fileList.item(i)->url().string());
|
| + doWriteWebCoreString(fileList.item(i)->uuid()); // TODO: bump version numbers somewhere?
|
| doWriteWebCoreString(fileList.item(i)->type());
|
| }
|
| }
|
| @@ -704,14 +704,14 @@
|
| JSFailure
|
| };
|
|
|
| - Serializer(Writer& writer, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, Vector<String>& blobURLs, v8::TryCatch& tryCatch)
|
| + Serializer(Writer& writer, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, BlobDataHandleMap& blobDataHandles, v8::TryCatch& tryCatch)
|
| : m_writer(writer)
|
| , m_tryCatch(tryCatch)
|
| , m_depth(0)
|
| , m_execDepth(0)
|
| , m_status(Success)
|
| , m_nextObjectReference(0)
|
| - , m_blobURLs(blobURLs)
|
| + , m_blobDataHandles(blobDataHandles)
|
| {
|
| ASSERT(!tryCatch.HasCaught());
|
| if (messagePorts) {
|
| @@ -1078,8 +1078,8 @@
|
| Blob* blob = V8Blob::toNative(value.As<v8::Object>());
|
| if (!blob)
|
| return;
|
| - m_writer.writeBlob(blob->url().string(), blob->type(), blob->size());
|
| - m_blobURLs.append(blob->url().string());
|
| + m_writer.writeBlob(blob->uuid(), blob->type(), blob->size());
|
| + m_blobDataHandles.add(blob->uuid(), blob->blobDataHandle());
|
| }
|
|
|
| #if ENABLE(FILE_SYSTEM)
|
| @@ -1100,8 +1100,8 @@
|
| File* file = V8File::toNative(value.As<v8::Object>());
|
| if (!file)
|
| return;
|
| - m_writer.writeFile(file->path(), file->url().string(), file->type());
|
| - m_blobURLs.append(file->url().string());
|
| + m_writer.writeFile(file->path(), file->uuid(), file->type());
|
| + m_blobDataHandles.add(file->uuid(), file->blobDataHandle());
|
| }
|
|
|
| void writeFileList(v8::Handle<v8::Value> value)
|
| @@ -1112,7 +1112,7 @@
|
| m_writer.writeFileList(*fileList);
|
| unsigned length = fileList->length();
|
| for (unsigned i = 0; i < length; ++i)
|
| - m_blobURLs.append(fileList->item(i)->url().string());
|
| + m_blobDataHandles.add(fileList->item(i)->uuid(), fileList->item(i)->blobDataHandle());
|
| }
|
|
|
| void writeImageData(v8::Handle<v8::Value> value)
|
| @@ -1231,7 +1231,7 @@
|
| ObjectPool m_transferredMessagePorts;
|
| ObjectPool m_transferredArrayBuffers;
|
| uint32_t m_nextObjectReference;
|
| - Vector<String>& m_blobURLs;
|
| + BlobDataHandleMap& m_blobDataHandles;
|
| };
|
|
|
| Serializer::StateBase* Serializer::doSerialize(v8::Handle<v8::Value> value, StateBase* next)
|
| @@ -1341,12 +1341,13 @@
|
| // restoring information about saved objects of composite types.
|
| class Reader {
|
| public:
|
| - Reader(const uint8_t* buffer, int length, v8::Isolate* isolate)
|
| + Reader(const uint8_t* buffer, int length, v8::Isolate* isolate, const BlobDataHandleMap& blobDataHandles)
|
| : m_buffer(buffer)
|
| , m_length(length)
|
| , m_position(0)
|
| , m_version(0)
|
| , m_isolate(isolate)
|
| + , m_blobDataHandles(blobDataHandles)
|
| {
|
| ASSERT(!(reinterpret_cast<size_t>(buffer) & 1));
|
| ASSERT(length >= 0);
|
| @@ -1859,16 +1860,16 @@
|
|
|
| bool readBlob(v8::Handle<v8::Value>* value)
|
| {
|
| - String url;
|
| + String uuid;
|
| String type;
|
| uint64_t size;
|
| - if (!readWebCoreString(&url))
|
| + if (!readWebCoreString(&uuid))
|
| return false;
|
| if (!readWebCoreString(&type))
|
| return false;
|
| if (!doReadUint64(&size))
|
| return false;
|
| - PassRefPtr<Blob> blob = Blob::create(KURL(ParsedURLString, url), type, size);
|
| + PassRefPtr<Blob> blob = Blob::create(getOrCreateBlobDataHandle(uuid, type, size));
|
| *value = toV8(blob, v8::Handle<v8::Object>(), m_isolate);
|
| return true;
|
| }
|
| @@ -1894,15 +1895,15 @@
|
| bool readFile(v8::Handle<v8::Value>* value)
|
| {
|
| String path;
|
| - String url;
|
| + String uuid;
|
| String type;
|
| if (!readWebCoreString(&path))
|
| return false;
|
| - if (!readWebCoreString(&url))
|
| + if (!readWebCoreString(&uuid))
|
| return false;
|
| if (!readWebCoreString(&type))
|
| return false;
|
| - PassRefPtr<File> file = File::create(path, KURL(ParsedURLString, url), type);
|
| + PassRefPtr<File> file = File::create(path, getOrCreateBlobDataHandle(uuid, type));
|
| *value = toV8(file, v8::Handle<v8::Object>(), m_isolate);
|
| return true;
|
| }
|
| @@ -1915,15 +1916,15 @@
|
| PassRefPtr<FileList> fileList = FileList::create();
|
| for (unsigned i = 0; i < length; ++i) {
|
| String path;
|
| - String urlString;
|
| + String uuid;
|
| String type;
|
| if (!readWebCoreString(&path))
|
| return false;
|
| - if (!readWebCoreString(&urlString))
|
| + if (!readWebCoreString(&uuid))
|
| return false;
|
| if (!readWebCoreString(&type))
|
| return false;
|
| - fileList->append(File::create(path, KURL(ParsedURLString, urlString), type));
|
| + fileList->append(File::create(path, getOrCreateBlobDataHandle(uuid, type)));
|
| }
|
| *value = toV8(fileList, v8::Handle<v8::Object>(), m_isolate);
|
| return true;
|
| @@ -1965,11 +1966,30 @@
|
| return true;
|
| }
|
|
|
| + PassRefPtr<BlobDataHandle> getOrCreateBlobDataHandle(const String& uuid, const String& type, long long size = -1)
|
| + {
|
| + // The containing ssv may have a BDH for this uuid if this ssv is just being
|
| + // passed from main to worker thread (for example). We use those values when creating the
|
| + // new blob instead of cons'ing up a new BDH.
|
| + //
|
| + // FIXME: Maybe we should require that it work that way where the ssv must have a BDH for any
|
| + // blobs it comes across during deserialization. Would require callers to explicitly populate
|
| + // the collection of BDH's for blobs to work, which would encourage lifetimes to be considered
|
| + // when passing ssv's around cross process. At present, we get 'lucky' in some cases because
|
| + // the blob in the src process happens to still exists at the time the dest process is deserializing.
|
| + // For example in sharedWorker.postMesssage(...).
|
| + BlobDataHandleMap::const_iterator it = m_blobDataHandles.find(uuid);
|
| + if (it != m_blobDataHandles.end())
|
| + return it->value;
|
| + return BlobDataHandle::create(uuid, type, size);
|
| + }
|
| +
|
| const uint8_t* m_buffer;
|
| const unsigned m_length;
|
| unsigned m_position;
|
| uint32_t m_version;
|
| v8::Isolate* m_isolate;
|
| + const BlobDataHandleMap& m_blobDataHandles;
|
| };
|
|
|
|
|
| @@ -2423,7 +2443,7 @@
|
| Serializer::Status status;
|
| {
|
| v8::TryCatch tryCatch;
|
| - Serializer serializer(writer, messagePorts, arrayBuffers, m_blobURLs, tryCatch);
|
| + Serializer serializer(writer, messagePorts, arrayBuffers, m_blobDataHandles, tryCatch);
|
| status = serializer.serialize(value);
|
| if (status == Serializer::JSException) {
|
| // If there was a JS exception thrown, re-throw it.
|
| @@ -2478,7 +2498,7 @@
|
| if (!m_data.impl())
|
| return v8NullWithCheck(isolate);
|
| COMPILE_ASSERT(sizeof(BufferValueType) == 2, BufferValueTypeIsTwoBytes);
|
| - Reader reader(reinterpret_cast<const uint8_t*>(m_data.impl()->characters()), 2 * m_data.length(), isolate);
|
| + Reader reader(reinterpret_cast<const uint8_t*>(m_data.impl()->characters()), 2 * m_data.length(), isolate, m_blobDataHandles);
|
| Deserializer deserializer(reader, messagePorts, m_arrayBufferContentsArray.get());
|
| return deserializer.deserialize();
|
| }
|
|
|