| 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 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 | 603 |
| 600 void ServiceWorkerContextClient::focus( | 604 void ServiceWorkerContextClient::focus( |
| 601 const blink::WebString& uuid, | 605 const blink::WebString& uuid, |
| 602 blink::WebServiceWorkerClientCallbacks* callback) { | 606 blink::WebServiceWorkerClientCallbacks* callback) { |
| 603 DCHECK(callback); | 607 DCHECK(callback); |
| 604 int request_id = context_->client_callbacks.Add(callback); | 608 int request_id = context_->client_callbacks.Add(callback); |
| 605 Send(new ServiceWorkerHostMsg_FocusClient(GetRoutingID(), request_id, | 609 Send(new ServiceWorkerHostMsg_FocusClient(GetRoutingID(), request_id, |
| 606 base::UTF16ToUTF8(uuid))); | 610 base::UTF16ToUTF8(uuid))); |
| 607 } | 611 } |
| 608 | 612 |
| 613 void ServiceWorkerContextClient::navigate( |
| 614 const blink::WebString& uuid, |
| 615 const blink::WebURL& url, |
| 616 blink::WebServiceWorkerClientCallbacks* callback) { |
| 617 DCHECK(callback); |
| 618 int request_id = context_->client_callbacks.Add(callback); |
| 619 Send(new ServiceWorkerHostMsg_NavigateClient(GetRoutingID(), request_id, |
| 620 base::UTF16ToUTF8(uuid), url)); |
| 621 } |
| 622 |
| 609 void ServiceWorkerContextClient::skipWaiting( | 623 void ServiceWorkerContextClient::skipWaiting( |
| 610 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks) { | 624 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks) { |
| 611 DCHECK(callbacks); | 625 DCHECK(callbacks); |
| 612 int request_id = context_->skip_waiting_callbacks.Add(callbacks); | 626 int request_id = context_->skip_waiting_callbacks.Add(callbacks); |
| 613 Send(new ServiceWorkerHostMsg_SkipWaiting(GetRoutingID(), request_id)); | 627 Send(new ServiceWorkerHostMsg_SkipWaiting(GetRoutingID(), request_id)); |
| 614 } | 628 } |
| 615 | 629 |
| 616 void ServiceWorkerContextClient::claim( | 630 void ServiceWorkerContextClient::claim( |
| 617 blink::WebServiceWorkerClientsClaimCallbacks* callbacks) { | 631 blink::WebServiceWorkerClientsClaimCallbacks* callbacks) { |
| 618 DCHECK(callbacks); | 632 DCHECK(callbacks); |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 908 scoped_ptr<blink::WebServiceWorkerError> error( | 922 scoped_ptr<blink::WebServiceWorkerError> error( |
| 909 new blink::WebServiceWorkerError( | 923 new blink::WebServiceWorkerError( |
| 910 blink::WebServiceWorkerError::ErrorTypeNotFound, | 924 blink::WebServiceWorkerError::ErrorTypeNotFound, |
| 911 "The WindowClient was not found.")); | 925 "The WindowClient was not found.")); |
| 912 callback->onError(error.release()); | 926 callback->onError(error.release()); |
| 913 } | 927 } |
| 914 | 928 |
| 915 context_->client_callbacks.Remove(request_id); | 929 context_->client_callbacks.Remove(request_id); |
| 916 } | 930 } |
| 917 | 931 |
| 932 void ServiceWorkerContextClient::OnNavigateClientResponse( |
| 933 int request_id, |
| 934 const ServiceWorkerClientInfo& client) { |
| 935 TRACE_EVENT0("ServiceWorker", |
| 936 "ServiceWorkerContextClient::OnNavigateClientResponse"); |
| 937 blink::WebServiceWorkerClientCallbacks* callbacks = |
| 938 context_->client_callbacks.Lookup(request_id); |
| 939 if (!callbacks) { |
| 940 NOTREACHED() << "Got stray response: " << request_id; |
| 941 return; |
| 942 } |
| 943 scoped_ptr<blink::WebServiceWorkerClientInfo> web_client; |
| 944 if (!client.IsEmpty()) { |
| 945 DCHECK(client.IsValid()); |
| 946 web_client.reset(new blink::WebServiceWorkerClientInfo( |
| 947 ToWebServiceWorkerClientInfo(client))); |
| 948 } |
| 949 callbacks->onSuccess(web_client.release()); |
| 950 context_->client_callbacks.Remove(request_id); |
| 951 } |
| 952 |
| 953 void ServiceWorkerContextClient::OnNavigateClientError( |
| 954 int request_id, |
| 955 const std::string& message) { |
| 956 TRACE_EVENT0("ServiceWorker", |
| 957 "ServiceWorkerContextClient::OnNavigateClientError"); |
| 958 blink::WebServiceWorkerClientCallbacks* callbacks = |
| 959 context_->client_callbacks.Lookup(request_id); |
| 960 if (!callbacks) { |
| 961 NOTREACHED() << "Got stray response: " << request_id; |
| 962 return; |
| 963 } |
| 964 scoped_ptr<blink::WebServiceWorkerError> error( |
| 965 new blink::WebServiceWorkerError( |
| 966 blink::WebServiceWorkerError::ErrorTypeUnknown, |
| 967 blink::WebString::fromUTF8(message))); |
| 968 callbacks->onError(error.release()); |
| 969 context_->client_callbacks.Remove(request_id); |
| 970 } |
| 971 |
| 918 void ServiceWorkerContextClient::OnDidSkipWaiting(int request_id) { | 972 void ServiceWorkerContextClient::OnDidSkipWaiting(int request_id) { |
| 919 TRACE_EVENT0("ServiceWorker", | 973 TRACE_EVENT0("ServiceWorker", |
| 920 "ServiceWorkerContextClient::OnDidSkipWaiting"); | 974 "ServiceWorkerContextClient::OnDidSkipWaiting"); |
| 921 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks = | 975 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks = |
| 922 context_->skip_waiting_callbacks.Lookup(request_id); | 976 context_->skip_waiting_callbacks.Lookup(request_id); |
| 923 if (!callbacks) { | 977 if (!callbacks) { |
| 924 NOTREACHED() << "Got stray response: " << request_id; | 978 NOTREACHED() << "Got stray response: " << request_id; |
| 925 return; | 979 return; |
| 926 } | 980 } |
| 927 callbacks->onSuccess(); | 981 callbacks->onSuccess(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 964 } | 1018 } |
| 965 | 1019 |
| 966 base::WeakPtr<ServiceWorkerContextClient> | 1020 base::WeakPtr<ServiceWorkerContextClient> |
| 967 ServiceWorkerContextClient::GetWeakPtr() { | 1021 ServiceWorkerContextClient::GetWeakPtr() { |
| 968 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 1022 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
| 969 DCHECK(context_); | 1023 DCHECK(context_); |
| 970 return context_->weak_factory.GetWeakPtr(); | 1024 return context_->weak_factory.GetWeakPtr(); |
| 971 } | 1025 } |
| 972 | 1026 |
| 973 } // namespace content | 1027 } // namespace content |
| OLD | NEW |