| 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 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1135 const ExtendableMessageEventSource& source, | 1136 const ExtendableMessageEventSource& source, |
| 1136 const StatusCallback& callback) { | 1137 const StatusCallback& callback) { |
| 1137 int request_id = | 1138 int request_id = |
| 1138 worker->StartRequest(ServiceWorkerMetrics::EventType::MESSAGE, callback); | 1139 worker->StartRequest(ServiceWorkerMetrics::EventType::MESSAGE, callback); |
| 1139 | 1140 |
| 1140 MessagePortMessageFilter* filter = | 1141 MessagePortMessageFilter* filter = |
| 1141 worker->embedded_worker()->message_port_message_filter(); | 1142 worker->embedded_worker()->message_port_message_filter(); |
| 1142 std::vector<int> new_routing_ids; | 1143 std::vector<int> new_routing_ids; |
| 1143 filter->UpdateMessagePortsWithNewRoutes(sent_message_ports, &new_routing_ids); | 1144 filter->UpdateMessagePortsWithNewRoutes(sent_message_ports, &new_routing_ids); |
| 1144 | 1145 |
| 1145 ServiceWorkerMsg_ExtendableMessageEvent_Params params; | 1146 mojom::ExtendableMessageEventPtr event = mojom::ExtendableMessageEvent::New(); |
| 1146 params.message = message; | 1147 event->message = message; |
| 1147 params.source_origin = source_origin; | 1148 event->source_origin = source_origin; |
| 1148 params.message_ports = sent_message_ports; | 1149 event->message_ports = sent_message_ports; |
| 1149 params.new_routing_ids = new_routing_ids; | 1150 event->new_routing_ids = new_routing_ids; |
| 1150 params.source = source; | 1151 event->source = source; |
| 1151 | 1152 |
| 1152 // Hide the client url if the client has a unique origin. | 1153 // Hide the client url if the client has a unique origin. |
| 1153 if (source_origin.unique()) { | 1154 if (source_origin.unique()) { |
| 1154 if (params.source.client_info.IsValid()) | 1155 if (event->source.client_info.IsValid()) |
| 1155 params.source.client_info.url = GURL(); | 1156 event->source.client_info.url = GURL(); |
| 1156 else | 1157 else |
| 1157 params.source.service_worker_info.url = GURL(); | 1158 event->source.service_worker_info.url = GURL(); |
| 1158 } | 1159 } |
| 1159 | 1160 |
| 1160 worker->DispatchSimpleEvent< | 1161 // |event_dispatcher| is owned by |worker|, once |worker| got destroyed, the |
| 1161 ServiceWorkerHostMsg_ExtendableMessageEventFinished>( | 1162 // bound function will never be called, so it is safe to use |
| 1162 request_id, ServiceWorkerMsg_ExtendableMessageEvent(request_id, params)); | 1163 // base::Unretained() here. |
| 1164 worker->event_dispatcher()->DispatchExtendableMessageEvent( |
| 1165 std::move(event), base::Bind(&ServiceWorkerVersion::OnSimpleEventFinished, |
| 1166 base::Unretained(worker.get()), request_id)); |
| 1163 } | 1167 } |
| 1164 | 1168 |
| 1165 template <typename SourceInfo> | 1169 template <typename SourceInfo> |
| 1166 void ServiceWorkerDispatcherHost::DidFailToDispatchExtendableMessageEvent( | 1170 void ServiceWorkerDispatcherHost::DidFailToDispatchExtendableMessageEvent( |
| 1167 const std::vector<int>& sent_message_ports, | 1171 const std::vector<int>& sent_message_ports, |
| 1168 const SourceInfo& source_info, | 1172 const SourceInfo& source_info, |
| 1169 const StatusCallback& callback, | 1173 const StatusCallback& callback, |
| 1170 ServiceWorkerStatusCode status) { | 1174 ServiceWorkerStatusCode status) { |
| 1171 // Transfering the message ports failed, so destroy the ports. | 1175 // Transfering the message ports failed, so destroy the ports. |
| 1172 for (int port : sent_message_ports) | 1176 for (int port : sent_message_ports) |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1720 if (!handle) { | 1724 if (!handle) { |
| 1721 bad_message::ReceivedBadMessage(this, | 1725 bad_message::ReceivedBadMessage(this, |
| 1722 bad_message::SWDH_TERMINATE_BAD_HANDLE); | 1726 bad_message::SWDH_TERMINATE_BAD_HANDLE); |
| 1723 return; | 1727 return; |
| 1724 } | 1728 } |
| 1725 handle->version()->StopWorker( | 1729 handle->version()->StopWorker( |
| 1726 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 1730 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
| 1727 } | 1731 } |
| 1728 | 1732 |
| 1729 } // namespace content | 1733 } // namespace content |
| OLD | NEW |