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

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

Issue 2843043002: network service: Create URLLoader for service worker navigation case
Patch Set: network fallback in simple cases 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..418ef2137e0f7f39993c63f28a6d85dca09b3069 100644
--- a/content/browser/service_worker/service_worker_request_handler.cc
+++ b/content/browser/service_worker/service_worker_request_handler.cc
@@ -55,8 +55,20 @@ class ServiceWorkerRequestInterceptor
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRequestInterceptor);
};
+void AttachToURLRequest(net::URLRequest* url_request,
+ std::unique_ptr<ServiceWorkerRequestHandler> handler) {
+ url_request->SetUserData(&kUserDataKey, std::move(handler));
+}
+
+void CreateURLLoader(mojom::URLLoaderFactoryPtrInfo* url_loader_factory_info,
+ const ResourceRequest& resource_request,
+ ResourceContext* resource_context,
+ std::unique_ptr<ServiceWorkerRequestHandler> handler) {
+ *url_loader_factory_info = handler->MaybeCreateURLLoader(
+ resource_request, resource_context, std::move(handler));
+}
+
void FinalizeHandlerInitialization(
- net::URLRequest* request,
ServiceWorkerProviderHost* provider_host,
storage::BlobStorageContext* blob_storage_context,
bool skip_service_worker,
@@ -66,7 +78,8 @@ void FinalizeHandlerInitialization(
ResourceType resource_type,
RequestContextType request_context_type,
RequestContextFrameType frame_type,
- scoped_refptr<ResourceRequestBodyImpl> body) {
+ scoped_refptr<ResourceRequestBodyImpl> body,
+ const ServiceWorkerRequestHandler::HandlerCreated& on_created) {
std::unique_ptr<ServiceWorkerRequestHandler> handler(
provider_host->CreateRequestHandler(
request_mode, credentials_mode, redirect_mode, resource_type,
@@ -75,14 +88,14 @@ void FinalizeHandlerInitialization(
if (!handler)
return;
- request->SetUserData(&kUserDataKey, std::move(handler));
+ on_created.Run(std::move(handler));
kinuko 2017/05/08 14:55:47 I think this method and InitializeForNavigationInt
scottmg 2017/05/08 20:12:31 The only reason I did that the complicated way was
}
} // namespace
// PlzNavigate
void ServiceWorkerRequestHandler::InitializeForNavigation(
- net::URLRequest* request,
+ net::URLRequest* url_request,
ServiceWorkerNavigationHandleCore* navigation_handle_core,
storage::BlobStorageContext* blob_storage_context,
bool skip_service_worker,
@@ -92,43 +105,35 @@ void ServiceWorkerRequestHandler::InitializeForNavigation(
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;
- }
-
- 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);
+ InitializeForNavigationImpl(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,
+ base::Bind(&AttachToURLRequest, url_request));
+}
- // 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));
+// 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,
+ 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) {
+ mojom::URLLoaderFactoryPtrInfo result;
+ InitializeForNavigationImpl(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,
+ base::Bind(&CreateURLLoader, &result,
+ resource_request, resource_context));
+ return std::move(result);
}
void ServiceWorkerRequestHandler::InitializeHandler(
@@ -162,10 +167,10 @@ 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);
+ FinalizeHandlerInitialization(
+ provider_host, blob_storage_context, skip_service_worker, request_mode,
+ credentials_mode, redirect_mode, resource_type, request_context_type,
+ frame_type, body, base::Bind(&AttachToURLRequest, request));
}
ServiceWorkerRequestHandler* ServiceWorkerRequestHandler::GetHandler(
@@ -252,4 +257,54 @@ ServiceWorkerRequestHandler::ServiceWorkerRequestHandler(
old_provider_id_(kInvalidServiceWorkerProviderId) {
}
+void ServiceWorkerRequestHandler::InitializeForNavigationImpl(
+ 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,
+ const HandlerCreated& on_handler_created) {
+ 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 (!url.SchemeIsHTTPOrHTTPS() && !OriginCanAccessServiceWorkers(url)) {
+ return;
+ }
+
+ 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(
+ 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, on_handler_created);
+
+ // 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));
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698