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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 // Note: Foreign entries are detected on the client side and | 88 // Note: Foreign entries are detected on the client side and |
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())) { |
michaeln
2011/08/31 23:42:08
maybe DCHECK(!first_party_url_.empty());
marja
2011/09/02 13:40:24
Done. For this, I also needed to add a call to Cre
| |
99 AppCachePolicy* policy = service()->appcache_policy(); | |
100 if (policy && | |
101 !policy->CanCreateAppCache(manifest_url, first_party_url_)) { | |
michaeln
2011/08/31 23:42:08
We need to call FinishCacheSelection(NULL,NULL) in
marja
2011/09/02 13:40:24
Done.
| |
102 return; | |
103 } | |
104 | |
98 // Note: The client detects if the document was not loaded using HTTP GET | 105 // 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 | 106 // and invokes SelectCache without a manifest url, so that detection step |
100 // is also skipped here. See WebApplicationCacheHostImpl.cc | 107 // is also skipped here. See WebApplicationCacheHostImpl.cc |
101 set_preferred_manifest_url(manifest_url); | 108 set_preferred_manifest_url(manifest_url); |
102 new_master_entry_url_ = document_url; | 109 new_master_entry_url_ = document_url; |
103 LoadOrCreateGroup(manifest_url); | 110 LoadOrCreateGroup(manifest_url); |
104 return; | 111 return; |
105 } | 112 } |
106 | 113 |
107 // TODO(michaeln): If there was a manifest URL, the user agent may report | 114 // TODO(michaeln): If there was a manifest URL, the user agent may report |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 | 260 |
254 AppCacheHost* AppCacheHost::GetParentAppCacheHost() const { | 261 AppCacheHost* AppCacheHost::GetParentAppCacheHost() const { |
255 DCHECK(is_for_dedicated_worker()); | 262 DCHECK(is_for_dedicated_worker()); |
256 AppCacheBackendImpl* backend = service_->GetBackend(parent_process_id_); | 263 AppCacheBackendImpl* backend = service_->GetBackend(parent_process_id_); |
257 return backend ? backend->GetHost(parent_host_id_) : NULL; | 264 return backend ? backend->GetHost(parent_host_id_) : NULL; |
258 } | 265 } |
259 | 266 |
260 AppCacheRequestHandler* AppCacheHost::CreateRequestHandler( | 267 AppCacheRequestHandler* AppCacheHost::CreateRequestHandler( |
261 net::URLRequest* request, | 268 net::URLRequest* request, |
262 ResourceType::Type resource_type) { | 269 ResourceType::Type resource_type) { |
270 // Store the first party origin so that it can be used later in SelectCache | |
271 // for checking whether the creation of the appcache is allowed. | |
272 first_party_url_ = request->first_party_for_cookies(); | |
michaeln
2011/08/31 23:42:08
Can this be moved down into the if (IsMainResource
marja
2011/09/02 13:40:24
Done.
| |
273 | |
263 if (is_for_dedicated_worker()) { | 274 if (is_for_dedicated_worker()) { |
264 AppCacheHost* parent_host = GetParentAppCacheHost(); | 275 AppCacheHost* parent_host = GetParentAppCacheHost(); |
265 if (parent_host) | 276 if (parent_host) |
266 return parent_host->CreateRequestHandler(request, resource_type); | 277 return parent_host->CreateRequestHandler(request, resource_type); |
267 return NULL; | 278 return NULL; |
268 } | 279 } |
269 | 280 |
270 if (AppCacheRequestHandler::IsMainResourceType(resource_type)) | 281 if (AppCacheRequestHandler::IsMainResourceType(resource_type)) { |
271 return new AppCacheRequestHandler(this, resource_type); | 282 return new AppCacheRequestHandler(this, resource_type); |
283 } | |
272 | 284 |
273 if ((associated_cache() && associated_cache()->is_complete()) || | 285 if ((associated_cache() && associated_cache()->is_complete()) || |
274 is_selection_pending()) { | 286 is_selection_pending()) { |
275 return new AppCacheRequestHandler(this, resource_type); | 287 return new AppCacheRequestHandler(this, resource_type); |
276 } | 288 } |
277 return NULL; | 289 return NULL; |
278 } | 290 } |
279 | 291 |
280 void AppCacheHost::GetResourceList( | 292 void AppCacheHost::GetResourceList( |
281 AppCacheResourceInfoVector* resource_infos) { | 293 AppCacheResourceInfoVector* resource_infos) { |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
414 | 426 |
415 if (associated_cache_info_pending_ && associated_cache_.get() && | 427 if (associated_cache_info_pending_ && associated_cache_.get() && |
416 associated_cache_->is_complete()) { | 428 associated_cache_->is_complete()) { |
417 AppCacheInfo info; | 429 AppCacheInfo info; |
418 FillCacheInfo(associated_cache_.get(), GetStatus(), &info); | 430 FillCacheInfo(associated_cache_.get(), GetStatus(), &info); |
419 associated_cache_info_pending_ = false; | 431 associated_cache_info_pending_ = false; |
420 frontend_->OnCacheSelected(host_id_, info); | 432 frontend_->OnCacheSelected(host_id_, info); |
421 } | 433 } |
422 } | 434 } |
423 | 435 |
424 void AppCacheHost::OnContentBlocked(AppCacheGroup* group) { | 436 void AppCacheHost::OnContentBlocked(AppCacheGroup* group) { |
michaeln
2011/08/31 23:42:08
i think this method can be removed now that the up
marja
2011/09/02 13:40:24
Done.
| |
425 frontend_->OnContentBlocked(host_id_, group->manifest_url()); | 437 frontend_->OnContentBlocked(host_id_, group->manifest_url()); |
426 } | 438 } |
427 | 439 |
428 void AppCacheHost::SetSwappableCache(AppCacheGroup* group) { | 440 void AppCacheHost::SetSwappableCache(AppCacheGroup* group) { |
429 if (!group) { | 441 if (!group) { |
430 swappable_cache_ = NULL; | 442 swappable_cache_ = NULL; |
431 } else { | 443 } else { |
432 AppCache* new_cache = group->newest_complete_cache(); | 444 AppCache* new_cache = group->newest_complete_cache(); |
433 if (new_cache != associated_cache_) | 445 if (new_cache != associated_cache_) |
434 swappable_cache_ = new_cache; | 446 swappable_cache_ = new_cache; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
467 associated_cache_info_pending_ = cache && !cache->is_complete(); | 479 associated_cache_info_pending_ = cache && !cache->is_complete(); |
468 AppCacheInfo info; | 480 AppCacheInfo info; |
469 if (cache) { | 481 if (cache) { |
470 cache->AssociateHost(this); | 482 cache->AssociateHost(this); |
471 FillCacheInfo(cache, GetStatus(), &info); | 483 FillCacheInfo(cache, GetStatus(), &info); |
472 } | 484 } |
473 frontend_->OnCacheSelected(host_id_, info); | 485 frontend_->OnCacheSelected(host_id_, info); |
474 } | 486 } |
475 | 487 |
476 } // namespace appcache | 488 } // namespace appcache |
OLD | NEW |