| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 OnNotificationClickEvent) | 96 OnNotificationClickEvent) |
| 97 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_PushEvent, OnPushEvent) | 97 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_PushEvent, OnPushEvent) |
| 98 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_GeofencingEvent, OnGeofencingEvent) | 98 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_GeofencingEvent, OnGeofencingEvent) |
| 99 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginConnectEvent, | 99 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginConnectEvent, |
| 100 OnCrossOriginConnectEvent) | 100 OnCrossOriginConnectEvent) |
| 101 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToWorker, OnPostMessage) | 101 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToWorker, OnPostMessage) |
| 102 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginMessageToWorker, | 102 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginMessageToWorker, |
| 103 OnCrossOriginMessageToWorker) | 103 OnCrossOriginMessageToWorker) |
| 104 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClientDocuments, | 104 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClientDocuments, |
| 105 OnDidGetClientDocuments) | 105 OnDidGetClientDocuments) |
| 106 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse, |
| 107 OnOpenWindowResponse) |
| 108 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowError, |
| 109 OnOpenWindowError) |
| 106 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse, | 110 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse, |
| 107 OnFocusClientResponse) | 111 OnFocusClientResponse) |
| 108 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidSkipWaiting, OnDidSkipWaiting) | 112 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidSkipWaiting, OnDidSkipWaiting) |
| 109 IPC_MESSAGE_UNHANDLED(handled = false) | 113 IPC_MESSAGE_UNHANDLED(handled = false) |
| 110 IPC_END_MESSAGE_MAP() | 114 IPC_END_MESSAGE_MAP() |
| 111 | 115 |
| 112 // TODO(gavinp): Would it be preferable to put an AddListener() method to | 116 // TODO(gavinp): Would it be preferable to put an AddListener() method to |
| 113 // EmbeddedWorkerContextClient? | 117 // EmbeddedWorkerContextClient? |
| 114 if (!handled) | 118 if (!handled) |
| 115 handled = cache_storage_dispatcher_->OnMessageReceived(message); | 119 handled = cache_storage_dispatcher_->OnMessageReceived(message); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 } | 202 } |
| 199 | 203 |
| 200 void ServiceWorkerScriptContext::GetClientDocuments( | 204 void ServiceWorkerScriptContext::GetClientDocuments( |
| 201 blink::WebServiceWorkerClientsCallbacks* callbacks) { | 205 blink::WebServiceWorkerClientsCallbacks* callbacks) { |
| 202 DCHECK(callbacks); | 206 DCHECK(callbacks); |
| 203 int request_id = pending_clients_callbacks_.Add(callbacks); | 207 int request_id = pending_clients_callbacks_.Add(callbacks); |
| 204 Send(new ServiceWorkerHostMsg_GetClientDocuments( | 208 Send(new ServiceWorkerHostMsg_GetClientDocuments( |
| 205 GetRoutingID(), request_id)); | 209 GetRoutingID(), request_id)); |
| 206 } | 210 } |
| 207 | 211 |
| 212 void ServiceWorkerScriptContext::OpenWindow( |
| 213 const GURL& url, blink::WebServiceWorkerClientCallbacks* callbacks) { |
| 214 DCHECK(callbacks); |
| 215 int request_id = pending_client_callbacks_.Add(callbacks); |
| 216 Send(new ServiceWorkerHostMsg_OpenWindow(GetRoutingID(), request_id, url)); |
| 217 } |
| 218 |
| 208 void ServiceWorkerScriptContext::PostMessageToDocument( | 219 void ServiceWorkerScriptContext::PostMessageToDocument( |
| 209 int client_id, | 220 int client_id, |
| 210 const base::string16& message, | 221 const base::string16& message, |
| 211 scoped_ptr<blink::WebMessagePortChannelArray> channels) { | 222 scoped_ptr<blink::WebMessagePortChannelArray> channels) { |
| 212 // This may send channels for MessagePorts, and all internal book-keeping | 223 // This may send channels for MessagePorts, and all internal book-keeping |
| 213 // messages for MessagePort (e.g. QueueMessages) are sent from main thread | 224 // messages for MessagePort (e.g. QueueMessages) are sent from main thread |
| 214 // (with thread hopping), so we need to do the same thread hopping here not | 225 // (with thread hopping), so we need to do the same thread hopping here not |
| 215 // to overtake those messages. | 226 // to overtake those messages. |
| 216 embedded_context_->main_thread_proxy()->PostTask( | 227 embedded_context_->main_thread_proxy()->PostTask( |
| 217 FROM_HERE, | 228 FROM_HERE, |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 new blink::WebServiceWorkerClientsInfo); | 431 new blink::WebServiceWorkerClientsInfo); |
| 421 blink::WebVector<blink::WebServiceWorkerClientInfo> convertedClients( | 432 blink::WebVector<blink::WebServiceWorkerClientInfo> convertedClients( |
| 422 clients.size()); | 433 clients.size()); |
| 423 for (size_t i = 0; i < clients.size(); ++i) | 434 for (size_t i = 0; i < clients.size(); ++i) |
| 424 convertedClients[i] = clients[i]; | 435 convertedClients[i] = clients[i]; |
| 425 info->clients.swap(convertedClients); | 436 info->clients.swap(convertedClients); |
| 426 callbacks->onSuccess(info.release()); | 437 callbacks->onSuccess(info.release()); |
| 427 pending_clients_callbacks_.Remove(request_id); | 438 pending_clients_callbacks_.Remove(request_id); |
| 428 } | 439 } |
| 429 | 440 |
| 441 void ServiceWorkerScriptContext::OnOpenWindowResponse( |
| 442 int request_id, |
| 443 const ServiceWorkerClientInfo& client) { |
| 444 TRACE_EVENT0("ServiceWorker", |
| 445 "ServiceWorkerScriptContext::OnOpenWindowResponse"); |
| 446 blink::WebServiceWorkerClientCallbacks* callbacks = |
| 447 pending_client_callbacks_.Lookup(request_id); |
| 448 if (!callbacks) { |
| 449 NOTREACHED() << "Got stray response: " << request_id; |
| 450 return; |
| 451 } |
| 452 scoped_ptr<blink::WebServiceWorkerClientInfo> web_client; |
| 453 if (!client.IsEmpty()) { |
| 454 DCHECK(client.IsValid()); |
| 455 web_client.reset(new blink::WebServiceWorkerClientInfo(client)); |
| 456 } |
| 457 callbacks->onSuccess(web_client.release()); |
| 458 pending_client_callbacks_.Remove(request_id); |
| 459 } |
| 460 |
| 461 void ServiceWorkerScriptContext::OnOpenWindowError(int request_id) { |
| 462 TRACE_EVENT0("ServiceWorker", |
| 463 "ServiceWorkerScriptContext::OnOpenWindowError"); |
| 464 blink::WebServiceWorkerClientCallbacks* callbacks = |
| 465 pending_client_callbacks_.Lookup(request_id); |
| 466 if (!callbacks) { |
| 467 NOTREACHED() << "Got stray response: " << request_id; |
| 468 return; |
| 469 } |
| 470 scoped_ptr<blink::WebServiceWorkerError> error( |
| 471 new blink::WebServiceWorkerError( |
| 472 blink::WebServiceWorkerError::ErrorTypeUnknown, |
| 473 "Something went wrong while trying to open the window.")); |
| 474 callbacks->onError(error.release()); |
| 475 pending_client_callbacks_.Remove(request_id); |
| 476 } |
| 477 |
| 430 void ServiceWorkerScriptContext::OnFocusClientResponse(int request_id, | 478 void ServiceWorkerScriptContext::OnFocusClientResponse(int request_id, |
| 431 bool result) { | 479 bool result) { |
| 432 TRACE_EVENT0("ServiceWorker", | 480 TRACE_EVENT0("ServiceWorker", |
| 433 "ServiceWorkerScriptContext::OnFocusClientResponse"); | 481 "ServiceWorkerScriptContext::OnFocusClientResponse"); |
| 434 blink::WebServiceWorkerClientFocusCallback* callback = | 482 blink::WebServiceWorkerClientFocusCallback* callback = |
| 435 pending_focus_client_callbacks_.Lookup(request_id); | 483 pending_focus_client_callbacks_.Lookup(request_id); |
| 436 if (!callback) { | 484 if (!callback) { |
| 437 NOTREACHED() << "Got stray response: " << request_id; | 485 NOTREACHED() << "Got stray response: " << request_id; |
| 438 return; | 486 return; |
| 439 } | 487 } |
| 440 callback->onSuccess(&result); | 488 callback->onSuccess(&result); |
| 441 pending_focus_client_callbacks_.Remove(request_id); | 489 pending_focus_client_callbacks_.Remove(request_id); |
| 442 } | 490 } |
| 443 | 491 |
| 444 void ServiceWorkerScriptContext::OnDidSkipWaiting(int request_id) { | 492 void ServiceWorkerScriptContext::OnDidSkipWaiting(int request_id) { |
| 445 TRACE_EVENT0("ServiceWorker", | 493 TRACE_EVENT0("ServiceWorker", |
| 446 "ServiceWorkerScriptContext::OnDidSkipWaiting"); | 494 "ServiceWorkerScriptContext::OnDidSkipWaiting"); |
| 447 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks = | 495 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks = |
| 448 pending_skip_waiting_callbacks_.Lookup(request_id); | 496 pending_skip_waiting_callbacks_.Lookup(request_id); |
| 449 if (!callbacks) { | 497 if (!callbacks) { |
| 450 NOTREACHED() << "Got stray response: " << request_id; | 498 NOTREACHED() << "Got stray response: " << request_id; |
| 451 return; | 499 return; |
| 452 } | 500 } |
| 453 callbacks->onSuccess(); | 501 callbacks->onSuccess(); |
| 454 pending_skip_waiting_callbacks_.Remove(request_id); | 502 pending_skip_waiting_callbacks_.Remove(request_id); |
| 455 } | 503 } |
| 456 | 504 |
| 457 } // namespace content | 505 } // namespace content |
| OLD | NEW |