summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-19 20:49:30 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-19 20:49:30 +0000
commitcf9e07811d9d198470ac73a6b84b0f0597854641 (patch)
tree1b50a1ca54cb886bfb908ffb0b5972bec2471fe7 /chrome/browser/views
parent7edf5b5462727c06c0232b541c5db549f176d84a (diff)
downloadchromium_src-cf9e07811d9d198470ac73a6b84b0f0597854641.zip
chromium_src-cf9e07811d9d198470ac73a6b84b0f0597854641.tar.gz
chromium_src-cf9e07811d9d198470ac73a6b84b0f0597854641.tar.bz2
Buttons for the collected cookies dialog to add content exceptions.
BUG=45230 TEST=CollectedCookiesTest.* Review URL: http://codereview.chromium.org/2808053 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52950 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r--chrome/browser/views/collected_cookies_win.cc104
-rw-r--r--chrome/browser/views/collected_cookies_win.h27
2 files changed, 119 insertions, 12 deletions
diff --git a/chrome/browser/views/collected_cookies_win.cc b/chrome/browser/views/collected_cookies_win.cc
index b5e5c3c..1a7f405 100644
--- a/chrome/browser/views/collected_cookies_win.cc
+++ b/chrome/browser/views/collected_cookies_win.cc
@@ -6,12 +6,13 @@
#include "app/l10n_util.h"
#include "chrome/browser/cookies_tree_model.h"
+#include "chrome/browser/profile.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/common/notification_service.h"
#include "grit/generated_resources.h"
#include "grit/locale_settings.h"
#include "views/controls/label.h"
-#include "views/controls/tree/tree_view.h"
+#include "views/controls/button/native_button.h"
#include "views/standard_layout.h"
#include "views/window/window.h"
@@ -32,7 +33,14 @@ void ShowCollectedCookiesDialog(gfx::NativeWindow parent_window,
CollectedCookiesWin::CollectedCookiesWin(gfx::NativeWindow parent_window,
TabContents* tab_contents)
- : tab_contents_(tab_contents) {
+ : tab_contents_(tab_contents),
+ allowed_label_(NULL),
+ blocked_label_(NULL),
+ allowed_cookies_tree_(NULL),
+ blocked_cookies_tree_(NULL),
+ block_allowed_button_(NULL),
+ allow_blocked_button_(NULL),
+ for_session_blocked_button_(NULL) {
TabSpecificContentSettings* content_settings =
tab_contents->GetTabSpecificContentSettings();
registrar_.Add(this, NotificationType::COLLECTED_COOKIES_SHOWN,
@@ -59,6 +67,7 @@ void CollectedCookiesWin::Init() {
content_settings->GetAllowedCookiesTreeModel());
allowed_cookies_tree_ = new views::TreeView();
allowed_cookies_tree_->SetModel(allowed_cookies_tree_model_.get());
+ allowed_cookies_tree_->SetController(this);
allowed_cookies_tree_->SetRootShown(false);
allowed_cookies_tree_->SetEditable(false);
allowed_cookies_tree_->set_lines_at_root(true);
@@ -71,6 +80,7 @@ void CollectedCookiesWin::Init() {
content_settings->GetBlockedCookiesTreeModel());
blocked_cookies_tree_ = new views::TreeView();
blocked_cookies_tree_->SetModel(blocked_cookies_tree_model_.get());
+ blocked_cookies_tree_->SetController(this);
blocked_cookies_tree_->SetRootShown(false);
blocked_cookies_tree_->SetEditable(false);
blocked_cookies_tree_->set_lines_at_root(true);
@@ -86,6 +96,14 @@ void CollectedCookiesWin::Init() {
column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1,
GridLayout::USE_PREF, 0, 0);
+ const int three_columns_layout_id = 1;
+ column_set = layout->AddColumnSet(three_columns_layout_id);
+ column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
+ GridLayout::USE_PREF, 0, 0);
+ column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing);
+ column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
+ GridLayout::USE_PREF, 0, 0);
+
layout->StartRow(0, single_column_layout_id);
layout->AddView(allowed_label_);
@@ -93,6 +111,13 @@ void CollectedCookiesWin::Init() {
layout->StartRow(1, single_column_layout_id);
layout->AddView(
allowed_cookies_tree_, 1, 1, GridLayout::FILL, GridLayout::FILL);
+ layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
+
+ layout->StartRow(0, single_column_layout_id);
+ block_allowed_button_ = new views::NativeButton(
+ this, l10n_util::GetString(IDS_COLLECTED_COOKIES_BLOCK_BUTTON));
+ layout->AddView(
+ block_allowed_button_, 1, 1, GridLayout::LEADING, GridLayout::CENTER);
layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing);
layout->StartRow(0, single_column_layout_id);
@@ -102,10 +127,21 @@ void CollectedCookiesWin::Init() {
layout->StartRow(1, single_column_layout_id);
layout->AddView(
blocked_cookies_tree_, 1, 1, GridLayout::FILL, GridLayout::FILL);
+ layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
+
+ layout->StartRow(0, three_columns_layout_id);
+ allow_blocked_button_ = new views::NativeButton(
+ this, l10n_util::GetString(IDS_COLLECTED_COOKIES_ALLOW_BUTTON));
+ layout->AddView(allow_blocked_button_);
+ for_session_blocked_button_ = new views::NativeButton(
+ this, l10n_util::GetString(IDS_COLLECTED_COOKIES_SESSION_ONLY_BUTTON));
+ layout->AddView(for_session_blocked_button_);
+
+ EnableControls();
}
///////////////////////////////////////////////////////////////////////////////
-// views::DialogDelegate implementation.
+// ConstrainedDialogDelegate implementation.
std::wstring CollectedCookiesWin::GetWindowTitle() const {
return l10n_util::GetString(IDS_COLLECTED_COOKIES_DIALOG_TITLE);
@@ -128,14 +164,32 @@ bool CollectedCookiesWin::Cancel() {
return true;
}
-///////////////////////////////////////////////////////////////////////////////
-// views::WindowDelegate implementation.
-
views::View* CollectedCookiesWin::GetContentsView() {
return this;
}
///////////////////////////////////////////////////////////////////////////////
+// views::ButtonListener implementation.
+
+void CollectedCookiesWin::ButtonPressed(views::Button* sender,
+ const views::Event& event) {
+ if (sender == block_allowed_button_)
+ AddContentException(allowed_cookies_tree_, CONTENT_SETTING_BLOCK);
+ else if (sender == allow_blocked_button_)
+ AddContentException(blocked_cookies_tree_, CONTENT_SETTING_ALLOW);
+ else if (sender == for_session_blocked_button_)
+ AddContentException(blocked_cookies_tree_, CONTENT_SETTING_SESSION_ONLY);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// views::View implementation.
+
+void CollectedCookiesWin::OnTreeViewSelectionChanged(
+ views::TreeView* tree_view) {
+ EnableControls();
+}
+
+///////////////////////////////////////////////////////////////////////////////
// views::View implementation.
gfx::Size CollectedCookiesWin::GetPreferredSize() {
@@ -145,6 +199,44 @@ gfx::Size CollectedCookiesWin::GetPreferredSize() {
}
///////////////////////////////////////////////////////////////////////////////
+// CollectedCookiesWin, private methods.
+
+void CollectedCookiesWin::EnableControls() {
+ bool enable_allowed_buttons = false;
+ TreeModelNode* node = allowed_cookies_tree_->GetSelectedNode();
+ if (node) {
+ CookieTreeNode* cookie_node = static_cast<CookieTreeNode*>(node);
+ if (cookie_node->GetDetailedInfo().node_type ==
+ CookieTreeNode::DetailedInfo::TYPE_ORIGIN) {
+ enable_allowed_buttons = static_cast<CookieTreeOriginNode*>(
+ cookie_node)->CanCreateContentException();
+ }
+ }
+ block_allowed_button_->SetEnabled(enable_allowed_buttons);
+
+ bool enable_blocked_buttons = false;
+ node = blocked_cookies_tree_->GetSelectedNode();
+ if (node) {
+ CookieTreeNode* cookie_node = static_cast<CookieTreeNode*>(node);
+ if (cookie_node->GetDetailedInfo().node_type ==
+ CookieTreeNode::DetailedInfo::TYPE_ORIGIN) {
+ enable_blocked_buttons = static_cast<CookieTreeOriginNode*>(
+ cookie_node)->CanCreateContentException();
+ }
+ }
+ allow_blocked_button_->SetEnabled(enable_blocked_buttons);
+ for_session_blocked_button_->SetEnabled(enable_blocked_buttons);
+}
+
+void CollectedCookiesWin::AddContentException(views::TreeView* tree_view,
+ ContentSetting setting) {
+ CookieTreeOriginNode* origin_node =
+ static_cast<CookieTreeOriginNode*>(tree_view->GetSelectedNode());
+ origin_node->CreateContentException(
+ tab_contents_->profile()->GetHostContentSettingsMap(), setting);
+}
+
+///////////////////////////////////////////////////////////////////////////////
// NotificationObserver implementation.
void CollectedCookiesWin::Observe(NotificationType type,
diff --git a/chrome/browser/views/collected_cookies_win.h b/chrome/browser/views/collected_cookies_win.h
index 16b5f89..fc33d3c 100644
--- a/chrome/browser/views/collected_cookies_win.h
+++ b/chrome/browser/views/collected_cookies_win.h
@@ -8,7 +8,9 @@
#define CHROME_BROWSER_VIEWS_COLLECTED_COOKIES_WIN_H_
#include "chrome/browser/tab_contents/constrained_window.h"
+#include "chrome/common/content_settings.h"
#include "chrome/common/notification_registrar.h"
+#include "views/controls/tree/tree_view.h"
#include "views/window/dialog_delegate.h"
class ConstrainedWindow;
@@ -16,7 +18,7 @@ class CookiesTreeModel;
class TabContents;
namespace views {
class Label;
-class TreeView;
+class NativeButton;
}
// CollectedCookiesWin is a dialog that displays the allowed and blocked
@@ -25,32 +27,41 @@ class TreeView;
class CollectedCookiesWin : public ConstrainedDialogDelegate,
NotificationObserver,
+ views::ButtonListener,
+ views::TreeViewController,
views::View {
public:
// Use BrowserWindow::ShowCollectedCookiesDialog to show.
CollectedCookiesWin(gfx::NativeWindow parent_window,
TabContents* tab_contents);
- // views::DialogDelegate implementation.
+ // ConstrainedDialogDelegate implementation.
virtual std::wstring GetWindowTitle() const;
virtual int GetDialogButtons() const;
virtual std::wstring GetDialogButtonLabel(
MessageBoxFlags::DialogButton button) const;
virtual void DeleteDelegate();
-
virtual bool Cancel();
-
- // views::WindowDelegate implementation.
virtual views::View* GetContentsView();
+ // views::ButtonListener implementation.
+ virtual void ButtonPressed(views::Button* sender, const views::Event& event);
+
+ // views::TreeViewController implementation.
+ virtual void OnTreeViewSelectionChanged(views::TreeView* tree_view);
+
// views::View implementation.
- gfx::Size GetPreferredSize();
+ virtual gfx::Size GetPreferredSize();
private:
virtual ~CollectedCookiesWin();
void Init();
+ void EnableControls();
+
+ void AddContentException(views::TreeView* tree_view, ContentSetting setting);
+
// Notification Observer implementation.
void Observe(NotificationType type,
const NotificationSource& source,
@@ -70,6 +81,10 @@ class CollectedCookiesWin : public ConstrainedDialogDelegate,
views::TreeView* allowed_cookies_tree_;
views::TreeView* blocked_cookies_tree_;
+ views::NativeButton* block_allowed_button_;
+ views::NativeButton* allow_blocked_button_;
+ views::NativeButton* for_session_blocked_button_;
+
scoped_ptr<CookiesTreeModel> allowed_cookies_tree_model_;
scoped_ptr<CookiesTreeModel> blocked_cookies_tree_model_;