| 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 "content/browser/appcache/appcache_request_handler.h" |
| 6 | 6 |
| 7 #include "content/browser/appcache/appcache.h" |
| 8 #include "content/browser/appcache/appcache_backend_impl.h" |
| 9 #include "content/browser/appcache/appcache_policy.h" |
| 10 #include "content/browser/appcache/appcache_url_request_job.h" |
| 7 #include "net/url_request/url_request.h" | 11 #include "net/url_request/url_request.h" |
| 8 #include "net/url_request/url_request_job.h" | 12 #include "net/url_request/url_request_job.h" |
| 9 #include "webkit/browser/appcache/appcache.h" | |
| 10 #include "webkit/browser/appcache/appcache_backend_impl.h" | |
| 11 #include "webkit/browser/appcache/appcache_policy.h" | |
| 12 #include "webkit/browser/appcache/appcache_url_request_job.h" | |
| 13 | 13 |
| 14 namespace appcache { | 14 namespace content { |
| 15 | 15 |
| 16 AppCacheRequestHandler::AppCacheRequestHandler( | 16 AppCacheRequestHandler::AppCacheRequestHandler( |
| 17 AppCacheHost* host, ResourceType::Type resource_type) | 17 AppCacheHost* host, ResourceType::Type resource_type) |
| 18 : host_(host), resource_type_(resource_type), | 18 : host_(host), resource_type_(resource_type), |
| 19 is_waiting_for_cache_selection_(false), found_group_id_(0), | 19 is_waiting_for_cache_selection_(false), found_group_id_(0), |
| 20 found_cache_id_(0), found_network_namespace_(false), | 20 found_cache_id_(0), found_network_namespace_(false), |
| 21 cache_entry_not_found_(false), maybe_load_resource_executed_(false) { | 21 cache_entry_not_found_(false), maybe_load_resource_executed_(false) { |
| 22 DCHECK(host_); | 22 DCHECK(host_); |
| 23 host_->AddObserver(this); | 23 host_->AddObserver(this); |
| 24 } | 24 } |
| 25 | 25 |
| 26 AppCacheRequestHandler::~AppCacheRequestHandler() { | 26 AppCacheRequestHandler::~AppCacheRequestHandler() { |
| 27 if (host_) { | 27 if (host_) { |
| 28 storage()->CancelDelegateCallbacks(this); | 28 storage()->CancelDelegateCallbacks(this); |
| 29 host_->RemoveObserver(this); | 29 host_->RemoveObserver(this); |
| 30 } | 30 } |
| 31 } | 31 } |
| 32 | 32 |
| 33 AppCacheStorage* AppCacheRequestHandler::storage() const { | 33 AppCacheStorage* AppCacheRequestHandler::storage() const { |
| 34 DCHECK(host_); | 34 DCHECK(host_); |
| 35 return host_->storage(); | 35 return host_->storage(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadResource( | 38 AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadResource( |
| 39 net::URLRequest* request, net::NetworkDelegate* network_delegate) { | 39 net::URLRequest* request, net::NetworkDelegate* network_delegate) { |
| 40 maybe_load_resource_executed_ = true; | 40 maybe_load_resource_executed_ = true; |
| 41 if (!host_ || !IsSchemeAndMethodSupported(request) || cache_entry_not_found_) | 41 if (!host_ || !IsSchemeAndMethodSupportedForAppCache(request) || |
| 42 cache_entry_not_found_) |
| 42 return NULL; | 43 return NULL; |
| 43 | 44 |
| 44 // This method can get called multiple times over the life | 45 // This method can get called multiple times over the life |
| 45 // of a request. The case we detect here is having scheduled | 46 // of a request. The case we detect here is having scheduled |
| 46 // delivery of a "network response" using a job setup on an | 47 // delivery of a "network response" using a job setup on an |
| 47 // earlier call thru this method. To send the request thru | 48 // earlier call thru this method. To send the request thru |
| 48 // to the network involves restarting the request altogether, | 49 // to the network involves restarting the request altogether, |
| 49 // which will call thru to our interception layer again. | 50 // which will call thru to our interception layer again. |
| 50 // This time thru, we return NULL so the request hits the wire. | 51 // This time thru, we return NULL so the request hits the wire. |
| 51 if (job_.get()) { | 52 if (job_.get()) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 79 job_ = NULL; | 80 job_ = NULL; |
| 80 } | 81 } |
| 81 | 82 |
| 82 return job_.get(); | 83 return job_.get(); |
| 83 } | 84 } |
| 84 | 85 |
| 85 AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadFallbackForRedirect( | 86 AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadFallbackForRedirect( |
| 86 net::URLRequest* request, | 87 net::URLRequest* request, |
| 87 net::NetworkDelegate* network_delegate, | 88 net::NetworkDelegate* network_delegate, |
| 88 const GURL& location) { | 89 const GURL& location) { |
| 89 if (!host_ || !IsSchemeAndMethodSupported(request) || cache_entry_not_found_) | 90 if (!host_ || !IsSchemeAndMethodSupportedForAppCache(request) || |
| 91 cache_entry_not_found_) |
| 90 return NULL; | 92 return NULL; |
| 91 if (is_main_resource()) | 93 if (is_main_resource()) |
| 92 return NULL; | 94 return NULL; |
| 93 // TODO(vabr) This is a temporary fix (see crbug/141114). We should get rid of | 95 // TODO(vabr) This is a temporary fix (see crbug/141114). We should get rid of |
| 94 // it once a more general solution to crbug/121325 is in place. | 96 // it once a more general solution to crbug/121325 is in place. |
| 95 if (!maybe_load_resource_executed_) | 97 if (!maybe_load_resource_executed_) |
| 96 return NULL; | 98 return NULL; |
| 97 if (request->url().GetOrigin() == location.GetOrigin()) | 99 if (request->url().GetOrigin() == location.GetOrigin()) |
| 98 return NULL; | 100 return NULL; |
| 99 | 101 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 114 DeliverErrorResponse(); | 116 DeliverErrorResponse(); |
| 115 } else { | 117 } else { |
| 116 // 6.9.6 step 3 and 5: Fetch the resource normally. | 118 // 6.9.6 step 3 and 5: Fetch the resource normally. |
| 117 } | 119 } |
| 118 | 120 |
| 119 return job_.get(); | 121 return job_.get(); |
| 120 } | 122 } |
| 121 | 123 |
| 122 AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadFallbackForResponse( | 124 AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadFallbackForResponse( |
| 123 net::URLRequest* request, net::NetworkDelegate* network_delegate) { | 125 net::URLRequest* request, net::NetworkDelegate* network_delegate) { |
| 124 if (!host_ || !IsSchemeAndMethodSupported(request) || cache_entry_not_found_) | 126 if (!host_ || !IsSchemeAndMethodSupportedForAppCache(request) || |
| 127 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; |
| 128 | 131 |
| 129 if (request->status().status() == net::URLRequestStatus::CANCELED) { | 132 if (request->status().status() == net::URLRequestStatus::CANCELED) { |
| 130 // 6.9.6, step 4: But not if the user canceled the download. | 133 // 6.9.6, step 4: But not if the user canceled the download. |
| 131 return NULL; | 134 return NULL; |
| 132 } | 135 } |
| 133 | 136 |
| 134 // We don't fallback for responses that we delivered. | 137 // We don't fallback for responses that we delivered. |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 | 392 |
| 390 if (!host_->associated_cache() || | 393 if (!host_->associated_cache() || |
| 391 !host_->associated_cache()->is_complete()) { | 394 !host_->associated_cache()->is_complete()) { |
| 392 DeliverNetworkResponse(); | 395 DeliverNetworkResponse(); |
| 393 return; | 396 return; |
| 394 } | 397 } |
| 395 | 398 |
| 396 ContinueMaybeLoadSubResource(); | 399 ContinueMaybeLoadSubResource(); |
| 397 } | 400 } |
| 398 | 401 |
| 399 } // namespace appcache | 402 } // namespace content |
| OLD | NEW |