| 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) |
| 265 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidSkipWaiting, OnDidSkipWaiting) | 267 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidSkipWaiting, OnDidSkipWaiting) |
| 266 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidClaimClients, OnDidClaimClients) | 268 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidClaimClients, OnDidClaimClients) |
| 267 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ClaimClientsError, OnClaimClientsError) | 269 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ClaimClientsError, OnClaimClientsError) |
| 268 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_Ping, OnPing); | 270 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_Ping, OnPing); |
| 269 IPC_MESSAGE_UNHANDLED(handled = false) | 271 IPC_MESSAGE_UNHANDLED(handled = false) |
| 270 IPC_END_MESSAGE_MAP() | 272 IPC_END_MESSAGE_MAP() |
| 271 DCHECK(handled); | 273 DCHECK(handled); |
| 272 } | 274 } |
| 273 | 275 |
| 274 blink::WebURL ServiceWorkerContextClient::scope() const { | 276 blink::WebURL ServiceWorkerContextClient::scope() const { |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 | 608 |
| 607 void ServiceWorkerContextClient::focus( | 609 void ServiceWorkerContextClient::focus( |
| 608 const blink::WebString& uuid, | 610 const blink::WebString& uuid, |
| 609 blink::WebServiceWorkerClientCallbacks* callback) { | 611 blink::WebServiceWorkerClientCallbacks* callback) { |
| 610 DCHECK(callback); | 612 DCHECK(callback); |
| 611 int request_id = context_->client_callbacks.Add(callback); | 613 int request_id = context_->client_callbacks.Add(callback); |
| 612 Send(new ServiceWorkerHostMsg_FocusClient(GetRoutingID(), request_id, | 614 Send(new ServiceWorkerHostMsg_FocusClient(GetRoutingID(), request_id, |
| 613 base::UTF16ToUTF8(uuid))); | 615 base::UTF16ToUTF8(uuid))); |
| 614 } | 616 } |
| 615 | 617 |
| 618 void ServiceWorkerContextClient::navigate( |
| 619 const blink::WebString& uuid, |
| 620 const blink::WebURL& url, |
| 621 blink::WebServiceWorkerClientCallbacks* callback) { |
| 622 DCHECK(callback); |
| 623 int request_id = context_->client_callbacks.Add(callback); |
| 624 Send(new ServiceWorkerHostMsg_NavigateClient(GetRoutingID(), request_id, |
| 625 base::UTF16ToUTF8(uuid), url)); |
| 626 } |
| 627 |
| 616 void ServiceWorkerContextClient::skipWaiting( | 628 void ServiceWorkerContextClient::skipWaiting( |
| 617 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks) { | 629 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks) { |
| 618 DCHECK(callbacks); | 630 DCHECK(callbacks); |
| 619 int request_id = context_->skip_waiting_callbacks.Add(callbacks); | 631 int request_id = context_->skip_waiting_callbacks.Add(callbacks); |
| 620 Send(new ServiceWorkerHostMsg_SkipWaiting(GetRoutingID(), request_id)); | 632 Send(new ServiceWorkerHostMsg_SkipWaiting(GetRoutingID(), request_id)); |
| 621 } | 633 } |
| 622 | 634 |
| 623 void ServiceWorkerContextClient::claim( | 635 void ServiceWorkerContextClient::claim( |
| 624 blink::WebServiceWorkerClientsClaimCallbacks* callbacks) { | 636 blink::WebServiceWorkerClientsClaimCallbacks* callbacks) { |
| 625 DCHECK(callbacks); | 637 DCHECK(callbacks); |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 915 scoped_ptr<blink::WebServiceWorkerError> error( | 927 scoped_ptr<blink::WebServiceWorkerError> error( |
| 916 new blink::WebServiceWorkerError( | 928 new blink::WebServiceWorkerError( |
| 917 blink::WebServiceWorkerError::ErrorTypeNotFound, | 929 blink::WebServiceWorkerError::ErrorTypeNotFound, |
| 918 "The WindowClient was not found.")); | 930 "The WindowClient was not found.")); |
| 919 callback->onError(error.release()); | 931 callback->onError(error.release()); |
| 920 } | 932 } |
| 921 | 933 |
| 922 context_->client_callbacks.Remove(request_id); | 934 context_->client_callbacks.Remove(request_id); |
| 923 } | 935 } |
| 924 | 936 |
| 937 void ServiceWorkerContextClient::OnNavigateClientResponse( |
| 938 int request_id, |
| 939 const ServiceWorkerClientInfo& client) { |
| 940 TRACE_EVENT0("ServiceWorker", |
| 941 "ServiceWorkerContextClient::OnNavigateClientResponse"); |
| 942 blink::WebServiceWorkerClientCallbacks* callback = |
| 943 context_->client_callbacks.Lookup(request_id); |
| 944 if (!callback) { |
| 945 NOTREACHED() << "Got stray response: " << request_id; |
| 946 return; |
| 947 } |
| 948 |
| 949 if (client.IsEmpty()) { |
| 950 callback->onSuccess(nullptr); |
| 951 } else { |
| 952 scoped_ptr<blink::WebServiceWorkerClientInfo> web_client( |
| 953 new blink::WebServiceWorkerClientInfo( |
| 954 ToWebServiceWorkerClientInfo(client))); |
| 955 callback->onSuccess(web_client.release()); |
| 956 } |
| 957 |
| 958 context_->client_callbacks.Remove(request_id); |
| 959 } |
| 960 |
| 925 void ServiceWorkerContextClient::OnDidSkipWaiting(int request_id) { | 961 void ServiceWorkerContextClient::OnDidSkipWaiting(int request_id) { |
| 926 TRACE_EVENT0("ServiceWorker", | 962 TRACE_EVENT0("ServiceWorker", |
| 927 "ServiceWorkerContextClient::OnDidSkipWaiting"); | 963 "ServiceWorkerContextClient::OnDidSkipWaiting"); |
| 928 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks = | 964 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks = |
| 929 context_->skip_waiting_callbacks.Lookup(request_id); | 965 context_->skip_waiting_callbacks.Lookup(request_id); |
| 930 if (!callbacks) { | 966 if (!callbacks) { |
| 931 NOTREACHED() << "Got stray response: " << request_id; | 967 NOTREACHED() << "Got stray response: " << request_id; |
| 932 return; | 968 return; |
| 933 } | 969 } |
| 934 callbacks->onSuccess(); | 970 callbacks->onSuccess(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 } | 1007 } |
| 972 | 1008 |
| 973 base::WeakPtr<ServiceWorkerContextClient> | 1009 base::WeakPtr<ServiceWorkerContextClient> |
| 974 ServiceWorkerContextClient::GetWeakPtr() { | 1010 ServiceWorkerContextClient::GetWeakPtr() { |
| 975 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 1011 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
| 976 DCHECK(context_); | 1012 DCHECK(context_); |
| 977 return context_->weak_factory.GetWeakPtr(); | 1013 return context_->weak_factory.GetWeakPtr(); |
| 978 } | 1014 } |
| 979 | 1015 |
| 980 } // namespace content | 1016 } // namespace content |
| OLD | NEW |