summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-08 21:10:55 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-08 21:10:55 +0000
commit45134197a411fd9e02986c9e11d7b6d876891f23 (patch)
treec46c08306d7424b3a607ca0d06b2742d7e879c68 /chrome
parent7d74aaab9390a7502dac835ddcd2a5175224702e (diff)
downloadchromium_src-45134197a411fd9e02986c9e11d7b6d876891f23.zip
chromium_src-45134197a411fd9e02986c9e11d7b6d876891f23.tar.gz
chromium_src-45134197a411fd9e02986c9e11d7b6d876891f23.tar.bz2
Show an app modal dialog when the cookie policy is ASK.
This hooks up the dialog for cookies and localstorage. It also includes support for remembering the decision, and in the case of cookies, support is added for forcing a cookie to be a stored as a session cookie. BUG=34625,34572 Review URL: http://codereview.chromium.org/583004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38393 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/cookie_modal_dialog.cc5
-rw-r--r--chrome/browser/cookie_modal_dialog.h6
-rw-r--r--chrome/browser/cookie_modal_dialog_views.cc2
-rw-r--r--chrome/browser/in_process_webkit/dom_storage_area.cc12
-rw-r--r--chrome/browser/in_process_webkit/dom_storage_permission_request.cc73
-rw-r--r--chrome/browser/in_process_webkit/dom_storage_permission_request.h31
-rw-r--r--chrome/browser/message_box_handler.cc4
-rw-r--r--chrome/browser/message_box_handler.h4
-rw-r--r--chrome/browser/net/chrome_cookie_policy.cc159
-rw-r--r--chrome/browser/net/chrome_cookie_policy.h29
-rw-r--r--chrome/browser/views/cookie_info_view.cc49
-rw-r--r--chrome/browser/views/cookie_info_view.h4
-rw-r--r--chrome/browser/views/cookie_prompt_view.cc66
-rw-r--r--chrome/browser/views/cookie_prompt_view.h9
14 files changed, 303 insertions, 150 deletions
diff --git a/chrome/browser/cookie_modal_dialog.cc b/chrome/browser/cookie_modal_dialog.cc
index c6ccdc1..eea617d 100644
--- a/chrome/browser/cookie_modal_dialog.cc
+++ b/chrome/browser/cookie_modal_dialog.cc
@@ -5,15 +5,14 @@
#include "chrome/browser/cookie_modal_dialog.h"
#include "chrome/browser/views/cookie_prompt_view.h"
-#include "googleurl/src/gurl.h"
CookiePromptModalDialog::CookiePromptModalDialog(
TabContents* tab_contents,
- const GURL& url,
+ const std::string& host,
const std::string& cookie_line,
CookiePromptModalDialogDelegate* delegate)
: AppModalDialog(tab_contents, std::wstring()),
- url_(url),
+ host_(host),
cookie_line_(cookie_line),
cookie_ui_(true),
delegate_(delegate) {
diff --git a/chrome/browser/cookie_modal_dialog.h b/chrome/browser/cookie_modal_dialog.h
index 390e6137..df70f0a 100644
--- a/chrome/browser/cookie_modal_dialog.h
+++ b/chrome/browser/cookie_modal_dialog.h
@@ -20,7 +20,7 @@ class CookiePromptModalDialog : public AppModalDialog {
// A union of data necessary to determine the type of message box to
// show.
CookiePromptModalDialog(TabContents* tab_contents,
- const GURL& url,
+ const std::string& host,
const std::string& cookie_line,
CookiePromptModalDialogDelegate* delegate);
CookiePromptModalDialog(
@@ -42,8 +42,8 @@ class CookiePromptModalDialog : public AppModalDialog {
#endif
private:
- // Cookie url.
- GURL url_;
+ // Cookie host.
+ std::string host_;
// Cookie to display.
std::string cookie_line_;
diff --git a/chrome/browser/cookie_modal_dialog_views.cc b/chrome/browser/cookie_modal_dialog_views.cc
index 4324059..1cf3ac5 100644
--- a/chrome/browser/cookie_modal_dialog_views.cc
+++ b/chrome/browser/cookie_modal_dialog_views.cc
@@ -43,7 +43,7 @@ NativeDialog CookiePromptModalDialog::CreateNativeDialog() {
return new CookiePromptView(this,
tab_contents_->GetMessageBoxRootWindow(),
tab_contents_->profile(),
- url_, cookie_line_, delegate_);
+ host_, cookie_line_, delegate_);
}
return new CookiePromptView(this,
tab_contents_->GetMessageBoxRootWindow(),
diff --git a/chrome/browser/in_process_webkit/dom_storage_area.cc b/chrome/browser/in_process_webkit/dom_storage_area.cc
index bda59cf..e2a4549 100644
--- a/chrome/browser/in_process_webkit/dom_storage_area.cc
+++ b/chrome/browser/in_process_webkit/dom_storage_area.cc
@@ -1,6 +1,6 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved. Use of this
-// source code is governed by a BSD-style license that can be found in the
-// LICENSE file.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include "chrome/browser/in_process_webkit/dom_storage_area.h"
@@ -132,11 +132,11 @@ bool DOMStorageArea::CheckContentSetting() {
last_modified = file_info.last_modified;
}
DOMStoragePermissionRequest request(host_, file_exists, size,
- last_modified);
- // TODO(jorlow/darin): Do something useful instead of calling DoSomething.
+ last_modified,
+ host_content_settings_map_);
ChromeThread::PostTask(
ChromeThread::UI, FROM_HERE,
- NewRunnableFunction(&DOMStoragePermissionRequest::DoSomething,
+ NewRunnableFunction(&DOMStoragePermissionRequest::PromptUser,
&request));
content_setting = request.WaitOnResponse();
}
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 05635aa..3fd0045 100644
--- a/chrome/browser/in_process_webkit/dom_storage_permission_request.cc
+++ b/chrome/browser/in_process_webkit/dom_storage_permission_request.cc
@@ -1,19 +1,24 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved. Use of this
-// source code is governed by a BSD-style license that can be found in the
-// LICENSE file.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include "chrome/browser/in_process_webkit/dom_storage_permission_request.h"
+#include "chrome/browser/browser_list.h"
+#include "chrome/browser/message_box_handler.h"
+
DOMStoragePermissionRequest::DOMStoragePermissionRequest(
const std::string& host,
bool file_exists,
int64 size,
- const base::Time last_modified)
+ base::Time last_modified,
+ HostContentSettingsMap* settings)
: host_(host),
file_exists_(file_exists),
size_(size),
last_modified_(last_modified),
- event_(true, false) { // manual reset, not initially signaled
+ event_(true, false), // manual reset, not initially signaled
+ host_content_settings_map_(settings) {
}
ContentSetting DOMStoragePermissionRequest::WaitOnResponse() {
@@ -21,15 +26,63 @@ ContentSetting DOMStoragePermissionRequest::WaitOnResponse() {
return response_content_setting_;
}
-void DOMStoragePermissionRequest::SendResponse(ContentSetting content_setting) {
+void DOMStoragePermissionRequest::SendResponse(ContentSetting content_setting,
+ bool remember) {
response_content_setting_ = content_setting;
+ if (remember) {
+ host_content_settings_map_->SetContentSetting(
+ host_, CONTENT_SETTINGS_TYPE_COOKIES, content_setting);
+ }
event_.Signal();
}
// static
-void DOMStoragePermissionRequest::DoSomething(
+void DOMStoragePermissionRequest::PromptUser(
DOMStoragePermissionRequest *dom_storage_permission_request) {
- // TODO(jorlow/darin): This function is just a placeholder until we work out
- // exactly what needs to happen here.
- dom_storage_permission_request->SendResponse(CONTENT_SETTING_BLOCK);
+ 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->host(),
+ CONTENT_SETTINGS_TYPE_COOKIES);
+ if (setting != CONTENT_SETTING_ASK) {
+ dom_storage_permission_request->SendResponse(setting, false);
+ return;
+ }
+
+ Browser* browser = BrowserList::GetLastActive();
+ if (!browser || !browser->GetSelectedTabContents()) {
+ dom_storage_permission_request->SendResponse(CONTENT_SETTING_BLOCK, false);
+ return;
+ }
+
+#if defined(OS_WIN)
+ // TODO(darin): It seems like it would be interesting if the dialog actually
+ // showed the name and value being stored (as is done for cookies).
+ RunLocalStoragePrompt(browser->GetSelectedTabContents(),
+ BrowsingDataLocalStorageHelper::LocalStorageInfo(
+ std::string(),
+ dom_storage_permission_request->host(),
+ -1,
+ std::string(),
+ dom_storage_permission_request->host(),
+ FilePath(),
+ dom_storage_permission_request->size(),
+ dom_storage_permission_request->last_modified()),
+ dom_storage_permission_request);
+#else
+ // TODO(darin): Enable prompting for other ports.
+ dom_storage_permission_request->SendResponse(CONTENT_SETTING_BLOCK, false);
+#endif
+}
+
+void DOMStoragePermissionRequest::AllowSiteData(bool remember,
+ bool session_expire) {
+ // The session_expire parameter is not relevant.
+ SendResponse(CONTENT_SETTING_ALLOW, remember);
+}
+
+void DOMStoragePermissionRequest::BlockSiteData(bool remember) {
+ SendResponse(CONTENT_SETTING_BLOCK, remember);
}
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 362cf52..d84ed09 100644
--- a/chrome/browser/in_process_webkit/dom_storage_permission_request.h
+++ b/chrome/browser/in_process_webkit/dom_storage_permission_request.h
@@ -1,35 +1,44 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved. Use of this
-// source code is governed by a BSD-style license that can be found in the
-// LICENSE file.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#ifndef CHROME_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_PERMISSION_REQUEST_H_
#define CHROME_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_PERMISSION_REQUEST_H_
#include <string>
+#include "base/ref_counted.h"
#include "base/time.h"
#include "base/waitable_event.h"
+#include "chrome/browser/host_content_settings_map.h"
+#include "chrome/browser/cookie_prompt_modal_dialog_delegate.h"
#include "chrome/common/content_settings.h"
// This class is used to request content setting related permission for local
// storage. It should only be used for one such event and then discarded.
-class DOMStoragePermissionRequest {
+class DOMStoragePermissionRequest : public CookiePromptModalDialogDelegate {
public:
DOMStoragePermissionRequest(const std::string& host,
- bool file_exists_,
- int64 size,
- const base::Time last_modified);
+ bool file_exists,
+ int64 size,
+ base::Time last_modified,
+ HostContentSettingsMap* settings);
+
ContentSetting WaitOnResponse();
- void SendResponse(ContentSetting content_setting);
+ void SendResponse(ContentSetting content_setting, bool remember);
const std::string& host() const { return host_; }
bool file_exists() const { return file_exists_; }
int64 size() const { return size_; }
const base::Time last_modified() const { return last_modified_; }
- // Just an example.
- static void DoSomething(DOMStoragePermissionRequest *request);
+ // Called on the UI thread.
+ static void PromptUser(DOMStoragePermissionRequest *request);
+
+ // CookiesPromptViewDelegate methods:
+ virtual void AllowSiteData(bool remember, bool session_expire);
+ virtual void BlockSiteData(bool remember);
private:
// The host we need to get permission for.
@@ -50,6 +59,8 @@ class DOMStoragePermissionRequest {
// One time use. Never reset.
base::WaitableEvent event_;
+ scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
+
DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStoragePermissionRequest);
};
diff --git a/chrome/browser/message_box_handler.cc b/chrome/browser/message_box_handler.cc
index 3e1793c..b1c33a7 100644
--- a/chrome/browser/message_box_handler.cc
+++ b/chrome/browser/message_box_handler.cc
@@ -60,11 +60,11 @@ void RunBeforeUnloadDialog(TabContents* tab_contents,
#if defined(OS_WIN)
void RunCookiePrompt(TabContents* tab_contents,
- const GURL& url,
+ const std::string& host,
const std::string& cookie_line,
CookiePromptModalDialogDelegate* delegate) {
Singleton<AppModalDialogQueue>()->AddDialog(
- new CookiePromptModalDialog(tab_contents, url, cookie_line, delegate));
+ new CookiePromptModalDialog(tab_contents, host, cookie_line, delegate));
}
diff --git a/chrome/browser/message_box_handler.h b/chrome/browser/message_box_handler.h
index d7382bb..04df1f8 100644
--- a/chrome/browser/message_box_handler.h
+++ b/chrome/browser/message_box_handler.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -45,7 +45,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,
- const GURL& url,
+ const std::string& host,
const std::string& cookie_line,
CookiePromptModalDialogDelegate* delegate);
diff --git a/chrome/browser/net/chrome_cookie_policy.cc b/chrome/browser/net/chrome_cookie_policy.cc
index 3e924d1..a72d916 100644
--- a/chrome/browser/net/chrome_cookie_policy.cc
+++ b/chrome/browser/net/chrome_cookie_policy.cc
@@ -5,8 +5,11 @@
#include "chrome/browser/net/chrome_cookie_policy.h"
#include "base/string_util.h"
+#include "chrome/browser/browser_list.h"
#include "chrome/browser/chrome_thread.h"
+#include "chrome/browser/cookie_prompt_modal_dialog_delegate.h"
#include "chrome/browser/host_content_settings_map.h"
+#include "chrome/browser/message_box_handler.h"
#include "googleurl/src/gurl.h"
#include "net/base/net_errors.h"
#include "net/base/static_cookie_policy.h"
@@ -16,6 +19,40 @@
// sign of trouble anyways.
static const size_t kMaxCompletionsPerHost = 10000;
+// ----------------------------------------------------------------------------
+
+class ChromeCookiePolicy::PromptDelegate
+ : public CookiePromptModalDialogDelegate {
+ public:
+ PromptDelegate(ChromeCookiePolicy* cookie_policy, const std::string& host)
+ : cookie_policy_(cookie_policy),
+ host_(host) {
+ }
+
+ // CookiesPromptViewDelegate methods:
+ virtual void AllowSiteData(bool remember, bool session_expire);
+ virtual void BlockSiteData(bool remember);
+
+ private:
+ scoped_refptr<ChromeCookiePolicy> cookie_policy_;
+ std::string host_;
+};
+
+void ChromeCookiePolicy::PromptDelegate::AllowSiteData(bool remember,
+ bool session_expire) {
+ int policy = net::OK;
+ if (session_expire)
+ policy = net::OK_FOR_SESSION_ONLY;
+ cookie_policy_->DidPromptForSetCookie(host_, policy, remember);
+}
+
+void ChromeCookiePolicy::PromptDelegate::BlockSiteData(bool remember) {
+ cookie_policy_->DidPromptForSetCookie(host_, net::ERR_ACCESS_DENIED,
+ remember);
+}
+
+// ----------------------------------------------------------------------------
+
ChromeCookiePolicy::ChromeCookiePolicy(HostContentSettingsMap* map)
: host_content_settings_map_(map) {
}
@@ -27,6 +64,8 @@ ChromeCookiePolicy::~ChromeCookiePolicy() {
int ChromeCookiePolicy::CanGetCookies(const GURL& url,
const GURL& first_party,
net::CompletionCallback* callback) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
+
if (host_content_settings_map_->BlockThirdPartyCookies()) {
net::StaticCookiePolicy policy(
net::StaticCookiePolicy::BLOCK_THIRD_PARTY_COOKIES);
@@ -37,36 +76,33 @@ int ChromeCookiePolicy::CanGetCookies(const GURL& url,
const std::string& host = url.host();
- ContentSetting setting = host_content_settings_map_->GetContentSetting(
- host, CONTENT_SETTINGS_TYPE_COOKIES);
- if (setting == CONTENT_SETTING_BLOCK)
- return net::ERR_ACCESS_DENIED;
- if (setting == CONTENT_SETTING_ALLOW)
- return net::OK;
+ int policy = CheckPolicy(host);
+ if (policy != net::ERR_IO_PENDING)
+ return policy;
DCHECK(callback);
// If we are currently prompting the user for a 'set-cookie' matching this
// host, then we need to defer reading cookies.
-
HostCompletionsMap::iterator it = host_completions_map_.find(host);
- if (it == host_completions_map_.end())
- return net::OK;
-
- if (it->second.size() >= kMaxCompletionsPerHost) {
+ if (it == host_completions_map_.end()) {
+ policy = net::OK;
+ } else if (it->second.size() >= kMaxCompletionsPerHost) {
LOG(ERROR) << "Would exceed kMaxCompletionsPerHost";
- return net::ERR_ACCESS_DENIED;
+ policy = net::ERR_ACCESS_DENIED;
+ } else {
+ it->second.push_back(Completion::ForGetCookies(callback));
+ policy = net::ERR_IO_PENDING;
}
-
- it->second.push_back(Completion::ForGetCookies(callback));
-
- return net::ERR_IO_PENDING;
+ return policy;
}
int ChromeCookiePolicy::CanSetCookie(const GURL& url,
const GURL& first_party,
const std::string& cookie_line,
net::CompletionCallback* callback) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
+
if (host_content_settings_map_->BlockThirdPartyCookies()) {
net::StaticCookiePolicy policy(
net::StaticCookiePolicy::BLOCK_THIRD_PARTY_COOKIES);
@@ -77,12 +113,9 @@ int ChromeCookiePolicy::CanSetCookie(const GURL& url,
const std::string& host = url.host();
- ContentSetting setting = host_content_settings_map_->GetContentSetting(
- host, CONTENT_SETTINGS_TYPE_COOKIES);
- if (setting == CONTENT_SETTING_BLOCK)
- return net::ERR_ACCESS_DENIED;
- if (setting == CONTENT_SETTING_ALLOW)
- return net::OK;
+ int policy = CheckPolicy(host);
+ if (policy != net::ERR_IO_PENDING)
+ return policy;
DCHECK(callback);
@@ -92,13 +125,56 @@ int ChromeCookiePolicy::CanSetCookie(const GURL& url,
if (completions.size() >= kMaxCompletionsPerHost) {
LOG(ERROR) << "Would exceed kMaxCompletionsPerHost";
+ policy = net::ERR_ACCESS_DENIED;
+ } else {
+ completions.push_back(Completion::ForSetCookie(callback));
+ policy = net::ERR_IO_PENDING;
+ }
+
+ PromptForSetCookie(host, cookie_line);
+ return policy;
+}
+
+int ChromeCookiePolicy::CheckPolicy(const std::string& host) const {
+ ContentSetting setting = host_content_settings_map_->GetContentSetting(
+ host, CONTENT_SETTINGS_TYPE_COOKIES);
+ if (setting == CONTENT_SETTING_BLOCK)
return net::ERR_ACCESS_DENIED;
+ if (setting == CONTENT_SETTING_ALLOW)
+ return net::OK;
+ return net::ERR_IO_PENDING; // Need to prompt.
+}
+
+void ChromeCookiePolicy::ShowNextPrompt() {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
+
+ if (prompt_queue_.empty())
+ return;
+ PromptData data = prompt_queue_.front();
+
+ // The policy may have changed (due to the "remember" option).
+ int policy = CheckPolicy(data.host);
+ if (policy != net::ERR_IO_PENDING) {
+ DidPromptForSetCookie(data.host, policy, false);
+ return;
}
- completions.push_back(Completion::ForSetCookie(callback));
+ // Show the prompt on top of the current tab.
+ Browser* browser = BrowserList::GetLastActive();
+ if (!browser || !browser->GetSelectedTabContents()) {
+ DidPromptForSetCookie(data.host, net::ERR_ACCESS_DENIED, false);
+ return;
+ }
- PromptForSetCookie(host, cookie_line);
- return net::ERR_IO_PENDING;
+#if defined(OS_WIN)
+ RunCookiePrompt(browser->GetSelectedTabContents(),
+ data.host,
+ data.cookie_line,
+ new PromptDelegate(this, data.host));
+#else
+ // TODO(darin): Enable prompting for other ports.
+ DidPromptForSetCookie(data.host, net::ERR_ACCESS_DENIED, false);
+#endif
}
void ChromeCookiePolicy::PromptForSetCookie(const std::string &host,
@@ -111,27 +187,38 @@ void ChromeCookiePolicy::PromptForSetCookie(const std::string &host,
return;
}
- // TODO(darin): Prompt user!
-#if 0
- MessageBox(NULL,
- UTF8ToWide(cookie_line).c_str(),
- UTF8ToWide(host).c_str(),
- MB_OK);
-#endif
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
- DidPromptForSetCookie(host, net::OK);
+ bool show_now = prompt_queue_.empty();
+ prompt_queue_.push(PromptData(host, cookie_line));
+ if (show_now)
+ ShowNextPrompt();
}
void ChromeCookiePolicy::DidPromptForSetCookie(const std::string &host,
- int result) {
+ int policy, bool remember) {
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, result));
+ host, policy, remember));
+
+ prompt_queue_.pop();
+ ShowNextPrompt();
return;
}
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
+
// Notify all callbacks, starting with the first until we hit another that
// is for a 'set-cookie'.
HostCompletionsMap::iterator it = host_completions_map_.find(host);
@@ -158,5 +245,5 @@ void ChromeCookiePolicy::DidPromptForSetCookie(const std::string &host,
host_completions_map_.erase(it);
for (size_t j = 0; j < callbacks.size(); ++j)
- callbacks[j]->Run(result);
+ callbacks[j]->Run(policy);
}
diff --git a/chrome/browser/net/chrome_cookie_policy.h b/chrome/browser/net/chrome_cookie_policy.h
index 0d536f8..6b4d675 100644
--- a/chrome/browser/net/chrome_cookie_policy.h
+++ b/chrome/browser/net/chrome_cookie_policy.h
@@ -6,6 +6,8 @@
#define CHROME_BROWSER_NET_CHROME_COOKIE_POLICY_H_
#include <map>
+#include <queue>
+#include <string>
#include <vector>
#include "base/ref_counted.h"
@@ -35,6 +37,9 @@ class ChromeCookiePolicy
net::CompletionCallback* callback);
private:
+ class PromptDelegate;
+ friend class PromptDelegate;
+
class Completion {
public:
static Completion ForSetCookie(net::CompletionCallback* callback) {
@@ -57,17 +62,37 @@ class ChromeCookiePolicy
bool is_set_cookie_request_;
net::CompletionCallback* callback_;
};
-
typedef std::vector<Completion> Completions;
typedef std::map<std::string, Completions> HostCompletionsMap;
+ struct PromptData {
+ std::string host;
+ std::string cookie_line;
+
+ PromptData(const std::string& host, const std::string& cookie_line)
+ : host(host),
+ cookie_line(cookie_line) {
+ }
+ };
+ typedef std::queue<PromptData> PromptQueue;
+
+ int CheckPolicy(const std::string& host) const;
+ void ShowNextPrompt();
void PromptForSetCookie(const std::string& host,
const std::string& cookie_line);
- void DidPromptForSetCookie(const std::string& host, int result);
+ void DidPromptForSetCookie(const std::string& host, int result,
+ bool remember);
// A map from hostname to callbacks awaiting a cookie policy response.
+ // 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/views/cookie_info_view.cc b/chrome/browser/views/cookie_info_view.cc
index da51988..2f7970b 100644
--- a/chrome/browser/views/cookie_info_view.cc
+++ b/chrome/browser/views/cookie_info_view.cc
@@ -16,7 +16,6 @@
#include "chrome/browser/profile.h"
#include "grit/generated_resources.h"
#include "grit/locale_settings.h"
-#include "net/base/cookie_monster.h"
#include "views/border.h"
#include "views/grid_layout.h"
#include "views/controls/label.h"
@@ -90,38 +89,22 @@ void CookieInfoView::SetCookie(
}
void CookieInfoView::SetCookieString(
- const std::string& domain,
- const net::CookieMonster::ParsedCookie& cookie) {
- name_value_field_->SetText(UTF8ToWide(cookie.Name()));
- content_value_field_->SetText(UTF8ToWide(cookie.Value()));
- domain_value_field_->SetText(UTF8ToWide(domain));
- path_value_field_->SetText(UTF8ToWide(cookie.Path()));
- created_value_field_->SetText(
- base::TimeFormatFriendlyDateAndTime(base::Time::Now()));
-
- std::wstring expire_text = cookie.HasExpires() ?
- base::TimeFormatFriendlyDateAndTime(
- net::CookieMonster::ParseCookieTime(cookie.Expires())) :
- l10n_util::GetString(IDS_COOKIES_COOKIE_EXPIRES_SESSION);
-
- if (editable_expiration_date_) {
- expire_combo_values_.clear();
- if (cookie.HasExpires())
- expire_combo_values_.push_back(expire_text);
- expire_combo_values_.push_back(
- l10n_util::GetString(IDS_COOKIES_COOKIE_EXPIRES_SESSION));
- expires_value_combobox_->ModelChanged();
- expires_value_combobox_->SetSelectedItem(0);
- expires_value_combobox_->SetEnabled(true);
- } else {
- expires_value_field_->SetText(expire_text);
- }
-
- send_for_value_field_->SetText(cookie.IsSecure() ?
- l10n_util::GetString(IDS_COOKIES_COOKIE_SENDFOR_SECURE) :
- l10n_util::GetString(IDS_COOKIES_COOKIE_SENDFOR_ANY));
- EnableCookieDisplay(true);
- Layout();
+ const std::string& host,
+ const std::string& cookie_line) {
+ net::CookieMonster::ParsedCookie pc(cookie_line);
+ net::CookieMonster::CanonicalCookie cookie(
+ pc.Name(),
+ pc.Value(),
+ pc.Path(),
+ pc.IsSecure(),
+ pc.IsHttpOnly(),
+ base::Time::Now(), // creation time
+ base::Time(), // last access time is unused
+ pc.HasExpires(),
+ pc.HasExpires() ?
+ net::CookieMonster::ParseCookieTime(pc.Expires()) :
+ base::Time());
+ SetCookie(pc.HasDomain() ? pc.Domain() : host, cookie);
}
diff --git a/chrome/browser/views/cookie_info_view.h b/chrome/browser/views/cookie_info_view.h
index b0be231..f793d95 100644
--- a/chrome/browser/views/cookie_info_view.h
+++ b/chrome/browser/views/cookie_info_view.h
@@ -48,8 +48,8 @@ class CookieInfoView : public views::View,
const net::CookieMonster::CanonicalCookie& cookie_node);
// Update the display from the specified cookie string.
- void SetCookieString(const std::string& domain,
- const net::CookieMonster::ParsedCookie& cookie);
+ void SetCookieString(const std::string& host,
+ const std::string& cookie_line);
// Clears the cookie display to indicate that no or multiple cookies are
// selected.
diff --git a/chrome/browser/views/cookie_prompt_view.cc b/chrome/browser/views/cookie_prompt_view.cc
index d08fb49..9a69ad9 100644
--- a/chrome/browser/views/cookie_prompt_view.cc
+++ b/chrome/browser/views/cookie_prompt_view.cc
@@ -34,33 +34,33 @@ static const int kCookiePromptViewInsetSize = 5;
// CookiePromptView, public:
CookiePromptView::CookiePromptView(
- CookiePromptModalDialog* parent,
- gfx::NativeWindow root_window,
- Profile* profile,
- const GURL& url,
- const std::string& cookie_line,
- CookiePromptModalDialogDelegate* delegate)
- : parent_(parent),
- root_window_(root_window),
- profile_(profile),
- delegate_(delegate) {
- cookie_ui_ = true;
- net::CookieMonster::ParsedCookie cookie(cookie_line);
- InitializeViewResources(cookie.HasDomain() ? cookie.Domain() : url.host());
+ CookiePromptModalDialog* parent,
+ gfx::NativeWindow root_window,
+ Profile* profile,
+ const std::string& host,
+ const std::string& cookie_line,
+ CookiePromptModalDialogDelegate* delegate)
+ : cookie_ui_(true),
+ parent_(parent),
+ root_window_(root_window),
+ profile_(profile),
+ cookie_line_(cookie_line),
+ delegate_(delegate) {
+ InitializeViewResources(host);
}
CookiePromptView::CookiePromptView(
- CookiePromptModalDialog* parent,
- gfx::NativeWindow root_window,
- Profile* profile,
- const BrowsingDataLocalStorageHelper::LocalStorageInfo& storage_info,
- CookiePromptModalDialogDelegate* delegate)
- : parent_(parent),
- root_window_(root_window),
- profile_(profile),
- local_storage_info_(storage_info),
- delegate_(delegate) {
- cookie_ui_ = false;
+ CookiePromptModalDialog* parent,
+ gfx::NativeWindow root_window,
+ Profile* profile,
+ const BrowsingDataLocalStorageHelper::LocalStorageInfo& storage_info,
+ CookiePromptModalDialogDelegate* delegate)
+ : cookie_ui_(false),
+ parent_(parent),
+ root_window_(root_window),
+ profile_(profile),
+ local_storage_info_(storage_info),
+ delegate_(delegate) {
InitializeViewResources(storage_info.host);
}
@@ -165,12 +165,13 @@ CookiePromptView::CookiePromptView(Profile* profile,
}
void CookiePromptView::Init() {
+ std::wstring display_host = UTF8ToWide(host_);
views::Label* description_label = new views::Label(l10n_util::GetStringF(
cookie_ui_ ? IDS_COOKIE_ALERT_LABEL : IDS_DATA_ALERT_LABEL,
- display_domain_));
+ display_host));
int radio_group_id = 0;
remember_radio_ = new views::RadioButton(
- l10n_util::GetStringF(IDS_COOKIE_ALERT_REMEMBER_RADIO, display_domain_),
+ l10n_util::GetStringF(IDS_COOKIE_ALERT_REMEMBER_RADIO, display_host),
radio_group_id);
remember_radio_->set_listener(this);
ask_radio_ = new views::RadioButton(
@@ -263,7 +264,7 @@ void CookiePromptView::Init() {
layout->AddView(cookie_info_view, 1, 1, GridLayout::FILL,
GridLayout::CENTER);
- cookie_info_view->SetCookieString(domain_, cookie_line_);
+ cookie_info_view->SetCookieString(host_, cookie_line_);
info_view_ = cookie_info_view;
} else {
LocalStorageInfoView* local_storage_info_view = new LocalStorageInfoView();
@@ -296,14 +297,11 @@ void CookiePromptView::ToggleDetailsViewExpand() {
Layout();
}
-void CookiePromptView::InitializeViewResources(const std::string& domain) {
- domain_ = domain;
- std::string display_domain = domain;
- if (!domain.empty() && domain[0] == '.')
- display_domain = display_domain.substr(1);
- display_domain_ = UTF8ToWide(display_domain);
+void CookiePromptView::InitializeViewResources(const std::string& host) {
+ DCHECK(host.empty() || host[0] != '.');
+ host_ = host;
title_ = l10n_util::GetStringF(
cookie_ui_ ? IDS_COOKIE_ALERT_TITLE : IDS_DATA_ALERT_TITLE,
- display_domain_);
+ UTF8ToWide(host_));
}
diff --git a/chrome/browser/views/cookie_prompt_view.h b/chrome/browser/views/cookie_prompt_view.h
index 756687e..14560bc 100644
--- a/chrome/browser/views/cookie_prompt_view.h
+++ b/chrome/browser/views/cookie_prompt_view.h
@@ -42,7 +42,7 @@ class CookiePromptView : public views::View,
CookiePromptModalDialog* parent,
gfx::NativeWindow root_window,
Profile* profile,
- const GURL& url,
+ const std::string& host,
const std::string& cookie_line,
CookiePromptModalDialogDelegate* delegate);
@@ -135,11 +135,8 @@ class CookiePromptView : public views::View,
// The Profile for which Cookies are displayed.
Profile* profile_;
- // Cookie / local storage domain.
- std::string domain_;
-
- // Domain name formatted for displaying (removed leading '.').
- std::wstring display_domain_;
+ // Cookie / local storage host.
+ std::string host_;
// Displayed cookie. Only used when |cookie_ui_| is true.
std::string cookie_line_;