Chromium Code Reviews| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 | 95 |
| 96 // Initialize the SWProviderHost. | 96 // Initialize the SWProviderHost. |
| 97 std::unique_ptr<ServiceWorkerProviderHost> provider_host = | 97 std::unique_ptr<ServiceWorkerProviderHost> provider_host = |
| 98 ServiceWorkerProviderHost::PreCreateNavigationHost( | 98 ServiceWorkerProviderHost::PreCreateNavigationHost( |
| 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, "" /*integrity*/, resource_type, |
|
falken
2017/07/07 00:56:11
ditto
xiaofengzhang
2017/07/12 09:13:52
Done.
| |
| 106 frame_type, blob_storage_context->AsWeakPtr(), body, | 106 request_context_type, frame_type, blob_storage_context->AsWeakPtr(), |
| 107 skip_service_worker)); | 107 body, skip_service_worker)); |
| 108 if (handler) | 108 if (handler) |
| 109 request->SetUserData(&kUserDataKey, std::move(handler)); | 109 request->SetUserData(&kUserDataKey, 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 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 | 149 |
| 150 // Initialize the SWProviderHost. | 150 // Initialize the SWProviderHost. |
| 151 std::unique_ptr<ServiceWorkerProviderHost> provider_host = | 151 std::unique_ptr<ServiceWorkerProviderHost> provider_host = |
| 152 ServiceWorkerProviderHost::PreCreateNavigationHost( | 152 ServiceWorkerProviderHost::PreCreateNavigationHost( |
| 153 navigation_handle_core->context_wrapper()->context()->AsWeakPtr(), | 153 navigation_handle_core->context_wrapper()->context()->AsWeakPtr(), |
| 154 is_parent_frame_secure, web_contents_getter); | 154 is_parent_frame_secure, web_contents_getter); |
| 155 | 155 |
| 156 std::unique_ptr<ServiceWorkerRequestHandler> handler( | 156 std::unique_ptr<ServiceWorkerRequestHandler> handler( |
| 157 provider_host->CreateRequestHandler( | 157 provider_host->CreateRequestHandler( |
| 158 FETCH_REQUEST_MODE_NAVIGATE, FETCH_CREDENTIALS_MODE_INCLUDE, | 158 FETCH_REQUEST_MODE_NAVIGATE, FETCH_CREDENTIALS_MODE_INCLUDE, |
| 159 FetchRedirectMode::MANUAL_MODE, resource_type, request_context_type, | 159 FetchRedirectMode::MANUAL_MODE, "" /*integrity*/, resource_type, |
|
falken
2017/07/07 00:56:11
ditto*
xiaofengzhang
2017/07/12 09:13:52
Done.
| |
| 160 frame_type, blob_storage_context->AsWeakPtr(), body, | 160 request_context_type, frame_type, blob_storage_context->AsWeakPtr(), |
| 161 skip_service_worker)); | 161 body, skip_service_worker)); |
| 162 | 162 |
| 163 // Transfer ownership to the ServiceWorkerNavigationHandleCore. | 163 // Transfer ownership to the ServiceWorkerNavigationHandleCore. |
| 164 // In the case of a successful navigation, the SWProviderHost will be | 164 // In the case of a successful navigation, the SWProviderHost will be |
| 165 // transferred to its "final" destination in the OnProviderCreated handler. If | 165 // transferred to its "final" destination in the OnProviderCreated handler. If |
| 166 // the navigation fails, it will be destroyed along with the | 166 // the navigation fails, it will be destroyed along with the |
| 167 // ServiceWorkerNavigationHandleCore. | 167 // ServiceWorkerNavigationHandleCore. |
| 168 navigation_handle_core->DidPreCreateProviderHost(std::move(provider_host)); | 168 navigation_handle_core->DidPreCreateProviderHost(std::move(provider_host)); |
| 169 | 169 |
| 170 return base::WrapUnique<URLLoaderRequestHandler>(handler.release()); | 170 return base::WrapUnique<URLLoaderRequestHandler>(handler.release()); |
| 171 } | 171 } |
| 172 | 172 |
| 173 void ServiceWorkerRequestHandler::InitializeHandler( | 173 void ServiceWorkerRequestHandler::InitializeHandler( |
| 174 net::URLRequest* request, | 174 net::URLRequest* request, |
| 175 ServiceWorkerContextWrapper* context_wrapper, | 175 ServiceWorkerContextWrapper* context_wrapper, |
| 176 storage::BlobStorageContext* blob_storage_context, | 176 storage::BlobStorageContext* blob_storage_context, |
| 177 int process_id, | 177 int process_id, |
| 178 int provider_id, | 178 int provider_id, |
| 179 bool skip_service_worker, | 179 bool skip_service_worker, |
| 180 FetchRequestMode request_mode, | 180 FetchRequestMode request_mode, |
| 181 FetchCredentialsMode credentials_mode, | 181 FetchCredentialsMode credentials_mode, |
| 182 FetchRedirectMode redirect_mode, | 182 FetchRedirectMode redirect_mode, |
| 183 const std::string& integrity, | |
| 183 ResourceType resource_type, | 184 ResourceType resource_type, |
| 184 RequestContextType request_context_type, | 185 RequestContextType request_context_type, |
| 185 RequestContextFrameType frame_type, | 186 RequestContextFrameType frame_type, |
| 186 scoped_refptr<ResourceRequestBody> body) { | 187 scoped_refptr<ResourceRequestBody> body) { |
| 187 // Create the handler even for insecure HTTP since it's used in the | 188 // Create the handler even for insecure HTTP since it's used in the |
| 188 // case of redirect to HTTPS. | 189 // case of redirect to HTTPS. |
| 189 if (!request->url().SchemeIsHTTPOrHTTPS() && | 190 if (!request->url().SchemeIsHTTPOrHTTPS() && |
| 190 !OriginCanAccessServiceWorkers(request->url())) { | 191 !OriginCanAccessServiceWorkers(request->url())) { |
| 191 return; | 192 return; |
| 192 } | 193 } |
| 193 | 194 |
| 194 if (!context_wrapper || !context_wrapper->context() || | 195 if (!context_wrapper || !context_wrapper->context() || |
| 195 provider_id == kInvalidServiceWorkerProviderId) { | 196 provider_id == kInvalidServiceWorkerProviderId) { |
| 196 return; | 197 return; |
| 197 } | 198 } |
| 198 | 199 |
| 199 ServiceWorkerProviderHost* provider_host = | 200 ServiceWorkerProviderHost* provider_host = |
| 200 context_wrapper->context()->GetProviderHost(process_id, provider_id); | 201 context_wrapper->context()->GetProviderHost(process_id, provider_id); |
| 201 if (!provider_host || !provider_host->IsContextAlive()) | 202 if (!provider_host || !provider_host->IsContextAlive()) |
| 202 return; | 203 return; |
| 203 | 204 |
| 204 std::unique_ptr<ServiceWorkerRequestHandler> handler( | 205 std::unique_ptr<ServiceWorkerRequestHandler> handler( |
| 205 provider_host->CreateRequestHandler( | 206 provider_host->CreateRequestHandler( |
| 206 request_mode, credentials_mode, redirect_mode, resource_type, | 207 request_mode, credentials_mode, redirect_mode, integrity, |
| 207 request_context_type, frame_type, blob_storage_context->AsWeakPtr(), | 208 resource_type, request_context_type, frame_type, |
| 208 body, skip_service_worker)); | 209 blob_storage_context->AsWeakPtr(), body, skip_service_worker)); |
| 209 if (handler) | 210 if (handler) |
| 210 request->SetUserData(&kUserDataKey, std::move(handler)); | 211 request->SetUserData(&kUserDataKey, std::move(handler)); |
| 211 } | 212 } |
| 212 | 213 |
| 213 ServiceWorkerRequestHandler* ServiceWorkerRequestHandler::GetHandler( | 214 ServiceWorkerRequestHandler* ServiceWorkerRequestHandler::GetHandler( |
| 214 const net::URLRequest* request) { | 215 const net::URLRequest* request) { |
| 215 return static_cast<ServiceWorkerRequestHandler*>( | 216 return static_cast<ServiceWorkerRequestHandler*>( |
| 216 request->GetUserData(&kUserDataKey)); | 217 request->GetUserData(&kUserDataKey)); |
| 217 } | 218 } |
| 218 | 219 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 ResourceType resource_type) | 297 ResourceType resource_type) |
| 297 : context_(context), | 298 : context_(context), |
| 298 provider_host_(provider_host), | 299 provider_host_(provider_host), |
| 299 blob_storage_context_(blob_storage_context), | 300 blob_storage_context_(blob_storage_context), |
| 300 resource_type_(resource_type), | 301 resource_type_(resource_type), |
| 301 old_process_id_(0), | 302 old_process_id_(0), |
| 302 old_provider_id_(kInvalidServiceWorkerProviderId) { | 303 old_provider_id_(kInvalidServiceWorkerProviderId) { |
| 303 } | 304 } |
| 304 | 305 |
| 305 } // namespace content | 306 } // namespace content |
| OLD | NEW |