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 "content/public/browser/content_browser_client.h" | |
9 #include "content/public/common/content_client.h" | |
8 #include "net/url_request/redirect_info.h" | 10 #include "net/url_request/redirect_info.h" |
9 | 11 |
10 namespace content { | 12 namespace content { |
11 | 13 |
12 // static | |
13 scoped_ptr<NavigationHandleImpl> NavigationHandleImpl::Create( | |
14 const GURL& url, | |
15 const bool is_main_frame, | |
16 NavigatorDelegate* delegate) { | |
17 return scoped_ptr<NavigationHandleImpl>( | |
18 new NavigationHandleImpl(url, is_main_frame, delegate)); | |
19 } | |
20 | |
21 NavigationHandleImpl::NavigationHandleImpl(const GURL& url, | 14 NavigationHandleImpl::NavigationHandleImpl(const GURL& url, |
15 const GURL& validated_url, | |
22 const bool is_main_frame, | 16 const bool is_main_frame, |
23 NavigatorDelegate* delegate) | 17 NavigatorDelegate* delegate) |
24 : url_(url), | 18 : url_(url), |
19 validated_url_(validated_url), | |
20 is_main_frame_(is_main_frame), | |
21 is_post_(false), | |
22 has_user_gesture_(false), | |
23 transition_(ui::PAGE_TRANSITION_LINK), | |
24 is_external_protocol_(false), | |
25 net_error_code_(net::OK), | 25 net_error_code_(net::OK), |
26 state_(DID_START), | 26 state_(DID_START), |
27 is_main_frame_(is_main_frame), | |
28 is_transferring_(false), | 27 is_transferring_(false), |
29 delegate_(delegate) { | 28 delegate_(delegate) { |
30 delegate_->DidStartNavigation(this); | 29 delegate_->DidStartNavigation(this); |
31 } | 30 } |
32 | 31 |
33 NavigationHandleImpl::~NavigationHandleImpl() { | 32 NavigationHandleImpl::~NavigationHandleImpl() { |
34 delegate_->DidFinishNavigation(this); | 33 delegate_->DidFinishNavigation(this); |
35 } | 34 } |
36 | 35 |
37 const GURL& NavigationHandleImpl::GetURL() const { | 36 const GURL& NavigationHandleImpl::GetURL() const { |
38 return url_; | 37 return url_; |
39 } | 38 } |
40 | 39 |
40 const GURL& NavigationHandleImpl::GetValidatedURL() const { | |
41 return validated_url_; | |
42 } | |
43 | |
44 bool NavigationHandleImpl::IsInMainFrame() const { | |
45 return is_main_frame_; | |
46 } | |
47 | |
48 WebContents* NavigationHandleImpl::GetWebContents() const { | |
49 return web_contents_; | |
50 } | |
51 | |
52 bool NavigationHandleImpl::IsPost() const { | |
53 CHECK_NE(DID_START, state_) | |
54 << "This accessor should not be called before the request is started."; | |
55 return is_post_; | |
56 } | |
57 | |
58 const Referrer& NavigationHandleImpl::GetReferrer() const { | |
59 CHECK_NE(DID_START, state_) | |
60 << "This accessor should not be called before the request is started."; | |
61 return sanitized_referrer_; | |
62 } | |
63 | |
64 bool NavigationHandleImpl::HasUserGesture() const { | |
65 CHECK_NE(DID_START, state_) | |
66 << "This accessor should not be called before the request is started."; | |
67 return has_user_gesture_; | |
68 } | |
69 | |
70 ui::PageTransition NavigationHandleImpl::GetPageTransition() const { | |
71 CHECK_NE(DID_START, state_) | |
72 << "This accessor should not be called before the request is started."; | |
73 return transition_; | |
74 } | |
75 | |
76 bool NavigationHandleImpl::IsExternalProtocol() const { | |
77 CHECK_NE(DID_START, state_) | |
78 << "This accessor should not be called before the request is started."; | |
79 return is_external_protocol_; | |
80 } | |
81 | |
41 net::Error NavigationHandleImpl::GetNetErrorCode() const { | 82 net::Error NavigationHandleImpl::GetNetErrorCode() const { |
42 return net_error_code_; | 83 return net_error_code_; |
43 } | 84 } |
44 | 85 |
45 bool NavigationHandleImpl::IsInMainFrame() const { | |
46 return is_main_frame_; | |
47 } | |
48 | |
49 bool NavigationHandleImpl::HasCommittedDocument() const { | 86 bool NavigationHandleImpl::HasCommittedDocument() const { |
50 return state_ == DID_COMMIT; | 87 return state_ == DID_COMMIT; |
51 } | 88 } |
52 | 89 |
53 bool NavigationHandleImpl::HasCommittedErrorPage() const { | 90 bool NavigationHandleImpl::HasCommittedErrorPage() const { |
54 return state_ == DID_COMMIT_ERROR_PAGE; | 91 return state_ == DID_COMMIT_ERROR_PAGE; |
55 } | 92 } |
56 | 93 |
94 void NavigationHandleImpl::RegisterThrottleForTesting( | |
95 scoped_ptr<NavigationThrottle> navigation_throttle) { | |
96 throttles_.push_back(navigation_throttle.Pass()); | |
97 } | |
98 | |
99 NavigationThrottle::ThrottleCheckResult NavigationHandleImpl::WillStartRequest( | |
100 bool is_post, | |
101 const Referrer& sanitized_referrer, | |
102 bool has_user_gesture, | |
103 ui::PageTransition transition, | |
104 bool is_external_protocol) { | |
105 // Update the navigation parameters. | |
106 is_post_ = is_post; | |
107 sanitized_referrer_ = sanitized_referrer; | |
108 has_user_gesture_ = has_user_gesture; | |
109 transition_ = transition; | |
110 is_external_protocol_ = is_external_protocol; | |
111 | |
112 state_ = WILL_SEND_REQUEST; | |
113 | |
114 // Register the navigation throttles. The scoped_vector returned by | |
nasko
2015/09/14 22:00:04
nit: s/scoped_vector/ScopedVector/
clamy
2015/09/16 01:03:21
Done.
| |
115 // GetNavigationThrottles is not assigned to throttles_ directly because it | |
116 // would overwrite any throttle previously added with | |
117 // RegisterThrottleForTesting. | |
118 ScopedVector<NavigationThrottle> throttles_to_register = | |
119 GetContentClient()->browser()->GetNavigationThrottles(this); | |
120 if (throttles_to_register.size() > 0) { | |
121 throttles_.insert(throttles_.end(), throttles_to_register.begin(), | |
122 throttles_to_register.end()); | |
123 throttles_to_register.weak_clear(); | |
124 } | |
125 | |
126 // Notify each throttle of the request. | |
127 for (NavigationThrottle* throttle : throttles_) { | |
128 NavigationThrottle::ThrottleCheckResult result = | |
129 throttle->WillStartRequest(); | |
130 if (result == NavigationThrottle::CANCEL_AND_IGNORE) | |
131 return NavigationThrottle::CANCEL_AND_IGNORE; | |
132 } | |
133 return NavigationThrottle::PROCEED; | |
134 } | |
135 | |
136 NavigationThrottle::ThrottleCheckResult | |
137 NavigationHandleImpl::WillRedirectRequest(const GURL& new_url, | |
138 const GURL& new_validated_url, | |
139 bool new_method_is_post, | |
140 const GURL& new_referrer_url, | |
141 bool new_is_external_protocol) { | |
142 // Update the navigation parameters. | |
143 url_ = new_url; | |
144 validated_url_ = new_validated_url; | |
145 is_post_ = new_method_is_post; | |
146 sanitized_referrer_.url = new_referrer_url; | |
147 sanitized_referrer_ = Referrer::SanitizeForRequest(url_, sanitized_referrer_); | |
148 is_external_protocol_ = new_is_external_protocol; | |
149 | |
150 // Have each throttle be notified of the request. | |
151 for (NavigationThrottle* throttle : throttles_) { | |
152 NavigationThrottle::ThrottleCheckResult result = | |
153 throttle->WillRedirectRequest(); | |
154 if (result == NavigationThrottle::CANCEL_AND_IGNORE) | |
155 return NavigationThrottle::CANCEL_AND_IGNORE; | |
156 } | |
157 return NavigationThrottle::PROCEED; | |
158 } | |
159 | |
57 void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) { | 160 void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) { |
58 url_ = new_url; | 161 url_ = new_url; |
59 delegate_->DidRedirectNavigation(this); | 162 delegate_->DidRedirectNavigation(this); |
60 } | 163 } |
61 | 164 |
62 void NavigationHandleImpl::DidCommitNavigation() { | 165 void NavigationHandleImpl::DidCommitNavigation() { |
63 state_ = net_error_code_ == net::OK ? DID_COMMIT : DID_COMMIT_ERROR_PAGE; | 166 state_ = net_error_code_ == net::OK ? DID_COMMIT : DID_COMMIT_ERROR_PAGE; |
64 delegate_->DidCommitNavigation(this); | 167 delegate_->DidCommitNavigation(this); |
65 } | 168 } |
66 | 169 |
67 } // namespace content | 170 } // namespace content |
OLD | NEW |