https://bugs.webkit.org/show_bug.cgi?id=70120
authordslomov@google.com <dslomov@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Oct 2011 22:13:00 +0000 (22:13 +0000)
committerdslomov@google.com <dslomov@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Oct 2011 22:13:00 +0000 (22:13 +0000)
[Chromium] Pass MessagePortArray to SerializedScriptValue::serialize/deserialize.
This patch augments SerializedScriptValue with MessagePortArray* parameter to implement MessagePort
transfer within the message in the future.

Reviewed by David Levin.

Source/WebCore:

* bindings/scripts/CodeGeneratorV8.pm:
(GenerateParametersCheck):
* bindings/v8/SerializedScriptValue.cpp:
(WebCore::SerializedScriptValue::create):
(WebCore::SerializedScriptValue::SerializedScriptValue):
(WebCore::SerializedScriptValue::deserialize):
* bindings/v8/SerializedScriptValue.h:
* bindings/v8/custom/V8DOMWindowCustom.cpp:
(WebCore::handlePostMessageCallback):
(WebCore::V8DOMWindow::postMessageCallback):
(WebCore::V8DOMWindow::webkitPostMessageCallback):
* bindings/v8/custom/V8DedicatedWorkerContextCustom.cpp:
(WebCore::handlePostMessageCallback):
(WebCore::V8DedicatedWorkerContext::postMessageCallback):
(WebCore::V8DedicatedWorkerContext::webkitPostMessageCallback):
* bindings/v8/custom/V8HistoryCustom.cpp:
(WebCore::V8History::pushStateCallback):
(WebCore::V8History::replaceStateCallback):
* bindings/v8/custom/V8MessageEventCustom.cpp:
(WebCore::V8MessageEvent::dataAccessorGetter):
* bindings/v8/custom/V8MessagePortCustom.cpp:
(WebCore::handlePostMessageCallback):
(WebCore::V8MessagePort::postMessageCallback):
(WebCore::V8MessagePort::webkitPostMessageCallback):
* bindings/v8/custom/V8WorkerCustom.cpp:
(WebCore::handlePostMessageCallback):
(WebCore::V8Worker::postMessageCallback):
(WebCore::V8Worker::webkitPostMessageCallback):
* workers/Worker.idl:

Source/WebKit/chromium:

* src/WebSerializedScriptValue.cpp:
(WebKit::WebSerializedScriptValue::serialize):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@97516 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
Source/WebCore/ChangeLog
Source/WebCore/bindings/scripts/CodeGeneratorV8.pm
Source/WebCore/bindings/v8/SerializedScriptValue.cpp
Source/WebCore/bindings/v8/SerializedScriptValue.h
Source/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp
Source/WebCore/bindings/v8/custom/V8DedicatedWorkerContextCustom.cpp
Source/WebCore/bindings/v8/custom/V8HistoryCustom.cpp
Source/WebCore/bindings/v8/custom/V8MessageEventCustom.cpp
Source/WebCore/bindings/v8/custom/V8MessagePortCustom.cpp
Source/WebCore/bindings/v8/custom/V8WorkerCustom.cpp
Source/WebCore/workers/Worker.idl
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/src/WebSerializedScriptValue.cpp

index f0daa39..6b8aa9e 100644 (file)
@@ -1,3 +1,42 @@
+2011-10-14  Dmitry Lomov  <dslomov@google.com>
+
+        https://bugs.webkit.org/show_bug.cgi?id=70120
+        [Chromium] Pass MessagePortArray to SerializedScriptValue::serialize/deserialize.
+        This patch augments SerializedScriptValue with MessagePortArray* parameter to implement MessagePort 
+        transfer within the message in the future.
+
+        Reviewed by David Levin.
+
+        * bindings/scripts/CodeGeneratorV8.pm:
+        (GenerateParametersCheck):
+        * bindings/v8/SerializedScriptValue.cpp:
+        (WebCore::SerializedScriptValue::create):
+        (WebCore::SerializedScriptValue::SerializedScriptValue):
+        (WebCore::SerializedScriptValue::deserialize):
+        * bindings/v8/SerializedScriptValue.h:
+        * bindings/v8/custom/V8DOMWindowCustom.cpp:
+        (WebCore::handlePostMessageCallback):
+        (WebCore::V8DOMWindow::postMessageCallback):
+        (WebCore::V8DOMWindow::webkitPostMessageCallback):
+        * bindings/v8/custom/V8DedicatedWorkerContextCustom.cpp:
+        (WebCore::handlePostMessageCallback):
+        (WebCore::V8DedicatedWorkerContext::postMessageCallback):
+        (WebCore::V8DedicatedWorkerContext::webkitPostMessageCallback):
+        * bindings/v8/custom/V8HistoryCustom.cpp:
+        (WebCore::V8History::pushStateCallback):
+        (WebCore::V8History::replaceStateCallback):
+        * bindings/v8/custom/V8MessageEventCustom.cpp:
+        (WebCore::V8MessageEvent::dataAccessorGetter):
+        * bindings/v8/custom/V8MessagePortCustom.cpp:
+        (WebCore::handlePostMessageCallback):
+        (WebCore::V8MessagePort::postMessageCallback):
+        (WebCore::V8MessagePort::webkitPostMessageCallback):
+        * bindings/v8/custom/V8WorkerCustom.cpp:
+        (WebCore::handlePostMessageCallback):
+        (WebCore::V8Worker::postMessageCallback):
+        (WebCore::V8Worker::webkitPostMessageCallback):
+        * workers/Worker.idl:
+
 2011-10-14  Jeff Miller  <jeffm@apple.com>
 
         InjectedBundleHitTestResult::imageRect() should return rect in WKView coordinates
index f2f4dad..71ace6f 100644 (file)
@@ -1458,7 +1458,7 @@ sub GenerateParametersCheck
         } elsif ($parameter->type eq "SerializedScriptValue") {
             AddToImplIncludes("SerializedScriptValue.h");
             $parameterCheckString .= "    bool ${parameterName}DidThrow = false;\n";
-            $parameterCheckString .= "    $nativeType $parameterName = SerializedScriptValue::create(args[$paramIndex], ${parameterName}DidThrow);\n";
+            $parameterCheckString .= "    $nativeType $parameterName = SerializedScriptValue::create(args[$paramIndex], 0, ${parameterName}DidThrow);\n";
             $parameterCheckString .= "    if (${parameterName}DidThrow)\n";
             $parameterCheckString .= "        return v8::Undefined();\n";
         } elsif (TypeCanFailConversion($parameter)) {
index 2d9d0cd..e5ecf36 100644 (file)
@@ -46,6 +46,7 @@
 #include "Int16Array.h"
 #include "Int32Array.h"
 #include "Int8Array.h"
+#include "MessagePort.h"
 #include "SharedBuffer.h"
 #include "Uint16Array.h"
 #include "Uint32Array.h"
@@ -1840,7 +1841,6 @@ private:
 };
 
 } // namespace
-
 void SerializedScriptValue::deserializeAndSetProperty(v8::Handle<v8::Object> object, const char* propertyName,
                                                       v8::PropertyAttribute attribute, SerializedScriptValue* value)
 {
@@ -1856,15 +1856,15 @@ void SerializedScriptValue::deserializeAndSetProperty(v8::Handle<v8::Object> obj
     deserializeAndSetProperty(object, propertyName, attribute, value.get());
 }
 
-PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(v8::Handle<v8::Value> value, bool& didThrow)
+PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(v8::Handle<v8::Value> value, MessagePortArray* messagePorts, bool& didThrow)
 {
-    return adoptRef(new SerializedScriptValue(value, didThrow));
+    return adoptRef(new SerializedScriptValue(value, messagePorts, didThrow));
 }
 
 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(v8::Handle<v8::Value> value)
 {
     bool didThrow;
-    return adoptRef(new SerializedScriptValue(value, didThrow));
+    return adoptRef(new SerializedScriptValue(value, 0, didThrow));
 }
 
 PassRefPtr<SerializedScriptValue> SerializedScriptValue::createFromWire(const String& data)
@@ -1920,7 +1920,7 @@ SerializedScriptValue::SerializedScriptValue()
 {
 }
 
-SerializedScriptValue::SerializedScriptValue(v8::Handle<v8::Value> value, bool& didThrow)
+SerializedScriptValue::SerializedScriptValue(v8::Handle<v8::Value> value, MessagePortArray*, bool& didThrow)
 {
     didThrow = false;
     Writer writer;
@@ -1965,7 +1965,7 @@ SerializedScriptValue::SerializedScriptValue(const String& wireData)
     m_data = wireData.crossThreadString();
 }
 
-v8::Handle<v8::Value> SerializedScriptValue::deserialize()
+v8::Handle<v8::Value> SerializedScriptValue::deserialize(MessagePortArray*)
 {
     if (!m_data.impl())
         return v8::Null();
index 4d2492d..a559cf9 100644 (file)
 
 namespace WebCore {
 
+class MessagePort;
+
+typedef Vector<RefPtr<MessagePort>, 1> MessagePortArray;
+
 class SerializedScriptValue : public ThreadSafeRefCounted<SerializedScriptValue> {
 public:
     static void deserializeAndSetProperty(v8::Handle<v8::Object>, const char* propertyName,
@@ -49,7 +53,7 @@ public:
     // be thrown using v8::ThrowException(), and sets |didThrow|. In this case
     // the caller must not invoke any V8 operations until control returns to
     // V8. When serialization is successful, |didThrow| is false.
-    static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value> value, bool& didThrow);
+    static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>, MessagePortArray*, bool& didThrow);
     static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>);
     static PassRefPtr<SerializedScriptValue> createFromWire(const String& data);
     static PassRefPtr<SerializedScriptValue> create(const String& data);
@@ -64,7 +68,7 @@ public:
 
     // Deserializes the value (in the current context). Returns a null value in
     // case of failure.
-    v8::Handle<v8::Value> deserialize();
+    v8::Handle<v8::Value> deserialize(MessagePortArray* = 0);
 
 private:
     enum StringDataMode {
@@ -73,7 +77,7 @@ private:
     };
 
     SerializedScriptValue();
-    SerializedScriptValue(v8::Handle<v8::Value>, bool& didThrow);
+    SerializedScriptValue(v8::Handle<v8::Value>, MessagePortArray*, bool& didThrow);
     explicit SerializedScriptValue(const String& wireData);
 
     String m_data;
index 49105e2..3a3e7a5 100644 (file)
@@ -313,35 +313,36 @@ v8::Handle<v8::Value> V8DOMWindow::removeEventListenerCallback(const v8::Argumen
     return v8::Undefined();
 }
 
-static v8::Handle<v8::Value> handlePostMessageCallback(const v8::Arguments& args)
+static v8::Handle<v8::Value> handlePostMessageCallback(const v8::Arguments& args, bool doTransfer)
 {
     DOMWindow* window = V8DOMWindow::toNative(args.Holder());
 
     DOMWindow* source = V8Proxy::retrieveFrameForCallingContext()->domWindow();
     ASSERT(source->frame());
 
-    bool didThrow = false;
-    RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(args[0], didThrow);
-    if (didThrow)
-        return v8::Undefined();
-
-    MessagePortArray portArray;
-    String targetOrigin;
-
     // This function has variable arguments and can either be:
     //   postMessage(message, port, targetOrigin);
     // or
     //   postMessage(message, targetOrigin);
-    v8::TryCatch tryCatch;
-    if (args.Length() > 2) {
-        if (!getMessagePortArray(args[1], portArray))
+    MessagePortArray portArray;
+    String targetOrigin;
+    {
+        v8::TryCatch tryCatch;
+        if (args.Length() > 2) {
+            if (!getMessagePortArray(args[1], portArray))
+                return v8::Undefined();
+            targetOrigin = toWebCoreStringWithNullOrUndefinedCheck(args[2]);
+        } else
+            targetOrigin = toWebCoreStringWithNullOrUndefinedCheck(args[1]);
+
+        if (tryCatch.HasCaught())
             return v8::Undefined();
-        targetOrigin = toWebCoreStringWithNullOrUndefinedCheck(args[2]);
-    } else {
-        targetOrigin = toWebCoreStringWithNullOrUndefinedCheck(args[1]);
     }
 
-    if (tryCatch.HasCaught())
+
+    bool didThrow = false;
+    RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(args[0], doTransfer ? &portArray : 0, didThrow);
+    if (didThrow)
         return v8::Undefined();
 
     ExceptionCode ec = 0;
@@ -352,13 +353,13 @@ static v8::Handle<v8::Value> handlePostMessageCallback(const v8::Arguments& args
 v8::Handle<v8::Value> V8DOMWindow::postMessageCallback(const v8::Arguments& args)
 {
     INC_STATS("DOM.DOMWindow.postMessage()");
-    return handlePostMessageCallback(args);
+    return handlePostMessageCallback(args, false);
 }
 
 v8::Handle<v8::Value> V8DOMWindow::webkitPostMessageCallback(const v8::Arguments& args)
 {
     INC_STATS("DOM.DOMWindow.webkitPostMessage()");
-    return handlePostMessageCallback(args);
+    return handlePostMessageCallback(args, true);
 }
 
 // FIXME(fqian): returning string is cheating, and we should
index c38573a..95a69d4 100644 (file)
 
 namespace WebCore {
 
-static v8::Handle<v8::Value> handlePostMessageCallback(const v8::Arguments& args)
+static v8::Handle<v8::Value> handlePostMessageCallback(const v8::Arguments& args, bool doTransfer)
 {
     DedicatedWorkerContext* workerContext = V8DedicatedWorkerContext::toNative(args.Holder());
-    bool didThrow = false;
-    RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(args[0], didThrow);
-    if (didThrow)
-        return v8::Undefined();
     MessagePortArray portArray;
     if (args.Length() > 1) {
         if (!getMessagePortArray(args[1], portArray))
             return v8::Undefined();
     }
-    ExceptionCode ec = 0;
+    bool didThrow = false;
+    RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(args[0], doTransfer ? &portArray : 0, didThrow);
+    if (didThrow)
+        return v8::Undefined();
+     ExceptionCode ec = 0;
     workerContext->postMessage(message.release(), &portArray, ec);
     return throwError(ec);
 }
@@ -62,13 +62,13 @@ static v8::Handle<v8::Value> handlePostMessageCallback(const v8::Arguments& args
 v8::Handle<v8::Value> V8DedicatedWorkerContext::postMessageCallback(const v8::Arguments& args)
 {
     INC_STATS(L"DOM.DedicatedWorkerContext.postMessage");
-    return handlePostMessageCallback(args);
+    return handlePostMessageCallback(args, false);
 }
 
 v8::Handle<v8::Value> V8DedicatedWorkerContext::webkitPostMessageCallback(const v8::Arguments& args)
 {
     INC_STATS(L"DOM.DedicatedWorkerContext.postMessage");
-    return handlePostMessageCallback(args);
+    return handlePostMessageCallback(args, true);
 }
 
 } // namespace WebCore
index ad2b9a9..bf9815a 100644 (file)
@@ -44,7 +44,7 @@ namespace WebCore {
 v8::Handle<v8::Value> V8History::pushStateCallback(const v8::Arguments& args)
 {
     bool didThrow = false;
-    RefPtr<SerializedScriptValue> historyState = SerializedScriptValue::create(args[0], didThrow);
+    RefPtr<SerializedScriptValue> historyState = SerializedScriptValue::create(args[0], 0, didThrow);
     if (didThrow)
         return v8::Undefined();
 
@@ -68,7 +68,7 @@ v8::Handle<v8::Value> V8History::pushStateCallback(const v8::Arguments& args)
 v8::Handle<v8::Value> V8History::replaceStateCallback(const v8::Arguments& args)
 {
     bool didThrow = false;
-    RefPtr<SerializedScriptValue> historyState = SerializedScriptValue::create(args[0], didThrow);
+    RefPtr<SerializedScriptValue> historyState = SerializedScriptValue::create(args[0], 0, didThrow);
     if (didThrow)
         return v8::Undefined();
 
index 6047cdd..f693cd7 100644 (file)
@@ -53,7 +53,7 @@ v8::Handle<v8::Value> V8MessageEvent::dataAccessorGetter(v8::Local<v8::String> n
     switch (event->dataType()) {
     case MessageEvent::DataTypeSerializedScriptValue:
         if (SerializedScriptValue* serializedValue = event->dataAsSerializedScriptValue())
-            result = serializedValue->deserialize();
+            result = serializedValue->deserialize(event->ports());
         else
             result = v8::Null();
         break;
index 5543a1b..dd997b1 100644 (file)
 
 namespace WebCore {
 
-static v8::Handle<v8::Value> handlePostMessageCallback(const v8::Arguments& args)
+static v8::Handle<v8::Value> handlePostMessageCallback(const v8::Arguments& args, bool doTransfer)
 {
     MessagePort* messagePort = V8MessagePort::toNative(args.Holder());
-    bool didThrow = false;
-    RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(args[0], didThrow);
-    if (didThrow)
-        return v8::Undefined();
     MessagePortArray portArray;
     if (args.Length() > 1) {
         if (!getMessagePortArray(args[1], portArray))
             return v8::Undefined();
     }
+    bool didThrow = false;
+    RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(args[0], doTransfer ? &portArray : 0, didThrow);
+    if (didThrow)
+        return v8::Undefined();
     ExceptionCode ec = 0;
     messagePort->postMessage(message.release(), &portArray, ec);
     return throwError(ec);
@@ -62,13 +62,13 @@ static v8::Handle<v8::Value> handlePostMessageCallback(const v8::Arguments& args
 v8::Handle<v8::Value> V8MessagePort::postMessageCallback(const v8::Arguments& args)
 {
     INC_STATS("DOM.MessagePort.postMessage");
-    return handlePostMessageCallback(args);
+    return handlePostMessageCallback(args, false);
 }
 
 v8::Handle<v8::Value> V8MessagePort::webkitPostMessageCallback(const v8::Arguments& args)
 {
     INC_STATS("DOM.MessagePort.webkitPostMessage");
-    return handlePostMessageCallback(args);
+    return handlePostMessageCallback(args, true);
 }
 
 bool getMessagePortArray(v8::Local<v8::Value> value, MessagePortArray& portArray)
index a84120a..430972b 100644 (file)
 
 namespace WebCore {
 
-static v8::Handle<v8::Value> handlePostMessageCallback(const v8::Arguments& args)
+static v8::Handle<v8::Value> handlePostMessageCallback(const v8::Arguments& args, bool doTransfer)
 {
     INC_STATS("DOM.Worker.postMessage");
     Worker* worker = V8Worker::toNative(args.Holder());
-    bool didThrow = false;
-    RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(args[0], didThrow);
-    if (didThrow)
-        return v8::Undefined();
     MessagePortArray portArray;
     if (args.Length() > 1) {
         if (!getMessagePortArray(args[1], portArray))
             return v8::Undefined();
     }
+    bool didThrow = false;
+    RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(args[0], doTransfer ? &portArray : 0, didThrow);
+    if (didThrow)
+        return v8::Undefined();
     ExceptionCode ec = 0;
     worker->postMessage(message.release(), &portArray, ec);
     return throwError(ec);
@@ -68,13 +68,13 @@ static v8::Handle<v8::Value> handlePostMessageCallback(const v8::Arguments& args
 v8::Handle<v8::Value> V8Worker::postMessageCallback(const v8::Arguments& args)
 {
     INC_STATS("DOM.Worker.postMessage");
-    return handlePostMessageCallback(args);
+    return handlePostMessageCallback(args, false);
 }
 
 v8::Handle<v8::Value> V8Worker::webkitPostMessageCallback(const v8::Arguments& args)
 {
     INC_STATS("DOM.Worker.webkitPostMessage");
-    return handlePostMessageCallback(args);
+    return handlePostMessageCallback(args, true);
 }
 
 
index 088db8e..46e7ed8 100644 (file)
@@ -44,9 +44,9 @@ module threads {
         attribute EventListener onmessage;
 
 #if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT
-        [Custom] void postMessage(in SerialisedScriptValue message, in [Optional] Array messagePorts)
+        [Custom] void postMessage(in SerializedScriptValue message, in [Optional] Array messagePorts)
             raises(DOMException);
-        [Custom] void webkitPostMessage(in SerialisedScriptValue message, in [Optional] Array messagePorts)
+        [Custom] void webkitPostMessage(in SerializedScriptValue message, in [Optional] Array messagePorts)
             raises(DOMException);
 #else
         // There's no good way to expose an array via the ObjC bindings, so for now just allow passing in a single port.
index 39278bc..1a228ed 100644 (file)
@@ -1,3 +1,15 @@
+2011-10-14  Dmitry Lomov  <dslomov@google.com>
+
+        https://bugs.webkit.org/show_bug.cgi?id=70120
+        [Chromium] Pass MessagePortArray to SerializedScriptValue::serialize/deserialize.
+        This patch augments SerializedScriptValue with MessagePortArray* parameter to implement MessagePort 
+        transfer within the message in the future.
+
+        Reviewed by David Levin.
+
+        * src/WebSerializedScriptValue.cpp:
+        (WebKit::WebSerializedScriptValue::serialize):
+
 2011-10-14  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed.  Rolled DEPS.
index e1997eb..9f3bc63 100644 (file)
@@ -47,7 +47,7 @@ WebSerializedScriptValue WebSerializedScriptValue::fromString(const WebString& s
 WebSerializedScriptValue WebSerializedScriptValue::serialize(v8::Handle<v8::Value> value)
 {
     bool didThrow;
-    WebSerializedScriptValue serializedValue = SerializedScriptValue::create(value, didThrow);
+    WebSerializedScriptValue serializedValue = SerializedScriptValue::create(value, 0, didThrow);
     if (didThrow)
         return createInvalid();
     return serializedValue;