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/browser/appcache/appcache_request_handler.h" | 5 #include "webkit/browser/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/browser/appcache/appcache.h" | 9 #include "webkit/browser/appcache/appcache.h" |
10 #include "webkit/browser/appcache/appcache_policy.h" | 10 #include "webkit/browser/appcache/appcache_policy.h" |
(...skipping 18 matching lines...) Expand all Loading... |
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_.get() && job_->is_delivering_appcache_response()) { | 39 if (job_.get() && (job_->is_delivering_appcache_response() || |
| 40 job_->is_delivering_synthesized_response())) { |
40 *cache_id = job_->cache_id(); | 41 *cache_id = job_->cache_id(); |
41 *manifest_url = job_->manifest_url(); | 42 *manifest_url = job_->manifest_url(); |
42 } | 43 } |
43 } | 44 } |
44 | 45 |
45 AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadResource( | 46 AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadResource( |
46 net::URLRequest* request, net::NetworkDelegate* network_delegate) { | 47 net::URLRequest* request, net::NetworkDelegate* network_delegate) { |
47 maybe_load_resource_executed_ = true; | 48 maybe_load_resource_executed_ = true; |
48 if (!host_ || !IsSchemeAndMethodSupported(request) || cache_entry_not_found_) | 49 if (!host_ || !IsSchemeAndMethodSupported(request) || cache_entry_not_found_) |
49 return NULL; | 50 return NULL; |
50 | 51 |
51 // This method can get called multiple times over the life | 52 // This method can get called multiple times over the life |
52 // of a request. The case we detect here is having scheduled | 53 // of a request. The case we detect here is having scheduled |
53 // delivery of a "network response" using a job setup on an | 54 // delivery of a "network response" using a job setup on an |
54 // earlier call thru this method. To send the request thru | 55 // earlier call thru this method. To send the request thru |
55 // to the network involves restarting the request altogether, | 56 // to the network involves restarting the request altogether, |
56 // which will call thru to our interception layer again. | 57 // which will call thru to our interception layer again. |
57 // This time thru, we return NULL so the request hits the wire. | 58 // This time thru, we return NULL so the request hits the wire. |
58 if (job_.get()) { | 59 if (job_.get()) { |
59 DCHECK(job_->is_delivering_network_response() || | 60 // Note: no longer valid since we can generate 302s now. |
60 job_->cache_entry_not_found()); | 61 //DCHECK(job_->is_delivering_network_response() || |
| 62 // job_->cache_entry_not_found()); |
| 63 bool use_network = job_->is_delivering_network_response(); |
61 if (job_->cache_entry_not_found()) | 64 if (job_->cache_entry_not_found()) |
62 cache_entry_not_found_ = true; | 65 cache_entry_not_found_ = true; |
63 job_ = NULL; | 66 job_ = NULL; |
64 storage()->CancelDelegateCallbacks(this); | 67 storage()->CancelDelegateCallbacks(this); |
65 return NULL; | 68 if (use_network) |
| 69 return NULL; |
66 } | 70 } |
67 | 71 |
68 // Clear out our 'found' fields since we're starting a request for a | 72 // Clear out our 'found' fields since we're starting a request for a |
69 // new resource, any values in those fields are no longer valid. | 73 // new resource, any values in those fields are no longer valid. |
70 found_entry_ = AppCacheEntry(); | 74 found_entry_ = AppCacheEntry(); |
71 found_fallback_entry_ = AppCacheEntry(); | 75 found_fallback_entry_ = AppCacheEntry(); |
72 found_cache_id_ = kNoCacheId; | 76 found_cache_id_ = kNoCacheId; |
73 found_manifest_url_ = GURL(); | 77 found_manifest_url_ = GURL(); |
74 found_network_namespace_ = false; | 78 found_network_namespace_ = false; |
75 | 79 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 void AppCacheRequestHandler::DeliverAppCachedResponse( | 189 void AppCacheRequestHandler::DeliverAppCachedResponse( |
186 const AppCacheEntry& entry, int64 cache_id, int64 group_id, | 190 const AppCacheEntry& entry, int64 cache_id, int64 group_id, |
187 const GURL& manifest_url, bool is_fallback, | 191 const GURL& manifest_url, bool is_fallback, |
188 const GURL& namespace_entry_url) { | 192 const GURL& namespace_entry_url) { |
189 DCHECK(host_ && job_.get() && job_->is_waiting()); | 193 DCHECK(host_ && job_.get() && job_->is_waiting()); |
190 DCHECK(entry.has_response_id()); | 194 DCHECK(entry.has_response_id()); |
191 | 195 |
192 if (ResourceType::IsFrame(resource_type_) && !namespace_entry_url.is_empty()) | 196 if (ResourceType::IsFrame(resource_type_) && !namespace_entry_url.is_empty()) |
193 host_->NotifyMainResourceIsNamespaceEntry(namespace_entry_url); | 197 host_->NotifyMainResourceIsNamespaceEntry(namespace_entry_url); |
194 | 198 |
| 199 // Executable handler hackery to distinguish between main vs sub resource |
| 200 // loads in the handler script. |
| 201 if (entry.IsExecutable()) |
| 202 job_->set_is_main_resource_load(is_main_resource()); |
| 203 |
195 job_->DeliverAppCachedResponse(manifest_url, group_id, cache_id, | 204 job_->DeliverAppCachedResponse(manifest_url, group_id, cache_id, |
196 entry, is_fallback); | 205 entry, is_fallback); |
197 } | 206 } |
198 | 207 |
199 void AppCacheRequestHandler::DeliverErrorResponse() { | 208 void AppCacheRequestHandler::DeliverErrorResponse() { |
200 DCHECK(job_.get() && job_->is_waiting()); | 209 DCHECK(job_.get() && job_->is_waiting()); |
201 job_->DeliverErrorResponse(); | 210 job_->DeliverErrorResponse(); |
202 } | 211 } |
203 | 212 |
204 void AppCacheRequestHandler::DeliverNetworkResponse() { | 213 void AppCacheRequestHandler::DeliverNetworkResponse() { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 ContinueMaybeLoadSubResource(); | 319 ContinueMaybeLoadSubResource(); |
311 } | 320 } |
312 | 321 |
313 void AppCacheRequestHandler::ContinueMaybeLoadSubResource() { | 322 void AppCacheRequestHandler::ContinueMaybeLoadSubResource() { |
314 // 6.9.6 Changes to the networking model | 323 // 6.9.6 Changes to the networking model |
315 // If the resource is not to be fetched using the HTTP GET mechanism or | 324 // If the resource is not to be fetched using the HTTP GET mechanism or |
316 // equivalent ... then fetch the resource normally. | 325 // equivalent ... then fetch the resource normally. |
317 DCHECK(job_.get()); | 326 DCHECK(job_.get()); |
318 DCHECK(host_->associated_cache() && host_->associated_cache()->is_complete()); | 327 DCHECK(host_->associated_cache() && host_->associated_cache()->is_complete()); |
319 | 328 |
| 329 // Hackery for navcontroller semantics where the controller gets a crack |
| 330 // and any and all subresource requests <period>. |
| 331 if (host_->associated_cache()->owning_group()->IsFakeNavControllerGroup()) { |
| 332 // We assume there's one entry and its the controller script. |
| 333 AppCache* cache = host_->associated_cache(); |
| 334 found_cache_id_ = cache->cache_id(); |
| 335 found_group_id_ = cache->owning_group()->group_id(); |
| 336 found_manifest_url_ = cache->owning_group()->manifest_url(); |
| 337 found_entry_ = cache->entries().begin()->second; |
| 338 DCHECK(found_entry_.IsExecutable()); |
| 339 DeliverAppCachedResponse( |
| 340 found_entry_, found_cache_id_, found_group_id_, found_manifest_url_, |
| 341 false, GURL()); |
| 342 return; |
| 343 } |
| 344 |
320 const GURL& url = job_->request()->url(); | 345 const GURL& url = job_->request()->url(); |
321 AppCache* cache = host_->associated_cache(); | 346 AppCache* cache = host_->associated_cache(); |
322 storage()->FindResponseForSubRequest( | 347 storage()->FindResponseForSubRequest( |
323 host_->associated_cache(), url, | 348 host_->associated_cache(), url, |
324 &found_entry_, &found_fallback_entry_, &found_network_namespace_); | 349 &found_entry_, &found_fallback_entry_, &found_network_namespace_); |
325 | 350 |
326 if (found_entry_.has_response_id()) { | 351 if (found_entry_.has_response_id()) { |
327 // Step 2: If there's an entry, get it instead. | 352 // Step 2: If there's an entry, get it instead. |
328 DCHECK(!found_network_namespace_ && | 353 DCHECK(!found_network_namespace_ && |
329 !found_fallback_entry_.has_response_id()); | 354 !found_fallback_entry_.has_response_id()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 if (!host_->associated_cache() || | 396 if (!host_->associated_cache() || |
372 !host_->associated_cache()->is_complete()) { | 397 !host_->associated_cache()->is_complete()) { |
373 DeliverNetworkResponse(); | 398 DeliverNetworkResponse(); |
374 return; | 399 return; |
375 } | 400 } |
376 | 401 |
377 ContinueMaybeLoadSubResource(); | 402 ContinueMaybeLoadSubResource(); |
378 } | 403 } |
379 | 404 |
380 } // namespace appcache | 405 } // namespace appcache |
OLD | NEW |