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/logging.h" | 9 #include "base/logging.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/profiler/scoped_tracker.h" | 12 #include "base/profiler/scoped_tracker.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
15 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
16 #include "content/browser/bad_message.h" | 16 #include "content/browser/bad_message.h" |
17 #include "content/browser/message_port_message_filter.h" | 17 #include "content/browser/message_port_message_filter.h" |
18 #include "content/browser/message_port_service.h" | 18 #include "content/browser/message_port_service.h" |
19 #include "content/browser/service_worker/embedded_worker_registry.h" | 19 #include "content/browser/service_worker/embedded_worker_registry.h" |
20 #include "content/browser/service_worker/embedded_worker_status.h" | 20 #include "content/browser/service_worker/embedded_worker_status.h" |
21 #include "content/browser/service_worker/service_worker_client_utils.h" | 21 #include "content/browser/service_worker/service_worker_client_utils.h" |
22 #include "content/browser/service_worker/service_worker_context_core.h" | 22 #include "content/browser/service_worker/service_worker_context_core.h" |
23 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 23 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
24 #include "content/browser/service_worker/service_worker_handle.h" | 24 #include "content/browser/service_worker/service_worker_handle.h" |
25 #include "content/browser/service_worker/service_worker_navigation_handle_core.h
" | |
26 #include "content/browser/service_worker/service_worker_registration.h" | 25 #include "content/browser/service_worker/service_worker_registration.h" |
27 #include "content/browser/service_worker/service_worker_registration_handle.h" | 26 #include "content/browser/service_worker/service_worker_registration_handle.h" |
28 #include "content/common/service_worker/embedded_worker_messages.h" | 27 #include "content/common/service_worker/embedded_worker_messages.h" |
29 #include "content/common/service_worker/service_worker_messages.h" | 28 #include "content/common/service_worker/service_worker_messages.h" |
30 #include "content/common/service_worker/service_worker_types.h" | 29 #include "content/common/service_worker/service_worker_types.h" |
31 #include "content/common/service_worker/service_worker_utils.h" | 30 #include "content/common/service_worker/service_worker_utils.h" |
32 #include "content/public/browser/content_browser_client.h" | 31 #include "content/public/browser/content_browser_client.h" |
33 #include "content/public/common/browser_side_navigation_policy.h" | 32 #include "content/public/common/browser_side_navigation_policy.h" |
34 #include "content/public/common/content_client.h" | 33 #include "content/public/common/content_client.h" |
35 #include "content/public/common/origin_util.h" | 34 #include "content/public/common/origin_util.h" |
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 TRACE_EVENT0("ServiceWorker", | 755 TRACE_EVENT0("ServiceWorker", |
757 "ServiceWorkerDispatcherHost::OnProviderCreated"); | 756 "ServiceWorkerDispatcherHost::OnProviderCreated"); |
758 if (!GetContext()) | 757 if (!GetContext()) |
759 return; | 758 return; |
760 if (GetContext()->GetProviderHost(render_process_id_, provider_id)) { | 759 if (GetContext()->GetProviderHost(render_process_id_, provider_id)) { |
761 bad_message::ReceivedBadMessage(this, | 760 bad_message::ReceivedBadMessage(this, |
762 bad_message::SWDH_PROVIDER_CREATED_NO_HOST); | 761 bad_message::SWDH_PROVIDER_CREATED_NO_HOST); |
763 return; | 762 return; |
764 } | 763 } |
765 | 764 |
766 std::unique_ptr<ServiceWorkerProviderHost> provider_host; | 765 ServiceWorkerProviderHost::FrameSecurityLevel parent_frame_security_level = |
767 if (IsBrowserSideNavigationEnabled() && | 766 is_parent_frame_secure |
768 ServiceWorkerUtils::IsBrowserAssignedProviderId(provider_id)) { | 767 ? ServiceWorkerProviderHost::FrameSecurityLevel::SECURE |
769 // PlzNavigate | 768 : ServiceWorkerProviderHost::FrameSecurityLevel::INSECURE; |
770 // Retrieve the provider host previously created for navigation requests. | 769 std::unique_ptr<ServiceWorkerProviderHost> provider_host = |
771 ServiceWorkerNavigationHandleCore* navigation_handle_core = | 770 std::unique_ptr<ServiceWorkerProviderHost>(new ServiceWorkerProviderHost( |
772 GetContext()->GetNavigationHandleCore(provider_id); | 771 render_process_id_, route_id, provider_id, provider_type, |
773 if (navigation_handle_core != nullptr) { | 772 parent_frame_security_level, GetContext()->AsWeakPtr(), this)); |
774 provider_host = navigation_handle_core->RetrievePreCreatedHost(); | |
775 provider_host->set_parent_frame_secure(is_parent_frame_secure); | |
776 } | |
777 | |
778 // If no host is found, the navigation has been cancelled in the meantime. | |
779 // Just return as the navigation will be stopped in the renderer as well. | |
780 if (provider_host == nullptr) | |
781 return; | |
782 DCHECK_EQ(SERVICE_WORKER_PROVIDER_FOR_WINDOW, provider_type); | |
783 provider_host->CompleteNavigationInitialized(render_process_id_, route_id, | |
784 this); | |
785 } else { | |
786 if (ServiceWorkerUtils::IsBrowserAssignedProviderId(provider_id)) { | |
787 bad_message::ReceivedBadMessage( | |
788 this, bad_message::SWDH_PROVIDER_CREATED_NO_HOST); | |
789 return; | |
790 } | |
791 ServiceWorkerProviderHost::FrameSecurityLevel parent_frame_security_level = | |
792 is_parent_frame_secure | |
793 ? ServiceWorkerProviderHost::FrameSecurityLevel::SECURE | |
794 : ServiceWorkerProviderHost::FrameSecurityLevel::INSECURE; | |
795 provider_host = std::unique_ptr<ServiceWorkerProviderHost>( | |
796 new ServiceWorkerProviderHost( | |
797 render_process_id_, route_id, provider_id, provider_type, | |
798 parent_frame_security_level, GetContext()->AsWeakPtr(), this)); | |
799 } | |
800 GetContext()->AddProviderHost(std::move(provider_host)); | 773 GetContext()->AddProviderHost(std::move(provider_host)); |
801 } | 774 } |
802 | 775 |
803 void ServiceWorkerDispatcherHost::OnProviderDestroyed(int provider_id) { | 776 void ServiceWorkerDispatcherHost::OnProviderDestroyed(int provider_id) { |
804 TRACE_EVENT0("ServiceWorker", | 777 TRACE_EVENT0("ServiceWorker", |
805 "ServiceWorkerDispatcherHost::OnProviderDestroyed"); | 778 "ServiceWorkerDispatcherHost::OnProviderDestroyed"); |
806 if (!GetContext()) | 779 if (!GetContext()) |
807 return; | 780 return; |
808 if (!GetContext()->GetProviderHost(render_process_id_, provider_id)) { | 781 if (!GetContext()->GetProviderHost(render_process_id_, provider_id)) { |
809 // PlzNavigate: in some cancellation of navigation cases, it is possible | 782 // PlzNavigate: in some cancellation of navigation cases, it is possible |
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1414 if (!handle) { | 1387 if (!handle) { |
1415 bad_message::ReceivedBadMessage(this, | 1388 bad_message::ReceivedBadMessage(this, |
1416 bad_message::SWDH_TERMINATE_BAD_HANDLE); | 1389 bad_message::SWDH_TERMINATE_BAD_HANDLE); |
1417 return; | 1390 return; |
1418 } | 1391 } |
1419 handle->version()->StopWorker( | 1392 handle->version()->StopWorker( |
1420 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 1393 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
1421 } | 1394 } |
1422 | 1395 |
1423 } // namespace content | 1396 } // namespace content |
OLD | NEW |