| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent) | 259 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent) |
| 260 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NotificationClickEvent, | 260 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NotificationClickEvent, |
| 261 OnNotificationClickEvent) | 261 OnNotificationClickEvent) |
| 262 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NotificationCloseEvent, | 262 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NotificationCloseEvent, |
| 263 OnNotificationCloseEvent) | 263 OnNotificationCloseEvent) |
| 264 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_PushEvent, OnPushEvent) | 264 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_PushEvent, OnPushEvent) |
| 265 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_GeofencingEvent, OnGeofencingEvent) | 265 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_GeofencingEvent, OnGeofencingEvent) |
| 266 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToWorker, OnPostMessage) | 266 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToWorker, OnPostMessage) |
| 267 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginMessageToWorker, | 267 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CrossOriginMessageToWorker, |
| 268 OnCrossOriginMessageToWorker) | 268 OnCrossOriginMessageToWorker) |
| 269 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClient, OnDidGetClient) |
| 269 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClients, OnDidGetClients) | 270 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClients, OnDidGetClients) |
| 270 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse, | 271 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse, |
| 271 OnOpenWindowResponse) | 272 OnOpenWindowResponse) |
| 272 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowError, | 273 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowError, |
| 273 OnOpenWindowError) | 274 OnOpenWindowError) |
| 274 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse, | 275 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse, |
| 275 OnFocusClientResponse) | 276 OnFocusClientResponse) |
| 276 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NavigateClientResponse, | 277 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NavigateClientResponse, |
| 277 OnNavigateClientResponse) | 278 OnNavigateClientResponse) |
| 278 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NavigateClientError, | 279 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NavigateClientError, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 291 mojo::shell::mojom::InterfaceProviderPtr exposed_services) { | 292 mojo::shell::mojom::InterfaceProviderPtr exposed_services) { |
| 292 context_->service_registry.Bind(std::move(services)); | 293 context_->service_registry.Bind(std::move(services)); |
| 293 context_->service_registry.BindRemoteServiceProvider( | 294 context_->service_registry.BindRemoteServiceProvider( |
| 294 std::move(exposed_services)); | 295 std::move(exposed_services)); |
| 295 } | 296 } |
| 296 | 297 |
| 297 blink::WebURL ServiceWorkerContextClient::scope() const { | 298 blink::WebURL ServiceWorkerContextClient::scope() const { |
| 298 return service_worker_scope_; | 299 return service_worker_scope_; |
| 299 } | 300 } |
| 300 | 301 |
| 302 void ServiceWorkerContextClient::getClient( |
| 303 const blink::WebString& id, |
| 304 blink::WebServiceWorkerClientCallbacks* callbacks) { |
| 305 DCHECK(callbacks); |
| 306 int request_id = context_->client_callbacks.Add(callbacks); |
| 307 Send(new ServiceWorkerHostMsg_GetClient( |
| 308 GetRoutingID(), request_id, base::UTF16ToUTF8(base::StringPiece16(id)))); |
| 309 } |
| 310 |
| 301 void ServiceWorkerContextClient::getClients( | 311 void ServiceWorkerContextClient::getClients( |
| 302 const blink::WebServiceWorkerClientQueryOptions& weboptions, | 312 const blink::WebServiceWorkerClientQueryOptions& weboptions, |
| 303 blink::WebServiceWorkerClientsCallbacks* callbacks) { | 313 blink::WebServiceWorkerClientsCallbacks* callbacks) { |
| 304 DCHECK(callbacks); | 314 DCHECK(callbacks); |
| 305 int request_id = context_->clients_callbacks.Add(callbacks); | 315 int request_id = context_->clients_callbacks.Add(callbacks); |
| 306 ServiceWorkerClientQueryOptions options; | 316 ServiceWorkerClientQueryOptions options; |
| 307 options.client_type = weboptions.clientType; | 317 options.client_type = weboptions.clientType; |
| 308 options.include_uncontrolled = weboptions.includeUncontrolled; | 318 options.include_uncontrolled = weboptions.includeUncontrolled; |
| 309 Send(new ServiceWorkerHostMsg_GetClients( | 319 Send(new ServiceWorkerHostMsg_GetClients( |
| 310 GetRoutingID(), request_id, options)); | 320 GetRoutingID(), request_id, options)); |
| (...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 sent_message_ports, new_routing_ids, | 875 sent_message_ports, new_routing_ids, |
| 866 main_thread_task_runner_); | 876 main_thread_task_runner_); |
| 867 | 877 |
| 868 blink::WebCrossOriginServiceWorkerClient web_client; | 878 blink::WebCrossOriginServiceWorkerClient web_client; |
| 869 web_client.origin = client.origin; | 879 web_client.origin = client.origin; |
| 870 web_client.targetURL = client.target_url; | 880 web_client.targetURL = client.target_url; |
| 871 web_client.clientID = client.message_port_id; | 881 web_client.clientID = client.message_port_id; |
| 872 proxy_->dispatchCrossOriginMessageEvent(web_client, message, ports); | 882 proxy_->dispatchCrossOriginMessageEvent(web_client, message, ports); |
| 873 } | 883 } |
| 874 | 884 |
| 885 void ServiceWorkerContextClient::OnDidGetClient( |
| 886 int request_id, |
| 887 const ServiceWorkerClientInfo& client) { |
| 888 TRACE_EVENT0("ServiceWorker", "ServiceWorkerContextClient::OnDidGetClient"); |
| 889 blink::WebServiceWorkerClientCallbacks* callbacks = |
| 890 context_->client_callbacks.Lookup(request_id); |
| 891 if (!callbacks) { |
| 892 NOTREACHED() << "Got stray response: " << request_id; |
| 893 return; |
| 894 } |
| 895 scoped_ptr<blink::WebServiceWorkerClientInfo> web_client; |
| 896 if (!client.IsEmpty()) { |
| 897 DCHECK(client.IsValid()); |
| 898 web_client.reset(new blink::WebServiceWorkerClientInfo( |
| 899 ToWebServiceWorkerClientInfo(client))); |
| 900 } |
| 901 callbacks->onSuccess(blink::adoptWebPtr(web_client.release())); |
| 902 context_->client_callbacks.Remove(request_id); |
| 903 } |
| 904 |
| 875 void ServiceWorkerContextClient::OnDidGetClients( | 905 void ServiceWorkerContextClient::OnDidGetClients( |
| 876 int request_id, const std::vector<ServiceWorkerClientInfo>& clients) { | 906 int request_id, const std::vector<ServiceWorkerClientInfo>& clients) { |
| 877 TRACE_EVENT0("ServiceWorker", | 907 TRACE_EVENT0("ServiceWorker", |
| 878 "ServiceWorkerContextClient::OnDidGetClients"); | 908 "ServiceWorkerContextClient::OnDidGetClients"); |
| 879 blink::WebServiceWorkerClientsCallbacks* callbacks = | 909 blink::WebServiceWorkerClientsCallbacks* callbacks = |
| 880 context_->clients_callbacks.Lookup(request_id); | 910 context_->clients_callbacks.Lookup(request_id); |
| 881 if (!callbacks) { | 911 if (!callbacks) { |
| 882 NOTREACHED() << "Got stray response: " << request_id; | 912 NOTREACHED() << "Got stray response: " << request_id; |
| 883 return; | 913 return; |
| 884 } | 914 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 902 if (!callbacks) { | 932 if (!callbacks) { |
| 903 NOTREACHED() << "Got stray response: " << request_id; | 933 NOTREACHED() << "Got stray response: " << request_id; |
| 904 return; | 934 return; |
| 905 } | 935 } |
| 906 scoped_ptr<blink::WebServiceWorkerClientInfo> web_client; | 936 scoped_ptr<blink::WebServiceWorkerClientInfo> web_client; |
| 907 if (!client.IsEmpty()) { | 937 if (!client.IsEmpty()) { |
| 908 DCHECK(client.IsValid()); | 938 DCHECK(client.IsValid()); |
| 909 web_client.reset(new blink::WebServiceWorkerClientInfo( | 939 web_client.reset(new blink::WebServiceWorkerClientInfo( |
| 910 ToWebServiceWorkerClientInfo(client))); | 940 ToWebServiceWorkerClientInfo(client))); |
| 911 } | 941 } |
| 912 callbacks->onSuccess(adoptWebPtr(web_client.release())); | 942 callbacks->onSuccess(blink::adoptWebPtr(web_client.release())); |
| 913 context_->client_callbacks.Remove(request_id); | 943 context_->client_callbacks.Remove(request_id); |
| 914 } | 944 } |
| 915 | 945 |
| 916 void ServiceWorkerContextClient::OnOpenWindowError( | 946 void ServiceWorkerContextClient::OnOpenWindowError( |
| 917 int request_id, | 947 int request_id, |
| 918 const std::string& message) { | 948 const std::string& message) { |
| 919 TRACE_EVENT0("ServiceWorker", | 949 TRACE_EVENT0("ServiceWorker", |
| 920 "ServiceWorkerContextClient::OnOpenWindowError"); | 950 "ServiceWorkerContextClient::OnOpenWindowError"); |
| 921 blink::WebServiceWorkerClientCallbacks* callbacks = | 951 blink::WebServiceWorkerClientCallbacks* callbacks = |
| 922 context_->client_callbacks.Lookup(request_id); | 952 context_->client_callbacks.Lookup(request_id); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 938 context_->client_callbacks.Lookup(request_id); | 968 context_->client_callbacks.Lookup(request_id); |
| 939 if (!callback) { | 969 if (!callback) { |
| 940 NOTREACHED() << "Got stray response: " << request_id; | 970 NOTREACHED() << "Got stray response: " << request_id; |
| 941 return; | 971 return; |
| 942 } | 972 } |
| 943 if (!client.IsEmpty()) { | 973 if (!client.IsEmpty()) { |
| 944 DCHECK(client.IsValid()); | 974 DCHECK(client.IsValid()); |
| 945 scoped_ptr<blink::WebServiceWorkerClientInfo> web_client ( | 975 scoped_ptr<blink::WebServiceWorkerClientInfo> web_client ( |
| 946 new blink::WebServiceWorkerClientInfo( | 976 new blink::WebServiceWorkerClientInfo( |
| 947 ToWebServiceWorkerClientInfo(client))); | 977 ToWebServiceWorkerClientInfo(client))); |
| 948 callback->onSuccess(adoptWebPtr(web_client.release())); | 978 callback->onSuccess(blink::adoptWebPtr(web_client.release())); |
| 949 } else { | 979 } else { |
| 950 callback->onError(blink::WebServiceWorkerError( | 980 callback->onError(blink::WebServiceWorkerError( |
| 951 blink::WebServiceWorkerError::ErrorTypeNotFound, | 981 blink::WebServiceWorkerError::ErrorTypeNotFound, |
| 952 "The WindowClient was not found.")); | 982 "The WindowClient was not found.")); |
| 953 } | 983 } |
| 954 | 984 |
| 955 context_->client_callbacks.Remove(request_id); | 985 context_->client_callbacks.Remove(request_id); |
| 956 } | 986 } |
| 957 | 987 |
| 958 void ServiceWorkerContextClient::OnNavigateClientResponse( | 988 void ServiceWorkerContextClient::OnNavigateClientResponse( |
| 959 int request_id, | 989 int request_id, |
| 960 const ServiceWorkerClientInfo& client) { | 990 const ServiceWorkerClientInfo& client) { |
| 961 TRACE_EVENT0("ServiceWorker", | 991 TRACE_EVENT0("ServiceWorker", |
| 962 "ServiceWorkerContextClient::OnNavigateClientResponse"); | 992 "ServiceWorkerContextClient::OnNavigateClientResponse"); |
| 963 blink::WebServiceWorkerClientCallbacks* callbacks = | 993 blink::WebServiceWorkerClientCallbacks* callbacks = |
| 964 context_->client_callbacks.Lookup(request_id); | 994 context_->client_callbacks.Lookup(request_id); |
| 965 if (!callbacks) { | 995 if (!callbacks) { |
| 966 NOTREACHED() << "Got stray response: " << request_id; | 996 NOTREACHED() << "Got stray response: " << request_id; |
| 967 return; | 997 return; |
| 968 } | 998 } |
| 969 scoped_ptr<blink::WebServiceWorkerClientInfo> web_client; | 999 scoped_ptr<blink::WebServiceWorkerClientInfo> web_client; |
| 970 if (!client.IsEmpty()) { | 1000 if (!client.IsEmpty()) { |
| 971 DCHECK(client.IsValid()); | 1001 DCHECK(client.IsValid()); |
| 972 web_client.reset(new blink::WebServiceWorkerClientInfo( | 1002 web_client.reset(new blink::WebServiceWorkerClientInfo( |
| 973 ToWebServiceWorkerClientInfo(client))); | 1003 ToWebServiceWorkerClientInfo(client))); |
| 974 } | 1004 } |
| 975 callbacks->onSuccess(adoptWebPtr(web_client.release())); | 1005 callbacks->onSuccess(blink::adoptWebPtr(web_client.release())); |
| 976 context_->client_callbacks.Remove(request_id); | 1006 context_->client_callbacks.Remove(request_id); |
| 977 } | 1007 } |
| 978 | 1008 |
| 979 void ServiceWorkerContextClient::OnNavigateClientError(int request_id, | 1009 void ServiceWorkerContextClient::OnNavigateClientError(int request_id, |
| 980 const GURL& url) { | 1010 const GURL& url) { |
| 981 TRACE_EVENT0("ServiceWorker", | 1011 TRACE_EVENT0("ServiceWorker", |
| 982 "ServiceWorkerContextClient::OnNavigateClientError"); | 1012 "ServiceWorkerContextClient::OnNavigateClientError"); |
| 983 blink::WebServiceWorkerClientCallbacks* callbacks = | 1013 blink::WebServiceWorkerClientCallbacks* callbacks = |
| 984 context_->client_callbacks.Lookup(request_id); | 1014 context_->client_callbacks.Lookup(request_id); |
| 985 if (!callbacks) { | 1015 if (!callbacks) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1040 } | 1070 } |
| 1041 | 1071 |
| 1042 base::WeakPtr<ServiceWorkerContextClient> | 1072 base::WeakPtr<ServiceWorkerContextClient> |
| 1043 ServiceWorkerContextClient::GetWeakPtr() { | 1073 ServiceWorkerContextClient::GetWeakPtr() { |
| 1044 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 1074 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
| 1045 DCHECK(context_); | 1075 DCHECK(context_); |
| 1046 return context_->weak_factory.GetWeakPtr(); | 1076 return context_->weak_factory.GetWeakPtr(); |
| 1047 } | 1077 } |
| 1048 | 1078 |
| 1049 } // namespace content | 1079 } // namespace content |
| OLD | NEW |