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