Index: content/common/webmessageportchannel_impl.cc |
diff --git a/content/common/webmessageportchannel_impl.cc b/content/common/webmessageportchannel_impl.cc |
index 6a9ac365498fccc7dcce673f4e78552e853df271..97e39cdc5c14144339d397951894780d4380bdf4 100644 |
--- a/content/common/webmessageportchannel_impl.cc |
+++ b/content/common/webmessageportchannel_impl.cc |
@@ -7,12 +7,18 @@ |
#include "content/common/child_process.h" |
#include "content/common/child_thread.h" |
#include "content/common/worker_messages.h" |
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebSerializedScriptValue.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebMessagePortChannel.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebMessagePortChannelClient.h" |
using WebKit::WebMessagePortChannel; |
-using WebKit::WebMessagePortChannelArray; |
+#ifdef WebTransferableReceipt_h |
+using WebKit::WebMessagePortReceipt; |
+#endif |
+using WebKit::WebTransferableReceiptArray; |
using WebKit::WebMessagePortChannelClient; |
+using WebKit::WebSerializedScriptValue; |
using WebKit::WebString; |
WebMessagePortChannelImpl::WebMessagePortChannelImpl() |
@@ -75,36 +81,68 @@ void WebMessagePortChannelImpl::entangle(WebMessagePortChannel* channel) { |
} |
void WebMessagePortChannelImpl::postMessage( |
- const WebString& message, |
- WebMessagePortChannelArray* channels) { |
+ const WebString& raw_message, |
+ WebTransferableReceiptArray* receipts) { |
if (MessageLoop::current() != ChildThread::current()->message_loop()) { |
ChildThread::current()->message_loop()->PostTask(FROM_HERE, |
NewRunnableMethod(this, &WebMessagePortChannelImpl::postMessage, |
- message, channels)); |
+ raw_message, receipts)); |
return; |
} |
- std::vector<int> message_port_ids(channels ? channels->size() : 0); |
- if (channels) { |
+ size_t unflattenable_count = 0; |
+#ifndef WebTransferableReceipt_h |
+ WebString message = raw_message; |
+ unflattenable_count = receipts ? receipts->size() : 0; |
+#else |
+ WebString message = receipts ? WebSerializedScriptValue::flattenReceiptList( |
+ raw_message, *receipts, &unflattenable_count) : raw_message; |
+#endif |
+ std::vector<int> message_port_ids(unflattenable_count); |
+ size_t next_unflattenable = 0; |
+ if (receipts) { |
// Extract the port IDs from the source array, then free it. |
- for (size_t i = 0; i < channels->size(); ++i) { |
- WebMessagePortChannelImpl* webchannel = |
- static_cast<WebMessagePortChannelImpl*>((*channels)[i]); |
- message_port_ids[i] = webchannel->message_port_id(); |
- webchannel->QueueMessages(); |
- DCHECK(message_port_ids[i] != MSG_ROUTING_NONE); |
+ for (size_t i = 0; i < receipts->size(); ++i) { |
+#ifndef WebTransferableReceipt_h |
+ { |
+#else |
+ if (!WebSerializedScriptValue::isFlattenable((*receipts)[i])) { |
+ DCHECK(toWebMessagePortReceipt((*receipts)[i])); |
+#endif |
+ DCHECK(next_unflattenable < unflattenable_count); |
+ WebMessagePortChannelImpl* webchannel = |
+#ifndef WebTransferableReceipt_h |
+ static_cast<WebMessagePortChannelImpl*>((*receipts)[i]); |
+#else |
+ static_cast<WebMessagePortChannelImpl*>( |
+ static_cast<WebMessagePortReceipt*>((*receipts)[i])->channel()); |
+#endif |
+ message_port_ids[next_unflattenable] = webchannel->message_port_id(); |
+ webchannel->QueueMessages(); |
+ DCHECK(message_port_ids[next_unflattenable] != MSG_ROUTING_NONE); |
+ ++next_unflattenable; |
+ } |
+#ifdef WebTransferableReceipt_h |
+ delete ((*receipts)[i]); |
+ (*receipts)[i] = 0; |
+#endif |
} |
- delete channels; |
+ delete receipts; |
} |
+ DCHECK(next_unflattenable == unflattenable_count); |
IPC::Message* msg = new WorkerProcessHostMsg_PostMessage( |
message_port_id_, message, message_port_ids); |
Send(msg); |
} |
+#ifndef WebTransferableReceipt_h |
bool WebMessagePortChannelImpl::tryGetMessage( |
+#else |
+bool WebMessagePortChannelImpl::tryGetMessageWithNewReceipts( |
+#endif |
WebString* message, |
- WebMessagePortChannelArray& channels) { |
+ WebTransferableReceiptArray& receipts) { |
base::AutoLock auto_lock(lock_); |
if (message_queue_.empty()) |
return false; |
@@ -112,12 +150,16 @@ bool WebMessagePortChannelImpl::tryGetMessage( |
*message = message_queue_.front().message; |
const std::vector<WebMessagePortChannelImpl*>& channel_array = |
message_queue_.front().ports; |
- WebMessagePortChannelArray result_ports(channel_array.size()); |
+ WebTransferableReceiptArray result_ports(channel_array.size()); |
for (size_t i = 0; i < channel_array.size(); i++) { |
+#ifndef WebTransferableReceipt_h |
result_ports[i] = channel_array[i]; |
+#else |
+ result_ports[i] = new WebMessagePortReceipt(channel_array[i]); |
+#endif |
} |
- channels.swap(result_ports); |
+ receipts.swap(result_ports); |
message_queue_.pop(); |
return true; |
} |