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/renderer/service_worker/service_worker_script_context.h" | 5 #include "content/renderer/service_worker/service_worker_script_context.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
11 #include "content/child/notifications/notification_data_conversions.h" | 11 #include "content/child/notifications/notification_data_conversions.h" |
| 12 #include "content/child/service_worker/service_worker_message_sender.h" |
12 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 13 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
13 #include "content/child/thread_safe_sender.h" | 14 #include "content/child/thread_safe_sender.h" |
14 #include "content/child/webmessageportchannel_impl.h" | 15 #include "content/child/webmessageportchannel_impl.h" |
15 #include "content/common/message_port_messages.h" | 16 #include "content/common/message_port_messages.h" |
16 #include "content/common/service_worker/service_worker_messages.h" | 17 #include "content/common/service_worker/service_worker_messages.h" |
17 #include "content/public/common/referrer.h" | 18 #include "content/public/common/referrer.h" |
18 #include "content/renderer/service_worker/embedded_worker_context_client.h" | 19 #include "content/renderer/service_worker/embedded_worker_context_client.h" |
19 #include "ipc/ipc_message.h" | 20 #include "ipc/ipc_message.h" |
20 #include "third_party/WebKit/public/platform/WebCrossOriginServiceWorkerClient.h
" | 21 #include "third_party/WebKit/public/platform/WebCrossOriginServiceWorkerClient.h
" |
21 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" | 22 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" |
22 #include "third_party/WebKit/public/platform/WebServiceWorkerClientQueryOptions.
h" | 23 #include "third_party/WebKit/public/platform/WebServiceWorkerClientQueryOptions.
h" |
23 #include "third_party/WebKit/public/platform/WebServiceWorkerRequest.h" | 24 #include "third_party/WebKit/public/platform/WebServiceWorkerRequest.h" |
24 #include "third_party/WebKit/public/platform/WebString.h" | 25 #include "third_party/WebKit/public/platform/WebString.h" |
25 #include "third_party/WebKit/public/platform/WebURL.h" | 26 #include "third_party/WebKit/public/platform/WebURL.h" |
26 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati
onData.h" | 27 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati
onData.h" |
27 #include "third_party/WebKit/public/web/WebServiceWorkerContextClient.h" | 28 #include "third_party/WebKit/public/web/WebServiceWorkerContextClient.h" |
28 #include "third_party/WebKit/public/web/WebServiceWorkerContextProxy.h" | 29 #include "third_party/WebKit/public/web/WebServiceWorkerContextProxy.h" |
29 | 30 |
30 namespace content { | 31 namespace content { |
31 | 32 |
32 namespace { | 33 namespace { |
33 | 34 |
34 void SendPostMessageToClientOnMainThread( | 35 void SendPostMessageToClientOnMainThread( |
35 ThreadSafeSender* sender, | 36 ServiceWorkerMessageSender* sender, |
36 int routing_id, | 37 int routing_id, |
37 const std::string& uuid, | 38 const std::string& uuid, |
38 const base::string16& message, | 39 const base::string16& message, |
39 scoped_ptr<blink::WebMessagePortChannelArray> channels) { | 40 scoped_ptr<blink::WebMessagePortChannelArray> channels) { |
40 sender->Send(new ServiceWorkerHostMsg_PostMessageToClient( | 41 sender->Send(new ServiceWorkerHostMsg_PostMessageToClient( |
41 routing_id, uuid, message, | 42 routing_id, uuid, message, |
42 WebMessagePortChannelImpl::ExtractMessagePortIDs(channels.release()))); | 43 WebMessagePortChannelImpl::ExtractMessagePortIDs(channels.release()))); |
43 } | 44 } |
44 | 45 |
45 void SendCrossOriginMessageToClientOnMainThread( | 46 void SendCrossOriginMessageToClientOnMainThread( |
46 ThreadSafeSender* sender, | 47 ServiceWorkerMessageSender* sender, |
47 int message_port_id, | 48 int message_port_id, |
48 const base::string16& message, | 49 const base::string16& message, |
49 scoped_ptr<blink::WebMessagePortChannelArray> channels) { | 50 scoped_ptr<blink::WebMessagePortChannelArray> channels) { |
50 sender->Send(new MessagePortHostMsg_PostMessage( | 51 sender->Send(new MessagePortHostMsg_PostMessage( |
51 message_port_id, | 52 message_port_id, |
52 MessagePortMessage(message), | 53 MessagePortMessage(message), |
53 WebMessagePortChannelImpl::ExtractMessagePortIDs( | 54 WebMessagePortChannelImpl::ExtractMessagePortIDs( |
54 channels.release()))); | 55 channels.release()))); |
55 } | 56 } |
56 | 57 |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 const base::string16& uuid, | 259 const base::string16& uuid, |
259 const base::string16& message, | 260 const base::string16& message, |
260 scoped_ptr<blink::WebMessagePortChannelArray> channels) { | 261 scoped_ptr<blink::WebMessagePortChannelArray> channels) { |
261 // This may send channels for MessagePorts, and all internal book-keeping | 262 // This may send channels for MessagePorts, and all internal book-keeping |
262 // messages for MessagePort (e.g. QueueMessages) are sent from main thread | 263 // messages for MessagePort (e.g. QueueMessages) are sent from main thread |
263 // (with thread hopping), so we need to do the same thread hopping here not | 264 // (with thread hopping), so we need to do the same thread hopping here not |
264 // to overtake those messages. | 265 // to overtake those messages. |
265 embedded_context_->main_thread_task_runner()->PostTask( | 266 embedded_context_->main_thread_task_runner()->PostTask( |
266 FROM_HERE, | 267 FROM_HERE, |
267 base::Bind(&SendPostMessageToClientOnMainThread, | 268 base::Bind(&SendPostMessageToClientOnMainThread, |
268 make_scoped_refptr(embedded_context_->thread_safe_sender()), | 269 make_scoped_refptr(embedded_context_->sender()), |
269 GetRoutingID(), | 270 GetRoutingID(), |
270 base::UTF16ToUTF8(uuid), | 271 base::UTF16ToUTF8(uuid), |
271 message, base::Passed(&channels))); | 272 message, base::Passed(&channels))); |
272 } | 273 } |
273 | 274 |
274 void ServiceWorkerScriptContext::PostCrossOriginMessageToClient( | 275 void ServiceWorkerScriptContext::PostCrossOriginMessageToClient( |
275 const blink::WebCrossOriginServiceWorkerClient& client, | 276 const blink::WebCrossOriginServiceWorkerClient& client, |
276 const base::string16& message, | 277 const base::string16& message, |
277 scoped_ptr<blink::WebMessagePortChannelArray> channels) { | 278 scoped_ptr<blink::WebMessagePortChannelArray> channels) { |
278 // This may send channels for MessagePorts, and all internal book-keeping | 279 // This may send channels for MessagePorts, and all internal book-keeping |
279 // messages for MessagePort (e.g. QueueMessages) are sent from main thread | 280 // messages for MessagePort (e.g. QueueMessages) are sent from main thread |
280 // (with thread hopping), so we need to do the same thread hopping here not | 281 // (with thread hopping), so we need to do the same thread hopping here not |
281 // to overtake those messages. | 282 // to overtake those messages. |
282 embedded_context_->main_thread_task_runner()->PostTask( | 283 embedded_context_->main_thread_task_runner()->PostTask( |
283 FROM_HERE, | 284 FROM_HERE, |
284 base::Bind(&SendCrossOriginMessageToClientOnMainThread, | 285 base::Bind(&SendCrossOriginMessageToClientOnMainThread, |
285 make_scoped_refptr(embedded_context_->thread_safe_sender()), | 286 make_scoped_refptr(embedded_context_->sender()), |
286 client.clientID, message, base::Passed(&channels))); | 287 client.clientID, message, base::Passed(&channels))); |
287 } | 288 } |
288 | 289 |
289 void ServiceWorkerScriptContext::FocusClient( | 290 void ServiceWorkerScriptContext::FocusClient( |
290 const base::string16& uuid, | 291 const base::string16& uuid, |
291 blink::WebServiceWorkerClientCallbacks* callback) { | 292 blink::WebServiceWorkerClientCallbacks* callback) { |
292 DCHECK(callback); | 293 DCHECK(callback); |
293 int request_id = pending_client_callbacks_.Add(callback); | 294 int request_id = pending_client_callbacks_.Add(callback); |
294 Send(new ServiceWorkerHostMsg_FocusClient(GetRoutingID(), request_id, | 295 Send(new ServiceWorkerHostMsg_FocusClient(GetRoutingID(), request_id, |
295 base::UTF16ToUTF8(uuid))); | 296 base::UTF16ToUTF8(uuid))); |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 new blink::WebServiceWorkerError(error_type, message)); | 585 new blink::WebServiceWorkerError(error_type, message)); |
585 callbacks->onError(error.release()); | 586 callbacks->onError(error.release()); |
586 pending_claim_clients_callbacks_.Remove(request_id); | 587 pending_claim_clients_callbacks_.Remove(request_id); |
587 } | 588 } |
588 | 589 |
589 void ServiceWorkerScriptContext::OnPing() { | 590 void ServiceWorkerScriptContext::OnPing() { |
590 Send(new ServiceWorkerHostMsg_Pong(GetRoutingID())); | 591 Send(new ServiceWorkerHostMsg_Pong(GetRoutingID())); |
591 } | 592 } |
592 | 593 |
593 } // namespace content | 594 } // namespace content |
OLD | NEW |