OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/frame_host/navigation_handle_impl.h" | 5 #include "content/browser/frame_host/navigation_handle_impl.h" |
6 | 6 |
7 #include "content/browser/frame_host/navigator_delegate.h" | 7 #include "content/browser/frame_host/navigator_delegate.h" |
8 #include "net/url_request/redirect_info.h" | 8 #include "net/url_request/redirect_info.h" |
9 | 9 |
10 namespace content { | 10 namespace content { |
11 | 11 |
12 // static | 12 // static |
13 scoped_ptr<NavigationHandleImpl> NavigationHandleImpl::Create( | 13 scoped_ptr<NavigationHandleImpl> NavigationHandleImpl::Create( |
14 const GURL& url, | 14 const GURL& url, |
| 15 const GURL& validated_url, |
15 const bool is_main_frame, | 16 const bool is_main_frame, |
16 NavigatorDelegate* delegate) { | 17 NavigatorDelegate* delegate) { |
17 return scoped_ptr<NavigationHandleImpl>( | 18 return scoped_ptr<NavigationHandleImpl>( |
18 new NavigationHandleImpl(url, is_main_frame, delegate)); | 19 new NavigationHandleImpl(url, validated_url, is_main_frame, delegate)); |
19 } | 20 } |
20 | 21 |
21 NavigationHandleImpl::NavigationHandleImpl(const GURL& url, | 22 NavigationHandleImpl::NavigationHandleImpl(const GURL& url, |
| 23 const GURL& validated_url, |
22 const bool is_main_frame, | 24 const bool is_main_frame, |
23 NavigatorDelegate* delegate) | 25 NavigatorDelegate* delegate) |
24 : url_(url), | 26 : url_(url), |
| 27 validated_url_(validated_url), |
| 28 is_main_frame_(is_main_frame), |
| 29 is_post_(false), |
| 30 has_user_gesture_(false), |
| 31 transition_(ui::PAGE_TRANSITION_LINK), |
| 32 is_external_protocol_(false), |
25 net_error_code_(net::OK), | 33 net_error_code_(net::OK), |
26 state_(DID_START), | 34 state_(DID_START), |
27 is_main_frame_(is_main_frame), | |
28 is_transferring_(false), | 35 is_transferring_(false), |
29 delegate_(delegate) { | 36 delegate_(delegate) { |
30 delegate_->DidStartNavigation(this); | 37 delegate_->DidStartNavigation(this); |
31 } | 38 } |
32 | 39 |
33 NavigationHandleImpl::~NavigationHandleImpl() { | 40 NavigationHandleImpl::~NavigationHandleImpl() { |
34 delegate_->DidFinishNavigation(this); | 41 delegate_->DidFinishNavigation(this); |
35 } | 42 } |
36 | 43 |
37 const GURL& NavigationHandleImpl::GetURL() const { | 44 const GURL& NavigationHandleImpl::GetURL() const { |
38 return url_; | 45 return url_; |
39 } | 46 } |
40 | 47 |
| 48 const GURL& NavigationHandleImpl::GetValidatedURL() const { |
| 49 return validated_url_; |
| 50 } |
| 51 |
| 52 bool NavigationHandleImpl::IsInMainFrame() const { |
| 53 return is_main_frame_; |
| 54 } |
| 55 |
| 56 bool NavigationHandleImpl::IsPost() const { |
| 57 CHECK_NE(DID_START, state_) |
| 58 << "This accessor should not be called before the request is started."; |
| 59 return is_post_; |
| 60 } |
| 61 |
| 62 const Referrer& NavigationHandleImpl::GetReferrer() const { |
| 63 CHECK_NE(DID_START, state_) |
| 64 << "This accessor should not be called before the request is started."; |
| 65 return sanitized_referrer_; |
| 66 } |
| 67 |
| 68 bool NavigationHandleImpl::HasUserGesture() const { |
| 69 CHECK_NE(DID_START, state_) |
| 70 << "This accessor should not be called before the request is started."; |
| 71 return has_user_gesture_; |
| 72 } |
| 73 |
| 74 ui::PageTransition NavigationHandleImpl::GetPageTransition() const { |
| 75 CHECK_NE(DID_START, state_) |
| 76 << "This accessor should not be called before the request is started."; |
| 77 return transition_; |
| 78 } |
| 79 |
| 80 bool NavigationHandleImpl::IsExternalProtocol() const { |
| 81 CHECK_NE(DID_START, state_) |
| 82 << "This accessor should not be called before the request is started."; |
| 83 return is_external_protocol_; |
| 84 } |
| 85 |
41 net::Error NavigationHandleImpl::GetNetErrorCode() const { | 86 net::Error NavigationHandleImpl::GetNetErrorCode() const { |
42 return net_error_code_; | 87 return net_error_code_; |
43 } | 88 } |
44 | 89 |
45 bool NavigationHandleImpl::IsInMainFrame() const { | |
46 return is_main_frame_; | |
47 } | |
48 | |
49 bool NavigationHandleImpl::HasCommittedDocument() const { | 90 bool NavigationHandleImpl::HasCommittedDocument() const { |
50 return state_ == DID_COMMIT; | 91 return state_ == DID_COMMIT; |
51 } | 92 } |
52 | 93 |
53 bool NavigationHandleImpl::HasCommittedErrorPage() const { | 94 bool NavigationHandleImpl::HasCommittedErrorPage() const { |
54 return state_ == DID_COMMIT_ERROR_PAGE; | 95 return state_ == DID_COMMIT_ERROR_PAGE; |
55 } | 96 } |
56 | 97 |
| 98 void NavigationHandleImpl::RegisterThrottleForTesting( |
| 99 scoped_ptr<NavigationThrottle> navigation_throttle) { |
| 100 throttles_.push_back(navigation_throttle.Pass()); |
| 101 } |
| 102 |
| 103 NavigationThrottle::ThrottleCheckResult NavigationHandleImpl::WillStartRequest( |
| 104 bool is_post, |
| 105 const Referrer& sanitized_referrer, |
| 106 bool has_user_gesture, |
| 107 ui::PageTransition transition, |
| 108 bool is_external_protocol) { |
| 109 // Update the navigation parameters. |
| 110 is_post_ = is_post; |
| 111 sanitized_referrer_ = sanitized_referrer; |
| 112 has_user_gesture_ = has_user_gesture; |
| 113 transition_ = transition; |
| 114 is_external_protocol_ = is_external_protocol; |
| 115 |
| 116 state_ = WILL_SEND_REQUEST; |
| 117 |
| 118 // Register the navigation throttles. |
| 119 std::vector<NavigationThrottle*> throttles = |
| 120 delegate_->AddNavigationThrottles(this); |
| 121 for (NavigationThrottle* throttle : throttles) |
| 122 throttles_.push_back(throttle); |
| 123 |
| 124 // Notify each throttle of the request. |
| 125 for (NavigationThrottle* throttle : throttles_) { |
| 126 NavigationThrottle::ThrottleCheckResult result = |
| 127 throttle->WillStartRequest(); |
| 128 if (result == NavigationThrottle::CANCEL_AND_IGNORE) |
| 129 return NavigationThrottle::CANCEL_AND_IGNORE; |
| 130 } |
| 131 return NavigationThrottle::PROCEED; |
| 132 } |
| 133 |
| 134 NavigationThrottle::ThrottleCheckResult |
| 135 NavigationHandleImpl::WillRedirectRequest(const GURL& new_url, |
| 136 const GURL& new_validated_url, |
| 137 bool new_method_is_post, |
| 138 const GURL& new_referrer_url, |
| 139 bool new_is_external_protocol) { |
| 140 // Update the navigation parameters. |
| 141 url_ = new_url; |
| 142 validated_url_ = new_validated_url; |
| 143 is_post_ = new_method_is_post; |
| 144 sanitized_referrer_.url = new_referrer_url; |
| 145 sanitized_referrer_ = Referrer::SanitizeForRequest(url_, sanitized_referrer_); |
| 146 is_external_protocol_ = new_is_external_protocol; |
| 147 |
| 148 // Have each throttle be notified of the request. |
| 149 for (NavigationThrottle* throttle : throttles_) { |
| 150 NavigationThrottle::ThrottleCheckResult result = |
| 151 throttle->WillRedirectRequest(); |
| 152 if (result == NavigationThrottle::CANCEL_AND_IGNORE) |
| 153 return NavigationThrottle::CANCEL_AND_IGNORE; |
| 154 } |
| 155 return NavigationThrottle::PROCEED; |
| 156 } |
| 157 |
57 void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) { | 158 void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) { |
58 url_ = new_url; | 159 url_ = new_url; |
59 delegate_->DidRedirectNavigation(this); | 160 delegate_->DidRedirectNavigation(this); |
60 } | 161 } |
61 | 162 |
62 void NavigationHandleImpl::DidCommitNavigation() { | 163 void NavigationHandleImpl::DidCommitNavigation() { |
63 state_ = net_error_code_ == net::OK ? DID_COMMIT : DID_COMMIT_ERROR_PAGE; | 164 state_ = net_error_code_ == net::OK ? DID_COMMIT : DID_COMMIT_ERROR_PAGE; |
64 delegate_->DidCommitNavigation(this); | 165 delegate_->DidCommitNavigation(this); |
65 } | 166 } |
66 | 167 |
67 } // namespace content | 168 } // namespace content |
OLD | NEW |