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/shared_worker/websharedworker_proxy.h" | 5 #include "content/renderer/shared_worker/websharedworker_proxy.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "content/child/child_thread_impl.h" | |
9 #include "content/child/webmessageportchannel_impl.h" | 10 #include "content/child/webmessageportchannel_impl.h" |
10 #include "content/common/view_messages.h" | 11 #include "content/common/view_messages.h" |
11 #include "content/common/worker_messages.h" | 12 #include "content/common/worker_messages.h" |
13 #include "ipc/ipc_sync_channel.h" | |
12 #include "ipc/message_router.h" | 14 #include "ipc/message_router.h" |
13 | 15 |
14 namespace content { | 16 namespace content { |
15 | 17 |
16 WebSharedWorkerProxy::WebSharedWorkerProxy(IPC::MessageRouter* router, | 18 WebSharedWorkerProxy::WebSharedWorkerProxy(int route_id) |
17 int route_id) | |
18 : route_id_(route_id), | 19 : route_id_(route_id), |
19 router_(router), | |
20 message_port_id_(MSG_ROUTING_NONE), | 20 message_port_id_(MSG_ROUTING_NONE), |
21 router_(ChildThreadImpl::current()->GetRouter()), | |
21 connect_listener_(nullptr) { | 22 connect_listener_(nullptr) { |
22 DCHECK_NE(MSG_ROUTING_NONE, route_id_); | 23 DCHECK_NE(MSG_ROUTING_NONE, route_id_); |
23 router_->AddRoute(route_id_, this); | 24 router_->AddRoute(route_id_, this); |
25 ChildThreadImpl::current()->channel()->GetRemoteAssociatedInterface( | |
26 &message_filter_); | |
24 } | 27 } |
25 | 28 |
26 WebSharedWorkerProxy::~WebSharedWorkerProxy() { | 29 WebSharedWorkerProxy::~WebSharedWorkerProxy() { |
27 router_->RemoveRoute(route_id_); | 30 router_->RemoveRoute(route_id_); |
28 } | 31 } |
29 | 32 |
30 void WebSharedWorkerProxy::connect(blink::WebMessagePortChannel* channel, | 33 void WebSharedWorkerProxy::connect(blink::WebMessagePortChannel* channel, |
31 ConnectListener* listener) { | 34 ConnectListener* listener) { |
32 DCHECK_EQ(MSG_ROUTING_NONE, message_port_id_); | 35 DCHECK_EQ(MSG_ROUTING_NONE, message_port_id_); |
33 WebMessagePortChannelImpl* webchannel = | 36 WebMessagePortChannelImpl* webchannel = |
34 static_cast<WebMessagePortChannelImpl*>(channel); | 37 static_cast<WebMessagePortChannelImpl*>(channel); |
35 message_port_id_ = webchannel->message_port_id(); | 38 message_port_id_ = webchannel->message_port_id(); |
36 DCHECK_NE(MSG_ROUTING_NONE, message_port_id_); | 39 DCHECK_NE(MSG_ROUTING_NONE, message_port_id_); |
37 webchannel->QueueMessages(); | 40 webchannel->QueueMessages(); |
41 | |
38 connect_listener_ = listener; | 42 connect_listener_ = listener; |
39 // An actual connection request will be issued on OnWorkerCreated(). | 43 // An actual connection request will be issued on OnWorkerCreated(). |
40 } | 44 } |
41 | 45 |
42 bool WebSharedWorkerProxy::OnMessageReceived(const IPC::Message& message) { | 46 bool WebSharedWorkerProxy::OnMessageReceived(const IPC::Message& message) { |
43 bool handled = true; | 47 bool handled = true; |
44 IPC_BEGIN_MESSAGE_MAP(WebSharedWorkerProxy, message) | 48 IPC_BEGIN_MESSAGE_MAP(WebSharedWorkerProxy, message) |
45 IPC_MESSAGE_HANDLER(ViewMsg_WorkerCreated, OnWorkerCreated) | 49 IPC_MESSAGE_HANDLER(ViewMsg_WorkerCreated, OnWorkerCreated) |
46 IPC_MESSAGE_HANDLER(ViewMsg_WorkerScriptLoadFailed, | 50 IPC_MESSAGE_HANDLER(ViewMsg_WorkerScriptLoadFailed, |
47 OnWorkerScriptLoadFailed) | 51 OnWorkerScriptLoadFailed) |
48 IPC_MESSAGE_HANDLER(ViewMsg_WorkerConnected, | 52 IPC_MESSAGE_HANDLER(ViewMsg_WorkerConnected, |
49 OnWorkerConnected) | 53 OnWorkerConnected) |
50 IPC_MESSAGE_UNHANDLED(handled = false) | 54 IPC_MESSAGE_UNHANDLED(handled = false) |
51 IPC_END_MESSAGE_MAP() | 55 IPC_END_MESSAGE_MAP() |
52 return handled; | 56 return handled; |
53 } | 57 } |
54 | 58 |
55 void WebSharedWorkerProxy::OnWorkerCreated() { | 59 void WebSharedWorkerProxy::OnWorkerCreated() { |
56 // connect() should be called before. | 60 // connect() should be called before. |
57 DCHECK_NE(MSG_ROUTING_NONE, message_port_id_); | 61 DCHECK_NE(MSG_ROUTING_NONE, message_port_id_); |
58 | 62 |
59 // The worker is created - now send off the connection request. | 63 // The worker is created - nowconnect to the worker. |
kinuko
2017/01/11 06:06:43
nowconnect -> now connect
| |
60 router_->Send( | 64 message_filter_->OnConnectToWorker(route_id_, message_port_id_); |
61 new ViewHostMsg_ConnectToWorker(route_id_, message_port_id_)); | |
62 } | 65 } |
63 | 66 |
64 void WebSharedWorkerProxy::OnWorkerScriptLoadFailed() { | 67 void WebSharedWorkerProxy::OnWorkerScriptLoadFailed() { |
65 if (connect_listener_) { | 68 if (connect_listener_) { |
66 // This can result in this object being freed. | 69 // This can result in this object being freed. |
67 connect_listener_->scriptLoadFailed(); | 70 connect_listener_->scriptLoadFailed(); |
68 } | 71 } |
69 } | 72 } |
70 | 73 |
71 void WebSharedWorkerProxy::OnWorkerConnected() { | 74 void WebSharedWorkerProxy::OnWorkerConnected() { |
72 if (connect_listener_) { | 75 if (connect_listener_) { |
73 // This can result in this object being freed. | 76 // This can result in this object being freed. |
74 connect_listener_->connected(); | 77 connect_listener_->connected(); |
75 } | 78 } |
76 } | 79 } |
77 | 80 |
78 } // namespace content | 81 } // namespace content |
OLD | NEW |