| 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 <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 RequestContextFrameType frame_type) { | 148 RequestContextFrameType frame_type) { |
| 149 return static_cast<blink::WebURLRequest::FrameType>(frame_type); | 149 return static_cast<blink::WebURLRequest::FrameType>(frame_type); |
| 150 } | 150 } |
| 151 | 151 |
| 152 blink::WebServiceWorkerClientInfo | 152 blink::WebServiceWorkerClientInfo |
| 153 ToWebServiceWorkerClientInfo(const ServiceWorkerClientInfo& client_info) { | 153 ToWebServiceWorkerClientInfo(const ServiceWorkerClientInfo& client_info) { |
| 154 DCHECK(client_info.IsValid()); | 154 DCHECK(client_info.IsValid()); |
| 155 | 155 |
| 156 blink::WebServiceWorkerClientInfo web_client_info; | 156 blink::WebServiceWorkerClientInfo web_client_info; |
| 157 | 157 |
| 158 web_client_info.uuid = base::UTF8ToUTF16(client_info.client_uuid); | 158 web_client_info.uuid = blink::WebString::fromUTF8(client_info.client_uuid); |
| 159 web_client_info.pageVisibilityState = client_info.page_visibility_state; | 159 web_client_info.pageVisibilityState = client_info.page_visibility_state; |
| 160 web_client_info.isFocused = client_info.is_focused; | 160 web_client_info.isFocused = client_info.is_focused; |
| 161 web_client_info.url = client_info.url; | 161 web_client_info.url = client_info.url; |
| 162 web_client_info.frameType = GetBlinkFrameType(client_info.frame_type); | 162 web_client_info.frameType = GetBlinkFrameType(client_info.frame_type); |
| 163 web_client_info.clientType = client_info.client_type; | 163 web_client_info.clientType = client_info.client_type; |
| 164 | 164 |
| 165 return web_client_info; | 165 return web_client_info; |
| 166 } | 166 } |
| 167 | 167 |
| 168 } // namespace | 168 } // namespace |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 | 427 |
| 428 blink::WebURL ServiceWorkerContextClient::scope() const { | 428 blink::WebURL ServiceWorkerContextClient::scope() const { |
| 429 return service_worker_scope_; | 429 return service_worker_scope_; |
| 430 } | 430 } |
| 431 | 431 |
| 432 void ServiceWorkerContextClient::getClient( | 432 void ServiceWorkerContextClient::getClient( |
| 433 const blink::WebString& id, | 433 const blink::WebString& id, |
| 434 std::unique_ptr<blink::WebServiceWorkerClientCallbacks> callbacks) { | 434 std::unique_ptr<blink::WebServiceWorkerClientCallbacks> callbacks) { |
| 435 DCHECK(callbacks); | 435 DCHECK(callbacks); |
| 436 int request_id = context_->client_callbacks.Add(std::move(callbacks)); | 436 int request_id = context_->client_callbacks.Add(std::move(callbacks)); |
| 437 Send(new ServiceWorkerHostMsg_GetClient( | 437 Send(new ServiceWorkerHostMsg_GetClient(GetRoutingID(), request_id, |
| 438 GetRoutingID(), request_id, base::UTF16ToUTF8(base::StringPiece16(id)))); | 438 id.utf8())); |
| 439 } | 439 } |
| 440 | 440 |
| 441 void ServiceWorkerContextClient::getClients( | 441 void ServiceWorkerContextClient::getClients( |
| 442 const blink::WebServiceWorkerClientQueryOptions& weboptions, | 442 const blink::WebServiceWorkerClientQueryOptions& weboptions, |
| 443 std::unique_ptr<blink::WebServiceWorkerClientsCallbacks> callbacks) { | 443 std::unique_ptr<blink::WebServiceWorkerClientsCallbacks> callbacks) { |
| 444 DCHECK(callbacks); | 444 DCHECK(callbacks); |
| 445 int request_id = context_->clients_callbacks.Add(std::move(callbacks)); | 445 int request_id = context_->clients_callbacks.Add(std::move(callbacks)); |
| 446 ServiceWorkerClientQueryOptions options; | 446 ServiceWorkerClientQueryOptions options; |
| 447 options.client_type = weboptions.clientType; | 447 options.client_type = weboptions.clientType; |
| 448 options.include_uncontrolled = weboptions.includeUncontrolled; | 448 options.include_uncontrolled = weboptions.includeUncontrolled; |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 base::Bind(&CallWorkerContextDestroyedOnMainThread, | 610 base::Bind(&CallWorkerContextDestroyedOnMainThread, |
| 611 embedded_worker_id_)); | 611 embedded_worker_id_)); |
| 612 } | 612 } |
| 613 | 613 |
| 614 void ServiceWorkerContextClient::reportException( | 614 void ServiceWorkerContextClient::reportException( |
| 615 const blink::WebString& error_message, | 615 const blink::WebString& error_message, |
| 616 int line_number, | 616 int line_number, |
| 617 int column_number, | 617 int column_number, |
| 618 const blink::WebString& source_url) { | 618 const blink::WebString& source_url) { |
| 619 Send(new EmbeddedWorkerHostMsg_ReportException( | 619 Send(new EmbeddedWorkerHostMsg_ReportException( |
| 620 embedded_worker_id_, error_message, line_number, column_number, | 620 embedded_worker_id_, error_message.utf16(), line_number, column_number, |
| 621 blink::WebStringToGURL(source_url))); | 621 blink::WebStringToGURL(source_url))); |
| 622 } | 622 } |
| 623 | 623 |
| 624 void ServiceWorkerContextClient::reportConsoleMessage( | 624 void ServiceWorkerContextClient::reportConsoleMessage( |
| 625 int source, | 625 int source, |
| 626 int level, | 626 int level, |
| 627 const blink::WebString& message, | 627 const blink::WebString& message, |
| 628 int line_number, | 628 int line_number, |
| 629 const blink::WebString& source_url) { | 629 const blink::WebString& source_url) { |
| 630 EmbeddedWorkerHostMsg_ReportConsoleMessage_Params params; | 630 EmbeddedWorkerHostMsg_ReportConsoleMessage_Params params; |
| 631 params.source_identifier = source; | 631 params.source_identifier = source; |
| 632 params.message_level = level; | 632 params.message_level = level; |
| 633 params.message = message; | 633 params.message = message.utf16(); |
| 634 params.line_number = line_number; | 634 params.line_number = line_number; |
| 635 params.source_url = blink::WebStringToGURL(source_url); | 635 params.source_url = blink::WebStringToGURL(source_url); |
| 636 | 636 |
| 637 Send(new EmbeddedWorkerHostMsg_ReportConsoleMessage( | 637 Send(new EmbeddedWorkerHostMsg_ReportConsoleMessage( |
| 638 embedded_worker_id_, params)); | 638 embedded_worker_id_, params)); |
| 639 } | 639 } |
| 640 | 640 |
| 641 void ServiceWorkerContextClient::sendDevToolsMessage( | 641 void ServiceWorkerContextClient::sendDevToolsMessage( |
| 642 int session_id, | 642 int session_id, |
| 643 int call_id, | 643 int call_id, |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 void ServiceWorkerContextClient::postMessageToClient( | 820 void ServiceWorkerContextClient::postMessageToClient( |
| 821 const blink::WebString& uuid, | 821 const blink::WebString& uuid, |
| 822 const blink::WebString& message, | 822 const blink::WebString& message, |
| 823 blink::WebMessagePortChannelArray* channels) { | 823 blink::WebMessagePortChannelArray* channels) { |
| 824 // This may send channels for MessagePorts, and all internal book-keeping | 824 // This may send channels for MessagePorts, and all internal book-keeping |
| 825 // messages for MessagePort (e.g. QueueMessages) are sent from main thread | 825 // messages for MessagePort (e.g. QueueMessages) are sent from main thread |
| 826 // (with thread hopping), so we need to do the same thread hopping here not | 826 // (with thread hopping), so we need to do the same thread hopping here not |
| 827 // to overtake those messages. | 827 // to overtake those messages. |
| 828 std::unique_ptr<blink::WebMessagePortChannelArray> channel_array(channels); | 828 std::unique_ptr<blink::WebMessagePortChannelArray> channel_array(channels); |
| 829 main_thread_task_runner_->PostTask( | 829 main_thread_task_runner_->PostTask( |
| 830 FROM_HERE, base::Bind(&SendPostMessageToClientOnMainThread, | 830 FROM_HERE, |
| 831 base::RetainedRef(sender_), GetRoutingID(), | 831 base::Bind(&SendPostMessageToClientOnMainThread, |
| 832 base::UTF16ToUTF8(base::StringPiece16(uuid)), | 832 base::RetainedRef(sender_), GetRoutingID(), uuid.utf8(), |
| 833 static_cast<base::string16>(message), | 833 message.utf16(), base::Passed(&channel_array))); |
| 834 base::Passed(&channel_array))); | |
| 835 } | 834 } |
| 836 | 835 |
| 837 void ServiceWorkerContextClient::postMessageToCrossOriginClient( | 836 void ServiceWorkerContextClient::postMessageToCrossOriginClient( |
| 838 const blink::WebCrossOriginServiceWorkerClient&, | 837 const blink::WebCrossOriginServiceWorkerClient&, |
| 839 const blink::WebString&, | 838 const blink::WebString&, |
| 840 blink::WebMessagePortChannelArray*) { | 839 blink::WebMessagePortChannelArray*) { |
| 841 NOTREACHED(); | 840 NOTREACHED(); |
| 842 } | 841 } |
| 843 | 842 |
| 844 void ServiceWorkerContextClient::focus( | 843 void ServiceWorkerContextClient::focus( |
| 845 const blink::WebString& uuid, | 844 const blink::WebString& uuid, |
| 846 std::unique_ptr<blink::WebServiceWorkerClientCallbacks> callback) { | 845 std::unique_ptr<blink::WebServiceWorkerClientCallbacks> callback) { |
| 847 DCHECK(callback); | 846 DCHECK(callback); |
| 848 int request_id = context_->client_callbacks.Add(std::move(callback)); | 847 int request_id = context_->client_callbacks.Add(std::move(callback)); |
| 849 Send(new ServiceWorkerHostMsg_FocusClient( | 848 Send(new ServiceWorkerHostMsg_FocusClient(GetRoutingID(), request_id, |
| 850 GetRoutingID(), request_id, | 849 uuid.utf8())); |
| 851 base::UTF16ToUTF8(base::StringPiece16(uuid)))); | |
| 852 } | 850 } |
| 853 | 851 |
| 854 void ServiceWorkerContextClient::navigate( | 852 void ServiceWorkerContextClient::navigate( |
| 855 const blink::WebString& uuid, | 853 const blink::WebString& uuid, |
| 856 const blink::WebURL& url, | 854 const blink::WebURL& url, |
| 857 std::unique_ptr<blink::WebServiceWorkerClientCallbacks> callback) { | 855 std::unique_ptr<blink::WebServiceWorkerClientCallbacks> callback) { |
| 858 DCHECK(callback); | 856 DCHECK(callback); |
| 859 int request_id = context_->client_callbacks.Add(std::move(callback)); | 857 int request_id = context_->client_callbacks.Add(std::move(callback)); |
| 860 Send(new ServiceWorkerHostMsg_NavigateClient( | 858 Send(new ServiceWorkerHostMsg_NavigateClient(GetRoutingID(), request_id, |
| 861 GetRoutingID(), request_id, base::UTF16ToUTF8(base::StringPiece16(uuid)), | 859 uuid.utf8(), url)); |
| 862 url)); | |
| 863 } | 860 } |
| 864 | 861 |
| 865 void ServiceWorkerContextClient::skipWaiting( | 862 void ServiceWorkerContextClient::skipWaiting( |
| 866 std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks> callbacks) { | 863 std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks> callbacks) { |
| 867 DCHECK(callbacks); | 864 DCHECK(callbacks); |
| 868 int request_id = context_->skip_waiting_callbacks.Add(std::move(callbacks)); | 865 int request_id = context_->skip_waiting_callbacks.Add(std::move(callbacks)); |
| 869 Send(new ServiceWorkerHostMsg_SkipWaiting(GetRoutingID(), request_id)); | 866 Send(new ServiceWorkerHostMsg_SkipWaiting(GetRoutingID(), request_id)); |
| 870 } | 867 } |
| 871 | 868 |
| 872 void ServiceWorkerContextClient::claim( | 869 void ServiceWorkerContextClient::claim( |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 945 TRACE_EVENT0("ServiceWorker", | 942 TRACE_EVENT0("ServiceWorker", |
| 946 "ServiceWorkerContextClient::OnExtendableMessageEvent"); | 943 "ServiceWorkerContextClient::OnExtendableMessageEvent"); |
| 947 blink::WebMessagePortChannelArray ports = | 944 blink::WebMessagePortChannelArray ports = |
| 948 WebMessagePortChannelImpl::CreatePorts(params.message_ports, | 945 WebMessagePortChannelImpl::CreatePorts(params.message_ports, |
| 949 params.new_routing_ids, | 946 params.new_routing_ids, |
| 950 main_thread_task_runner_); | 947 main_thread_task_runner_); |
| 951 if (params.source.client_info.IsValid()) { | 948 if (params.source.client_info.IsValid()) { |
| 952 blink::WebServiceWorkerClientInfo web_client = | 949 blink::WebServiceWorkerClientInfo web_client = |
| 953 ToWebServiceWorkerClientInfo(params.source.client_info); | 950 ToWebServiceWorkerClientInfo(params.source.client_info); |
| 954 proxy_->dispatchExtendableMessageEvent( | 951 proxy_->dispatchExtendableMessageEvent( |
| 955 request_id, params.message, params.source_origin, ports, web_client); | 952 request_id, blink::WebString::fromUTF16(params.message), |
| 953 params.source_origin, ports, web_client); |
| 956 return; | 954 return; |
| 957 } | 955 } |
| 958 | 956 |
| 959 DCHECK(params.source.service_worker_info.IsValid()); | 957 DCHECK(params.source.service_worker_info.IsValid()); |
| 960 std::unique_ptr<ServiceWorkerHandleReference> handle = | 958 std::unique_ptr<ServiceWorkerHandleReference> handle = |
| 961 ServiceWorkerHandleReference::Adopt(params.source.service_worker_info, | 959 ServiceWorkerHandleReference::Adopt(params.source.service_worker_info, |
| 962 sender_.get()); | 960 sender_.get()); |
| 963 ServiceWorkerDispatcher* dispatcher = | 961 ServiceWorkerDispatcher* dispatcher = |
| 964 ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( | 962 ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( |
| 965 sender_.get(), main_thread_task_runner_.get()); | 963 sender_.get(), main_thread_task_runner_.get()); |
| 966 scoped_refptr<WebServiceWorkerImpl> worker = | 964 scoped_refptr<WebServiceWorkerImpl> worker = |
| 967 dispatcher->GetOrCreateServiceWorker(std::move(handle)); | 965 dispatcher->GetOrCreateServiceWorker(std::move(handle)); |
| 968 proxy_->dispatchExtendableMessageEvent( | 966 proxy_->dispatchExtendableMessageEvent( |
| 969 request_id, params.message, params.source_origin, ports, | 967 request_id, blink::WebString::fromUTF16(params.message), |
| 970 WebServiceWorkerImpl::CreateHandle(worker)); | 968 params.source_origin, ports, WebServiceWorkerImpl::CreateHandle(worker)); |
| 971 } | 969 } |
| 972 | 970 |
| 973 void ServiceWorkerContextClient::OnInstallEvent(int request_id) { | 971 void ServiceWorkerContextClient::OnInstallEvent(int request_id) { |
| 974 TRACE_EVENT0("ServiceWorker", | 972 TRACE_EVENT0("ServiceWorker", |
| 975 "ServiceWorkerContextClient::OnInstallEvent"); | 973 "ServiceWorkerContextClient::OnInstallEvent"); |
| 976 proxy_->dispatchInstallEvent(request_id); | 974 proxy_->dispatchInstallEvent(request_id); |
| 977 } | 975 } |
| 978 | 976 |
| 979 void ServiceWorkerContextClient::DispatchFetchEvent( | 977 void ServiceWorkerContextClient::DispatchFetchEvent( |
| 980 int fetch_event_id, | 978 int fetch_event_id, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1034 int request_id, | 1032 int request_id, |
| 1035 const std::string& notification_id, | 1033 const std::string& notification_id, |
| 1036 const PlatformNotificationData& notification_data, | 1034 const PlatformNotificationData& notification_data, |
| 1037 int action_index, | 1035 int action_index, |
| 1038 const base::NullableString16& reply) { | 1036 const base::NullableString16& reply) { |
| 1039 TRACE_EVENT0("ServiceWorker", | 1037 TRACE_EVENT0("ServiceWorker", |
| 1040 "ServiceWorkerContextClient::OnNotificationClickEvent"); | 1038 "ServiceWorkerContextClient::OnNotificationClickEvent"); |
| 1041 proxy_->dispatchNotificationClickEvent( | 1039 proxy_->dispatchNotificationClickEvent( |
| 1042 request_id, blink::WebString::fromUTF8(notification_id), | 1040 request_id, blink::WebString::fromUTF8(notification_id), |
| 1043 ToWebNotificationData(notification_data), action_index, | 1041 ToWebNotificationData(notification_data), action_index, |
| 1044 blink::WebString(reply)); | 1042 blink::WebString::fromUTF16(reply)); |
| 1045 } | 1043 } |
| 1046 | 1044 |
| 1047 void ServiceWorkerContextClient::OnNotificationCloseEvent( | 1045 void ServiceWorkerContextClient::OnNotificationCloseEvent( |
| 1048 int request_id, | 1046 int request_id, |
| 1049 const std::string& notification_id, | 1047 const std::string& notification_id, |
| 1050 const PlatformNotificationData& notification_data) { | 1048 const PlatformNotificationData& notification_data) { |
| 1051 TRACE_EVENT0("ServiceWorker", | 1049 TRACE_EVENT0("ServiceWorker", |
| 1052 "ServiceWorkerContextClient::OnNotificationCloseEvent"); | 1050 "ServiceWorkerContextClient::OnNotificationCloseEvent"); |
| 1053 proxy_->dispatchNotificationCloseEvent( | 1051 proxy_->dispatchNotificationCloseEvent( |
| 1054 request_id, blink::WebString::fromUTF8(notification_id), | 1052 request_id, blink::WebString::fromUTF8(notification_id), |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1238 blink::WebServiceWorkerError::ErrorType error_type, | 1236 blink::WebServiceWorkerError::ErrorType error_type, |
| 1239 const base::string16& message) { | 1237 const base::string16& message) { |
| 1240 TRACE_EVENT0("ServiceWorker", | 1238 TRACE_EVENT0("ServiceWorker", |
| 1241 "ServiceWorkerContextClient::OnClaimClientsError"); | 1239 "ServiceWorkerContextClient::OnClaimClientsError"); |
| 1242 blink::WebServiceWorkerClientsClaimCallbacks* callbacks = | 1240 blink::WebServiceWorkerClientsClaimCallbacks* callbacks = |
| 1243 context_->claim_clients_callbacks.Lookup(request_id); | 1241 context_->claim_clients_callbacks.Lookup(request_id); |
| 1244 if (!callbacks) { | 1242 if (!callbacks) { |
| 1245 NOTREACHED() << "Got stray response: " << request_id; | 1243 NOTREACHED() << "Got stray response: " << request_id; |
| 1246 return; | 1244 return; |
| 1247 } | 1245 } |
| 1248 callbacks->onError(blink::WebServiceWorkerError(error_type, message)); | 1246 callbacks->onError(blink::WebServiceWorkerError( |
| 1247 error_type, blink::WebString::fromUTF16(message))); |
| 1249 context_->claim_clients_callbacks.Remove(request_id); | 1248 context_->claim_clients_callbacks.Remove(request_id); |
| 1250 } | 1249 } |
| 1251 | 1250 |
| 1252 void ServiceWorkerContextClient::OnPing() { | 1251 void ServiceWorkerContextClient::OnPing() { |
| 1253 Send(new ServiceWorkerHostMsg_Pong(GetRoutingID())); | 1252 Send(new ServiceWorkerHostMsg_Pong(GetRoutingID())); |
| 1254 } | 1253 } |
| 1255 | 1254 |
| 1256 void ServiceWorkerContextClient::OnNavigationPreloadResponse( | 1255 void ServiceWorkerContextClient::OnNavigationPreloadResponse( |
| 1257 int fetch_event_id, | 1256 int fetch_event_id, |
| 1258 std::unique_ptr<blink::WebServiceWorkerResponse> response, | 1257 std::unique_ptr<blink::WebServiceWorkerResponse> response, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1275 } | 1274 } |
| 1276 | 1275 |
| 1277 base::WeakPtr<ServiceWorkerContextClient> | 1276 base::WeakPtr<ServiceWorkerContextClient> |
| 1278 ServiceWorkerContextClient::GetWeakPtr() { | 1277 ServiceWorkerContextClient::GetWeakPtr() { |
| 1279 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 1278 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
| 1280 DCHECK(context_); | 1279 DCHECK(context_); |
| 1281 return context_->weak_factory.GetWeakPtr(); | 1280 return context_->weak_factory.GetWeakPtr(); |
| 1282 } | 1281 } |
| 1283 | 1282 |
| 1284 } // namespace content | 1283 } // namespace content |
| OLD | NEW |