Commit 88ed9c19 authored by oliver@apple.com's avatar oliver@apple.com
Browse files

postMessage should serialize File objects

https://bugs.webkit.org/show_bug.cgi?id=31955

Reviewed by Sam Weinig.

Update SerializedScriptValue to include support for
File objects in the serialized object graph.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@51480 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 521f502c
2009-11-28 Oliver Hunt <oliver@apple.com>
Reviewed by Sam Weinig.
postMessage should serialize File objects
https://bugs.webkit.org/show_bug.cgi?id=31955
Add test for postMessage serialization of File objects.
* fast/dom/Window/window-postmessage-clone-expected.txt:
* fast/dom/Window/window-postmessage-clone.html:
2009-11-29 Simon Fraser <simon.fraser@apple.com>
 
Rubber-stamped by Eric Seidel.
......@@ -16,5 +16,6 @@ PASS: eventData is ,,1 of type object
PASS: eventData is null of type object
PASS: eventData is 2009-02-13T23:31:30.000Z of type object
PASS: eventData is [object Array](default toString threw RangeError: Maximum call stack size exceeded.) of type object
PASS: eventData is [object File] of type object
PASS: eventData is done of type string
......@@ -3,6 +3,7 @@
<body>
<div id="description"></div>
<div id="console"></div>
<input type="file" id="fileInput"></input>
<script>
if (window.layoutTestController) {
layoutTestController.dumpAsText();
......@@ -123,6 +124,16 @@ for (var i = 0; i < 100000; i++)
tryPostMessage('reallyDeepArray', true);
tryPostMessage('window', true);
var fileInput = document.getElementById("fileInput");
var fileRect = fileInput.getClientRects()[0];
var targetX = fileRect.left + fileRect.width / 2;
var targetY = fileRect.top + fileRect.height / 2;
eventSender.beginDragWithFiles(['get-file-upload.html']);
eventSender.mouseMoveTo(targetX, targetY);
eventSender.mouseUp();
tryPostMessage('fileInput.files[0]', false, fileInput.files[0]);
tryPostMessage('"done"');
</script>
</body>
......
2009-11-28 Oliver Hunt <oliver@apple.com>
Reviewed by Sam Weinig.
postMessage should serialize File objects
https://bugs.webkit.org/show_bug.cgi?id=31955
Update SerializedScriptValue to include support for
File objects in the serialized object graph.
* bindings/js/SerializedScriptValue.cpp:
(WebCore::SerializedScriptValueData::SerializedScriptValueData):
(WebCore::SerializingTreeWalker::convertIfTerminal):
(WebCore::DeserializingTreeWalker::convertIfTerminal):
* bindings/js/SerializedScriptValue.h:
(WebCore::SerializedScriptValueData::):
(WebCore::SerializedScriptValueData::asString):
2009-11-29 Simon Fraser <simon.fraser@apple.com>
 
Reviewed by Dan Bernstein.
......@@ -27,6 +27,10 @@
#include "config.h"
#include "SerializedScriptValue.h"
#include "File.h"
#include "JSDOMGlobalObject.h"
#include "JSFile.h"
#include "JSFileList.h"
#include <JavaScriptCore/APICast.h>
#include <runtime/DateInstance.h>
#include <runtime/ExceptionHelpers.h>
......@@ -149,6 +153,12 @@ SerializedScriptValueData::SerializedScriptValueData(RefPtr<SerializedArray> dat
{
}
SerializedScriptValueData::SerializedScriptValueData(const File* file)
: m_type(FileType)
, m_string(file->path().crossThreadString())
{
}
SerializedArray* SharedSerializedData::asArray()
{
return static_cast<SerializedArray*>(this);
......@@ -482,10 +492,15 @@ struct SerializingTreeWalker : public BaseWalker {
if (isArray(value))
return SerializedScriptValueData();
CallData unusedData;
if (value.isObject() && value.getCallData(unusedData) == CallTypeNone)
return SerializedScriptValueData();
if (value.isObject()) {
JSObject* obj = asObject(value);
if (obj->inherits(&JSFile::s_info))
return SerializedScriptValueData(toFile(obj));
CallData unusedData;
if (value.getCallData(unusedData) == CallTypeNone)
return SerializedScriptValueData();
}
// Any other types are expected to serialize as null.
return SerializedScriptValueData(jsNull());
}
......@@ -641,6 +656,8 @@ struct DeserializingTreeWalker : public BaseWalker {
return jsNumber(m_exec, value.asDouble());
case SerializedScriptValueData::DateType:
return new (m_exec) DateInstance(m_exec, value.asDouble());
case SerializedScriptValueData::FileType:
return toJS(m_exec, static_cast<JSDOMGlobalObject*>(m_exec->lexicalGlobalObject()), File::create(value.asString().crossThreadString()));
default:
ASSERT_NOT_REACHED();
return JSValue();
......
......@@ -33,6 +33,7 @@ typedef const struct OpaqueJSContext* JSContextRef;
typedef const struct OpaqueJSValue* JSValueRef;
namespace WebCore {
class File;
class SerializedObject;
class SerializedArray;
......@@ -54,7 +55,8 @@ namespace WebCore {
ImmediateType,
ObjectType,
ArrayType,
StringType
StringType,
FileType
};
SerializedType type() const { return m_type; }
......@@ -77,6 +79,8 @@ namespace WebCore {
, m_string(string.crossThreadString()) // FIXME: Should be able to just share the Rep
{
}
explicit SerializedScriptValueData(const File*);
explicit SerializedScriptValueData(JSC::JSValue value)
: m_type(ImmediateType)
......@@ -108,7 +112,7 @@ namespace WebCore {
String asString() const
{
ASSERT(m_type == StringType);
ASSERT(m_type == StringType || m_type == FileType);
return m_string;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment