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

Side by Side 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, 3 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 unified diff | Download patch
OLDNEW
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 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
58 << "This accessor should not be called before the request is started.";
59 return is_post_;
60 }
61
62 const Referrer& NavigationHandleImpl::GetSanitizedReferrer() const {
63 DCHECK(state_ != DID_START)
64 << "This accessor should not be called before the request is started.";
65 return sanitized_referrer_;
66 }
67
68 bool NavigationHandleImpl::HasUserGesture() const {
69 DCHECK(state_ != DID_START)
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 DCHECK(state_ != DID_START)
76 << "This accessor should not be called before the request is started.";
77 return transition_;
78 }
79
80 bool NavigationHandleImpl::IsExternalProtocol() const {
81 DCHECK(state_ != DID_START)
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::RegisterThrottle(
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 delegate_->AddNavigationThrottles(this);
120
121 // 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.
122 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
123 NavigationThrottle::ThrottleCheckResult result = (*it)->WillStartRequest();
124 if (result == NavigationThrottle::CANCEL_AND_IGNORE)
125 return NavigationThrottle::CANCEL_AND_IGNORE;
126 }
127 return NavigationThrottle::PROCEED;
128 }
129
130 NavigationThrottle::ThrottleCheckResult
131 NavigationHandleImpl::WillRedirectRequest(const GURL& new_url,
132 const GURL& new_validated_url,
133 bool new_method_is_post,
134 const GURL& new_referrer_url,
135 bool new_is_external_protocol) {
136 // Update the navigation parameters.
137 url_ = new_url;
138 validated_url_ = new_validated_url;
139 is_post_ = new_method_is_post;
140 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
141 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
142 is_external_protocol_ = new_is_external_protocol;
143
144 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
145
146 // Have each throttle be notified of the request.
147 for (auto it = throttles_.begin(); it != throttles_.end(); ++it) {
148 NavigationThrottle::ThrottleCheckResult result =
149 (*it)->WillRedirectRequest();
150 if (result == NavigationThrottle::CANCEL_AND_IGNORE)
151 return NavigationThrottle::CANCEL_AND_IGNORE;
152 }
153 return NavigationThrottle::PROCEED;
154 }
155
57 void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) { 156 void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) {
58 url_ = new_url; 157 url_ = new_url;
59 delegate_->DidRedirectNavigation(this); 158 delegate_->DidRedirectNavigation(this);
60 } 159 }
61 160
62 void NavigationHandleImpl::DidCommitNavigation() { 161 void NavigationHandleImpl::DidCommitNavigation() {
63 state_ = net_error_code_ == net::OK ? DID_COMMIT : DID_COMMIT_ERROR_PAGE; 162 state_ = net_error_code_ == net::OK ? DID_COMMIT : DID_COMMIT_ERROR_PAGE;
64 delegate_->DidCommitNavigation(this); 163 delegate_->DidCommitNavigation(this);
65 } 164 }
66 165
67 } // namespace content 166 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698