summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorjorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-17 21:35:08 +0000
committerjorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-17 21:35:08 +0000
commit37e050cf1d493e210ac6035c1ff45ccb1784c69b (patch)
tree4f4fc7766e17084d44eff9ca637a78f950c43ddb /chrome
parentf2e5f9dbec4e957fbf709afefd49813b5515b846 (diff)
downloadchromium_src-37e050cf1d493e210ac6035c1ff45ccb1784c69b.zip
chromium_src-37e050cf1d493e210ac6035c1ff45ccb1784c69b.tar.gz
chromium_src-37e050cf1d493e210ac6035c1ff45ccb1784c69b.tar.bz2
When we're initializing the modal dialog box which asks whether the page has permission to access a "cookie", double check that the value has not since been set. If it has, close the window before it's even shown.
This is a stop-gap solution. We should probably come up with something more elegent long term. TEST=Go to a page that starts a database transaction and immediately sets a local storage value. You should get one prompt instead of 2. BUG=36006 Review URL: http://codereview.chromium.org/619009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39270 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/cookie_modal_dialog.h3
-rw-r--r--chrome/browser/net/chrome_cookie_policy.cc44
-rw-r--r--chrome/browser/net/chrome_cookie_policy.h18
-rw-r--r--chrome/browser/renderer_host/database_permission_request.cc9
-rw-r--r--chrome/browser/views/cookie_prompt_view.cc20
5 files changed, 40 insertions, 54 deletions
diff --git a/chrome/browser/cookie_modal_dialog.h b/chrome/browser/cookie_modal_dialog.h
index 6410c32..c5cb8bd 100644
--- a/chrome/browser/cookie_modal_dialog.h
+++ b/chrome/browser/cookie_modal_dialog.h
@@ -55,8 +55,9 @@ class CookiePromptModalDialog : public AppModalDialog {
const string16& local_storage_key() const { return local_storage_key_; }
const string16& local_storage_value() const { return local_storage_value_; }
const string16& database_name() const { return database_name_; }
+ TabContents* tab_contents() const { return tab_contents_; }
- // Send a response to our delegate.
+ // Implement CookiePromptModalDialogDelegate.
void AllowSiteData(bool remember, bool session_expire);
void BlockSiteData(bool remember);
diff --git a/chrome/browser/net/chrome_cookie_policy.cc b/chrome/browser/net/chrome_cookie_policy.cc
index 6646af3..b825257 100644
--- a/chrome/browser/net/chrome_cookie_policy.cc
+++ b/chrome/browser/net/chrome_cookie_policy.cc
@@ -140,16 +140,21 @@ int ChromeCookiePolicy::CheckPolicy(const GURL& url) const {
return net::ERR_IO_PENDING; // Need to prompt.
}
-void ChromeCookiePolicy::ShowNextPrompt() {
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
-
- if (prompt_queue_.empty())
+void ChromeCookiePolicy::PromptForSetCookie(const GURL& url,
+ const std::string& cookie_line) {
+ if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) {
+ ChromeThread::PostTask(
+ ChromeThread::UI, FROM_HERE,
+ NewRunnableMethod(this, &ChromeCookiePolicy::PromptForSetCookie, url,
+ cookie_line));
return;
- PromptData data = prompt_queue_.front();
- const std::string& host = data.url.host();
+ }
- // The policy may have changed (due to the "remember" option).
- int policy = CheckPolicy(data.url);
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
+ const std::string& host = url.host();
+
+ // The policy may have changed (due to the "remember" option)
+ int policy = CheckPolicy(url);
if (policy != net::ERR_IO_PENDING) {
DidPromptForSetCookie(host, policy, false);
return;
@@ -163,7 +168,7 @@ void ChromeCookiePolicy::ShowNextPrompt() {
}
#if defined(OS_WIN)
- RunCookiePrompt(browser->GetSelectedTabContents(), data.url, data.cookie_line,
+ RunCookiePrompt(browser->GetSelectedTabContents(), url, cookie_line,
new PromptDelegate(this, host));
#else
// TODO(darin): Enable prompting for other ports.
@@ -171,24 +176,6 @@ void ChromeCookiePolicy::ShowNextPrompt() {
#endif
}
-void ChromeCookiePolicy::PromptForSetCookie(const GURL& url,
- const std::string& cookie_line) {
- if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) {
- ChromeThread::PostTask(
- ChromeThread::UI, FROM_HERE,
- NewRunnableMethod(this, &ChromeCookiePolicy::PromptForSetCookie, url,
- cookie_line));
- return;
- }
-
- DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
-
- bool show_now = prompt_queue_.empty();
- prompt_queue_.push(PromptData(url, cookie_line));
- if (show_now)
- ShowNextPrompt();
-}
-
void ChromeCookiePolicy::DidPromptForSetCookie(const std::string& host,
int policy, bool remember) {
if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) {
@@ -205,9 +192,6 @@ void ChromeCookiePolicy::DidPromptForSetCookie(const std::string& host,
ChromeThread::IO, FROM_HERE,
NewRunnableMethod(this, &ChromeCookiePolicy::DidPromptForSetCookie,
host, policy, remember));
-
- prompt_queue_.pop();
- ShowNextPrompt();
return;
}
diff --git a/chrome/browser/net/chrome_cookie_policy.h b/chrome/browser/net/chrome_cookie_policy.h
index 40138a2..ae60764 100644
--- a/chrome/browser/net/chrome_cookie_policy.h
+++ b/chrome/browser/net/chrome_cookie_policy.h
@@ -66,19 +66,7 @@ class ChromeCookiePolicy
typedef std::vector<Completion> Completions;
typedef std::map<std::string, Completions> HostCompletionsMap;
- struct PromptData {
- GURL url;
- std::string cookie_line;
-
- PromptData(const GURL& url, const std::string& cookie_line)
- : url(url),
- cookie_line(cookie_line) {
- }
- };
- typedef std::queue<PromptData> PromptQueue;
-
int CheckPolicy(const GURL& url) const;
- void ShowNextPrompt();
void PromptForSetCookie(const GURL& url, const std::string& cookie_line);
void DidPromptForSetCookie(const std::string& host, int result,
bool remember);
@@ -87,12 +75,6 @@ class ChromeCookiePolicy
// This map is only accessed on the IO thread.
HostCompletionsMap host_completions_map_;
- // A queue of pending prompts. We queue these up here so that before showing
- // the next prompt we can reconsult the HostContentSettingsMap in case
- // settings have changed since the prompt request was placed in the queue.
- // This queue is only accessed on the UI thread.
- PromptQueue prompt_queue_;
-
scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
};
diff --git a/chrome/browser/renderer_host/database_permission_request.cc b/chrome/browser/renderer_host/database_permission_request.cc
index 32fa8e6..29030de 100644
--- a/chrome/browser/renderer_host/database_permission_request.cc
+++ b/chrome/browser/renderer_host/database_permission_request.cc
@@ -90,9 +90,8 @@ void DatabasePermissionRequest::SendResponse(ContentSetting content_setting,
on_allow_.reset();
on_block_.reset();
- // And lastly, release our self ref which may trigger delete. Do the release
- // on a local variable instead of a member variable to avoid reentrancy
- // nastiness if the ref count goes to 0.
- scoped_refptr<DatabasePermissionRequest> self;
- self.swap(self_ref_);
+ // This seems safer than possibly being deleted while in method(s) related to
+ // this object. Any thread will do, but UI is always around and can be
+ // posted without locking, so we'll ask it to do the release.
+ ChromeThread::ReleaseSoon(ChromeThread::UI, FROM_HERE, self_ref_.release());
}
diff --git a/chrome/browser/views/cookie_prompt_view.cc b/chrome/browser/views/cookie_prompt_view.cc
index dcb7a4a..6cc526a 100644
--- a/chrome/browser/views/cookie_prompt_view.cc
+++ b/chrome/browser/views/cookie_prompt_view.cc
@@ -14,7 +14,9 @@
#include "base/string_util.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/cookie_modal_dialog.h"
+#include "chrome/browser/host_content_settings_map.h"
#include "chrome/browser/profile.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/views/browser_dialogs.h"
#include "chrome/browser/views/cookie_info_view.h"
#include "chrome/browser/views/database_open_info_view.h"
@@ -135,6 +137,24 @@ void CookiePromptView::LinkActivated(views::Link* source, int event_flags) {
// CookiePromptView, private:
void CookiePromptView::Init() {
+ // See if there's still a need for this dialog. Self destruct if not.
+ HostContentSettingsMap* host_content_settings_map =
+ parent_->tab_contents()->profile()->GetHostContentSettingsMap();
+ ContentSetting content_setting =
+ host_content_settings_map->GetContentSetting(
+ parent_->origin(), CONTENT_SETTINGS_TYPE_COOKIES);
+ if (content_setting != CONTENT_SETTING_ASK) {
+ if (content_setting == CONTENT_SETTING_ALLOW) {
+ parent_->AllowSiteData(false, false);
+ } else {
+ DCHECK(content_setting == CONTENT_SETTING_BLOCK);
+ parent_->BlockSiteData(false);
+ }
+ signaled_ = true;
+ GetWindow()->Close();
+ return;
+ }
+
CookiePromptModalDialog::DialogType type = parent_->dialog_type();
std::wstring display_host = UTF8ToWide(parent_->origin().host());
views::Label* description_label = new views::Label(l10n_util::GetStringF(