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 "content/browser/appcache/appcache_request_handler.h" | 5 #include "content/browser/appcache/appcache_request_handler.h" |
6 | 6 |
7 #include "content/browser/appcache/appcache.h" | 7 #include "content/browser/appcache/appcache.h" |
8 #include "content/browser/appcache/appcache_backend_impl.h" | 8 #include "content/browser/appcache/appcache_backend_impl.h" |
9 #include "content/browser/appcache/appcache_policy.h" | 9 #include "content/browser/appcache/appcache_policy.h" |
10 #include "content/browser/appcache/appcache_url_request_job.h" | 10 #include "content/browser/appcache/appcache_url_request_job.h" |
11 #include "net/url_request/url_request.h" | 11 #include "net/url_request/url_request.h" |
12 #include "net/url_request/url_request_job.h" | 12 #include "net/url_request/url_request_job.h" |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 | 15 |
16 AppCacheRequestHandler::AppCacheRequestHandler( | 16 AppCacheRequestHandler::AppCacheRequestHandler(AppCacheHost* host, |
17 AppCacheHost* host, ResourceType::Type resource_type) | 17 ResourceType resource_type) |
18 : host_(host), resource_type_(resource_type), | 18 : host_(host), |
19 is_waiting_for_cache_selection_(false), found_group_id_(0), | 19 resource_type_(resource_type), |
20 found_cache_id_(0), found_network_namespace_(false), | 20 is_waiting_for_cache_selection_(false), |
21 cache_entry_not_found_(false), maybe_load_resource_executed_(false) { | 21 found_group_id_(0), |
| 22 found_cache_id_(0), |
| 23 found_network_namespace_(false), |
| 24 cache_entry_not_found_(false), |
| 25 maybe_load_resource_executed_(false) { |
22 DCHECK(host_); | 26 DCHECK(host_); |
23 host_->AddObserver(this); | 27 host_->AddObserver(this); |
24 } | 28 } |
25 | 29 |
26 AppCacheRequestHandler::~AppCacheRequestHandler() { | 30 AppCacheRequestHandler::~AppCacheRequestHandler() { |
27 if (host_) { | 31 if (host_) { |
28 storage()->CancelDelegateCallbacks(this); | 32 storage()->CancelDelegateCallbacks(this); |
29 host_->RemoveObserver(this); | 33 host_->RemoveObserver(this); |
30 } | 34 } |
31 } | 35 } |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 } | 207 } |
204 } | 208 } |
205 | 209 |
206 void AppCacheRequestHandler::DeliverAppCachedResponse( | 210 void AppCacheRequestHandler::DeliverAppCachedResponse( |
207 const AppCacheEntry& entry, int64 cache_id, int64 group_id, | 211 const AppCacheEntry& entry, int64 cache_id, int64 group_id, |
208 const GURL& manifest_url, bool is_fallback, | 212 const GURL& manifest_url, bool is_fallback, |
209 const GURL& namespace_entry_url) { | 213 const GURL& namespace_entry_url) { |
210 DCHECK(host_ && job_.get() && job_->is_waiting()); | 214 DCHECK(host_ && job_.get() && job_->is_waiting()); |
211 DCHECK(entry.has_response_id()); | 215 DCHECK(entry.has_response_id()); |
212 | 216 |
213 if (ResourceType::IsFrame(resource_type_) && !namespace_entry_url.is_empty()) | 217 if (IsResourceTypeFrame(resource_type_) && !namespace_entry_url.is_empty()) |
214 host_->NotifyMainResourceIsNamespaceEntry(namespace_entry_url); | 218 host_->NotifyMainResourceIsNamespaceEntry(namespace_entry_url); |
215 | 219 |
216 job_->DeliverAppCachedResponse(manifest_url, group_id, cache_id, | 220 job_->DeliverAppCachedResponse(manifest_url, group_id, cache_id, |
217 entry, is_fallback); | 221 entry, is_fallback); |
218 } | 222 } |
219 | 223 |
220 void AppCacheRequestHandler::DeliverErrorResponse() { | 224 void AppCacheRequestHandler::DeliverErrorResponse() { |
221 DCHECK(job_.get() && job_->is_waiting()); | 225 DCHECK(job_.get() && job_->is_waiting()); |
222 job_->DeliverErrorResponse(); | 226 job_->DeliverErrorResponse(); |
223 } | 227 } |
224 | 228 |
225 void AppCacheRequestHandler::DeliverNetworkResponse() { | 229 void AppCacheRequestHandler::DeliverNetworkResponse() { |
226 DCHECK(job_.get() && job_->is_waiting()); | 230 DCHECK(job_.get() && job_->is_waiting()); |
227 job_->DeliverNetworkResponse(); | 231 job_->DeliverNetworkResponse(); |
228 } | 232 } |
229 | 233 |
230 // Main-resource handling ---------------------------------------------- | 234 // Main-resource handling ---------------------------------------------- |
231 | 235 |
232 void AppCacheRequestHandler::MaybeLoadMainResource( | 236 void AppCacheRequestHandler::MaybeLoadMainResource( |
233 net::URLRequest* request, net::NetworkDelegate* network_delegate) { | 237 net::URLRequest* request, net::NetworkDelegate* network_delegate) { |
234 DCHECK(!job_.get()); | 238 DCHECK(!job_.get()); |
235 DCHECK(host_); | 239 DCHECK(host_); |
236 | 240 |
237 const AppCacheHost* spawning_host = | 241 const AppCacheHost* spawning_host = |
238 ResourceType::IsSharedWorker(resource_type_) ? | 242 (resource_type_ == RESOURCE_TYPE_SHARED_WORKER) ? |
239 host_ : host_->GetSpawningHost(); | 243 host_ : host_->GetSpawningHost(); |
240 GURL preferred_manifest_url = spawning_host ? | 244 GURL preferred_manifest_url = spawning_host ? |
241 spawning_host->preferred_manifest_url() : GURL(); | 245 spawning_host->preferred_manifest_url() : GURL(); |
242 | 246 |
243 // We may have to wait for our storage query to complete, but | 247 // We may have to wait for our storage query to complete, but |
244 // this query can also complete syncrhonously. | 248 // this query can also complete syncrhonously. |
245 job_ = new AppCacheURLRequestJob(request, network_delegate, | 249 job_ = new AppCacheURLRequestJob(request, network_delegate, |
246 storage(), host_, is_main_resource()); | 250 storage(), host_, is_main_resource()); |
247 storage()->FindResponseForMainRequest( | 251 storage()->FindResponseForMainRequest( |
248 request->url(), preferred_manifest_url, this); | 252 request->url(), preferred_manifest_url, this); |
249 } | 253 } |
(...skipping 10 matching lines...) Expand all Loading... |
260 DCHECK(!(entry.has_response_id() && fallback_entry.has_response_id())); | 264 DCHECK(!(entry.has_response_id() && fallback_entry.has_response_id())); |
261 | 265 |
262 if (!job_.get()) | 266 if (!job_.get()) |
263 return; | 267 return; |
264 | 268 |
265 AppCachePolicy* policy = host_->service()->appcache_policy(); | 269 AppCachePolicy* policy = host_->service()->appcache_policy(); |
266 bool was_blocked_by_policy = !manifest_url.is_empty() && policy && | 270 bool was_blocked_by_policy = !manifest_url.is_empty() && policy && |
267 !policy->CanLoadAppCache(manifest_url, host_->first_party_url()); | 271 !policy->CanLoadAppCache(manifest_url, host_->first_party_url()); |
268 | 272 |
269 if (was_blocked_by_policy) { | 273 if (was_blocked_by_policy) { |
270 if (ResourceType::IsFrame(resource_type_)) { | 274 if (IsResourceTypeFrame(resource_type_)) { |
271 host_->NotifyMainResourceBlocked(manifest_url); | 275 host_->NotifyMainResourceBlocked(manifest_url); |
272 } else { | 276 } else { |
273 DCHECK(ResourceType::IsSharedWorker(resource_type_)); | 277 DCHECK_EQ(resource_type_, RESOURCE_TYPE_SHARED_WORKER); |
274 host_->frontend()->OnContentBlocked(host_->host_id(), manifest_url); | 278 host_->frontend()->OnContentBlocked(host_->host_id(), manifest_url); |
275 } | 279 } |
276 DeliverNetworkResponse(); | 280 DeliverNetworkResponse(); |
277 return; | 281 return; |
278 } | 282 } |
279 | 283 |
280 if (ResourceType::IsFrame(resource_type_) && cache_id != kAppCacheNoCacheId) { | 284 if (IsResourceTypeFrame(resource_type_) && cache_id != kAppCacheNoCacheId) { |
281 // AppCacheHost loads and holds a reference to the main resource cache | 285 // AppCacheHost loads and holds a reference to the main resource cache |
282 // for two reasons, firstly to preload the cache into the working set | 286 // for two reasons, firstly to preload the cache into the working set |
283 // in advance of subresource loads happening, secondly to prevent the | 287 // in advance of subresource loads happening, secondly to prevent the |
284 // AppCache from falling out of the working set on frame navigations. | 288 // AppCache from falling out of the working set on frame navigations. |
285 host_->LoadMainResourceCache(cache_id); | 289 host_->LoadMainResourceCache(cache_id); |
286 host_->set_preferred_manifest_url(manifest_url); | 290 host_->set_preferred_manifest_url(manifest_url); |
287 } | 291 } |
288 | 292 |
289 // 6.11.1 Navigating across documents, steps 10 and 14. | 293 // 6.11.1 Navigating across documents, steps 10 and 14. |
290 | 294 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 if (!host_->associated_cache() || | 397 if (!host_->associated_cache() || |
394 !host_->associated_cache()->is_complete()) { | 398 !host_->associated_cache()->is_complete()) { |
395 DeliverNetworkResponse(); | 399 DeliverNetworkResponse(); |
396 return; | 400 return; |
397 } | 401 } |
398 | 402 |
399 ContinueMaybeLoadSubResource(); | 403 ContinueMaybeLoadSubResource(); |
400 } | 404 } |
401 | 405 |
402 } // namespace content | 406 } // namespace content |
OLD | NEW |