Chromium Code Reviews| 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..6c40de7a71279f2b7a01cec5211ba6f89b1879e2 100644 |
| --- a/content/browser/frame_host/navigation_handle_impl.cc |
| +++ b/content/browser/frame_host/navigation_handle_impl.cc |
| @@ -5,6 +5,8 @@ |
| #include "content/browser/frame_host/navigation_handle_impl.h" |
| #include "content/browser/frame_host/navigator_delegate.h" |
| +#include "content/public/browser/content_browser_client.h" |
| +#include "content/public/common/content_client.h" |
| #include "net/url_request/redirect_info.h" |
| namespace content { |
| @@ -12,7 +14,7 @@ namespace content { |
| // static |
| scoped_ptr<NavigationHandleImpl> NavigationHandleImpl::Create( |
| const GURL& url, |
| - const bool is_main_frame, |
| + bool is_main_frame, |
| NavigatorDelegate* delegate) { |
| return scoped_ptr<NavigationHandleImpl>( |
| new NavigationHandleImpl(url, is_main_frame, delegate)); |
| @@ -22,9 +24,13 @@ NavigationHandleImpl::NavigationHandleImpl(const GURL& url, |
| const bool is_main_frame, |
| NavigatorDelegate* delegate) |
| : url_(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); |
| @@ -34,26 +40,141 @@ NavigationHandleImpl::~NavigationHandleImpl() { |
| delegate_->DidFinishNavigation(this); |
| } |
| -const GURL& NavigationHandleImpl::GetURL() const { |
| +const GURL& NavigationHandleImpl::GetURL() { |
| return url_; |
| } |
| -net::Error NavigationHandleImpl::GetNetErrorCode() const { |
| - return net_error_code_; |
| +bool NavigationHandleImpl::IsInMainFrame() { |
| + return is_main_frame_; |
| } |
| -bool NavigationHandleImpl::IsInMainFrame() const { |
| - return is_main_frame_; |
| +bool NavigationHandleImpl::IsPost() { |
| + CHECK_NE(DID_START, state_) |
| + << "This accessor should not be called before the request is started."; |
|
Charlie Reis
2015/09/18 05:40:02
This message is confusing because DID_START sounds
clamy
2015/09/18 17:35:39
I changed the state name to INITIAL.
|
| + return is_post_; |
| +} |
| + |
| +const Referrer& NavigationHandleImpl::GetReferrer() { |
| + CHECK_NE(DID_START, state_) |
| + << "This accessor should not be called before the request is started."; |
| + return sanitized_referrer_; |
| +} |
| + |
| +bool NavigationHandleImpl::HasUserGesture() { |
| + CHECK_NE(DID_START, state_) |
| + << "This accessor should not be called before the request is started."; |
| + return has_user_gesture_; |
| +} |
| + |
| +ui::PageTransition NavigationHandleImpl::GetPageTransition() { |
| + CHECK_NE(DID_START, state_) |
| + << "This accessor should not be called before the request is started."; |
| + return transition_; |
| +} |
| + |
| +bool NavigationHandleImpl::IsExternalProtocol() { |
| + CHECK_NE(DID_START, state_) |
| + << "This accessor should not be called before the request is started."; |
| + return is_external_protocol_; |
| +} |
| + |
| +net::Error NavigationHandleImpl::GetNetErrorCode() { |
| + return net_error_code_; |
| } |
| -bool NavigationHandleImpl::HasCommittedDocument() const { |
| +bool NavigationHandleImpl::HasCommittedDocument() { |
| return state_ == DID_COMMIT; |
| } |
| -bool NavigationHandleImpl::HasCommittedErrorPage() const { |
| +bool NavigationHandleImpl::HasCommittedErrorPage() { |
| return state_ == DID_COMMIT_ERROR_PAGE; |
| } |
| +void NavigationHandleImpl::RegisterThrottleForTesting( |
| + scoped_ptr<NavigationThrottle> navigation_throttle) { |
| + throttles_.push_back(navigation_throttle.Pass()); |
| +} |
| + |
| +NavigationThrottle::ThrottleCheckResult |
| +NavigationHandleImpl::CallWillStartRequestForTesting( |
| + bool is_post, |
| + const Referrer& sanitized_referrer, |
| + bool has_user_gesture, |
| + ui::PageTransition transition, |
| + bool is_external_protocol) { |
| + return WillStartRequest(is_post, sanitized_referrer, has_user_gesture, |
| + transition, is_external_protocol); |
| +} |
| + |
| +NavigationThrottle::ThrottleCheckResult |
| +NavigationHandleImpl::CallWillRedirectRequestForTesting( |
| + const GURL& new_url, |
| + bool new_method_is_post, |
| + const GURL& new_referrer_url, |
| + bool new_is_external_protocol) { |
| + return WillRedirectRequest(new_url, new_method_is_post, new_referrer_url, |
| + new_is_external_protocol); |
| +} |
| + |
| +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. The ScopedVector returned by |
| + // GetNavigationThrottles is not assigned to throttles_ directly because it |
| + // would overwrite any throttle previously added with |
| + // RegisterThrottleForTesting. |
| + ScopedVector<NavigationThrottle> throttles_to_register = |
| + GetContentClient()->browser()->CreateThrottlesForNavigation(this); |
| + if (throttles_to_register.size() > 0) { |
| + throttles_.insert(throttles_.end(), throttles_to_register.begin(), |
| + throttles_to_register.end()); |
| + throttles_to_register.weak_clear(); |
| + } |
| + |
| + // Notify each throttle of the request. |
| + for (NavigationThrottle* throttle : throttles_) { |
| + NavigationThrottle::ThrottleCheckResult result = |
| + throttle->WillStartRequest(); |
| + if (result == NavigationThrottle::CANCEL_AND_IGNORE) |
| + return NavigationThrottle::CANCEL_AND_IGNORE; |
| + } |
| + return NavigationThrottle::PROCEED; |
| +} |
| + |
| +NavigationThrottle::ThrottleCheckResult |
| +NavigationHandleImpl::WillRedirectRequest(const GURL& new_url, |
| + bool new_method_is_post, |
| + const GURL& new_referrer_url, |
| + bool new_is_external_protocol) { |
| + // Update the navigation parameters. |
| + url_ = new_url; |
| + is_post_ = new_method_is_post; |
| + sanitized_referrer_.url = new_referrer_url; |
| + sanitized_referrer_ = Referrer::SanitizeForRequest(url_, sanitized_referrer_); |
| + is_external_protocol_ = new_is_external_protocol; |
| + |
| + // Have each throttle be notified of the request. |
| + for (NavigationThrottle* throttle : throttles_) { |
| + NavigationThrottle::ThrottleCheckResult result = |
| + throttle->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); |