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