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/macros.h" | 10 #include "base/macros.h" |
11 #include "content/browser/service_worker/service_worker_context_core.h" | 11 #include "content/browser/service_worker/service_worker_context_core.h" |
12 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 12 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
13 #include "content/browser/service_worker/service_worker_navigation_handle_core.h
" | |
14 #include "content/browser/service_worker/service_worker_provider_host.h" | 13 #include "content/browser/service_worker/service_worker_provider_host.h" |
15 #include "content/browser/service_worker/service_worker_registration.h" | 14 #include "content/browser/service_worker/service_worker_registration.h" |
16 #include "content/browser/service_worker/service_worker_url_request_job.h" | 15 #include "content/browser/service_worker/service_worker_url_request_job.h" |
17 #include "content/common/resource_request_body_impl.h" | 16 #include "content/common/resource_request_body_impl.h" |
18 #include "content/common/service_worker/service_worker_types.h" | 17 #include "content/common/service_worker/service_worker_types.h" |
19 #include "content/common/service_worker/service_worker_utils.h" | 18 #include "content/common/service_worker/service_worker_utils.h" |
20 #include "content/public/browser/resource_context.h" | 19 #include "content/public/browser/resource_context.h" |
21 #include "content/public/common/browser_side_navigation_policy.h" | 20 #include "content/public/common/browser_side_navigation_policy.h" |
22 #include "content/public/common/child_process_host.h" | 21 #include "content/public/common/child_process_host.h" |
23 #include "content/public/common/origin_util.h" | 22 #include "content/public/common/origin_util.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 request_context_type, frame_type, blob_storage_context->AsWeakPtr(), | 84 request_context_type, frame_type, blob_storage_context->AsWeakPtr(), |
86 body)); | 85 body)); |
87 if (!handler) | 86 if (!handler) |
88 return; | 87 return; |
89 | 88 |
90 request->SetUserData(&kUserDataKey, handler.release()); | 89 request->SetUserData(&kUserDataKey, handler.release()); |
91 } | 90 } |
92 | 91 |
93 } // namespace | 92 } // namespace |
94 | 93 |
95 // PlzNavigate | |
96 void ServiceWorkerRequestHandler::InitializeForNavigation( | |
97 net::URLRequest* request, | |
98 ServiceWorkerNavigationHandleCore* navigation_handle_core, | |
99 storage::BlobStorageContext* blob_storage_context, | |
100 bool skip_service_worker, | |
101 ResourceType resource_type, | |
102 RequestContextType request_context_type, | |
103 RequestContextFrameType frame_type, | |
104 scoped_refptr<ResourceRequestBodyImpl> body) { | |
105 CHECK(IsBrowserSideNavigationEnabled()); | |
106 | |
107 // Only create a handler when there is a ServiceWorkerNavigationHandlerCore | |
108 // to take ownership of a pre-created SeviceWorkerProviderHost. | |
109 if (!navigation_handle_core) | |
110 return; | |
111 | |
112 // Create the handler even for insecure HTTP since it's used in the | |
113 // case of redirect to HTTPS. | |
114 if (!request->url().SchemeIsHTTPOrHTTPS() && | |
115 !OriginCanAccessServiceWorkers(request->url())) { | |
116 return; | |
117 } | |
118 | |
119 if (!navigation_handle_core->context_wrapper() || | |
120 !navigation_handle_core->context_wrapper()->context()) { | |
121 return; | |
122 } | |
123 | |
124 // Initialize the SWProviderHost. | |
125 std::unique_ptr<ServiceWorkerProviderHost> provider_host = | |
126 ServiceWorkerProviderHost::PreCreateNavigationHost( | |
127 navigation_handle_core->context_wrapper()->context()->AsWeakPtr()); | |
128 | |
129 FinalizeHandlerInitialization( | |
130 request, provider_host.get(), blob_storage_context, skip_service_worker, | |
131 FETCH_REQUEST_MODE_SAME_ORIGIN, FETCH_CREDENTIALS_MODE_INCLUDE, | |
132 FetchRedirectMode::MANUAL_MODE, resource_type, request_context_type, | |
133 frame_type, body); | |
134 | |
135 // Transfer ownership to the ServiceWorkerNavigationHandleCore. | |
136 // In the case of a successful navigation, the SWProviderHost will be | |
137 // transferred to its "final" destination in the OnProviderCreated handler. If | |
138 // the navigation fails, it will be destroyed along with the | |
139 // ServiceWorkerNavigationHandleCore. | |
140 navigation_handle_core->DidPreCreateProviderHost(std::move(provider_host)); | |
141 } | |
142 | |
143 void ServiceWorkerRequestHandler::InitializeHandler( | 94 void ServiceWorkerRequestHandler::InitializeHandler( |
144 net::URLRequest* request, | 95 net::URLRequest* request, |
145 ServiceWorkerContextWrapper* context_wrapper, | 96 ServiceWorkerContextWrapper* context_wrapper, |
146 storage::BlobStorageContext* blob_storage_context, | 97 storage::BlobStorageContext* blob_storage_context, |
147 int process_id, | 98 int process_id, |
148 int provider_id, | 99 int provider_id, |
149 bool skip_service_worker, | 100 bool skip_service_worker, |
150 FetchRequestMode request_mode, | 101 FetchRequestMode request_mode, |
151 FetchCredentialsMode credentials_mode, | 102 FetchCredentialsMode credentials_mode, |
152 FetchRedirectMode redirect_mode, | 103 FetchRedirectMode redirect_mode, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 ResourceType resource_type) | 200 ResourceType resource_type) |
250 : context_(context), | 201 : context_(context), |
251 provider_host_(provider_host), | 202 provider_host_(provider_host), |
252 blob_storage_context_(blob_storage_context), | 203 blob_storage_context_(blob_storage_context), |
253 resource_type_(resource_type), | 204 resource_type_(resource_type), |
254 old_process_id_(0), | 205 old_process_id_(0), |
255 old_provider_id_(kInvalidServiceWorkerProviderId) { | 206 old_provider_id_(kInvalidServiceWorkerProviderId) { |
256 } | 207 } |
257 | 208 |
258 } // namespace content | 209 } // namespace content |
OLD | NEW |