Chromium Code Reviews| 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 DCHECK(!job_.get()); // our jobs never generate redirects |
| 131 | 131 |
| 132 std::unique_ptr<AppCacheJob> job; | 132 std::unique_ptr<AppCacheJob> job; |
| 133 // In network service land, the job initiates a fallback request. We reuse | |
| 134 // the existing job to deliver the fallback response. | |
|
michaeln
2017/07/17 21:04:55
I think we might be able to better encapsulate thi
ananta
2017/07/18 00:19:03
Did not want to touch the CreateJob() function. I
| |
| 135 if (!base::FeatureList::IsEnabled(features::kNetworkService)) { | |
| 136 job = CreateJob(network_delegate); | |
| 137 } else { | |
| 138 job.reset(job_.get()); | |
|
michaeln
2017/07/17 21:04:55
does the dcheck on line 130 no longer hold true?
ananta
2017/07/18 00:19:03
It does. I changed the DCHECK for the network serv
| |
| 139 } | |
| 140 | |
| 133 if (found_fallback_entry_.has_response_id()) { | 141 if (found_fallback_entry_.has_response_id()) { |
| 134 // 6.9.6, step 4: If this results in a redirect to another origin, | 142 // 6.9.6, step 4: If this results in a redirect to another origin, |
| 135 // get the resource of the fallback entry. | 143 // get the resource of the fallback entry. |
| 136 job = CreateJob(network_delegate); | |
| 137 DeliverAppCachedResponse(found_fallback_entry_, found_cache_id_, | 144 DeliverAppCachedResponse(found_fallback_entry_, found_cache_id_, |
| 138 found_manifest_url_, true, | 145 found_manifest_url_, true, |
| 139 found_namespace_entry_url_); | 146 found_namespace_entry_url_); |
| 140 } else if (!found_network_namespace_) { | 147 } else if (!found_network_namespace_) { |
| 141 // 6.9.6, step 6: Fail the resource load. | 148 // 6.9.6, step 6: Fail the resource load. |
| 142 job = CreateJob(network_delegate); | |
| 143 DeliverErrorResponse(); | 149 DeliverErrorResponse(); |
| 144 } else { | 150 } else { |
| 145 // 6.9.6 step 3 and 5: Fetch the resource normally. | 151 // 6.9.6 step 3 and 5: Fetch the resource normally. |
|
michaeln
2017/07/17 21:04:55
In the net::urlrequest based impl, exsting code re
ananta
2017/07/18 00:19:03
I restored the code back to how it was originally.
| |
| 146 } | 152 } |
| 147 | 153 |
| 148 return job.release(); | 154 return job.release(); |
| 149 } | 155 } |
| 150 | 156 |
| 151 AppCacheJob* AppCacheRequestHandler::MaybeLoadFallbackForResponse( | 157 AppCacheJob* AppCacheRequestHandler::MaybeLoadFallbackForResponse( |
| 152 net::NetworkDelegate* network_delegate) { | 158 net::NetworkDelegate* network_delegate) { |
| 153 if (!host_ || | 159 if (!host_ || |
| 154 !AppCacheRequest::IsSchemeAndMethodSupportedForAppCache(request_.get()) || | 160 !AppCacheRequest::IsSchemeAndMethodSupportedForAppCache(request_.get()) || |
| 155 cache_entry_not_found_) | 161 cache_entry_not_found_) |
| 156 return NULL; | 162 return NULL; |
| 157 if (!found_fallback_entry_.has_response_id()) | 163 if (!found_fallback_entry_.has_response_id()) |
| 158 return NULL; | 164 return NULL; |
| 159 | 165 |
| 160 if (request_->IsCancelled()) { | 166 if (request_->IsCancelled()) { |
| 161 // 6.9.6, step 4: But not if the user canceled the download. | 167 // 6.9.6, step 4: But not if the user canceled the download. |
| 162 return NULL; | 168 return NULL; |
| 163 } | 169 } |
| 164 | 170 |
| 165 // We don't fallback for responses that we delivered. | 171 // We don't fallback for responses that we delivered. |
| 166 if (job_.get()) { | 172 if (job_.get() && !base::FeatureList::IsEnabled(features::kNetworkService)) { |
| 167 DCHECK(!job_->IsDeliveringNetworkResponse()); | 173 DCHECK(!job_->IsDeliveringNetworkResponse()); |
| 168 return NULL; | 174 return NULL; |
| 169 } | 175 } |
| 170 | 176 |
| 171 if (request_->IsSuccess()) { | 177 if (request_->IsSuccess()) { |
| 172 int code_major = request_->GetResponseCode() / 100; | 178 int code_major = request_->GetResponseCode() / 100; |
| 173 if (code_major !=4 && code_major != 5) | 179 if (code_major !=4 && code_major != 5) |
| 174 return NULL; | 180 return NULL; |
| 175 | 181 |
| 176 // Servers can override the fallback behavior with a response header. | 182 // Servers can override the fallback behavior with a response header. |
| 177 const std::string kFallbackOverrideHeader( | 183 const std::string kFallbackOverrideHeader( |
| 178 "x-chromium-appcache-fallback-override"); | 184 "x-chromium-appcache-fallback-override"); |
| 179 const std::string kFallbackOverrideValue( | 185 const std::string kFallbackOverrideValue( |
| 180 "disallow-fallback"); | 186 "disallow-fallback"); |
| 181 std::string header_value; | 187 std::string header_value; |
| 182 header_value = request_->GetResponseHeaderByName(kFallbackOverrideHeader); | 188 header_value = request_->GetResponseHeaderByName(kFallbackOverrideHeader); |
| 183 if (header_value == kFallbackOverrideValue) | 189 if (header_value == kFallbackOverrideValue) |
| 184 return NULL; | 190 return NULL; |
| 185 } | 191 } |
| 186 | 192 |
| 187 // 6.9.6, step 4: If this results in a 4xx or 5xx status code | 193 // 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. | 194 // or there were network errors, get the resource of the fallback entry. |
| 189 std::unique_ptr<AppCacheJob> job = CreateJob(network_delegate); | 195 |
| 196 // In network service land, the job initiates a fallback request. We reuse | |
| 197 // the existing job to deliver the fallback response. | |
| 198 std::unique_ptr<AppCacheJob> job; | |
| 199 if (!base::FeatureList::IsEnabled(features::kNetworkService)) { | |
|
michaeln
2017/07/17 21:04:55
Ditto question about encapsulating reuse vs recrea
ananta
2017/07/18 00:19:03
Moved this code to MaybeCreateJobForFallback().
| |
| 200 job = CreateJob(network_delegate); | |
| 201 } else { | |
| 202 DCHECK(job_.get()); | |
| 203 job.reset(job_.get()); | |
| 204 } | |
| 205 | |
| 190 DeliverAppCachedResponse(found_fallback_entry_, found_cache_id_, | 206 DeliverAppCachedResponse(found_fallback_entry_, found_cache_id_, |
| 191 found_manifest_url_, true, | 207 found_manifest_url_, true, |
| 192 found_namespace_entry_url_); | 208 found_namespace_entry_url_); |
| 193 return job.release(); | 209 return job.release(); |
| 194 } | 210 } |
| 195 | 211 |
| 196 void AppCacheRequestHandler::GetExtraResponseInfo(int64_t* cache_id, | 212 void AppCacheRequestHandler::GetExtraResponseInfo(int64_t* cache_id, |
| 197 GURL* manifest_url) { | 213 GURL* manifest_url) { |
| 198 *cache_id = cache_id_; | 214 *cache_id = cache_id_; |
| 199 *manifest_url = manifest_url_; | 215 *manifest_url = manifest_url_; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 323 job_.reset(); | 339 job_.reset(); |
| 324 } | 340 } |
| 325 | 341 |
| 326 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::CreateJob( | 342 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::CreateJob( |
| 327 net::NetworkDelegate* network_delegate) { | 343 net::NetworkDelegate* network_delegate) { |
| 328 std::unique_ptr<AppCacheJob> job = AppCacheJob::Create( | 344 std::unique_ptr<AppCacheJob> job = AppCacheJob::Create( |
| 329 is_main_resource(), host_, storage(), request_.get(), network_delegate, | 345 is_main_resource(), host_, storage(), request_.get(), network_delegate, |
| 330 base::Bind(&AppCacheRequestHandler::OnPrepareToRestart, | 346 base::Bind(&AppCacheRequestHandler::OnPrepareToRestart, |
| 331 base::Unretained(this))); | 347 base::Unretained(this))); |
| 332 job_ = job->GetWeakPtr(); | 348 job_ = job->GetWeakPtr(); |
| 333 if (!is_main_resource() && | 349 if (job_.get() && !is_main_resource() && |
|
michaeln
2017/07/17 21:04:55
can job_.get() test false here?
ananta
2017/07/18 00:19:03
Yeah. Removed it.
| |
| 334 base::FeatureList::IsEnabled(features::kNetworkService)) { | 350 base::FeatureList::IsEnabled(features::kNetworkService)) { |
| 335 AppCacheURLLoaderJob* loader_job = job_->AsURLLoaderJob(); | 351 AppCacheURLLoaderJob* loader_job = job_->AsURLLoaderJob(); |
| 336 | 352 |
| 337 loader_job->SetSubresourceLoadInfo( | 353 loader_job->SetSubresourceLoadInfo( |
| 338 std::move(subresource_load_info_), | 354 std::move(subresource_load_info_), |
| 339 network_url_loader_factory_getter_.get()); | 355 network_url_loader_factory_getter_.get()); |
| 340 } | 356 } |
| 341 | 357 |
| 342 return job; | 358 return job; |
| 343 } | 359 } |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 569 mojom::URLLoaderFactoryPtr factory_ptr = nullptr; | 585 mojom::URLLoaderFactoryPtr factory_ptr = nullptr; |
| 570 | 586 |
| 571 // The factory is destroyed when the renderer drops the connection. | 587 // The factory is destroyed when the renderer drops the connection. |
| 572 AppCacheSubresourceURLFactory::CreateURLLoaderFactory( | 588 AppCacheSubresourceURLFactory::CreateURLLoaderFactory( |
| 573 network_url_loader_factory_getter_.get(), appcache_host_, &factory_ptr); | 589 network_url_loader_factory_getter_.get(), appcache_host_, &factory_ptr); |
| 574 | 590 |
| 575 return factory_ptr; | 591 return factory_ptr; |
| 576 } | 592 } |
| 577 | 593 |
| 578 } // namespace content | 594 } // namespace content |
| OLD | NEW |