diff options
author | michaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-24 20:38:29 +0000 |
---|---|---|
committer | michaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-24 20:38:29 +0000 |
commit | 3868baed7247f13ac96e2f14f09121d43b59aab2 (patch) | |
tree | 46f15ba8f29d762b99a20c83b7011e3bb965396d /chrome/browser/appcache | |
parent | 2b8e7ca060b5c7cae81676c233039c33c5ce080f (diff) | |
download | chromium_src-3868baed7247f13ac96e2f14f09121d43b59aab2.zip chromium_src-3868baed7247f13ac96e2f14f09121d43b59aab2.tar.gz chromium_src-3868baed7247f13ac96e2f14f09121d43b59aab2.tar.bz2 |
Put up a prompt to create appcaches if the Content Settings indicate to do so. Done for windows and linux (sorry mac, you're out of luck). Also put in place a GenericInfoView class.
BUG=38362
TEST=manual and generic_info_view_unittest.cc
Review URL: http://codereview.chromium.org/1115005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42525 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/appcache')
-rw-r--r-- | chrome/browser/appcache/chrome_appcache_service.cc | 88 | ||||
-rw-r--r-- | chrome/browser/appcache/chrome_appcache_service.h | 19 |
2 files changed, 100 insertions, 7 deletions
diff --git a/chrome/browser/appcache/chrome_appcache_service.cc b/chrome/browser/appcache/chrome_appcache_service.cc index 2fb7772..6e94f25 100644 --- a/chrome/browser/appcache/chrome_appcache_service.cc +++ b/chrome/browser/appcache/chrome_appcache_service.cc @@ -6,7 +6,9 @@ #include "base/file_path.h" #include "base/file_util.h" -#include "chrome/browser/chrome_thread.h" +#include "chrome/browser/browser_list.h" +#include "chrome/browser/cookie_prompt_modal_dialog_delegate.h" +#include "chrome/browser/message_box_handler.h" #include "chrome/browser/net/chrome_url_request_context.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/notification_service.h" @@ -15,6 +17,34 @@ static bool has_initialized_thread_ids; +// ChromeAppCacheService cannot just subclass the delegate interface +// because we may have several prompts pending. +class ChromeAppCacheService::PromptDelegate + : public CookiePromptModalDialogDelegate { + public: + PromptDelegate(ChromeAppCacheService* service, + const GURL& manifest_url, net::CompletionCallback* callback) + : service_(service), manifest_url_(manifest_url), callback_(callback) { + } + + virtual void AllowSiteData(bool session_expire) { + service_->DidPrompt(net::OK, manifest_url_, callback_); + delete this; + } + + virtual void BlockSiteData() { + service_->DidPrompt(net::ERR_ACCESS_DENIED, manifest_url_, callback_); + delete this; + } + + private: + scoped_refptr<ChromeAppCacheService> service_; + GURL manifest_url_; + net::CompletionCallback* callback_; +}; + +// ---------------------------------------------------------------------------- + ChromeAppCacheService::ChromeAppCacheService( const FilePath& profile_path, ChromeURLRequestContext* request_context) { @@ -48,6 +78,7 @@ void ChromeAppCacheService::ClearLocalState(const FilePath& profile_path) { } bool ChromeAppCacheService::CanLoadAppCache(const GURL& manifest_url) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); ContentSetting setting = host_contents_settings_map_->GetContentSetting( manifest_url, CONTENT_SETTINGS_TYPE_COOKIES); DCHECK(setting != CONTENT_SETTING_DEFAULT); @@ -57,23 +88,72 @@ bool ChromeAppCacheService::CanLoadAppCache(const GURL& manifest_url) { int ChromeAppCacheService::CanCreateAppCache( const GURL& manifest_url, net::CompletionCallback* callback) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); 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; + ChromeThread::PostTask( + ChromeThread::UI, FROM_HERE, + NewRunnableMethod(this, &ChromeAppCacheService::DoPrompt, + manifest_url, callback)); + return net::ERR_IO_PENDING; } - return (setting != CONTENT_SETTING_BLOCK) ? net::OK : net::ERR_ACCESS_DENIED; + return (setting != CONTENT_SETTING_BLOCK) ? net::OK : + net::ERR_ACCESS_DENIED; +} + +void ChromeAppCacheService::DoPrompt( + const GURL& manifest_url, net::CompletionCallback* callback) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); + + // The setting may have changed (due to the "remember" option) + ContentSetting setting = host_contents_settings_map_->GetContentSetting( + manifest_url, CONTENT_SETTINGS_TYPE_COOKIES); + if (setting != CONTENT_SETTING_ASK) { + int rv = (setting != CONTENT_SETTING_BLOCK) ? net::OK : + net::ERR_ACCESS_DENIED; + DidPrompt(rv, manifest_url, callback); + return; + } + + // Show the prompt on top of the current tab. + Browser* browser = BrowserList::GetLastActive(); + if (!browser || !browser->GetSelectedTabContents()) { + DidPrompt(net::ERR_ACCESS_DENIED, manifest_url, callback); + return; + } + + RunAppCachePrompt(browser->GetSelectedTabContents(), + host_contents_settings_map_, manifest_url, + new PromptDelegate(this, manifest_url, callback)); +} + +void ChromeAppCacheService::DidPrompt( + int rv, const GURL& manifest_url, net::CompletionCallback* callback) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); + ChromeThread::PostTask( + ChromeThread::IO, FROM_HERE, + NewRunnableMethod(this, &ChromeAppCacheService::CallCallback, + rv, callback)); +} + +void ChromeAppCacheService::CallCallback( + int rv, net::CompletionCallback* callback) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); + callback->Run(rv); } void ChromeAppCacheService::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); DCHECK(type == NotificationType::PURGE_MEMORY); PurgeMemory(); } +// ---------------------------------------------------------------------------- + static ChromeThread::ID ToChromeThreadID(int id) { DCHECK(has_initialized_thread_ids); DCHECK(id == ChromeThread::DB || id == ChromeThread::IO); diff --git a/chrome/browser/appcache/chrome_appcache_service.h b/chrome/browser/appcache/chrome_appcache_service.h index 848a83f..888b672 100644 --- a/chrome/browser/appcache/chrome_appcache_service.h +++ b/chrome/browser/appcache/chrome_appcache_service.h @@ -6,6 +6,7 @@ #define CHROME_BROWSER_APPCACHE_CHROME_APPCACHE_SERVICE_H_ #include "base/ref_counted.h" +#include "chrome/browser/chrome_thread.h" #include "chrome/browser/host_content_settings_map.h" #include "chrome/common/notification_registrar.h" #include "webkit/appcache/appcache_policy.h" @@ -21,9 +22,10 @@ class FilePath; // owning profile. // // All methods, including the ctor and dtor, are expected to be called on -// the IO thread. +// the IO thread (unless specifically called out in doc comments). class ChromeAppCacheService - : public base::RefCounted<ChromeAppCacheService>, + : public base::RefCountedThreadSafe<ChromeAppCacheService, + ChromeThread::DeleteOnIOThread>, public appcache::AppCacheService, public appcache::AppCachePolicy, public NotificationObserver { @@ -34,7 +36,11 @@ class ChromeAppCacheService static void ClearLocalState(const FilePath& profile_path); private: - friend class base::RefCounted<ChromeAppCacheService>; + friend class ChromeThread; + friend class DeleteTask<ChromeAppCacheService>; + + class PromptDelegate; + virtual ~ChromeAppCacheService(); // AppCachePolicy overrides @@ -42,6 +48,13 @@ class ChromeAppCacheService virtual int CanCreateAppCache(const GURL& manifest_url, net::CompletionCallback* callback); + // The DoPrompt and DidPrrompt methods are called on the UI thread, and + // the following CallCallback method is called on the IO thread. + void DoPrompt(const GURL& manifest_url, net::CompletionCallback* callback); + void DidPrompt(int rv, const GURL& manifest_url, + net::CompletionCallback* callback); + void CallCallback(int rv, net::CompletionCallback* callback); + // NotificationObserver override virtual void Observe(NotificationType type, const NotificationSource& source, |