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_host.h" | 5 #include "webkit/appcache/appcache_host.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "webkit/appcache/appcache.h" | 10 #include "webkit/appcache/appcache.h" |
11 #include "webkit/appcache/appcache_backend_impl.h" | 11 #include "webkit/appcache/appcache_backend_impl.h" |
12 #include "webkit/appcache/appcache_policy.h" | |
12 #include "webkit/appcache/appcache_request_handler.h" | 13 #include "webkit/appcache/appcache_request_handler.h" |
13 #include "webkit/quota/quota_manager.h" | 14 #include "webkit/quota/quota_manager.h" |
14 | 15 |
15 namespace appcache { | 16 namespace appcache { |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 void FillCacheInfo( | 20 void FillCacheInfo( |
20 const AppCache* cache, Status status, AppCacheInfo* info) { | 21 const AppCache* cache, Status status, AppCacheInfo* info) { |
21 DCHECK(cache); | 22 DCHECK(cache); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 // MarkAsForeignEntry is called in that case, so that detection | 89 // MarkAsForeignEntry is called in that case, so that detection |
89 // step is skipped here. See WebApplicationCacheHostImpl.cc | 90 // step is skipped here. See WebApplicationCacheHostImpl.cc |
90 | 91 |
91 if (cache_document_was_loaded_from != kNoCacheId) { | 92 if (cache_document_was_loaded_from != kNoCacheId) { |
92 LoadSelectedCache(cache_document_was_loaded_from); | 93 LoadSelectedCache(cache_document_was_loaded_from); |
93 return; | 94 return; |
94 } | 95 } |
95 | 96 |
96 if (!manifest_url.is_empty() && | 97 if (!manifest_url.is_empty() && |
97 (manifest_url.GetOrigin() == document_url.GetOrigin())) { | 98 (manifest_url.GetOrigin() == document_url.GetOrigin())) { |
99 DCHECK(!first_party_url_.is_empty()); | |
100 AppCachePolicy* policy = service()->appcache_policy(); | |
101 if (policy && | |
102 !policy->CanCreateAppCache(manifest_url, first_party_url_)) { | |
103 FinishCacheSelection(NULL, NULL); | |
104 std::vector<int> host_ids; | |
105 host_ids.push_back(host_id_); | |
michaeln
2011/09/02 19:32:04
there's a ctor for this single element vector case
marja
2011/09/05 10:42:24
Done.
| |
106 frontend_->OnEventRaised(host_ids, CHECKING_EVENT); | |
107 frontend_->OnErrorEventRaised( | |
108 host_ids, "Cache creation was blocked by the content policy"); | |
109 frontend_->OnContentBlocked(host_id_, manifest_url); | |
110 return; | |
111 } | |
112 | |
98 // Note: The client detects if the document was not loaded using HTTP GET | 113 // Note: The client detects if the document was not loaded using HTTP GET |
99 // and invokes SelectCache without a manifest url, so that detection step | 114 // and invokes SelectCache without a manifest url, so that detection step |
100 // is also skipped here. See WebApplicationCacheHostImpl.cc | 115 // is also skipped here. See WebApplicationCacheHostImpl.cc |
101 set_preferred_manifest_url(manifest_url); | 116 set_preferred_manifest_url(manifest_url); |
102 new_master_entry_url_ = document_url; | 117 new_master_entry_url_ = document_url; |
103 LoadOrCreateGroup(manifest_url); | 118 LoadOrCreateGroup(manifest_url); |
104 return; | 119 return; |
105 } | 120 } |
106 | 121 |
107 // TODO(michaeln): If there was a manifest URL, the user agent may report | 122 // TODO(michaeln): If there was a manifest URL, the user agent may report |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 AppCacheRequestHandler* AppCacheHost::CreateRequestHandler( | 275 AppCacheRequestHandler* AppCacheHost::CreateRequestHandler( |
261 net::URLRequest* request, | 276 net::URLRequest* request, |
262 ResourceType::Type resource_type) { | 277 ResourceType::Type resource_type) { |
263 if (is_for_dedicated_worker()) { | 278 if (is_for_dedicated_worker()) { |
264 AppCacheHost* parent_host = GetParentAppCacheHost(); | 279 AppCacheHost* parent_host = GetParentAppCacheHost(); |
265 if (parent_host) | 280 if (parent_host) |
266 return parent_host->CreateRequestHandler(request, resource_type); | 281 return parent_host->CreateRequestHandler(request, resource_type); |
267 return NULL; | 282 return NULL; |
268 } | 283 } |
269 | 284 |
270 if (AppCacheRequestHandler::IsMainResourceType(resource_type)) | 285 if (AppCacheRequestHandler::IsMainResourceType(resource_type)) { |
286 // Store the first party origin so that it can be used later in SelectCache | |
287 // for checking whether the creation of the appcache is allowed. | |
288 first_party_url_ = request->first_party_for_cookies(); | |
271 return new AppCacheRequestHandler(this, resource_type); | 289 return new AppCacheRequestHandler(this, resource_type); |
290 } | |
272 | 291 |
273 if ((associated_cache() && associated_cache()->is_complete()) || | 292 if ((associated_cache() && associated_cache()->is_complete()) || |
274 is_selection_pending()) { | 293 is_selection_pending()) { |
275 return new AppCacheRequestHandler(this, resource_type); | 294 return new AppCacheRequestHandler(this, resource_type); |
276 } | 295 } |
277 return NULL; | 296 return NULL; |
278 } | 297 } |
279 | 298 |
280 void AppCacheHost::GetResourceList( | 299 void AppCacheHost::GetResourceList( |
281 AppCacheResourceInfoVector* resource_infos) { | 300 AppCacheResourceInfoVector* resource_infos) { |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
414 | 433 |
415 if (associated_cache_info_pending_ && associated_cache_.get() && | 434 if (associated_cache_info_pending_ && associated_cache_.get() && |
416 associated_cache_->is_complete()) { | 435 associated_cache_->is_complete()) { |
417 AppCacheInfo info; | 436 AppCacheInfo info; |
418 FillCacheInfo(associated_cache_.get(), GetStatus(), &info); | 437 FillCacheInfo(associated_cache_.get(), GetStatus(), &info); |
419 associated_cache_info_pending_ = false; | 438 associated_cache_info_pending_ = false; |
420 frontend_->OnCacheSelected(host_id_, info); | 439 frontend_->OnCacheSelected(host_id_, info); |
421 } | 440 } |
422 } | 441 } |
423 | 442 |
424 void AppCacheHost::OnContentBlocked(AppCacheGroup* group) { | |
425 frontend_->OnContentBlocked(host_id_, group->manifest_url()); | |
426 } | |
427 | |
428 void AppCacheHost::SetSwappableCache(AppCacheGroup* group) { | 443 void AppCacheHost::SetSwappableCache(AppCacheGroup* group) { |
429 if (!group) { | 444 if (!group) { |
430 swappable_cache_ = NULL; | 445 swappable_cache_ = NULL; |
431 } else { | 446 } else { |
432 AppCache* new_cache = group->newest_complete_cache(); | 447 AppCache* new_cache = group->newest_complete_cache(); |
433 if (new_cache != associated_cache_) | 448 if (new_cache != associated_cache_) |
434 swappable_cache_ = new_cache; | 449 swappable_cache_ = new_cache; |
435 else | 450 else |
436 swappable_cache_ = NULL; | 451 swappable_cache_ = NULL; |
437 } | 452 } |
(...skipping 29 matching lines...) Expand all Loading... | |
467 associated_cache_info_pending_ = cache && !cache->is_complete(); | 482 associated_cache_info_pending_ = cache && !cache->is_complete(); |
468 AppCacheInfo info; | 483 AppCacheInfo info; |
469 if (cache) { | 484 if (cache) { |
470 cache->AssociateHost(this); | 485 cache->AssociateHost(this); |
471 FillCacheInfo(cache, GetStatus(), &info); | 486 FillCacheInfo(cache, GetStatus(), &info); |
472 } | 487 } |
473 frontend_->OnCacheSelected(host_id_, info); | 488 frontend_->OnCacheSelected(host_id_, info); |
474 } | 489 } |
475 | 490 |
476 } // namespace appcache | 491 } // namespace appcache |
OLD | NEW |