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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 // We may have to wait for our storage query to complete, but | 211 // We may have to wait for our storage query to complete, but |
211 // this query can also complete syncrhonously. | 212 // this query can also complete syncrhonously. |
212 job_ = new AppCacheURLRequestJob(request, storage()); | 213 job_ = new AppCacheURLRequestJob(request, storage()); |
213 storage()->FindResponseForMainRequest( | 214 storage()->FindResponseForMainRequest( |
214 request->url(), preferred_manifest_url, this); | 215 request->url(), preferred_manifest_url, this); |
215 } | 216 } |
216 | 217 |
217 void AppCacheRequestHandler::OnMainResponseFound( | 218 void AppCacheRequestHandler::OnMainResponseFound( |
218 const GURL& url, const AppCacheEntry& entry, | 219 const GURL& url, const AppCacheEntry& entry, |
219 const GURL& fallback_url, const AppCacheEntry& fallback_entry, | 220 const GURL& fallback_url, const AppCacheEntry& fallback_entry, |
220 int64 cache_id, const GURL& manifest_url, | 221 int64 cache_id, const GURL& manifest_url) { |
221 bool was_blocked_by_policy) { | |
222 DCHECK(job_); | 222 DCHECK(job_); |
223 DCHECK(host_); | 223 DCHECK(host_); |
224 DCHECK(is_main_resource()); | 224 DCHECK(is_main_resource()); |
225 DCHECK(!entry.IsForeign()); | 225 DCHECK(!entry.IsForeign()); |
226 DCHECK(!fallback_entry.IsForeign()); | 226 DCHECK(!fallback_entry.IsForeign()); |
227 DCHECK(!(entry.has_response_id() && fallback_entry.has_response_id())); | 227 DCHECK(!(entry.has_response_id() && fallback_entry.has_response_id())); |
228 | 228 |
229 if (!job_) | 229 if (!job_) |
230 return; | 230 return; |
231 | 231 |
232 if (ResourceType::IsFrame(resource_type_)) { | 232 AppCachePolicy* policy = host_->service()->appcache_policy(); |
233 if (was_blocked_by_policy) | 233 bool was_blocked_by_policy = !manifest_url.is_empty() && policy && |
| 234 !policy->CanLoadAppCache(manifest_url, host_->first_party_url()); |
| 235 |
| 236 if (was_blocked_by_policy) { |
| 237 if (ResourceType::IsFrame(resource_type_)) { |
234 host_->NotifyMainResourceBlocked(manifest_url); | 238 host_->NotifyMainResourceBlocked(manifest_url); |
| 239 } else { |
| 240 DCHECK(ResourceType::IsSharedWorker(resource_type_)); |
| 241 host_->frontend()->OnContentBlocked(host_->host_id(), manifest_url); |
| 242 } |
| 243 DeliverNetworkResponse(); |
| 244 return; |
| 245 } |
235 | 246 |
236 if (cache_id != kNoCacheId) { | 247 if (ResourceType::IsFrame(resource_type_) && cache_id != kNoCacheId) { |
237 // AppCacheHost loads and holds a reference to the main resource cache | 248 // AppCacheHost loads and holds a reference to the main resource cache |
238 // for two reasons, firstly to preload the cache into the working set | 249 // for two reasons, firstly to preload the cache into the working set |
239 // in advance of subresource loads happening, secondly to prevent the | 250 // in advance of subresource loads happening, secondly to prevent the |
240 // AppCache from falling out of the working set on frame navigations. | 251 // AppCache from falling out of the working set on frame navigations. |
241 host_->LoadMainResourceCache(cache_id); | 252 host_->LoadMainResourceCache(cache_id); |
242 host_->set_preferred_manifest_url(manifest_url); | 253 host_->set_preferred_manifest_url(manifest_url); |
243 } | |
244 } else { | |
245 DCHECK(ResourceType::IsSharedWorker(resource_type_)); | |
246 if (was_blocked_by_policy) | |
247 host_->frontend()->OnContentBlocked(host_->host_id(), manifest_url); | |
248 } | 254 } |
249 | 255 |
250 // 6.11.1 Navigating across documents, steps 10 and 14. | 256 // 6.11.1 Navigating across documents, steps 10 and 14. |
251 | 257 |
252 found_entry_ = entry; | 258 found_entry_ = entry; |
253 found_fallback_url_ = fallback_url; | 259 found_fallback_url_ = fallback_url; |
254 found_fallback_entry_ = fallback_entry; | 260 found_fallback_entry_ = fallback_entry; |
255 found_cache_id_ = cache_id; | 261 found_cache_id_ = cache_id; |
256 found_manifest_url_ = manifest_url; | 262 found_manifest_url_ = manifest_url; |
257 found_network_namespace_ = false; // not applicable to main requests | 263 found_network_namespace_ = false; // not applicable to main requests |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 if (!host_->associated_cache() || | 355 if (!host_->associated_cache() || |
350 !host_->associated_cache()->is_complete()) { | 356 !host_->associated_cache()->is_complete()) { |
351 DeliverNetworkResponse(); | 357 DeliverNetworkResponse(); |
352 return; | 358 return; |
353 } | 359 } |
354 | 360 |
355 ContinueMaybeLoadSubResource(); | 361 ContinueMaybeLoadSubResource(); |
356 } | 362 } |
357 | 363 |
358 } // namespace appcache | 364 } // namespace appcache |
OLD | NEW |