Chromium Code Reviews| 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/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_policy.h" | |
| 10 #include "webkit/appcache/appcache_url_request_job.h" | 11 #include "webkit/appcache/appcache_url_request_job.h" |
| 11 | 12 |
| 12 namespace appcache { | 13 namespace appcache { |
| 13 | 14 |
| 14 AppCacheRequestHandler::AppCacheRequestHandler(AppCacheHost* host, | 15 AppCacheRequestHandler::AppCacheRequestHandler(AppCacheHost* host, |
| 15 ResourceType::Type resource_type) | 16 ResourceType::Type resource_type) |
| 16 : host_(host), resource_type_(resource_type), | 17 : host_(host), resource_type_(resource_type), |
| 17 is_waiting_for_cache_selection_(false), found_cache_id_(0), | 18 is_waiting_for_cache_selection_(false), found_cache_id_(0), |
| 18 found_network_namespace_(false), cache_entry_not_found_(false) { | 19 found_network_namespace_(false), cache_entry_not_found_(false) { |
| 19 DCHECK(host_); | 20 DCHECK(host_); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 // We may have to wait for our storage query to complete, but | 210 // We may have to wait for our storage query to complete, but |
| 210 // this query can also complete syncrhonously. | 211 // this query can also complete syncrhonously. |
| 211 job_ = new AppCacheURLRequestJob(request, storage()); | 212 job_ = new AppCacheURLRequestJob(request, storage()); |
| 212 storage()->FindResponseForMainRequest( | 213 storage()->FindResponseForMainRequest( |
| 213 request->url(), preferred_manifest_url, this); | 214 request->url(), preferred_manifest_url, this); |
| 214 } | 215 } |
| 215 | 216 |
| 216 void AppCacheRequestHandler::OnMainResponseFound( | 217 void AppCacheRequestHandler::OnMainResponseFound( |
| 217 const GURL& url, const AppCacheEntry& entry, | 218 const GURL& url, const AppCacheEntry& entry, |
| 218 const GURL& fallback_url, const AppCacheEntry& fallback_entry, | 219 const GURL& fallback_url, const AppCacheEntry& fallback_entry, |
| 219 int64 cache_id, const GURL& manifest_url, | 220 int64 cache_id, const GURL& manifest_url) { |
| 220 bool was_blocked_by_policy) { | |
| 221 DCHECK(host_); | 221 DCHECK(host_); |
| 222 DCHECK(is_main_resource()); | 222 DCHECK(is_main_resource()); |
| 223 DCHECK(!entry.IsForeign()); | 223 DCHECK(!entry.IsForeign()); |
| 224 DCHECK(!fallback_entry.IsForeign()); | 224 DCHECK(!fallback_entry.IsForeign()); |
| 225 DCHECK(!(entry.has_response_id() && fallback_entry.has_response_id())); | 225 DCHECK(!(entry.has_response_id() && fallback_entry.has_response_id())); |
| 226 | 226 |
| 227 AppCachePolicy* policy = host_->service()->appcache_policy(); | |
| 228 bool was_blocked_by_policy = !manifest_url.is_empty() && policy && | |
| 229 !policy->CanLoadAppCache(manifest_url, host_->first_party_url()); | |
| 230 | |
|
michaeln
2011/09/05 19:49:31
it may be more readable to hoist all of this was_b
marja
2011/09/06 09:09:28
Done.
| |
| 227 if (ResourceType::IsFrame(resource_type_)) { | 231 if (ResourceType::IsFrame(resource_type_)) { |
| 228 if (was_blocked_by_policy) | 232 if (was_blocked_by_policy) |
|
michaeln
2011/09/05 19:49:31
style: since the else clause needs {'s, this if cl
marja
2011/09/06 09:09:28
Gone.
| |
| 229 host_->NotifyMainResourceBlocked(manifest_url); | 233 host_->NotifyMainResourceBlocked(manifest_url); |
| 230 | 234 else if (cache_id != kNoCacheId) { |
| 231 if (cache_id != kNoCacheId) { | |
| 232 // AppCacheHost loads and holds a reference to the main resource cache | 235 // AppCacheHost loads and holds a reference to the main resource cache |
| 233 // for two reasons, firstly to preload the cache into the working set | 236 // for two reasons, firstly to preload the cache into the working set |
| 234 // in advance of subresource loads happening, secondly to prevent the | 237 // in advance of subresource loads happening, secondly to prevent the |
| 235 // AppCache from falling out of the working set on frame navigations. | 238 // AppCache from falling out of the working set on frame navigations. |
| 236 host_->LoadMainResourceCache(cache_id); | 239 host_->LoadMainResourceCache(cache_id); |
| 237 host_->set_preferred_manifest_url(manifest_url); | 240 host_->set_preferred_manifest_url(manifest_url); |
| 238 } | 241 } |
| 239 } else { | 242 } else { |
| 240 DCHECK(ResourceType::IsSharedWorker(resource_type_)); | 243 DCHECK(ResourceType::IsSharedWorker(resource_type_)); |
| 241 if (was_blocked_by_policy) | 244 if (was_blocked_by_policy) |
| 242 host_->frontend()->OnContentBlocked(host_->host_id(), manifest_url); | 245 host_->frontend()->OnContentBlocked(host_->host_id(), manifest_url); |
| 243 } | 246 } |
| 244 | 247 |
| 248 if (was_blocked_by_policy) { | |
| 249 DeliverNetworkResponse(); | |
| 250 return; | |
| 251 } | |
| 252 | |
| 245 // 6.11.1 Navigating across documents, steps 10 and 14. | 253 // 6.11.1 Navigating across documents, steps 10 and 14. |
| 246 | 254 |
| 247 found_entry_ = entry; | 255 found_entry_ = entry; |
| 248 found_fallback_url_ = fallback_url; | 256 found_fallback_url_ = fallback_url; |
| 249 found_fallback_entry_ = fallback_entry; | 257 found_fallback_entry_ = fallback_entry; |
| 250 found_cache_id_ = cache_id; | 258 found_cache_id_ = cache_id; |
| 251 found_manifest_url_ = manifest_url; | 259 found_manifest_url_ = manifest_url; |
| 252 found_network_namespace_ = false; // not applicable to main requests | 260 found_network_namespace_ = false; // not applicable to main requests |
| 253 | 261 |
| 254 if (found_entry_.has_response_id()) { | 262 if (found_entry_.has_response_id()) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 if (!host_->associated_cache() || | 352 if (!host_->associated_cache() || |
| 345 !host_->associated_cache()->is_complete()) { | 353 !host_->associated_cache()->is_complete()) { |
| 346 DeliverNetworkResponse(); | 354 DeliverNetworkResponse(); |
| 347 return; | 355 return; |
| 348 } | 356 } |
| 349 | 357 |
| 350 ContinueMaybeLoadSubResource(); | 358 ContinueMaybeLoadSubResource(); |
| 351 } | 359 } |
| 352 | 360 |
| 353 } // namespace appcache | 361 } // namespace appcache |
| OLD | NEW |