Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: content/renderer/webworker_proxy.cc

Issue 7477027: Support Transferable objects (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Update for interface changes. Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/renderer/webworker_proxy.h ('k') | content/worker/webworker_stub.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifdef WebTransferableReceipt_h
20 using WebKit::WebMessagePortReceipt;
21 #endif
22 using WebKit::WebTransferableReceiptArray;
23 using WebKit::WebSerializedScriptValue;
19 using WebKit::WebString; 24 using WebKit::WebString;
20 using WebKit::WebURL; 25 using WebKit::WebURL;
21 using WebKit::WebWorkerClient; 26 using WebKit::WebWorkerClient;
22 27
23 WebWorkerProxy::WebWorkerProxy( 28 WebWorkerProxy::WebWorkerProxy(
24 WebWorkerClient* client, 29 WebWorkerClient* client,
25 ChildThread* child_thread, 30 ChildThread* child_thread,
26 int render_view_route_id, 31 int render_view_route_id,
27 int parent_appcache_host_id) 32 int parent_appcache_host_id)
28 : WebWorkerBase( 33 : WebWorkerBase(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 65
61 void WebWorkerProxy::terminateWorkerContext() { 66 void WebWorkerProxy::terminateWorkerContext() {
62 if (route_id_ != MSG_ROUTING_NONE) { 67 if (route_id_ != MSG_ROUTING_NONE) {
63 Send(new WorkerMsg_TerminateWorkerContext(route_id_)); 68 Send(new WorkerMsg_TerminateWorkerContext(route_id_));
64 CancelCreation(); 69 CancelCreation();
65 Disconnect(); 70 Disconnect();
66 } 71 }
67 } 72 }
68 73
69 void WebWorkerProxy::postMessageToWorkerContext( 74 void WebWorkerProxy::postMessageToWorkerContext(
70 const WebString& message, const WebMessagePortChannelArray& channels) { 75 const WebString& raw_message,
71 std::vector<int> message_port_ids(channels.size()); 76 const WebTransferableReceiptArray& receipts) {
72 std::vector<int> routing_ids(channels.size()); 77 size_t unflattenable_count;
73 for (size_t i = 0; i < channels.size(); ++i) { 78 #ifndef WebTransferableReceipt_h
74 WebMessagePortChannelImpl* webchannel = 79 WebString message = raw_message;
75 static_cast<WebMessagePortChannelImpl*>(channels[i]); 80 unflattenable_count = receipts.size();
76 message_port_ids[i] = webchannel->message_port_id(); 81 #else
77 webchannel->QueueMessages(); 82 WebString message = WebSerializedScriptValue::flattenReceiptList(
78 routing_ids[i] = MSG_ROUTING_NONE; 83 raw_message, receipts, &unflattenable_count);
79 DCHECK(message_port_ids[i] != MSG_ROUTING_NONE); 84 #endif
85 std::vector<int> message_port_ids(unflattenable_count);
86 std::vector<int> routing_ids(unflattenable_count);
87 size_t next_unflattenable = 0;
88 for (size_t i = 0; i < receipts.size(); ++i) {
89 #ifndef WebTransferableReceipt_h
90 {
91 #else
92 if (!WebSerializedScriptValue::isFlattenable(receipts[i])) {
93 DCHECK(toWebMessagePortReceipt(receipts[i]));
94 #endif
95 DCHECK(next_unflattenable < unflattenable_count);
96 WebMessagePortChannelImpl* webchannel =
97 #ifndef WebTransferableReceipt_h
98 static_cast<WebMessagePortChannelImpl*>(receipts[i]);
99 #else
100 static_cast<WebMessagePortChannelImpl*>(
101 static_cast<WebMessagePortReceipt*>(receipts[i])->channel());
102 #endif
103 message_port_ids[next_unflattenable] = webchannel->message_port_id();
104 webchannel->QueueMessages();
105 routing_ids[next_unflattenable] = MSG_ROUTING_NONE;
106 DCHECK(message_port_ids[next_unflattenable] != MSG_ROUTING_NONE);
107 ++next_unflattenable;
108 }
80 } 109 }
81 110 DCHECK(next_unflattenable == unflattenable_count);
82 Send(new WorkerMsg_PostMessage( 111 Send(new WorkerMsg_PostMessage(
83 route_id_, message, message_port_ids, routing_ids)); 112 route_id_, message, message_port_ids, routing_ids));
84 } 113 }
85 114
86 void WebWorkerProxy::workerObjectDestroyed() { 115 void WebWorkerProxy::workerObjectDestroyed() {
87 Send(new WorkerMsg_WorkerObjectDestroyed(route_id_)); 116 Send(new WorkerMsg_WorkerObjectDestroyed(route_id_));
88 delete this; 117 delete this;
89 } 118 }
90 119
91 void WebWorkerProxy::clientDestroyed() { 120 void WebWorkerProxy::clientDestroyed() {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 // The worker is created - now send off the CreateWorkerContext message and 166 // The worker is created - now send off the CreateWorkerContext message and
138 // any other queued messages 167 // any other queued messages
139 SendQueuedMessages(); 168 SendQueuedMessages();
140 } 169 }
141 170
142 void WebWorkerProxy::OnPostMessage( 171 void WebWorkerProxy::OnPostMessage(
143 const string16& message, 172 const string16& message,
144 const std::vector<int>& sent_message_port_ids, 173 const std::vector<int>& sent_message_port_ids,
145 const std::vector<int>& new_routing_ids) { 174 const std::vector<int>& new_routing_ids) {
146 DCHECK(new_routing_ids.size() == sent_message_port_ids.size()); 175 DCHECK(new_routing_ids.size() == sent_message_port_ids.size());
147 WebMessagePortChannelArray channels(sent_message_port_ids.size()); 176 WebTransferableReceiptArray receipts(sent_message_port_ids.size());
148 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) { 177 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) {
149 channels[i] = new WebMessagePortChannelImpl( 178 WebMessagePortChannelImpl* impl = new WebMessagePortChannelImpl(
150 new_routing_ids[i], sent_message_port_ids[i]); 179 new_routing_ids[i], sent_message_port_ids[i]);
180 #ifndef WebTransferableReceipt_h
181 receipts[i] = impl;
182 #else
183 receipts[i] = new WebMessagePortReceipt(impl);
184 #endif
151 } 185 }
152 186
153 client_->postMessageToWorkerObject(message, channels); 187 client_->postMessageToWorkerObject(message, receipts);
188
189 #ifdef WebTransferableReceipt_h
190 for (size_t i = 0; i < receipts.size(); ++i) {
191 delete receipts[i];
192 receipts[i] = 0;
193 }
194 #endif
154 } 195 }
155 196
156 void WebWorkerProxy::OnPostConsoleMessageToWorkerObject( 197 void WebWorkerProxy::OnPostConsoleMessageToWorkerObject(
157 const WorkerHostMsg_PostConsoleMessageToWorkerObject_Params& params) { 198 const WorkerHostMsg_PostConsoleMessageToWorkerObject_Params& params) {
158 client_->postConsoleMessageToWorkerObject(params.source_identifier, 199 client_->postConsoleMessageToWorkerObject(params.source_identifier,
159 params.message_type, params.message_level, 200 params.message_type, params.message_level,
160 params.message, params.line_number, params.source_url); 201 params.message, params.line_number, params.source_url);
161 } 202 }
162 203
OLDNEW
« no previous file with comments | « content/renderer/webworker_proxy.h ('k') | content/worker/webworker_stub.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698