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/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
10 #include "content/child/notifications/notification_data_conversions.h" | 11 #include "content/child/notifications/notification_data_conversions.h" |
11 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 12 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
12 #include "content/child/thread_safe_sender.h" | 13 #include "content/child/thread_safe_sender.h" |
13 #include "content/child/webmessageportchannel_impl.h" | 14 #include "content/child/webmessageportchannel_impl.h" |
14 #include "content/common/message_port_messages.h" | 15 #include "content/common/message_port_messages.h" |
15 #include "content/common/service_worker/service_worker_messages.h" | 16 #include "content/common/service_worker/service_worker_messages.h" |
16 #include "content/public/common/referrer.h" | 17 #include "content/public/common/referrer.h" |
17 #include "content/renderer/service_worker/embedded_worker_context_client.h" | 18 #include "content/renderer/service_worker/embedded_worker_context_client.h" |
18 #include "ipc/ipc_message.h" | 19 #include "ipc/ipc_message.h" |
19 #include "third_party/WebKit/public/platform/WebCrossOriginServiceWorkerClient.h
" | 20 #include "third_party/WebKit/public/platform/WebCrossOriginServiceWorkerClient.h
" |
20 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" | 21 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" |
21 #include "third_party/WebKit/public/platform/WebServiceWorkerClientQueryOptions.
h" | 22 #include "third_party/WebKit/public/platform/WebServiceWorkerClientQueryOptions.
h" |
22 #include "third_party/WebKit/public/platform/WebServiceWorkerRequest.h" | 23 #include "third_party/WebKit/public/platform/WebServiceWorkerRequest.h" |
23 #include "third_party/WebKit/public/platform/WebString.h" | 24 #include "third_party/WebKit/public/platform/WebString.h" |
24 #include "third_party/WebKit/public/platform/WebURL.h" | 25 #include "third_party/WebKit/public/platform/WebURL.h" |
25 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati
onData.h" | 26 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati
onData.h" |
26 #include "third_party/WebKit/public/web/WebServiceWorkerContextClient.h" | 27 #include "third_party/WebKit/public/web/WebServiceWorkerContextClient.h" |
27 #include "third_party/WebKit/public/web/WebServiceWorkerContextProxy.h" | 28 #include "third_party/WebKit/public/web/WebServiceWorkerContextProxy.h" |
28 | 29 |
29 namespace content { | 30 namespace content { |
30 | 31 |
31 namespace { | 32 namespace { |
32 | 33 |
33 void SendPostMessageToDocumentOnMainThread( | 34 void SendPostMessageToClientOnMainThread( |
34 ThreadSafeSender* sender, | 35 ThreadSafeSender* sender, |
35 int routing_id, | 36 int routing_id, |
36 int client_id, | 37 const std::string& uuid, |
37 const base::string16& message, | 38 const base::string16& message, |
38 scoped_ptr<blink::WebMessagePortChannelArray> channels) { | 39 scoped_ptr<blink::WebMessagePortChannelArray> channels) { |
39 sender->Send(new ServiceWorkerHostMsg_PostMessageToDocument( | 40 sender->Send(new ServiceWorkerHostMsg_PostMessageToClient( |
40 routing_id, client_id, message, | 41 routing_id, uuid, message, |
41 WebMessagePortChannelImpl::ExtractMessagePortIDs(channels.release()))); | 42 WebMessagePortChannelImpl::ExtractMessagePortIDs(channels.release()))); |
42 } | 43 } |
43 | 44 |
44 void SendCrossOriginMessageToClientOnMainThread( | 45 void SendCrossOriginMessageToClientOnMainThread( |
45 ThreadSafeSender* sender, | 46 ThreadSafeSender* sender, |
46 int message_port_id, | 47 int message_port_id, |
47 const base::string16& message, | 48 const base::string16& message, |
48 scoped_ptr<blink::WebMessagePortChannelArray> channels) { | 49 scoped_ptr<blink::WebMessagePortChannelArray> channels) { |
49 sender->Send(new MessagePortHostMsg_PostMessage( | 50 sender->Send(new MessagePortHostMsg_PostMessage( |
50 message_port_id, | 51 message_port_id, |
(...skipping 23 matching lines...) Expand all Loading... |
74 RequestContextFrameType frame_type) { | 75 RequestContextFrameType frame_type) { |
75 return static_cast<blink::WebURLRequest::FrameType>(frame_type); | 76 return static_cast<blink::WebURLRequest::FrameType>(frame_type); |
76 } | 77 } |
77 | 78 |
78 blink::WebServiceWorkerClientInfo | 79 blink::WebServiceWorkerClientInfo |
79 ToWebServiceWorkerClientInfo(const ServiceWorkerClientInfo& client_info) { | 80 ToWebServiceWorkerClientInfo(const ServiceWorkerClientInfo& client_info) { |
80 DCHECK(client_info.IsValid()); | 81 DCHECK(client_info.IsValid()); |
81 | 82 |
82 blink::WebServiceWorkerClientInfo web_client_info; | 83 blink::WebServiceWorkerClientInfo web_client_info; |
83 | 84 |
84 web_client_info.clientID = client_info.client_id; | 85 web_client_info.uuid = base::UTF8ToUTF16(client_info.client_uuid); |
85 web_client_info.pageVisibilityState = client_info.page_visibility_state; | 86 web_client_info.pageVisibilityState = client_info.page_visibility_state; |
86 web_client_info.isFocused = client_info.is_focused; | 87 web_client_info.isFocused = client_info.is_focused; |
87 web_client_info.url = client_info.url; | 88 web_client_info.url = client_info.url; |
88 web_client_info.frameType = GetBlinkFrameType(client_info.frame_type); | 89 web_client_info.frameType = GetBlinkFrameType(client_info.frame_type); |
89 web_client_info.clientType = client_info.client_type; | 90 web_client_info.clientType = client_info.client_type; |
90 | 91 |
91 return web_client_info; | 92 return web_client_info; |
92 } | 93 } |
93 | 94 |
94 } // namespace | 95 } // namespace |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 const char* data, | 247 const char* data, |
247 size_t size) { | 248 size_t size) { |
248 std::vector<char> copy(data, data + size); | 249 std::vector<char> copy(data, data + size); |
249 Send(new ServiceWorkerHostMsg_SetCachedMetadata(GetRoutingID(), url, copy)); | 250 Send(new ServiceWorkerHostMsg_SetCachedMetadata(GetRoutingID(), url, copy)); |
250 } | 251 } |
251 | 252 |
252 void ServiceWorkerScriptContext::ClearCachedMetadata(const GURL& url) { | 253 void ServiceWorkerScriptContext::ClearCachedMetadata(const GURL& url) { |
253 Send(new ServiceWorkerHostMsg_ClearCachedMetadata(GetRoutingID(), url)); | 254 Send(new ServiceWorkerHostMsg_ClearCachedMetadata(GetRoutingID(), url)); |
254 } | 255 } |
255 | 256 |
256 void ServiceWorkerScriptContext::PostMessageToDocument( | 257 void ServiceWorkerScriptContext::PostMessageToClient( |
257 int client_id, | 258 const base::string16& uuid, |
258 const base::string16& message, | 259 const base::string16& message, |
259 scoped_ptr<blink::WebMessagePortChannelArray> channels) { | 260 scoped_ptr<blink::WebMessagePortChannelArray> channels) { |
260 // This may send channels for MessagePorts, and all internal book-keeping | 261 // This may send channels for MessagePorts, and all internal book-keeping |
261 // messages for MessagePort (e.g. QueueMessages) are sent from main thread | 262 // messages for MessagePort (e.g. QueueMessages) are sent from main thread |
262 // (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 |
263 // to overtake those messages. | 264 // to overtake those messages. |
264 embedded_context_->main_thread_task_runner()->PostTask( | 265 embedded_context_->main_thread_task_runner()->PostTask( |
265 FROM_HERE, | 266 FROM_HERE, |
266 base::Bind(&SendPostMessageToDocumentOnMainThread, | 267 base::Bind(&SendPostMessageToClientOnMainThread, |
267 make_scoped_refptr(embedded_context_->thread_safe_sender()), | 268 make_scoped_refptr(embedded_context_->thread_safe_sender()), |
268 GetRoutingID(), client_id, message, base::Passed(&channels))); | 269 GetRoutingID(), |
| 270 base::UTF16ToUTF8(uuid), |
| 271 message, base::Passed(&channels))); |
269 } | 272 } |
270 | 273 |
271 void ServiceWorkerScriptContext::PostCrossOriginMessageToClient( | 274 void ServiceWorkerScriptContext::PostCrossOriginMessageToClient( |
272 const blink::WebCrossOriginServiceWorkerClient& client, | 275 const blink::WebCrossOriginServiceWorkerClient& client, |
273 const base::string16& message, | 276 const base::string16& message, |
274 scoped_ptr<blink::WebMessagePortChannelArray> channels) { | 277 scoped_ptr<blink::WebMessagePortChannelArray> channels) { |
275 // This may send channels for MessagePorts, and all internal book-keeping | 278 // This may send channels for MessagePorts, and all internal book-keeping |
276 // messages for MessagePort (e.g. QueueMessages) are sent from main thread | 279 // messages for MessagePort (e.g. QueueMessages) are sent from main thread |
277 // (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 |
278 // to overtake those messages. | 281 // to overtake those messages. |
279 embedded_context_->main_thread_task_runner()->PostTask( | 282 embedded_context_->main_thread_task_runner()->PostTask( |
280 FROM_HERE, | 283 FROM_HERE, |
281 base::Bind(&SendCrossOriginMessageToClientOnMainThread, | 284 base::Bind(&SendCrossOriginMessageToClientOnMainThread, |
282 make_scoped_refptr(embedded_context_->thread_safe_sender()), | 285 make_scoped_refptr(embedded_context_->thread_safe_sender()), |
283 client.clientID, message, base::Passed(&channels))); | 286 client.clientID, message, base::Passed(&channels))); |
284 } | 287 } |
285 | 288 |
286 void ServiceWorkerScriptContext::FocusClient( | 289 void ServiceWorkerScriptContext::FocusClient( |
287 int client_id, blink::WebServiceWorkerClientCallbacks* callback) { | 290 const base::string16& uuid, |
| 291 blink::WebServiceWorkerClientCallbacks* callback) { |
288 DCHECK(callback); | 292 DCHECK(callback); |
289 int request_id = pending_client_callbacks_.Add(callback); | 293 int request_id = pending_client_callbacks_.Add(callback); |
290 Send(new ServiceWorkerHostMsg_FocusClient( | 294 Send(new ServiceWorkerHostMsg_FocusClient(GetRoutingID(), request_id, |
291 GetRoutingID(), request_id, client_id)); | 295 base::UTF16ToUTF8(uuid))); |
292 } | 296 } |
293 | 297 |
294 void ServiceWorkerScriptContext::ClaimClients( | 298 void ServiceWorkerScriptContext::ClaimClients( |
295 blink::WebServiceWorkerClientsClaimCallbacks* callbacks) { | 299 blink::WebServiceWorkerClientsClaimCallbacks* callbacks) { |
296 DCHECK(callbacks); | 300 DCHECK(callbacks); |
297 int request_id = pending_claim_clients_callbacks_.Add(callbacks); | 301 int request_id = pending_claim_clients_callbacks_.Add(callbacks); |
298 Send(new ServiceWorkerHostMsg_ClaimClients(GetRoutingID(), request_id)); | 302 Send(new ServiceWorkerHostMsg_ClaimClients(GetRoutingID(), request_id)); |
299 } | 303 } |
300 | 304 |
301 void ServiceWorkerScriptContext::SkipWaiting( | 305 void ServiceWorkerScriptContext::SkipWaiting( |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 new blink::WebServiceWorkerError(error_type, message)); | 582 new blink::WebServiceWorkerError(error_type, message)); |
579 callbacks->onError(error.release()); | 583 callbacks->onError(error.release()); |
580 pending_claim_clients_callbacks_.Remove(request_id); | 584 pending_claim_clients_callbacks_.Remove(request_id); |
581 } | 585 } |
582 | 586 |
583 void ServiceWorkerScriptContext::OnPing() { | 587 void ServiceWorkerScriptContext::OnPing() { |
584 Send(new ServiceWorkerHostMsg_Pong(GetRoutingID())); | 588 Send(new ServiceWorkerHostMsg_Pong(GetRoutingID())); |
585 } | 589 } |
586 | 590 |
587 } // namespace content | 591 } // namespace content |
OLD | NEW |