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 23 matching lines...) Expand all Loading... |
34 #include "content/public/renderer/document_state.h" | 34 #include "content/public/renderer/document_state.h" |
35 #include "content/renderer/background_sync/background_sync_client_impl.h" | 35 #include "content/renderer/background_sync/background_sync_client_impl.h" |
36 #include "content/renderer/devtools/devtools_agent.h" | 36 #include "content/renderer/devtools/devtools_agent.h" |
37 #include "content/renderer/render_thread_impl.h" | 37 #include "content/renderer/render_thread_impl.h" |
38 #include "content/renderer/service_worker/embedded_worker_dispatcher.h" | 38 #include "content/renderer/service_worker/embedded_worker_dispatcher.h" |
39 #include "content/renderer/service_worker/service_worker_type_util.h" | 39 #include "content/renderer/service_worker/service_worker_type_util.h" |
40 #include "ipc/ipc_message.h" | 40 #include "ipc/ipc_message.h" |
41 #include "ipc/ipc_message_macros.h" | 41 #include "ipc/ipc_message_macros.h" |
42 #include "third_party/WebKit/public/platform/WebCrossOriginServiceWorkerClient.h
" | 42 #include "third_party/WebKit/public/platform/WebCrossOriginServiceWorkerClient.h
" |
43 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" | 43 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" |
| 44 #include "third_party/WebKit/public/platform/WebPassOwnPtr.h" |
44 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" | 45 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" |
45 #include "third_party/WebKit/public/platform/WebServiceWorkerClientQueryOptions.
h" | 46 #include "third_party/WebKit/public/platform/WebServiceWorkerClientQueryOptions.
h" |
46 #include "third_party/WebKit/public/platform/WebServiceWorkerRequest.h" | 47 #include "third_party/WebKit/public/platform/WebServiceWorkerRequest.h" |
47 #include "third_party/WebKit/public/platform/WebServiceWorkerResponse.h" | 48 #include "third_party/WebKit/public/platform/WebServiceWorkerResponse.h" |
48 #include "third_party/WebKit/public/platform/WebString.h" | 49 #include "third_party/WebKit/public/platform/WebString.h" |
49 #include "third_party/WebKit/public/platform/modules/background_sync/WebSyncRegi
stration.h" | 50 #include "third_party/WebKit/public/platform/modules/background_sync/WebSyncRegi
stration.h" |
50 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati
onData.h" | 51 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati
onData.h" |
51 #include "third_party/WebKit/public/web/WebDataSource.h" | 52 #include "third_party/WebKit/public/web/WebDataSource.h" |
52 #include "third_party/WebKit/public/web/WebServiceWorkerContextClient.h" | 53 #include "third_party/WebKit/public/web/WebServiceWorkerContextClient.h" |
53 #include "third_party/WebKit/public/web/WebServiceWorkerContextProxy.h" | 54 #include "third_party/WebKit/public/web/WebServiceWorkerContextProxy.h" |
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
786 void ServiceWorkerContextClient::OnDidGetClients( | 787 void ServiceWorkerContextClient::OnDidGetClients( |
787 int request_id, const std::vector<ServiceWorkerClientInfo>& clients) { | 788 int request_id, const std::vector<ServiceWorkerClientInfo>& clients) { |
788 TRACE_EVENT0("ServiceWorker", | 789 TRACE_EVENT0("ServiceWorker", |
789 "ServiceWorkerContextClient::OnDidGetClients"); | 790 "ServiceWorkerContextClient::OnDidGetClients"); |
790 blink::WebServiceWorkerClientsCallbacks* callbacks = | 791 blink::WebServiceWorkerClientsCallbacks* callbacks = |
791 context_->clients_callbacks.Lookup(request_id); | 792 context_->clients_callbacks.Lookup(request_id); |
792 if (!callbacks) { | 793 if (!callbacks) { |
793 NOTREACHED() << "Got stray response: " << request_id; | 794 NOTREACHED() << "Got stray response: " << request_id; |
794 return; | 795 return; |
795 } | 796 } |
796 scoped_ptr<blink::WebServiceWorkerClientsInfo> info( | 797 blink::WebServiceWorkerClientsInfo info; |
797 new blink::WebServiceWorkerClientsInfo); | |
798 blink::WebVector<blink::WebServiceWorkerClientInfo> convertedClients( | 798 blink::WebVector<blink::WebServiceWorkerClientInfo> convertedClients( |
799 clients.size()); | 799 clients.size()); |
800 for (size_t i = 0; i < clients.size(); ++i) | 800 for (size_t i = 0; i < clients.size(); ++i) |
801 convertedClients[i] = ToWebServiceWorkerClientInfo(clients[i]); | 801 convertedClients[i] = ToWebServiceWorkerClientInfo(clients[i]); |
802 info->clients.swap(convertedClients); | 802 info.clients.swap(convertedClients); |
803 callbacks->onSuccess(info.release()); | 803 callbacks->onSuccess(info); |
804 context_->clients_callbacks.Remove(request_id); | 804 context_->clients_callbacks.Remove(request_id); |
805 } | 805 } |
806 | 806 |
807 void ServiceWorkerContextClient::OnOpenWindowResponse( | 807 void ServiceWorkerContextClient::OnOpenWindowResponse( |
808 int request_id, | 808 int request_id, |
809 const ServiceWorkerClientInfo& client) { | 809 const ServiceWorkerClientInfo& client) { |
810 TRACE_EVENT0("ServiceWorker", | 810 TRACE_EVENT0("ServiceWorker", |
811 "ServiceWorkerContextClient::OnOpenWindowResponse"); | 811 "ServiceWorkerContextClient::OnOpenWindowResponse"); |
812 blink::WebServiceWorkerClientCallbacks* callbacks = | 812 blink::WebServiceWorkerClientCallbacks* callbacks = |
813 context_->client_callbacks.Lookup(request_id); | 813 context_->client_callbacks.Lookup(request_id); |
814 if (!callbacks) { | 814 if (!callbacks) { |
815 NOTREACHED() << "Got stray response: " << request_id; | 815 NOTREACHED() << "Got stray response: " << request_id; |
816 return; | 816 return; |
817 } | 817 } |
818 scoped_ptr<blink::WebServiceWorkerClientInfo> web_client; | 818 scoped_ptr<blink::WebServiceWorkerClientInfo> web_client; |
819 if (!client.IsEmpty()) { | 819 if (!client.IsEmpty()) { |
820 DCHECK(client.IsValid()); | 820 DCHECK(client.IsValid()); |
821 web_client.reset(new blink::WebServiceWorkerClientInfo( | 821 web_client.reset(new blink::WebServiceWorkerClientInfo( |
822 ToWebServiceWorkerClientInfo(client))); | 822 ToWebServiceWorkerClientInfo(client))); |
823 } | 823 } |
824 callbacks->onSuccess(web_client.release()); | 824 callbacks->onSuccess(adoptWebPtr(web_client.release())); |
825 context_->client_callbacks.Remove(request_id); | 825 context_->client_callbacks.Remove(request_id); |
826 } | 826 } |
827 | 827 |
828 void ServiceWorkerContextClient::OnOpenWindowError( | 828 void ServiceWorkerContextClient::OnOpenWindowError( |
829 int request_id, | 829 int request_id, |
830 const std::string& message) { | 830 const std::string& message) { |
831 TRACE_EVENT0("ServiceWorker", | 831 TRACE_EVENT0("ServiceWorker", |
832 "ServiceWorkerContextClient::OnOpenWindowError"); | 832 "ServiceWorkerContextClient::OnOpenWindowError"); |
833 blink::WebServiceWorkerClientCallbacks* callbacks = | 833 blink::WebServiceWorkerClientCallbacks* callbacks = |
834 context_->client_callbacks.Lookup(request_id); | 834 context_->client_callbacks.Lookup(request_id); |
835 if (!callbacks) { | 835 if (!callbacks) { |
836 NOTREACHED() << "Got stray response: " << request_id; | 836 NOTREACHED() << "Got stray response: " << request_id; |
837 return; | 837 return; |
838 } | 838 } |
839 scoped_ptr<blink::WebServiceWorkerError> error( | 839 callbacks->onError(blink::WebServiceWorkerError( |
840 new blink::WebServiceWorkerError( | 840 blink::WebServiceWorkerError::ErrorTypeUnknown, |
841 blink::WebServiceWorkerError::ErrorTypeUnknown, | 841 blink::WebString::fromUTF8(message))); |
842 blink::WebString::fromUTF8(message))); | |
843 callbacks->onError(error.release()); | |
844 context_->client_callbacks.Remove(request_id); | 842 context_->client_callbacks.Remove(request_id); |
845 } | 843 } |
846 | 844 |
847 void ServiceWorkerContextClient::OnFocusClientResponse( | 845 void ServiceWorkerContextClient::OnFocusClientResponse( |
848 int request_id, const ServiceWorkerClientInfo& client) { | 846 int request_id, const ServiceWorkerClientInfo& client) { |
849 TRACE_EVENT0("ServiceWorker", | 847 TRACE_EVENT0("ServiceWorker", |
850 "ServiceWorkerContextClient::OnFocusClientResponse"); | 848 "ServiceWorkerContextClient::OnFocusClientResponse"); |
851 blink::WebServiceWorkerClientCallbacks* callback = | 849 blink::WebServiceWorkerClientCallbacks* callback = |
852 context_->client_callbacks.Lookup(request_id); | 850 context_->client_callbacks.Lookup(request_id); |
853 if (!callback) { | 851 if (!callback) { |
854 NOTREACHED() << "Got stray response: " << request_id; | 852 NOTREACHED() << "Got stray response: " << request_id; |
855 return; | 853 return; |
856 } | 854 } |
857 if (!client.IsEmpty()) { | 855 if (!client.IsEmpty()) { |
858 DCHECK(client.IsValid()); | 856 DCHECK(client.IsValid()); |
859 scoped_ptr<blink::WebServiceWorkerClientInfo> web_client ( | 857 scoped_ptr<blink::WebServiceWorkerClientInfo> web_client ( |
860 new blink::WebServiceWorkerClientInfo( | 858 new blink::WebServiceWorkerClientInfo( |
861 ToWebServiceWorkerClientInfo(client))); | 859 ToWebServiceWorkerClientInfo(client))); |
862 callback->onSuccess(web_client.release()); | 860 callback->onSuccess(adoptWebPtr(web_client.release())); |
863 } else { | 861 } else { |
864 scoped_ptr<blink::WebServiceWorkerError> error( | 862 callback->onError(blink::WebServiceWorkerError( |
865 new blink::WebServiceWorkerError( | 863 blink::WebServiceWorkerError::ErrorTypeNotFound, |
866 blink::WebServiceWorkerError::ErrorTypeNotFound, | 864 "The WindowClient was not found.")); |
867 "The WindowClient was not found.")); | |
868 callback->onError(error.release()); | |
869 } | 865 } |
870 | 866 |
871 context_->client_callbacks.Remove(request_id); | 867 context_->client_callbacks.Remove(request_id); |
872 } | 868 } |
873 | 869 |
874 void ServiceWorkerContextClient::OnNavigateClientResponse( | 870 void ServiceWorkerContextClient::OnNavigateClientResponse( |
875 int request_id, | 871 int request_id, |
876 const ServiceWorkerClientInfo& client) { | 872 const ServiceWorkerClientInfo& client) { |
877 TRACE_EVENT0("ServiceWorker", | 873 TRACE_EVENT0("ServiceWorker", |
878 "ServiceWorkerContextClient::OnNavigateClientResponse"); | 874 "ServiceWorkerContextClient::OnNavigateClientResponse"); |
879 blink::WebServiceWorkerClientCallbacks* callbacks = | 875 blink::WebServiceWorkerClientCallbacks* callbacks = |
880 context_->client_callbacks.Lookup(request_id); | 876 context_->client_callbacks.Lookup(request_id); |
881 if (!callbacks) { | 877 if (!callbacks) { |
882 NOTREACHED() << "Got stray response: " << request_id; | 878 NOTREACHED() << "Got stray response: " << request_id; |
883 return; | 879 return; |
884 } | 880 } |
885 scoped_ptr<blink::WebServiceWorkerClientInfo> web_client; | 881 scoped_ptr<blink::WebServiceWorkerClientInfo> web_client; |
886 if (!client.IsEmpty()) { | 882 if (!client.IsEmpty()) { |
887 DCHECK(client.IsValid()); | 883 DCHECK(client.IsValid()); |
888 web_client.reset(new blink::WebServiceWorkerClientInfo( | 884 web_client.reset(new blink::WebServiceWorkerClientInfo( |
889 ToWebServiceWorkerClientInfo(client))); | 885 ToWebServiceWorkerClientInfo(client))); |
890 } | 886 } |
891 callbacks->onSuccess(web_client.release()); | 887 callbacks->onSuccess(adoptWebPtr(web_client.release())); |
892 context_->client_callbacks.Remove(request_id); | 888 context_->client_callbacks.Remove(request_id); |
893 } | 889 } |
894 | 890 |
895 void ServiceWorkerContextClient::OnNavigateClientError(int request_id, | 891 void ServiceWorkerContextClient::OnNavigateClientError(int request_id, |
896 const GURL& url) { | 892 const GURL& url) { |
897 TRACE_EVENT0("ServiceWorker", | 893 TRACE_EVENT0("ServiceWorker", |
898 "ServiceWorkerContextClient::OnNavigateClientError"); | 894 "ServiceWorkerContextClient::OnNavigateClientError"); |
899 blink::WebServiceWorkerClientCallbacks* callbacks = | 895 blink::WebServiceWorkerClientCallbacks* callbacks = |
900 context_->client_callbacks.Lookup(request_id); | 896 context_->client_callbacks.Lookup(request_id); |
901 if (!callbacks) { | 897 if (!callbacks) { |
902 NOTREACHED() << "Got stray response: " << request_id; | 898 NOTREACHED() << "Got stray response: " << request_id; |
903 return; | 899 return; |
904 } | 900 } |
905 std::string message = "Cannot navigate to URL: " + url.spec(); | 901 std::string message = "Cannot navigate to URL: " + url.spec(); |
906 scoped_ptr<blink::WebServiceWorkerError> error( | 902 callbacks->onError(blink::WebServiceWorkerError( |
907 new blink::WebServiceWorkerError( | 903 blink::WebServiceWorkerError::ErrorTypeUnknown, |
908 blink::WebServiceWorkerError::ErrorTypeUnknown, | 904 blink::WebString::fromUTF8(message))); |
909 blink::WebString::fromUTF8(message))); | |
910 callbacks->onError(error.release()); | |
911 context_->client_callbacks.Remove(request_id); | 905 context_->client_callbacks.Remove(request_id); |
912 } | 906 } |
913 | 907 |
914 void ServiceWorkerContextClient::OnDidSkipWaiting(int request_id) { | 908 void ServiceWorkerContextClient::OnDidSkipWaiting(int request_id) { |
915 TRACE_EVENT0("ServiceWorker", | 909 TRACE_EVENT0("ServiceWorker", |
916 "ServiceWorkerContextClient::OnDidSkipWaiting"); | 910 "ServiceWorkerContextClient::OnDidSkipWaiting"); |
917 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks = | 911 blink::WebServiceWorkerSkipWaitingCallbacks* callbacks = |
918 context_->skip_waiting_callbacks.Lookup(request_id); | 912 context_->skip_waiting_callbacks.Lookup(request_id); |
919 if (!callbacks) { | 913 if (!callbacks) { |
920 NOTREACHED() << "Got stray response: " << request_id; | 914 NOTREACHED() << "Got stray response: " << request_id; |
(...skipping 21 matching lines...) Expand all Loading... |
942 blink::WebServiceWorkerError::ErrorType error_type, | 936 blink::WebServiceWorkerError::ErrorType error_type, |
943 const base::string16& message) { | 937 const base::string16& message) { |
944 TRACE_EVENT0("ServiceWorker", | 938 TRACE_EVENT0("ServiceWorker", |
945 "ServiceWorkerContextClient::OnClaimClientsError"); | 939 "ServiceWorkerContextClient::OnClaimClientsError"); |
946 blink::WebServiceWorkerClientsClaimCallbacks* callbacks = | 940 blink::WebServiceWorkerClientsClaimCallbacks* callbacks = |
947 context_->claim_clients_callbacks.Lookup(request_id); | 941 context_->claim_clients_callbacks.Lookup(request_id); |
948 if (!callbacks) { | 942 if (!callbacks) { |
949 NOTREACHED() << "Got stray response: " << request_id; | 943 NOTREACHED() << "Got stray response: " << request_id; |
950 return; | 944 return; |
951 } | 945 } |
952 scoped_ptr<blink::WebServiceWorkerError> error( | 946 callbacks->onError(blink::WebServiceWorkerError(error_type, message)); |
953 new blink::WebServiceWorkerError(error_type, message)); | |
954 callbacks->onError(error.release()); | |
955 context_->claim_clients_callbacks.Remove(request_id); | 947 context_->claim_clients_callbacks.Remove(request_id); |
956 } | 948 } |
957 | 949 |
958 void ServiceWorkerContextClient::OnPing() { | 950 void ServiceWorkerContextClient::OnPing() { |
959 Send(new ServiceWorkerHostMsg_Pong(GetRoutingID())); | 951 Send(new ServiceWorkerHostMsg_Pong(GetRoutingID())); |
960 } | 952 } |
961 | 953 |
962 base::WeakPtr<ServiceWorkerContextClient> | 954 base::WeakPtr<ServiceWorkerContextClient> |
963 ServiceWorkerContextClient::GetWeakPtr() { | 955 ServiceWorkerContextClient::GetWeakPtr() { |
964 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 956 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
965 DCHECK(context_); | 957 DCHECK(context_); |
966 return context_->weak_factory.GetWeakPtr(); | 958 return context_->weak_factory.GetWeakPtr(); |
967 } | 959 } |
968 | 960 |
969 } // namespace content | 961 } // namespace content |
OLD | NEW |