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" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 OnNotificationClickEvent) | 111 OnNotificationClickEvent) |
112 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_PushEvent, OnPushEvent) | 112 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_PushEvent, OnPushEvent) |
113 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_GeofencingEvent, OnGeofencingEvent) | 113 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_GeofencingEvent, OnGeofencingEvent) |
114 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginConnectEvent, | 114 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginConnectEvent, |
115 OnCrossOriginConnectEvent) | 115 OnCrossOriginConnectEvent) |
116 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToWorker, OnPostMessage) | 116 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToWorker, OnPostMessage) |
117 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginMessageToWorker, | 117 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginMessageToWorker, |
118 OnCrossOriginMessageToWorker) | 118 OnCrossOriginMessageToWorker) |
119 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClientDocuments, | 119 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClientDocuments, |
120 OnDidGetClientDocuments) | 120 OnDidGetClientDocuments) |
| 121 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse, |
| 122 OnOpenWindowResponse) |
| 123 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowError, |
| 124 OnOpenWindowError) |
121 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse, | 125 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse, |
122 OnFocusClientResponse) | 126 OnFocusClientResponse) |
123 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidSkipWaiting, OnDidSkipWaiting) | 127 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidSkipWaiting, OnDidSkipWaiting) |
124 IPC_MESSAGE_UNHANDLED(handled = false) | 128 IPC_MESSAGE_UNHANDLED(handled = false) |
125 IPC_END_MESSAGE_MAP() | 129 IPC_END_MESSAGE_MAP() |
126 | 130 |
127 // TODO(gavinp): Would it be preferable to put an AddListener() method to | 131 // TODO(gavinp): Would it be preferable to put an AddListener() method to |
128 // EmbeddedWorkerContextClient? | 132 // EmbeddedWorkerContextClient? |
129 if (!handled) | 133 if (!handled) |
130 handled = cache_storage_dispatcher_->OnMessageReceived(message); | 134 handled = cache_storage_dispatcher_->OnMessageReceived(message); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 } | 217 } |
214 | 218 |
215 void ServiceWorkerScriptContext::GetClientDocuments( | 219 void ServiceWorkerScriptContext::GetClientDocuments( |
216 blink::WebServiceWorkerClientsCallbacks* callbacks) { | 220 blink::WebServiceWorkerClientsCallbacks* callbacks) { |
217 DCHECK(callbacks); | 221 DCHECK(callbacks); |
218 int request_id = pending_clients_callbacks_.Add(callbacks); | 222 int request_id = pending_clients_callbacks_.Add(callbacks); |
219 Send(new ServiceWorkerHostMsg_GetClientDocuments( | 223 Send(new ServiceWorkerHostMsg_GetClientDocuments( |
220 GetRoutingID(), request_id)); | 224 GetRoutingID(), request_id)); |
221 } | 225 } |
222 | 226 |
| 227 void ServiceWorkerScriptContext::OpenWindow( |
| 228 const GURL& url, blink::WebServiceWorkerClientCallbacks* callbacks) { |
| 229 DCHECK(callbacks); |
| 230 int request_id = pending_client_callbacks_.Add(callbacks); |
| 231 Send(new ServiceWorkerHostMsg_OpenWindow(GetRoutingID(), request_id, url)); |
| 232 } |
| 233 |
223 void ServiceWorkerScriptContext::PostMessageToDocument( | 234 void ServiceWorkerScriptContext::PostMessageToDocument( |
224 int client_id, | 235 int client_id, |
225 const base::string16& message, | 236 const base::string16& message, |
226 scoped_ptr<blink::WebMessagePortChannelArray> channels) { | 237 scoped_ptr<blink::WebMessagePortChannelArray> channels) { |
227 // This may send channels for MessagePorts, and all internal book-keeping | 238 // This may send channels for MessagePorts, and all internal book-keeping |
228 // messages for MessagePort (e.g. QueueMessages) are sent from main thread | 239 // messages for MessagePort (e.g. QueueMessages) are sent from main thread |
229 // (with thread hopping), so we need to do the same thread hopping here not | 240 // (with thread hopping), so we need to do the same thread hopping here not |
230 // to overtake those messages. | 241 // to overtake those messages. |
231 embedded_context_->main_thread_proxy()->PostTask( | 242 embedded_context_->main_thread_proxy()->PostTask( |
232 FROM_HERE, | 243 FROM_HERE, |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 new blink::WebServiceWorkerClientsInfo); | 446 new blink::WebServiceWorkerClientsInfo); |
436 blink::WebVector<blink::WebServiceWorkerClientInfo> convertedClients( | 447 blink::WebVector<blink::WebServiceWorkerClientInfo> convertedClients( |
437 clients.size()); | 448 clients.size()); |
438 for (size_t i = 0; i < clients.size(); ++i) | 449 for (size_t i = 0; i < clients.size(); ++i) |
439 convertedClients[i] = ToWebServiceWorkerClientInfo(clients[i]); | 450 convertedClients[i] = ToWebServiceWorkerClientInfo(clients[i]); |
440 info->clients.swap(convertedClients); | 451 info->clients.swap(convertedClients); |
441 callbacks->onSuccess(info.release()); | 452 callbacks->onSuccess(info.release()); |
442 pending_clients_callbacks_.Remove(request_id); | 453 pending_clients_callbacks_.Remove(request_id); |
443 } | 454 } |
444 | 455 |
| 456 void ServiceWorkerScriptContext::OnOpenWindowResponse( |
| 457 int request_id, |
| 458 const ServiceWorkerClientInfo& client) { |
| 459 TRACE_EVENT0("ServiceWorker", |
| 460 "ServiceWorkerScriptContext::OnOpenWindowResponse"); |
| 461 blink::WebServiceWorkerClientCallbacks* callbacks = |
| 462 pending_client_callbacks_.Lookup(request_id); |
| 463 if (!callbacks) { |
| 464 NOTREACHED() << "Got stray response: " << request_id; |
| 465 return; |
| 466 } |
| 467 scoped_ptr<blink::WebServiceWorkerClientInfo> web_client; |
| 468 if (!client.IsEmpty()) { |
| 469 DCHECK(client.IsValid()); |
| 470 web_client.reset(new blink::WebServiceWorkerClientInfo( |
| 471 ToWebServiceWorkerClientInfo(client))); |
| 472 } |
| 473 callbacks->onSuccess(web_client.release()); |
| 474 pending_client_callbacks_.Remove(request_id); |
| 475 } |
| 476 |
| 477 void ServiceWorkerScriptContext::OnOpenWindowError(int request_id) { |
| 478 TRACE_EVENT0("ServiceWorker", |
| 479 "ServiceWorkerScriptContext::OnOpenWindowError"); |
| 480 blink::WebServiceWorkerClientCallbacks* callbacks = |
| 481 pending_client_callbacks_.Lookup(request_id); |
| 482 if (!callbacks) { |
| 483 NOTREACHED() << "Got stray response: " << request_id; |
| 484 return; |
| 485 } |
| 486 scoped_ptr<blink::WebServiceWorkerError> error( |
| 487 new blink::WebServiceWorkerError( |
| 488 blink::WebServiceWorkerError::ErrorTypeUnknown, |
| 489 "Something went wrong while trying to open the window.")); |
| 490 callbacks->onError(error.release()); |
| 491 pending_client_callbacks_.Remove(request_id); |
| 492 } |
| 493 |
445 void ServiceWorkerScriptContext::OnFocusClientResponse(int request_id, | 494 void ServiceWorkerScriptContext::OnFocusClientResponse(int request_id, |
446 bool result) { | 495 bool result) { |
447 TRACE_EVENT0("ServiceWorker", | 496 TRACE_EVENT0("ServiceWorker", |
448 "ServiceWorkerScriptContext::OnFocusClientResponse"); | 497 "ServiceWorkerScriptContext::OnFocusClientResponse"); |
449 blink::WebServiceWorkerClientFocusCallback* callback = | 498 blink::WebServiceWorkerClientFocusCallback* callback = |
450 pending_focus_client_callbacks_.Lookup(request_id); | 499 pending_focus_client_callbacks_.Lookup(request_id); |
451 if (!callback) { | 500 if (!callback) { |
452 NOTREACHED() << "Got stray response: " << request_id; | 501 NOTREACHED() << "Got stray response: " << request_id; |
453 return; | 502 return; |
454 } | 503 } |
455 callback->onSuccess(&result); | 504 callback->onSuccess(&result); |
456 pending_focus_client_callbacks_.Remove(request_id); | 505 pending_focus_client_callbacks_.Remove(request_id); |
457 } | 506 } |
458 | 507 |
459 void ServiceWorkerScriptContext::OnDidSkipWaiting(int request_id) { | 508 void ServiceWorkerScriptContext::OnDidSkipWaiting(int request_id) { |
460 TRACE_EVENT0("ServiceWorker", | 509 TRACE_EVENT0("ServiceWorker", |
461 "ServiceWorkerScriptContext::OnDidSkipWaiting"); | 510 "ServiceWorkerScriptContext::OnDidSkipWaiting"); |
462 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks = | 511 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks = |
463 pending_skip_waiting_callbacks_.Lookup(request_id); | 512 pending_skip_waiting_callbacks_.Lookup(request_id); |
464 if (!callbacks) { | 513 if (!callbacks) { |
465 NOTREACHED() << "Got stray response: " << request_id; | 514 NOTREACHED() << "Got stray response: " << request_id; |
466 return; | 515 return; |
467 } | 516 } |
468 callbacks->onSuccess(); | 517 callbacks->onSuccess(); |
469 pending_skip_waiting_callbacks_.Remove(request_id); | 518 pending_skip_waiting_callbacks_.Remove(request_id); |
470 } | 519 } |
471 | 520 |
472 } // namespace content | 521 } // namespace content |
OLD | NEW |