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 "webkit/appcache/appcache_request_handler.h" | 5 #include "webkit/appcache/appcache_request_handler.h" |
| 6 | 6 |
| 7 #include "net/url_request/url_request.h" | 7 #include "net/url_request/url_request.h" |
| 8 #include "net/url_request/url_request_job.h" | 8 #include "net/url_request/url_request_job.h" |
| 9 #include "webkit/appcache/appcache.h" | 9 #include "webkit/appcache/appcache.h" |
| 10 #include "webkit/appcache/appcache_policy.h" | 10 #include "webkit/appcache/appcache_policy.h" |
| 11 #include "webkit/appcache/appcache_url_request_job.h" | 11 #include "webkit/appcache/appcache_url_request_job.h" |
| 12 | 12 |
| 13 namespace appcache { | 13 namespace appcache { |
| 14 | 14 |
| 15 AppCacheRequestHandler::AppCacheRequestHandler( | 15 AppCacheRequestHandler::AppCacheRequestHandler( |
| 16 AppCacheHost* host, ResourceType::Type resource_type) | 16 AppCacheHost* host, ResourceType::Type resource_type) |
| 17 : host_(host), resource_type_(resource_type), | 17 : host_(host), resource_type_(resource_type), |
| 18 is_waiting_for_cache_selection_(false), found_group_id_(0), | 18 is_waiting_for_cache_selection_(false), found_group_id_(0), |
| 19 found_cache_id_(0), found_network_namespace_(false), | 19 found_cache_id_(0), found_network_namespace_(false), |
| 20 cache_entry_not_found_(false) { | 20 cache_entry_not_found_(false), maybe_load_resource_executed_(false) { |
| 21 DCHECK(host_); | 21 DCHECK(host_); |
| 22 host_->AddObserver(this); | 22 host_->AddObserver(this); |
| 23 } | 23 } |
| 24 | 24 |
| 25 AppCacheRequestHandler::~AppCacheRequestHandler() { | 25 AppCacheRequestHandler::~AppCacheRequestHandler() { |
| 26 if (host_) { | 26 if (host_) { |
| 27 storage()->CancelDelegateCallbacks(this); | 27 storage()->CancelDelegateCallbacks(this); |
| 28 host_->RemoveObserver(this); | 28 host_->RemoveObserver(this); |
| 29 } | 29 } |
| 30 } | 30 } |
| 31 | 31 |
| 32 AppCacheStorage* AppCacheRequestHandler::storage() const { | 32 AppCacheStorage* AppCacheRequestHandler::storage() const { |
| 33 DCHECK(host_); | 33 DCHECK(host_); |
| 34 return host_->service()->storage(); | 34 return host_->service()->storage(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 void AppCacheRequestHandler::GetExtraResponseInfo( | 37 void AppCacheRequestHandler::GetExtraResponseInfo( |
| 38 int64* cache_id, GURL* manifest_url) { | 38 int64* cache_id, GURL* manifest_url) { |
| 39 if (job_ && job_->is_delivering_appcache_response()) { | 39 if (job_ && job_->is_delivering_appcache_response()) { |
| 40 *cache_id = job_->cache_id(); | 40 *cache_id = job_->cache_id(); |
| 41 *manifest_url = job_->manifest_url(); | 41 *manifest_url = job_->manifest_url(); |
| 42 } | 42 } |
| 43 } | 43 } |
| 44 | 44 |
| 45 AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadResource( | 45 AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadResource( |
| 46 net::URLRequest* request, net::NetworkDelegate* network_delegate) { | 46 net::URLRequest* request, net::NetworkDelegate* network_delegate) { |
| 47 maybe_load_resource_executed_ = true; | |
| 47 if (!host_ || !IsSchemeAndMethodSupported(request) || cache_entry_not_found_) | 48 if (!host_ || !IsSchemeAndMethodSupported(request) || cache_entry_not_found_) |
| 48 return NULL; | 49 return NULL; |
| 49 | 50 |
| 50 // This method can get called multiple times over the life | 51 // This method can get called multiple times over the life |
| 51 // of a request. The case we detect here is having scheduled | 52 // of a request. The case we detect here is having scheduled |
| 52 // delivery of a "network response" using a job setup on an | 53 // delivery of a "network response" using a job setup on an |
| 53 // earlier call thru this method. To send the request thru | 54 // earlier call thru this method. To send the request thru |
| 54 // to the network involves restarting the request altogether, | 55 // to the network involves restarting the request altogether, |
| 55 // which will call thru to our interception layer again. | 56 // which will call thru to our interception layer again. |
| 56 // This time thru, we return NULL so the request hits the wire. | 57 // This time thru, we return NULL so the request hits the wire. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 } | 90 } |
| 90 | 91 |
| 91 AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadFallbackForRedirect( | 92 AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadFallbackForRedirect( |
| 92 net::URLRequest* request, | 93 net::URLRequest* request, |
| 93 net::NetworkDelegate* network_delegate, | 94 net::NetworkDelegate* network_delegate, |
| 94 const GURL& location) { | 95 const GURL& location) { |
| 95 if (!host_ || !IsSchemeAndMethodSupported(request) || cache_entry_not_found_) | 96 if (!host_ || !IsSchemeAndMethodSupported(request) || cache_entry_not_found_) |
| 96 return NULL; | 97 return NULL; |
| 97 if (is_main_resource()) | 98 if (is_main_resource()) |
| 98 return NULL; | 99 return NULL; |
| 100 if (!maybe_load_resource_executed_) | |
|
michaeln
2012/09/06 19:49:05
Please add a TODO here points at crbug/121325
vabr (Chromium)
2012/09/07 08:37:27
Done.
| |
| 101 return NULL; | |
| 99 if (request->url().GetOrigin() == location.GetOrigin()) | 102 if (request->url().GetOrigin() == location.GetOrigin()) |
| 100 return NULL; | 103 return NULL; |
| 101 | 104 |
| 102 DCHECK(!job_); // our jobs never generate redirects | 105 DCHECK(!job_); // our jobs never generate redirects |
| 103 | 106 |
| 104 if (found_fallback_entry_.has_response_id()) { | 107 if (found_fallback_entry_.has_response_id()) { |
| 105 // 6.9.6, step 4: If this results in a redirect to another origin, | 108 // 6.9.6, step 4: If this results in a redirect to another origin, |
| 106 // get the resource of the fallback entry. | 109 // get the resource of the fallback entry. |
| 107 job_ = new AppCacheURLRequestJob(request, network_delegate, storage()); | 110 job_ = new AppCacheURLRequestJob(request, network_delegate, storage()); |
| 108 DeliverAppCachedResponse( | 111 DeliverAppCachedResponse( |
| 109 found_fallback_entry_, found_cache_id_, found_group_id_, | 112 found_fallback_entry_, found_cache_id_, found_group_id_, |
| 110 found_manifest_url_, true, found_namespace_entry_url_); | 113 found_manifest_url_, true, found_namespace_entry_url_); |
| 111 } else if (!found_network_namespace_) { | 114 } else if (!found_network_namespace_) { |
| 112 // 6.9.6, step 6: Fail the resource load. | 115 // 6.9.6, step 6: Fail the resource load. |
| 113 job_ = new AppCacheURLRequestJob(request, network_delegate, storage()); | 116 job_ = new AppCacheURLRequestJob(request, network_delegate, storage()); |
| 114 DeliverErrorResponse(); | 117 DeliverErrorResponse(); |
| 115 } else { | 118 } else { |
| 116 // 6.9.6 step 3 and 5: Fetch the resource normally. | 119 // 6.9.6 step 3 and 5: Fetch the resource normally. |
| 117 } | 120 } |
| 118 | 121 |
| 119 return job_; | 122 return job_; |
| 120 } | 123 } |
| 121 | 124 |
| 122 AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadFallbackForResponse( | 125 AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadFallbackForResponse( |
| 123 net::URLRequest* request, net::NetworkDelegate* network_delegate) { | 126 net::URLRequest* request, net::NetworkDelegate* network_delegate) { |
| 124 if (!host_ || !IsSchemeAndMethodSupported(request) || cache_entry_not_found_) | 127 if (!host_ || !IsSchemeAndMethodSupported(request) || cache_entry_not_found_) |
| 125 return NULL; | 128 return NULL; |
| 126 if (!found_fallback_entry_.has_response_id()) | 129 if (!found_fallback_entry_.has_response_id()) |
| 127 return NULL; | 130 return NULL; |
|
vabr (Chromium)
2012/09/06 17:34:21
I did not add any condition "!maybe_load_resource_
michaeln
2012/09/06 19:49:05
Ok. Since found_fallback_entry_ will not have anyt
| |
| 128 | 131 |
| 129 if (request->status().status() == net::URLRequestStatus::CANCELED || | 132 if (request->status().status() == net::URLRequestStatus::CANCELED || |
| 130 request->status().status() == net::URLRequestStatus::HANDLED_EXTERNALLY) { | 133 request->status().status() == net::URLRequestStatus::HANDLED_EXTERNALLY) { |
| 131 // 6.9.6, step 4: But not if the user canceled the download. | 134 // 6.9.6, step 4: But not if the user canceled the download. |
| 132 return NULL; | 135 return NULL; |
| 133 } | 136 } |
| 134 | 137 |
| 135 // We don't fallback for responses that we delivered. | 138 // We don't fallback for responses that we delivered. |
| 136 if (job_) { | 139 if (job_) { |
| 137 DCHECK(!job_->is_delivering_network_response()); | 140 DCHECK(!job_->is_delivering_network_response()); |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 if (!host_->associated_cache() || | 365 if (!host_->associated_cache() || |
| 363 !host_->associated_cache()->is_complete()) { | 366 !host_->associated_cache()->is_complete()) { |
| 364 DeliverNetworkResponse(); | 367 DeliverNetworkResponse(); |
| 365 return; | 368 return; |
| 366 } | 369 } |
| 367 | 370 |
| 368 ContinueMaybeLoadSubResource(); | 371 ContinueMaybeLoadSubResource(); |
| 369 } | 372 } |
| 370 | 373 |
| 371 } // namespace appcache | 374 } // namespace appcache |
| OLD | NEW |