diff --git a/android_webview/browser/aw_content_browser_client.cc b/android_webview/browser/aw_content_browser_client.cc index 559c17c6f2b7f..cab4c11ffe802 100644 --- a/android_webview/browser/aw_content_browser_client.cc +++ b/android_webview/browser/aw_content_browser_client.cc @@ -662,8 +662,7 @@ void AwContentBrowserClient::OverrideWebPreferences( (delegate) ? delegate->isModalContextMenu() : false; } -std::vector<std::unique_ptr<content::NavigationThrottle>> -AwContentBrowserClient::CreateThrottlesForNavigation( +void AwContentBrowserClient::CreateThrottlesForNavigation( content::NavigationThrottleRegistry& registry) { // We allow intercepting only navigations within main frames. This // is used to post onPageStarted. We handle shouldOverrideUrlLoading @@ -711,8 +710,6 @@ AwContentBrowserClient::CreateThrottlesForNavigation( &navigation_handle, urlClassifier)); } } - - return {}; } std::unique_ptr<content::PrefetchServiceDelegate> diff --git a/android_webview/browser/aw_content_browser_client.h b/android_webview/browser/aw_content_browser_client.h index 13fb94036819e..d2ed3814bdb98 100644 --- a/android_webview/browser/aw_content_browser_client.h +++ b/android_webview/browser/aw_content_browser_client.h @@ -149,8 +149,7 @@ class AwContentBrowserClient : public content::ContentBrowserClient { content::WebContents* web_contents, content::SiteInstance& main_frame_site, blink::web_pref::WebPreferences* web_prefs) override; - std::vector<std::unique_ptr<content::NavigationThrottle>> - CreateThrottlesForNavigation( + void CreateThrottlesForNavigation( content::NavigationThrottleRegistry& registry) override; std::unique_ptr<content::PrefetchServiceDelegate> CreatePrefetchServiceDelegate( diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index 17918fb7b206e..0a2664d2c32e2 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -5395,8 +5395,7 @@ void ChromeContentBrowserClient::RemovePresentationObserver( } } -std::vector<std::unique_ptr<content::NavigationThrottle>> -ChromeContentBrowserClient::CreateThrottlesForNavigation( +void ChromeContentBrowserClient::CreateThrottlesForNavigation( content::NavigationThrottleRegistry& registry) { // MetricsNavigationThrottle requires that it runs before NavigationThrottles // that may delay or cancel navigations, so only NavigationThrottles that @@ -5767,8 +5766,6 @@ ChromeContentBrowserClient::CreateThrottlesForNavigation( registry.MaybeAddThrottle( web_app::IsolatedWebAppThrottle::MaybeCreateThrottleFor(&handle)); #endif // !BUILDFLAG(IS_ANDROID) - - return {}; } std::vector<std::unique_ptr<content::CommitDeferringCondition>> diff --git a/chrome/browser/chrome_content_browser_client.h b/chrome/browser/chrome_content_browser_client.h index 48fd2e34d1a2c..4d28838005ab1 100644 --- a/chrome/browser/chrome_content_browser_client.h +++ b/chrome/browser/chrome_content_browser_client.h @@ -635,8 +635,7 @@ class ChromeContentBrowserClient : public content::ContentBrowserClient { content::WebContents* web_contents) override; void RemovePresentationObserver(content::PresentationObserver* observer, content::WebContents* web_contents) override; - std::vector<std::unique_ptr<content::NavigationThrottle>> - CreateThrottlesForNavigation( + void CreateThrottlesForNavigation( content::NavigationThrottleRegistry& registry) override; std::vector<std::unique_ptr<content::CommitDeferringCondition>> CreateCommitDeferringConditionsForNavigation( diff --git a/chrome/browser/extensions/extension_navigation_throttle_unittest.cc b/chrome/browser/extensions/extension_navigation_throttle_unittest.cc index f0f03d18548d2..806a514c2915d 100644 --- a/chrome/browser/extensions/extension_navigation_throttle_unittest.cc +++ b/chrome/browser/extensions/extension_navigation_throttle_unittest.cc @@ -46,11 +46,10 @@ class MockBrowserClient : public content::ContentBrowserClient { // Only construct an ExtensionNavigationThrottle so that we can test it in // isolation. - std::vector<std::unique_ptr<NavigationThrottle>> CreateThrottlesForNavigation( + void CreateThrottlesForNavigation( content::NavigationThrottleRegistry& registry) override { registry.AddThrottle(std::make_unique<ExtensionNavigationThrottle>( ®istry.GetNavigationHandle())); - return {}; } }; diff --git a/chromecast/browser/cast_content_browser_client.cc b/chromecast/browser/cast_content_browser_client.cc index af91de23084b0..67198aec1d5eb 100644 --- a/chromecast/browser/cast_content_browser_client.cc +++ b/chromecast/browser/cast_content_browser_client.cc @@ -809,8 +809,7 @@ CastContentBrowserClient::CreateCrashHandlerHost( } #endif // BUILDFLAG(IS_ANDROID) -std::vector<std::unique_ptr<content::NavigationThrottle>> -CastContentBrowserClient::CreateThrottlesForNavigation( +void CastContentBrowserClient::CreateThrottlesForNavigation( content::NavigationThrottleRegistry& registry) { if (chromecast::IsFeatureEnabled(kEnableGeneralAudienceBrowsing)) { registry.AddThrottle( @@ -818,8 +817,6 @@ CastContentBrowserClient::CreateThrottlesForNavigation( ®istry.GetNavigationHandle(), general_audience_browsing_service_.get())); } - - return {}; } void CastContentBrowserClient::RegisterNonNetworkSubresourceURLLoaderFactories( diff --git a/chromecast/browser/cast_content_browser_client.h b/chromecast/browser/cast_content_browser_client.h index bec64fa7de47b..e4e91e64afc32 100644 --- a/chromecast/browser/cast_content_browser_client.h +++ b/chromecast/browser/cast_content_browser_client.h @@ -241,8 +241,7 @@ class CastContentBrowserClient std::unique_ptr<content::NavigationUIData> GetNavigationUIData( content::NavigationHandle* navigation_handle) override; bool ShouldEnableStrictSiteIsolation() override; - std::vector<std::unique_ptr<content::NavigationThrottle>> - CreateThrottlesForNavigation( + void CreateThrottlesForNavigation( content::NavigationThrottleRegistry& registry) override; void RegisterNonNetworkSubresourceURLLoaderFactories( int render_process_id, diff --git a/components/error_page/content/browser/net_error_auto_reloader_browsertest.cc b/components/error_page/content/browser/net_error_auto_reloader_browsertest.cc index eec3b072a7426..819a3b297fff2 100644 --- a/components/error_page/content/browser/net_error_auto_reloader_browsertest.cc +++ b/components/error_page/content/browser/net_error_auto_reloader_browsertest.cc @@ -11,6 +11,7 @@ #include "base/memory/raw_ptr.h" #include "base/test/bind.h" #include "content/public/browser/navigation_controller.h" +#include "content/public/browser/navigation_throttle_registry.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_observer.h" #include "content/public/common/content_features.h" @@ -43,8 +44,9 @@ class NetErrorUrlInterceptor { interceptor_(base::BindLambdaForTesting( [this, error](content::URLLoaderInterceptor::RequestParams* params) { - if (params->url_request.url != url_) + if (params->url_request.url != url_) { return false; + } network::URLLoaderCompletionStatus status; status.error_code = error; params->client->OnComplete(status); @@ -133,15 +135,17 @@ class DeferNextNavigationThrottleInserter // content::WebContentsObserver: void DidFinishNavigation(content::NavigationHandle* handle) override { DCHECK(throttle_); - if (handle == throttle_->navigation_handle()) + if (handle == throttle_->navigation_handle()) { finish_wait_loop_.Quit(); + } } private: std::unique_ptr<content::NavigationThrottle> MaybeCreateThrottle( content::NavigationHandle* handle) { - if (throttle_) + if (throttle_) { return nullptr; + } auto throttle = std::make_unique<DeferringThrottle>( handle, defer_wait_loop_.QuitClosure()); @@ -170,15 +174,10 @@ class NetErrorAutoReloaderBrowserTest : public content::ContentBrowserTest { content::ShellContentBrowserClient::Get() ->set_create_throttles_for_navigation_callback(base::BindRepeating( - [](content::NavigationHandle* handle) - -> std::vector<std::unique_ptr<content::NavigationThrottle>> { - std::vector<std::unique_ptr<content::NavigationThrottle>> - throttles; - auto throttle = - NetErrorAutoReloader::MaybeCreateThrottleFor(handle); - if (throttle) - throttles.push_back(std::move(throttle)); - return throttles; + [](content::NavigationThrottleRegistry& registry) -> void { + registry.MaybeAddThrottle( + NetErrorAutoReloader::MaybeCreateThrottleFor( + ®istry.GetNavigationHandle())); })); } @@ -193,8 +192,9 @@ class NetErrorAutoReloaderBrowserTest : public content::ContentBrowserTest { std::optional<base::TimeDelta> GetCurrentAutoReloadDelay() { const std::optional<base::OneShotTimer>& timer = GetAutoReloader()->next_reload_timer_for_testing(); - if (!timer) + if (!timer) { return std::nullopt; + } return timer->GetCurrentDelay(); } @@ -239,8 +239,9 @@ class NetErrorAutoReloaderBrowserTest : public content::ContentBrowserTest { error_page::NetErrorAutoReloader::FromWebContents(wc); std::optional<base::OneShotTimer>& timer = reloader->next_reload_timer_for_testing(); - if (timer && timer->IsRunning()) + if (timer && timer->IsRunning()) { timer->FireNow(); + } } static void SimulateNetworkGoingOnline(content::WebContents* wc) { diff --git a/components/page_load_metrics/browser/page_load_metrics_test_content_browser_client.cc b/components/page_load_metrics/browser/page_load_metrics_test_content_browser_client.cc index 2ec156b8ec843..334957334abb1 100644 --- a/components/page_load_metrics/browser/page_load_metrics_test_content_browser_client.cc +++ b/components/page_load_metrics/browser/page_load_metrics_test_content_browser_client.cc @@ -19,15 +19,13 @@ PageLoadMetricsTestContentBrowserClient:: PageLoadMetricsTestContentBrowserClient:: ~PageLoadMetricsTestContentBrowserClient() = default; -std::vector<std::unique_ptr<content::NavigationThrottle>> -PageLoadMetricsTestContentBrowserClient::CreateThrottlesForNavigation( +void PageLoadMetricsTestContentBrowserClient::CreateThrottlesForNavigation( content::NavigationThrottleRegistry& registry) { content::NavigationHandle& navigation_handle = registry.GetNavigationHandle(); if (navigation_handle.IsInMainFrame()) { registry.AddThrottle(page_load_metrics::MetricsNavigationThrottle::Create( &navigation_handle)); } - return {}; } } // namespace page_load_metrics diff --git a/components/page_load_metrics/browser/page_load_metrics_test_content_browser_client.h b/components/page_load_metrics/browser/page_load_metrics_test_content_browser_client.h index c2159944beeea..7613343be2d0e 100644 --- a/components/page_load_metrics/browser/page_load_metrics_test_content_browser_client.h +++ b/components/page_load_metrics/browser/page_load_metrics_test_content_browser_client.h @@ -24,8 +24,7 @@ class PageLoadMetricsTestContentBrowserClient ~PageLoadMetricsTestContentBrowserClient() override; // content::ContentBrowserClient: - std::vector<std::unique_ptr<content::NavigationThrottle>> - CreateThrottlesForNavigation( + void CreateThrottlesForNavigation( content::NavigationThrottleRegistry& registry) override; }; diff --git a/content/browser/back_forward_cache_internal_browsertest.cc b/content/browser/back_forward_cache_internal_browsertest.cc index 87ec41154f162..85a599df5b495 100644 --- a/content/browser/back_forward_cache_internal_browsertest.cc +++ b/content/browser/back_forward_cache_internal_browsertest.cc @@ -3516,10 +3516,9 @@ IN_PROC_BROWSER_TEST_F(BackForwardCacheBrowserTest, NoThrottlesOnCacheRestore) { // NavigationThrottles. content::ShellContentBrowserClient::Get() ->set_create_throttles_for_navigation_callback(base::BindLambdaForTesting( - [&did_register_throttles](content::NavigationHandle* handle) - -> std::vector<std::unique_ptr<content::NavigationThrottle>> { + [&did_register_throttles]( + content::NavigationThrottleRegistry& registry) -> void { did_register_throttles = true; - return std::vector<std::unique_ptr<content::NavigationThrottle>>(); })); // 2) Navigate to B. diff --git a/content/browser/preloading/prerender/prerender_browsertest.cc b/content/browser/preloading/prerender/prerender_browsertest.cc index e8d7389535619..1fd69fcec3bf5 100644 --- a/content/browser/preloading/prerender/prerender_browsertest.cc +++ b/content/browser/preloading/prerender/prerender_browsertest.cc @@ -4101,8 +4101,9 @@ class RedirectChainObserver : public WebContentsObserver { private: void DidFinishNavigation(NavigationHandle* handle) override { - if (handle->GetURL() != url_) + if (handle->GetURL() != url_) { return; + } redirect_chain_ = handle->GetRedirectChain(); } @@ -5409,8 +5410,9 @@ class IsActivationObserver : public WebContentsObserver { private: void DidStartNavigation(NavigationHandle* handle) override { - if (handle->GetURL() != url_) + if (handle->GetURL() != url_) { return; + } did_navigate_ = true; was_activation_ = handle->IsPrerenderedPageActivation(); } @@ -5470,20 +5472,16 @@ IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, ActivationDoesntRunThrottles) { // WillStartRequest into all new navigations. ShellContentBrowserClient::Get() ->set_create_throttles_for_navigation_callback(base::BindLambdaForTesting( - [&throttle](NavigationHandle* handle) - -> std::vector<std::unique_ptr<NavigationThrottle>> { - std::vector<std::unique_ptr<NavigationThrottle>> throttles; - - auto throttle_ptr = - std::make_unique<TestNavigationThrottle>(handle); + [&throttle](NavigationThrottleRegistry& registry) -> void { + auto throttle_ptr = std::make_unique<TestNavigationThrottle>( + ®istry.GetNavigationHandle()); CHECK(!throttle); throttle = throttle_ptr.get(); throttle_ptr->SetResponse( TestNavigationThrottle::WILL_START_REQUEST, TestNavigationThrottle::SYNCHRONOUS, NavigationThrottle::DEFER); - throttles.push_back(std::move(throttle_ptr)); - return throttles; + registry.AddThrottle(std::move(throttle_ptr)); })); // Start a prerender and ensure that a NavigationThrottle can defer the @@ -5768,13 +5766,11 @@ IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, // before PrerenderSubframeNavigationThrottle. ShellContentBrowserClient::Get() ->set_create_throttles_for_navigation_callback(base::BindLambdaForTesting( - [](NavigationHandle* handle) - -> std::vector<std::unique_ptr<NavigationThrottle>> { - std::vector<std::unique_ptr<NavigationThrottle>> throttles; - throttles.push_back( + [](NavigationThrottleRegistry& registry) -> void { + registry.AddThrottle( std::make_unique< - TestPrerenderCancellerSubframeNavigationThrottle>(handle)); - return throttles; + TestPrerenderCancellerSubframeNavigationThrottle>( + ®istry.GetNavigationHandle())); })); // Use ExecuteScriptAsync instead of EvalJs as inserted cross-origin iframe @@ -6654,8 +6650,9 @@ IN_PROC_BROWSER_TEST_P(SSLPrerenderBrowserTest, // Skip the test when the block type is kCertError. With the type, this test // times out due to https://crbug.com/1311887. // TODO(crbug.com/40220378): Enable the test with kCertError. - if (GetParam() == SSLPrerenderTestErrorBlockType::kCertError) + if (GetParam() == SSLPrerenderTestErrorBlockType::kCertError) { return; + } // Load an initial page and register a service worker that intercepts // resources requests. @@ -8061,8 +8058,9 @@ IN_PROC_BROWSER_TEST_F(PrerenderSequentialPrerenderingBrowserTest, // Confirm that all the other prerender hosts are successfully cancelled. for (auto& url : prerender_urls) { - if (url == prerender_urls[0]) + if (url == prerender_urls[0]) { continue; + } EXPECT_TRUE(GetHostForUrl(url).is_null()); } @@ -11999,10 +11997,11 @@ class FrameDisplayStateChangedObserver : public WebContentsObserver { void FrameDisplayStateChanged(RenderFrameHost* host, bool is_display_none) override { if (host == target_host_) { - if (callback_) + if (callback_) { std::move(callback_).Run(); - else + } else { changed_count_++; + } } } @@ -12509,8 +12508,9 @@ class PrerenderRequestHeadersBrowserTest : public PrerenderBrowserTest { // Note: Checking the origin of `request.GetURL()` doesn't work here because // the host part of the URL is translated (e.g., "a.test" to "127.0.0.1") // based on the host resolver rule before this point. - if (request.relative_url.find("cors") == std::string::npos) + if (request.relative_url.find("cors") == std::string::npos) { return nullptr; + } // Serves a fake response with the ACAO header. auto response = std::make_unique<net::test_server::BasicHttpResponse>(); @@ -13257,8 +13257,9 @@ IN_PROC_BROWSER_TEST_F(PrerenderFencedFrameBrowserTest, // child frames. size_t child_frame_count = 0; prerendered_rfh->ForEachRenderFrameHostImpl([&](RenderFrameHostImpl* rfh) { - if (rfh != prerendered_rfh) + if (rfh != prerendered_rfh) { child_frame_count++; + } }); EXPECT_EQ(0lu, child_frame_count); @@ -13444,8 +13445,9 @@ class PrerenderClientHintsBrowserTest : public PrerenderBrowserTest { static std::unique_ptr<net::test_server::HttpResponse> HandleRequest( const net::test_server::HttpRequest& request) { - if (request.relative_url.find("acceptch") == std::string::npos) + if (request.relative_url.find("acceptch") == std::string::npos) { return nullptr; + } // Serve a response indicating clients to provide full version of UA. auto response = std::make_unique<net::test_server::BasicHttpResponse>(); diff --git a/content/browser/renderer_host/navigation_request_browsertest.cc b/content/browser/renderer_host/navigation_request_browsertest.cc index 552a48132aef3..f16f62ca5a15b 100644 --- a/content/browser/renderer_host/navigation_request_browsertest.cc +++ b/content/browser/renderer_host/navigation_request_browsertest.cc @@ -272,32 +272,36 @@ class TestNavigationThrottleInstaller : public WebContentsObserver { TestNavigationThrottle* navigation_throttle() { return navigation_throttle_; } void WaitForThrottleWillStart() { - if (will_start_called_) + if (will_start_called_) { return; + } will_start_loop_runner_ = new MessageLoopRunner(); will_start_loop_runner_->Run(); will_start_loop_runner_ = nullptr; } void WaitForThrottleWillRedirect() { - if (will_redirect_called_) + if (will_redirect_called_) { return; + } will_redirect_loop_runner_ = new MessageLoopRunner(); will_redirect_loop_runner_->Run(); will_redirect_loop_runner_ = nullptr; } void WaitForThrottleWillFail() { - if (will_fail_called_) + if (will_fail_called_) { return; + } will_fail_loop_runner_ = new MessageLoopRunner(); will_fail_loop_runner_->Run(); will_fail_loop_runner_ = nullptr; } void WaitForThrottleWillProcess() { - if (will_process_called_) + if (will_process_called_) { return; + } will_process_loop_runner_ = new MessageLoopRunner(); will_process_loop_runner_->Run(); will_process_loop_runner_ = nullptr; @@ -314,10 +318,11 @@ class TestNavigationThrottleInstaller : public WebContentsObserver { void Continue(NavigationThrottle::ThrottleCheckResult result) { ASSERT_NE(NavigationThrottle::DEFER, result.action()); - if (result.action() == NavigationThrottle::PROCEED) + if (result.action() == NavigationThrottle::PROCEED) { navigation_throttle()->ResumeNavigation(); - else + } else { navigation_throttle()->CancelNavigation(result); + } } int will_start_called() { return will_start_called_; } @@ -333,26 +338,30 @@ class TestNavigationThrottleInstaller : public WebContentsObserver { protected: virtual void DidCallWillStartRequest() { will_start_called_++; - if (will_start_loop_runner_) + if (will_start_loop_runner_) { will_start_loop_runner_->Quit(); + } } virtual void DidCallWillRedirectRequest() { will_redirect_called_++; - if (will_redirect_loop_runner_) + if (will_redirect_loop_runner_) { will_redirect_loop_runner_->Quit(); + } } virtual void DidCallWillFailRequest() { will_fail_called_++; - if (will_fail_loop_runner_) + if (will_fail_loop_runner_) { will_fail_loop_runner_->Quit(); + } } virtual void DidCallWillProcessResponse() { will_process_called_++; - if (will_process_loop_runner_) + if (will_process_loop_runner_) { will_process_loop_runner_->Quit(); + } } virtual void DidCallWillCommitWithoutUrlLoader() { @@ -365,8 +374,9 @@ class TestNavigationThrottleInstaller : public WebContentsObserver { private: void DidStartNavigation(NavigationHandle* handle) override { if (!expected_start_url_.is_empty() && - handle->GetURL() != expected_start_url_) + handle->GetURL() != expected_start_url_) { return; + } std::unique_ptr<NavigationThrottle> throttle(new TestNavigationThrottle( handle, will_start_result_, will_redirect_result_, will_fail_result_, @@ -391,11 +401,13 @@ class TestNavigationThrottleInstaller : public WebContentsObserver { } void DidFinishNavigation(NavigationHandle* handle) override { - if (!navigation_throttle_) + if (!navigation_throttle_) { return; + } - if (handle == navigation_throttle_->navigation_handle()) + if (handle == navigation_throttle_->navigation_handle()) { navigation_throttle_ = nullptr; + } } NavigationThrottle::ThrottleCheckResult will_start_result_; @@ -2663,19 +2675,17 @@ IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest, // |client_throttle| when its registered. content::ShellContentBrowserClient::Get() ->set_create_throttles_for_navigation_callback(base::BindLambdaForTesting( - [&client_throttle](content::NavigationHandle* handle) - -> std::vector<std::unique_ptr<content::NavigationThrottle>> { - std::vector<std::unique_ptr<content::NavigationThrottle>> throttles; + [&client_throttle]( + content::NavigationThrottleRegistry& registry) -> void { std::unique_ptr<TestNavigationThrottle> throttle( new TestNavigationThrottle( - handle, NavigationThrottle::DEFER, + ®istry.GetNavigationHandle(), NavigationThrottle::DEFER, NavigationThrottle::PROCEED, NavigationThrottle::PROCEED, NavigationThrottle::PROCEED, NavigationThrottle::PROCEED, base::DoNothing(), base::DoNothing(), base::DoNothing(), base::DoNothing(), base::DoNothing())); client_throttle = throttle.get(); - throttles.push_back(std::move(throttle)); - return throttles; + registry.AddThrottle(std::move(throttle)); })); // Add another similar throttle using the installer which will use @@ -2938,8 +2948,9 @@ IN_PROC_BROWSER_TEST_F(NavigationRequestBrowserTest_IsolateAllSites, auto add_suffix = [&names](std::vector<std::string> suffixes) { size_t original_size = names.size(); for (size_t i = 0; i < original_size; i++) { - for (const std::string& suffix : suffixes) + for (const std::string& suffix : suffixes) { names.push_back(names[i] + suffix); + } } }; add_suffix({kProcessSuffixes.at(process_type)}); @@ -4493,9 +4504,9 @@ IN_PROC_BROWSER_TEST_P(NavigationRequestMPArchBrowserTest, DCHECK_EQ(navigation_handle->GetNavigatingFrameType(), GetParam() == TestMPArchType::kPrerender ? FrameType::kPrerenderMainFrame - : GetParam() == TestMPArchType::kFencedFrame - ? FrameType::kFencedFrameRoot - : FrameType::kPrimaryMainFrame); + : GetParam() == TestMPArchType::kFencedFrame + ? FrameType::kFencedFrameRoot + : FrameType::kPrimaryMainFrame); EXPECT_FALSE(navigation_handle->ShouldUpdateHistory()); })); }; @@ -4689,14 +4700,12 @@ IN_PROC_BROWSER_TEST_F(NavigationRequestResponseBodyBrowserTest, Received) { // to this throttle in `client_throttle` on registration. content::ShellContentBrowserClient::Get() ->set_create_throttles_for_navigation_callback(base::BindLambdaForTesting( - [&client_throttle](content::NavigationHandle* handle) - -> std::vector<std::unique_ptr<content::NavigationThrottle>> { - std::vector<std::unique_ptr<content::NavigationThrottle>> throttles; - auto throttle = - std::make_unique<ResponseBodyNavigationThrottle>(handle); + [&client_throttle]( + content::NavigationThrottleRegistry& registry) -> void { + auto throttle = std::make_unique<ResponseBodyNavigationThrottle>( + ®istry.GetNavigationHandle()); client_throttle = throttle.get(); - throttles.push_back(std::move(throttle)); - return throttles; + registry.AddThrottle(std::move(throttle)); })); // Start navigating. @@ -4732,14 +4741,12 @@ IN_PROC_BROWSER_TEST_F(NavigationRequestResponseBodyBrowserTest, // to this throttle in `client_throttle` on registration. content::ShellContentBrowserClient::Get() ->set_create_throttles_for_navigation_callback(base::BindLambdaForTesting( - [&client_throttle](content::NavigationHandle* handle) - -> std::vector<std::unique_ptr<content::NavigationThrottle>> { - std::vector<std::unique_ptr<content::NavigationThrottle>> throttles; - auto throttle = - std::make_unique<ResponseBodyNavigationThrottle>(handle); + [&client_throttle]( + content::NavigationThrottleRegistry& registry) -> void { + auto throttle = std::make_unique<ResponseBodyNavigationThrottle>( + ®istry.GetNavigationHandle()); client_throttle = throttle.get(); - throttles.push_back(std::move(throttle)); - return throttles; + registry.AddThrottle(std::move(throttle)); })); // Start navigating. @@ -4775,14 +4782,12 @@ IN_PROC_BROWSER_TEST_F(NavigationRequestResponseBodyBrowserTest, // to this throttle in `client_throttle` on registration. content::ShellContentBrowserClient::Get() ->set_create_throttles_for_navigation_callback(base::BindLambdaForTesting( - [&client_throttle](content::NavigationHandle* handle) - -> std::vector<std::unique_ptr<content::NavigationThrottle>> { - std::vector<std::unique_ptr<content::NavigationThrottle>> throttles; - auto throttle = - std::make_unique<ResponseBodyNavigationThrottle>(handle); + [&client_throttle]( + content::NavigationThrottleRegistry& registry) -> void { + auto throttle = std::make_unique<ResponseBodyNavigationThrottle>( + ®istry.GetNavigationHandle()); client_throttle = throttle.get(); - throttles.push_back(std::move(throttle)); - return throttles; + registry.AddThrottle(std::move(throttle)); })); // Start navigating to a page with a large body (>5 million characters). diff --git a/content/browser/renderer_host/navigation_request_unittest.cc b/content/browser/renderer_host/navigation_request_unittest.cc index 10505c2e5a209..d4a96ab75aeeb 100644 --- a/content/browser/renderer_host/navigation_request_unittest.cc +++ b/content/browser/renderer_host/navigation_request_unittest.cc @@ -592,13 +592,11 @@ class GetRenderFrameHostOnFailureNavigationThrottle }; class ThrottleTestContentBrowserClient : public ContentBrowserClient { - std::vector<std::unique_ptr<NavigationThrottle>> CreateThrottlesForNavigation( + void CreateThrottlesForNavigation( NavigationThrottleRegistry& registry) override { - std::vector<std::unique_ptr<NavigationThrottle>> throttle; registry.AddThrottle( std::make_unique<GetRenderFrameHostOnFailureNavigationThrottle>( ®istry.GetNavigationHandle())); - return throttle; } }; diff --git a/content/browser/renderer_host/navigation_throttle_runner.cc b/content/browser/renderer_host/navigation_throttle_runner.cc index 455a6c9a7cc72..b4f7e218b174a 100644 --- a/content/browser/renderer_host/navigation_throttle_runner.cc +++ b/content/browser/renderer_host/navigation_throttle_runner.cc @@ -218,16 +218,7 @@ void NavigationThrottleRunner::RegisterNavigationThrottles() { // NavigationRequest. NavigationRequest* request = static_cast<NavigationRequest*>(delegate_); - std::vector<std::unique_ptr<NavigationThrottle>> throttles_under_migration = - request->GetDelegate()->CreateThrottlesForNavigation(*this); - // TODO(https://crbug.com/412524375): Remove `throttles_under_migration` and - // following code to move them to the member variable. When the call returns - // above, migrated throttles are already registered in `throttles_` via the - // new NavigationThrottleRegistry interface. So, we cannot assign the returned - // vector directly to `throttles_`. - throttles_.insert(throttles_.end(), - std::make_move_iterator(throttles_under_migration.begin()), - std::make_move_iterator(throttles_under_migration.end())); + request->GetDelegate()->CreateThrottlesForNavigation(*this); // Check for renderer-inititated main frame navigations to blocked URL schemes // (data, filesystem). This is done early as it may block the main frame diff --git a/content/browser/renderer_host/navigator_delegate.h b/content/browser/renderer_host/navigator_delegate.h index dd41492bee1e9..645edb8ab7325 100644 --- a/content/browser/renderer_host/navigator_delegate.h +++ b/content/browser/renderer_host/navigator_delegate.h @@ -120,12 +120,8 @@ class NavigatorDelegate { // Returns the NavigationThrottles to add to this navigation. Normally these // are defined by the content/ embedder, except in the case of interstitials // where no NavigationThrottles are added to the navigation. - // TODO(https://crbug.com/412524375): New code should add a NavigationThrottle - // via the given `registry` instead of returning a NavigationThrottle from - // this method. Once all existing NavigationThrottles are migrated, the - // returned type will be changed to `void`. - virtual std::vector<std::unique_ptr<NavigationThrottle>> - CreateThrottlesForNavigation(NavigationThrottleRegistry& registry) = 0; + virtual void CreateThrottlesForNavigation( + NavigationThrottleRegistry& registry) = 0; // Returns commit deferring conditions to add to this navigation. virtual std::vector<std::unique_ptr<CommitDeferringCondition>> diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc index 45b84cb6a555e..6d39dcc1addc5 100644 --- a/content/browser/web_contents/web_contents_impl.cc +++ b/content/browser/web_contents/web_contents_impl.cc @@ -9534,13 +9534,12 @@ bool WebContentsImpl::IsHidden() { return GetPageVisibilityState() == PageVisibilityState::kHidden; } -std::vector<std::unique_ptr<NavigationThrottle>> -WebContentsImpl::CreateThrottlesForNavigation( +void WebContentsImpl::CreateThrottlesForNavigation( NavigationThrottleRegistry& registry) { OPTIONAL_TRACE_EVENT1("content", "WebContentsImpl::CreateThrottlesForNavigation", "navigation", registry.GetNavigationHandle()); - return GetContentClient()->browser()->CreateThrottlesForNavigation(registry); + GetContentClient()->browser()->CreateThrottlesForNavigation(registry); } std::vector<std::unique_ptr<CommitDeferringCondition>> diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h index eabf30ffd32ae..98fdc7f788b38 100644 --- a/content/browser/web_contents/web_contents_impl.h +++ b/content/browser/web_contents/web_contents_impl.h @@ -1067,7 +1067,7 @@ class CONTENT_EXPORT WebContentsImpl bool is_outermost_main_frame_navigation) override; const blink::UserAgentOverride& GetUserAgentOverride( FrameTree& frame_tree) override; - std::vector<std::unique_ptr<NavigationThrottle>> CreateThrottlesForNavigation( + void CreateThrottlesForNavigation( NavigationThrottleRegistry& registry) override; std::vector<std::unique_ptr<CommitDeferringCondition>> CreateDeferringConditionsForNavigationCommit( diff --git a/content/public/browser/content_browser_client.cc b/content/public/browser/content_browser_client.cc index 1f5468c6f81db..3c8b3320d6017 100644 --- a/content/public/browser/content_browser_client.cc +++ b/content/public/browser/content_browser_client.cc @@ -997,11 +997,8 @@ void ContentBrowserClient::OpenURL( std::move(callback).Run(nullptr); } -std::vector<std::unique_ptr<NavigationThrottle>> -content::ContentBrowserClient::CreateThrottlesForNavigation( - NavigationThrottleRegistry& registry) { - return std::vector<std::unique_ptr<NavigationThrottle>>(); -} +void ContentBrowserClient::CreateThrottlesForNavigation( + NavigationThrottleRegistry& registry) {} std::vector<std::unique_ptr<CommitDeferringCondition>> ContentBrowserClient::CreateCommitDeferringConditionsForNavigation( diff --git a/content/public/browser/content_browser_client.h b/content/public/browser/content_browser_client.h index a0f6c7e63a32d..afc935255180e 100644 --- a/content/public/browser/content_browser_client.h +++ b/content/public/browser/content_browser_client.h @@ -1705,12 +1705,8 @@ class CONTENT_EXPORT ContentBrowserClient { // navigations; they are specifically not run for page activating navigations // such as prerender activation and back-forward cache restores or for // navigations that don't use a URLLoader like same-document navigations. - // TODO(https://crbug.com/412524375): New code should add a NavigationThrottle - // via the given `registry` instead of returning a NavigationThrottle from - // this method. Once all existing NavigationThrottles are migrated, the - // returned type will be changed to `void`. - virtual std::vector<std::unique_ptr<NavigationThrottle>> - CreateThrottlesForNavigation(NavigationThrottleRegistry& registry); + virtual void CreateThrottlesForNavigation( + NavigationThrottleRegistry& registry); // Allows the embedder to register one or more CommitDeferringConditions for // the navigation indicated by |navigation_handle|. A diff --git a/content/shell/browser/shell_content_browser_client.cc b/content/shell/browser/shell_content_browser_client.cc index e9a1782479365..cdf86904660d3 100644 --- a/content/shell/browser/shell_content_browser_client.cc +++ b/content/shell/browser/shell_content_browser_client.cc @@ -693,16 +693,11 @@ void ShellContentBrowserClient::OpenURL( ->web_contents()); } -std::vector<std::unique_ptr<NavigationThrottle>> -ShellContentBrowserClient::CreateThrottlesForNavigation( +void ShellContentBrowserClient::CreateThrottlesForNavigation( NavigationThrottleRegistry& registry) { - std::vector<std::unique_ptr<NavigationThrottle>> empty_throttles; if (create_throttles_for_navigation_callback_) { - // TODO(https://crbug.com/412524375): NavigationThrottleRegistry migration. - return create_throttles_for_navigation_callback_.Run( - ®istry.GetNavigationHandle()); + create_throttles_for_navigation_callback_.Run(registry); } - return empty_throttles; } std::unique_ptr<LoginDelegate> ShellContentBrowserClient::CreateLoginDelegate( diff --git a/content/shell/browser/shell_content_browser_client.h b/content/shell/browser/shell_content_browser_client.h index 2730cbce08509..e608835c3d16f 100644 --- a/content/shell/browser/shell_content_browser_client.h +++ b/content/shell/browser/shell_content_browser_client.h @@ -125,7 +125,7 @@ class ShellContentBrowserClient : public ContentBrowserClient { void OpenURL(SiteInstance* site_instance, const OpenURLParams& params, base::OnceCallback<void(WebContents*)> callback) override; - std::vector<std::unique_ptr<NavigationThrottle>> CreateThrottlesForNavigation( + void CreateThrottlesForNavigation( NavigationThrottleRegistry& registry) override; std::unique_ptr<LoginDelegate> CreateLoginDelegate( const net::AuthChallengeInfo& auth_info, @@ -218,8 +218,8 @@ class ShellContentBrowserClient : public ContentBrowserClient { std::move(url_loader_factory_params_callback); } void set_create_throttles_for_navigation_callback( - base::RepeatingCallback<std::vector<std::unique_ptr<NavigationThrottle>>( - NavigationHandle*)> create_throttles_for_navigation_callback) { + base::RepeatingCallback<void(NavigationThrottleRegistry&)> + create_throttles_for_navigation_callback) { create_throttles_for_navigation_callback_ = create_throttles_for_navigation_callback; } @@ -271,8 +271,7 @@ class ShellContentBrowserClient : public ContentBrowserClient { bool is_for_isolated_world, bool is_for_service_worker)> url_loader_factory_params_callback_; - base::RepeatingCallback<std::vector<std::unique_ptr<NavigationThrottle>>( - NavigationHandle*)> + base::RepeatingCallback<void(NavigationThrottleRegistry&)> create_throttles_for_navigation_callback_; base::RepeatingCallback<void(blink::web_pref::WebPreferences*)> override_web_preferences_callback_; diff --git a/content/web_test/browser/web_test_content_browser_client.cc b/content/web_test/browser/web_test_content_browser_client.cc index e5f7596c1b3e5..7f265db63f3fa 100644 --- a/content/web_test/browser/web_test_content_browser_client.cc +++ b/content/web_test/browser/web_test_content_browser_client.cc @@ -420,21 +420,14 @@ void WebTestContentBrowserClient::OverrideWebPreferences( WebTestControlHost::Get()->OverrideWebPreferences(prefs); } -std::vector<std::unique_ptr<content::NavigationThrottle>> -WebTestContentBrowserClient::CreateThrottlesForNavigation( +void WebTestContentBrowserClient::CreateThrottlesForNavigation( content::NavigationThrottleRegistry& registry) { - content::NavigationHandle* navigation_handle = - ®istry.GetNavigationHandle(); - std::vector<std::unique_ptr<content::NavigationThrottle>> throttles = - ShellContentBrowserClient::CreateThrottlesForNavigation(registry); - - throttles.push_back(std::make_unique<WebTestOriginTrialThrottle>( - navigation_handle, navigation_handle->GetWebContents() - ->GetBrowserContext() - ->GetOriginTrialsControllerDelegate())); - - // TODO(https://crbug.com/412524375): NavigationThrottleRegistry migration. - return throttles; + ShellContentBrowserClient::CreateThrottlesForNavigation(registry); + content::NavigationHandle& navigation_handle = registry.GetNavigationHandle(); + registry.AddThrottle(std::make_unique<WebTestOriginTrialThrottle>( + &navigation_handle, navigation_handle.GetWebContents() + ->GetBrowserContext() + ->GetOriginTrialsControllerDelegate())); } void WebTestContentBrowserClient::AppendExtraCommandLineSwitches( diff --git a/content/web_test/browser/web_test_content_browser_client.h b/content/web_test/browser/web_test_content_browser_client.h index e4eaba65b2526..b50d5628cfe6d 100644 --- a/content/web_test/browser/web_test_content_browser_client.h +++ b/content/web_test/browser/web_test_content_browser_client.h @@ -75,8 +75,7 @@ class WebTestContentBrowserClient : public ShellContentBrowserClient { void OverrideWebPreferences(WebContents* web_contents, SiteInstance& main_frame_site, blink::web_pref::WebPreferences* prefs) override; - std::vector<std::unique_ptr<content::NavigationThrottle>> - CreateThrottlesForNavigation( + void CreateThrottlesForNavigation( content::NavigationThrottleRegistry& registry) override; void AppendExtraCommandLineSwitches(base::CommandLine* command_line, int child_process_id) override; diff --git a/extensions/shell/browser/shell_content_browser_client.cc b/extensions/shell/browser/shell_content_browser_client.cc index 28e12bf58f876..fab3a409201ed 100644 --- a/extensions/shell/browser/shell_content_browser_client.cc +++ b/extensions/shell/browser/shell_content_browser_client.cc @@ -252,8 +252,7 @@ void ShellContentBrowserClient:: render_frame_host.GetGlobalId())); } -std::vector<std::unique_ptr<content::NavigationThrottle>> -ShellContentBrowserClient::CreateThrottlesForNavigation( +void ShellContentBrowserClient::CreateThrottlesForNavigation( content::NavigationThrottleRegistry& registry) { content::NavigationHandle& navigation_handle = registry.GetNavigationHandle(); @@ -265,7 +264,6 @@ ShellContentBrowserClient::CreateThrottlesForNavigation( } registry.MaybeAddThrottle( WebViewGuest::MaybeCreateNavigationThrottle(&navigation_handle)); - return {}; } std::unique_ptr<content::NavigationUIData> diff --git a/extensions/shell/browser/shell_content_browser_client.h b/extensions/shell/browser/shell_content_browser_client.h index 8da3baa67c27c..368f9a485ce33 100644 --- a/extensions/shell/browser/shell_content_browser_client.h +++ b/extensions/shell/browser/shell_content_browser_client.h @@ -89,8 +89,7 @@ class ShellContentBrowserClient : public content::ContentBrowserClient { void RegisterAssociatedInterfaceBindersForRenderFrameHost( content::RenderFrameHost& render_frame_host, blink::AssociatedInterfaceRegistry& associated_registry) override; - std::vector<std::unique_ptr<content::NavigationThrottle>> - CreateThrottlesForNavigation( + void CreateThrottlesForNavigation( content::NavigationThrottleRegistry& registry) override; std::unique_ptr<content::NavigationUIData> GetNavigationUIData( content::NavigationHandle* navigation_handle) override; diff --git a/fuchsia_web/webengine/browser/web_engine_content_browser_client.cc b/fuchsia_web/webengine/browser/web_engine_content_browser_client.cc index 80729d4dd33a3..c0bfdc6208cc0 100644 --- a/fuchsia_web/webengine/browser/web_engine_content_browser_client.cc +++ b/fuchsia_web/webengine/browser/web_engine_content_browser_client.cc @@ -310,8 +310,7 @@ base::OnceClosure WebEngineContentBrowserClient::SelectClientCertificate( return base::OnceClosure(); } -std::vector<std::unique_ptr<content::NavigationThrottle>> -WebEngineContentBrowserClient::CreateThrottlesForNavigation( +void WebEngineContentBrowserClient::CreateThrottlesForNavigation( content::NavigationThrottleRegistry& registry) { auto& navigation_handle = registry.GetNavigationHandle(); auto* frame_impl = @@ -334,8 +333,6 @@ WebEngineContentBrowserClient::CreateThrottlesForNavigation( navigation_handle.GetWebContents()->GetBrowserContext(), *explicit_sites_filter_error_page)); } - - return {}; } std::vector<std::unique_ptr<blink::URLLoaderThrottle>> diff --git a/fuchsia_web/webengine/browser/web_engine_content_browser_client.h b/fuchsia_web/webengine/browser/web_engine_content_browser_client.h index e887887204b33..057785c91d269 100644 --- a/fuchsia_web/webengine/browser/web_engine_content_browser_client.h +++ b/fuchsia_web/webengine/browser/web_engine_content_browser_client.h @@ -62,8 +62,7 @@ class WebEngineContentBrowserClient final net::SSLCertRequestInfo* cert_request_info, net::ClientCertIdentityList client_certs, std::unique_ptr<content::ClientCertificateDelegate> delegate) override; - std::vector<std::unique_ptr<content::NavigationThrottle>> - CreateThrottlesForNavigation( + void CreateThrottlesForNavigation( content::NavigationThrottleRegistry& registry) override; std::vector<std::unique_ptr<blink::URLLoaderThrottle>> CreateURLLoaderThrottles( diff --git a/headless/lib/browser/headless_content_browser_client.cc b/headless/lib/browser/headless_content_browser_client.cc index 12252b463e58a..0865a1159dbe1 100644 --- a/headless/lib/browser/headless_content_browser_client.cc +++ b/headless/lib/browser/headless_content_browser_client.cc @@ -453,21 +453,15 @@ void HeadlessContentBrowserClient::SessionEnding( #endif #if defined(HEADLESS_USE_POLICY) -std::vector<std::unique_ptr<content::NavigationThrottle>> -HeadlessContentBrowserClient::CreateThrottlesForNavigation( +void HeadlessContentBrowserClient::CreateThrottlesForNavigation( content::NavigationThrottleRegistry& registry) { - std::vector<std::unique_ptr<content::NavigationThrottle>> throttles; - // Avoid creating naviagtion throttle if preferences are not available // (happens in tests). content::NavigationHandle& handle = registry.GetNavigationHandle(); if (browser_->GetPrefs()) { - throttles.push_back(std::make_unique<PolicyBlocklistNavigationThrottle>( + registry.AddThrottle(std::make_unique<PolicyBlocklistNavigationThrottle>( &handle, handle.GetWebContents()->GetBrowserContext())); } - - // TODO(https://crbug.com/412524375): NavigationThrottleRegistry migration. - return throttles; } #endif // defined(HEADLESS_USE_POLICY) diff --git a/headless/lib/browser/headless_content_browser_client.h b/headless/lib/browser/headless_content_browser_client.h index c41428cd3efd0..9a23173a4f1d7 100644 --- a/headless/lib/browser/headless_content_browser_client.h +++ b/headless/lib/browser/headless_content_browser_client.h @@ -133,8 +133,7 @@ class HeadlessContentBrowserClient : public content::ContentBrowserClient { #endif #if defined(HEADLESS_USE_POLICY) - std::vector<std::unique_ptr<content::NavigationThrottle>> - CreateThrottlesForNavigation( + void CreateThrottlesForNavigation( content::NavigationThrottleRegistry& registry) override; #endif