diff options
author | michaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-17 22:20:36 +0000 |
---|---|---|
committer | michaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-17 22:20:36 +0000 |
commit | ea776d0208899b770ea386b994216ef476197a46 (patch) | |
tree | cb614ced5bd6e764e01f244813d07b0a48870a0a /chrome | |
parent | a3d3a7cf3b81cc8d00490bb7bfd92b57f0146d9c (diff) | |
download | chromium_src-ea776d0208899b770ea386b994216ef476197a46.zip chromium_src-ea776d0208899b770ea386b994216ef476197a46.tar.gz chromium_src-ea776d0208899b770ea386b994216ef476197a46.tar.bz2 |
Introduce an AppCachePolicy interface that allows the containing browser to determine appcache permissions. The policy can allow or deny loading existing manifests or the creation of new manifests. The policy check for creating new manifests can be async to allow for a user prompt.
BUG=none
TEST=new unit tests added
Review URL: http://codereview.chromium.org/565042
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39280 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/common/appcache/chrome_appcache_service.cc | 22 | ||||
-rw-r--r-- | chrome/common/appcache/chrome_appcache_service.h | 7 |
2 files changed, 29 insertions, 0 deletions
diff --git a/chrome/common/appcache/chrome_appcache_service.cc b/chrome/common/appcache/chrome_appcache_service.cc index 68e30c7..5fdb17f 100644 --- a/chrome/common/appcache/chrome_appcache_service.cc +++ b/chrome/common/appcache/chrome_appcache_service.cc @@ -10,6 +10,7 @@ #include "chrome/browser/net/chrome_url_request_context.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/notification_service.h" +#include "net/base/net_errors.h" #include "webkit/appcache/appcache_thread.h" static bool has_initialized_thread_ids; @@ -33,6 +34,7 @@ ChromeAppCacheService::ChromeAppCacheService( Initialize(request_context->is_off_the_record() ? FilePath() : profile_path.Append(chrome::kAppCacheDirname)); set_request_context(request_context); + set_appcache_policy(this); } ChromeAppCacheService::~ChromeAppCacheService() { @@ -44,6 +46,26 @@ void ChromeAppCacheService::ClearLocalState(const FilePath& profile_path) { file_util::Delete(profile_path.Append(chrome::kAppCacheDirname), true); } +bool ChromeAppCacheService::CanLoadAppCache(const GURL& manifest_url) { + ContentSetting setting = host_contents_settings_map_->GetContentSetting( + manifest_url, CONTENT_SETTINGS_TYPE_COOKIES); + DCHECK(setting != CONTENT_SETTING_DEFAULT); + return setting == CONTENT_SETTING_ALLOW || + setting == CONTENT_SETTING_ASK; // we don't prompt for read access +} + +int ChromeAppCacheService::CanCreateAppCache( + const GURL& manifest_url, net::CompletionCallback* callback) { + ContentSetting setting = host_contents_settings_map_->GetContentSetting( + manifest_url, CONTENT_SETTINGS_TYPE_COOKIES); + DCHECK(setting != CONTENT_SETTING_DEFAULT); + if (setting == CONTENT_SETTING_ASK) { + // TODO(michaeln): prompt the user, for now we block + setting = CONTENT_SETTING_BLOCK; + } + return (setting != CONTENT_SETTING_BLOCK) ? net::OK : net::ERR_ACCESS_DENIED; +} + void ChromeAppCacheService::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { diff --git a/chrome/common/appcache/chrome_appcache_service.h b/chrome/common/appcache/chrome_appcache_service.h index ec7b0bd..fd36a05 100644 --- a/chrome/common/appcache/chrome_appcache_service.h +++ b/chrome/common/appcache/chrome_appcache_service.h @@ -8,6 +8,7 @@ #include "base/ref_counted.h" #include "chrome/browser/host_content_settings_map.h" #include "chrome/common/notification_registrar.h" +#include "webkit/appcache/appcache_policy.h" #include "webkit/appcache/appcache_service.h" class ChromeURLRequestContext; @@ -24,6 +25,7 @@ class FilePath; class ChromeAppCacheService : public base::RefCounted<ChromeAppCacheService>, public appcache::AppCacheService, + public appcache::AppCachePolicy, public NotificationObserver { public: ChromeAppCacheService(const FilePath& profile_path, @@ -35,6 +37,11 @@ class ChromeAppCacheService friend class base::RefCounted<ChromeAppCacheService>; virtual ~ChromeAppCacheService(); + // AppCachePolicy overrides + virtual bool CanLoadAppCache(const GURL& manifest_url); + virtual int CanCreateAppCache(const GURL& manifest_url, + net::CompletionCallback* callback); + // NotificationObserver override virtual void Observe(NotificationType type, const NotificationSource& source, |