Commit b7c5f00a authored by arthursonzogni's avatar arthursonzogni Committed by Commit Bot

Refactor NavigationHandleImpl::RegisterNavigationThrottles.

This CL removes |throttles_to_register| and introduces |AddThrottle()|.
This will be easier to know understand in which order the throttle are
inserted into |throttle_|.

Some throttle were not inserted in the right order. AncestorThrottle
and MixedContentThrottle for instance.

BUG=733099
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_site_isolation

Review-Url: https://codereview.chromium.org/2967363002
Cr-Commit-Position: refs/heads/master@{#485911}
parent a1b6731c
...@@ -1136,50 +1136,43 @@ void NavigationHandleImpl::RunCompleteCallback( ...@@ -1136,50 +1136,43 @@ void NavigationHandleImpl::RunCompleteCallback(
} }
void NavigationHandleImpl::RegisterNavigationThrottles() { void NavigationHandleImpl::RegisterNavigationThrottles() {
// Register the navigation throttles. The vector returned by // Note: |throttle_| might not be empty. Some NavigationThrottles might have
// CreateThrottlesForNavigation is not assigned to throttles_ directly because // been registered with RegisterThrottleForTesting. These must reside at the
// it would overwrite any throttles previously added with // end of |throttles_|. TestNavigationManagerThrottle expects that the
// RegisterThrottleForTesting. // NavigationThrottles added for test are the last NavigationThrottles to
// TODO(carlosk, arthursonzogni): should simplify this to either use // execute. Take them out while appending the rest of the
// |throttles_| directly (except for the case described above) or // NavigationThrottles.
// |throttles_to_register| for registering all throttles. std::vector<std::unique_ptr<NavigationThrottle>> testing_throttles =
std::vector<std::unique_ptr<NavigationThrottle>> throttles_to_register = std::move(throttles_);
GetDelegate()->CreateThrottlesForNavigation(this);
throttles_ = GetDelegate()->CreateThrottlesForNavigation(this);
// Check for renderer-inititated main frame navigations to data URLs. This is // Check for renderer-inititated main frame navigations to data URLs. This is
// done first as it may block the main frame navigation altogether. // done first as it may block the main frame navigation altogether.
std::unique_ptr<NavigationThrottle> data_url_navigation_throttle = AddThrottle(DataUrlNavigationThrottle::CreateThrottleForNavigation(this));
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));
std::unique_ptr<content::NavigationThrottle> form_submission_throttle = AddThrottle(AncestorThrottle::MaybeCreateThrottleFor(this));
content::FormSubmissionThrottle::MaybeCreateThrottleFor(this); AddThrottle(FormSubmissionThrottle::MaybeCreateThrottleFor(this));
if (form_submission_throttle)
throttles_.push_back(std::move(form_submission_throttle));
// Check for mixed content. This is done after the AncestorThrottle and the // Check for mixed content. This is done after the AncestorThrottle and the
// FormSubmissionThrottle so that when folks block mixed content with a CSP // 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 // policy, they don't get a warning. They'll still get a warning in the
// console about CSP blocking the load. // console about CSP blocking the load.
std::unique_ptr<NavigationThrottle> mixed_content_throttle = AddThrottle(
MixedContentNavigationThrottle::CreateThrottleForNavigation(this); MixedContentNavigationThrottle::CreateThrottleForNavigation(this));
if (mixed_content_throttle)
throttles_to_register.push_back(std::move(mixed_content_throttle)); AddThrottle(RenderFrameDevToolsAgentHost::CreateThrottleForNavigation(this));
std::unique_ptr<NavigationThrottle> devtools_throttle = // Insert all testing NavigationThrottles last.
RenderFrameDevToolsAgentHost::CreateThrottleForNavigation(this); throttles_.insert(throttles_.end(),
if (devtools_throttle) std::make_move_iterator(testing_throttles.begin()),
throttles_to_register.push_back(std::move(devtools_throttle)); std::make_move_iterator(testing_throttles.end()));
}
throttles_.insert(throttles_.begin(),
std::make_move_iterator(throttles_to_register.begin()), void NavigationHandleImpl::AddThrottle(
std::make_move_iterator(throttles_to_register.end())); std::unique_ptr<NavigationThrottle> throttle) {
if (throttle)
throttles_.push_back(std::move(throttle));
} }
bool NavigationHandleImpl::IsSelfReferentialURL() { bool NavigationHandleImpl::IsSelfReferentialURL() {
......
...@@ -429,6 +429,9 @@ class CONTENT_EXPORT NavigationHandleImpl : public NavigationHandle { ...@@ -429,6 +429,9 @@ class CONTENT_EXPORT NavigationHandleImpl : public NavigationHandle {
// Populates |throttles_| with the throttles for this navigation. // Populates |throttles_| with the throttles for this navigation.
void RegisterNavigationThrottles(); void RegisterNavigationThrottles();
// Takes ownership of |throttle| (if any) and appends it to |throttles_|.
void AddThrottle(std::unique_ptr<NavigationThrottle> throttle);
// Checks for attempts to navigate to a page that is already referenced more // Checks for attempts to navigate to a page that is already referenced more
// than once in the frame's ancestors. This is a helper function used by // than once in the frame's ancestors. This is a helper function used by
// WillStartRequest and WillRedirectRequest to prevent the navigation. // WillStartRequest and WillRedirectRequest to prevent the navigation.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment