0

NavigationThrottleRunner2: void CreateThrottlesForNavigation

Change the CreateThrottlesForNavigation's signature to deprecate
legacy registration approach, returning a vector.

Bug: 412524375
Change-Id: Ia7bc8b6ed7e8407ef3b0b3d2e559a7a1c12b5638
Cq-Include-Trybots: luci.chromium.try:android-cast-arm64-rel
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6493688
Reviewed-by: Nate Fischer <ntfschr@chromium.org>
Reviewed-by: Alex Moshchuk <alexmos@chromium.org>
Commit-Queue: Takashi Toyoshima <toyoshim@chromium.org>
Reviewed-by: Andrey Kosyakov <caseq@chromium.org>
Reviewed-by: Devlin Cronin <rdevlin.cronin@chromium.org>
Reviewed-by: Simeon Anfinrud <sanfin@chromium.org>
Reviewed-by: David Dorwin <ddorwin@chromium.org>
Reviewed-by: Nidhi Jaju <nidhijaju@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1456795}
This commit is contained in:
Takashi Toyoshima
2025-05-07 00:58:46 -07:00
committed by Chromium LUCI CQ
parent b736216d23
commit 2a7f8cc0a3
30 changed files with 132 additions and 192 deletions

@ -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>

@ -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(

@ -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>>

@ -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(

@ -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>(
&registry.GetNavigationHandle()));
return {};
}
};

@ -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(
&registry.GetNavigationHandle(),
general_audience_browsing_service_.get()));
}
return {};
}
void CastContentBrowserClient::RegisterNonNetworkSubresourceURLLoaderFactories(

@ -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,

@ -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(
&registry.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,9 +239,10 @@ 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) {
error_page::NetErrorAutoReloader* reloader =

@ -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

@ -24,8 +24,7 @@ class PageLoadMetricsTestContentBrowserClient
~PageLoadMetricsTestContentBrowserClient() override;
// content::ContentBrowserClient:
std::vector<std::unique_ptr<content::NavigationThrottle>>
CreateThrottlesForNavigation(
void CreateThrottlesForNavigation(
content::NavigationThrottleRegistry& registry) override;
};

@ -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.

@ -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>(
&registry.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>(
&registry.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,12 +11997,13 @@ 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_++;
}
}
}
int changed_count_ = 0;
const raw_ptr<RenderFrameHost> target_host_;
@ -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>();

@ -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,11 +318,12 @@ 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_; }
int will_redirect_called() { return will_redirect_called_; }
@ -333,27 +338,31 @@ 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() {
will_commit_without_url_loader_called_++;
@ -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,12 +401,14 @@ 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_;
NavigationThrottle::ThrottleCheckResult will_redirect_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,
&registry.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,9 +2948,10 @@ 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)});
add_suffix({kFrameSuffixes.at(frame_type)});
@ -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>(
&registry.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>(
&registry.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>(
&registry.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).

@ -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>(
&registry.GetNavigationHandle()));
return throttle;
}
};

@ -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()));
// Check for renderer-inititated main frame navigations to blocked URL schemes
// (data, filesystem). This is done early as it may block the main frame

@ -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>>

@ -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>>

@ -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(

@ -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(

@ -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

@ -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(
&registry.GetNavigationHandle());
create_throttles_for_navigation_callback_.Run(registry);
}
return empty_throttles;
}
std::unique_ptr<LoginDelegate> ShellContentBrowserClient::CreateLoginDelegate(

@ -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_;

@ -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 =
&registry.GetNavigationHandle();
std::vector<std::unique_ptr<content::NavigationThrottle>> throttles =
ShellContentBrowserClient::CreateThrottlesForNavigation(registry);
throttles.push_back(std::make_unique<WebTestOriginTrialThrottle>(
navigation_handle, navigation_handle->GetWebContents()
content::NavigationHandle& navigation_handle = registry.GetNavigationHandle();
registry.AddThrottle(std::make_unique<WebTestOriginTrialThrottle>(
&navigation_handle, navigation_handle.GetWebContents()
->GetBrowserContext()
->GetOriginTrialsControllerDelegate()));
// TODO(https://crbug.com/412524375): NavigationThrottleRegistry migration.
return throttles;
}
void WebTestContentBrowserClient::AppendExtraCommandLineSwitches(

@ -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;

@ -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>

@ -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;

@ -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>>

@ -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(

@ -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)

@ -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