| 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, resource_type, request_context_type, | 105 FetchRedirectMode::MANUAL_MODE, resource_type, request_context_type, |
| 106 frame_type, blob_storage_context->AsWeakPtr(), body, | 106 frame_type, blob_storage_context->AsWeakPtr(), body, |
| 107 skip_service_worker)); | 107 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 context_wrapper->context()->GetProviderHost(process_id, provider_id); | 200 context_wrapper->context()->GetProviderHost(process_id, provider_id); |
| 201 if (!provider_host || !provider_host->IsContextAlive()) | 201 if (!provider_host || !provider_host->IsContextAlive()) |
| 202 return; | 202 return; |
| 203 | 203 |
| 204 std::unique_ptr<ServiceWorkerRequestHandler> handler( | 204 std::unique_ptr<ServiceWorkerRequestHandler> handler( |
| 205 provider_host->CreateRequestHandler( | 205 provider_host->CreateRequestHandler( |
| 206 request_mode, credentials_mode, redirect_mode, resource_type, | 206 request_mode, credentials_mode, redirect_mode, resource_type, |
| 207 request_context_type, frame_type, blob_storage_context->AsWeakPtr(), | 207 request_context_type, frame_type, blob_storage_context->AsWeakPtr(), |
| 208 body, skip_service_worker)); | 208 body, skip_service_worker)); |
| 209 if (handler) | 209 if (handler) |
| 210 request->SetUserData(&kUserDataKey, std::move(handler)); | 210 request->SetUserData(&kSWUserDataKey, std::move(handler)); |
| 211 } | 211 } |
| 212 | 212 |
| 213 ServiceWorkerRequestHandler* ServiceWorkerRequestHandler::GetHandler( | 213 ServiceWorkerRequestHandler* ServiceWorkerRequestHandler::GetHandler( |
| 214 const net::URLRequest* request) { | 214 const net::URLRequest* request) { |
| 215 return static_cast<ServiceWorkerRequestHandler*>( | 215 return static_cast<ServiceWorkerRequestHandler*>( |
| 216 request->GetUserData(&kUserDataKey)); | 216 request->GetUserData(&kSWUserDataKey)); |
| 217 } | 217 } |
| 218 | 218 |
| 219 std::unique_ptr<net::URLRequestInterceptor> | 219 std::unique_ptr<net::URLRequestInterceptor> |
| 220 ServiceWorkerRequestHandler::CreateInterceptor( | 220 ServiceWorkerRequestHandler::CreateInterceptor( |
| 221 ResourceContext* resource_context) { | 221 ResourceContext* resource_context) { |
| 222 return std::unique_ptr<net::URLRequestInterceptor>( | 222 return std::unique_ptr<net::URLRequestInterceptor>( |
| 223 new ServiceWorkerRequestInterceptor(resource_context)); | 223 new ServiceWorkerRequestInterceptor(resource_context)); |
| 224 } | 224 } |
| 225 | 225 |
| 226 bool ServiceWorkerRequestHandler::IsControlledByServiceWorker( | 226 bool ServiceWorkerRequestHandler::IsControlledByServiceWorker( |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 ResourceType resource_type) | 296 ResourceType resource_type) |
| 297 : context_(context), | 297 : context_(context), |
| 298 provider_host_(provider_host), | 298 provider_host_(provider_host), |
| 299 blob_storage_context_(blob_storage_context), | 299 blob_storage_context_(blob_storage_context), |
| 300 resource_type_(resource_type), | 300 resource_type_(resource_type), |
| 301 old_process_id_(0), | 301 old_process_id_(0), |
| 302 old_provider_id_(kInvalidServiceWorkerProviderId) { | 302 old_provider_id_(kInvalidServiceWorkerProviderId) { |
| 303 } | 303 } |
| 304 | 304 |
| 305 } // namespace content | 305 } // namespace content |
| OLD | NEW |