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

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

Issue 1269813002: Add a NavigationThrottle to the public content/ interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@navigation-api
Patch Set: Created 5 years, 4 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
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 f24999058b5f36021c507f91087d45f01b5435a8..846853b418afbad5e364c1f983bd37aecab9d668 100644
--- a/content/browser/frame_host/navigation_handle_impl.cc
+++ b/content/browser/frame_host/navigation_handle_impl.cc
@@ -12,19 +12,26 @@ namespace content {
// static
scoped_ptr<NavigationHandleImpl> NavigationHandleImpl::Create(
const GURL& url,
+ const GURL& validated_url,
const bool is_main_frame,
NavigatorDelegate* delegate) {
return scoped_ptr<NavigationHandleImpl>(
- new NavigationHandleImpl(url, is_main_frame, delegate));
+ new NavigationHandleImpl(url, validated_url, is_main_frame, delegate));
}
NavigationHandleImpl::NavigationHandleImpl(const GURL& url,
+ const GURL& validated_url,
const bool is_main_frame,
NavigatorDelegate* delegate)
: url_(url),
+ validated_url_(validated_url),
+ is_main_frame_(is_main_frame),
+ is_post_(false),
+ has_user_gesture_(false),
+ transition_(ui::PAGE_TRANSITION_LINK),
+ is_external_protocol_(false),
net_error_code_(net::OK),
state_(DID_START),
- is_main_frame_(is_main_frame),
is_transferring_(false),
delegate_(delegate) {
delegate_->DidStartNavigation(this);
@@ -38,14 +45,48 @@ const GURL& NavigationHandleImpl::GetURL() const {
return url_;
}
-net::Error NavigationHandleImpl::GetNetErrorCode() const {
- return net_error_code_;
+const GURL& NavigationHandleImpl::GetValidatedURL() const {
+ return validated_url_;
}
bool NavigationHandleImpl::IsInMainFrame() const {
return is_main_frame_;
}
+bool NavigationHandleImpl::IsPost() const {
+ DCHECK(state_ != DID_START)
nasko 2015/08/31 23:25:15 nit: CHECK? Also in the methods below.
Avi (use Gerrit) 2015/09/01 16:38:47 DCHECK is the usual Chromium style; why are you pr
davidben 2015/09/01 21:55:18 I think this line doesn't have enough people comme
nasko 2015/09/01 22:08:12 This is not a codepath that the renderer can induc
clamy 2015/09/03 15:30:51 I think CHECKS are ok in that case, but apart from
nasko 2015/09/04 23:36:49 In general this is a great point. It must be a rea
+ << "This accessor should not be called before the request is started.";
+ return is_post_;
+}
+
+const Referrer& NavigationHandleImpl::GetSanitizedReferrer() const {
+ DCHECK(state_ != DID_START)
+ << "This accessor should not be called before the request is started.";
+ return sanitized_referrer_;
+}
+
+bool NavigationHandleImpl::HasUserGesture() const {
+ DCHECK(state_ != DID_START)
+ << "This accessor should not be called before the request is started.";
+ return has_user_gesture_;
+}
+
+ui::PageTransition NavigationHandleImpl::GetPageTransition() const {
+ DCHECK(state_ != DID_START)
+ << "This accessor should not be called before the request is started.";
+ return transition_;
+}
+
+bool NavigationHandleImpl::IsExternalProtocol() const {
+ DCHECK(state_ != DID_START)
+ << "This accessor should not be called before the request is started.";
+ return is_external_protocol_;
+}
+
+net::Error NavigationHandleImpl::GetNetErrorCode() const {
+ return net_error_code_;
+}
+
bool NavigationHandleImpl::HasCommittedDocument() const {
return state_ == DID_COMMIT;
}
@@ -54,6 +95,64 @@ bool NavigationHandleImpl::HasCommittedErrorPage() const {
return state_ == DID_COMMIT_ERROR_PAGE;
}
+void NavigationHandleImpl::RegisterThrottle(
+ scoped_ptr<NavigationThrottle> navigation_throttle) {
+ throttles_.push_back(navigation_throttle.Pass());
+}
+
+NavigationThrottle::ThrottleCheckResult NavigationHandleImpl::WillStartRequest(
+ bool is_post,
+ const Referrer& sanitized_referrer,
+ bool has_user_gesture,
+ ui::PageTransition transition,
+ bool is_external_protocol) {
+ // Update the navigation parameters.
+ is_post_ = is_post;
+ sanitized_referrer_ = sanitized_referrer;
+ has_user_gesture_ = has_user_gesture;
+ transition_ = transition;
+ is_external_protocol_ = is_external_protocol;
+
+ state_ = WILL_SEND_REQUEST;
+
+ // Register the navigation throttles.
+ delegate_->AddNavigationThrottles(this);
+
+ // Have each throttle be notified of the request.
davidben 2015/09/01 21:55:17 Nit: Perhaps "Notify each throttle of the request.
clamy 2015/09/03 15:30:51 Done.
+ for (auto it = throttles_.begin(); it != throttles_.end(); ++it) {
davidben 2015/09/01 21:55:18 (Is it possible to use a range-based for loop here
clamy 2015/09/03 15:30:51 Done (it's been so long since I wrote a loop in Ch
+ NavigationThrottle::ThrottleCheckResult result = (*it)->WillStartRequest();
+ if (result == NavigationThrottle::CANCEL_AND_IGNORE)
+ return NavigationThrottle::CANCEL_AND_IGNORE;
+ }
+ return NavigationThrottle::PROCEED;
+}
+
+NavigationThrottle::ThrottleCheckResult
+NavigationHandleImpl::WillRedirectRequest(const GURL& new_url,
+ const GURL& new_validated_url,
+ bool new_method_is_post,
+ const GURL& new_referrer_url,
+ bool new_is_external_protocol) {
+ // Update the navigation parameters.
+ url_ = new_url;
+ validated_url_ = new_validated_url;
+ is_post_ = new_method_is_post;
+ sanitized_referrer_.url = new_referrer_url;
carlosk 2015/08/28 16:40:24 Why setting this member URL here when the next lin
clamy 2015/09/03 15:30:51 Because it needs to be updated before being saniti
+ sanitized_referrer_ = Referrer::SanitizeForRequest(url_, sanitized_referrer_);
davidben 2015/09/01 21:55:18 I'm a little puzzled by this line. Wouldn't the re
clamy 2015/09/03 15:30:51 I based myself on the fact that the ResourceThrott
+ is_external_protocol_ = new_is_external_protocol;
+
+ state_ = WILL_REDIRECT_REQUEST;
davidben 2015/09/01 21:55:18 Is anything actually sensitive to this state? You
clamy 2015/09/03 15:30:51 Done. Note that we may have to reintroduce it if t
+
+ // Have each throttle be notified of the request.
+ for (auto it = throttles_.begin(); it != throttles_.end(); ++it) {
+ NavigationThrottle::ThrottleCheckResult result =
+ (*it)->WillRedirectRequest();
+ if (result == NavigationThrottle::CANCEL_AND_IGNORE)
+ return NavigationThrottle::CANCEL_AND_IGNORE;
+ }
+ return NavigationThrottle::PROCEED;
+}
+
void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) {
url_ = new_url;
delegate_->DidRedirectNavigation(this);

Powered by Google App Engine
This is Rietveld 408576698