Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: content/renderer/service_worker/service_worker_context_client.cc

Issue 2422793002: HTML MessagePort as mojo::MessagePipeHandle (Closed)
Patch Set: Add missing ScopedAsyncTaskScheduler instance for the new unit tests; required by a recent change t… Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 15 matching lines...) Expand all
26 #include "content/child/service_worker/service_worker_provider_context.h" 26 #include "content/child/service_worker/service_worker_provider_context.h"
27 #include "content/child/service_worker/service_worker_registration_handle_refere nce.h" 27 #include "content/child/service_worker/service_worker_registration_handle_refere nce.h"
28 #include "content/child/service_worker/web_service_worker_impl.h" 28 #include "content/child/service_worker/web_service_worker_impl.h"
29 #include "content/child/service_worker/web_service_worker_provider_impl.h" 29 #include "content/child/service_worker/web_service_worker_provider_impl.h"
30 #include "content/child/service_worker/web_service_worker_registration_impl.h" 30 #include "content/child/service_worker/web_service_worker_registration_impl.h"
31 #include "content/child/thread_safe_sender.h" 31 #include "content/child/thread_safe_sender.h"
32 #include "content/child/web_data_consumer_handle_impl.h" 32 #include "content/child/web_data_consumer_handle_impl.h"
33 #include "content/child/web_url_loader_impl.h" 33 #include "content/child/web_url_loader_impl.h"
34 #include "content/child/webmessageportchannel_impl.h" 34 #include "content/child/webmessageportchannel_impl.h"
35 #include "content/common/devtools_messages.h" 35 #include "content/common/devtools_messages.h"
36 #include "content/common/message_port_messages.h"
37 #include "content/common/service_worker/embedded_worker_messages.h" 36 #include "content/common/service_worker/embedded_worker_messages.h"
38 #include "content/common/service_worker/service_worker_event_dispatcher.mojom.h" 37 #include "content/common/service_worker/service_worker_event_dispatcher.mojom.h"
39 #include "content/common/service_worker/service_worker_messages.h" 38 #include "content/common/service_worker/service_worker_messages.h"
40 #include "content/common/service_worker/service_worker_status_code.h" 39 #include "content/common/service_worker/service_worker_status_code.h"
41 #include "content/common/service_worker/service_worker_utils.h" 40 #include "content/common/service_worker/service_worker_utils.h"
42 #include "content/public/common/push_event_payload.h" 41 #include "content/public/common/push_event_payload.h"
43 #include "content/public/common/referrer.h" 42 #include "content/public/common/referrer.h"
44 #include "content/public/renderer/content_renderer_client.h" 43 #include "content/public/renderer/content_renderer_client.h"
45 #include "content/public/renderer/document_state.h" 44 #include "content/public/renderer/document_state.h"
46 #include "content/renderer/devtools/devtools_agent.h" 45 #include "content/renderer/devtools/devtools_agent.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 switch (result) { 121 switch (result) {
123 case blink::WebServiceWorkerEventResultCompleted: 122 case blink::WebServiceWorkerEventResultCompleted:
124 return SERVICE_WORKER_OK; 123 return SERVICE_WORKER_OK;
125 case blink::WebServiceWorkerEventResultRejected: 124 case blink::WebServiceWorkerEventResultRejected:
126 return SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED; 125 return SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED;
127 } 126 }
128 NOTREACHED() << "Got invalid result: " << result; 127 NOTREACHED() << "Got invalid result: " << result;
129 return SERVICE_WORKER_ERROR_FAILED; 128 return SERVICE_WORKER_ERROR_FAILED;
130 } 129 }
131 130
132 void SendPostMessageToClientOnMainThread(
133 ThreadSafeSender* sender,
134 int routing_id,
135 const std::string& uuid,
136 const base::string16& message,
137 std::unique_ptr<blink::WebMessagePortChannelArray> channels) {
138 sender->Send(new ServiceWorkerHostMsg_PostMessageToClient(
139 routing_id, uuid, message,
140 WebMessagePortChannelImpl::ExtractMessagePortIDs(std::move(channels))));
141 }
142
143 blink::WebURLRequest::FetchRequestMode GetBlinkFetchRequestMode( 131 blink::WebURLRequest::FetchRequestMode GetBlinkFetchRequestMode(
144 FetchRequestMode mode) { 132 FetchRequestMode mode) {
145 return static_cast<blink::WebURLRequest::FetchRequestMode>(mode); 133 return static_cast<blink::WebURLRequest::FetchRequestMode>(mode);
146 } 134 }
147 135
148 blink::WebURLRequest::FetchCredentialsMode GetBlinkFetchCredentialsMode( 136 blink::WebURLRequest::FetchCredentialsMode GetBlinkFetchCredentialsMode(
149 FetchCredentialsMode credentials_mode) { 137 FetchCredentialsMode credentials_mode) {
150 return static_cast<blink::WebURLRequest::FetchCredentialsMode>( 138 return static_cast<blink::WebURLRequest::FetchCredentialsMode>(
151 credentials_mode); 139 credentials_mode);
152 } 140 }
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 DCHECK(provider_context_); 820 DCHECK(provider_context_);
833 821
834 // Blink is responsible for deleting the returned object. 822 // Blink is responsible for deleting the returned object.
835 return new WebServiceWorkerProviderImpl( 823 return new WebServiceWorkerProviderImpl(
836 sender_.get(), provider_context_.get()); 824 sender_.get(), provider_context_.get());
837 } 825 }
838 826
839 void ServiceWorkerContextClient::postMessageToClient( 827 void ServiceWorkerContextClient::postMessageToClient(
840 const blink::WebString& uuid, 828 const blink::WebString& uuid,
841 const blink::WebString& message, 829 const blink::WebString& message,
842 blink::WebMessagePortChannelArray* channels) { 830 blink::WebMessagePortChannelArray channels) {
843 // This may send channels for MessagePorts, and all internal book-keeping 831 Send(new ServiceWorkerHostMsg_PostMessageToClient(
844 // messages for MessagePort (e.g. QueueMessages) are sent from main thread 832 GetRoutingID(), uuid.utf8(), message.utf16(),
845 // (with thread hopping), so we need to do the same thread hopping here not 833 WebMessagePortChannelImpl::ExtractMessagePorts(std::move(channels))));
846 // to overtake those messages.
847 std::unique_ptr<blink::WebMessagePortChannelArray> channel_array(channels);
848 main_thread_task_runner_->PostTask(
849 FROM_HERE,
850 base::Bind(&SendPostMessageToClientOnMainThread,
851 base::RetainedRef(sender_), GetRoutingID(), uuid.utf8(),
852 message.utf16(), base::Passed(&channel_array)));
853 } 834 }
854 835
855 void ServiceWorkerContextClient::focus( 836 void ServiceWorkerContextClient::focus(
856 const blink::WebString& uuid, 837 const blink::WebString& uuid,
857 std::unique_ptr<blink::WebServiceWorkerClientCallbacks> callback) { 838 std::unique_ptr<blink::WebServiceWorkerClientCallbacks> callback) {
858 DCHECK(callback); 839 DCHECK(callback);
859 int request_id = context_->client_callbacks.Add(std::move(callback)); 840 int request_id = context_->client_callbacks.Add(std::move(callback));
860 Send(new ServiceWorkerHostMsg_FocusClient(GetRoutingID(), request_id, 841 Send(new ServiceWorkerHostMsg_FocusClient(GetRoutingID(), request_id,
861 uuid.utf8())); 842 uuid.utf8()));
862 } 843 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 941
961 void ServiceWorkerContextClient::DispatchExtendableMessageEvent( 942 void ServiceWorkerContextClient::DispatchExtendableMessageEvent(
962 mojom::ExtendableMessageEventPtr event, 943 mojom::ExtendableMessageEventPtr event,
963 const DispatchExtendableMessageEventCallback& callback) { 944 const DispatchExtendableMessageEventCallback& callback) {
964 TRACE_EVENT0("ServiceWorker", 945 TRACE_EVENT0("ServiceWorker",
965 "ServiceWorkerContextClient::DispatchExtendableMessageEvent"); 946 "ServiceWorkerContextClient::DispatchExtendableMessageEvent");
966 int request_id = context_->message_event_callbacks.Add( 947 int request_id = context_->message_event_callbacks.Add(
967 base::MakeUnique<DispatchExtendableMessageEventCallback>(callback)); 948 base::MakeUnique<DispatchExtendableMessageEventCallback>(callback));
968 949
969 blink::WebMessagePortChannelArray ports = 950 blink::WebMessagePortChannelArray ports =
970 WebMessagePortChannelImpl::CreatePorts(event->message_ports, 951 WebMessagePortChannelImpl::CreateFromMessagePipeHandles(
971 event->new_routing_ids, 952 std::move(event->message_ports));
972 main_thread_task_runner_);
973 if (event->source.client_info.IsValid()) { 953 if (event->source.client_info.IsValid()) {
974 blink::WebServiceWorkerClientInfo web_client = 954 blink::WebServiceWorkerClientInfo web_client =
975 ToWebServiceWorkerClientInfo(event->source.client_info); 955 ToWebServiceWorkerClientInfo(event->source.client_info);
976 proxy_->dispatchExtendableMessageEvent( 956 proxy_->dispatchExtendableMessageEvent(
977 request_id, blink::WebString::fromUTF16(event->message), 957 request_id, blink::WebString::fromUTF16(event->message),
978 event->source_origin, ports, web_client); 958 event->source_origin, std::move(ports), web_client);
979 return; 959 return;
980 } 960 }
981 961
982 DCHECK(event->source.service_worker_info.IsValid()); 962 DCHECK(event->source.service_worker_info.IsValid());
983 std::unique_ptr<ServiceWorkerHandleReference> handle = 963 std::unique_ptr<ServiceWorkerHandleReference> handle =
984 ServiceWorkerHandleReference::Adopt(event->source.service_worker_info, 964 ServiceWorkerHandleReference::Adopt(event->source.service_worker_info,
985 sender_.get()); 965 sender_.get());
986 ServiceWorkerDispatcher* dispatcher = 966 ServiceWorkerDispatcher* dispatcher =
987 ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( 967 ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance(
988 sender_.get(), main_thread_task_runner_.get()); 968 sender_.get(), main_thread_task_runner_.get());
989 scoped_refptr<WebServiceWorkerImpl> worker = 969 scoped_refptr<WebServiceWorkerImpl> worker =
990 dispatcher->GetOrCreateServiceWorker(std::move(handle)); 970 dispatcher->GetOrCreateServiceWorker(std::move(handle));
991 proxy_->dispatchExtendableMessageEvent( 971 proxy_->dispatchExtendableMessageEvent(
992 request_id, blink::WebString::fromUTF16(event->message), 972 request_id, blink::WebString::fromUTF16(event->message),
993 event->source_origin, ports, WebServiceWorkerImpl::CreateHandle(worker)); 973 event->source_origin, std::move(ports),
974 WebServiceWorkerImpl::CreateHandle(worker));
994 } 975 }
995 976
996 void ServiceWorkerContextClient::OnInstallEvent(int request_id) { 977 void ServiceWorkerContextClient::OnInstallEvent(int request_id) {
997 TRACE_EVENT0("ServiceWorker", 978 TRACE_EVENT0("ServiceWorker",
998 "ServiceWorkerContextClient::OnInstallEvent"); 979 "ServiceWorkerContextClient::OnInstallEvent");
999 proxy_->dispatchInstallEvent(request_id); 980 proxy_->dispatchInstallEvent(request_id);
1000 } 981 }
1001 982
1002 void ServiceWorkerContextClient::DispatchFetchEvent( 983 void ServiceWorkerContextClient::DispatchFetchEvent(
1003 int fetch_event_id, 984 int fetch_event_id,
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
1313 } 1294 }
1314 1295
1315 base::WeakPtr<ServiceWorkerContextClient> 1296 base::WeakPtr<ServiceWorkerContextClient>
1316 ServiceWorkerContextClient::GetWeakPtr() { 1297 ServiceWorkerContextClient::GetWeakPtr() {
1317 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); 1298 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread());
1318 DCHECK(context_); 1299 DCHECK(context_);
1319 return context_->weak_factory.GetWeakPtr(); 1300 return context_->weak_factory.GetWeakPtr();
1320 } 1301 }
1321 1302
1322 } // namespace content 1303 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698