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_service.h" | 5 #include "webkit/appcache/appcache_service.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
11 #include "webkit/appcache/appcache.h" | 11 #include "webkit/appcache/appcache.h" |
12 #include "webkit/appcache/appcache_backend_impl.h" | 12 #include "webkit/appcache/appcache_backend_impl.h" |
13 #include "webkit/appcache/appcache_entry.h" | 13 #include "webkit/appcache/appcache_entry.h" |
14 #include "webkit/appcache/appcache_histograms.h" | 14 #include "webkit/appcache/appcache_histograms.h" |
| 15 #include "webkit/appcache/appcache_policy.h" |
15 #include "webkit/appcache/appcache_quota_client.h" | 16 #include "webkit/appcache/appcache_quota_client.h" |
16 #include "webkit/appcache/appcache_response.h" | 17 #include "webkit/appcache/appcache_response.h" |
17 #include "webkit/appcache/appcache_storage_impl.h" | 18 #include "webkit/appcache/appcache_storage_impl.h" |
18 #include "webkit/quota/quota_manager.h" | 19 #include "webkit/quota/quota_manager.h" |
19 #include "webkit/quota/special_storage_policy.h" | 20 #include "webkit/quota/special_storage_policy.h" |
20 | 21 |
21 namespace appcache { | 22 namespace appcache { |
22 | 23 |
23 AppCacheInfoCollection::AppCacheInfoCollection() {} | 24 AppCacheInfoCollection::AppCacheInfoCollection() {} |
24 | 25 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 service_->storage()->CancelDelegateCallbacks(this); | 71 service_->storage()->CancelDelegateCallbacks(this); |
71 service_ = NULL; | 72 service_ = NULL; |
72 } | 73 } |
73 | 74 |
74 // CanHandleOfflineHelper ------- | 75 // CanHandleOfflineHelper ------- |
75 | 76 |
76 class AppCacheService::CanHandleOfflineHelper : AsyncHelper { | 77 class AppCacheService::CanHandleOfflineHelper : AsyncHelper { |
77 public: | 78 public: |
78 CanHandleOfflineHelper( | 79 CanHandleOfflineHelper( |
79 AppCacheService* service, const GURL& url, | 80 AppCacheService* service, const GURL& url, |
80 net::CompletionCallback* callback) | 81 const GURL& first_party, net::CompletionCallback* callback) |
81 : AsyncHelper(service, callback), url_(url) { | 82 : AsyncHelper(service, callback), url_(url), first_party_(first_party) { |
82 } | 83 } |
83 | 84 |
84 virtual void Start() { | 85 virtual void Start() { |
| 86 AppCachePolicy* policy = service_->appcache_policy(); |
| 87 if (policy && !policy->CanLoadAppCache(url_, first_party_)) { |
| 88 CallCallback(net::ERR_FAILED); |
| 89 delete this; |
| 90 return; |
| 91 } |
85 service_->storage()->FindResponseForMainRequest(url_, GURL(), this); | 92 service_->storage()->FindResponseForMainRequest(url_, GURL(), this); |
86 } | 93 } |
87 | 94 |
88 private: | 95 private: |
89 // AppCacheStorage::Delegate override | 96 // AppCacheStorage::Delegate override |
90 virtual void OnMainResponseFound( | 97 virtual void OnMainResponseFound( |
91 const GURL& url, const AppCacheEntry& entry, | 98 const GURL& url, const AppCacheEntry& entry, |
92 const GURL& fallback_url, const AppCacheEntry& fallback_entry, | 99 const GURL& fallback_url, const AppCacheEntry& fallback_entry, |
93 int64 cache_id, const GURL& mainfest_url, | 100 int64 cache_id, const GURL& mainfest_url); |
94 bool was_blocked_by_policy); | |
95 | 101 |
96 GURL url_; | 102 GURL url_; |
| 103 GURL first_party_; |
97 DISALLOW_COPY_AND_ASSIGN(CanHandleOfflineHelper); | 104 DISALLOW_COPY_AND_ASSIGN(CanHandleOfflineHelper); |
98 }; | 105 }; |
99 | 106 |
100 void AppCacheService::CanHandleOfflineHelper::OnMainResponseFound( | 107 void AppCacheService::CanHandleOfflineHelper::OnMainResponseFound( |
101 const GURL& url, const AppCacheEntry& entry, | 108 const GURL& url, const AppCacheEntry& entry, |
102 const GURL& fallback_url, const AppCacheEntry& fallback_entry, | 109 const GURL& fallback_url, const AppCacheEntry& fallback_entry, |
103 int64 cache_id, const GURL& mainfest_url, | 110 int64 cache_id, const GURL& manifest_url) { |
104 bool was_blocked_by_policy) { | 111 bool can = (entry.has_response_id() || fallback_entry.has_response_id()); |
105 bool can = !was_blocked_by_policy && | |
106 (entry.has_response_id() || fallback_entry.has_response_id()); | |
107 CallCallback(can ? net::OK : net::ERR_FAILED); | 112 CallCallback(can ? net::OK : net::ERR_FAILED); |
108 delete this; | 113 delete this; |
109 } | 114 } |
110 | 115 |
111 // DeleteHelper ------- | 116 // DeleteHelper ------- |
112 | 117 |
113 class AppCacheService::DeleteHelper : public AsyncHelper { | 118 class AppCacheService::DeleteHelper : public AsyncHelper { |
114 public: | 119 public: |
115 DeleteHelper( | 120 DeleteHelper( |
116 AppCacheService* service, const GURL& manifest_url, | 121 AppCacheService* service, const GURL& manifest_url, |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 void AppCacheService::Initialize(const FilePath& cache_directory, | 436 void AppCacheService::Initialize(const FilePath& cache_directory, |
432 base::MessageLoopProxy* cache_thread) { | 437 base::MessageLoopProxy* cache_thread) { |
433 DCHECK(!storage_.get()); | 438 DCHECK(!storage_.get()); |
434 AppCacheStorageImpl* storage = new AppCacheStorageImpl(this); | 439 AppCacheStorageImpl* storage = new AppCacheStorageImpl(this); |
435 storage->Initialize(cache_directory, cache_thread); | 440 storage->Initialize(cache_directory, cache_thread); |
436 storage_.reset(storage); | 441 storage_.reset(storage); |
437 } | 442 } |
438 | 443 |
439 void AppCacheService::CanHandleMainResourceOffline( | 444 void AppCacheService::CanHandleMainResourceOffline( |
440 const GURL& url, | 445 const GURL& url, |
| 446 const GURL& first_party, |
441 net::CompletionCallback* callback) { | 447 net::CompletionCallback* callback) { |
442 CanHandleOfflineHelper* helper = | 448 CanHandleOfflineHelper* helper = |
443 new CanHandleOfflineHelper(this, url, callback); | 449 new CanHandleOfflineHelper(this, url, first_party, callback); |
444 helper->Start(); | 450 helper->Start(); |
445 } | 451 } |
446 | 452 |
447 void AppCacheService::GetAllAppCacheInfo(AppCacheInfoCollection* collection, | 453 void AppCacheService::GetAllAppCacheInfo(AppCacheInfoCollection* collection, |
448 net::CompletionCallback* callback) { | 454 net::CompletionCallback* callback) { |
449 DCHECK(collection); | 455 DCHECK(collection); |
450 GetInfoHelper* helper = new GetInfoHelper(this, collection, callback); | 456 GetInfoHelper* helper = new GetInfoHelper(this, collection, callback); |
451 helper->Start(); | 457 helper->Start(); |
452 } | 458 } |
453 | 459 |
(...skipping 28 matching lines...) Expand all Loading... |
482 backends_.insert( | 488 backends_.insert( |
483 BackendMap::value_type(backend_impl->process_id(), backend_impl)); | 489 BackendMap::value_type(backend_impl->process_id(), backend_impl)); |
484 } | 490 } |
485 | 491 |
486 void AppCacheService::UnregisterBackend( | 492 void AppCacheService::UnregisterBackend( |
487 AppCacheBackendImpl* backend_impl) { | 493 AppCacheBackendImpl* backend_impl) { |
488 backends_.erase(backend_impl->process_id()); | 494 backends_.erase(backend_impl->process_id()); |
489 } | 495 } |
490 | 496 |
491 } // namespace appcache | 497 } // namespace appcache |
OLD | NEW |