Chromium Code Reviews| 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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 OnCrossOriginMessageToWorker) | 256 OnCrossOriginMessageToWorker) |
| 257 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SendStashedMessagePorts, | 257 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SendStashedMessagePorts, |
| 258 OnSendStashedMessagePorts) | 258 OnSendStashedMessagePorts) |
| 259 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClients, OnDidGetClients) | 259 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClients, OnDidGetClients) |
| 260 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse, | 260 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse, |
| 261 OnOpenWindowResponse) | 261 OnOpenWindowResponse) |
| 262 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowError, | 262 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowError, |
| 263 OnOpenWindowError) | 263 OnOpenWindowError) |
| 264 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse, | 264 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse, |
| 265 OnFocusClientResponse) | 265 OnFocusClientResponse) |
| 266 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NavigateClientResponse, | |
| 267 OnNavigateClientResponse) | |
| 268 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NavigateClientError, | |
| 269 OnNavigateClientError) | |
| 266 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidSkipWaiting, OnDidSkipWaiting) | 270 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidSkipWaiting, OnDidSkipWaiting) |
| 267 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidClaimClients, OnDidClaimClients) | 271 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidClaimClients, OnDidClaimClients) |
| 268 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ClaimClientsError, OnClaimClientsError) | 272 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ClaimClientsError, OnClaimClientsError) |
| 269 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_Ping, OnPing); | 273 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_Ping, OnPing); |
| 270 IPC_MESSAGE_UNHANDLED(handled = false) | 274 IPC_MESSAGE_UNHANDLED(handled = false) |
| 271 IPC_END_MESSAGE_MAP() | 275 IPC_END_MESSAGE_MAP() |
| 272 DCHECK(handled); | 276 DCHECK(handled); |
| 273 } | 277 } |
| 274 | 278 |
| 275 void ServiceWorkerContextClient::BindServiceRegistry( | 279 void ServiceWorkerContextClient::BindServiceRegistry( |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 574 | 578 |
| 575 void ServiceWorkerContextClient::focus( | 579 void ServiceWorkerContextClient::focus( |
| 576 const blink::WebString& uuid, | 580 const blink::WebString& uuid, |
| 577 blink::WebServiceWorkerClientCallbacks* callback) { | 581 blink::WebServiceWorkerClientCallbacks* callback) { |
| 578 DCHECK(callback); | 582 DCHECK(callback); |
| 579 int request_id = context_->client_callbacks.Add(callback); | 583 int request_id = context_->client_callbacks.Add(callback); |
| 580 Send(new ServiceWorkerHostMsg_FocusClient(GetRoutingID(), request_id, | 584 Send(new ServiceWorkerHostMsg_FocusClient(GetRoutingID(), request_id, |
| 581 base::UTF16ToUTF8(uuid))); | 585 base::UTF16ToUTF8(uuid))); |
| 582 } | 586 } |
| 583 | 587 |
| 588 void ServiceWorkerContextClient::navigate( | |
| 589 const blink::WebString& uuid, | |
| 590 const blink::WebURL& url, | |
| 591 blink::WebServiceWorkerClientCallbacks* callback) { | |
| 592 DCHECK(callback); | |
| 593 int request_id = context_->client_callbacks.Add(callback); | |
| 594 Send(new ServiceWorkerHostMsg_NavigateClient(GetRoutingID(), request_id, | |
| 595 base::UTF16ToUTF8(uuid), url)); | |
| 596 } | |
| 597 | |
| 584 void ServiceWorkerContextClient::skipWaiting( | 598 void ServiceWorkerContextClient::skipWaiting( |
| 585 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks) { | 599 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks) { |
| 586 DCHECK(callbacks); | 600 DCHECK(callbacks); |
| 587 int request_id = context_->skip_waiting_callbacks.Add(callbacks); | 601 int request_id = context_->skip_waiting_callbacks.Add(callbacks); |
| 588 Send(new ServiceWorkerHostMsg_SkipWaiting(GetRoutingID(), request_id)); | 602 Send(new ServiceWorkerHostMsg_SkipWaiting(GetRoutingID(), request_id)); |
| 589 } | 603 } |
| 590 | 604 |
| 591 void ServiceWorkerContextClient::claim( | 605 void ServiceWorkerContextClient::claim( |
| 592 blink::WebServiceWorkerClientsClaimCallbacks* callbacks) { | 606 blink::WebServiceWorkerClientsClaimCallbacks* callbacks) { |
| 593 DCHECK(callbacks); | 607 DCHECK(callbacks); |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 866 scoped_ptr<blink::WebServiceWorkerError> error( | 880 scoped_ptr<blink::WebServiceWorkerError> error( |
| 867 new blink::WebServiceWorkerError( | 881 new blink::WebServiceWorkerError( |
| 868 blink::WebServiceWorkerError::ErrorTypeNotFound, | 882 blink::WebServiceWorkerError::ErrorTypeNotFound, |
| 869 "The WindowClient was not found.")); | 883 "The WindowClient was not found.")); |
| 870 callback->onError(error.release()); | 884 callback->onError(error.release()); |
| 871 } | 885 } |
| 872 | 886 |
| 873 context_->client_callbacks.Remove(request_id); | 887 context_->client_callbacks.Remove(request_id); |
| 874 } | 888 } |
| 875 | 889 |
| 890 void ServiceWorkerContextClient::OnNavigateClientResponse( | |
| 891 int request_id, | |
| 892 const ServiceWorkerClientInfo& client) { | |
| 893 TRACE_EVENT0("ServiceWorker", | |
| 894 "ServiceWorkerContextClient::OnNavigateClientResponse"); | |
| 895 blink::WebServiceWorkerClientCallbacks* callbacks = | |
| 896 context_->client_callbacks.Lookup(request_id); | |
| 897 if (!callbacks) { | |
| 898 NOTREACHED() << "Got stray response: " << request_id; | |
| 899 return; | |
| 900 } | |
| 901 scoped_ptr<blink::WebServiceWorkerClientInfo> web_client; | |
| 902 if (!client.IsEmpty()) { | |
| 903 DCHECK(client.IsValid()); | |
| 904 web_client.reset(new blink::WebServiceWorkerClientInfo( | |
| 905 ToWebServiceWorkerClientInfo(client))); | |
| 906 } | |
| 907 callbacks->onSuccess(web_client.release()); | |
| 908 context_->client_callbacks.Remove(request_id); | |
| 909 } | |
| 910 | |
| 911 void ServiceWorkerContextClient::OnNavigateClientError(int request_id, | |
| 912 const GURL& url) { | |
| 913 TRACE_EVENT0("ServiceWorker", | |
| 914 "ServiceWorkerContextClient::OnNavigateClientError"); | |
| 915 blink::WebServiceWorkerClientCallbacks* callbacks = | |
| 916 context_->client_callbacks.Lookup(request_id); | |
| 917 if (!callbacks) { | |
| 918 NOTREACHED() << "Got stray response: " << request_id; | |
| 919 return; | |
| 920 } | |
| 921 std::string message; | |
|
palmer
2015/07/27 21:55:58
I might simplify this error message, and also disa
zino
2015/07/28 01:27:22
Done.
| |
| 922 if (url.is_empty()) | |
| 923 message = "Something went wrong while trying to navigate client."; | |
| 924 else | |
| 925 message = url.spec() + " cannot navigate."; | |
| 926 scoped_ptr<blink::WebServiceWorkerError> error( | |
| 927 new blink::WebServiceWorkerError( | |
| 928 blink::WebServiceWorkerError::ErrorTypeUnknown, | |
| 929 blink::WebString::fromUTF8(message))); | |
| 930 callbacks->onError(error.release()); | |
| 931 context_->client_callbacks.Remove(request_id); | |
| 932 } | |
| 933 | |
| 876 void ServiceWorkerContextClient::OnDidSkipWaiting(int request_id) { | 934 void ServiceWorkerContextClient::OnDidSkipWaiting(int request_id) { |
| 877 TRACE_EVENT0("ServiceWorker", | 935 TRACE_EVENT0("ServiceWorker", |
| 878 "ServiceWorkerContextClient::OnDidSkipWaiting"); | 936 "ServiceWorkerContextClient::OnDidSkipWaiting"); |
| 879 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks = | 937 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks = |
| 880 context_->skip_waiting_callbacks.Lookup(request_id); | 938 context_->skip_waiting_callbacks.Lookup(request_id); |
| 881 if (!callbacks) { | 939 if (!callbacks) { |
| 882 NOTREACHED() << "Got stray response: " << request_id; | 940 NOTREACHED() << "Got stray response: " << request_id; |
| 883 return; | 941 return; |
| 884 } | 942 } |
| 885 callbacks->onSuccess(); | 943 callbacks->onSuccess(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 922 } | 980 } |
| 923 | 981 |
| 924 base::WeakPtr<ServiceWorkerContextClient> | 982 base::WeakPtr<ServiceWorkerContextClient> |
| 925 ServiceWorkerContextClient::GetWeakPtr() { | 983 ServiceWorkerContextClient::GetWeakPtr() { |
| 926 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 984 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
| 927 DCHECK(context_); | 985 DCHECK(context_); |
| 928 return context_->weak_factory.GetWeakPtr(); | 986 return context_->weak_factory.GetWeakPtr(); |
| 929 } | 987 } |
| 930 | 988 |
| 931 } // namespace content | 989 } // namespace content |
| OLD | NEW |