OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/webworker_proxy.h" | 5 #include "content/renderer/webworker_proxy.h" |
6 | 6 |
7 #include "content/common/child_thread.h" | 7 #include "content/common/child_thread.h" |
8 #include "content/common/content_client.h" | 8 #include "content/common/content_client.h" |
9 #include "content/common/view_messages.h" | 9 #include "content/common/view_messages.h" |
10 #include "content/common/webmessageportchannel_impl.h" | 10 #include "content/common/webmessageportchannel_impl.h" |
11 #include "content/common/worker_messages.h" | 11 #include "content/common/worker_messages.h" |
12 #include "content/renderer/worker_devtools_agent_proxy.h" | 12 #include "content/renderer/worker_devtools_agent_proxy.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSerializedScriptVa
lue.h" |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWorkerClient.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWorkerClient.h" |
15 | 16 |
16 using WebKit::WebCommonWorkerClient; | 17 using WebKit::WebCommonWorkerClient; |
17 using WebKit::WebMessagePortChannel; | 18 using WebKit::WebMessagePortChannel; |
18 using WebKit::WebMessagePortChannelArray; | 19 using WebKit::WebTransferableReceiptArray; |
| 20 using WebKit::WebSerializedScriptValue; |
19 using WebKit::WebString; | 21 using WebKit::WebString; |
20 using WebKit::WebURL; | 22 using WebKit::WebURL; |
21 using WebKit::WebWorkerClient; | 23 using WebKit::WebWorkerClient; |
22 | 24 |
23 WebWorkerProxy::WebWorkerProxy( | 25 WebWorkerProxy::WebWorkerProxy( |
24 WebWorkerClient* client, | 26 WebWorkerClient* client, |
25 ChildThread* child_thread, | 27 ChildThread* child_thread, |
26 int render_view_route_id, | 28 int render_view_route_id, |
27 int parent_appcache_host_id) | 29 int parent_appcache_host_id) |
28 : WebWorkerBase( | 30 : WebWorkerBase( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 62 |
61 void WebWorkerProxy::terminateWorkerContext() { | 63 void WebWorkerProxy::terminateWorkerContext() { |
62 if (route_id_ != MSG_ROUTING_NONE) { | 64 if (route_id_ != MSG_ROUTING_NONE) { |
63 Send(new WorkerMsg_TerminateWorkerContext(route_id_)); | 65 Send(new WorkerMsg_TerminateWorkerContext(route_id_)); |
64 CancelCreation(); | 66 CancelCreation(); |
65 Disconnect(); | 67 Disconnect(); |
66 } | 68 } |
67 } | 69 } |
68 | 70 |
69 void WebWorkerProxy::postMessageToWorkerContext( | 71 void WebWorkerProxy::postMessageToWorkerContext( |
70 const WebString& message, const WebMessagePortChannelArray& channels) { | 72 const WebString& raw_message, |
71 std::vector<int> message_port_ids(channels.size()); | 73 const WebTransferableReceiptArray& receipts) { |
72 std::vector<int> routing_ids(channels.size()); | 74 size_t unflattenable_count; |
73 for (size_t i = 0; i < channels.size(); ++i) { | 75 #ifndef WebTransferableReceipt_h |
74 WebMessagePortChannelImpl* webchannel = | 76 WebString message = raw_message; |
75 static_cast<WebMessagePortChannelImpl*>(channels[i]); | 77 unflattenable_count = receipts.size(); |
76 message_port_ids[i] = webchannel->message_port_id(); | 78 #else |
77 webchannel->QueueMessages(); | 79 WebString message = WebSerializedScriptValue::flattenReceiptList( |
78 routing_ids[i] = MSG_ROUTING_NONE; | 80 raw_message, receipts, &unflattenable_count); |
79 DCHECK(message_port_ids[i] != MSG_ROUTING_NONE); | 81 #endif |
| 82 std::vector<int> message_port_ids(unflattenable_count); |
| 83 std::vector<int> routing_ids(unflattenable_count); |
| 84 size_t next_unflattenable = 0; |
| 85 for (size_t i = 0; i < receipts.size(); ++i) { |
| 86 #ifndef WebTransferableReceipt_h |
| 87 { |
| 88 #else |
| 89 if (!receipts[i]->isFlattenable()) { |
| 90 DCHECK(receipts[i]->asWebMessagePortChannel()); |
| 91 #endif |
| 92 DCHECK(next_unflattenable < unflattenable_count); |
| 93 WebMessagePortChannelImpl* webchannel = |
| 94 static_cast<WebMessagePortChannelImpl*>(receipts[i]); |
| 95 message_port_ids[next_unflattenable] = webchannel->message_port_id(); |
| 96 webchannel->QueueMessages(); |
| 97 routing_ids[next_unflattenable] = MSG_ROUTING_NONE; |
| 98 DCHECK(message_port_ids[next_unflattenable] != MSG_ROUTING_NONE); |
| 99 ++next_unflattenable; |
| 100 } |
80 } | 101 } |
81 | 102 DCHECK(next_unflattenable == unflattenable_count); |
82 Send(new WorkerMsg_PostMessage( | 103 Send(new WorkerMsg_PostMessage( |
83 route_id_, message, message_port_ids, routing_ids)); | 104 route_id_, message, message_port_ids, routing_ids)); |
84 } | 105 } |
85 | 106 |
86 void WebWorkerProxy::workerObjectDestroyed() { | 107 void WebWorkerProxy::workerObjectDestroyed() { |
87 Send(new WorkerMsg_WorkerObjectDestroyed(route_id_)); | 108 Send(new WorkerMsg_WorkerObjectDestroyed(route_id_)); |
88 delete this; | 109 delete this; |
89 } | 110 } |
90 | 111 |
91 void WebWorkerProxy::clientDestroyed() { | 112 void WebWorkerProxy::clientDestroyed() { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 // The worker is created - now send off the CreateWorkerContext message and | 158 // The worker is created - now send off the CreateWorkerContext message and |
138 // any other queued messages | 159 // any other queued messages |
139 SendQueuedMessages(); | 160 SendQueuedMessages(); |
140 } | 161 } |
141 | 162 |
142 void WebWorkerProxy::OnPostMessage( | 163 void WebWorkerProxy::OnPostMessage( |
143 const string16& message, | 164 const string16& message, |
144 const std::vector<int>& sent_message_port_ids, | 165 const std::vector<int>& sent_message_port_ids, |
145 const std::vector<int>& new_routing_ids) { | 166 const std::vector<int>& new_routing_ids) { |
146 DCHECK(new_routing_ids.size() == sent_message_port_ids.size()); | 167 DCHECK(new_routing_ids.size() == sent_message_port_ids.size()); |
147 WebMessagePortChannelArray channels(sent_message_port_ids.size()); | 168 WebTransferableReceiptArray receipts(sent_message_port_ids.size()); |
148 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) { | 169 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) { |
149 channels[i] = new WebMessagePortChannelImpl( | 170 receipts[i] = new WebMessagePortChannelImpl( |
150 new_routing_ids[i], sent_message_port_ids[i]); | 171 new_routing_ids[i], sent_message_port_ids[i]); |
151 } | 172 } |
152 | 173 |
153 client_->postMessageToWorkerObject(message, channels); | 174 client_->postMessageToWorkerObject(message, receipts); |
154 } | 175 } |
155 | 176 |
156 void WebWorkerProxy::OnPostConsoleMessageToWorkerObject( | 177 void WebWorkerProxy::OnPostConsoleMessageToWorkerObject( |
157 const WorkerHostMsg_PostConsoleMessageToWorkerObject_Params& params) { | 178 const WorkerHostMsg_PostConsoleMessageToWorkerObject_Params& params) { |
158 client_->postConsoleMessageToWorkerObject(params.source_identifier, | 179 client_->postConsoleMessageToWorkerObject(params.source_identifier, |
159 params.message_type, params.message_level, | 180 params.message_type, params.message_level, |
160 params.message, params.line_number, params.source_url); | 181 params.message, params.line_number, params.source_url); |
161 } | 182 } |
162 | 183 |
OLD | NEW |