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