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 23 matching lines...) Expand all Loading... |
34 | 34 |
35 void AppCacheRequestHandler::GetExtraResponseInfo( | 35 void AppCacheRequestHandler::GetExtraResponseInfo( |
36 int64* cache_id, GURL* manifest_url) { | 36 int64* cache_id, GURL* manifest_url) { |
37 if (job_ && job_->is_delivering_appcache_response()) { | 37 if (job_ && job_->is_delivering_appcache_response()) { |
38 *cache_id = job_->cache_id(); | 38 *cache_id = job_->cache_id(); |
39 *manifest_url = job_->manifest_url(); | 39 *manifest_url = job_->manifest_url(); |
40 } | 40 } |
41 } | 41 } |
42 | 42 |
43 AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadResource( | 43 AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadResource( |
44 URLRequest* request) { | 44 net::URLRequest* request) { |
45 if (!host_ || !IsSchemeAndMethodSupported(request) || cache_entry_not_found_) | 45 if (!host_ || !IsSchemeAndMethodSupported(request) || cache_entry_not_found_) |
46 return NULL; | 46 return NULL; |
47 | 47 |
48 // This method can get called multiple times over the life | 48 // This method can get called multiple times over the life |
49 // of a request. The case we detect here is having scheduled | 49 // of a request. The case we detect here is having scheduled |
50 // delivery of a "network response" using a job setup on an | 50 // delivery of a "network response" using a job setup on an |
51 // earlier call thru this method. To send the request thru | 51 // earlier call thru this method. To send the request thru |
52 // to the network involves restarting the request altogether, | 52 // to the network involves restarting the request altogether, |
53 // which will call thru to our interception layer again. | 53 // which will call thru to our interception layer again. |
54 // This time thru, we return NULL so the request hits the wire. | 54 // This time thru, we return NULL so the request hits the wire. |
(...skipping 24 matching lines...) Expand all Loading... |
79 // have been started yet. | 79 // have been started yet. |
80 if (job_ && job_->is_delivering_network_response()) { | 80 if (job_ && job_->is_delivering_network_response()) { |
81 DCHECK(!job_->has_been_started()); | 81 DCHECK(!job_->has_been_started()); |
82 job_ = NULL; | 82 job_ = NULL; |
83 } | 83 } |
84 | 84 |
85 return job_; | 85 return job_; |
86 } | 86 } |
87 | 87 |
88 AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadFallbackForRedirect( | 88 AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadFallbackForRedirect( |
89 URLRequest* request, const GURL& location) { | 89 net::URLRequest* request, const GURL& location) { |
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, |
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_, | 104 found_fallback_entry_, found_cache_id_, found_manifest_url_, |
105 true, found_fallback_url_); | 105 true, found_fallback_url_); |
106 } else if (!found_network_namespace_) { | 106 } else if (!found_network_namespace_) { |
107 // 6.9.6, step 6: Fail the resource load. | 107 // 6.9.6, step 6: Fail the resource load. |
108 job_ = new AppCacheURLRequestJob(request, storage()); | 108 job_ = new AppCacheURLRequestJob(request, storage()); |
109 DeliverErrorResponse(); | 109 DeliverErrorResponse(); |
110 } else { | 110 } else { |
111 // 6.9.6 step 3 and 5: Fetch the resource normally. | 111 // 6.9.6 step 3 and 5: Fetch the resource normally. |
112 } | 112 } |
113 | 113 |
114 return job_; | 114 return job_; |
115 } | 115 } |
116 | 116 |
117 AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadFallbackForResponse( | 117 AppCacheURLRequestJob* AppCacheRequestHandler::MaybeLoadFallbackForResponse( |
118 URLRequest* request) { | 118 net::URLRequest* request) { |
119 if (!host_ || !IsSchemeAndMethodSupported(request) || cache_entry_not_found_) | 119 if (!host_ || !IsSchemeAndMethodSupported(request) || cache_entry_not_found_) |
120 return NULL; | 120 return NULL; |
121 if (!found_fallback_entry_.has_response_id()) | 121 if (!found_fallback_entry_.has_response_id()) |
122 return NULL; | 122 return NULL; |
123 | 123 |
124 if (request->status().status() == URLRequestStatus::CANCELED || | 124 if (request->status().status() == URLRequestStatus::CANCELED || |
125 request->status().status() == URLRequestStatus::HANDLED_EXTERNALLY) { | 125 request->status().status() == URLRequestStatus::HANDLED_EXTERNALLY) { |
126 // 6.9.6, step 4: But not if the user canceled the download. | 126 // 6.9.6, step 4: But not if the user canceled the download. |
127 return NULL; | 127 return NULL; |
128 } | 128 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 job_->DeliverErrorResponse(); | 179 job_->DeliverErrorResponse(); |
180 } | 180 } |
181 | 181 |
182 void AppCacheRequestHandler::DeliverNetworkResponse() { | 182 void AppCacheRequestHandler::DeliverNetworkResponse() { |
183 DCHECK(job_ && job_->is_waiting()); | 183 DCHECK(job_ && job_->is_waiting()); |
184 job_->DeliverNetworkResponse(); | 184 job_->DeliverNetworkResponse(); |
185 } | 185 } |
186 | 186 |
187 // Main-resource handling ---------------------------------------------- | 187 // Main-resource handling ---------------------------------------------- |
188 | 188 |
189 void AppCacheRequestHandler::MaybeLoadMainResource(URLRequest* request) { | 189 void AppCacheRequestHandler::MaybeLoadMainResource(net::URLRequest* request) { |
190 DCHECK(!job_); | 190 DCHECK(!job_); |
191 | 191 |
192 // 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 |
193 // this query can also complete syncrhonously. | 193 // this query can also complete syncrhonously. |
194 job_ = new AppCacheURLRequestJob(request, storage()); | 194 job_ = new AppCacheURLRequestJob(request, storage()); |
195 storage()->FindResponseForMainRequest(request->url(), this); | 195 storage()->FindResponseForMainRequest(request->url(), this); |
196 } | 196 } |
197 | 197 |
198 void AppCacheRequestHandler::OnMainResponseFound( | 198 void AppCacheRequestHandler::OnMainResponseFound( |
199 const GURL& url, const AppCacheEntry& entry, | 199 const GURL& url, const AppCacheEntry& entry, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 found_entry_, found_cache_id_, found_manifest_url_, | 237 found_entry_, found_cache_id_, found_manifest_url_, |
238 false, GURL()); | 238 false, GURL()); |
239 } else { | 239 } else { |
240 DeliverNetworkResponse(); | 240 DeliverNetworkResponse(); |
241 } | 241 } |
242 } | 242 } |
243 | 243 |
244 // Sub-resource handling ---------------------------------------------- | 244 // Sub-resource handling ---------------------------------------------- |
245 | 245 |
246 void AppCacheRequestHandler::MaybeLoadSubResource( | 246 void AppCacheRequestHandler::MaybeLoadSubResource( |
247 URLRequest* request) { | 247 net::URLRequest* request) { |
248 DCHECK(!job_); | 248 DCHECK(!job_); |
249 | 249 |
250 if (host_->is_selection_pending()) { | 250 if (host_->is_selection_pending()) { |
251 // We have to wait until cache selection is complete and the | 251 // We have to wait until cache selection is complete and the |
252 // selected cache is loaded. | 252 // selected cache is loaded. |
253 is_waiting_for_cache_selection_ = true; | 253 is_waiting_for_cache_selection_ = true; |
254 job_ = new AppCacheURLRequestJob(request, storage()); | 254 job_ = new AppCacheURLRequestJob(request, storage()); |
255 return; | 255 return; |
256 } | 256 } |
257 | 257 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 if (!host_->associated_cache() || | 325 if (!host_->associated_cache() || |
326 !host_->associated_cache()->is_complete()) { | 326 !host_->associated_cache()->is_complete()) { |
327 DeliverNetworkResponse(); | 327 DeliverNetworkResponse(); |
328 return; | 328 return; |
329 } | 329 } |
330 | 330 |
331 ContinueMaybeLoadSubResource(); | 331 ContinueMaybeLoadSubResource(); |
332 } | 332 } |
333 | 333 |
334 } // namespace appcache | 334 } // namespace appcache |
OLD | NEW |