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/web_service_worker_registration_impl.h" | 12 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
13 #include "content/child/thread_safe_sender.h" | 13 #include "content/child/thread_safe_sender.h" |
14 #include "content/child/webmessageportchannel_impl.h" | 14 #include "content/child/webmessageportchannel_impl.h" |
15 #include "content/common/message_port_messages.h" | 15 #include "content/common/message_port_messages.h" |
16 #include "content/common/service_worker/service_worker_messages.h" | 16 #include "content/common/service_worker/service_worker_messages.h" |
| 17 #include "content/public/child/child_thread.h" |
17 #include "content/public/common/referrer.h" | 18 #include "content/public/common/referrer.h" |
| 19 #include "content/renderer/render_thread_impl.h" |
| 20 #include "content/renderer/renderer_blink_platform_impl.h" |
18 #include "content/renderer/service_worker/embedded_worker_context_client.h" | 21 #include "content/renderer/service_worker/embedded_worker_context_client.h" |
19 #include "ipc/ipc_message.h" | 22 #include "ipc/ipc_message.h" |
20 #include "third_party/WebKit/public/platform/WebCrossOriginServiceWorkerClient.h
" | 23 #include "third_party/WebKit/public/platform/WebCrossOriginServiceWorkerClient.h
" |
21 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" | 24 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" |
22 #include "third_party/WebKit/public/platform/WebServiceWorkerClientQueryOptions.
h" | 25 #include "third_party/WebKit/public/platform/WebServiceWorkerClientQueryOptions.
h" |
23 #include "third_party/WebKit/public/platform/WebServiceWorkerRequest.h" | 26 #include "third_party/WebKit/public/platform/WebServiceWorkerRequest.h" |
24 #include "third_party/WebKit/public/platform/WebString.h" | 27 #include "third_party/WebKit/public/platform/WebString.h" |
25 #include "third_party/WebKit/public/platform/WebURL.h" | 28 #include "third_party/WebKit/public/platform/WebURL.h" |
26 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati
onData.h" | 29 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati
onData.h" |
27 #include "third_party/WebKit/public/web/WebServiceWorkerContextClient.h" | 30 #include "third_party/WebKit/public/web/WebServiceWorkerContextClient.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 | 116 |
114 ServiceWorkerScriptContext::~ServiceWorkerScriptContext() {} | 117 ServiceWorkerScriptContext::~ServiceWorkerScriptContext() {} |
115 | 118 |
116 void ServiceWorkerScriptContext::OnMessageReceived( | 119 void ServiceWorkerScriptContext::OnMessageReceived( |
117 const IPC::Message& message) { | 120 const IPC::Message& message) { |
118 bool handled = true; | 121 bool handled = true; |
119 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerScriptContext, message) | 122 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerScriptContext, message) |
120 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ActivateEvent, OnActivateEvent) | 123 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ActivateEvent, OnActivateEvent) |
121 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FetchEvent, OnFetchEvent) | 124 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FetchEvent, OnFetchEvent) |
122 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent) | 125 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent) |
123 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SyncEvent, OnSyncEvent) | |
124 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NotificationClickEvent, | 126 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NotificationClickEvent, |
125 OnNotificationClickEvent) | 127 OnNotificationClickEvent) |
126 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_PushEvent, OnPushEvent) | 128 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_PushEvent, OnPushEvent) |
127 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_GeofencingEvent, OnGeofencingEvent) | 129 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_GeofencingEvent, OnGeofencingEvent) |
128 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginConnectEvent, | 130 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginConnectEvent, |
129 OnCrossOriginConnectEvent) | 131 OnCrossOriginConnectEvent) |
130 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToWorker, OnPostMessage) | 132 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToWorker, OnPostMessage) |
131 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginMessageToWorker, | 133 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginMessageToWorker, |
132 OnCrossOriginMessageToWorker) | 134 OnCrossOriginMessageToWorker) |
133 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SendStashedMessagePorts, | 135 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SendStashedMessagePorts, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 } | 216 } |
215 push_start_timings_.erase(request_id); | 217 push_start_timings_.erase(request_id); |
216 | 218 |
217 Send(new ServiceWorkerHostMsg_PushEventFinished( | 219 Send(new ServiceWorkerHostMsg_PushEventFinished( |
218 GetRoutingID(), request_id, result)); | 220 GetRoutingID(), request_id, result)); |
219 } | 221 } |
220 | 222 |
221 void ServiceWorkerScriptContext::DidHandleSyncEvent( | 223 void ServiceWorkerScriptContext::DidHandleSyncEvent( |
222 int request_id, | 224 int request_id, |
223 blink::WebServiceWorkerEventResult result) { | 225 blink::WebServiceWorkerEventResult result) { |
224 Send(new ServiceWorkerHostMsg_SyncEventFinished(GetRoutingID(), request_id, | 226 const SyncCallback* callback = sync_event_callbacks_.Lookup(request_id); |
225 result)); | 227 if (!callback) |
| 228 return; |
| 229 if (result == blink::WebServiceWorkerEventResultCompleted) { |
| 230 callback->Run(BACKGROUND_SYNC_EVENT_STATUS_COMPLETED); |
| 231 } else { |
| 232 callback->Run(BACKGROUND_SYNC_EVENT_STATUS_REJECTED); |
| 233 } |
| 234 sync_event_callbacks_.Remove(request_id); |
226 } | 235 } |
227 | 236 |
228 void ServiceWorkerScriptContext::DidHandleCrossOriginConnectEvent( | 237 void ServiceWorkerScriptContext::DidHandleCrossOriginConnectEvent( |
229 int request_id, | 238 int request_id, |
230 bool accept_connection) { | 239 bool accept_connection) { |
231 Send(new ServiceWorkerHostMsg_CrossOriginConnectEventFinished( | 240 Send(new ServiceWorkerHostMsg_CrossOriginConnectEventFinished( |
232 GetRoutingID(), request_id, accept_connection)); | 241 GetRoutingID(), request_id, accept_connection)); |
233 } | 242 } |
234 | 243 |
235 void ServiceWorkerScriptContext::GetClients( | 244 void ServiceWorkerScriptContext::GetClients( |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 } | 342 } |
334 | 343 |
335 void ServiceWorkerScriptContext::Send(IPC::Message* message) { | 344 void ServiceWorkerScriptContext::Send(IPC::Message* message) { |
336 embedded_context_->Send(message); | 345 embedded_context_->Send(message); |
337 } | 346 } |
338 | 347 |
339 int ServiceWorkerScriptContext::GetRoutingID() const { | 348 int ServiceWorkerScriptContext::GetRoutingID() const { |
340 return embedded_context_->embedded_worker_id(); | 349 return embedded_context_->embedded_worker_id(); |
341 } | 350 } |
342 | 351 |
| 352 void ServiceWorkerScriptContext::DispatchSyncEvent( |
| 353 const SyncCallback& callbacks) { |
| 354 TRACE_EVENT0("ServiceWorker", |
| 355 "ServiceWorkerScriptContext::DispatchSyncEvent"); |
| 356 int request_id = sync_event_callbacks_.Add(&callbacks); |
| 357 proxy_->dispatchSyncEvent(request_id); |
| 358 } |
| 359 |
343 void ServiceWorkerScriptContext::OnActivateEvent(int request_id) { | 360 void ServiceWorkerScriptContext::OnActivateEvent(int request_id) { |
344 TRACE_EVENT0("ServiceWorker", | 361 TRACE_EVENT0("ServiceWorker", |
345 "ServiceWorkerScriptContext::OnActivateEvent"); | 362 "ServiceWorkerScriptContext::OnActivateEvent"); |
346 activate_start_timings_[request_id] = base::TimeTicks::Now(); | 363 activate_start_timings_[request_id] = base::TimeTicks::Now(); |
347 proxy_->dispatchActivateEvent(request_id); | 364 proxy_->dispatchActivateEvent(request_id); |
348 } | 365 } |
349 | 366 |
350 void ServiceWorkerScriptContext::OnInstallEvent(int request_id) { | 367 void ServiceWorkerScriptContext::OnInstallEvent(int request_id) { |
351 TRACE_EVENT0("ServiceWorker", | 368 TRACE_EVENT0("ServiceWorker", |
352 "ServiceWorkerScriptContext::OnInstallEvent"); | 369 "ServiceWorkerScriptContext::OnInstallEvent"); |
(...skipping 26 matching lines...) Expand all Loading... |
379 webRequest.setCredentialsMode( | 396 webRequest.setCredentialsMode( |
380 GetBlinkFetchCredentialsMode(request.credentials_mode)); | 397 GetBlinkFetchCredentialsMode(request.credentials_mode)); |
381 webRequest.setRequestContext( | 398 webRequest.setRequestContext( |
382 GetBlinkRequestContext(request.request_context_type)); | 399 GetBlinkRequestContext(request.request_context_type)); |
383 webRequest.setFrameType(GetBlinkFrameType(request.frame_type)); | 400 webRequest.setFrameType(GetBlinkFrameType(request.frame_type)); |
384 webRequest.setIsReload(request.is_reload); | 401 webRequest.setIsReload(request.is_reload); |
385 fetch_start_timings_[request_id] = base::TimeTicks::Now(); | 402 fetch_start_timings_[request_id] = base::TimeTicks::Now(); |
386 proxy_->dispatchFetchEvent(request_id, webRequest); | 403 proxy_->dispatchFetchEvent(request_id, webRequest); |
387 } | 404 } |
388 | 405 |
389 void ServiceWorkerScriptContext::OnSyncEvent(int request_id) { | |
390 TRACE_EVENT0("ServiceWorker", | |
391 "ServiceWorkerScriptContext::OnSyncEvent"); | |
392 proxy_->dispatchSyncEvent(request_id); | |
393 } | |
394 | |
395 void ServiceWorkerScriptContext::OnNotificationClickEvent( | 406 void ServiceWorkerScriptContext::OnNotificationClickEvent( |
396 int request_id, | 407 int request_id, |
397 int64_t persistent_notification_id, | 408 int64_t persistent_notification_id, |
398 const PlatformNotificationData& notification_data) { | 409 const PlatformNotificationData& notification_data) { |
399 TRACE_EVENT0("ServiceWorker", | 410 TRACE_EVENT0("ServiceWorker", |
400 "ServiceWorkerScriptContext::OnNotificationClickEvent"); | 411 "ServiceWorkerScriptContext::OnNotificationClickEvent"); |
401 notification_click_start_timings_[request_id] = base::TimeTicks::Now(); | 412 notification_click_start_timings_[request_id] = base::TimeTicks::Now(); |
402 proxy_->dispatchNotificationClickEvent( | 413 proxy_->dispatchNotificationClickEvent( |
403 request_id, | 414 request_id, |
404 persistent_notification_id, | 415 persistent_notification_id, |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 new blink::WebServiceWorkerError(error_type, message)); | 633 new blink::WebServiceWorkerError(error_type, message)); |
623 callbacks->onError(error.release()); | 634 callbacks->onError(error.release()); |
624 pending_claim_clients_callbacks_.Remove(request_id); | 635 pending_claim_clients_callbacks_.Remove(request_id); |
625 } | 636 } |
626 | 637 |
627 void ServiceWorkerScriptContext::OnPing() { | 638 void ServiceWorkerScriptContext::OnPing() { |
628 Send(new ServiceWorkerHostMsg_Pong(GetRoutingID())); | 639 Send(new ServiceWorkerHostMsg_Pong(GetRoutingID())); |
629 } | 640 } |
630 | 641 |
631 } // namespace content | 642 } // namespace content |
OLD | NEW |