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

Side by Side Diff: content/browser/frame_host/navigation_request.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: Rebase on https://codereview.chromium.org/1312213010/ 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_request.h" 5 #include "content/browser/frame_host/navigation_request.h"
6 6
7 #include "content/browser/frame_host/frame_tree.h" 7 #include "content/browser/frame_host/frame_tree.h"
8 #include "content/browser/frame_host/frame_tree_node.h" 8 #include "content/browser/frame_host/frame_tree_node.h"
9 #include "content/browser/frame_host/navigation_controller_impl.h" 9 #include "content/browser/frame_host/navigation_controller_impl.h"
10 #include "content/browser/frame_host/navigation_handle_impl.h" 10 #include "content/browser/frame_host/navigation_handle_impl.h"
11 #include "content/browser/frame_host/navigation_request_info.h" 11 #include "content/browser/frame_host/navigation_request_info.h"
12 #include "content/browser/frame_host/navigator.h" 12 #include "content/browser/frame_host/navigator.h"
13 #include "content/browser/loader/navigation_url_loader.h" 13 #include "content/browser/loader/navigation_url_loader.h"
14 #include "content/browser/site_instance_impl.h" 14 #include "content/browser/site_instance_impl.h"
15 #include "content/common/resource_request_body.h" 15 #include "content/common/resource_request_body.h"
16 #include "content/public/browser/navigation_controller.h" 16 #include "content/public/browser/navigation_controller.h"
17 #include "content/public/browser/navigation_throttle.h"
17 #include "content/public/browser/stream_handle.h" 18 #include "content/public/browser/stream_handle.h"
18 #include "content/public/common/content_client.h" 19 #include "content/public/common/content_client.h"
19 #include "net/base/load_flags.h" 20 #include "net/base/load_flags.h"
20 #include "net/http/http_request_headers.h" 21 #include "net/http/http_request_headers.h"
21 #include "net/url_request/redirect_info.h" 22 #include "net/url_request/redirect_info.h"
22 23
23 namespace content { 24 namespace content {
24 25
25 namespace { 26 namespace {
26 27
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 173
173 NavigationRequest::~NavigationRequest() { 174 NavigationRequest::~NavigationRequest() {
174 } 175 }
175 176
176 bool NavigationRequest::BeginNavigation() { 177 bool NavigationRequest::BeginNavigation() {
177 DCHECK(!loader_); 178 DCHECK(!loader_);
178 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); 179 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE);
179 state_ = STARTED; 180 state_ = STARTED;
180 181
181 if (ShouldMakeNetworkRequestForURL(common_params_.url)) { 182 if (ShouldMakeNetworkRequestForURL(common_params_.url)) {
183 // TODO(clamy): pass the real value for |is_external_protocol| if needed.
184 NavigationThrottle::ThrottleCheckResult result =
185 navigation_handle_->WillStartRequest(
186 begin_params_.method == "POST",
187 Referrer::SanitizeForRequest(common_params_.url,
188 common_params_.referrer),
189 begin_params_.has_user_gesture, common_params_.transition, false);
190
191 // Abort the request if needed. This will destroy the NavigationRequest.
192 if (result == NavigationThrottle::CANCEL_AND_IGNORE) {
193 frame_tree_node_->ResetNavigationRequest(false);
194 return false;
195 }
196
182 loader_ = NavigationURLLoader::Create( 197 loader_ = NavigationURLLoader::Create(
183 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), 198 frame_tree_node_->navigator()->GetController()->GetBrowserContext(),
184 frame_tree_node_->frame_tree_node_id(), info_.Pass(), this); 199 frame_tree_node_->frame_tree_node_id(), info_.Pass(), this);
185 return true; 200 return true;
186 } 201 }
187 202
188 // There is no need to make a network request for this navigation, so commit 203 // There is no need to make a network request for this navigation, so commit
189 // it immediately. 204 // it immediately.
190 state_ = RESPONSE_STARTED; 205 state_ = RESPONSE_STARTED;
191 frame_tree_node_->navigator()->CommitNavigation( 206 frame_tree_node_->navigator()->CommitNavigation(
(...skipping 10 matching lines...) Expand all
202 } 217 }
203 218
204 void NavigationRequest::TransferNavigationHandleOwnership( 219 void NavigationRequest::TransferNavigationHandleOwnership(
205 RenderFrameHostImpl* render_frame_host) { 220 RenderFrameHostImpl* render_frame_host) {
206 render_frame_host->SetNavigationHandle(navigation_handle_.Pass()); 221 render_frame_host->SetNavigationHandle(navigation_handle_.Pass());
207 } 222 }
208 223
209 void NavigationRequest::OnRequestRedirected( 224 void NavigationRequest::OnRequestRedirected(
210 const net::RedirectInfo& redirect_info, 225 const net::RedirectInfo& redirect_info,
211 const scoped_refptr<ResourceResponse>& response) { 226 const scoped_refptr<ResourceResponse>& response) {
212 // TODO(davidben): Track other changes from redirects. These are important
213 // for, e.g., reloads.
214 common_params_.url = redirect_info.new_url; 227 common_params_.url = redirect_info.new_url;
228 begin_params_.method = redirect_info.new_method;
229 common_params_.referrer.url = GURL(redirect_info.new_referrer);
215 230
216 // TODO(davidben): This where prerender and navigation_interceptor should be 231 // TODO(clamy): Have CSP + security upgrade checks here.
217 // integrated. For now, just always follow all redirects. 232 // TODO(clamy): Kill the renderer if FilterURL fails?
233 // TODO(clamy): pass the real value for |is_external_protocol| if needed.
234 NavigationThrottle::ThrottleCheckResult result =
235 navigation_handle_->WillRedirectRequest(
236 common_params_.url, begin_params_.method == "POST",
237 common_params_.referrer.url, false);
238
239 // Abort the request if needed. This will destroy the NavigationRequest.
240 if (result == NavigationThrottle::CANCEL_AND_IGNORE) {
241 frame_tree_node_->ResetNavigationRequest(false);
242 return;
243 }
244
218 loader_->FollowRedirect(); 245 loader_->FollowRedirect();
219 246
220 navigation_handle_->DidRedirectNavigation(redirect_info.new_url); 247 navigation_handle_->DidRedirectNavigation(redirect_info.new_url);
221 } 248 }
222 249
223 void NavigationRequest::OnResponseStarted( 250 void NavigationRequest::OnResponseStarted(
224 const scoped_refptr<ResourceResponse>& response, 251 const scoped_refptr<ResourceResponse>& response,
225 scoped_ptr<StreamHandle> body) { 252 scoped_ptr<StreamHandle> body) {
226 DCHECK(state_ == STARTED); 253 DCHECK(state_ == STARTED);
227 state_ = RESPONSE_STARTED; 254 state_ = RESPONSE_STARTED;
228 frame_tree_node_->navigator()->CommitNavigation(frame_tree_node_, 255 frame_tree_node_->navigator()->CommitNavigation(frame_tree_node_,
229 response.get(), body.Pass()); 256 response.get(), body.Pass());
230 } 257 }
231 258
232 void NavigationRequest::OnRequestFailed(bool has_stale_copy_in_cache, 259 void NavigationRequest::OnRequestFailed(bool has_stale_copy_in_cache,
233 int net_error) { 260 int net_error) {
234 DCHECK(state_ == STARTED); 261 DCHECK(state_ == STARTED);
235 state_ = FAILED; 262 state_ = FAILED;
236 navigation_handle_->set_net_error_code(static_cast<net::Error>(net_error)); 263 navigation_handle_->set_net_error_code(static_cast<net::Error>(net_error));
237 frame_tree_node_->navigator()->FailedNavigation( 264 frame_tree_node_->navigator()->FailedNavigation(
238 frame_tree_node_, has_stale_copy_in_cache, net_error); 265 frame_tree_node_, has_stale_copy_in_cache, net_error);
239 } 266 }
240 267
241 void NavigationRequest::OnRequestStarted(base::TimeTicks timestamp) { 268 void NavigationRequest::OnRequestStarted(base::TimeTicks timestamp) {
242 frame_tree_node_->navigator()->LogResourceRequestTime(timestamp, 269 frame_tree_node_->navigator()->LogResourceRequestTime(timestamp,
243 common_params_.url); 270 common_params_.url);
244 } 271 }
245 272
246 } // namespace content 273 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigation_request.h ('k') | content/browser/frame_host/navigator_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698