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" |
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 case SERVICE_WORKER_PROVIDER_UNKNOWN: | 739 case SERVICE_WORKER_PROVIDER_UNKNOWN: |
740 default: | 740 default: |
741 NOTREACHED() << sender_provider_host->provider_type(); | 741 NOTREACHED() << sender_provider_host->provider_type(); |
742 break; | 742 break; |
743 } | 743 } |
744 } | 744 } |
745 | 745 |
746 void ServiceWorkerDispatcherHost::OnProviderCreated( | 746 void ServiceWorkerDispatcherHost::OnProviderCreated( |
747 int provider_id, | 747 int provider_id, |
748 int route_id, | 748 int route_id, |
749 ServiceWorkerProviderType provider_type, | 749 ServiceWorkerProviderType provider_type) { |
750 bool is_parent_frame_secure) { | |
751 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. | 750 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. |
752 tracked_objects::ScopedTracker tracking_profile( | 751 tracked_objects::ScopedTracker tracking_profile( |
753 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 752 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
754 "477117 ServiceWorkerDispatcherHost::OnProviderCreated")); | 753 "477117 ServiceWorkerDispatcherHost::OnProviderCreated")); |
755 TRACE_EVENT0("ServiceWorker", | 754 TRACE_EVENT0("ServiceWorker", |
756 "ServiceWorkerDispatcherHost::OnProviderCreated"); | 755 "ServiceWorkerDispatcherHost::OnProviderCreated"); |
757 if (!GetContext()) | 756 if (!GetContext()) |
758 return; | 757 return; |
759 if (GetContext()->GetProviderHost(render_process_id_, provider_id)) { | 758 if (GetContext()->GetProviderHost(render_process_id_, provider_id)) { |
760 bad_message::ReceivedBadMessage(this, | 759 bad_message::ReceivedBadMessage(this, |
761 bad_message::SWDH_PROVIDER_CREATED_NO_HOST); | 760 bad_message::SWDH_PROVIDER_CREATED_NO_HOST); |
762 return; | 761 return; |
763 } | 762 } |
764 | 763 |
765 std::unique_ptr<ServiceWorkerProviderHost> provider_host; | 764 std::unique_ptr<ServiceWorkerProviderHost> provider_host; |
766 if (IsBrowserSideNavigationEnabled() && | 765 if (IsBrowserSideNavigationEnabled() && |
767 ServiceWorkerUtils::IsBrowserAssignedProviderId(provider_id)) { | 766 ServiceWorkerUtils::IsBrowserAssignedProviderId(provider_id)) { |
768 // PlzNavigate | 767 // PlzNavigate |
769 // Retrieve the provider host previously created for navigation requests. | 768 // Retrieve the provider host previously created for navigation requests. |
770 ServiceWorkerNavigationHandleCore* navigation_handle_core = | 769 ServiceWorkerNavigationHandleCore* navigation_handle_core = |
771 GetContext()->GetNavigationHandleCore(provider_id); | 770 GetContext()->GetNavigationHandleCore(provider_id); |
772 if (navigation_handle_core != nullptr) { | 771 if (navigation_handle_core != nullptr) |
773 provider_host = navigation_handle_core->RetrievePreCreatedHost(); | 772 provider_host = navigation_handle_core->RetrievePreCreatedHost(); |
774 provider_host->set_parent_frame_secure(is_parent_frame_secure); | |
775 } | |
776 | 773 |
777 // If no host is found, the navigation has been cancelled in the meantime. | 774 // If no host is found, the navigation has been cancelled in the meantime. |
778 // Just return as the navigation will be stopped in the renderer as well. | 775 // Just return as the navigation will be stopped in the renderer as well. |
779 if (provider_host == nullptr) | 776 if (provider_host == nullptr) |
780 return; | 777 return; |
781 DCHECK_EQ(SERVICE_WORKER_PROVIDER_FOR_WINDOW, provider_type); | 778 DCHECK_EQ(SERVICE_WORKER_PROVIDER_FOR_WINDOW, provider_type); |
782 provider_host->CompleteNavigationInitialized(render_process_id_, route_id, | 779 provider_host->CompleteNavigationInitialized(render_process_id_, route_id, |
783 this); | 780 this); |
784 } else { | 781 } else { |
785 if (ServiceWorkerUtils::IsBrowserAssignedProviderId(provider_id)) { | 782 if (ServiceWorkerUtils::IsBrowserAssignedProviderId(provider_id)) { |
786 bad_message::ReceivedBadMessage( | 783 bad_message::ReceivedBadMessage( |
787 this, bad_message::SWDH_PROVIDER_CREATED_NO_HOST); | 784 this, bad_message::SWDH_PROVIDER_CREATED_NO_HOST); |
788 return; | 785 return; |
789 } | 786 } |
790 ServiceWorkerProviderHost::FrameSecurityLevel parent_frame_security_level = | |
791 is_parent_frame_secure | |
792 ? ServiceWorkerProviderHost::FrameSecurityLevel::SECURE | |
793 : ServiceWorkerProviderHost::FrameSecurityLevel::INSECURE; | |
794 provider_host = std::unique_ptr<ServiceWorkerProviderHost>( | 787 provider_host = std::unique_ptr<ServiceWorkerProviderHost>( |
795 new ServiceWorkerProviderHost( | 788 new ServiceWorkerProviderHost(render_process_id_, route_id, provider_id, |
796 render_process_id_, route_id, provider_id, provider_type, | 789 provider_type, GetContext()->AsWeakPtr(), |
797 parent_frame_security_level, GetContext()->AsWeakPtr(), this)); | 790 this)); |
798 } | 791 } |
799 GetContext()->AddProviderHost(std::move(provider_host)); | 792 GetContext()->AddProviderHost(std::move(provider_host)); |
800 } | 793 } |
801 | 794 |
802 void ServiceWorkerDispatcherHost::OnProviderDestroyed(int provider_id) { | 795 void ServiceWorkerDispatcherHost::OnProviderDestroyed(int provider_id) { |
803 TRACE_EVENT0("ServiceWorker", | 796 TRACE_EVENT0("ServiceWorker", |
804 "ServiceWorkerDispatcherHost::OnProviderDestroyed"); | 797 "ServiceWorkerDispatcherHost::OnProviderDestroyed"); |
805 if (!GetContext()) | 798 if (!GetContext()) |
806 return; | 799 return; |
807 if (!GetContext()->GetProviderHost(render_process_id_, provider_id)) { | 800 if (!GetContext()->GetProviderHost(render_process_id_, provider_id)) { |
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1413 if (!handle) { | 1406 if (!handle) { |
1414 bad_message::ReceivedBadMessage(this, | 1407 bad_message::ReceivedBadMessage(this, |
1415 bad_message::SWDH_TERMINATE_BAD_HANDLE); | 1408 bad_message::SWDH_TERMINATE_BAD_HANDLE); |
1416 return; | 1409 return; |
1417 } | 1410 } |
1418 handle->version()->StopWorker( | 1411 handle->version()->StopWorker( |
1419 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 1412 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
1420 } | 1413 } |
1421 | 1414 |
1422 } // namespace content | 1415 } // namespace content |
OLD | NEW |