OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_context_client.h" | 5 #include "content/renderer/service_worker/service_worker_context_client.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.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 "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToWorker, OnPostMessage) | 251 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToWorker, OnPostMessage) |
252 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginMessageToWorker, | 252 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginMessageToWorker, |
253 OnCrossOriginMessageToWorker) | 253 OnCrossOriginMessageToWorker) |
254 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClients, OnDidGetClients) | 254 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClients, OnDidGetClients) |
255 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse, | 255 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse, |
256 OnOpenWindowResponse) | 256 OnOpenWindowResponse) |
257 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowError, | 257 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowError, |
258 OnOpenWindowError) | 258 OnOpenWindowError) |
259 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse, | 259 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse, |
260 OnFocusClientResponse) | 260 OnFocusClientResponse) |
| 261 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NavigateClientResponse, |
| 262 OnNavigateClientResponse) |
| 263 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NavigateClientError, |
| 264 OnNavigateClientError) |
261 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidSkipWaiting, OnDidSkipWaiting) | 265 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidSkipWaiting, OnDidSkipWaiting) |
262 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidClaimClients, OnDidClaimClients) | 266 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidClaimClients, OnDidClaimClients) |
263 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ClaimClientsError, OnClaimClientsError) | 267 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ClaimClientsError, OnClaimClientsError) |
264 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_Ping, OnPing); | 268 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_Ping, OnPing); |
265 IPC_MESSAGE_UNHANDLED(handled = false) | 269 IPC_MESSAGE_UNHANDLED(handled = false) |
266 IPC_END_MESSAGE_MAP() | 270 IPC_END_MESSAGE_MAP() |
267 DCHECK(handled); | 271 DCHECK(handled); |
268 } | 272 } |
269 | 273 |
270 void ServiceWorkerContextClient::BindServiceRegistry( | 274 void ServiceWorkerContextClient::BindServiceRegistry( |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 void ServiceWorkerContextClient::focus( | 584 void ServiceWorkerContextClient::focus( |
581 const blink::WebString& uuid, | 585 const blink::WebString& uuid, |
582 blink::WebServiceWorkerClientCallbacks* callback) { | 586 blink::WebServiceWorkerClientCallbacks* callback) { |
583 DCHECK(callback); | 587 DCHECK(callback); |
584 int request_id = context_->client_callbacks.Add(callback); | 588 int request_id = context_->client_callbacks.Add(callback); |
585 Send(new ServiceWorkerHostMsg_FocusClient( | 589 Send(new ServiceWorkerHostMsg_FocusClient( |
586 GetRoutingID(), request_id, | 590 GetRoutingID(), request_id, |
587 base::UTF16ToUTF8(base::StringPiece16(uuid)))); | 591 base::UTF16ToUTF8(base::StringPiece16(uuid)))); |
588 } | 592 } |
589 | 593 |
| 594 void ServiceWorkerContextClient::navigate( |
| 595 const blink::WebString& uuid, |
| 596 const blink::WebURL& url, |
| 597 blink::WebServiceWorkerClientCallbacks* callback) { |
| 598 DCHECK(callback); |
| 599 int request_id = context_->client_callbacks.Add(callback); |
| 600 Send(new ServiceWorkerHostMsg_NavigateClient( |
| 601 GetRoutingID(), request_id, base::UTF16ToUTF8(base::StringPiece16(uuid)), |
| 602 url)); |
| 603 } |
| 604 |
590 void ServiceWorkerContextClient::skipWaiting( | 605 void ServiceWorkerContextClient::skipWaiting( |
591 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks) { | 606 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks) { |
592 DCHECK(callbacks); | 607 DCHECK(callbacks); |
593 int request_id = context_->skip_waiting_callbacks.Add(callbacks); | 608 int request_id = context_->skip_waiting_callbacks.Add(callbacks); |
594 Send(new ServiceWorkerHostMsg_SkipWaiting(GetRoutingID(), request_id)); | 609 Send(new ServiceWorkerHostMsg_SkipWaiting(GetRoutingID(), request_id)); |
595 } | 610 } |
596 | 611 |
597 void ServiceWorkerContextClient::claim( | 612 void ServiceWorkerContextClient::claim( |
598 blink::WebServiceWorkerClientsClaimCallbacks* callbacks) { | 613 blink::WebServiceWorkerClientsClaimCallbacks* callbacks) { |
599 DCHECK(callbacks); | 614 DCHECK(callbacks); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 scoped_ptr<blink::WebServiceWorkerError> error( | 862 scoped_ptr<blink::WebServiceWorkerError> error( |
848 new blink::WebServiceWorkerError( | 863 new blink::WebServiceWorkerError( |
849 blink::WebServiceWorkerError::ErrorTypeNotFound, | 864 blink::WebServiceWorkerError::ErrorTypeNotFound, |
850 "The WindowClient was not found.")); | 865 "The WindowClient was not found.")); |
851 callback->onError(error.release()); | 866 callback->onError(error.release()); |
852 } | 867 } |
853 | 868 |
854 context_->client_callbacks.Remove(request_id); | 869 context_->client_callbacks.Remove(request_id); |
855 } | 870 } |
856 | 871 |
| 872 void ServiceWorkerContextClient::OnNavigateClientResponse( |
| 873 int request_id, |
| 874 const ServiceWorkerClientInfo& client) { |
| 875 TRACE_EVENT0("ServiceWorker", |
| 876 "ServiceWorkerContextClient::OnNavigateClientResponse"); |
| 877 blink::WebServiceWorkerClientCallbacks* callbacks = |
| 878 context_->client_callbacks.Lookup(request_id); |
| 879 if (!callbacks) { |
| 880 NOTREACHED() << "Got stray response: " << request_id; |
| 881 return; |
| 882 } |
| 883 scoped_ptr<blink::WebServiceWorkerClientInfo> web_client; |
| 884 if (!client.IsEmpty()) { |
| 885 DCHECK(client.IsValid()); |
| 886 web_client.reset(new blink::WebServiceWorkerClientInfo( |
| 887 ToWebServiceWorkerClientInfo(client))); |
| 888 } |
| 889 callbacks->onSuccess(web_client.release()); |
| 890 context_->client_callbacks.Remove(request_id); |
| 891 } |
| 892 |
| 893 void ServiceWorkerContextClient::OnNavigateClientError(int request_id, |
| 894 const GURL& url) { |
| 895 TRACE_EVENT0("ServiceWorker", |
| 896 "ServiceWorkerContextClient::OnNavigateClientError"); |
| 897 blink::WebServiceWorkerClientCallbacks* callbacks = |
| 898 context_->client_callbacks.Lookup(request_id); |
| 899 if (!callbacks) { |
| 900 NOTREACHED() << "Got stray response: " << request_id; |
| 901 return; |
| 902 } |
| 903 std::string message = "Cannot navigate to URL: " + url.spec(); |
| 904 scoped_ptr<blink::WebServiceWorkerError> error( |
| 905 new blink::WebServiceWorkerError( |
| 906 blink::WebServiceWorkerError::ErrorTypeUnknown, |
| 907 blink::WebString::fromUTF8(message))); |
| 908 callbacks->onError(error.release()); |
| 909 context_->client_callbacks.Remove(request_id); |
| 910 } |
| 911 |
857 void ServiceWorkerContextClient::OnDidSkipWaiting(int request_id) { | 912 void ServiceWorkerContextClient::OnDidSkipWaiting(int request_id) { |
858 TRACE_EVENT0("ServiceWorker", | 913 TRACE_EVENT0("ServiceWorker", |
859 "ServiceWorkerContextClient::OnDidSkipWaiting"); | 914 "ServiceWorkerContextClient::OnDidSkipWaiting"); |
860 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks = | 915 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks = |
861 context_->skip_waiting_callbacks.Lookup(request_id); | 916 context_->skip_waiting_callbacks.Lookup(request_id); |
862 if (!callbacks) { | 917 if (!callbacks) { |
863 NOTREACHED() << "Got stray response: " << request_id; | 918 NOTREACHED() << "Got stray response: " << request_id; |
864 return; | 919 return; |
865 } | 920 } |
866 callbacks->onSuccess(); | 921 callbacks->onSuccess(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
903 } | 958 } |
904 | 959 |
905 base::WeakPtr<ServiceWorkerContextClient> | 960 base::WeakPtr<ServiceWorkerContextClient> |
906 ServiceWorkerContextClient::GetWeakPtr() { | 961 ServiceWorkerContextClient::GetWeakPtr() { |
907 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 962 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
908 DCHECK(context_); | 963 DCHECK(context_); |
909 return context_->weak_factory.GetWeakPtr(); | 964 return context_->weak_factory.GetWeakPtr(); |
910 } | 965 } |
911 | 966 |
912 } // namespace content | 967 } // namespace content |
OLD | NEW |