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 "content/browser/appcache/appcache.h" | 10 #include "content/browser/appcache/appcache.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 if (request->url().GetOrigin() == location.GetOrigin()) | 111 if (request->url().GetOrigin() == location.GetOrigin()) |
112 return NULL; | 112 return NULL; |
113 | 113 |
114 DCHECK(!job_.get()); // our jobs never generate redirects | 114 DCHECK(!job_.get()); // our jobs never generate redirects |
115 | 115 |
116 std::unique_ptr<AppCacheURLRequestJob> job; | 116 std::unique_ptr<AppCacheURLRequestJob> job; |
117 if (found_fallback_entry_.has_response_id()) { | 117 if (found_fallback_entry_.has_response_id()) { |
118 // 6.9.6, step 4: If this results in a redirect to another origin, | 118 // 6.9.6, step 4: If this results in a redirect to another origin, |
119 // get the resource of the fallback entry. | 119 // get the resource of the fallback entry. |
120 job = CreateJob(request, network_delegate); | 120 job = CreateJob(request, network_delegate); |
121 DeliverAppCachedResponse( | 121 DeliverAppCachedResponse(found_fallback_entry_, found_cache_id_, |
122 found_fallback_entry_, found_cache_id_, found_group_id_, | 122 found_manifest_url_, true, |
123 found_manifest_url_, true, found_namespace_entry_url_); | 123 found_namespace_entry_url_); |
124 } else if (!found_network_namespace_) { | 124 } else if (!found_network_namespace_) { |
125 // 6.9.6, step 6: Fail the resource load. | 125 // 6.9.6, step 6: Fail the resource load. |
126 job = CreateJob(request, network_delegate); | 126 job = CreateJob(request, network_delegate); |
127 DeliverErrorResponse(); | 127 DeliverErrorResponse(); |
128 } else { | 128 } else { |
129 // 6.9.6 step 3 and 5: Fetch the resource normally. | 129 // 6.9.6 step 3 and 5: Fetch the resource normally. |
130 } | 130 } |
131 | 131 |
132 return job.release(); | 132 return job.release(); |
133 } | 133 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 std::string header_value; | 165 std::string header_value; |
166 request->GetResponseHeaderByName(kFallbackOverrideHeader, &header_value); | 166 request->GetResponseHeaderByName(kFallbackOverrideHeader, &header_value); |
167 if (header_value == kFallbackOverrideValue) | 167 if (header_value == kFallbackOverrideValue) |
168 return NULL; | 168 return NULL; |
169 } | 169 } |
170 | 170 |
171 // 6.9.6, step 4: If this results in a 4xx or 5xx status code | 171 // 6.9.6, step 4: If this results in a 4xx or 5xx status code |
172 // or there were network errors, get the resource of the fallback entry. | 172 // or there were network errors, get the resource of the fallback entry. |
173 std::unique_ptr<AppCacheURLRequestJob> job = | 173 std::unique_ptr<AppCacheURLRequestJob> job = |
174 CreateJob(request, network_delegate); | 174 CreateJob(request, network_delegate); |
175 DeliverAppCachedResponse( | 175 DeliverAppCachedResponse(found_fallback_entry_, found_cache_id_, |
176 found_fallback_entry_, found_cache_id_, found_group_id_, | 176 found_manifest_url_, true, |
177 found_manifest_url_, true, found_namespace_entry_url_); | 177 found_namespace_entry_url_); |
178 return job.release(); | 178 return job.release(); |
179 } | 179 } |
180 | 180 |
181 void AppCacheRequestHandler::GetExtraResponseInfo(int64_t* cache_id, | 181 void AppCacheRequestHandler::GetExtraResponseInfo(int64_t* cache_id, |
182 GURL* manifest_url) { | 182 GURL* manifest_url) { |
183 *cache_id = cache_id_; | 183 *cache_id = cache_id_; |
184 *manifest_url = manifest_url_; | 184 *manifest_url = manifest_url_; |
185 } | 185 } |
186 | 186 |
187 void AppCacheRequestHandler::PrepareForCrossSiteTransfer(int old_process_id) { | 187 void AppCacheRequestHandler::PrepareForCrossSiteTransfer(int old_process_id) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 // that is current running. It's destined for the bit bucket anyway. | 223 // that is current running. It's destined for the bit bucket anyway. |
224 if (job_.get()) { | 224 if (job_.get()) { |
225 job_->Kill(); | 225 job_->Kill(); |
226 job_.reset(); | 226 job_.reset(); |
227 } | 227 } |
228 } | 228 } |
229 | 229 |
230 void AppCacheRequestHandler::DeliverAppCachedResponse( | 230 void AppCacheRequestHandler::DeliverAppCachedResponse( |
231 const AppCacheEntry& entry, | 231 const AppCacheEntry& entry, |
232 int64_t cache_id, | 232 int64_t cache_id, |
233 int64_t group_id, | |
234 const GURL& manifest_url, | 233 const GURL& manifest_url, |
235 bool is_fallback, | 234 bool is_fallback, |
236 const GURL& namespace_entry_url) { | 235 const GURL& namespace_entry_url) { |
237 DCHECK(host_ && job_.get() && job_->is_waiting()); | 236 DCHECK(host_ && job_.get() && job_->is_waiting()); |
238 DCHECK(entry.has_response_id()); | 237 DCHECK(entry.has_response_id()); |
239 | 238 |
240 // Cache information about the response, for use by GetExtraResponseInfo. | 239 // Cache information about the response, for use by GetExtraResponseInfo. |
241 cache_id_ = cache_id; | 240 cache_id_ = cache_id; |
242 manifest_url_ = manifest_url; | 241 manifest_url_ = manifest_url; |
243 | 242 |
244 if (IsResourceTypeFrame(resource_type_) && !namespace_entry_url.is_empty()) | 243 if (IsResourceTypeFrame(resource_type_) && !namespace_entry_url.is_empty()) |
245 host_->NotifyMainResourceIsNamespaceEntry(namespace_entry_url); | 244 host_->NotifyMainResourceIsNamespaceEntry(namespace_entry_url); |
246 | 245 |
247 job_->DeliverAppCachedResponse(manifest_url, group_id, cache_id, | 246 job_->DeliverAppCachedResponse(manifest_url, cache_id, entry, is_fallback); |
248 entry, is_fallback); | |
249 } | 247 } |
250 | 248 |
251 void AppCacheRequestHandler::DeliverErrorResponse() { | 249 void AppCacheRequestHandler::DeliverErrorResponse() { |
252 DCHECK(job_.get() && job_->is_waiting()); | 250 DCHECK(job_.get() && job_->is_waiting()); |
253 DCHECK_EQ(kAppCacheNoCacheId, cache_id_); | 251 DCHECK_EQ(kAppCacheNoCacheId, cache_id_); |
254 DCHECK(manifest_url_.is_empty()); | 252 DCHECK(manifest_url_.is_empty()); |
255 job_->DeliverErrorResponse(); | 253 job_->DeliverErrorResponse(); |
256 } | 254 } |
257 | 255 |
258 void AppCacheRequestHandler::DeliverNetworkResponse() { | 256 void AppCacheRequestHandler::DeliverNetworkResponse() { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 found_entry_ = entry; | 376 found_entry_ = entry; |
379 found_namespace_entry_url_ = namespace_entry_url; | 377 found_namespace_entry_url_ = namespace_entry_url; |
380 found_fallback_entry_ = fallback_entry; | 378 found_fallback_entry_ = fallback_entry; |
381 found_cache_id_ = cache_id; | 379 found_cache_id_ = cache_id; |
382 found_group_id_ = group_id; | 380 found_group_id_ = group_id; |
383 found_manifest_url_ = manifest_url; | 381 found_manifest_url_ = manifest_url; |
384 found_network_namespace_ = false; // not applicable to main requests | 382 found_network_namespace_ = false; // not applicable to main requests |
385 | 383 |
386 if (found_entry_.has_response_id()) { | 384 if (found_entry_.has_response_id()) { |
387 DCHECK(!found_fallback_entry_.has_response_id()); | 385 DCHECK(!found_fallback_entry_.has_response_id()); |
388 DeliverAppCachedResponse( | 386 DeliverAppCachedResponse(found_entry_, found_cache_id_, found_manifest_url_, |
389 found_entry_, found_cache_id_, found_group_id_, found_manifest_url_, | 387 false, found_namespace_entry_url_); |
390 false, found_namespace_entry_url_); | |
391 } else { | 388 } else { |
392 DeliverNetworkResponse(); | 389 DeliverNetworkResponse(); |
393 } | 390 } |
394 } | 391 } |
395 | 392 |
396 // Sub-resource handling ---------------------------------------------- | 393 // Sub-resource handling ---------------------------------------------- |
397 | 394 |
398 std::unique_ptr<AppCacheURLRequestJob> | 395 std::unique_ptr<AppCacheURLRequestJob> |
399 AppCacheRequestHandler::MaybeLoadSubResource( | 396 AppCacheRequestHandler::MaybeLoadSubResource( |
400 net::URLRequest* request, | 397 net::URLRequest* request, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 host_->associated_cache(), url, | 430 host_->associated_cache(), url, |
434 &found_entry_, &found_fallback_entry_, &found_network_namespace_); | 431 &found_entry_, &found_fallback_entry_, &found_network_namespace_); |
435 | 432 |
436 if (found_entry_.has_response_id()) { | 433 if (found_entry_.has_response_id()) { |
437 // Step 2: If there's an entry, get it instead. | 434 // Step 2: If there's an entry, get it instead. |
438 DCHECK(!found_network_namespace_ && | 435 DCHECK(!found_network_namespace_ && |
439 !found_fallback_entry_.has_response_id()); | 436 !found_fallback_entry_.has_response_id()); |
440 found_cache_id_ = cache->cache_id(); | 437 found_cache_id_ = cache->cache_id(); |
441 found_group_id_ = cache->owning_group()->group_id(); | 438 found_group_id_ = cache->owning_group()->group_id(); |
442 found_manifest_url_ = cache->owning_group()->manifest_url(); | 439 found_manifest_url_ = cache->owning_group()->manifest_url(); |
443 DeliverAppCachedResponse( | 440 DeliverAppCachedResponse(found_entry_, found_cache_id_, found_manifest_url_, |
444 found_entry_, found_cache_id_, found_group_id_, found_manifest_url_, | 441 false, GURL()); |
445 false, GURL()); | |
446 return; | 442 return; |
447 } | 443 } |
448 | 444 |
449 if (found_fallback_entry_.has_response_id()) { | 445 if (found_fallback_entry_.has_response_id()) { |
450 // Step 4: Fetch the resource normally, if this results | 446 // Step 4: Fetch the resource normally, if this results |
451 // in certain conditions, then use the fallback. | 447 // in certain conditions, then use the fallback. |
452 DCHECK(!found_network_namespace_ && | 448 DCHECK(!found_network_namespace_ && |
453 !found_entry_.has_response_id()); | 449 !found_entry_.has_response_id()); |
454 found_cache_id_ = cache->cache_id(); | 450 found_cache_id_ = cache->cache_id(); |
455 found_manifest_url_ = cache->owning_group()->manifest_url(); | 451 found_manifest_url_ = cache->owning_group()->manifest_url(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 if (!host_->associated_cache() || | 483 if (!host_->associated_cache() || |
488 !host_->associated_cache()->is_complete()) { | 484 !host_->associated_cache()->is_complete()) { |
489 DeliverNetworkResponse(); | 485 DeliverNetworkResponse(); |
490 return; | 486 return; |
491 } | 487 } |
492 | 488 |
493 ContinueMaybeLoadSubResource(); | 489 ContinueMaybeLoadSubResource(); |
494 } | 490 } |
495 | 491 |
496 } // namespace content | 492 } // namespace content |
OLD | NEW |