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