Changeset 57382 in webkit


Ignore:
Timestamp:
Apr 9, 2010 4:28:00 PM (14 years ago)
Author:
vitalyr@chromium.org
Message:

2010-04-09 Vitaly Repeshko <vitalyr@chromium.org>

Reviewed by Darin Fisher.

[V8] SerializedScriptValue value doesn't follow the spec for DOM objects and files
https://bugs.webkit.org/show_bug.cgi?id=37094

This patch adds support for file-related types.

  • bindings/v8/SerializedScriptValue.cpp: (WebCore::): (WebCore::Writer::writeString): (WebCore::Writer::writeWebCoreString): (WebCore::Writer::writeBlob): (WebCore::Writer::writeFile): (WebCore::Writer::writeFileList): (WebCore::Writer::doWriteString): (WebCore::Writer::doWriteWebCoreString): (WebCore::Serializer::writeBlob): (WebCore::Serializer::writeFile): (WebCore::Serializer::writeFileList): (WebCore::Serializer::doSerialize): (WebCore::Reader::read): (WebCore::Reader::readWebCoreString): (WebCore::Reader::readBlob): (WebCore::Reader::readFile): (WebCore::Reader::readFileList): (WebCore::SerializedScriptValue::SerializedScriptValue):
Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r57379 r57382  
     12010-04-09  Vitaly Repeshko  <vitalyr@chromium.org>
     2
     3        Reviewed by Darin Fisher.
     4
     5        [V8] SerializedScriptValue value doesn't follow the spec for DOM objects and files
     6        https://bugs.webkit.org/show_bug.cgi?id=37094
     7
     8        This patch adds support for file-related types.
     9
     10        * bindings/v8/SerializedScriptValue.cpp:
     11        (WebCore::):
     12        (WebCore::Writer::writeString):
     13        (WebCore::Writer::writeWebCoreString):
     14        (WebCore::Writer::writeBlob):
     15        (WebCore::Writer::writeFile):
     16        (WebCore::Writer::writeFileList):
     17        (WebCore::Writer::doWriteString):
     18        (WebCore::Writer::doWriteWebCoreString):
     19        (WebCore::Serializer::writeBlob):
     20        (WebCore::Serializer::writeFile):
     21        (WebCore::Serializer::writeFileList):
     22        (WebCore::Serializer::doSerialize):
     23        (WebCore::Reader::read):
     24        (WebCore::Reader::readWebCoreString):
     25        (WebCore::Reader::readBlob):
     26        (WebCore::Reader::readFile):
     27        (WebCore::Reader::readFileList):
     28        (WebCore::SerializedScriptValue::SerializedScriptValue):
     29
    1302010-04-09  Geoffrey Garen  <ggaren@apple.com>
    231
  • trunk/WebCore/bindings/v8/SerializedScriptValue.cpp

    r57276 r57382  
    3232#include "SerializedScriptValue.h"
    3333
     34#include "Blob.h"
    3435#include "ByteArray.h"
    3536#include "CanvasPixelArray.h"
     37#include "File.h"
     38#include "FileList.h"
    3639#include "ImageData.h"
    3740#include "SharedBuffer.h"
     41#include "V8Blob.h"
     42#include "V8File.h"
     43#include "V8FileList.h"
    3844#include "V8ImageData.h"
    3945#include "V8Proxy.h"
     
    6874    DateTag = 'D',
    6975    NumberTag = 'N',
     76    BlobTag = 'b',
     77    FileTag = 'f',
     78    FileListTag = 'l',
    7079    ImageDataTag = '#',
    7180    ArrayTag = '[',
     
    138147        ASSERT(length >= 0);
    139148        append(StringTag);
    140         doWriteUint32(static_cast<uint32_t>(length));
    141         append(reinterpret_cast<const uint8_t*>(data), length);
     149        doWriteString(data, length);
     150    }
     151
     152    void writeWebCoreString(const String& string)
     153    {
     154        // Uses UTF8 encoding so we can read it back as either V8 or
     155        // WebCore string.
     156        append(StringTag);
     157        doWriteWebCoreString(string);
    142158    }
    143159
     
    164180        append(NumberTag);
    165181        doWriteNumber(number);
     182    }
     183
     184    void writeBlob(const String& path)
     185    {
     186        append(BlobTag);
     187        doWriteWebCoreString(path);
     188    }
     189
     190    void writeFile(const String& path)
     191    {
     192        append(FileTag);
     193        doWriteWebCoreString(path);
     194    }
     195
     196    void writeFileList(const FileList& fileList)
     197    {
     198        append(FileListTag);
     199        uint32_t length = fileList.length();
     200        doWriteUint32(length);
     201        for (unsigned i = 0; i < length; ++i)
     202            doWriteWebCoreString(fileList.item(i)->path());
    166203    }
    167204
     
    201238
    202239private:
     240    void doWriteString(const char* data, int length)
     241    {
     242        doWriteUint32(static_cast<uint32_t>(length));
     243        append(reinterpret_cast<const uint8_t*>(data), length);
     244    }
     245
     246    void doWriteWebCoreString(const String& string)
     247    {
     248        RefPtr<SharedBuffer> buffer = utf8Buffer(string);
     249        doWriteString(buffer->data(), buffer->size());
     250    }
     251
    203252    void doWriteUint32(uint32_t value)
    204253    {
     
    505554    }
    506555
     556    void writeBlob(v8::Handle<v8::Value> value)
     557    {
     558        Blob* blob = V8Blob::toNative(value.As<v8::Object>());
     559        if (!blob)
     560            return;
     561        m_writer.writeBlob(blob->path());
     562    }
     563
     564    void writeFile(v8::Handle<v8::Value> value)
     565    {
     566        File* file = V8File::toNative(value.As<v8::Object>());
     567        if (!file)
     568            return;
     569        m_writer.writeFile(file->path());
     570    }
     571
     572    void writeFileList(v8::Handle<v8::Value> value)
     573    {
     574        FileList* fileList = V8FileList::toNative(value.As<v8::Object>());
     575        if (!fileList)
     576            return;
     577        m_writer.writeFileList(*fileList);
     578    }
     579
    507580    void writeImageData(v8::Handle<v8::Value> value)
    508581    {
     
    556629    else if (value->IsArray())
    557630        return push(newArrayState(value.As<v8::Array>(), next));
     631    else if (V8File::HasInstance(value))
     632        writeFile(value);
     633    else if (V8Blob::HasInstance(value))
     634        writeBlob(value);
     635    else if (V8FileList::HasInstance(value))
     636        writeFileList(value);
    558637    else if (V8ImageData::HasInstance(value))
    559638        writeImageData(value);
     
    629708                return false;
    630709            break;
     710        case BlobTag:
     711            if (!readBlob(value))
     712                return false;
     713            break;
     714        case FileTag:
     715            if (!readFile(value))
     716                return false;
     717            break;
     718        case FileListTag:
     719            if (!readFileList(value))
     720                return false;
     721            break;
    631722        case ImageDataTag:
    632723            if (!readImageData(value))
     
    683774            return false;
    684775        *value = v8::String::New(reinterpret_cast<const char*>(m_buffer + m_position), length);
     776        m_position += length;
     777        return true;
     778    }
     779
     780    bool readWebCoreString(String* string)
     781    {
     782        uint32_t length;
     783        if (!doReadUint32(&length))
     784            return false;
     785        if (m_position + length > m_length)
     786            return false;
     787        *string = String::fromUTF8(reinterpret_cast<const char*>(m_buffer + m_position), length);
    685788        m_position += length;
    686789        return true;
     
    743846        m_position += pixelDataLength;
    744847        *value = toV8(imageData);
     848        return true;
     849    }
     850
     851    bool readBlob(v8::Handle<v8::Value>* value)
     852    {
     853        String path;
     854        if (!readWebCoreString(&path))
     855            return false;
     856        PassRefPtr<Blob> blob = Blob::create(path);
     857        *value = toV8(blob);
     858        return true;
     859    }
     860
     861    bool readFile(v8::Handle<v8::Value>* value)
     862    {
     863        String path;
     864        if (!readWebCoreString(&path))
     865            return false;
     866        PassRefPtr<File> file = File::create(path);
     867        *value = toV8(file);
     868        return true;
     869    }
     870
     871    bool readFileList(v8::Handle<v8::Value>* value)
     872    {
     873        uint32_t length;
     874        if (!doReadUint32(&length))
     875            return false;
     876        PassRefPtr<FileList> fileList = FileList::create();
     877        for (unsigned i = 0; i < length; ++i) {
     878            String path;
     879            if (!readWebCoreString(&path))
     880                return false;
     881            fileList->append(File::create(path));
     882        }
     883        *value = toV8(fileList);
    745884        return true;
    746885    }
     
    8931032    else {
    8941033        ASSERT(mode == StringValue);
    895         RefPtr<SharedBuffer> buffer = utf8Buffer(data);
    8961034        Writer writer;
    897         writer.writeString(buffer->data(), buffer->size());
     1035        writer.writeWebCoreString(data);
    8981036        m_data = StringImpl::adopt(writer.data());
    8991037    }
Note: See TracChangeset for help on using the changeset viewer.