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/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "content/child/notifications/notification_data_conversions.h" | 10 #include "content/child/notifications/notification_data_conversions.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginConnectEvent, | 97 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginConnectEvent, |
98 OnCrossOriginConnectEvent) | 98 OnCrossOriginConnectEvent) |
99 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToWorker, OnPostMessage) | 99 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToWorker, OnPostMessage) |
100 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginMessageToWorker, | 100 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginMessageToWorker, |
101 OnCrossOriginMessageToWorker) | 101 OnCrossOriginMessageToWorker) |
102 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClientDocuments, | 102 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClientDocuments, |
103 OnDidGetClientDocuments) | 103 OnDidGetClientDocuments) |
104 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse, | 104 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse, |
105 OnFocusClientResponse) | 105 OnFocusClientResponse) |
106 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidSkipWaiting, OnDidSkipWaiting) | 106 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidSkipWaiting, OnDidSkipWaiting) |
| 107 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidClaimClients, OnDidClaimClients) |
| 108 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ClaimClientsError, OnClaimClientsError) |
107 IPC_MESSAGE_UNHANDLED(handled = false) | 109 IPC_MESSAGE_UNHANDLED(handled = false) |
108 IPC_END_MESSAGE_MAP() | 110 IPC_END_MESSAGE_MAP() |
109 | 111 |
110 // TODO(gavinp): Would it be preferable to put an AddListener() method to | 112 // TODO(gavinp): Would it be preferable to put an AddListener() method to |
111 // EmbeddedWorkerContextClient? | 113 // EmbeddedWorkerContextClient? |
112 if (!handled) | 114 if (!handled) |
113 handled = cache_storage_dispatcher_->OnMessageReceived(message); | 115 handled = cache_storage_dispatcher_->OnMessageReceived(message); |
114 | 116 |
115 DCHECK(handled); | 117 DCHECK(handled); |
116 } | 118 } |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 } | 231 } |
230 | 232 |
231 void ServiceWorkerScriptContext::FocusClient( | 233 void ServiceWorkerScriptContext::FocusClient( |
232 int client_id, blink::WebServiceWorkerClientFocusCallback* callback) { | 234 int client_id, blink::WebServiceWorkerClientFocusCallback* callback) { |
233 DCHECK(callback); | 235 DCHECK(callback); |
234 int request_id = pending_focus_client_callbacks_.Add(callback); | 236 int request_id = pending_focus_client_callbacks_.Add(callback); |
235 Send(new ServiceWorkerHostMsg_FocusClient( | 237 Send(new ServiceWorkerHostMsg_FocusClient( |
236 GetRoutingID(), request_id, client_id)); | 238 GetRoutingID(), request_id, client_id)); |
237 } | 239 } |
238 | 240 |
| 241 void ServiceWorkerScriptContext::ClaimClients( |
| 242 blink::WebServiceWorkerClientsClaimCallbacks* callbacks) { |
| 243 DCHECK(callbacks); |
| 244 int request_id = pending_claim_clients_callbacks_.Add(callbacks); |
| 245 Send(new ServiceWorkerHostMsg_ClaimClients(GetRoutingID(), request_id)); |
| 246 } |
| 247 |
239 void ServiceWorkerScriptContext::SkipWaiting( | 248 void ServiceWorkerScriptContext::SkipWaiting( |
240 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks) { | 249 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks) { |
241 DCHECK(callbacks); | 250 DCHECK(callbacks); |
242 int request_id = pending_skip_waiting_callbacks_.Add(callbacks); | 251 int request_id = pending_skip_waiting_callbacks_.Add(callbacks); |
243 Send(new ServiceWorkerHostMsg_SkipWaiting(GetRoutingID(), request_id)); | 252 Send(new ServiceWorkerHostMsg_SkipWaiting(GetRoutingID(), request_id)); |
244 } | 253 } |
245 | 254 |
246 void ServiceWorkerScriptContext::Send(IPC::Message* message) { | 255 void ServiceWorkerScriptContext::Send(IPC::Message* message) { |
247 embedded_context_->Send(message); | 256 embedded_context_->Send(message); |
248 } | 257 } |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks = | 454 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks = |
446 pending_skip_waiting_callbacks_.Lookup(request_id); | 455 pending_skip_waiting_callbacks_.Lookup(request_id); |
447 if (!callbacks) { | 456 if (!callbacks) { |
448 NOTREACHED() << "Got stray response: " << request_id; | 457 NOTREACHED() << "Got stray response: " << request_id; |
449 return; | 458 return; |
450 } | 459 } |
451 callbacks->onSuccess(); | 460 callbacks->onSuccess(); |
452 pending_skip_waiting_callbacks_.Remove(request_id); | 461 pending_skip_waiting_callbacks_.Remove(request_id); |
453 } | 462 } |
454 | 463 |
| 464 void ServiceWorkerScriptContext::OnDidClaimClients(int request_id) { |
| 465 TRACE_EVENT0("ServiceWorker", |
| 466 "ServiceWorkerScriptContext::OnDidClaimClients"); |
| 467 blink::WebServiceWorkerClientsClaimCallbacks* callbacks = |
| 468 pending_claim_clients_callbacks_.Lookup(request_id); |
| 469 if (!callbacks) { |
| 470 NOTREACHED() << "Got stray response: " << request_id; |
| 471 return; |
| 472 } |
| 473 callbacks->onSuccess(); |
| 474 pending_claim_clients_callbacks_.Remove(request_id); |
| 475 } |
| 476 |
| 477 void ServiceWorkerScriptContext::OnClaimClientsError( |
| 478 int request_id, |
| 479 blink::WebServiceWorkerError::ErrorType error_type, |
| 480 const base::string16& message) { |
| 481 TRACE_EVENT0("ServiceWorker", |
| 482 "ServiceWorkerScriptContext::OnClaimClientsError"); |
| 483 blink::WebServiceWorkerClientsClaimCallbacks* callbacks = |
| 484 pending_claim_clients_callbacks_.Lookup(request_id); |
| 485 if (!callbacks) { |
| 486 NOTREACHED() << "Got stray response: " << request_id; |
| 487 return; |
| 488 } |
| 489 scoped_ptr<blink::WebServiceWorkerError> error( |
| 490 new blink::WebServiceWorkerError(error_type, message)); |
| 491 callbacks->onError(error.release()); |
| 492 pending_claim_clients_callbacks_.Remove(request_id); |
| 493 } |
| 494 |
455 } // namespace content | 495 } // namespace content |
OLD | NEW |