 Chromium Code Reviews
 Chromium Code Reviews Issue 3529009:
  Fix http/tests/appcache/foreign-fallback.html  (Closed) 
  Base URL: svn://chrome-svn/chrome/trunk/src/
    
  
    Issue 3529009:
  Fix http/tests/appcache/foreign-fallback.html  (Closed) 
  Base URL: svn://chrome-svn/chrome/trunk/src/| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_url_request_job.h" | 10 #include "webkit/appcache/appcache_url_request_job.h" | 
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 if (!host_ || !IsSchemeAndMethodSupported(request) || cache_entry_not_found_) | 90 if (!host_ || !IsSchemeAndMethodSupported(request) || cache_entry_not_found_) | 
| 91 return NULL; | 91 return NULL; | 
| 92 if (is_main_resource()) | 92 if (is_main_resource()) | 
| 93 return NULL; | 93 return NULL; | 
| 94 if (request->url().GetOrigin() == location.GetOrigin()) | 94 if (request->url().GetOrigin() == location.GetOrigin()) | 
| 95 return NULL; | 95 return NULL; | 
| 96 | 96 | 
| 97 DCHECK(!job_); // our jobs never generate redirects | 97 DCHECK(!job_); // our jobs never generate redirects | 
| 98 | 98 | 
| 99 if (found_fallback_entry_.has_response_id()) { | 99 if (found_fallback_entry_.has_response_id()) { | 
| 100 // 6.9.6, step 4: If this results in a redirect to another origin, | 100 // 6.9.6, step 4: If this results in a redirect to another origin, | 
| 
kinuko
2010/11/02 07:47:23
(not a review comment) I thought it would be nice
 
michaeln
2010/11/02 20:25:36
Comments that refer section number in the HTML5 dr
 
kinuko
2010/11/03 00:25:18
That's true. I just wasn't able to find a relevant
 | |
| 101 // get the resource of the fallback entry. | 101 // get the resource of the fallback entry. | 
| 102 job_ = new AppCacheURLRequestJob(request, storage()); | 102 job_ = new AppCacheURLRequestJob(request, storage()); | 
| 103 DeliverAppCachedResponse( | 103 DeliverAppCachedResponse( | 
| 104 found_fallback_entry_, found_cache_id_, found_manifest_url_, true); | 104 found_fallback_entry_, found_cache_id_, found_manifest_url_, | 
| 105 true, found_fallback_url_); | |
| 105 } else if (!found_network_namespace_) { | 106 } else if (!found_network_namespace_) { | 
| 106 // 6.9.6, step 6: Fail the resource load. | 107 // 6.9.6, step 6: Fail the resource load. | 
| 107 job_ = new AppCacheURLRequestJob(request, storage()); | 108 job_ = new AppCacheURLRequestJob(request, storage()); | 
| 108 DeliverErrorResponse(); | 109 DeliverErrorResponse(); | 
| 109 } else { | 110 } else { | 
| 110 // 6.9.6 step 3 and 5: Fetch the resource normally. | 111 // 6.9.6 step 3 and 5: Fetch the resource normally. | 
| 111 } | 112 } | 
| 112 | 113 | 
| 113 return job_; | 114 return job_; | 
| 114 } | 115 } | 
| (...skipping 20 matching lines...) Expand all Loading... | |
| 135 if (request->status().is_success()) { | 136 if (request->status().is_success()) { | 
| 136 int code_major = request->GetResponseCode() / 100; | 137 int code_major = request->GetResponseCode() / 100; | 
| 137 if (code_major !=4 && code_major != 5) | 138 if (code_major !=4 && code_major != 5) | 
| 138 return NULL; | 139 return NULL; | 
| 139 } | 140 } | 
| 140 | 141 | 
| 141 // 6.9.6, step 4: If this results in a 4xx or 5xx status code | 142 // 6.9.6, step 4: If this results in a 4xx or 5xx status code | 
| 142 // or there were network errors, get the resource of the fallback entry. | 143 // or there were network errors, get the resource of the fallback entry. | 
| 143 job_ = new AppCacheURLRequestJob(request, storage()); | 144 job_ = new AppCacheURLRequestJob(request, storage()); | 
| 144 DeliverAppCachedResponse( | 145 DeliverAppCachedResponse( | 
| 145 found_fallback_entry_, found_cache_id_, found_manifest_url_, true); | 146 found_fallback_entry_, found_cache_id_, found_manifest_url_, | 
| 147 true, found_fallback_url_); | |
| 146 return job_; | 148 return job_; | 
| 147 } | 149 } | 
| 148 | 150 | 
| 149 void AppCacheRequestHandler::OnDestructionImminent(AppCacheHost* host) { | 151 void AppCacheRequestHandler::OnDestructionImminent(AppCacheHost* host) { | 
| 150 storage()->CancelDelegateCallbacks(this); | 152 storage()->CancelDelegateCallbacks(this); | 
| 151 host_ = NULL; // no need to RemoveObserver, the host is being deleted | 153 host_ = NULL; // no need to RemoveObserver, the host is being deleted | 
| 152 | 154 | 
| 153 // Since the host is being deleted, we don't have to complete any job | 155 // Since the host is being deleted, we don't have to complete any job | 
| 154 // that is current running. It's destined for the bit bucket anyway. | 156 // that is current running. It's destined for the bit bucket anyway. | 
| 155 if (job_) { | 157 if (job_) { | 
| 156 job_->Kill(); | 158 job_->Kill(); | 
| 157 job_ = NULL; | 159 job_ = NULL; | 
| 158 } | 160 } | 
| 159 } | 161 } | 
| 160 | 162 | 
| 161 void AppCacheRequestHandler::DeliverAppCachedResponse( | 163 void AppCacheRequestHandler::DeliverAppCachedResponse( | 
| 162 const AppCacheEntry& entry, int64 cache_id, const GURL& manifest_url, | 164 const AppCacheEntry& entry, int64 cache_id, const GURL& manifest_url, | 
| 163 bool is_fallback) { | 165 bool is_fallback, const GURL& fallback_url) { | 
| 164 DCHECK(job_ && job_->is_waiting()); | 166 DCHECK(host_ && job_ && job_->is_waiting()); | 
| 165 DCHECK(entry.has_response_id()); | 167 DCHECK(entry.has_response_id()); | 
| 168 | |
| 169 if (ResourceType::IsFrame(resource_type_) && is_fallback) { | |
| 170 DCHECK(!fallback_url.is_empty()); | |
| 171 host_->NotifyMainResourceFallback(fallback_url); | |
| 172 } | |
| 173 | |
| 166 job_->DeliverAppCachedResponse(manifest_url, cache_id, entry, is_fallback); | 174 job_->DeliverAppCachedResponse(manifest_url, cache_id, entry, is_fallback); | 
| 167 } | 175 } | 
| 168 | 176 | 
| 169 void AppCacheRequestHandler::DeliverErrorResponse() { | 177 void AppCacheRequestHandler::DeliverErrorResponse() { | 
| 170 DCHECK(job_ && job_->is_waiting()); | 178 DCHECK(job_ && job_->is_waiting()); | 
| 171 job_->DeliverErrorResponse(); | 179 job_->DeliverErrorResponse(); | 
| 172 } | 180 } | 
| 173 | 181 | 
| 174 void AppCacheRequestHandler::DeliverNetworkResponse() { | 182 void AppCacheRequestHandler::DeliverNetworkResponse() { | 
| 175 DCHECK(job_ && job_->is_waiting()); | 183 DCHECK(job_ && job_->is_waiting()); | 
| 176 job_->DeliverNetworkResponse(); | 184 job_->DeliverNetworkResponse(); | 
| 177 } | 185 } | 
| 178 | 186 | 
| 179 // Main-resource handling ---------------------------------------------- | 187 // Main-resource handling ---------------------------------------------- | 
| 180 | 188 | 
| 181 void AppCacheRequestHandler::MaybeLoadMainResource(URLRequest* request) { | 189 void AppCacheRequestHandler::MaybeLoadMainResource(URLRequest* request) { | 
| 182 DCHECK(!job_); | 190 DCHECK(!job_); | 
| 183 | 191 | 
| 184 // We may have to wait for our storage query to complete, but | 192 // We may have to wait for our storage query to complete, but | 
| 185 // this query can also complete syncrhonously. | 193 // this query can also complete syncrhonously. | 
| 186 job_ = new AppCacheURLRequestJob(request, storage()); | 194 job_ = new AppCacheURLRequestJob(request, storage()); | 
| 187 storage()->FindResponseForMainRequest(request->url(), this); | 195 storage()->FindResponseForMainRequest(request->url(), this); | 
| 188 } | 196 } | 
| 189 | 197 | 
| 190 void AppCacheRequestHandler::OnMainResponseFound( | 198 void AppCacheRequestHandler::OnMainResponseFound( | 
| 191 const GURL& url, const AppCacheEntry& entry, | 199 const GURL& url, const AppCacheEntry& entry, | 
| 192 const AppCacheEntry& fallback_entry, | 200 const GURL& fallback_url, const AppCacheEntry& fallback_entry, | 
| 193 int64 cache_id, const GURL& manifest_url, | 201 int64 cache_id, const GURL& manifest_url, | 
| 194 bool was_blocked_by_policy) { | 202 bool was_blocked_by_policy) { | 
| 195 DCHECK(host_); | 203 DCHECK(host_); | 
| 196 DCHECK(is_main_resource()); | 204 DCHECK(is_main_resource()); | 
| 197 DCHECK(!entry.IsForeign()); | 205 DCHECK(!entry.IsForeign()); | 
| 198 DCHECK(!fallback_entry.IsForeign()); | 206 DCHECK(!fallback_entry.IsForeign()); | 
| 199 DCHECK(!(entry.has_response_id() && fallback_entry.has_response_id())); | 207 DCHECK(!(entry.has_response_id() && fallback_entry.has_response_id())); | 
| 200 | 208 | 
| 201 if (ResourceType::IsFrame(resource_type_)) { | 209 if (ResourceType::IsFrame(resource_type_)) { | 
| 202 if (was_blocked_by_policy) | 210 if (was_blocked_by_policy) | 
| 203 host_->NotifyMainResourceBlocked(manifest_url); | 211 host_->NotifyMainResourceBlocked(manifest_url); | 
| 204 | 212 | 
| 205 if (cache_id != kNoCacheId) { | 213 if (cache_id != kNoCacheId) { | 
| 206 // AppCacheHost loads and holds a reference to the main resource cache | 214 // AppCacheHost loads and holds a reference to the main resource cache | 
| 207 // for two reasons, firstly to preload the cache into the working set | 215 // for two reasons, firstly to preload the cache into the working set | 
| 208 // in advance of subresource loads happening, secondly to prevent the | 216 // in advance of subresource loads happening, secondly to prevent the | 
| 209 // AppCache from falling out of the working set on frame navigations. | 217 // AppCache from falling out of the working set on frame navigations. | 
| 210 host_->LoadMainResourceCache(cache_id); | 218 host_->LoadMainResourceCache(cache_id); | 
| 211 } | 219 } | 
| 212 } else { | 220 } else { | 
| 213 DCHECK(ResourceType::IsSharedWorker(resource_type_)); | 221 DCHECK(ResourceType::IsSharedWorker(resource_type_)); | 
| 214 if (was_blocked_by_policy) | 222 if (was_blocked_by_policy) | 
| 215 host_->frontend()->OnContentBlocked(host_->host_id(), manifest_url); | 223 host_->frontend()->OnContentBlocked(host_->host_id(), manifest_url); | 
| 216 } | 224 } | 
| 217 | 225 | 
| 218 // 6.11.1 Navigating across documents, steps 10 and 14. | 226 // 6.11.1 Navigating across documents, steps 10 and 14. | 
| 219 | 227 | 
| 220 found_entry_ = entry; | 228 found_entry_ = entry; | 
| 229 found_fallback_url_ = fallback_url; | |
| 221 found_fallback_entry_ = fallback_entry; | 230 found_fallback_entry_ = fallback_entry; | 
| 222 found_cache_id_ = cache_id; | 231 found_cache_id_ = cache_id; | 
| 223 found_manifest_url_ = manifest_url; | 232 found_manifest_url_ = manifest_url; | 
| 224 found_network_namespace_ = false; // not applicable to main requests | 233 found_network_namespace_ = false; // not applicable to main requests | 
| 225 | 234 | 
| 226 if (found_entry_.has_response_id()) { | 235 if (found_entry_.has_response_id()) { | 
| 227 DeliverAppCachedResponse( | 236 DeliverAppCachedResponse( | 
| 228 found_entry_, found_cache_id_, found_manifest_url_, false); | 237 found_entry_, found_cache_id_, found_manifest_url_, | 
| 238 false, GURL()); | |
| 229 } else { | 239 } else { | 
| 230 DeliverNetworkResponse(); | 240 DeliverNetworkResponse(); | 
| 231 } | 241 } | 
| 232 } | 242 } | 
| 233 | 243 | 
| 234 // Sub-resource handling ---------------------------------------------- | 244 // Sub-resource handling ---------------------------------------------- | 
| 235 | 245 | 
| 236 void AppCacheRequestHandler::MaybeLoadSubResource( | 246 void AppCacheRequestHandler::MaybeLoadSubResource( | 
| 237 URLRequest* request) { | 247 URLRequest* request) { | 
| 238 DCHECK(!job_); | 248 DCHECK(!job_); | 
| (...skipping 29 matching lines...) Expand all Loading... | |
| 268 host_->associated_cache(), url, | 278 host_->associated_cache(), url, | 
| 269 &found_entry_, &found_fallback_entry_, &found_network_namespace_); | 279 &found_entry_, &found_fallback_entry_, &found_network_namespace_); | 
| 270 | 280 | 
| 271 if (found_entry_.has_response_id()) { | 281 if (found_entry_.has_response_id()) { | 
| 272 // Step 2: If there's an entry, get it instead. | 282 // Step 2: If there's an entry, get it instead. | 
| 273 DCHECK(!found_network_namespace_ && | 283 DCHECK(!found_network_namespace_ && | 
| 274 !found_fallback_entry_.has_response_id()); | 284 !found_fallback_entry_.has_response_id()); | 
| 275 found_cache_id_ = cache->cache_id(); | 285 found_cache_id_ = cache->cache_id(); | 
| 276 found_manifest_url_ = cache->owning_group()->manifest_url(); | 286 found_manifest_url_ = cache->owning_group()->manifest_url(); | 
| 277 DeliverAppCachedResponse( | 287 DeliverAppCachedResponse( | 
| 278 found_entry_, found_cache_id_, found_manifest_url_, false); | 288 found_entry_, found_cache_id_, found_manifest_url_, | 
| 289 false, GURL()); | |
| 279 return; | 290 return; | 
| 280 } | 291 } | 
| 281 | 292 | 
| 282 if (found_fallback_entry_.has_response_id()) { | 293 if (found_fallback_entry_.has_response_id()) { | 
| 283 // Step 4: Fetch the resource normally, if this results | 294 // Step 4: Fetch the resource normally, if this results | 
| 284 // in certain conditions, then use the fallback. | 295 // in certain conditions, then use the fallback. | 
| 285 DCHECK(!found_network_namespace_ && | 296 DCHECK(!found_network_namespace_ && | 
| 286 !found_entry_.has_response_id()); | 297 !found_entry_.has_response_id()); | 
| 287 found_cache_id_ = cache->cache_id(); | 298 found_cache_id_ = cache->cache_id(); | 
| 288 found_manifest_url_ = cache->owning_group()->manifest_url(); | 299 found_manifest_url_ = cache->owning_group()->manifest_url(); | 
| (...skipping 25 matching lines...) Expand all Loading... | |
| 314 if (!host_->associated_cache() || | 325 if (!host_->associated_cache() || | 
| 315 !host_->associated_cache()->is_complete()) { | 326 !host_->associated_cache()->is_complete()) { | 
| 316 DeliverNetworkResponse(); | 327 DeliverNetworkResponse(); | 
| 317 return; | 328 return; | 
| 318 } | 329 } | 
| 319 | 330 | 
| 320 ContinueMaybeLoadSubResource(); | 331 ContinueMaybeLoadSubResource(); | 
| 321 } | 332 } | 
| 322 | 333 | 
| 323 } // namespace appcache | 334 } // namespace appcache | 
| OLD | NEW |