diff options
-rw-r--r-- | chrome/browser/cookie_modal_dialog.cc | 33 | ||||
-rw-r--r-- | chrome/browser/cookie_modal_dialog.h | 11 | ||||
-rw-r--r-- | chrome/browser/cookie_prompt_modal_dialog_delegate.h | 10 | ||||
-rw-r--r-- | chrome/browser/in_process_webkit/dom_storage_permission_request.cc | 37 | ||||
-rw-r--r-- | chrome/browser/in_process_webkit/dom_storage_permission_request.h | 6 | ||||
-rw-r--r-- | chrome/browser/message_box_handler.cc | 13 | ||||
-rw-r--r-- | chrome/browser/message_box_handler.h | 4 | ||||
-rw-r--r-- | chrome/browser/net/chrome_cookie_policy.cc | 41 | ||||
-rw-r--r-- | chrome/browser/net/chrome_cookie_policy.h | 3 | ||||
-rw-r--r-- | chrome/browser/renderer_host/database_permission_request.cc | 27 | ||||
-rw-r--r-- | chrome/browser/renderer_host/database_permission_request.h | 6 | ||||
-rw-r--r-- | chrome/browser/views/cookie_prompt_view.cc | 1 | ||||
-rw-r--r-- | chrome/browser/views/cookie_prompt_view.h | 2 |
13 files changed, 100 insertions, 94 deletions
diff --git a/chrome/browser/cookie_modal_dialog.cc b/chrome/browser/cookie_modal_dialog.cc index 579698e..a744fdf 100644 --- a/chrome/browser/cookie_modal_dialog.cc +++ b/chrome/browser/cookie_modal_dialog.cc @@ -14,10 +14,12 @@ // Cookies CookiePromptModalDialog::CookiePromptModalDialog( TabContents* tab_contents, + HostContentSettingsMap* host_content_settings_map, const GURL& origin, const std::string& cookie_line, CookiePromptModalDialogDelegate* delegate) : AppModalDialog(tab_contents, std::wstring()), + host_content_settings_map_(host_content_settings_map), dialog_type_(DIALOG_TYPE_COOKIE), origin_(origin), cookie_line_(cookie_line), @@ -27,11 +29,13 @@ CookiePromptModalDialog::CookiePromptModalDialog( // LocalStorage CookiePromptModalDialog::CookiePromptModalDialog( TabContents* tab_contents, + HostContentSettingsMap* host_content_settings_map, const GURL& origin, const string16& key, const string16& value, CookiePromptModalDialogDelegate* delegate) : AppModalDialog(tab_contents, std::wstring()), + host_content_settings_map_(host_content_settings_map), dialog_type_(DIALOG_TYPE_LOCAL_STORAGE), origin_(origin), local_storage_key_(key), @@ -42,25 +46,28 @@ CookiePromptModalDialog::CookiePromptModalDialog( // Database CookiePromptModalDialog::CookiePromptModalDialog( TabContents* tab_contents, + HostContentSettingsMap* host_content_settings_map, const GURL& origin, const string16& database_name, CookiePromptModalDialogDelegate* delegate) : AppModalDialog(tab_contents, std::wstring()), + host_content_settings_map_(host_content_settings_map), dialog_type_(DIALOG_TYPE_DATABASE), origin_(origin), database_name_(database_name), delegate_(delegate) { } +CookiePromptModalDialog::~CookiePromptModalDialog() { +} + bool CookiePromptModalDialog::IsValid() { - HostContentSettingsMap* host_content_settings_map = - tab_contents()->profile()->GetHostContentSettingsMap(); ContentSetting content_setting = - host_content_settings_map->GetContentSetting( - origin(), - CONTENT_SETTINGS_TYPE_COOKIES); + host_content_settings_map_->GetContentSetting( + origin_, CONTENT_SETTINGS_TYPE_COOKIES); if (content_setting != CONTENT_SETTING_ASK) { if (content_setting == CONTENT_SETTING_ALLOW) { + // If it's remembered as allow, then we assume session_expire is false. AllowSiteData(false, false); } else { DCHECK(content_setting == CONTENT_SETTING_BLOCK); @@ -68,20 +75,30 @@ bool CookiePromptModalDialog::IsValid() { } return false; } - return true; + return !skip_this_dialog_; } void CookiePromptModalDialog::AllowSiteData(bool remember, bool session_expire) { + if (remember) { + host_content_settings_map_->SetContentSetting( + origin_.host(), CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_ALLOW); + } + if (delegate_) { - delegate_->AllowSiteData(remember, session_expire); + delegate_->AllowSiteData(session_expire); delegate_ = NULL; // It can be deleted at any point now. } } void CookiePromptModalDialog::BlockSiteData(bool remember) { + if (remember) { + host_content_settings_map_->SetContentSetting( + origin_.host(), CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); + } + if (delegate_) { - delegate_->BlockSiteData(remember); + delegate_->BlockSiteData(); delegate_ = NULL; // It can be deleted at any point now. } } diff --git a/chrome/browser/cookie_modal_dialog.h b/chrome/browser/cookie_modal_dialog.h index 05ed0e2..04fedae 100644 --- a/chrome/browser/cookie_modal_dialog.h +++ b/chrome/browser/cookie_modal_dialog.h @@ -7,11 +7,13 @@ #include <string> +#include "base/ref_counted.h" #include "chrome/browser/app_modal_dialog.h" #include "chrome/browser/browsing_data_local_storage_helper.h" #include "chrome/browser/cookie_prompt_modal_dialog_delegate.h" #include "googleurl/src/gurl.h" +class HostContentSettingsMap; class PrefService; // A controller+model class for cookie and local storage warning prompt. @@ -28,19 +30,22 @@ class CookiePromptModalDialog : public AppModalDialog { // A union of data necessary to determine the type of message box to // show. CookiePromptModalDialog(TabContents* tab_contents, + HostContentSettingsMap* host_content_settings_map, const GURL& origin, const std::string& cookie_line, CookiePromptModalDialogDelegate* delegate); CookiePromptModalDialog(TabContents* tab_contents, + HostContentSettingsMap* host_content_settings_map, const GURL& origin, const string16& key, const string16& value, CookiePromptModalDialogDelegate* delegate); CookiePromptModalDialog(TabContents* tab_contents, + HostContentSettingsMap* host_content_settings_map, const GURL& origin, const string16& database_name, CookiePromptModalDialogDelegate* delegate); - virtual ~CookiePromptModalDialog() {} + virtual ~CookiePromptModalDialog(); static void RegisterPrefs(PrefService* prefs); @@ -70,6 +75,10 @@ class CookiePromptModalDialog : public AppModalDialog { #endif private: + // Used to verify our request is still necessary and when the response should + // persist. + scoped_refptr<HostContentSettingsMap> host_content_settings_map_; + const DialogType dialog_type_; // The origin connected to this request. diff --git a/chrome/browser/cookie_prompt_modal_dialog_delegate.h b/chrome/browser/cookie_prompt_modal_dialog_delegate.h index ed21a74..3708c05 100644 --- a/chrome/browser/cookie_prompt_modal_dialog_delegate.h +++ b/chrome/browser/cookie_prompt_modal_dialog_delegate.h @@ -11,13 +11,11 @@ // deleted. class CookiePromptModalDialogDelegate { public: - // Allow site data to be set. If |remember| is true, record this decision - // for this host. - virtual void AllowSiteData(bool remember, bool session_expire) = 0; + // Allow site data to be set. + virtual void AllowSiteData(bool session_expire) = 0; - // Block site data from being stored. If |remember| is true, record this - // decision for this host. - virtual void BlockSiteData(bool remember) = 0; + // Block site data from being stored. + virtual void BlockSiteData() = 0; protected: virtual ~CookiePromptModalDialogDelegate() {} diff --git a/chrome/browser/in_process_webkit/dom_storage_permission_request.cc b/chrome/browser/in_process_webkit/dom_storage_permission_request.cc index 93b21ef..47b61ce 100644 --- a/chrome/browser/in_process_webkit/dom_storage_permission_request.cc +++ b/chrome/browser/in_process_webkit/dom_storage_permission_request.cc @@ -26,53 +26,44 @@ ContentSetting DOMStoragePermissionRequest::WaitOnResponse() { // static void DOMStoragePermissionRequest::PromptUser( - DOMStoragePermissionRequest* dom_storage_permission_request) { + DOMStoragePermissionRequest* request) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); // Cookie settings may have changed. ContentSetting setting = - dom_storage_permission_request->host_content_settings_map_-> - GetContentSetting(dom_storage_permission_request->url(), - CONTENT_SETTINGS_TYPE_COOKIES); + request->host_content_settings_map_->GetContentSetting( + request->url_, CONTENT_SETTINGS_TYPE_COOKIES); if (setting != CONTENT_SETTING_ASK) { - dom_storage_permission_request->SendResponse(setting, false); + request->SendResponse(setting); return; } Browser* browser = BrowserList::GetLastActive(); if (!browser || !browser->GetSelectedTabContents()) { - dom_storage_permission_request->SendResponse(CONTENT_SETTING_BLOCK, false); + request->SendResponse(CONTENT_SETTING_BLOCK); return; } #if defined(OS_WIN) RunLocalStoragePrompt(browser->GetSelectedTabContents(), - dom_storage_permission_request->url(), - dom_storage_permission_request->key(), - dom_storage_permission_request->value(), - dom_storage_permission_request); + request->host_content_settings_map_, request->url_, + request->key_, request->value_, request); #else // TODO(darin): Enable prompting for other ports. - dom_storage_permission_request->SendResponse(CONTENT_SETTING_BLOCK, false); + request->SendResponse(CONTENT_SETTING_BLOCK); #endif } -void DOMStoragePermissionRequest::AllowSiteData(bool remember, - bool session_expire) { - // The session_expire parameter is not relevant. - SendResponse(CONTENT_SETTING_ALLOW, remember); +void DOMStoragePermissionRequest::AllowSiteData(bool session_expire) { + SendResponse(CONTENT_SETTING_ALLOW); } -void DOMStoragePermissionRequest::BlockSiteData(bool remember) { - SendResponse(CONTENT_SETTING_BLOCK, remember); +void DOMStoragePermissionRequest::BlockSiteData() { + SendResponse(CONTENT_SETTING_BLOCK); } -void DOMStoragePermissionRequest::SendResponse(ContentSetting content_setting, - bool remember) { +void DOMStoragePermissionRequest::SendResponse( + ContentSetting content_setting) { response_content_setting_ = content_setting; - if (remember) { - host_content_settings_map_->SetContentSetting( - url_.host(), CONTENT_SETTINGS_TYPE_COOKIES, content_setting); - } event_.Signal(); } diff --git a/chrome/browser/in_process_webkit/dom_storage_permission_request.h b/chrome/browser/in_process_webkit/dom_storage_permission_request.h index cad41cb..48f93c3 100644 --- a/chrome/browser/in_process_webkit/dom_storage_permission_request.h +++ b/chrome/browser/in_process_webkit/dom_storage_permission_request.h @@ -35,11 +35,11 @@ class DOMStoragePermissionRequest : public CookiePromptModalDialogDelegate { static void PromptUser(DOMStoragePermissionRequest* request); // CookiesPromptViewDelegate methods: - virtual void AllowSiteData(bool remember, bool session_expire); - virtual void BlockSiteData(bool remember); + virtual void AllowSiteData(bool session_expire); + virtual void BlockSiteData(); private: - void SendResponse(ContentSetting content_setting, bool remember); + void SendResponse(ContentSetting content_setting); // The URL we need to get permission for. const GURL url_; diff --git a/chrome/browser/message_box_handler.cc b/chrome/browser/message_box_handler.cc index df4820f..6b9fa93 100644 --- a/chrome/browser/message_box_handler.cc +++ b/chrome/browser/message_box_handler.cc @@ -60,31 +60,36 @@ void RunBeforeUnloadDialog(TabContents* tab_contents, #if defined(OS_WIN) void RunCookiePrompt(TabContents* tab_contents, + HostContentSettingsMap* host_content_settings_map, const GURL& origin, const std::string& cookie_line, CookiePromptModalDialogDelegate* delegate) { Singleton<AppModalDialogQueue>()->AddDialog( - new CookiePromptModalDialog(tab_contents, origin, cookie_line, delegate)); + new CookiePromptModalDialog(tab_contents, host_content_settings_map, + origin, cookie_line, delegate)); } void RunLocalStoragePrompt( TabContents* tab_contents, + HostContentSettingsMap* host_content_settings_map, const GURL& origin, const string16& key, const string16& value, CookiePromptModalDialogDelegate* delegate) { Singleton<AppModalDialogQueue>()->AddDialog( - new CookiePromptModalDialog(tab_contents, origin, key, value, delegate)); + new CookiePromptModalDialog(tab_contents, host_content_settings_map, + origin, key, value, delegate)); } void RunDatabasePrompt( TabContents* tab_contents, + HostContentSettingsMap* host_content_settings_map, const GURL& origin, const string16& database_name, CookiePromptModalDialogDelegate* delegate) { Singleton<AppModalDialogQueue>()->AddDialog( - new CookiePromptModalDialog(tab_contents, origin, database_name, - delegate)); + new CookiePromptModalDialog(tab_contents, host_content_settings_map, + origin, database_name, delegate)); } #endif diff --git a/chrome/browser/message_box_handler.h b/chrome/browser/message_box_handler.h index 9521a0f..792055d 100644 --- a/chrome/browser/message_box_handler.h +++ b/chrome/browser/message_box_handler.h @@ -15,6 +15,7 @@ class CookiePromptModalDialogDelegate; class GURL; +class HostContentSettingsMap; class JavaScriptMessageBoxClient; class TabContents; @@ -46,6 +47,7 @@ void RunBeforeUnloadDialog(TabContents* tab_contents, // user to accept or reject the cookie. The caller should pass |delegate| // that will handle the reply from the dialog. void RunCookiePrompt(TabContents* tab_contents, + HostContentSettingsMap* host_content_settings_map, const GURL& origin, const std::string& cookie_line, CookiePromptModalDialogDelegate* delegate); @@ -55,6 +57,7 @@ void RunCookiePrompt(TabContents* tab_contents, // that will handle the reply from the dialog. void RunLocalStoragePrompt( TabContents* tab_contents, + HostContentSettingsMap* host_content_settings_map, const GURL& origin, const string16& key, const string16& value, @@ -65,6 +68,7 @@ void RunLocalStoragePrompt( // that will handle the reply from the dialog. void RunDatabasePrompt( TabContents* tab_contents, + HostContentSettingsMap* host_content_settings_map, const GURL& origin, const string16& database_name, CookiePromptModalDialogDelegate* delegate); diff --git a/chrome/browser/net/chrome_cookie_policy.cc b/chrome/browser/net/chrome_cookie_policy.cc index 583328b..e0956fb 100644 --- a/chrome/browser/net/chrome_cookie_policy.cc +++ b/chrome/browser/net/chrome_cookie_policy.cc @@ -31,30 +31,29 @@ class ChromeCookiePolicy::PromptDelegate } // CookiesPromptViewDelegate methods: - virtual void AllowSiteData(bool remember, bool session_expire); - virtual void BlockSiteData(bool remember); + virtual void AllowSiteData(bool session_expire); + virtual void BlockSiteData(); private: - void NotifyDone(int policy, bool remember); + void NotifyDone(int policy); scoped_refptr<ChromeCookiePolicy> cookie_policy_; std::string host_; }; -void ChromeCookiePolicy::PromptDelegate::AllowSiteData(bool remember, - bool session_expire) { +void ChromeCookiePolicy::PromptDelegate::AllowSiteData(bool session_expire) { int policy = net::OK; if (session_expire) policy = net::OK_FOR_SESSION_ONLY; - NotifyDone(policy, remember); + NotifyDone(policy); } -void ChromeCookiePolicy::PromptDelegate::BlockSiteData(bool remember) { - NotifyDone(net::ERR_ACCESS_DENIED, remember); +void ChromeCookiePolicy::PromptDelegate::BlockSiteData() { + NotifyDone(net::ERR_ACCESS_DENIED); } -void ChromeCookiePolicy::PromptDelegate::NotifyDone(int policy, bool remember) { - cookie_policy_->DidPromptForSetCookie(host_, policy, remember); +void ChromeCookiePolicy::PromptDelegate::NotifyDone(int policy) { + cookie_policy_->DidPromptForSetCookie(host_, policy); delete this; } @@ -164,42 +163,34 @@ void ChromeCookiePolicy::PromptForSetCookie(const GURL& url, // The policy may have changed (due to the "remember" option) int policy = CheckPolicy(url); if (policy != net::ERR_IO_PENDING) { - DidPromptForSetCookie(host, policy, false); + DidPromptForSetCookie(host, policy); return; } // Show the prompt on top of the current tab. Browser* browser = BrowserList::GetLastActive(); if (!browser || !browser->GetSelectedTabContents()) { - DidPromptForSetCookie(host, net::ERR_ACCESS_DENIED, false); + DidPromptForSetCookie(host, net::ERR_ACCESS_DENIED); return; } #if defined(OS_WIN) - RunCookiePrompt(browser->GetSelectedTabContents(), url, cookie_line, + RunCookiePrompt(browser->GetSelectedTabContents(), + host_content_settings_map_, url, cookie_line, new PromptDelegate(this, host)); #else // TODO(darin): Enable prompting for other ports. - DidPromptForSetCookie(host, net::ERR_ACCESS_DENIED, false); + DidPromptForSetCookie(host, net::ERR_ACCESS_DENIED); #endif } void ChromeCookiePolicy::DidPromptForSetCookie(const std::string& host, - int policy, bool remember) { + int policy) { if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) { - // Process the remember flag immediately. - if (remember) { - ContentSetting content_setting = CONTENT_SETTING_BLOCK; - if (policy == net::OK || policy == net::OK_FOR_SESSION_ONLY) - content_setting = CONTENT_SETTING_ALLOW; - host_content_settings_map_->SetContentSetting( - host, CONTENT_SETTINGS_TYPE_COOKIES, content_setting); - } - ChromeThread::PostTask( ChromeThread::IO, FROM_HERE, NewRunnableMethod(this, &ChromeCookiePolicy::DidPromptForSetCookie, - host, policy, remember)); + host, policy)); return; } diff --git a/chrome/browser/net/chrome_cookie_policy.h b/chrome/browser/net/chrome_cookie_policy.h index ae60764..92afcdb 100644 --- a/chrome/browser/net/chrome_cookie_policy.h +++ b/chrome/browser/net/chrome_cookie_policy.h @@ -68,8 +68,7 @@ class ChromeCookiePolicy int CheckPolicy(const GURL& url) const; void PromptForSetCookie(const GURL& url, const std::string& cookie_line); - void DidPromptForSetCookie(const std::string& host, int result, - bool remember); + void DidPromptForSetCookie(const std::string& host, int result); // A map from hostname to callbacks awaiting a cookie policy response. // This map is only accessed on the IO thread. diff --git a/chrome/browser/renderer_host/database_permission_request.cc b/chrome/browser/renderer_host/database_permission_request.cc index 29030de..9d96d0d 100644 --- a/chrome/browser/renderer_host/database_permission_request.cc +++ b/chrome/browser/renderer_host/database_permission_request.cc @@ -41,13 +41,13 @@ void DatabasePermissionRequest::RequestPermission() { ContentSetting setting = host_content_settings_map_->GetContentSetting( url_, CONTENT_SETTINGS_TYPE_COOKIES); if (setting != CONTENT_SETTING_ASK) { - SendResponse(setting, false); + SendResponse(setting); return; } Browser* browser = BrowserList::GetLastActive(); if (!browser || !browser->GetSelectedTabContents()) { - BlockSiteData(false); + BlockSiteData(); return; } @@ -55,30 +55,23 @@ void DatabasePermissionRequest::RequestPermission() { self_ref_ = this; // Will call either AllowSiteData or BlockSiteData which will NULL out our // self reference. - RunDatabasePrompt(browser->GetSelectedTabContents(), url_, - database_name_, this); + RunDatabasePrompt(browser->GetSelectedTabContents(), + host_content_settings_map_, url_, database_name_, this); #else // TODO(jorlow): Enable prompting for other ports. - BlockSiteData(false); + BlockSiteData(); #endif } -void DatabasePermissionRequest::AllowSiteData(bool remember, - bool session_expire) { - SendResponse(CONTENT_SETTING_ALLOW, remember); +void DatabasePermissionRequest::AllowSiteData(bool session_expire) { + SendResponse(CONTENT_SETTING_ALLOW); } -void DatabasePermissionRequest::BlockSiteData(bool remember) { - SendResponse(CONTENT_SETTING_BLOCK, remember); +void DatabasePermissionRequest::BlockSiteData() { + SendResponse(CONTENT_SETTING_BLOCK); } -void DatabasePermissionRequest::SendResponse(ContentSetting content_setting, - bool remember) { - if (remember) { - host_content_settings_map_->SetContentSetting( - url_.host(), CONTENT_SETTINGS_TYPE_COOKIES, content_setting); - } - +void DatabasePermissionRequest::SendResponse(ContentSetting content_setting) { if (content_setting == CONTENT_SETTING_ALLOW) { ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, on_allow_.release()); } else { diff --git a/chrome/browser/renderer_host/database_permission_request.h b/chrome/browser/renderer_host/database_permission_request.h index 5cf391c..8b3f033 100644 --- a/chrome/browser/renderer_host/database_permission_request.h +++ b/chrome/browser/renderer_host/database_permission_request.h @@ -34,11 +34,11 @@ class DatabasePermissionRequest void RequestPermission(); // CookiesPromptViewDelegate methods: - virtual void AllowSiteData(bool remember, bool session_expire); - virtual void BlockSiteData(bool remember); + virtual void AllowSiteData(bool session_expire); + virtual void BlockSiteData(); private: - void SendResponse(ContentSetting content_setting, bool remember); + void SendResponse(ContentSetting content_setting); // The URL to get permission for. const GURL url_; diff --git a/chrome/browser/views/cookie_prompt_view.cc b/chrome/browser/views/cookie_prompt_view.cc index 1870b23..2c01525 100644 --- a/chrome/browser/views/cookie_prompt_view.cc +++ b/chrome/browser/views/cookie_prompt_view.cc @@ -59,7 +59,6 @@ CookiePromptView::CookiePromptView( } CookiePromptView::~CookiePromptView() { - delete parent_; } /////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/views/cookie_prompt_view.h b/chrome/browser/views/cookie_prompt_view.h index 8f588e5..101895e 100644 --- a/chrome/browser/views/cookie_prompt_view.h +++ b/chrome/browser/views/cookie_prompt_view.h @@ -109,7 +109,7 @@ class CookiePromptView : public views::View, std::wstring title_; // A pointer to the AppModalDialog that created us. We own this. - CookiePromptModalDialog* parent_; + scoped_ptr<CookiePromptModalDialog> parent_; gfx::NativeWindow root_window_; |