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

Side by Side Diff: content/browser/frame_host/navigation_request.cc

Issue 2002633002: PlzNavigate: fix issue preventing navigations to WebUIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Now checking when ready to commit Created 4 years, 6 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 <utility> 7 #include <utility>
8 8
9 #include "content/browser/devtools/render_frame_devtools_agent_host.h" 9 #include "content/browser/devtools/render_frame_devtools_agent_host.h"
10 #include "content/browser/frame_host/frame_tree.h" 10 #include "content/browser/frame_host/frame_tree.h"
11 #include "content/browser/frame_host/frame_tree_node.h" 11 #include "content/browser/frame_host/frame_tree_node.h"
12 #include "content/browser/frame_host/navigation_controller_impl.h" 12 #include "content/browser/frame_host/navigation_controller_impl.h"
13 #include "content/browser/frame_host/navigation_handle_impl.h" 13 #include "content/browser/frame_host/navigation_handle_impl.h"
14 #include "content/browser/frame_host/navigation_request_info.h" 14 #include "content/browser/frame_host/navigation_request_info.h"
15 #include "content/browser/frame_host/navigator.h" 15 #include "content/browser/frame_host/navigator.h"
16 #include "content/browser/frame_host/navigator_impl.h" 16 #include "content/browser/frame_host/navigator_impl.h"
17 #include "content/browser/loader/navigation_url_loader.h" 17 #include "content/browser/loader/navigation_url_loader.h"
18 #include "content/browser/service_worker/service_worker_context_wrapper.h" 18 #include "content/browser/service_worker/service_worker_context_wrapper.h"
19 #include "content/browser/service_worker/service_worker_navigation_handle.h" 19 #include "content/browser/service_worker/service_worker_navigation_handle.h"
20 #include "content/browser/site_instance_impl.h" 20 #include "content/browser/site_instance_impl.h"
21 #include "content/browser/webui/web_ui_impl.h"
21 #include "content/common/resource_request_body.h" 22 #include "content/common/resource_request_body.h"
22 #include "content/public/browser/browser_context.h" 23 #include "content/public/browser/browser_context.h"
23 #include "content/public/browser/navigation_controller.h" 24 #include "content/public/browser/navigation_controller.h"
24 #include "content/public/browser/navigation_data.h" 25 #include "content/public/browser/navigation_data.h"
25 #include "content/public/browser/storage_partition.h" 26 #include "content/public/browser/storage_partition.h"
26 #include "content/public/browser/stream_handle.h" 27 #include "content/public/browser/stream_handle.h"
27 #include "content/public/common/content_client.h" 28 #include "content/public/common/content_client.h"
28 #include "content/public/common/resource_response.h" 29 #include "content/public/common/resource_response.h"
29 #include "net/base/load_flags.h" 30 #include "net/base/load_flags.h"
30 #include "net/http/http_request_headers.h" 31 #include "net/http/http_request_headers.h"
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 base::Unretained(this))); 227 base::Unretained(this)));
227 return; 228 return;
228 } 229 }
229 230
230 // There is no need to make a network request for this navigation, so commit 231 // There is no need to make a network request for this navigation, so commit
231 // it immediately. 232 // it immediately.
232 state_ = RESPONSE_STARTED; 233 state_ = RESPONSE_STARTED;
233 234
234 // Select an appropriate RenderFrameHost. 235 // Select an appropriate RenderFrameHost.
235 RenderFrameHostImpl* render_frame_host = 236 RenderFrameHostImpl* render_frame_host =
236 frame_tree_node_->render_manager()->GetFrameHostForNavigation(*this); 237 frame_tree_node_->render_manager()->GetFrameHostForNavigation(this);
238
239 // Perform the appropriate checks for WebUIs.
237 NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL(render_frame_host, 240 NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL(render_frame_host,
238 common_params_.url); 241 common_params_.url);
242 if (!WebUIImpl::RenderProcessAllowedForURL(render_frame_host->GetProcess(),
243 common_params_.url)) {
244 frame_tree_node_->ResetNavigationRequest(false);
245 return;
246 }
239 247
240 // Inform the NavigationHandle that the navigation will commit. 248 // Inform the NavigationHandle that the navigation will commit.
241 navigation_handle_->ReadyToCommitNavigation(render_frame_host); 249 navigation_handle_->ReadyToCommitNavigation(render_frame_host);
242 250
243 CommitNavigation(); 251 CommitNavigation();
244 } 252 }
245 253
246 void NavigationRequest::CreateNavigationHandle(int pending_nav_entry_id) { 254 void NavigationRequest::CreateNavigationHandle(int pending_nav_entry_id) {
247 // TODO(nasko): Update the NavigationHandle creation to ensure that the 255 // TODO(nasko): Update the NavigationHandle creation to ensure that the
248 // proper values are specified for is_synchronous and is_srcdoc. 256 // proper values are specified for is_synchronous and is_srcdoc.
249 navigation_handle_ = NavigationHandleImpl::Create( 257 navigation_handle_ = NavigationHandleImpl::Create(
250 common_params_.url, frame_tree_node_, 258 common_params_.url, frame_tree_node_,
251 !browser_initiated_, 259 !browser_initiated_,
252 false, // is_synchronous 260 false, // is_synchronous
253 false, // is_srcdoc 261 false, // is_srcdoc
254 common_params_.navigation_start, pending_nav_entry_id); 262 common_params_.navigation_start, pending_nav_entry_id);
255 } 263 }
256 264
257 void NavigationRequest::TransferNavigationHandleOwnership( 265 void NavigationRequest::TransferNavigationHandleOwnership(
258 RenderFrameHostImpl* render_frame_host) { 266 RenderFrameHostImpl* render_frame_host) {
259 render_frame_host->SetNavigationHandle(std::move(navigation_handle_)); 267 render_frame_host->SetNavigationHandle(std::move(navigation_handle_));
260 } 268 }
261 269
270 StoragePartition* NavigationRequest::GetStoragePartitionForNavigation() {
Charlie Reis 2016/05/25 21:38:02 Is this needed anymore? If it's just cleanup, we
271 // Use the SiteInstance of the navigating RenderFrameHost to get access to
272 // the StoragePartition. Using the url of the navigation will result in a
273 // wrong StoragePartition being picked when a WebView is navigating.
274 DCHECK(associated_site_instance_type_ != AssociatedSiteInstanceType::NONE);
275 SiteInstance* navigation_site_instance =
276 associated_site_instance_type_ == AssociatedSiteInstanceType::CURRENT
277 ? frame_tree_node_->current_frame_host()->GetSiteInstance()
278 : frame_tree_node_->render_manager()
279 ->speculative_frame_host()
280 ->GetSiteInstance();
281 DCHECK(navigation_site_instance);
282
283 BrowserContext* browser_context =
284 frame_tree_node_->navigator()->GetController()->GetBrowserContext();
285 return BrowserContext::GetStoragePartition(browser_context,
286 navigation_site_instance);
287 }
288
262 void NavigationRequest::OnRequestRedirected( 289 void NavigationRequest::OnRequestRedirected(
263 const net::RedirectInfo& redirect_info, 290 const net::RedirectInfo& redirect_info,
264 const scoped_refptr<ResourceResponse>& response) { 291 const scoped_refptr<ResourceResponse>& response) {
265 // If the navigation is no longer a POST, the POST data should be reset. 292 // If the navigation is no longer a POST, the POST data should be reset.
266 if (redirect_info.new_method != "POST") 293 if (redirect_info.new_method != "POST")
267 post_data_ = nullptr; 294 post_data_ = nullptr;
268 295
269 common_params_.url = redirect_info.new_url; 296 common_params_.url = redirect_info.new_url;
270 common_params_.method = redirect_info.new_method; 297 common_params_.method = redirect_info.new_method;
271 common_params_.referrer.url = GURL(redirect_info.new_referrer); 298 common_params_.referrer.url = GURL(redirect_info.new_referrer);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 } 338 }
312 339
313 // Update the lofi state of the request. 340 // Update the lofi state of the request.
314 if (response->head.is_using_lofi) 341 if (response->head.is_using_lofi)
315 common_params_.lofi_state = LOFI_ON; 342 common_params_.lofi_state = LOFI_ON;
316 else 343 else
317 common_params_.lofi_state = LOFI_OFF; 344 common_params_.lofi_state = LOFI_OFF;
318 345
319 // Select an appropriate renderer to commit the navigation. 346 // Select an appropriate renderer to commit the navigation.
320 RenderFrameHostImpl* render_frame_host = 347 RenderFrameHostImpl* render_frame_host =
321 frame_tree_node_->render_manager()->GetFrameHostForNavigation(*this); 348 frame_tree_node_->render_manager()->GetFrameHostForNavigation(this);
349
350 // Perform the appropriate checks for WebUIs.
322 NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL(render_frame_host, 351 NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL(render_frame_host,
323 common_params_.url); 352 common_params_.url);
353 if (!WebUIImpl::RenderProcessAllowedForURL(render_frame_host->GetProcess(),
354 common_params_.url)) {
355 frame_tree_node_->ResetNavigationRequest(false);
356 return;
357 }
324 358
325 // For renderer-initiated navigations that are set to commit in a different 359 // For renderer-initiated navigations that are set to commit in a different
326 // renderer, allow the embedder to cancel the transfer. 360 // renderer, allow the embedder to cancel the transfer.
327 if (!browser_initiated_ && 361 if (!browser_initiated_ &&
328 render_frame_host != frame_tree_node_->current_frame_host() && 362 render_frame_host != frame_tree_node_->current_frame_host() &&
329 !frame_tree_node_->navigator() 363 !frame_tree_node_->navigator()
330 ->GetDelegate() 364 ->GetDelegate()
331 ->ShouldTransferNavigation()) { 365 ->ShouldTransferNavigation()) {
332 frame_tree_node_->ResetNavigationRequest(false); 366 frame_tree_node_->ResetNavigationRequest(false);
333 return; 367 return;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 480
447 void NavigationRequest::InitializeServiceWorkerHandleIfNeeded() { 481 void NavigationRequest::InitializeServiceWorkerHandleIfNeeded() {
448 // Only initialize the ServiceWorkerNavigationHandle if it can be created for 482 // Only initialize the ServiceWorkerNavigationHandle if it can be created for
449 // this frame. 483 // this frame.
450 bool can_create_service_worker = 484 bool can_create_service_worker =
451 (frame_tree_node_->pending_sandbox_flags() & 485 (frame_tree_node_->pending_sandbox_flags() &
452 blink::WebSandboxFlags::Origin) != blink::WebSandboxFlags::Origin; 486 blink::WebSandboxFlags::Origin) != blink::WebSandboxFlags::Origin;
453 if (!can_create_service_worker) 487 if (!can_create_service_worker)
454 return; 488 return;
455 489
456 // Use the SiteInstance of the navigating RenderFrameHost to get access to
457 // the StoragePartition. Using the url of the navigation will result in a
458 // wrong StoragePartition being picked when a WebView is navigating.
459 RenderFrameHostImpl* navigating_frame_host =
460 frame_tree_node_->render_manager()->speculative_frame_host();
461 if (!navigating_frame_host)
462 navigating_frame_host = frame_tree_node_->current_frame_host();
463 DCHECK(navigating_frame_host);
464
465 BrowserContext* browser_context =
466 frame_tree_node_->navigator()->GetController()->GetBrowserContext();
467 StoragePartition* partition = BrowserContext::GetStoragePartition(
468 browser_context, navigating_frame_host->GetSiteInstance());
469 DCHECK(partition);
470
471 ServiceWorkerContextWrapper* service_worker_context = 490 ServiceWorkerContextWrapper* service_worker_context =
472 static_cast<ServiceWorkerContextWrapper*>( 491 static_cast<ServiceWorkerContextWrapper*>(
473 partition->GetServiceWorkerContext()); 492 GetStoragePartitionForNavigation()->GetServiceWorkerContext());
474 navigation_handle_->InitServiceWorkerHandle(service_worker_context); 493 navigation_handle_->InitServiceWorkerHandle(service_worker_context);
475 } 494 }
476 495
477 } // namespace content 496 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698