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

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

Powered by Google App Engine
This is Rietveld 408576698