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

Unified Diff: content/browser/service_worker/service_worker_request_handler.cc

Issue 2843043002: network service: Create URLLoader for service worker navigation case
Patch Set: fix rebase Created 3 years, 7 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/service_worker/service_worker_request_handler.cc
diff --git a/content/browser/service_worker/service_worker_request_handler.cc b/content/browser/service_worker/service_worker_request_handler.cc
index e23397d4b726c0daf1b7e9f0c6d321d25621d110..4455262e54f8951e460a1b4596578b5009168887 100644
--- a/content/browser/service_worker/service_worker_request_handler.cc
+++ b/content/browser/service_worker/service_worker_request_handler.cc
@@ -55,34 +55,34 @@ class ServiceWorkerRequestInterceptor
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRequestInterceptor);
};
-void FinalizeHandlerInitialization(
- net::URLRequest* request,
- ServiceWorkerProviderHost* provider_host,
+} // namespace
+
+// PlzNavigate
+void ServiceWorkerRequestHandler::InitializeForNavigation(
+ net::URLRequest* url_request,
+ ServiceWorkerNavigationHandleCore* navigation_handle_core,
storage::BlobStorageContext* blob_storage_context,
bool skip_service_worker,
- FetchRequestMode request_mode,
- FetchCredentialsMode credentials_mode,
- FetchRedirectMode redirect_mode,
ResourceType resource_type,
RequestContextType request_context_type,
RequestContextFrameType frame_type,
- scoped_refptr<ResourceRequestBodyImpl> body) {
- std::unique_ptr<ServiceWorkerRequestHandler> handler(
- provider_host->CreateRequestHandler(
- request_mode, credentials_mode, redirect_mode, resource_type,
- request_context_type, frame_type, blob_storage_context->AsWeakPtr(),
- body, skip_service_worker));
- if (!handler)
- return;
-
- request->SetUserData(&kUserDataKey, std::move(handler));
+ bool is_parent_frame_secure,
+ scoped_refptr<ResourceRequestBodyImpl> body,
+ const base::Callback<WebContents*(void)>& web_contents_getter) {
+ auto handler = InitializeForNavigationInternal(
+ url_request->url(), navigation_handle_core, blob_storage_context,
+ skip_service_worker, resource_type, request_context_type, frame_type,
+ is_parent_frame_secure, body, web_contents_getter,
+ NetworkFallbackCallback());
+ if (handler)
+ url_request->SetUserData(&kUserDataKey, std::move(handler));
}
-} // namespace
-
-// PlzNavigate
-void ServiceWorkerRequestHandler::InitializeForNavigation(
- net::URLRequest* request,
+// PlzNavigate and --enable-network-service
+mojom::URLLoaderFactoryPtrInfo
+ServiceWorkerRequestHandler::InitializeForNavigationNetworkService(
+ const ResourceRequest& resource_request,
+ ResourceContext* resource_context,
ServiceWorkerNavigationHandleCore* navigation_handle_core,
storage::BlobStorageContext* blob_storage_context,
bool skip_service_worker,
@@ -91,44 +91,18 @@ void ServiceWorkerRequestHandler::InitializeForNavigation(
RequestContextFrameType frame_type,
bool is_parent_frame_secure,
scoped_refptr<ResourceRequestBodyImpl> body,
- const base::Callback<WebContents*(void)>& web_contents_getter) {
- CHECK(IsBrowserSideNavigationEnabled());
-
- // Only create a handler when there is a ServiceWorkerNavigationHandlerCore
- // to take ownership of a pre-created SeviceWorkerProviderHost.
- if (!navigation_handle_core)
- return;
-
- // Create the handler even for insecure HTTP since it's used in the
- // case of redirect to HTTPS.
- if (!request->url().SchemeIsHTTPOrHTTPS() &&
- !OriginCanAccessServiceWorkers(request->url())) {
- return;
+ const base::Callback<WebContents*(void)>& web_contents_getter,
+ NetworkFallbackCallback network_fallback_callback) {
+ auto handler = InitializeForNavigationInternal(
+ resource_request.url, navigation_handle_core, blob_storage_context,
+ skip_service_worker, resource_type, request_context_type, frame_type,
+ is_parent_frame_secure, body, web_contents_getter,
+ network_fallback_callback);
+ if (handler) {
+ return handler->MaybeGetURLLoaderFactory(resource_request, resource_context,
+ std::move(handler));
}
-
- if (!navigation_handle_core->context_wrapper() ||
- !navigation_handle_core->context_wrapper()->context()) {
- return;
- }
-
- // Initialize the SWProviderHost.
- std::unique_ptr<ServiceWorkerProviderHost> provider_host =
- ServiceWorkerProviderHost::PreCreateNavigationHost(
- navigation_handle_core->context_wrapper()->context()->AsWeakPtr(),
- is_parent_frame_secure, web_contents_getter);
-
- FinalizeHandlerInitialization(
- request, provider_host.get(), blob_storage_context, skip_service_worker,
- FETCH_REQUEST_MODE_NAVIGATE, FETCH_CREDENTIALS_MODE_INCLUDE,
- FetchRedirectMode::MANUAL_MODE, resource_type, request_context_type,
- frame_type, body);
-
- // Transfer ownership to the ServiceWorkerNavigationHandleCore.
- // In the case of a successful navigation, the SWProviderHost will be
- // transferred to its "final" destination in the OnProviderCreated handler. If
- // the navigation fails, it will be destroyed along with the
- // ServiceWorkerNavigationHandleCore.
- navigation_handle_core->DidPreCreateProviderHost(std::move(provider_host));
+ return mojom::URLLoaderFactoryPtrInfo();
}
void ServiceWorkerRequestHandler::InitializeHandler(
@@ -162,10 +136,12 @@ void ServiceWorkerRequestHandler::InitializeHandler(
if (!provider_host || !provider_host->IsContextAlive())
return;
- FinalizeHandlerInitialization(request, provider_host, blob_storage_context,
- skip_service_worker, request_mode,
- credentials_mode, redirect_mode, resource_type,
- request_context_type, frame_type, body);
+ auto handler = provider_host->CreateRequestHandler(
+ request_mode, credentials_mode, redirect_mode, resource_type,
+ request_context_type, frame_type, blob_storage_context->AsWeakPtr(), body,
+ skip_service_worker, NetworkFallbackCallback());
+ if (handler)
+ request->SetUserData(&kUserDataKey, std::move(handler));
}
ServiceWorkerRequestHandler* ServiceWorkerRequestHandler::GetHandler(
@@ -252,4 +228,57 @@ ServiceWorkerRequestHandler::ServiceWorkerRequestHandler(
old_provider_id_(kInvalidServiceWorkerProviderId) {
}
+std::unique_ptr<ServiceWorkerRequestHandler>
+ServiceWorkerRequestHandler::InitializeForNavigationInternal(
+ const GURL& url,
+ ServiceWorkerNavigationHandleCore* navigation_handle_core,
+ storage::BlobStorageContext* blob_storage_context,
+ bool skip_service_worker,
+ ResourceType resource_type,
+ RequestContextType request_context_type,
+ RequestContextFrameType frame_type,
+ bool is_parent_frame_secure,
+ scoped_refptr<ResourceRequestBodyImpl> body,
+ const base::Callback<WebContents*(void)>& web_contents_getter,
+ NetworkFallbackCallback network_fallback_callback) {
+ CHECK(IsBrowserSideNavigationEnabled());
+
+ // Only create a handler when there is a ServiceWorkerNavigationHandlerCore
+ // to take ownership of a pre-created SeviceWorkerProviderHost.
+ if (!navigation_handle_core)
+ return nullptr;
+
+ // Create the handler even for insecure HTTP since it's used in the
+ // case of redirect to HTTPS.
+ if (!url.SchemeIsHTTPOrHTTPS() && !OriginCanAccessServiceWorkers(url)) {
+ return nullptr;
+ }
+
+ if (!navigation_handle_core->context_wrapper() ||
+ !navigation_handle_core->context_wrapper()->context()) {
+ return nullptr;
+ }
+
+ // Initialize the SWProviderHost.
+ std::unique_ptr<ServiceWorkerProviderHost> provider_host =
+ ServiceWorkerProviderHost::PreCreateNavigationHost(
+ navigation_handle_core->context_wrapper()->context()->AsWeakPtr(),
+ is_parent_frame_secure, web_contents_getter);
+
+ auto handler = provider_host->CreateRequestHandler(
+ FETCH_REQUEST_MODE_NAVIGATE, FETCH_CREDENTIALS_MODE_INCLUDE,
+ FetchRedirectMode::MANUAL_MODE, resource_type, request_context_type,
+ frame_type, blob_storage_context->AsWeakPtr(), body, skip_service_worker,
+ network_fallback_callback);
+
+ // Transfer ownership to the ServiceWorkerNavigationHandleCore.
+ // In the case of a successful navigation, the SWProviderHost will be
+ // transferred to its "final" destination in the OnProviderCreated handler. If
+ // the navigation fails, it will be destroyed along with the
+ // ServiceWorkerNavigationHandleCore.
+ navigation_handle_core->DidPreCreateProviderHost(std::move(provider_host));
+
+ return handler;
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698