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

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

Issue 2886843006: servificied service worker interception
Patch Set: 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 ac4edb2726094c1a3a7908b8bef7be7381dfa889..a35ec01541eab9903fc8173380526e4bb02fb5a9 100644
--- a/content/browser/service_worker/service_worker_request_handler.cc
+++ b/content/browser/service_worker/service_worker_request_handler.cc
@@ -57,34 +57,11 @@ class ServiceWorkerRequestInterceptor
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRequestInterceptor);
};
-void FinalizeHandlerInitialization(
- net::URLRequest* request,
- ServiceWorkerProviderHost* provider_host,
- 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));
-}
-
} // 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,
@@ -94,46 +71,18 @@ 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);
-
- // 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));
+ 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);
+#if 0
+ NetworkFallbackCallback());
+#endif
+ if (handler)
+ url_request->SetUserData(&kUserDataKey, std::move(handler));
}
-// PlzNavigate and --enable-network-service.
+// PlzNavigate and --enable-network-service
// static
mojom::URLLoaderFactoryPtr
ServiceWorkerRequestHandler::InitializeForNavigationNetworkService(
@@ -147,11 +96,26 @@ ServiceWorkerRequestHandler::InitializeForNavigationNetworkService(
RequestContextFrameType frame_type,
bool is_parent_frame_secure,
scoped_refptr<ResourceRequestBodyImpl> body,
+#if 0
+ const base::Callback<WebContents*(void)>& web_contents_getter,
+ NetworkFallbackCallback network_fallback_callback) {
+#endif
const base::Callback<WebContents*(void)>& web_contents_getter) {
DCHECK(IsBrowserSideNavigationEnabled() &&
base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableNetworkService));
- // TODO(scottmg): Currently being implemented. See https://crbug.com/715640.
+ std::unique_ptr<ServiceWorkerRequestHandler> 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);
+#if 0
+ network_fallback_callback);
+#endif
+ if (handler) {
+ return handler->MaybeGetURLLoaderFactory(resource_request, resource_context,
+ std::move(handler));
+ }
return mojom::URLLoaderFactoryPtr();
}
@@ -186,10 +150,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);
+ if (handler)
+ request->SetUserData(&kUserDataKey, std::move(handler));
}
ServiceWorkerRequestHandler* ServiceWorkerRequestHandler::GetHandler(
@@ -220,6 +186,14 @@ ServiceWorkerProviderHost* ServiceWorkerRequestHandler::GetProviderHost(
return handler ? handler->provider_host_.get() : nullptr;
}
+mojom::URLLoaderFactoryPtr
+ServiceWorkerRequestHandler::MaybeGetURLLoaderFactory(
+ const ResourceRequest& resource_request,
+ ResourceContext* resource_context,
+ std::unique_ptr<ServiceWorkerRequestHandler> request_handler) {
+ return mojom::URLLoaderFactoryPtr();
+}
+
void ServiceWorkerRequestHandler::PrepareForCrossSiteTransfer(
int old_process_id) {
CHECK(!IsBrowserSideNavigationEnabled());
@@ -276,4 +250,59 @@ 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,
+#if 0
+ const base::Callback<WebContents*(void)>& web_contents_getter,
+ NetworkFallbackCallback network_fallback_callback) {
+#endif
+ 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 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);
+
+ // 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