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 return; |
| 90 } |
85 service_->storage()->FindResponseForMainRequest(url_, GURL(), this); | 91 service_->storage()->FindResponseForMainRequest(url_, GURL(), this); |
86 } | 92 } |
87 | 93 |
88 private: | 94 private: |
89 // AppCacheStorage::Delegate override | 95 // AppCacheStorage::Delegate override |
90 virtual void OnMainResponseFound( | 96 virtual void OnMainResponseFound( |
91 const GURL& url, const AppCacheEntry& entry, | 97 const GURL& url, const AppCacheEntry& entry, |
92 const GURL& fallback_url, const AppCacheEntry& fallback_entry, | 98 const GURL& fallback_url, const AppCacheEntry& fallback_entry, |
93 int64 cache_id, const GURL& mainfest_url, | 99 int64 cache_id, const GURL& mainfest_url); |
94 bool was_blocked_by_policy); | |
95 | 100 |
96 GURL url_; | 101 GURL url_; |
| 102 GURL first_party_; |
97 DISALLOW_COPY_AND_ASSIGN(CanHandleOfflineHelper); | 103 DISALLOW_COPY_AND_ASSIGN(CanHandleOfflineHelper); |
98 }; | 104 }; |
99 | 105 |
100 void AppCacheService::CanHandleOfflineHelper::OnMainResponseFound( | 106 void AppCacheService::CanHandleOfflineHelper::OnMainResponseFound( |
101 const GURL& url, const AppCacheEntry& entry, | 107 const GURL& url, const AppCacheEntry& entry, |
102 const GURL& fallback_url, const AppCacheEntry& fallback_entry, | 108 const GURL& fallback_url, const AppCacheEntry& fallback_entry, |
103 int64 cache_id, const GURL& mainfest_url, | 109 int64 cache_id, const GURL& manifest_url) { |
104 bool was_blocked_by_policy) { | 110 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); | 111 CallCallback(can ? net::OK : net::ERR_FAILED); |
108 delete this; | 112 delete this; |
109 } | 113 } |
110 | 114 |
111 // DeleteHelper ------- | 115 // DeleteHelper ------- |
112 | 116 |
113 class AppCacheService::DeleteHelper : public AsyncHelper { | 117 class AppCacheService::DeleteHelper : public AsyncHelper { |
114 public: | 118 public: |
115 DeleteHelper( | 119 DeleteHelper( |
116 AppCacheService* service, const GURL& manifest_url, | 120 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, | 435 void AppCacheService::Initialize(const FilePath& cache_directory, |
432 base::MessageLoopProxy* cache_thread) { | 436 base::MessageLoopProxy* cache_thread) { |
433 DCHECK(!storage_.get()); | 437 DCHECK(!storage_.get()); |
434 AppCacheStorageImpl* storage = new AppCacheStorageImpl(this); | 438 AppCacheStorageImpl* storage = new AppCacheStorageImpl(this); |
435 storage->Initialize(cache_directory, cache_thread); | 439 storage->Initialize(cache_directory, cache_thread); |
436 storage_.reset(storage); | 440 storage_.reset(storage); |
437 } | 441 } |
438 | 442 |
439 void AppCacheService::CanHandleMainResourceOffline( | 443 void AppCacheService::CanHandleMainResourceOffline( |
440 const GURL& url, | 444 const GURL& url, |
| 445 const GURL& first_party, |
441 net::CompletionCallback* callback) { | 446 net::CompletionCallback* callback) { |
442 CanHandleOfflineHelper* helper = | 447 CanHandleOfflineHelper* helper = |
443 new CanHandleOfflineHelper(this, url, callback); | 448 new CanHandleOfflineHelper(this, url, first_party, callback); |
444 helper->Start(); | 449 helper->Start(); |
445 } | 450 } |
446 | 451 |
447 void AppCacheService::GetAllAppCacheInfo(AppCacheInfoCollection* collection, | 452 void AppCacheService::GetAllAppCacheInfo(AppCacheInfoCollection* collection, |
448 net::CompletionCallback* callback) { | 453 net::CompletionCallback* callback) { |
449 DCHECK(collection); | 454 DCHECK(collection); |
450 GetInfoHelper* helper = new GetInfoHelper(this, collection, callback); | 455 GetInfoHelper* helper = new GetInfoHelper(this, collection, callback); |
451 helper->Start(); | 456 helper->Start(); |
452 } | 457 } |
453 | 458 |
(...skipping 28 matching lines...) Expand all Loading... |
482 backends_.insert( | 487 backends_.insert( |
483 BackendMap::value_type(backend_impl->process_id(), backend_impl)); | 488 BackendMap::value_type(backend_impl->process_id(), backend_impl)); |
484 } | 489 } |
485 | 490 |
486 void AppCacheService::UnregisterBackend( | 491 void AppCacheService::UnregisterBackend( |
487 AppCacheBackendImpl* backend_impl) { | 492 AppCacheBackendImpl* backend_impl) { |
488 backends_.erase(backend_impl->process_id()); | 493 backends_.erase(backend_impl->process_id()); |
489 } | 494 } |
490 | 495 |
491 } // namespace appcache | 496 } // namespace appcache |
OLD | NEW |