OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/browser/shared_worker/shared_worker_host.h" | 5 #include "content/browser/shared_worker/shared_worker_host.h" |
6 | 6 |
7 #include "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
8 #include "content/browser/devtools/shared_worker_devtools_manager.h" | 8 #include "content/browser/devtools/shared_worker_devtools_manager.h" |
9 #include "content/browser/message_port_message_filter.h" | 9 #include "content/browser/message_port_message_filter.h" |
10 #include "content/browser/message_port_service.h" | 10 #include "content/browser/message_port_service.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 params.security_policy_type = instance_->security_policy_type(); | 91 params.security_policy_type = instance_->security_policy_type(); |
92 params.creation_address_space = instance_->creation_address_space(); | 92 params.creation_address_space = instance_->creation_address_space(); |
93 params.pause_on_start = pause_on_start; | 93 params.pause_on_start = pause_on_start; |
94 params.route_id = worker_route_id_; | 94 params.route_id = worker_route_id_; |
95 Send(new WorkerProcessMsg_CreateWorker(params)); | 95 Send(new WorkerProcessMsg_CreateWorker(params)); |
96 | 96 |
97 for (const FilterInfo& info : filters_) | 97 for (const FilterInfo& info : filters_) |
98 info.filter()->Send(new ViewMsg_WorkerCreated(info.route_id())); | 98 info.filter()->Send(new ViewMsg_WorkerCreated(info.route_id())); |
99 } | 99 } |
100 | 100 |
101 bool SharedWorkerHost::FilterMessage(const IPC::Message& message, | 101 bool SharedWorkerHost::CanHandleMessage(int route_id, |
102 SharedWorkerMessageFilter* filter) { | 102 SharedWorkerMessageFilter* filter) { |
103 if (!IsAvailable() || !HasFilter(filter, message.routing_id())) | 103 return IsAvailable() && HasFilter(filter, route_id); |
104 return false; | |
105 | |
106 RelayMessage(message, filter); | |
107 return true; | |
108 } | 104 } |
109 | 105 |
110 void SharedWorkerHost::FilterShutdown(SharedWorkerMessageFilter* filter) { | 106 void SharedWorkerHost::FilterShutdown(SharedWorkerMessageFilter* filter) { |
111 if (!instance_) | 107 if (!instance_) |
112 return; | 108 return; |
113 RemoveFilters(filter); | 109 RemoveFilters(filter); |
114 worker_document_set_->RemoveAll(filter); | 110 worker_document_set_->RemoveAll(filter); |
115 if (worker_document_set_->IsEmpty()) { | 111 if (worker_document_set_->IsEmpty()) { |
116 // This worker has no more associated documents - shut it down. | 112 // This worker has no more associated documents - shut it down. |
117 TerminateWorker(); | 113 TerminateWorker(); |
118 } | 114 } |
119 } | 115 } |
120 | 116 |
117 void SharedWorkerHost::Connect(int route_id, | |
118 int sent_message_port_id, | |
119 SharedWorkerMessageFilter* incoming_filter) { | |
120 if (!instance_) | |
horo
2017/01/05 03:54:13
nit: DCHECK(instance_);
nhiroki
2017/01/05 04:11:40
I'll make a separate CL to replace all such if-sta
dcheng
2017/01/05 06:19:18
Why is it OK to DCHECK instance_?
nhiroki
2017/01/05 07:54:33
|instance_| is set at the ctor of SharedWorkerHost
| |
121 return; | |
122 | |
123 DCHECK(container_render_filter_); | |
dcheng
2017/01/05 06:19:18
Ditto: why is this OK to DCHECK? These messages ar
nhiroki
2017/01/05 07:54:33
Because this filter is set at the ctor and the hos
| |
124 int new_routing_id = container_render_filter_->GetNextRoutingID(); | |
125 MessagePortService::GetInstance()->UpdateMessagePort( | |
126 sent_message_port_id, | |
127 container_render_filter_->message_port_message_filter(), new_routing_id); | |
128 SetMessagePortID(incoming_filter, route_id, sent_message_port_id); | |
129 Send(new WorkerMsg_Connect(worker_route_id_, sent_message_port_id, | |
130 new_routing_id)); | |
131 | |
132 // Send any queued messages for the sent port. | |
133 MessagePortService::GetInstance()->SendQueuedMessagesIfPossible( | |
134 sent_message_port_id); | |
135 } | |
136 | |
121 void SharedWorkerHost::DocumentDetached(SharedWorkerMessageFilter* filter, | 137 void SharedWorkerHost::DocumentDetached(SharedWorkerMessageFilter* filter, |
122 unsigned long long document_id) { | 138 unsigned long long document_id) { |
123 if (!instance_) | 139 if (!instance_) |
124 return; | 140 return; |
125 // Walk all instances and remove the document from their document set. | 141 // Walk all instances and remove the document from their document set. |
126 worker_document_set_->Remove(filter, document_id); | 142 worker_document_set_->Remove(filter, document_id); |
127 if (worker_document_set_->IsEmpty()) { | 143 if (worker_document_set_->IsEmpty()) { |
128 // This worker has no more associated documents - shut it down. | 144 // This worker has no more associated documents - shut it down. |
129 TerminateWorker(); | 145 TerminateWorker(); |
130 } | 146 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 | 231 |
216 void SharedWorkerHost::AllowIndexedDB(const GURL& url, | 232 void SharedWorkerHost::AllowIndexedDB(const GURL& url, |
217 const base::string16& name, | 233 const base::string16& name, |
218 bool* result) { | 234 bool* result) { |
219 if (!instance_) | 235 if (!instance_) |
220 return; | 236 return; |
221 *result = GetContentClient()->browser()->AllowWorkerIndexedDB( | 237 *result = GetContentClient()->browser()->AllowWorkerIndexedDB( |
222 url, name, instance_->resource_context(), GetRenderFrameIDsForWorker()); | 238 url, name, instance_->resource_context(), GetRenderFrameIDsForWorker()); |
223 } | 239 } |
224 | 240 |
225 void SharedWorkerHost::RelayMessage( | |
226 const IPC::Message& message, | |
227 SharedWorkerMessageFilter* incoming_filter) { | |
228 if (!instance_) | |
229 return; | |
230 if (message.type() == WorkerMsg_Connect::ID) { | |
231 // Crack the SharedWorker Connect message to setup routing for the port. | |
232 WorkerMsg_Connect::Param param; | |
233 if (!WorkerMsg_Connect::Read(&message, ¶m)) | |
234 return; | |
235 int sent_message_port_id = std::get<0>(param); | |
236 int new_routing_id = std::get<1>(param); | |
237 | |
238 DCHECK(container_render_filter_); | |
239 new_routing_id = container_render_filter_->GetNextRoutingID(); | |
240 MessagePortService::GetInstance()->UpdateMessagePort( | |
241 sent_message_port_id, | |
242 container_render_filter_->message_port_message_filter(), | |
243 new_routing_id); | |
244 SetMessagePortID( | |
245 incoming_filter, message.routing_id(), sent_message_port_id); | |
246 // Resend the message with the new routing id. | |
247 Send(new WorkerMsg_Connect( | |
248 worker_route_id_, sent_message_port_id, new_routing_id)); | |
249 | |
250 // Send any queued messages for the sent port. | |
251 MessagePortService::GetInstance()->SendQueuedMessagesIfPossible( | |
252 sent_message_port_id); | |
253 } else { | |
254 IPC::Message* new_message = new IPC::Message(message); | |
255 new_message->set_routing_id(worker_route_id_); | |
256 Send(new_message); | |
257 return; | |
258 } | |
259 } | |
260 | |
261 void SharedWorkerHost::TerminateWorker() { | 241 void SharedWorkerHost::TerminateWorker() { |
262 termination_message_sent_ = true; | 242 termination_message_sent_ = true; |
263 if (!closed_) | 243 if (!closed_) |
264 NotifyWorkerDestroyed(worker_process_id_, worker_route_id_); | 244 NotifyWorkerDestroyed(worker_process_id_, worker_route_id_); |
265 Send(new WorkerMsg_TerminateWorkerContext(worker_route_id_)); | 245 Send(new WorkerMsg_TerminateWorkerContext(worker_route_id_)); |
266 } | 246 } |
267 | 247 |
268 std::vector<std::pair<int, int> > | 248 std::vector<std::pair<int, int> > |
269 SharedWorkerHost::GetRenderFrameIDsForWorker() { | 249 SharedWorkerHost::GetRenderFrameIDsForWorker() { |
270 std::vector<std::pair<int, int> > result; | 250 std::vector<std::pair<int, int> > result; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
316 int message_port_id) { | 296 int message_port_id) { |
317 for (FilterList::iterator i = filters_.begin(); i != filters_.end(); ++i) { | 297 for (FilterList::iterator i = filters_.begin(); i != filters_.end(); ++i) { |
318 if (i->filter() == filter && i->route_id() == route_id) { | 298 if (i->filter() == filter && i->route_id() == route_id) { |
319 i->set_message_port_id(message_port_id); | 299 i->set_message_port_id(message_port_id); |
320 return; | 300 return; |
321 } | 301 } |
322 } | 302 } |
323 } | 303 } |
324 | 304 |
325 } // namespace content | 305 } // namespace content |
OLD | NEW |