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

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 15 matching lines...) Expand all
42 case FrameMsg_Navigate_Type::RESTORE_WITH_POST: 44 case FrameMsg_Navigate_Type::RESTORE_WITH_POST:
43 load_flags |= net::LOAD_ONLY_FROM_CACHE; 45 load_flags |= net::LOAD_ONLY_FROM_CACHE;
44 break; 46 break;
45 case FrameMsg_Navigate_Type::NORMAL: 47 case FrameMsg_Navigate_Type::NORMAL:
46 default: 48 default:
47 break; 49 break;
48 } 50 }
49 return load_flags; 51 return load_flags;
50 } 52 }
51 53
54 // Filters the URL for the navigation based.
55 GURL FilterURL(const GURL& url, FrameTreeNode* frame_tree_node) {
56 RenderFrameHostImpl* render_frame_host =
57 frame_tree_node->render_manager()->speculative_frame_host()
58 ? frame_tree_node->render_manager()->speculative_frame_host()
59 : frame_tree_node->render_manager()->current_frame_host();
60 GURL filtered_url = url;
61 render_frame_host->GetProcess()->FilterURL(false, &filtered_url);
62 return filtered_url;
63 }
64
52 } // namespace 65 } // namespace
53 66
54 // static 67 // static
55 scoped_ptr<NavigationRequest> NavigationRequest::CreateBrowserInitiated( 68 scoped_ptr<NavigationRequest> NavigationRequest::CreateBrowserInitiated(
56 FrameTreeNode* frame_tree_node, 69 FrameTreeNode* frame_tree_node,
57 const GURL& dest_url, 70 const GURL& dest_url,
58 const Referrer& dest_referrer, 71 const Referrer& dest_referrer,
59 const FrameNavigationEntry& frame_entry, 72 const FrameNavigationEntry& frame_entry,
60 const NavigationEntryImpl& entry, 73 const NavigationEntryImpl& entry,
61 FrameMsg_Navigate_Type::Value navigation_type, 74 FrameMsg_Navigate_Type::Value navigation_type,
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 185
173 NavigationRequest::~NavigationRequest() { 186 NavigationRequest::~NavigationRequest() {
174 } 187 }
175 188
176 bool NavigationRequest::BeginNavigation() { 189 bool NavigationRequest::BeginNavigation() {
177 DCHECK(!loader_); 190 DCHECK(!loader_);
178 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); 191 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE);
179 state_ = STARTED; 192 state_ = STARTED;
180 193
181 if (ShouldMakeNetworkRequestForURL(common_params_.url)) { 194 if (ShouldMakeNetworkRequestForURL(common_params_.url)) {
195 // TODO(clamy): pass the real value for |is_external_protocol|.
196 NavigationThrottle::ThrottleCheckResult result =
197 navigation_handle_->WillStartRequest(
198 begin_params_.method == "POST",
199 Referrer::SanitizeForRequest(common_params_.url,
200 common_params_.referrer),
201 begin_params_.has_user_gesture, common_params_.transition, false);
202
203 // Abort the request if needed. This will destroy the NavigationRequest.
204 if (result == NavigationThrottle::CANCEL_AND_IGNORE) {
205 frame_tree_node_->ResetNavigationRequest(false);
206 return false;
207 }
208
182 loader_ = NavigationURLLoader::Create( 209 loader_ = NavigationURLLoader::Create(
183 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), 210 frame_tree_node_->navigator()->GetController()->GetBrowserContext(),
184 frame_tree_node_->frame_tree_node_id(), info_.Pass(), this); 211 frame_tree_node_->frame_tree_node_id(), info_.Pass(), this);
185 return true; 212 return true;
186 } 213 }
187 214
188 // There is no need to make a network request for this navigation, so commit 215 // There is no need to make a network request for this navigation, so commit
189 // it immediately. 216 // it immediately.
190 state_ = RESPONSE_STARTED; 217 state_ = RESPONSE_STARTED;
191 frame_tree_node_->navigator()->CommitNavigation( 218 frame_tree_node_->navigator()->CommitNavigation(
192 frame_tree_node_, nullptr, scoped_ptr<StreamHandle>()); 219 frame_tree_node_, nullptr, scoped_ptr<StreamHandle>());
193 return false; 220 return false;
194 221
195 // TODO(davidben): Fire (and add as necessary) observer methods such as 222 // TODO(davidben): Fire (and add as necessary) observer methods such as
196 // DidStartProvisionalLoadForFrame for the navigation. 223 // DidStartProvisionalLoadForFrame for the navigation.
197 } 224 }
198 225
199 void NavigationRequest::CreateNavigationHandle(NavigatorDelegate* delegate) { 226 void NavigationRequest::CreateNavigationHandle(NavigatorDelegate* delegate) {
200 navigation_handle_ = NavigationHandleImpl::Create( 227 navigation_handle_ = NavigationHandleFactory::Create(
201 common_params_.url, frame_tree_node_->IsMainFrame(), delegate); 228 common_params_.url, FilterURL(common_params_.url, frame_tree_node_),
229 frame_tree_node_->IsMainFrame(), delegate);
202 } 230 }
203 231
204 void NavigationRequest::TransferNavigationHandleOwnership( 232 void NavigationRequest::TransferNavigationHandleOwnership(
205 RenderFrameHostImpl* render_frame_host) { 233 RenderFrameHostImpl* render_frame_host) {
206 render_frame_host->SetNavigationHandle(navigation_handle_.Pass()); 234 render_frame_host->SetNavigationHandle(navigation_handle_.Pass());
207 } 235 }
208 236
209 void NavigationRequest::OnRequestRedirected( 237 void NavigationRequest::OnRequestRedirected(
210 const net::RedirectInfo& redirect_info, 238 const net::RedirectInfo& redirect_info,
211 const scoped_refptr<ResourceResponse>& response) { 239 const scoped_refptr<ResourceResponse>& response,
212 // TODO(davidben): Track other changes from redirects. These are important 240 bool is_external_protocol) {
213 // for, e.g., reloads.
214 common_params_.url = redirect_info.new_url; 241 common_params_.url = redirect_info.new_url;
242 begin_params_.method = redirect_info.new_method;
243 common_params_.referrer.url = GURL(redirect_info.new_referrer);
215 244
216 // TODO(davidben): This where prerender and navigation_interceptor should be 245 // TODO(clamy): Have CSP + security upgrade checks here.
217 // integrated. For now, just always follow all redirects. 246 // TODO(clamy): Kill the renderer if FilterURL fails?
247 const GURL filtered_new_url = FilterURL(common_params_.url, frame_tree_node_);
nasko 2015/09/04 00:01:52 nit: Why not use "validated_url", which we do comm
clamy 2015/09/08 16:27:18 Done.
248 NavigationThrottle::ThrottleCheckResult result =
249 navigation_handle_->WillRedirectRequest(
250 common_params_.url, filtered_new_url, begin_params_.method == "POST",
251 common_params_.referrer.url, is_external_protocol);
252
253 // Abort the request if needed. This will destroy the NavigationRequest.
254 if (result == NavigationThrottle::CANCEL_AND_IGNORE) {
255 frame_tree_node_->ResetNavigationRequest(false);
256 return;
257 }
258
218 loader_->FollowRedirect(); 259 loader_->FollowRedirect();
219 260
220 navigation_handle_->DidRedirectNavigation(redirect_info.new_url); 261 navigation_handle_->DidRedirectNavigation(redirect_info.new_url);
221 } 262 }
222 263
223 void NavigationRequest::OnResponseStarted( 264 void NavigationRequest::OnResponseStarted(
224 const scoped_refptr<ResourceResponse>& response, 265 const scoped_refptr<ResourceResponse>& response,
225 scoped_ptr<StreamHandle> body) { 266 scoped_ptr<StreamHandle> body) {
226 DCHECK(state_ == STARTED); 267 DCHECK(state_ == STARTED);
227 state_ = RESPONSE_STARTED; 268 state_ = RESPONSE_STARTED;
228 frame_tree_node_->navigator()->CommitNavigation(frame_tree_node_, 269 frame_tree_node_->navigator()->CommitNavigation(frame_tree_node_,
229 response.get(), body.Pass()); 270 response.get(), body.Pass());
230 } 271 }
231 272
232 void NavigationRequest::OnRequestFailed(bool has_stale_copy_in_cache, 273 void NavigationRequest::OnRequestFailed(bool has_stale_copy_in_cache,
233 int net_error) { 274 int net_error) {
234 DCHECK(state_ == STARTED); 275 DCHECK(state_ == STARTED);
235 state_ = FAILED; 276 state_ = FAILED;
236 navigation_handle_->set_net_error_code(static_cast<net::Error>(net_error)); 277 navigation_handle_->set_net_error_code(static_cast<net::Error>(net_error));
237 frame_tree_node_->navigator()->FailedNavigation( 278 frame_tree_node_->navigator()->FailedNavigation(
238 frame_tree_node_, has_stale_copy_in_cache, net_error); 279 frame_tree_node_, has_stale_copy_in_cache, net_error);
239 } 280 }
240 281
241 void NavigationRequest::OnRequestStarted(base::TimeTicks timestamp) { 282 void NavigationRequest::OnRequestStarted(base::TimeTicks timestamp) {
242 frame_tree_node_->navigator()->LogResourceRequestTime(timestamp, 283 frame_tree_node_->navigator()->LogResourceRequestTime(timestamp,
243 common_params_.url); 284 common_params_.url);
244 } 285 }
245 286
246 } // namespace content 287 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698