| OLD | NEW | 
|---|
| 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/service_worker/service_worker_request_handler.h" | 5 #include "content/browser/service_worker/service_worker_request_handler.h" | 
| 6 | 6 | 
| 7 #include <string> | 7 #include <string> | 
| 8 #include <utility> | 8 #include <utility> | 
| 9 | 9 | 
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
| 29 #include "ipc/ipc_message.h" | 29 #include "ipc/ipc_message.h" | 
| 30 #include "net/base/url_util.h" | 30 #include "net/base/url_util.h" | 
| 31 #include "net/url_request/url_request.h" | 31 #include "net/url_request/url_request.h" | 
| 32 #include "net/url_request/url_request_interceptor.h" | 32 #include "net/url_request/url_request_interceptor.h" | 
| 33 #include "storage/browser/blob/blob_storage_context.h" | 33 #include "storage/browser/blob/blob_storage_context.h" | 
| 34 | 34 | 
| 35 namespace content { | 35 namespace content { | 
| 36 | 36 | 
| 37 namespace { | 37 namespace { | 
| 38 | 38 | 
| 39 int kUserDataKey;  // Key value is not important. | 39 int kSWUserDataKey;  // Key value is not important. | 
| 40 | 40 | 
| 41 class ServiceWorkerRequestInterceptor | 41 class ServiceWorkerRequestInterceptor | 
| 42     : public net::URLRequestInterceptor { | 42     : public net::URLRequestInterceptor { | 
| 43  public: | 43  public: | 
| 44   explicit ServiceWorkerRequestInterceptor(ResourceContext* resource_context) | 44   explicit ServiceWorkerRequestInterceptor(ResourceContext* resource_context) | 
| 45       : resource_context_(resource_context) {} | 45       : resource_context_(resource_context) {} | 
| 46   ~ServiceWorkerRequestInterceptor() override {} | 46   ~ServiceWorkerRequestInterceptor() override {} | 
| 47   net::URLRequestJob* MaybeInterceptRequest( | 47   net::URLRequestJob* MaybeInterceptRequest( | 
| 48       net::URLRequest* request, | 48       net::URLRequest* request, | 
| 49       net::NetworkDelegate* network_delegate) const override { | 49       net::NetworkDelegate* network_delegate) const override { | 
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 99           navigation_handle_core->context_wrapper()->context()->AsWeakPtr(), | 99           navigation_handle_core->context_wrapper()->context()->AsWeakPtr(), | 
| 100           is_parent_frame_secure, web_contents_getter); | 100           is_parent_frame_secure, web_contents_getter); | 
| 101 | 101 | 
| 102   std::unique_ptr<ServiceWorkerRequestHandler> handler( | 102   std::unique_ptr<ServiceWorkerRequestHandler> handler( | 
| 103       provider_host->CreateRequestHandler( | 103       provider_host->CreateRequestHandler( | 
| 104           FETCH_REQUEST_MODE_NAVIGATE, FETCH_CREDENTIALS_MODE_INCLUDE, | 104           FETCH_REQUEST_MODE_NAVIGATE, FETCH_CREDENTIALS_MODE_INCLUDE, | 
| 105           FetchRedirectMode::MANUAL_MODE, std::string() /* integrity */, | 105           FetchRedirectMode::MANUAL_MODE, std::string() /* integrity */, | 
| 106           resource_type, request_context_type, frame_type, | 106           resource_type, request_context_type, frame_type, | 
| 107           blob_storage_context->AsWeakPtr(), body, skip_service_worker)); | 107           blob_storage_context->AsWeakPtr(), body, skip_service_worker)); | 
| 108   if (handler) | 108   if (handler) | 
| 109     request->SetUserData(&kUserDataKey, std::move(handler)); | 109     request->SetUserData(&kSWUserDataKey, std::move(handler)); | 
| 110 | 110 | 
| 111   // Transfer ownership to the ServiceWorkerNavigationHandleCore. | 111   // Transfer ownership to the ServiceWorkerNavigationHandleCore. | 
| 112   // In the case of a successful navigation, the SWProviderHost will be | 112   // In the case of a successful navigation, the SWProviderHost will be | 
| 113   // transferred to its "final" destination in the OnProviderCreated handler. If | 113   // transferred to its "final" destination in the OnProviderCreated handler. If | 
| 114   // the navigation fails, it will be destroyed along with the | 114   // the navigation fails, it will be destroyed along with the | 
| 115   // ServiceWorkerNavigationHandleCore. | 115   // ServiceWorkerNavigationHandleCore. | 
| 116   navigation_handle_core->DidPreCreateProviderHost(std::move(provider_host)); | 116   navigation_handle_core->DidPreCreateProviderHost(std::move(provider_host)); | 
| 117 } | 117 } | 
| 118 | 118 | 
| 119 // PlzNavigate and --enable-network-service. | 119 // PlzNavigate and --enable-network-service. | 
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 201       context_wrapper->context()->GetProviderHost(process_id, provider_id); | 201       context_wrapper->context()->GetProviderHost(process_id, provider_id); | 
| 202   if (!provider_host || !provider_host->IsContextAlive()) | 202   if (!provider_host || !provider_host->IsContextAlive()) | 
| 203     return; | 203     return; | 
| 204 | 204 | 
| 205   std::unique_ptr<ServiceWorkerRequestHandler> handler( | 205   std::unique_ptr<ServiceWorkerRequestHandler> handler( | 
| 206       provider_host->CreateRequestHandler( | 206       provider_host->CreateRequestHandler( | 
| 207           request_mode, credentials_mode, redirect_mode, integrity, | 207           request_mode, credentials_mode, redirect_mode, integrity, | 
| 208           resource_type, request_context_type, frame_type, | 208           resource_type, request_context_type, frame_type, | 
| 209           blob_storage_context->AsWeakPtr(), body, skip_service_worker)); | 209           blob_storage_context->AsWeakPtr(), body, skip_service_worker)); | 
| 210   if (handler) | 210   if (handler) | 
| 211     request->SetUserData(&kUserDataKey, std::move(handler)); | 211     request->SetUserData(&kSWUserDataKey, std::move(handler)); | 
| 212 } | 212 } | 
| 213 | 213 | 
| 214 ServiceWorkerRequestHandler* ServiceWorkerRequestHandler::GetHandler( | 214 ServiceWorkerRequestHandler* ServiceWorkerRequestHandler::GetHandler( | 
| 215     const net::URLRequest* request) { | 215     const net::URLRequest* request) { | 
| 216   return static_cast<ServiceWorkerRequestHandler*>( | 216   return static_cast<ServiceWorkerRequestHandler*>( | 
| 217       request->GetUserData(&kUserDataKey)); | 217       request->GetUserData(&kSWUserDataKey)); | 
| 218 } | 218 } | 
| 219 | 219 | 
| 220 std::unique_ptr<net::URLRequestInterceptor> | 220 std::unique_ptr<net::URLRequestInterceptor> | 
| 221 ServiceWorkerRequestHandler::CreateInterceptor( | 221 ServiceWorkerRequestHandler::CreateInterceptor( | 
| 222     ResourceContext* resource_context) { | 222     ResourceContext* resource_context) { | 
| 223   return std::unique_ptr<net::URLRequestInterceptor>( | 223   return std::unique_ptr<net::URLRequestInterceptor>( | 
| 224       new ServiceWorkerRequestInterceptor(resource_context)); | 224       new ServiceWorkerRequestInterceptor(resource_context)); | 
| 225 } | 225 } | 
| 226 | 226 | 
| 227 bool ServiceWorkerRequestHandler::IsControlledByServiceWorker( | 227 bool ServiceWorkerRequestHandler::IsControlledByServiceWorker( | 
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 297     ResourceType resource_type) | 297     ResourceType resource_type) | 
| 298     : context_(context), | 298     : context_(context), | 
| 299       provider_host_(provider_host), | 299       provider_host_(provider_host), | 
| 300       blob_storage_context_(blob_storage_context), | 300       blob_storage_context_(blob_storage_context), | 
| 301       resource_type_(resource_type), | 301       resource_type_(resource_type), | 
| 302       old_process_id_(0), | 302       old_process_id_(0), | 
| 303       old_provider_id_(kInvalidServiceWorkerProviderId) { | 303       old_provider_id_(kInvalidServiceWorkerProviderId) { | 
| 304 } | 304 } | 
| 305 | 305 | 
| 306 }  // namespace content | 306 }  // namespace content | 
| OLD | NEW | 
|---|