Changeset 54646 in webkit


Ignore:
Timestamp:
Feb 11, 2010 12:30:34 AM (14 years ago)
Author:
oliver@apple.com
Message:

2010-02-10 Oliver Hunt <oliver@apple.com>

Reviewed by Gavin Barraclough.

postMessage does not send ImageData
https://bugs.webkit.org/show_bug.cgi?id=34825

Add test for postMessage passing ImageData

Update a few other tests to cover the fact that ImageData's constructor
is now available on the window object.

  • fast/dom/Window/window-postmessage-clone-expected.txt:
  • fast/dom/Window/window-postmessage-clone.html:
  • fast/dom/Window/window-properties-expected.txt:
  • fast/dom/Window/window-property-descriptors-expected.txt:
  • fast/dom/prototype-inheritance-2-expected.txt:
  • fast/dom/prototype-inheritance-expected.txt:
  • fast/js/global-constructors-expected.txt:

2010-02-10 Oliver Hunt <oliver@apple.com>

Reviewed by Gavin Barraclough.

postMessage does not send ImageData
https://bugs.webkit.org/show_bug.cgi?id=34825

Implement serialisation of ImageData, and for testing reasons
expose the ImageData constructor (which should already have
been exposed).

  • bindings/js/SerializedScriptValue.cpp: (WebCore::SerializedImageData::create): (WebCore::SerializedImageData::width): (WebCore::SerializedImageData::height): (WebCore::SerializedImageData::data): (WebCore::SerializedImageData::SerializedImageData): (WebCore::SerializedScriptValueData::SerializedScriptValueData): (WebCore::SharedSerializedData::asImageData): (WebCore::SerializingTreeWalker::convertIfTerminal): (WebCore::DeserializingTreeWalker::convertIfTerminal): (WebCore::TeardownTreeWalker::convertIfTerminal):
  • bindings/js/SerializedScriptValue.h: (WebCore::SerializedScriptValueData::): (WebCore::SerializedScriptValueData::asImageData):
  • html/canvas/CanvasPixelArray.h: (WebCore::CanvasPixelArray::data):
  • page/DOMWindow.idl:
Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r54638 r54646  
     12010-02-10  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Gavin Barraclough.
     4
     5        postMessage does not send ImageData
     6        https://bugs.webkit.org/show_bug.cgi?id=34825
     7
     8        Add test for postMessage passing ImageData
     9
     10        Update a few other tests to cover the fact that ImageData's constructor
     11        is now available on the window object.
     12
     13        * fast/dom/Window/window-postmessage-clone-expected.txt:
     14        * fast/dom/Window/window-postmessage-clone.html:
     15        * fast/dom/Window/window-properties-expected.txt:
     16        * fast/dom/Window/window-property-descriptors-expected.txt:
     17        * fast/dom/prototype-inheritance-2-expected.txt:
     18        * fast/dom/prototype-inheritance-expected.txt:
     19        * fast/js/global-constructors-expected.txt:
     20
    1212010-02-10  Beth Dakin  <bdakin@apple.com>
    222
  • trunk/LayoutTests/fast/dom/Window/window-postmessage-clone-expected.txt

    r53774 r54646  
    1919PASS: eventData is [object File] of type object
    2020PASS: eventData is [object FileList] of type object
     21PASS: eventData is [object ImageData] of type object
     22PASS: eventData is [object ImageData] of type object
    2123PASS: eventData is done of type string
    2224
  • trunk/LayoutTests/fast/dom/Window/window-postmessage-clone.html

    r54047 r54646  
    1717function equal(actual, expected)
    1818{
     19    if (actual === expected)
     20        return true;
    1921    if (typeof actual !== typeof expected)
    2022        return false;
    21     if (actual === expected)
    22         return true;
    2323    if ((actual instanceof Date) || (expected instanceof Date)) {
    2424        if ((actual instanceof Date) && (expected instanceof Date))
     
    4141    if (actual.constructor !== expected.constructor)
    4242        return false;
    43     var keys = Object.keys(actual);
     43    try {
     44        var keys = Object.keys(actual);
     45    } catch(e) {
     46        return false;
     47    }
     48    try {
    4449    if (!equal(keys, Object.keys(expected)))
    4550        return false;
     51    } catch(e) {
     52        return false;
     53    }
    4654    for (var i = 0; i < keys.length; i++) {
    4755        if (!equal(actual[keys[i]], expected[keys[i]]))
     
    7684    eventData = evt.data;
    7785    if (evt.data !== evt.data)
    78         console.innerHTML += "MessageEvent.data does not produce the same value on multiple queries.";
     86        console.innerHTML += "MessageEvent.data does not produce the same value on multiple queries.<br>";
    7987    shouldBe("eventData", messages.shift());
    8088
     
    130138tryPostMessage('window', true);
    131139
    132 var fileInput = document.getElementById("fileInput");
    133 var fileRect = fileInput.getClientRects()[0];
    134 var targetX = fileRect.left + fileRect.width / 2;
    135 var targetY = fileRect.top + fileRect.height / 2;
    136 eventSender.beginDragWithFiles(['get-file-upload.html']);
    137 eventSender.mouseMoveTo(targetX, targetY);
    138 eventSender.mouseUp();
    139 tryPostMessage('fileInput.files[0]', false, fileInput.files[0]);
    140 tryPostMessage('fileInput.files', false, fileInput.files);
     140if (window.eventSender) {
     141    var fileInput = document.getElementById("fileInput");
     142    var fileRect = fileInput.getClientRects()[0];
     143    var targetX = fileRect.left + fileRect.width / 2;
     144    var targetY = fileRect.top + fileRect.height / 2;
     145    eventSender.beginDragWithFiles(['get-file-upload.html']);
     146    eventSender.mouseMoveTo(targetX, targetY);
     147    eventSender.mouseUp();
     148    tryPostMessage('fileInput.files[0]', false, fileInput.files[0]);
     149    tryPostMessage('fileInput.files', false, fileInput.files);
     150}
     151var imageData = document.createElement("canvas").getContext("2d").createImageData(10,10);
     152for (var i = 0; i < imageData.data.length * 4; i++)
     153    imageData.data[i] = i % 256;
     154var mutatedImageData = document.createElement("canvas").getContext("2d").createImageData(10,10);
     155for (var i = 0; i < imageData.data.length * 4; i++)
     156    mutatedImageData.data[i] = i % 256;
     157tryPostMessage('imageData', false, imageData);
     158tryPostMessage('mutatedImageData', false, imageData);
     159for (var i = 0; i < imageData.data.length * 4; i++)
     160    mutatedImageData.data[i] = 0;
    141161
    142162tryPostMessage('"done"');
  • trunk/LayoutTests/fast/dom/Window/window-properties-expected.txt

    r54143 r54646  
    10451045window.Image [object ImageConstructor]
    10461046window.Image.prototype [printed above as window.Element.prototype]
     1047window.ImageData [object ImageDataConstructor]
     1048window.ImageData.prototype [object ImageDataPrototype]
    10471049window.KeyboardEvent [object KeyboardEventConstructor]
    10481050window.KeyboardEvent.prototype [printed above as window.Event.prototype]
  • trunk/LayoutTests/fast/dom/Window/window-property-descriptors-expected.txt

    r53727 r54646  
    115115PASS typeof Object.getOwnPropertyDescriptor(window, 'HTMLVideoElement') is 'object'
    116116PASS typeof Object.getOwnPropertyDescriptor(window, 'Image') is 'object'
     117PASS typeof Object.getOwnPropertyDescriptor(window, 'ImageData') is 'object'
    117118PASS typeof Object.getOwnPropertyDescriptor(window, 'Infinity') is 'object'
    118119PASS typeof Object.getOwnPropertyDescriptor(window, 'JSON') is 'object'
  • trunk/LayoutTests/fast/dom/prototype-inheritance-2-expected.txt

    r53722 r54646  
    265265Never found HTMLTableSectionElement
    266266Never found Image
     267Never found ImageData
    267268Never found MessageChannel
    268269Never found MessagePort
  • trunk/LayoutTests/fast/dom/prototype-inheritance-expected.txt

    r53722 r54646  
    216216PASS inner.Image.isInner is true
    217217PASS inner.Image.constructor.isInner is true
     218PASS inner.ImageData.isInner is true
     219PASS inner.ImageData.constructor.isInner is true
    218220PASS inner.KeyboardEvent.isInner is true
    219221PASS inner.KeyboardEvent.constructor.isInner is true
  • trunk/LayoutTests/fast/js/global-constructors-expected.txt

    r53722 r54646  
    108108PASS HTMLVideoElement.toString() is '[object HTMLVideoElementConstructor]'
    109109PASS Image.toString() is '[object ImageConstructor]'
     110PASS ImageData.toString() is '[object ImageDataConstructor]'
    110111PASS KeyboardEvent.toString() is '[object KeyboardEventConstructor]'
    111112PASS MediaError.toString() is '[object MediaErrorConstructor]'
  • trunk/WebCore/ChangeLog

    r54645 r54646  
     12010-02-10  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Gavin Barraclough.
     4
     5        postMessage does not send ImageData
     6        https://bugs.webkit.org/show_bug.cgi?id=34825
     7
     8        Implement serialisation of ImageData, and for testing reasons
     9        expose the ImageData constructor (which should already have
     10        been exposed).
     11
     12        * bindings/js/SerializedScriptValue.cpp:
     13        (WebCore::SerializedImageData::create):
     14        (WebCore::SerializedImageData::width):
     15        (WebCore::SerializedImageData::height):
     16        (WebCore::SerializedImageData::data):
     17        (WebCore::SerializedImageData::SerializedImageData):
     18        (WebCore::SerializedScriptValueData::SerializedScriptValueData):
     19        (WebCore::SharedSerializedData::asImageData):
     20        (WebCore::SerializingTreeWalker::convertIfTerminal):
     21        (WebCore::DeserializingTreeWalker::convertIfTerminal):
     22        (WebCore::TeardownTreeWalker::convertIfTerminal):
     23        * bindings/js/SerializedScriptValue.h:
     24        (WebCore::SerializedScriptValueData::):
     25        (WebCore::SerializedScriptValueData::asImageData):
     26        * html/canvas/CanvasPixelArray.h:
     27        (WebCore::CanvasPixelArray::data):
     28        * page/DOMWindow.idl:
     29
    1302010-02-10  Adam Barth  <abarth@webkit.org>
    231
  • trunk/WebCore/bindings/js/SerializedScriptValue.cpp

    r54023 r54646  
    3030#include "File.h"
    3131#include "FileList.h"
     32#include "ImageData.h"
    3233#include "JSDOMGlobalObject.h"
    3334#include "JSFile.h"
    3435#include "JSFileList.h"
     36#include "JSImageData.h"
    3537#include <JavaScriptCore/APICast.h>
    3638#include <runtime/DateInstance.h>
     
    3840#include <runtime/JSLock.h>
    3941#include <runtime/PropertyNameArray.h>
     42#include <wtf/ByteArray.h>
    4043#include <wtf/HashTraits.h>
    4144#include <wtf/Vector.h>
     
    166169};
    167170
     171class SerializedImageData : public SharedSerializedData {
     172public:
     173    static PassRefPtr<SerializedImageData> create(const ImageData* imageData)
     174    {
     175        return adoptRef(new SerializedImageData(imageData));
     176    }
     177   
     178    unsigned width() const { return m_width; }
     179    unsigned height() const { return m_height; }
     180    WTF::ByteArray* data() const { return m_storage.get(); }
     181private:
     182    SerializedImageData(const ImageData* imageData)
     183        : m_width(imageData->width())
     184        , m_height(imageData->height())
     185    {
     186        WTF::ByteArray* array = imageData->data()->data();
     187        m_storage = WTF::ByteArray::create(array->length());
     188        memcpy(m_storage->data(), array->data(), array->length());
     189    }
     190    unsigned m_width;
     191    unsigned m_height;
     192    RefPtr<WTF::ByteArray> m_storage;
     193};
     194
    168195SerializedScriptValueData::SerializedScriptValueData(RefPtr<SerializedObject> data)
    169196    : m_type(ObjectType)
     
    184211}
    185212
     213SerializedScriptValueData::SerializedScriptValueData(const ImageData* imageData)
     214    : m_type(ImageDataType)
     215    , m_sharedData(SerializedImageData::create(imageData))
     216{
     217}
     218
    186219SerializedScriptValueData::SerializedScriptValueData(const File* file)
    187220    : m_type(FileType)
     
    203236{
    204237    return static_cast<SerializedFileList*>(this);
     238}
     239
     240SerializedImageData* SharedSerializedData::asImageData()
     241{
     242    return static_cast<SerializedImageData*>(this);
    205243}
    206244
     
    534572            if (obj->inherits(&JSFileList::s_info))
    535573                return SerializedScriptValueData(toFileList(obj));
     574            if (obj->inherits(&JSImageData::s_info))
     575                return SerializedScriptValueData(toImageData(obj));
    536576               
    537577            CallData unusedData;
     
    710750                return toJS(m_exec, static_cast<JSDOMGlobalObject*>(m_globalObject), result.get());
    711751            }
     752            case SerializedScriptValueData::ImageDataType: {
     753                if (!m_isDOMGlobalObject)
     754                    return jsNull();
     755                SerializedImageData* serializedImageData = value.asImageData();
     756                RefPtr<ImageData> result = ImageData::create(serializedImageData->width(), serializedImageData->height());
     757                memcpy(result->data()->data()->data(), serializedImageData->data()->data(), serializedImageData->data()->length());
     758                return toJS(m_exec, static_cast<JSDOMGlobalObject*>(m_globalObject), result.get());
     759            }
    712760            case SerializedScriptValueData::EmptyType:
    713761                ASSERT_NOT_REACHED();
     
    869917            case SerializedScriptValueData::FileType:
    870918            case SerializedScriptValueData::FileListType:
     919            case SerializedScriptValueData::ImageDataType:
    871920                return true;
    872921        }
  • trunk/WebCore/bindings/js/SerializedScriptValue.h

    r53969 r54646  
    3636    class File;
    3737    class FileList;
     38    class ImageData;
    3839    class SerializedArray;
    3940    class SerializedFileList;
     41    class SerializedImageData;
    4042    class SerializedObject;
    4143
     
    4648        SerializedObject* asObject();
    4749        SerializedFileList* asFileList();
     50        SerializedImageData* asImageData();
    4851    };
    4952
     
    6164            StringType,
    6265            FileType,
    63             FileListType
     66            FileListType,
     67            ImageDataType
    6468        };
    6569
     
    8791        explicit SerializedScriptValueData(const File*);
    8892        explicit SerializedScriptValueData(const FileList*);
     93        explicit SerializedScriptValueData(const ImageData*);
    8994
    9095        explicit SerializedScriptValueData(JSC::JSValue value)
     
    141146            ASSERT(m_sharedData);
    142147            return m_sharedData->asFileList();
     148        }
     149       
     150        SerializedImageData* asImageData() const
     151        {
     152            ASSERT(m_type == ImageDataType);
     153            ASSERT(m_sharedData);
     154            return m_sharedData->asImageData();
    143155        }
    144156
  • trunk/WebCore/html/canvas/CanvasPixelArray.h

    r49734 r54646  
    4343       
    4444        WTF::ByteArray* data() { return m_data.get(); }
     45        const WTF::ByteArray* data() const { return m_data.get(); }
    4546        unsigned length() const { return m_data->length(); }
    4647       
  • trunk/WebCore/page/DOMWindow.idl

    r54085 r54646  
    442442
    443443        attribute CanvasRenderingContext2DConstructor CanvasRenderingContext2D;
     444        attribute ImageDataConstructor ImageData;
    444445        attribute [Conditional=3D_CANVAS] WebGLRenderingContextConstructor WebGLRenderingContext;
    445446        attribute TextMetricsConstructor TextMetrics;
Note: See TracChangeset for help on using the changeset viewer.