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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 OnCrossOriginMessageToWorker) | 255 OnCrossOriginMessageToWorker) |
256 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SendStashedMessagePorts, | 256 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SendStashedMessagePorts, |
257 OnSendStashedMessagePorts) | 257 OnSendStashedMessagePorts) |
258 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClients, OnDidGetClients) | 258 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClients, OnDidGetClients) |
259 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse, | 259 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse, |
260 OnOpenWindowResponse) | 260 OnOpenWindowResponse) |
261 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowError, | 261 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowError, |
262 OnOpenWindowError) | 262 OnOpenWindowError) |
263 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse, | 263 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse, |
264 OnFocusClientResponse) | 264 OnFocusClientResponse) |
| 265 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NavigateClientResponse, |
| 266 OnNavigateClientResponse) |
| 267 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NavigateClientError, |
| 268 OnNavigateClientError) |
265 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidSkipWaiting, OnDidSkipWaiting) | 269 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidSkipWaiting, OnDidSkipWaiting) |
266 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidClaimClients, OnDidClaimClients) | 270 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidClaimClients, OnDidClaimClients) |
267 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ClaimClientsError, OnClaimClientsError) | 271 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ClaimClientsError, OnClaimClientsError) |
268 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_Ping, OnPing); | 272 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_Ping, OnPing); |
269 IPC_MESSAGE_UNHANDLED(handled = false) | 273 IPC_MESSAGE_UNHANDLED(handled = false) |
270 IPC_END_MESSAGE_MAP() | 274 IPC_END_MESSAGE_MAP() |
271 DCHECK(handled); | 275 DCHECK(handled); |
272 } | 276 } |
273 | 277 |
274 blink::WebURL ServiceWorkerContextClient::scope() const { | 278 blink::WebURL ServiceWorkerContextClient::scope() const { |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 | 610 |
607 void ServiceWorkerContextClient::focus( | 611 void ServiceWorkerContextClient::focus( |
608 const blink::WebString& uuid, | 612 const blink::WebString& uuid, |
609 blink::WebServiceWorkerClientCallbacks* callback) { | 613 blink::WebServiceWorkerClientCallbacks* callback) { |
610 DCHECK(callback); | 614 DCHECK(callback); |
611 int request_id = context_->client_callbacks.Add(callback); | 615 int request_id = context_->client_callbacks.Add(callback); |
612 Send(new ServiceWorkerHostMsg_FocusClient(GetRoutingID(), request_id, | 616 Send(new ServiceWorkerHostMsg_FocusClient(GetRoutingID(), request_id, |
613 base::UTF16ToUTF8(uuid))); | 617 base::UTF16ToUTF8(uuid))); |
614 } | 618 } |
615 | 619 |
| 620 void ServiceWorkerContextClient::navigate( |
| 621 const blink::WebString& uuid, |
| 622 const blink::WebURL& url, |
| 623 blink::WebServiceWorkerClientCallbacks* callback) { |
| 624 DCHECK(callback); |
| 625 int request_id = context_->client_callbacks.Add(callback); |
| 626 Send(new ServiceWorkerHostMsg_NavigateClient(GetRoutingID(), request_id, |
| 627 base::UTF16ToUTF8(uuid), url)); |
| 628 } |
| 629 |
616 void ServiceWorkerContextClient::skipWaiting( | 630 void ServiceWorkerContextClient::skipWaiting( |
617 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks) { | 631 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks) { |
618 DCHECK(callbacks); | 632 DCHECK(callbacks); |
619 int request_id = context_->skip_waiting_callbacks.Add(callbacks); | 633 int request_id = context_->skip_waiting_callbacks.Add(callbacks); |
620 Send(new ServiceWorkerHostMsg_SkipWaiting(GetRoutingID(), request_id)); | 634 Send(new ServiceWorkerHostMsg_SkipWaiting(GetRoutingID(), request_id)); |
621 } | 635 } |
622 | 636 |
623 void ServiceWorkerContextClient::claim( | 637 void ServiceWorkerContextClient::claim( |
624 blink::WebServiceWorkerClientsClaimCallbacks* callbacks) { | 638 blink::WebServiceWorkerClientsClaimCallbacks* callbacks) { |
625 DCHECK(callbacks); | 639 DCHECK(callbacks); |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 scoped_ptr<blink::WebServiceWorkerError> error( | 929 scoped_ptr<blink::WebServiceWorkerError> error( |
916 new blink::WebServiceWorkerError( | 930 new blink::WebServiceWorkerError( |
917 blink::WebServiceWorkerError::ErrorTypeNotFound, | 931 blink::WebServiceWorkerError::ErrorTypeNotFound, |
918 "The WindowClient was not found.")); | 932 "The WindowClient was not found.")); |
919 callback->onError(error.release()); | 933 callback->onError(error.release()); |
920 } | 934 } |
921 | 935 |
922 context_->client_callbacks.Remove(request_id); | 936 context_->client_callbacks.Remove(request_id); |
923 } | 937 } |
924 | 938 |
| 939 void ServiceWorkerContextClient::OnNavigateClientResponse( |
| 940 int request_id, |
| 941 const ServiceWorkerClientInfo& client) { |
| 942 TRACE_EVENT0("ServiceWorker", |
| 943 "ServiceWorkerContextClient::OnNavigateClientResponse"); |
| 944 blink::WebServiceWorkerClientCallbacks* callbacks = |
| 945 context_->client_callbacks.Lookup(request_id); |
| 946 if (!callbacks) { |
| 947 NOTREACHED() << "Got stray response: " << request_id; |
| 948 return; |
| 949 } |
| 950 scoped_ptr<blink::WebServiceWorkerClientInfo> web_client; |
| 951 if (!client.IsEmpty()) { |
| 952 DCHECK(client.IsValid()); |
| 953 web_client.reset(new blink::WebServiceWorkerClientInfo( |
| 954 ToWebServiceWorkerClientInfo(client))); |
| 955 } |
| 956 callbacks->onSuccess(web_client.release()); |
| 957 context_->client_callbacks.Remove(request_id); |
| 958 } |
| 959 |
| 960 void ServiceWorkerContextClient::OnNavigateClientError( |
| 961 int request_id, |
| 962 const std::string& message) { |
| 963 TRACE_EVENT0("ServiceWorker", |
| 964 "ServiceWorkerContextClient::OnNavigateClientError"); |
| 965 blink::WebServiceWorkerClientCallbacks* callbacks = |
| 966 context_->client_callbacks.Lookup(request_id); |
| 967 if (!callbacks) { |
| 968 NOTREACHED() << "Got stray response: " << request_id; |
| 969 return; |
| 970 } |
| 971 scoped_ptr<blink::WebServiceWorkerError> error( |
| 972 new blink::WebServiceWorkerError( |
| 973 blink::WebServiceWorkerError::ErrorTypeUnknown, |
| 974 blink::WebString::fromUTF8(message))); |
| 975 callbacks->onError(error.release()); |
| 976 context_->client_callbacks.Remove(request_id); |
| 977 } |
| 978 |
925 void ServiceWorkerContextClient::OnDidSkipWaiting(int request_id) { | 979 void ServiceWorkerContextClient::OnDidSkipWaiting(int request_id) { |
926 TRACE_EVENT0("ServiceWorker", | 980 TRACE_EVENT0("ServiceWorker", |
927 "ServiceWorkerContextClient::OnDidSkipWaiting"); | 981 "ServiceWorkerContextClient::OnDidSkipWaiting"); |
928 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks = | 982 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks = |
929 context_->skip_waiting_callbacks.Lookup(request_id); | 983 context_->skip_waiting_callbacks.Lookup(request_id); |
930 if (!callbacks) { | 984 if (!callbacks) { |
931 NOTREACHED() << "Got stray response: " << request_id; | 985 NOTREACHED() << "Got stray response: " << request_id; |
932 return; | 986 return; |
933 } | 987 } |
934 callbacks->onSuccess(); | 988 callbacks->onSuccess(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 } | 1025 } |
972 | 1026 |
973 base::WeakPtr<ServiceWorkerContextClient> | 1027 base::WeakPtr<ServiceWorkerContextClient> |
974 ServiceWorkerContextClient::GetWeakPtr() { | 1028 ServiceWorkerContextClient::GetWeakPtr() { |
975 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 1029 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
976 DCHECK(context_); | 1030 DCHECK(context_); |
977 return context_->weak_factory.GetWeakPtr(); | 1031 return context_->weak_factory.GetWeakPtr(); |
978 } | 1032 } |
979 | 1033 |
980 } // namespace content | 1034 } // namespace content |
OLD | NEW |