OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/appcache/appcache_request_handler.h" | 5 #include "content/browser/appcache/appcache_request_handler.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 return NULL; | 120 return NULL; |
121 if (is_main_resource()) | 121 if (is_main_resource()) |
122 return NULL; | 122 return NULL; |
123 // TODO(vabr) This is a temporary fix (see crbug/141114). We should get rid of | 123 // TODO(vabr) This is a temporary fix (see crbug/141114). We should get rid of |
124 // it once a more general solution to crbug/121325 is in place. | 124 // it once a more general solution to crbug/121325 is in place. |
125 if (!maybe_load_resource_executed_) | 125 if (!maybe_load_resource_executed_) |
126 return NULL; | 126 return NULL; |
127 if (request_->GetURL().GetOrigin() == location.GetOrigin()) | 127 if (request_->GetURL().GetOrigin() == location.GetOrigin()) |
128 return NULL; | 128 return NULL; |
129 | 129 |
130 DCHECK(!job_.get()); // our jobs never generate redirects | 130 // In network service land, the existing job initiates a fallback request. |
| 131 if (!base::FeatureList::IsEnabled(features::kNetworkService)) { |
| 132 DCHECK(!job_.get()); // our jobs never generate redirects |
| 133 } else { |
| 134 DCHECK(job_.get()); |
| 135 } |
131 | 136 |
132 std::unique_ptr<AppCacheJob> job; | 137 std::unique_ptr<AppCacheJob> job; |
133 if (found_fallback_entry_.has_response_id()) { | 138 if (found_fallback_entry_.has_response_id()) { |
| 139 job = MaybeCreateJobForFallback(network_delegate); |
134 // 6.9.6, step 4: If this results in a redirect to another origin, | 140 // 6.9.6, step 4: If this results in a redirect to another origin, |
135 // get the resource of the fallback entry. | 141 // get the resource of the fallback entry. |
136 job = CreateJob(network_delegate); | |
137 DeliverAppCachedResponse(found_fallback_entry_, found_cache_id_, | 142 DeliverAppCachedResponse(found_fallback_entry_, found_cache_id_, |
138 found_manifest_url_, true, | 143 found_manifest_url_, true, |
139 found_namespace_entry_url_); | 144 found_namespace_entry_url_); |
140 } else if (!found_network_namespace_) { | 145 } else if (!found_network_namespace_) { |
141 // 6.9.6, step 6: Fail the resource load. | 146 // 6.9.6, step 6: Fail the resource load. |
142 job = CreateJob(network_delegate); | 147 job = MaybeCreateJobForFallback(network_delegate); |
143 DeliverErrorResponse(); | 148 DeliverErrorResponse(); |
144 } else { | 149 } else { |
145 // 6.9.6 step 3 and 5: Fetch the resource normally. | 150 // 6.9.6 step 3 and 5: Fetch the resource normally. |
146 } | 151 } |
147 | 152 |
148 return job.release(); | 153 return job.release(); |
149 } | 154 } |
150 | 155 |
151 AppCacheJob* AppCacheRequestHandler::MaybeLoadFallbackForResponse( | 156 AppCacheJob* AppCacheRequestHandler::MaybeLoadFallbackForResponse( |
152 net::NetworkDelegate* network_delegate) { | 157 net::NetworkDelegate* network_delegate) { |
153 if (!host_ || | 158 if (!host_ || |
154 !AppCacheRequest::IsSchemeAndMethodSupportedForAppCache(request_.get()) || | 159 !AppCacheRequest::IsSchemeAndMethodSupportedForAppCache(request_.get()) || |
155 cache_entry_not_found_) | 160 cache_entry_not_found_) |
156 return NULL; | 161 return NULL; |
157 if (!found_fallback_entry_.has_response_id()) | 162 if (!found_fallback_entry_.has_response_id()) |
158 return NULL; | 163 return NULL; |
159 | 164 |
160 if (request_->IsCancelled()) { | 165 if (request_->IsCancelled()) { |
161 // 6.9.6, step 4: But not if the user canceled the download. | 166 // 6.9.6, step 4: But not if the user canceled the download. |
162 return NULL; | 167 return NULL; |
163 } | 168 } |
164 | 169 |
165 // We don't fallback for responses that we delivered. | 170 // We don't fallback for responses that we delivered. |
166 if (job_.get()) { | 171 if (job_.get() && !base::FeatureList::IsEnabled(features::kNetworkService)) { |
167 DCHECK(!job_->IsDeliveringNetworkResponse()); | 172 DCHECK(!job_->IsDeliveringNetworkResponse()); |
168 return NULL; | 173 return NULL; |
169 } | 174 } |
170 | 175 |
171 if (request_->IsSuccess()) { | 176 if (request_->IsSuccess()) { |
172 int code_major = request_->GetResponseCode() / 100; | 177 int code_major = request_->GetResponseCode() / 100; |
173 if (code_major !=4 && code_major != 5) | 178 if (code_major !=4 && code_major != 5) |
174 return NULL; | 179 return NULL; |
175 | 180 |
176 // Servers can override the fallback behavior with a response header. | 181 // Servers can override the fallback behavior with a response header. |
177 const std::string kFallbackOverrideHeader( | 182 const std::string kFallbackOverrideHeader( |
178 "x-chromium-appcache-fallback-override"); | 183 "x-chromium-appcache-fallback-override"); |
179 const std::string kFallbackOverrideValue( | 184 const std::string kFallbackOverrideValue( |
180 "disallow-fallback"); | 185 "disallow-fallback"); |
181 std::string header_value; | 186 std::string header_value; |
182 header_value = request_->GetResponseHeaderByName(kFallbackOverrideHeader); | 187 header_value = request_->GetResponseHeaderByName(kFallbackOverrideHeader); |
183 if (header_value == kFallbackOverrideValue) | 188 if (header_value == kFallbackOverrideValue) |
184 return NULL; | 189 return NULL; |
185 } | 190 } |
186 | 191 |
187 // 6.9.6, step 4: If this results in a 4xx or 5xx status code | 192 // 6.9.6, step 4: If this results in a 4xx or 5xx status code |
188 // or there were network errors, get the resource of the fallback entry. | 193 // or there were network errors, get the resource of the fallback entry. |
189 std::unique_ptr<AppCacheJob> job = CreateJob(network_delegate); | 194 |
| 195 // In network service land, the job initiates a fallback request. We reuse |
| 196 // the existing job to deliver the fallback response. |
| 197 std::unique_ptr<AppCacheJob> job = |
| 198 MaybeCreateJobForFallback(network_delegate); |
| 199 |
190 DeliverAppCachedResponse(found_fallback_entry_, found_cache_id_, | 200 DeliverAppCachedResponse(found_fallback_entry_, found_cache_id_, |
191 found_manifest_url_, true, | 201 found_manifest_url_, true, |
192 found_namespace_entry_url_); | 202 found_namespace_entry_url_); |
193 return job.release(); | 203 return job.release(); |
194 } | 204 } |
195 | 205 |
196 void AppCacheRequestHandler::GetExtraResponseInfo(int64_t* cache_id, | 206 void AppCacheRequestHandler::GetExtraResponseInfo(int64_t* cache_id, |
197 GURL* manifest_url) { | 207 GURL* manifest_url) { |
198 *cache_id = cache_id_; | 208 *cache_id = cache_id_; |
199 *manifest_url = manifest_url_; | 209 *manifest_url = manifest_url_; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 AppCacheURLLoaderJob* loader_job = job_->AsURLLoaderJob(); | 345 AppCacheURLLoaderJob* loader_job = job_->AsURLLoaderJob(); |
336 | 346 |
337 loader_job->SetSubresourceLoadInfo( | 347 loader_job->SetSubresourceLoadInfo( |
338 std::move(subresource_load_info_), | 348 std::move(subresource_load_info_), |
339 network_url_loader_factory_getter_.get()); | 349 network_url_loader_factory_getter_.get()); |
340 } | 350 } |
341 | 351 |
342 return job; | 352 return job; |
343 } | 353 } |
344 | 354 |
| 355 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::MaybeCreateJobForFallback( |
| 356 net::NetworkDelegate* network_delegate) { |
| 357 if (!base::FeatureList::IsEnabled(features::kNetworkService)) |
| 358 return CreateJob(network_delegate); |
| 359 // In network service land, the job initiates a fallback request. We reuse |
| 360 // the existing job to deliver the fallback response. |
| 361 DCHECK(job_.get()); |
| 362 return std::unique_ptr<AppCacheJob>(job_.get()); |
| 363 } |
| 364 |
345 // Main-resource handling ---------------------------------------------- | 365 // Main-resource handling ---------------------------------------------- |
346 | 366 |
347 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::MaybeLoadMainResource( | 367 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::MaybeLoadMainResource( |
348 net::NetworkDelegate* network_delegate) { | 368 net::NetworkDelegate* network_delegate) { |
349 DCHECK(!job_.get()); | 369 DCHECK(!job_.get()); |
350 DCHECK(host_); | 370 DCHECK(host_); |
351 | 371 |
352 // If a page falls into the scope of a ServiceWorker, any matching AppCaches | 372 // If a page falls into the scope of a ServiceWorker, any matching AppCaches |
353 // should be ignored. This depends on the ServiceWorker handler being invoked | 373 // should be ignored. This depends on the ServiceWorker handler being invoked |
354 // prior to the AppCache handler. | 374 // prior to the AppCache handler. |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 mojom::URLLoaderFactoryPtr factory_ptr = nullptr; | 589 mojom::URLLoaderFactoryPtr factory_ptr = nullptr; |
570 | 590 |
571 // The factory is destroyed when the renderer drops the connection. | 591 // The factory is destroyed when the renderer drops the connection. |
572 AppCacheSubresourceURLFactory::CreateURLLoaderFactory( | 592 AppCacheSubresourceURLFactory::CreateURLLoaderFactory( |
573 network_url_loader_factory_getter_.get(), appcache_host_, &factory_ptr); | 593 network_url_loader_factory_getter_.get(), appcache_host_, &factory_ptr); |
574 | 594 |
575 return factory_ptr; | 595 return factory_ptr; |
576 } | 596 } |
577 | 597 |
578 } // namespace content | 598 } // namespace content |
OLD | NEW |