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 | 8 |
| 9 #include "base/command_line.h" | |
| 10 #include "content/browser/loader/navigation_url_loader_impl_core.h" | |
| 9 #include "content/browser/service_worker/service_worker_context_core.h" | 11 #include "content/browser/service_worker/service_worker_context_core.h" |
| 10 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 12 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 11 #include "content/browser/service_worker/service_worker_provider_host.h" | 13 #include "content/browser/service_worker/service_worker_provider_host.h" |
| 12 #include "content/browser/service_worker/service_worker_registration.h" | 14 #include "content/browser/service_worker/service_worker_registration.h" |
| 13 #include "content/browser/service_worker/service_worker_url_request_job.h" | 15 #include "content/browser/service_worker/service_worker_url_request_job.h" |
| 14 #include "content/common/resource_request_body.h" | 16 #include "content/common/resource_request_body.h" |
| 15 #include "content/common/service_worker/service_worker_types.h" | 17 #include "content/common/service_worker/service_worker_types.h" |
| 16 #include "content/common/service_worker/service_worker_utils.h" | 18 #include "content/common/service_worker/service_worker_utils.h" |
| 17 #include "content/public/browser/resource_context.h" | 19 #include "content/public/browser/resource_context.h" |
| 20 #include "content/public/common/content_switches.h" | |
| 18 #include "content/public/common/origin_util.h" | 21 #include "content/public/common/origin_util.h" |
| 19 #include "net/base/net_util.h" | 22 #include "net/base/net_util.h" |
| 20 #include "net/url_request/url_request.h" | 23 #include "net/url_request/url_request.h" |
| 21 #include "net/url_request/url_request_interceptor.h" | 24 #include "net/url_request/url_request_interceptor.h" |
| 22 #include "storage/browser/blob/blob_storage_context.h" | 25 #include "storage/browser/blob/blob_storage_context.h" |
| 23 | 26 |
| 24 namespace content { | 27 namespace content { |
| 25 | 28 |
| 26 namespace { | 29 namespace { |
| 27 | 30 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 57 storage::BlobStorageContext* blob_storage_context, | 60 storage::BlobStorageContext* blob_storage_context, |
| 58 int process_id, | 61 int process_id, |
| 59 int provider_id, | 62 int provider_id, |
| 60 bool skip_service_worker, | 63 bool skip_service_worker, |
| 61 FetchRequestMode request_mode, | 64 FetchRequestMode request_mode, |
| 62 FetchCredentialsMode credentials_mode, | 65 FetchCredentialsMode credentials_mode, |
| 63 FetchRedirectMode redirect_mode, | 66 FetchRedirectMode redirect_mode, |
| 64 ResourceType resource_type, | 67 ResourceType resource_type, |
| 65 RequestContextType request_context_type, | 68 RequestContextType request_context_type, |
| 66 RequestContextFrameType frame_type, | 69 RequestContextFrameType frame_type, |
| 67 scoped_refptr<ResourceRequestBody> body) { | 70 scoped_refptr<ResourceRequestBody> body, |
| 68 // Create the handler even for insecure HTTP since it's used in the | 71 NavigationURLLoaderImplCore* loader) { |
| 69 // case of redirect to HTTPS. | 72 // case of redirect to HTTPS. |
|
carlosk
2015/08/27 14:26:43
Re-add the first line of this comment.
Fabrice (no longer in Chrome)
2015/08/28 15:40:16
Bad auto-merge :(
Done.
| |
| 70 if (!request->url().SchemeIsHTTPOrHTTPS() && | 73 if (!request->url().SchemeIsHTTPOrHTTPS() && |
| 71 !OriginCanAccessServiceWorkers(request->url())) { | 74 !OriginCanAccessServiceWorkers(request->url())) { |
| 72 return; | 75 return; |
| 73 } | 76 } |
| 74 | 77 |
| 75 if (!context_wrapper || !context_wrapper->context() || | 78 if (!context_wrapper || !context_wrapper->context() || |
| 76 provider_id == kInvalidServiceWorkerProviderId) { | 79 provider_id == kInvalidServiceWorkerProviderId) { |
| 77 return; | 80 return; |
| 78 } | 81 } |
| 79 | 82 |
| 80 ServiceWorkerProviderHost* provider_host = | 83 ServiceWorkerProviderHost* provider_host = nullptr; |
| 81 context_wrapper->context()->GetProviderHost(process_id, provider_id); | 84 if (process_id == -1) { |
| 85 // PlzNavigate | |
| 86 // Initialize a dummy SWProviderHost for browser-initiated navigations. | |
| 87 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 88 switches::kEnableBrowserSideNavigation)); | |
| 89 DCHECK(ServiceWorkerUtils::IsBrowserAssignedProviderId(provider_id)); | |
| 90 scoped_ptr<ServiceWorkerProviderHost> scoped_provider_host( | |
| 91 context_wrapper->context()->CreateBrowserProviderHost(provider_id)); | |
| 92 provider_host = scoped_provider_host.get(); | |
| 93 loader->SetServiceWorkerProviderHost(scoped_provider_host.Pass()); | |
| 94 } else { | |
| 95 provider_host = | |
| 96 context_wrapper->context()->GetProviderHost(process_id, provider_id); | |
| 97 } | |
| 98 | |
| 82 if (!provider_host || !provider_host->IsContextAlive()) | 99 if (!provider_host || !provider_host->IsContextAlive()) |
| 83 return; | 100 return; |
| 84 | 101 |
| 85 if (skip_service_worker) { | 102 if (skip_service_worker) { |
| 86 if (ServiceWorkerUtils::IsMainResourceType(resource_type)) { | 103 if (ServiceWorkerUtils::IsMainResourceType(resource_type)) { |
| 104 // TODO(horo): Does this work properly for PlzNavigate? | |
| 87 provider_host->SetDocumentUrl(net::SimplifyUrlForRequest(request->url())); | 105 provider_host->SetDocumentUrl(net::SimplifyUrlForRequest(request->url())); |
| 88 provider_host->SetTopmostFrameUrl(request->first_party_for_cookies()); | 106 provider_host->SetTopmostFrameUrl(request->first_party_for_cookies()); |
| 89 // A page load with skip_service_worker should be triggered by | 107 // A page load with skip_service_worker should be triggered by |
| 90 // shift-reload, so retain all live matching registrations. | 108 // shift-reload, so retain all live matching registrations. |
| 91 provider_host->AddAllMatchingRegistrations(); | 109 provider_host->AddAllMatchingRegistrations(); |
| 92 } | 110 } |
| 93 return; | 111 return; |
| 94 } | 112 } |
| 95 | 113 |
| 96 scoped_ptr<ServiceWorkerRequestHandler> handler( | 114 scoped_ptr<ServiceWorkerRequestHandler> handler( |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 ResourceType resource_type) | 187 ResourceType resource_type) |
| 170 : context_(context), | 188 : context_(context), |
| 171 provider_host_(provider_host), | 189 provider_host_(provider_host), |
| 172 blob_storage_context_(blob_storage_context), | 190 blob_storage_context_(blob_storage_context), |
| 173 resource_type_(resource_type), | 191 resource_type_(resource_type), |
| 174 old_process_id_(0), | 192 old_process_id_(0), |
| 175 old_provider_id_(kInvalidServiceWorkerProviderId) { | 193 old_provider_id_(kInvalidServiceWorkerProviderId) { |
| 176 } | 194 } |
| 177 | 195 |
| 178 } // namespace content | 196 } // namespace content |
| OLD | NEW |