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, |
| 71 NavigationURLLoaderImplCore* loader) { |
68 if (!OriginCanAccessServiceWorkers(request->url())) | 72 if (!OriginCanAccessServiceWorkers(request->url())) |
69 return; | 73 return; |
70 | 74 |
71 if (!context_wrapper || !context_wrapper->context() || | 75 if (!context_wrapper || !context_wrapper->context() || |
72 provider_id == kInvalidServiceWorkerProviderId) { | 76 provider_id == kInvalidServiceWorkerProviderId) { |
73 return; | 77 return; |
74 } | 78 } |
75 | 79 |
76 ServiceWorkerProviderHost* provider_host = | 80 ServiceWorkerProviderHost* provider_host = nullptr; |
77 context_wrapper->context()->GetProviderHost(process_id, provider_id); | 81 if (provider_id < kInvalidServiceWorkerProviderId) { |
| 82 // PlzNavigate |
| 83 // Initialize a dummy SWProviderHost for browser-initiated navigations. |
| 84 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 85 switches::kEnableBrowserSideNavigation)); |
| 86 scoped_ptr<ServiceWorkerProviderHost> scoped_provider_host( |
| 87 context_wrapper->context()->CreateBrowserProviderHost(provider_id)); |
| 88 provider_host = scoped_provider_host.get(); |
| 89 loader->SetServiceWorkerProviderHost(scoped_provider_host.Pass()); |
| 90 } else { |
| 91 provider_host = |
| 92 context_wrapper->context()->GetProviderHost(process_id, provider_id); |
| 93 } |
| 94 |
78 if (!provider_host || !provider_host->IsContextAlive()) | 95 if (!provider_host || !provider_host->IsContextAlive()) |
79 return; | 96 return; |
80 | 97 |
81 if (skip_service_worker) { | 98 if (skip_service_worker) { |
82 if (ServiceWorkerUtils::IsMainResourceType(resource_type)) { | 99 if (ServiceWorkerUtils::IsMainResourceType(resource_type)) { |
| 100 // TODO(horo): Does this work properly for PlzNavigate? |
83 provider_host->SetDocumentUrl(net::SimplifyUrlForRequest(request->url())); | 101 provider_host->SetDocumentUrl(net::SimplifyUrlForRequest(request->url())); |
84 provider_host->SetTopmostFrameUrl(request->first_party_for_cookies()); | 102 provider_host->SetTopmostFrameUrl(request->first_party_for_cookies()); |
85 // A page load with skip_service_worker should be triggered by | 103 // A page load with skip_service_worker should be triggered by |
86 // shift-reload, so retain all live matching registrations. | 104 // shift-reload, so retain all live matching registrations. |
87 provider_host->AddAllMatchingRegistrations(); | 105 provider_host->AddAllMatchingRegistrations(); |
88 } | 106 } |
89 return; | 107 return; |
90 } | 108 } |
91 | 109 |
92 scoped_ptr<ServiceWorkerRequestHandler> handler( | 110 scoped_ptr<ServiceWorkerRequestHandler> handler( |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 ResourceType resource_type) | 183 ResourceType resource_type) |
166 : context_(context), | 184 : context_(context), |
167 provider_host_(provider_host), | 185 provider_host_(provider_host), |
168 blob_storage_context_(blob_storage_context), | 186 blob_storage_context_(blob_storage_context), |
169 resource_type_(resource_type), | 187 resource_type_(resource_type), |
170 old_process_id_(0), | 188 old_process_id_(0), |
171 old_provider_id_(kInvalidServiceWorkerProviderId) { | 189 old_provider_id_(kInvalidServiceWorkerProviderId) { |
172 } | 190 } |
173 | 191 |
174 } // namespace content | 192 } // namespace content |
OLD | NEW |