Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1536)

Unified Diff: content/browser/frame_host/navigation_handle_impl.cc

Issue 2967363002: Refactor NavigationHandleImpl::RegisterNavigationThrottles. (Closed)
Patch Set: Addressed comments (@clamy) (and rebase...) Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/frame_host/navigation_handle_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/frame_host/navigation_handle_impl.cc
diff --git a/content/browser/frame_host/navigation_handle_impl.cc b/content/browser/frame_host/navigation_handle_impl.cc
index 4f024e887254fe4a23cbcc25cc955ddb79c04f2c..009f8d10208b18b7a1d6b1677d259acb59d7920f 100644
--- a/content/browser/frame_host/navigation_handle_impl.cc
+++ b/content/browser/frame_host/navigation_handle_impl.cc
@@ -1098,50 +1098,43 @@ void NavigationHandleImpl::RunCompleteCallback(
}
void NavigationHandleImpl::RegisterNavigationThrottles() {
- // Register the navigation throttles. The vector returned by
- // CreateThrottlesForNavigation is not assigned to throttles_ directly because
- // it would overwrite any throttles previously added with
- // RegisterThrottleForTesting.
- // TODO(carlosk, arthursonzogni): should simplify this to either use
- // |throttles_| directly (except for the case described above) or
- // |throttles_to_register| for registering all throttles.
- std::vector<std::unique_ptr<NavigationThrottle>> throttles_to_register =
- GetDelegate()->CreateThrottlesForNavigation(this);
+ // Note: |throttle_| might not be empty. Some NavigationThrottles might have
+ // been registered with RegisterThrottleForTesting. These must reside at the
+ // end of |throttles_|. TestNavigationManagerThrottle expects that the
+ // NavigationThrottles added for test are the last NavigationThrottles to
+ // execute. Take them out while appending the rest of the
+ // NavigationThrottles.
+ std::vector<std::unique_ptr<NavigationThrottle>> testing_throttles =
+ std::move(throttles_);
+
+ throttles_ = GetDelegate()->CreateThrottlesForNavigation(this);
// Check for renderer-inititated main frame navigations to data URLs. This is
// done first as it may block the main frame navigation altogether.
- std::unique_ptr<NavigationThrottle> data_url_navigation_throttle =
- DataUrlNavigationThrottle::CreateThrottleForNavigation(this);
- if (data_url_navigation_throttle)
- throttles_to_register.push_back(std::move(data_url_navigation_throttle));
-
- std::unique_ptr<content::NavigationThrottle> ancestor_throttle =
- content::AncestorThrottle::MaybeCreateThrottleFor(this);
- if (ancestor_throttle)
- throttles_.push_back(std::move(ancestor_throttle));
+ AddThrottle(DataUrlNavigationThrottle::CreateThrottleForNavigation(this));
- std::unique_ptr<content::NavigationThrottle> form_submission_throttle =
- content::FormSubmissionThrottle::MaybeCreateThrottleFor(this);
- if (form_submission_throttle)
- throttles_.push_back(std::move(form_submission_throttle));
+ AddThrottle(AncestorThrottle::MaybeCreateThrottleFor(this));
+ AddThrottle(FormSubmissionThrottle::MaybeCreateThrottleFor(this));
// Check for mixed content. This is done after the AncestorThrottle and the
// FormSubmissionThrottle so that when folks block mixed content with a CSP
// policy, they don't get a warning. They'll still get a warning in the
// console about CSP blocking the load.
- std::unique_ptr<NavigationThrottle> mixed_content_throttle =
- MixedContentNavigationThrottle::CreateThrottleForNavigation(this);
- if (mixed_content_throttle)
- throttles_to_register.push_back(std::move(mixed_content_throttle));
-
- std::unique_ptr<NavigationThrottle> devtools_throttle =
- RenderFrameDevToolsAgentHost::CreateThrottleForNavigation(this);
- if (devtools_throttle)
- throttles_to_register.push_back(std::move(devtools_throttle));
-
- throttles_.insert(throttles_.begin(),
- std::make_move_iterator(throttles_to_register.begin()),
- std::make_move_iterator(throttles_to_register.end()));
+ AddThrottle(
+ MixedContentNavigationThrottle::CreateThrottleForNavigation(this));
+
+ AddThrottle(RenderFrameDevToolsAgentHost::CreateThrottleForNavigation(this));
+
+ // Insert all testing NavigationThrottles last.
+ throttles_.insert(throttles_.end(),
+ std::make_move_iterator(testing_throttles.begin()),
+ std::make_move_iterator(testing_throttles.end()));
+}
+
+void NavigationHandleImpl::AddThrottle(
+ std::unique_ptr<NavigationThrottle> throttle) {
+ if (throttle)
+ throttles_.push_back(std::move(throttle));
}
bool NavigationHandleImpl::IsSelfReferentialURL() {
« no previous file with comments | « content/browser/frame_host/navigation_handle_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698