OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/websharedworker_proxy.h" | 5 #include "content/renderer/websharedworker_proxy.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "content/child/webmessageportchannel_impl.h" | 9 #include "content/child/webmessageportchannel_impl.h" |
10 #include "content/common/view_messages.h" | 10 #include "content/common/view_messages.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 // with before the browser process told us that it started, in which case we | 46 // with before the browser process told us that it started, in which case we |
47 // also want to queue the message. | 47 // also want to queue the message. |
48 if (!created_) { | 48 if (!created_) { |
49 queued_messages_.push_back(std::move(message)); | 49 queued_messages_.push_back(std::move(message)); |
50 return true; | 50 return true; |
51 } | 51 } |
52 | 52 |
53 // For now we proxy all messages to the worker process through the browser. | 53 // For now we proxy all messages to the worker process through the browser. |
54 // Revisit if we find this slow. | 54 // Revisit if we find this slow. |
55 // TODO(jabdelmalek): handle sync messages if we need them. | 55 // TODO(jabdelmalek): handle sync messages if we need them. |
56 return router_->Send(new ViewHostMsg_ForwardToWorker(*message)); | 56 return router_->Send(message.release()); |
57 } | 57 } |
58 | 58 |
59 void WebSharedWorkerProxy::SendQueuedMessages() { | 59 void WebSharedWorkerProxy::SendQueuedMessages() { |
60 DCHECK(created_); | 60 DCHECK(created_); |
61 DCHECK(queued_messages_.size()); | 61 DCHECK(queued_messages_.size()); |
62 std::vector<std::unique_ptr<IPC::Message>> queued_messages; | 62 std::vector<std::unique_ptr<IPC::Message>> queued_messages; |
63 queued_messages.swap(queued_messages_); | 63 queued_messages.swap(queued_messages_); |
64 for (size_t i = 0; i < queued_messages.size(); ++i) { | 64 for (size_t i = 0; i < queued_messages.size(); ++i) { |
65 queued_messages[i]->set_routing_id(route_id_); | 65 queued_messages[i]->set_routing_id(route_id_); |
66 Send(std::move(queued_messages[i])); | 66 Send(std::move(queued_messages[i])); |
67 } | 67 } |
68 } | 68 } |
69 | 69 |
70 void WebSharedWorkerProxy::connect(blink::WebMessagePortChannel* channel, | 70 void WebSharedWorkerProxy::connect(blink::WebMessagePortChannel* channel, |
71 ConnectListener* listener) { | 71 ConnectListener* listener) { |
72 WebMessagePortChannelImpl* webchannel = | 72 WebMessagePortChannelImpl* webchannel = |
73 static_cast<WebMessagePortChannelImpl*>(channel); | 73 static_cast<WebMessagePortChannelImpl*>(channel); |
74 | 74 |
75 int message_port_id = webchannel->message_port_id(); | 75 int message_port_id = webchannel->message_port_id(); |
76 DCHECK_NE(MSG_ROUTING_NONE, message_port_id); | 76 DCHECK_NE(MSG_ROUTING_NONE, message_port_id); |
77 webchannel->QueueMessages(); | 77 webchannel->QueueMessages(); |
78 | 78 |
79 Send(base::MakeUnique<WorkerMsg_Connect>(route_id_, message_port_id, | 79 Send(base::MakeUnique<ViewHostMsg_ConnectToWorker>(route_id_, |
80 MSG_ROUTING_NONE)); | 80 message_port_id)); |
81 connect_listener_ = listener; | 81 connect_listener_ = listener; |
82 } | 82 } |
83 | 83 |
84 bool WebSharedWorkerProxy::OnMessageReceived(const IPC::Message& message) { | 84 bool WebSharedWorkerProxy::OnMessageReceived(const IPC::Message& message) { |
85 bool handled = true; | 85 bool handled = true; |
86 IPC_BEGIN_MESSAGE_MAP(WebSharedWorkerProxy, message) | 86 IPC_BEGIN_MESSAGE_MAP(WebSharedWorkerProxy, message) |
87 IPC_MESSAGE_HANDLER(ViewMsg_WorkerCreated, OnWorkerCreated) | 87 IPC_MESSAGE_HANDLER(ViewMsg_WorkerCreated, OnWorkerCreated) |
88 IPC_MESSAGE_HANDLER(ViewMsg_WorkerScriptLoadFailed, | 88 IPC_MESSAGE_HANDLER(ViewMsg_WorkerScriptLoadFailed, |
89 OnWorkerScriptLoadFailed) | 89 OnWorkerScriptLoadFailed) |
90 IPC_MESSAGE_HANDLER(ViewMsg_WorkerConnected, | 90 IPC_MESSAGE_HANDLER(ViewMsg_WorkerConnected, |
(...skipping 18 matching lines...) Expand all Loading... |
109 } | 109 } |
110 | 110 |
111 void WebSharedWorkerProxy::OnWorkerConnected() { | 111 void WebSharedWorkerProxy::OnWorkerConnected() { |
112 if (connect_listener_) { | 112 if (connect_listener_) { |
113 // This can result in this object being freed. | 113 // This can result in this object being freed. |
114 connect_listener_->connected(); | 114 connect_listener_->connected(); |
115 } | 115 } |
116 } | 116 } |
117 | 117 |
118 } // namespace content | 118 } // namespace content |
OLD | NEW |