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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/frame_host/navigation_request.cc
diff --git a/content/browser/frame_host/navigation_request.cc b/content/browser/frame_host/navigation_request.cc
index 4eaa5566320d115381f6af2e7dfd8ee510f9b7e5..47c945d30d6dd8f42b0f605aabe606d8a38a208b 100644
--- a/content/browser/frame_host/navigation_request.cc
+++ b/content/browser/frame_host/navigation_request.cc
@@ -16,7 +16,6 @@
#include "content/browser/frame_host/navigator_impl.h"
#include "content/browser/loader/navigation_url_loader.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
-#include "content/browser/service_worker/service_worker_navigation_handle.h"
#include "content/browser/site_instance_impl.h"
#include "content/common/resource_request_body_impl.h"
#include "content/public/browser/browser_context.h"
@@ -291,16 +290,6 @@ void NavigationRequest::OnResponseStarted(
return;
}
- // Update the service worker params of the request params.
- request_params_.should_create_service_worker =
- (frame_tree_node_->pending_sandbox_flags() &
- blink::WebSandboxFlags::Origin) != blink::WebSandboxFlags::Origin;
- if (navigation_handle_->service_worker_handle()) {
- request_params_.service_worker_provider_id =
- navigation_handle_->service_worker_handle()
- ->service_worker_provider_host_id();
- }
-
// Update the lofi state of the request.
if (response->head.is_using_lofi)
common_params_.lofi_state = LOFI_ON;
@@ -358,6 +347,14 @@ void NavigationRequest::OnRequestStarted(base::TimeTicks timestamp) {
common_params_.url);
}
+void NavigationRequest::OnServiceWorkerEncountered() {
+ request_params_.should_create_service_worker = true;
+
+ // TODO(clamy): the navigation should be sent to a RenderFrameHost to be
+ // picked up by the ServiceWorker.
+ NOTIMPLEMENTED();
+}
+
void NavigationRequest::OnStartChecksComplete(
NavigationThrottle::ThrottleCheckResult result) {
CHECK(result != NavigationThrottle::DEFER);
@@ -370,10 +367,29 @@ void NavigationRequest::OnStartChecksComplete(
return;
}
- InitializeServiceWorkerHandleIfNeeded();
+ // Use the SiteInstance of the navigating RenderFrameHost to get access to
+ // the StoragePartition. Using the url of the navigation will result in a
+ // wrong StoragePartition being picked when a WebView is navigating.
+ DCHECK_NE(AssociatedSiteInstanceType::NONE, associated_site_instance_type_);
+ RenderFrameHostImpl* navigating_frame_host =
+ associated_site_instance_type_ == AssociatedSiteInstanceType::SPECULATIVE
+ ? frame_tree_node_->render_manager()->speculative_frame_host()
+ : frame_tree_node_->current_frame_host();
+ DCHECK(navigating_frame_host);
+
+ BrowserContext* browser_context =
+ frame_tree_node_->navigator()->GetController()->GetBrowserContext();
+ StoragePartition* partition = BrowserContext::GetStoragePartition(
+ browser_context, navigating_frame_host->GetSiteInstance());
+ DCHECK(partition);
+
+ ServiceWorkerContextWrapper* service_worker_context =
+ static_cast<ServiceWorkerContextWrapper*>(
+ partition->GetServiceWorkerContext());
+
loader_ = NavigationURLLoader::Create(
frame_tree_node_->navigator()->GetController()->GetBrowserContext(),
- std::move(info_), navigation_handle_->service_worker_handle(), this);
+ std::move(info_), service_worker_context, this);
}
void NavigationRequest::OnRedirectChecksComplete(
@@ -435,34 +451,4 @@ void NavigationRequest::CommitNavigation() {
frame_tree_node_->ResetNavigationRequest(true);
}
-void NavigationRequest::InitializeServiceWorkerHandleIfNeeded() {
- // Only initialize the ServiceWorkerNavigationHandle if it can be created for
- // this frame.
- bool can_create_service_worker =
- (frame_tree_node_->pending_sandbox_flags() &
- blink::WebSandboxFlags::Origin) != blink::WebSandboxFlags::Origin;
- if (!can_create_service_worker)
- return;
-
- // Use the SiteInstance of the navigating RenderFrameHost to get access to
- // the StoragePartition. Using the url of the navigation will result in a
- // wrong StoragePartition being picked when a WebView is navigating.
- RenderFrameHostImpl* navigating_frame_host =
- frame_tree_node_->render_manager()->speculative_frame_host();
- if (!navigating_frame_host)
- navigating_frame_host = frame_tree_node_->current_frame_host();
- DCHECK(navigating_frame_host);
-
- BrowserContext* browser_context =
- frame_tree_node_->navigator()->GetController()->GetBrowserContext();
- StoragePartition* partition = BrowserContext::GetStoragePartition(
- browser_context, navigating_frame_host->GetSiteInstance());
- DCHECK(partition);
-
- ServiceWorkerContextWrapper* service_worker_context =
- static_cast<ServiceWorkerContextWrapper*>(
- partition->GetServiceWorkerContext());
- navigation_handle_->InitServiceWorkerHandle(service_worker_context);
-}
-
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698