| 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/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 10 #include "content/child/notifications/notification_data_conversions.h" | 10 #include "content/child/notifications/notification_data_conversions.h" |
| 11 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 11 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
| 12 #include "content/child/thread_safe_sender.h" | 12 #include "content/child/thread_safe_sender.h" |
| 13 #include "content/child/webmessageportchannel_impl.h" | 13 #include "content/child/webmessageportchannel_impl.h" |
| 14 #include "content/common/message_port_messages.h" | 14 #include "content/common/message_port_messages.h" |
| 15 #include "content/common/service_worker/service_worker_messages.h" | 15 #include "content/common/service_worker/service_worker_messages.h" |
| 16 #include "content/public/common/referrer.h" | 16 #include "content/public/common/referrer.h" |
| 17 #include "content/renderer/service_worker/embedded_worker_context_client.h" | 17 #include "content/renderer/service_worker/embedded_worker_context_client.h" |
| 18 #include "ipc/ipc_message.h" | 18 #include "ipc/ipc_message.h" |
| 19 #include "third_party/WebKit/public/platform/WebCrossOriginServiceWorkerClient.h
" | 19 #include "third_party/WebKit/public/platform/WebCrossOriginServiceWorkerClient.h
" |
| 20 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" | 20 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" |
| 21 #include "third_party/WebKit/public/platform/WebServiceWorkerClientQueryOptions.
h" |
| 21 #include "third_party/WebKit/public/platform/WebServiceWorkerRequest.h" | 22 #include "third_party/WebKit/public/platform/WebServiceWorkerRequest.h" |
| 22 #include "third_party/WebKit/public/platform/WebString.h" | 23 #include "third_party/WebKit/public/platform/WebString.h" |
| 23 #include "third_party/WebKit/public/platform/WebURL.h" | 24 #include "third_party/WebKit/public/platform/WebURL.h" |
| 24 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati
onData.h" | 25 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati
onData.h" |
| 25 #include "third_party/WebKit/public/web/WebServiceWorkerContextClient.h" | 26 #include "third_party/WebKit/public/web/WebServiceWorkerContextClient.h" |
| 26 #include "third_party/WebKit/public/web/WebServiceWorkerContextProxy.h" | 27 #include "third_party/WebKit/public/web/WebServiceWorkerContextProxy.h" |
| 27 | 28 |
| 28 namespace content { | 29 namespace content { |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 ToWebServiceWorkerClientInfo(const ServiceWorkerClientInfo& client_info) { | 79 ToWebServiceWorkerClientInfo(const ServiceWorkerClientInfo& client_info) { |
| 79 DCHECK(client_info.IsValid()); | 80 DCHECK(client_info.IsValid()); |
| 80 | 81 |
| 81 blink::WebServiceWorkerClientInfo web_client_info; | 82 blink::WebServiceWorkerClientInfo web_client_info; |
| 82 | 83 |
| 83 web_client_info.clientID = client_info.client_id; | 84 web_client_info.clientID = client_info.client_id; |
| 84 web_client_info.pageVisibilityState = client_info.page_visibility_state; | 85 web_client_info.pageVisibilityState = client_info.page_visibility_state; |
| 85 web_client_info.isFocused = client_info.is_focused; | 86 web_client_info.isFocused = client_info.is_focused; |
| 86 web_client_info.url = client_info.url; | 87 web_client_info.url = client_info.url; |
| 87 web_client_info.frameType = GetBlinkFrameType(client_info.frame_type); | 88 web_client_info.frameType = GetBlinkFrameType(client_info.frame_type); |
| 89 web_client_info.clientType = client_info.client_type; |
| 88 | 90 |
| 89 return web_client_info; | 91 return web_client_info; |
| 90 } | 92 } |
| 91 | 93 |
| 92 } // namespace | 94 } // namespace |
| 93 | 95 |
| 94 ServiceWorkerScriptContext::ServiceWorkerScriptContext( | 96 ServiceWorkerScriptContext::ServiceWorkerScriptContext( |
| 95 EmbeddedWorkerContextClient* embedded_context, | 97 EmbeddedWorkerContextClient* embedded_context, |
| 96 blink::WebServiceWorkerContextProxy* proxy) | 98 blink::WebServiceWorkerContextProxy* proxy) |
| 97 : cache_storage_dispatcher_(new ServiceWorkerCacheStorageDispatcher(this)), | 99 : cache_storage_dispatcher_(new ServiceWorkerCacheStorageDispatcher(this)), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 111 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SyncEvent, OnSyncEvent) | 113 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SyncEvent, OnSyncEvent) |
| 112 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NotificationClickEvent, | 114 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NotificationClickEvent, |
| 113 OnNotificationClickEvent) | 115 OnNotificationClickEvent) |
| 114 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_PushEvent, OnPushEvent) | 116 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_PushEvent, OnPushEvent) |
| 115 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_GeofencingEvent, OnGeofencingEvent) | 117 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_GeofencingEvent, OnGeofencingEvent) |
| 116 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginConnectEvent, | 118 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginConnectEvent, |
| 117 OnCrossOriginConnectEvent) | 119 OnCrossOriginConnectEvent) |
| 118 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToWorker, OnPostMessage) | 120 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToWorker, OnPostMessage) |
| 119 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginMessageToWorker, | 121 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginMessageToWorker, |
| 120 OnCrossOriginMessageToWorker) | 122 OnCrossOriginMessageToWorker) |
| 121 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClientDocuments, | 123 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClients, |
| 122 OnDidGetClientDocuments) | 124 OnDidGetClients) |
| 123 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse, | 125 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse, |
| 124 OnOpenWindowResponse) | 126 OnOpenWindowResponse) |
| 125 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowError, | 127 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowError, |
| 126 OnOpenWindowError) | 128 OnOpenWindowError) |
| 127 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse, | 129 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse, |
| 128 OnFocusClientResponse) | 130 OnFocusClientResponse) |
| 129 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidSkipWaiting, OnDidSkipWaiting) | 131 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidSkipWaiting, OnDidSkipWaiting) |
| 130 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidClaimClients, OnDidClaimClients) | 132 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidClaimClients, OnDidClaimClients) |
| 131 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ClaimClientsError, OnClaimClientsError) | 133 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ClaimClientsError, OnClaimClientsError) |
| 132 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_Ping, OnPing); | 134 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_Ping, OnPing); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 GetRoutingID(), request_id)); | 216 GetRoutingID(), request_id)); |
| 215 } | 217 } |
| 216 | 218 |
| 217 void ServiceWorkerScriptContext::DidHandleCrossOriginConnectEvent( | 219 void ServiceWorkerScriptContext::DidHandleCrossOriginConnectEvent( |
| 218 int request_id, | 220 int request_id, |
| 219 bool accept_connection) { | 221 bool accept_connection) { |
| 220 Send(new ServiceWorkerHostMsg_CrossOriginConnectEventFinished( | 222 Send(new ServiceWorkerHostMsg_CrossOriginConnectEventFinished( |
| 221 GetRoutingID(), request_id, accept_connection)); | 223 GetRoutingID(), request_id, accept_connection)); |
| 222 } | 224 } |
| 223 | 225 |
| 224 void ServiceWorkerScriptContext::GetClientDocuments( | 226 void ServiceWorkerScriptContext::GetClients( |
| 227 const blink::WebServiceWorkerClientQueryOptions& weboptions, |
| 225 blink::WebServiceWorkerClientsCallbacks* callbacks) { | 228 blink::WebServiceWorkerClientsCallbacks* callbacks) { |
| 226 DCHECK(callbacks); | 229 DCHECK(callbacks); |
| 227 int request_id = pending_clients_callbacks_.Add(callbacks); | 230 int request_id = pending_clients_callbacks_.Add(callbacks); |
| 228 Send(new ServiceWorkerHostMsg_GetClientDocuments( | 231 ServiceWorkerClientQueryOptions options; |
| 229 GetRoutingID(), request_id)); | 232 options.client_type = weboptions.clientType; |
| 233 options.include_uncontrolled = weboptions.includeUncontrolled; |
| 234 Send(new ServiceWorkerHostMsg_GetClients( |
| 235 GetRoutingID(), request_id, options)); |
| 230 } | 236 } |
| 231 | 237 |
| 232 void ServiceWorkerScriptContext::OpenWindow( | 238 void ServiceWorkerScriptContext::OpenWindow( |
| 233 const GURL& url, blink::WebServiceWorkerClientCallbacks* callbacks) { | 239 const GURL& url, blink::WebServiceWorkerClientCallbacks* callbacks) { |
| 234 DCHECK(callbacks); | 240 DCHECK(callbacks); |
| 235 int request_id = pending_client_callbacks_.Add(callbacks); | 241 int request_id = pending_client_callbacks_.Add(callbacks); |
| 236 Send(new ServiceWorkerHostMsg_OpenWindow(GetRoutingID(), request_id, url)); | 242 Send(new ServiceWorkerHostMsg_OpenWindow(GetRoutingID(), request_id, url)); |
| 237 } | 243 } |
| 238 | 244 |
| 239 void ServiceWorkerScriptContext::SetCachedMetadata(const GURL& url, | 245 void ServiceWorkerScriptContext::SetCachedMetadata(const GURL& url, |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 sent_message_ports, new_routing_ids, | 444 sent_message_ports, new_routing_ids, |
| 439 embedded_context_->main_thread_task_runner()); | 445 embedded_context_->main_thread_task_runner()); |
| 440 | 446 |
| 441 blink::WebCrossOriginServiceWorkerClient web_client; | 447 blink::WebCrossOriginServiceWorkerClient web_client; |
| 442 web_client.origin = client.origin; | 448 web_client.origin = client.origin; |
| 443 web_client.targetURL = client.target_url; | 449 web_client.targetURL = client.target_url; |
| 444 web_client.clientID = client.message_port_id; | 450 web_client.clientID = client.message_port_id; |
| 445 proxy_->dispatchCrossOriginMessageEvent(web_client, message, ports); | 451 proxy_->dispatchCrossOriginMessageEvent(web_client, message, ports); |
| 446 } | 452 } |
| 447 | 453 |
| 448 void ServiceWorkerScriptContext::OnDidGetClientDocuments( | 454 void ServiceWorkerScriptContext::OnDidGetClients( |
| 449 int request_id, const std::vector<ServiceWorkerClientInfo>& clients) { | 455 int request_id, const std::vector<ServiceWorkerClientInfo>& clients) { |
| 450 TRACE_EVENT0("ServiceWorker", | 456 TRACE_EVENT0("ServiceWorker", |
| 451 "ServiceWorkerScriptContext::OnDidGetClientDocuments"); | 457 "ServiceWorkerScriptContext::OnDidGetClients"); |
| 452 blink::WebServiceWorkerClientsCallbacks* callbacks = | 458 blink::WebServiceWorkerClientsCallbacks* callbacks = |
| 453 pending_clients_callbacks_.Lookup(request_id); | 459 pending_clients_callbacks_.Lookup(request_id); |
| 454 if (!callbacks) { | 460 if (!callbacks) { |
| 455 NOTREACHED() << "Got stray response: " << request_id; | 461 NOTREACHED() << "Got stray response: " << request_id; |
| 456 return; | 462 return; |
| 457 } | 463 } |
| 458 scoped_ptr<blink::WebServiceWorkerClientsInfo> info( | 464 scoped_ptr<blink::WebServiceWorkerClientsInfo> info( |
| 459 new blink::WebServiceWorkerClientsInfo); | 465 new blink::WebServiceWorkerClientsInfo); |
| 460 blink::WebVector<blink::WebServiceWorkerClientInfo> convertedClients( | 466 blink::WebVector<blink::WebServiceWorkerClientInfo> convertedClients( |
| 461 clients.size()); | 467 clients.size()); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 new blink::WebServiceWorkerError(error_type, message)); | 579 new blink::WebServiceWorkerError(error_type, message)); |
| 574 callbacks->onError(error.release()); | 580 callbacks->onError(error.release()); |
| 575 pending_claim_clients_callbacks_.Remove(request_id); | 581 pending_claim_clients_callbacks_.Remove(request_id); |
| 576 } | 582 } |
| 577 | 583 |
| 578 void ServiceWorkerScriptContext::OnPing() { | 584 void ServiceWorkerScriptContext::OnPing() { |
| 579 Send(new ServiceWorkerHostMsg_Pong(GetRoutingID())); | 585 Send(new ServiceWorkerHostMsg_Pong(GetRoutingID())); |
| 580 } | 586 } |
| 581 | 587 |
| 582 } // namespace content | 588 } // namespace content |
| OLD | NEW |