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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
568 | 572 |
569 void ServiceWorkerContextClient::focus( | 573 void ServiceWorkerContextClient::focus( |
570 const blink::WebString& uuid, | 574 const blink::WebString& uuid, |
571 blink::WebServiceWorkerClientCallbacks* callback) { | 575 blink::WebServiceWorkerClientCallbacks* callback) { |
572 DCHECK(callback); | 576 DCHECK(callback); |
573 int request_id = context_->client_callbacks.Add(callback); | 577 int request_id = context_->client_callbacks.Add(callback); |
574 Send(new ServiceWorkerHostMsg_FocusClient(GetRoutingID(), request_id, | 578 Send(new ServiceWorkerHostMsg_FocusClient(GetRoutingID(), request_id, |
575 base::UTF16ToUTF8(uuid))); | 579 base::UTF16ToUTF8(uuid))); |
576 } | 580 } |
577 | 581 |
582 void ServiceWorkerContextClient::navigate( | |
583 const blink::WebString& uuid, | |
584 const blink::WebURL& url, | |
585 blink::WebServiceWorkerClientCallbacks* callback) { | |
586 DCHECK(callback); | |
587 int request_id = context_->client_callbacks.Add(callback); | |
588 Send(new ServiceWorkerHostMsg_NavigateClient(GetRoutingID(), request_id, | |
589 base::UTF16ToUTF8(uuid), url)); | |
590 } | |
591 | |
578 void ServiceWorkerContextClient::skipWaiting( | 592 void ServiceWorkerContextClient::skipWaiting( |
579 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks) { | 593 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks) { |
580 DCHECK(callbacks); | 594 DCHECK(callbacks); |
581 int request_id = context_->skip_waiting_callbacks.Add(callbacks); | 595 int request_id = context_->skip_waiting_callbacks.Add(callbacks); |
582 Send(new ServiceWorkerHostMsg_SkipWaiting(GetRoutingID(), request_id)); | 596 Send(new ServiceWorkerHostMsg_SkipWaiting(GetRoutingID(), request_id)); |
583 } | 597 } |
584 | 598 |
585 void ServiceWorkerContextClient::claim( | 599 void ServiceWorkerContextClient::claim( |
586 blink::WebServiceWorkerClientsClaimCallbacks* callbacks) { | 600 blink::WebServiceWorkerClientsClaimCallbacks* callbacks) { |
587 DCHECK(callbacks); | 601 DCHECK(callbacks); |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
872 scoped_ptr<blink::WebServiceWorkerError> error( | 886 scoped_ptr<blink::WebServiceWorkerError> error( |
873 new blink::WebServiceWorkerError( | 887 new blink::WebServiceWorkerError( |
874 blink::WebServiceWorkerError::ErrorTypeNotFound, | 888 blink::WebServiceWorkerError::ErrorTypeNotFound, |
875 "The WindowClient was not found.")); | 889 "The WindowClient was not found.")); |
876 callback->onError(error.release()); | 890 callback->onError(error.release()); |
877 } | 891 } |
878 | 892 |
879 context_->client_callbacks.Remove(request_id); | 893 context_->client_callbacks.Remove(request_id); |
880 } | 894 } |
881 | 895 |
896 void ServiceWorkerContextClient::OnNavigateClientResponse( | |
897 int request_id, | |
898 const ServiceWorkerClientInfo& client) { | |
899 TRACE_EVENT0("ServiceWorker", | |
900 "ServiceWorkerContextClient::OnNavigateClientResponse"); | |
901 blink::WebServiceWorkerClientCallbacks* callbacks = | |
902 context_->client_callbacks.Lookup(request_id); | |
903 if (!callbacks) { | |
904 NOTREACHED() << "Got stray response: " << request_id; | |
905 return; | |
906 } | |
907 scoped_ptr<blink::WebServiceWorkerClientInfo> web_client; | |
908 if (!client.IsEmpty()) { | |
909 DCHECK(client.IsValid()); | |
910 web_client.reset(new blink::WebServiceWorkerClientInfo( | |
911 ToWebServiceWorkerClientInfo(client))); | |
912 } | |
913 callbacks->onSuccess(web_client.release()); | |
914 context_->client_callbacks.Remove(request_id); | |
915 } | |
916 | |
917 void ServiceWorkerContextClient::OnNavigateClientError( | |
918 int request_id, | |
919 const std::string& message) { | |
palmer
2015/07/15 17:07:54
What is the possible range of values for |message|
zino
2015/07/17 11:26:11
It's just error message.
It uses the same way with
palmer
2015/07/20 23:15:32
How about passing a reason code (an enum) and the
zino
2015/07/23 05:56:17
Done. (without using enum, because the message isn
| |
920 TRACE_EVENT0("ServiceWorker", | |
921 "ServiceWorkerContextClient::OnNavigateClientError"); | |
922 blink::WebServiceWorkerClientCallbacks* callbacks = | |
923 context_->client_callbacks.Lookup(request_id); | |
924 if (!callbacks) { | |
925 NOTREACHED() << "Got stray response: " << request_id; | |
926 return; | |
927 } | |
928 scoped_ptr<blink::WebServiceWorkerError> error( | |
929 new blink::WebServiceWorkerError( | |
930 blink::WebServiceWorkerError::ErrorTypeUnknown, | |
931 blink::WebString::fromUTF8(message))); | |
932 callbacks->onError(error.release()); | |
933 context_->client_callbacks.Remove(request_id); | |
934 } | |
935 | |
882 void ServiceWorkerContextClient::OnDidSkipWaiting(int request_id) { | 936 void ServiceWorkerContextClient::OnDidSkipWaiting(int request_id) { |
883 TRACE_EVENT0("ServiceWorker", | 937 TRACE_EVENT0("ServiceWorker", |
884 "ServiceWorkerContextClient::OnDidSkipWaiting"); | 938 "ServiceWorkerContextClient::OnDidSkipWaiting"); |
885 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks = | 939 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks = |
886 context_->skip_waiting_callbacks.Lookup(request_id); | 940 context_->skip_waiting_callbacks.Lookup(request_id); |
887 if (!callbacks) { | 941 if (!callbacks) { |
888 NOTREACHED() << "Got stray response: " << request_id; | 942 NOTREACHED() << "Got stray response: " << request_id; |
889 return; | 943 return; |
890 } | 944 } |
891 callbacks->onSuccess(); | 945 callbacks->onSuccess(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
928 } | 982 } |
929 | 983 |
930 base::WeakPtr<ServiceWorkerContextClient> | 984 base::WeakPtr<ServiceWorkerContextClient> |
931 ServiceWorkerContextClient::GetWeakPtr() { | 985 ServiceWorkerContextClient::GetWeakPtr() { |
932 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 986 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
933 DCHECK(context_); | 987 DCHECK(context_); |
934 return context_->weak_factory.GetWeakPtr(); | 988 return context_->weak_factory.GetWeakPtr(); |
935 } | 989 } |
936 | 990 |
937 } // namespace content | 991 } // namespace content |
OLD | NEW |