Skip to content

Commit 865369f

Browse files
committed
[cr138] CreateThrottlesForNavigation takes a NavigationThrottleRegistry param now
Chromium change: https://source.chromium.org/chromium/chromium/src/+/be55153df12fd44a855f9db49f4656e624db3010 commit be55153df12fd44a855f9db49f4656e624db3010 Author: Takashi Toyoshima <[email protected]> Date: Fri May 2 11:13:52 2025 -0700 Reland "NavigationThrottleRunner2: content::NavigationThrottleRegistry" This is a reland of commit 06e076907244efc5fae5abe219b326238889071d The original change below didn't handle a chromecast specific subclass, and it caused a build failure on chromecast bot. Original change's description: > NavigationThrottleRunner2: content::NavigationThrottleRegistry > > This CL introduces a NavigationThrottleRegistry. > CreateThrottlesForNavigation() is changed to use this interface to > register a NavigationThrottle for a new navigation. > > We still handle the returned throttles vector to keep the legacy > interface available. But, once all the existing NavigationThrottle are > migrated to use the NavigationThrottleRegistry, we will remove the > legacy way, and the signature will be changed to return void. > > With this interface, we can implement several optimization step by step > without changing the existing API signature further more. For instance, > we can provide following features via the new registry interface; > - fast access paths to check navigation attributes > - per-event registration to optimize event loops > > Eventually, I will introduce a new NavigationThrottleRunner class. As we > want to share some common implementation among the original runner and > the new runner during the experiment, I will move the common logic to > this registry class and both runners will own it to share the > implementation. > > Essential changes are in the NavigationThrottleRunner, and > //content/public. Others are call side mechanical changes. > > Bug: 412524375 > Change-Id: Ifda11e0f5cf446135c9ab34df025573346c7639c > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6478853 > Reviewed-by: Nate Fischer <[email protected]> > Auto-Submit: Takashi Toyoshima <[email protected]> > Commit-Queue: Takashi Toyoshima <[email protected]> > Reviewed-by: Alex Moshchuk <[email protected]> > Cr-Commit-Position: refs/heads/main@{#1454542} Bug: 412524375
1 parent 9c38d30 commit 865369f

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

browser/brave_content_browser_client.cc

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,64 +1168,68 @@ bool BraveContentBrowserClient::HandleURLOverrideRewrite(
11681168

11691169
std::vector<std::unique_ptr<content::NavigationThrottle>>
11701170
BraveContentBrowserClient::CreateThrottlesForNavigation(
1171-
content::NavigationHandle* handle) {
1171+
NavigationThrottleRegistry& registry) {
11721172
std::vector<std::unique_ptr<content::NavigationThrottle>> throttles =
1173-
ChromeContentBrowserClient::CreateThrottlesForNavigation(handle);
1173+
ChromeContentBrowserClient::CreateThrottlesForNavigation(registry);
11741174

11751175
// inserting the navigation throttle at the fist position before any java
11761176
// navigation happens
1177+
content::NavigationHandle& navigation_handle = registry.GetNavigationHandle();
11771178
content::BrowserContext* context =
1178-
handle->GetWebContents()->GetBrowserContext();
1179+
navigation_handle.GetWebContents()->GetBrowserContext();
11791180

11801181
if (auto rewards_throttle = brave_rewards::RewardsProtocolNavigationThrottle::
1181-
MaybeCreateThrottleFor(handle)) {
1182+
MaybeCreateThrottleFor(navigation_handle)) {
11821183
throttles.insert(throttles.begin(), std::move(rewards_throttle));
11831184
}
11841185

11851186
#if !BUILDFLAG(IS_ANDROID)
11861187
std::unique_ptr<content::NavigationThrottle> ntp_shows_navigation_throttle =
1187-
NewTabShowsNavigationThrottle::MaybeCreateThrottleFor(handle);
1188+
NewTabShowsNavigationThrottle::MaybeCreateThrottleFor(navigation_handle);
11881189
if (ntp_shows_navigation_throttle) {
11891190
throttles.push_back(std::move(ntp_shows_navigation_throttle));
11901191
}
11911192
#endif
11921193

11931194
#if BUILDFLAG(ENABLE_BRAVE_WEBTORRENT)
11941195
throttles.push_back(
1195-
std::make_unique<extensions::BraveWebTorrentNavigationThrottle>(handle));
1196+
std::make_unique<extensions::BraveWebTorrentNavigationThrottle>(
1197+
navigation_handle));
11961198
#endif
11971199

11981200
#if BUILDFLAG(ENABLE_TOR)
11991201
std::unique_ptr<content::NavigationThrottle> tor_navigation_throttle =
1200-
tor::TorNavigationThrottle::MaybeCreateThrottleFor(handle,
1202+
tor::TorNavigationThrottle::MaybeCreateThrottleFor(navigation_handle,
12011203
context->IsTor());
12021204
if (tor_navigation_throttle) {
12031205
throttles.push_back(std::move(tor_navigation_throttle));
12041206
}
12051207
std::unique_ptr<content::NavigationThrottle>
12061208
onion_location_navigation_throttle =
12071209
tor::OnionLocationNavigationThrottle::MaybeCreateThrottleFor(
1208-
handle, TorProfileServiceFactory::IsTorDisabled(context),
1210+
navigation_handle,
1211+
TorProfileServiceFactory::IsTorDisabled(context),
12091212
context->IsTor());
12101213
if (onion_location_navigation_throttle) {
12111214
throttles.push_back(std::move(onion_location_navigation_throttle));
12121215
}
12131216
#endif
12141217

12151218
std::unique_ptr<content::NavigationThrottle>
1216-
decentralized_dns_navigation_throttle =
1217-
decentralized_dns::DecentralizedDnsNavigationThrottle::
1218-
MaybeCreateThrottleFor(handle, g_browser_process->local_state(),
1219-
g_browser_process->GetApplicationLocale());
1219+
decentralized_dns_navigation_throttle = decentralized_dns::
1220+
DecentralizedDnsNavigationThrottle::MaybeCreateThrottleFor(
1221+
navigation_handle, g_browser_process->local_state(),
1222+
g_browser_process->GetApplicationLocale());
12201223
if (decentralized_dns_navigation_throttle) {
12211224
throttles.push_back(std::move(decentralized_dns_navigation_throttle));
12221225
}
12231226

12241227
// Debounce
12251228
if (auto debounce_throttle =
12261229
debounce::DebounceNavigationThrottle::MaybeCreateThrottleFor(
1227-
handle, debounce::DebounceServiceFactory::GetForBrowserContext(
1228-
context))) {
1230+
navigation_handle,
1231+
debounce::DebounceServiceFactory::GetForBrowserContext(
1232+
context))) {
12291233
throttles.push_back(std::move(debounce_throttle));
12301234
}
12311235

@@ -1237,7 +1241,8 @@ BraveContentBrowserClient::CreateThrottlesForNavigation(
12371241
if (std::unique_ptr<content::NavigationThrottle>
12381242
domain_block_navigation_throttle = brave_shields::
12391243
DomainBlockNavigationThrottle::MaybeCreateThrottleFor(
1240-
handle, g_brave_browser_process->ad_block_service(),
1244+
navigation_handle,
1245+
g_brave_browser_process->ad_block_service(),
12411246
g_brave_browser_process->ad_block_service()
12421247
->custom_filters_provider(),
12431248
EphemeralStorageServiceFactory::GetForContext(context),
@@ -1251,7 +1256,7 @@ BraveContentBrowserClient::CreateThrottlesForNavigation(
12511256
// Request Off-The-Record
12521257
if (auto request_otr_throttle =
12531258
request_otr::RequestOTRNavigationThrottle::MaybeCreateThrottleFor(
1254-
handle,
1259+
navigation_handle,
12551260
request_otr::RequestOTRServiceFactory::GetForBrowserContext(
12561261
context),
12571262
EphemeralStorageServiceFactory::GetForContext(context),
@@ -1262,16 +1267,16 @@ BraveContentBrowserClient::CreateThrottlesForNavigation(
12621267
#endif
12631268

12641269
if (Profile::FromBrowserContext(context)->IsRegularProfile()) {
1265-
if (auto ai_chat_throttle =
1266-
ai_chat::AIChatThrottle::MaybeCreateThrottleFor(handle)) {
1270+
if (auto ai_chat_throttle = ai_chat::AIChatThrottle::MaybeCreateThrottleFor(
1271+
navigation_handle)) {
12671272
throttles.push_back(std::move(ai_chat_throttle));
12681273
}
12691274
}
12701275

12711276
#if !BUILDFLAG(IS_ANDROID)
12721277
if (auto ai_chat_brave_search_throttle =
12731278
ai_chat::AIChatBraveSearchThrottle::MaybeCreateThrottleFor(
1274-
base::BindOnce(&ai_chat::OpenAIChatForTab), handle,
1279+
base::BindOnce(&ai_chat::OpenAIChatForTab), navigation_handle,
12751280
ai_chat::AIChatServiceFactory::GetForBrowserContext(context),
12761281
user_prefs::UserPrefs::Get(context))) {
12771282
throttles.push_back(std::move(ai_chat_brave_search_throttle));
@@ -1280,7 +1285,7 @@ BraveContentBrowserClient::CreateThrottlesForNavigation(
12801285

12811286
if (auto backup_results_throttle =
12821287
brave_search::BackupResultsNavigationThrottle::MaybeCreateThrottleFor(
1283-
handle)) {
1288+
naviagation_handle)) {
12841289
throttles.push_back(std::move(backup_results_throttle));
12851290
}
12861291

browser/brave_content_browser_client.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class BraveContentBrowserClient : public ChromeContentBrowserClient {
146146
GURL* url,
147147
content::BrowserContext* browser_context);
148148
std::vector<std::unique_ptr<content::NavigationThrottle>>
149-
CreateThrottlesForNavigation(content::NavigationHandle* handle) override;
149+
CreateThrottlesForNavigation(NavigationThrottleRegistry& registry) override;
150150
std::vector<url::Origin> GetOriginsRequiringDedicatedProcess() override;
151151
// We use this for the Google Sign-In feature
152152
bool CanCreateWindow(content::RenderFrameHost* opener,

0 commit comments

Comments
 (0)