OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/browser/service_worker/service_worker_dispatcher_host.h" | 5 #include "content/browser/service_worker/service_worker_dispatcher_host.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/debug/crash_logging.h" | 9 #include "base/debug/crash_logging.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
13 #include "base/profiler/scoped_tracker.h" | 13 #include "base/profiler/scoped_tracker.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
16 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
17 #include "content/browser/bad_message.h" | 17 #include "content/browser/bad_message.h" |
18 #include "content/browser/message_port_message_filter.h" | 18 #include "content/browser/message_port_message_filter.h" |
19 #include "content/browser/message_port_service.h" | 19 #include "content/browser/message_port_service.h" |
20 #include "content/browser/service_worker/embedded_worker_registry.h" | 20 #include "content/browser/service_worker/embedded_worker_registry.h" |
21 #include "content/browser/service_worker/embedded_worker_status.h" | 21 #include "content/browser/service_worker/embedded_worker_status.h" |
22 #include "content/browser/service_worker/service_worker_client_utils.h" | 22 #include "content/browser/service_worker/service_worker_client_utils.h" |
23 #include "content/browser/service_worker/service_worker_context_core.h" | 23 #include "content/browser/service_worker/service_worker_context_core.h" |
24 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 24 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
25 #include "content/browser/service_worker/service_worker_handle.h" | 25 #include "content/browser/service_worker/service_worker_handle.h" |
26 #include "content/browser/service_worker/service_worker_navigation_handle_core.h
" | 26 #include "content/browser/service_worker/service_worker_navigation_handle_core.h
" |
27 #include "content/browser/service_worker/service_worker_registration.h" | 27 #include "content/browser/service_worker/service_worker_registration.h" |
28 #include "content/browser/service_worker/service_worker_registration_handle.h" | 28 #include "content/browser/service_worker/service_worker_registration_handle.h" |
29 #include "content/common/service_worker/embedded_worker_messages.h" | 29 #include "content/common/service_worker/embedded_worker_messages.h" |
| 30 #include "content/common/service_worker/service_worker_event_dispatcher.mojom.h" |
30 #include "content/common/service_worker/service_worker_messages.h" | 31 #include "content/common/service_worker/service_worker_messages.h" |
31 #include "content/common/service_worker/service_worker_types.h" | 32 #include "content/common/service_worker/service_worker_types.h" |
32 #include "content/common/service_worker/service_worker_utils.h" | 33 #include "content/common/service_worker/service_worker_utils.h" |
33 #include "content/public/browser/content_browser_client.h" | 34 #include "content/public/browser/content_browser_client.h" |
34 #include "content/public/common/browser_side_navigation_policy.h" | 35 #include "content/public/common/browser_side_navigation_policy.h" |
35 #include "content/public/common/content_client.h" | 36 #include "content/public/common/content_client.h" |
36 #include "content/public/common/origin_util.h" | 37 #include "content/public/common/origin_util.h" |
37 #include "ipc/ipc_message_macros.h" | 38 #include "ipc/ipc_message_macros.h" |
38 #include "net/http/http_util.h" | 39 #include "net/http/http_util.h" |
39 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerError.h" | 40 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerError.h" |
(...skipping 1120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1160 } else { | 1161 } else { |
1161 request_id = worker->StartRequest(ServiceWorkerMetrics::EventType::MESSAGE, | 1162 request_id = worker->StartRequest(ServiceWorkerMetrics::EventType::MESSAGE, |
1162 callback); | 1163 callback); |
1163 } | 1164 } |
1164 | 1165 |
1165 MessagePortMessageFilter* filter = | 1166 MessagePortMessageFilter* filter = |
1166 worker->embedded_worker()->message_port_message_filter(); | 1167 worker->embedded_worker()->message_port_message_filter(); |
1167 std::vector<int> new_routing_ids; | 1168 std::vector<int> new_routing_ids; |
1168 filter->UpdateMessagePortsWithNewRoutes(sent_message_ports, &new_routing_ids); | 1169 filter->UpdateMessagePortsWithNewRoutes(sent_message_ports, &new_routing_ids); |
1169 | 1170 |
1170 ServiceWorkerMsg_ExtendableMessageEvent_Params params; | 1171 mojom::ExtendableMessageEventPtr event = mojom::ExtendableMessageEvent::New(); |
1171 params.message = message; | 1172 event->message = message; |
1172 params.source_origin = source_origin; | 1173 event->source_origin = source_origin; |
1173 params.message_ports = sent_message_ports; | 1174 event->message_ports = sent_message_ports; |
1174 params.new_routing_ids = new_routing_ids; | 1175 event->new_routing_ids = new_routing_ids; |
1175 params.source = source; | 1176 event->source = source; |
1176 | 1177 |
1177 // Hide the client url if the client has a unique origin. | 1178 // Hide the client url if the client has a unique origin. |
1178 if (source_origin.unique()) { | 1179 if (source_origin.unique()) { |
1179 if (params.source.client_info.IsValid()) | 1180 if (event->source.client_info.IsValid()) |
1180 params.source.client_info.url = GURL(); | 1181 event->source.client_info.url = GURL(); |
1181 else | 1182 else |
1182 params.source.service_worker_info.url = GURL(); | 1183 event->source.service_worker_info.url = GURL(); |
1183 } | 1184 } |
1184 | 1185 |
1185 worker->DispatchSimpleEvent< | 1186 // |event_dispatcher| is owned by |worker|, once |worker| got destroyed, the |
1186 ServiceWorkerHostMsg_ExtendableMessageEventFinished>( | 1187 // bound function will never be called, so it is safe to use |
1187 request_id, ServiceWorkerMsg_ExtendableMessageEvent(request_id, params)); | 1188 // base::Unretained() here. |
| 1189 worker->event_dispatcher()->DispatchExtendableMessageEvent( |
| 1190 std::move(event), base::Bind(&ServiceWorkerVersion::OnSimpleEventFinished, |
| 1191 base::Unretained(worker.get()), request_id)); |
1188 } | 1192 } |
1189 | 1193 |
1190 template <typename SourceInfo> | 1194 template <typename SourceInfo> |
1191 void ServiceWorkerDispatcherHost::DidFailToDispatchExtendableMessageEvent( | 1195 void ServiceWorkerDispatcherHost::DidFailToDispatchExtendableMessageEvent( |
1192 const std::vector<int>& sent_message_ports, | 1196 const std::vector<int>& sent_message_ports, |
1193 const SourceInfo& source_info, | 1197 const SourceInfo& source_info, |
1194 const StatusCallback& callback, | 1198 const StatusCallback& callback, |
1195 ServiceWorkerStatusCode status) { | 1199 ServiceWorkerStatusCode status) { |
1196 // Transfering the message ports failed, so destroy the ports. | 1200 // Transfering the message ports failed, so destroy the ports. |
1197 for (int port : sent_message_ports) | 1201 for (int port : sent_message_ports) |
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1745 if (!handle) { | 1749 if (!handle) { |
1746 bad_message::ReceivedBadMessage(this, | 1750 bad_message::ReceivedBadMessage(this, |
1747 bad_message::SWDH_TERMINATE_BAD_HANDLE); | 1751 bad_message::SWDH_TERMINATE_BAD_HANDLE); |
1748 return; | 1752 return; |
1749 } | 1753 } |
1750 handle->version()->StopWorker( | 1754 handle->version()->StopWorker( |
1751 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 1755 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
1752 } | 1756 } |
1753 | 1757 |
1754 } // namespace content | 1758 } // namespace content |
OLD | NEW |