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

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

Issue 2045383002: PlzNavigate: detect when a ServiceWorker is present (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments 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"
20 #include "content/browser/site_instance_impl.h" 19 #include "content/browser/site_instance_impl.h"
21 #include "content/common/resource_request_body_impl.h" 20 #include "content/common/resource_request_body_impl.h"
22 #include "content/public/browser/browser_context.h" 21 #include "content/public/browser/browser_context.h"
23 #include "content/public/browser/navigation_controller.h" 22 #include "content/public/browser/navigation_controller.h"
24 #include "content/public/browser/navigation_data.h" 23 #include "content/public/browser/navigation_data.h"
25 #include "content/public/browser/storage_partition.h" 24 #include "content/public/browser/storage_partition.h"
26 #include "content/public/browser/stream_handle.h" 25 #include "content/public/browser/stream_handle.h"
27 #include "content/public/common/content_client.h" 26 #include "content/public/common/content_client.h"
28 #include "content/public/common/resource_response.h" 27 #include "content/public/common/resource_response.h"
29 #include "net/base/load_flags.h" 28 #include "net/base/load_flags.h"
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 // HTTP 204 (No Content) and HTTP 205 (Reset Content) responses should not 282 // HTTP 204 (No Content) and HTTP 205 (Reset Content) responses should not
284 // commit; they leave the frame showing the previous page. 283 // commit; they leave the frame showing the previous page.
285 DCHECK(response); 284 DCHECK(response);
286 if (response->head.headers.get() && 285 if (response->head.headers.get() &&
287 (response->head.headers->response_code() == 204 || 286 (response->head.headers->response_code() == 204 ||
288 response->head.headers->response_code() == 205)) { 287 response->head.headers->response_code() == 205)) {
289 frame_tree_node_->ResetNavigationRequest(false); 288 frame_tree_node_->ResetNavigationRequest(false);
290 return; 289 return;
291 } 290 }
292 291
293 // Update the service worker params of the request params.
294 request_params_.should_create_service_worker =
295 (frame_tree_node_->pending_sandbox_flags() &
296 blink::WebSandboxFlags::Origin) != blink::WebSandboxFlags::Origin;
297 if (navigation_handle_->service_worker_handle()) {
298 request_params_.service_worker_provider_id =
299 navigation_handle_->service_worker_handle()
300 ->service_worker_provider_host_id();
301 }
302
303 // Update the lofi state of the request. 292 // Update the lofi state of the request.
304 if (response->head.is_using_lofi) 293 if (response->head.is_using_lofi)
305 common_params_.lofi_state = LOFI_ON; 294 common_params_.lofi_state = LOFI_ON;
306 else 295 else
307 common_params_.lofi_state = LOFI_OFF; 296 common_params_.lofi_state = LOFI_OFF;
308 297
309 // Select an appropriate renderer to commit the navigation. 298 // Select an appropriate renderer to commit the navigation.
310 RenderFrameHostImpl* render_frame_host = 299 RenderFrameHostImpl* render_frame_host =
311 frame_tree_node_->render_manager()->GetFrameHostForNavigation(*this); 300 frame_tree_node_->render_manager()->GetFrameHostForNavigation(*this);
312 NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL(render_frame_host, 301 NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL(render_frame_host,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 if (frame_tree_node_->IsMainFrame()) { 339 if (frame_tree_node_->IsMainFrame()) {
351 TRACE_EVENT_ASYNC_END_WITH_TIMESTAMP0( 340 TRACE_EVENT_ASYNC_END_WITH_TIMESTAMP0(
352 "navigation", "Navigation timeToNetworkStack", navigation_handle_.get(), 341 "navigation", "Navigation timeToNetworkStack", navigation_handle_.get(),
353 timestamp.ToInternalValue()); 342 timestamp.ToInternalValue());
354 } 343 }
355 344
356 frame_tree_node_->navigator()->LogResourceRequestTime(timestamp, 345 frame_tree_node_->navigator()->LogResourceRequestTime(timestamp,
357 common_params_.url); 346 common_params_.url);
358 } 347 }
359 348
349 void NavigationRequest::OnServiceWorkerEncountered() {
350 request_params_.should_create_service_worker = true;
351
352 // TODO(clamy): the navigation should be sent to a RenderFrameHost to be
353 // picked up by the ServiceWorker.
354 NOTIMPLEMENTED();
355 }
356
360 void NavigationRequest::OnStartChecksComplete( 357 void NavigationRequest::OnStartChecksComplete(
361 NavigationThrottle::ThrottleCheckResult result) { 358 NavigationThrottle::ThrottleCheckResult result) {
362 CHECK(result != NavigationThrottle::DEFER); 359 CHECK(result != NavigationThrottle::DEFER);
363 360
364 // Abort the request if needed. This will destroy the NavigationRequest. 361 // Abort the request if needed. This will destroy the NavigationRequest.
365 if (result == NavigationThrottle::CANCEL_AND_IGNORE || 362 if (result == NavigationThrottle::CANCEL_AND_IGNORE ||
366 result == NavigationThrottle::CANCEL) { 363 result == NavigationThrottle::CANCEL) {
367 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE. 364 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE.
368 frame_tree_node_->ResetNavigationRequest(false); 365 frame_tree_node_->ResetNavigationRequest(false);
369 return; 366 return;
370 } 367 }
371 368
372 InitializeServiceWorkerHandleIfNeeded(); 369 // Use the SiteInstance of the navigating RenderFrameHost to get access to
370 // the StoragePartition. Using the url of the navigation will result in a
371 // wrong StoragePartition being picked when a WebView is navigating.
372 DCHECK_NE(AssociatedSiteInstanceType::NONE, associated_site_instance_type_);
373 RenderFrameHostImpl* navigating_frame_host =
374 associated_site_instance_type_ == AssociatedSiteInstanceType::SPECULATIVE
375 ? frame_tree_node_->render_manager()->speculative_frame_host()
376 : frame_tree_node_->current_frame_host();
377 DCHECK(navigating_frame_host);
378
379 BrowserContext* browser_context =
380 frame_tree_node_->navigator()->GetController()->GetBrowserContext();
381 StoragePartition* partition = BrowserContext::GetStoragePartition(
382 browser_context, navigating_frame_host->GetSiteInstance());
383 DCHECK(partition);
384
385 ServiceWorkerContextWrapper* service_worker_context =
386 static_cast<ServiceWorkerContextWrapper*>(
387 partition->GetServiceWorkerContext());
388
373 loader_ = NavigationURLLoader::Create( 389 loader_ = NavigationURLLoader::Create(
374 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), 390 frame_tree_node_->navigator()->GetController()->GetBrowserContext(),
375 std::move(info_), navigation_handle_->service_worker_handle(), this); 391 std::move(info_), service_worker_context, this);
376 } 392 }
377 393
378 void NavigationRequest::OnRedirectChecksComplete( 394 void NavigationRequest::OnRedirectChecksComplete(
379 NavigationThrottle::ThrottleCheckResult result) { 395 NavigationThrottle::ThrottleCheckResult result) {
380 CHECK(result != NavigationThrottle::DEFER); 396 CHECK(result != NavigationThrottle::DEFER);
381 397
382 // Abort the request if needed. This will destroy the NavigationRequest. 398 // Abort the request if needed. This will destroy the NavigationRequest.
383 if (result == NavigationThrottle::CANCEL_AND_IGNORE || 399 if (result == NavigationThrottle::CANCEL_AND_IGNORE ||
384 result == NavigationThrottle::CANCEL) { 400 result == NavigationThrottle::CANCEL) {
385 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE. 401 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 common_params_, request_params_, 443 common_params_, request_params_,
428 is_view_source_); 444 is_view_source_);
429 445
430 // When navigating to a Javascript url, the NavigationRequest is not stored 446 // When navigating to a Javascript url, the NavigationRequest is not stored
431 // in the FrameTreeNode. Therefore do not reset it, as this could cancel an 447 // in the FrameTreeNode. Therefore do not reset it, as this could cancel an
432 // existing pending navigation. 448 // existing pending navigation.
433 if (!common_params_.url.SchemeIs(url::kJavaScriptScheme)) 449 if (!common_params_.url.SchemeIs(url::kJavaScriptScheme))
434 frame_tree_node_->ResetNavigationRequest(true); 450 frame_tree_node_->ResetNavigationRequest(true);
435 } 451 }
436 452
437 void NavigationRequest::InitializeServiceWorkerHandleIfNeeded() {
438 // Only initialize the ServiceWorkerNavigationHandle if it can be created for
439 // this frame.
440 bool can_create_service_worker =
441 (frame_tree_node_->pending_sandbox_flags() &
442 blink::WebSandboxFlags::Origin) != blink::WebSandboxFlags::Origin;
443 if (!can_create_service_worker)
444 return;
445
446 // Use the SiteInstance of the navigating RenderFrameHost to get access to
447 // the StoragePartition. Using the url of the navigation will result in a
448 // wrong StoragePartition being picked when a WebView is navigating.
449 RenderFrameHostImpl* navigating_frame_host =
450 frame_tree_node_->render_manager()->speculative_frame_host();
451 if (!navigating_frame_host)
452 navigating_frame_host = frame_tree_node_->current_frame_host();
453 DCHECK(navigating_frame_host);
454
455 BrowserContext* browser_context =
456 frame_tree_node_->navigator()->GetController()->GetBrowserContext();
457 StoragePartition* partition = BrowserContext::GetStoragePartition(
458 browser_context, navigating_frame_host->GetSiteInstance());
459 DCHECK(partition);
460
461 ServiceWorkerContextWrapper* service_worker_context =
462 static_cast<ServiceWorkerContextWrapper*>(
463 partition->GetServiceWorkerContext());
464 navigation_handle_->InitServiceWorkerHandle(service_worker_context);
465 }
466
467 } // namespace content 453 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698