Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: chrome/browser/views/collected_cookies_win.cc

Issue 2808053: Buttons for the collected cookies dialog to add content exceptions. (Closed)
Patch Set: compile fix Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/views/collected_cookies_win.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/views/collected_cookies_win.h" 5 #include "chrome/browser/views/collected_cookies_win.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "chrome/browser/cookies_tree_model.h" 8 #include "chrome/browser/cookies_tree_model.h"
9 #include "chrome/browser/profile.h"
9 #include "chrome/browser/tab_contents/tab_contents.h" 10 #include "chrome/browser/tab_contents/tab_contents.h"
10 #include "chrome/common/notification_service.h" 11 #include "chrome/common/notification_service.h"
11 #include "grit/generated_resources.h" 12 #include "grit/generated_resources.h"
12 #include "grit/locale_settings.h" 13 #include "grit/locale_settings.h"
13 #include "views/controls/label.h" 14 #include "views/controls/label.h"
14 #include "views/controls/tree/tree_view.h" 15 #include "views/controls/button/native_button.h"
15 #include "views/standard_layout.h" 16 #include "views/standard_layout.h"
16 #include "views/window/window.h" 17 #include "views/window/window.h"
17 18
18 namespace browser { 19 namespace browser {
19 20
20 // Declared in browser_dialogs.h so others don't have to depend on our header. 21 // Declared in browser_dialogs.h so others don't have to depend on our header.
21 void ShowCollectedCookiesDialog(gfx::NativeWindow parent_window, 22 void ShowCollectedCookiesDialog(gfx::NativeWindow parent_window,
22 TabContents* tab_contents) { 23 TabContents* tab_contents) {
23 // Deletes itself on close. 24 // Deletes itself on close.
24 new CollectedCookiesWin(parent_window, tab_contents); 25 new CollectedCookiesWin(parent_window, tab_contents);
25 } 26 }
26 27
27 } // namespace browser 28 } // namespace browser
28 29
29 30
30 /////////////////////////////////////////////////////////////////////////////// 31 ///////////////////////////////////////////////////////////////////////////////
31 // CollectedCookiesWin, constructor and destructor: 32 // CollectedCookiesWin, constructor and destructor:
32 33
33 CollectedCookiesWin::CollectedCookiesWin(gfx::NativeWindow parent_window, 34 CollectedCookiesWin::CollectedCookiesWin(gfx::NativeWindow parent_window,
34 TabContents* tab_contents) 35 TabContents* tab_contents)
35 : tab_contents_(tab_contents) { 36 : tab_contents_(tab_contents),
37 allowed_label_(NULL),
38 blocked_label_(NULL),
39 allowed_cookies_tree_(NULL),
40 blocked_cookies_tree_(NULL),
41 block_allowed_button_(NULL),
42 allow_blocked_button_(NULL),
43 for_session_blocked_button_(NULL) {
36 TabSpecificContentSettings* content_settings = 44 TabSpecificContentSettings* content_settings =
37 tab_contents->GetTabSpecificContentSettings(); 45 tab_contents->GetTabSpecificContentSettings();
38 registrar_.Add(this, NotificationType::COLLECTED_COOKIES_SHOWN, 46 registrar_.Add(this, NotificationType::COLLECTED_COOKIES_SHOWN,
39 Source<TabSpecificContentSettings>(content_settings)); 47 Source<TabSpecificContentSettings>(content_settings));
40 48
41 Init(); 49 Init();
42 50
43 window_ = tab_contents_->CreateConstrainedDialog(this); 51 window_ = tab_contents_->CreateConstrainedDialog(this);
44 } 52 }
45 53
46 CollectedCookiesWin::~CollectedCookiesWin() { 54 CollectedCookiesWin::~CollectedCookiesWin() {
47 allowed_cookies_tree_->SetModel(NULL); 55 allowed_cookies_tree_->SetModel(NULL);
48 blocked_cookies_tree_->SetModel(NULL); 56 blocked_cookies_tree_->SetModel(NULL);
49 } 57 }
50 58
51 void CollectedCookiesWin::Init() { 59 void CollectedCookiesWin::Init() {
52 TabSpecificContentSettings* content_settings = 60 TabSpecificContentSettings* content_settings =
53 tab_contents_->GetTabSpecificContentSettings(); 61 tab_contents_->GetTabSpecificContentSettings();
54 62
55 // Allowed Cookie list. 63 // Allowed Cookie list.
56 allowed_label_ = new views::Label( 64 allowed_label_ = new views::Label(
57 l10n_util::GetString(IDS_COLLECTED_COOKIES_ALLOWED_COOKIES_LABEL)); 65 l10n_util::GetString(IDS_COLLECTED_COOKIES_ALLOWED_COOKIES_LABEL));
58 allowed_cookies_tree_model_.reset( 66 allowed_cookies_tree_model_.reset(
59 content_settings->GetAllowedCookiesTreeModel()); 67 content_settings->GetAllowedCookiesTreeModel());
60 allowed_cookies_tree_ = new views::TreeView(); 68 allowed_cookies_tree_ = new views::TreeView();
61 allowed_cookies_tree_->SetModel(allowed_cookies_tree_model_.get()); 69 allowed_cookies_tree_->SetModel(allowed_cookies_tree_model_.get());
70 allowed_cookies_tree_->SetController(this);
62 allowed_cookies_tree_->SetRootShown(false); 71 allowed_cookies_tree_->SetRootShown(false);
63 allowed_cookies_tree_->SetEditable(false); 72 allowed_cookies_tree_->SetEditable(false);
64 allowed_cookies_tree_->set_lines_at_root(true); 73 allowed_cookies_tree_->set_lines_at_root(true);
65 allowed_cookies_tree_->set_auto_expand_children(true); 74 allowed_cookies_tree_->set_auto_expand_children(true);
66 75
67 // Blocked Cookie list. 76 // Blocked Cookie list.
68 blocked_label_ = new views::Label( 77 blocked_label_ = new views::Label(
69 l10n_util::GetString(IDS_COLLECTED_COOKIES_BLOCKED_COOKIES_LABEL)); 78 l10n_util::GetString(IDS_COLLECTED_COOKIES_BLOCKED_COOKIES_LABEL));
70 blocked_cookies_tree_model_.reset( 79 blocked_cookies_tree_model_.reset(
71 content_settings->GetBlockedCookiesTreeModel()); 80 content_settings->GetBlockedCookiesTreeModel());
72 blocked_cookies_tree_ = new views::TreeView(); 81 blocked_cookies_tree_ = new views::TreeView();
73 blocked_cookies_tree_->SetModel(blocked_cookies_tree_model_.get()); 82 blocked_cookies_tree_->SetModel(blocked_cookies_tree_model_.get());
83 blocked_cookies_tree_->SetController(this);
74 blocked_cookies_tree_->SetRootShown(false); 84 blocked_cookies_tree_->SetRootShown(false);
75 blocked_cookies_tree_->SetEditable(false); 85 blocked_cookies_tree_->SetEditable(false);
76 blocked_cookies_tree_->set_lines_at_root(true); 86 blocked_cookies_tree_->set_lines_at_root(true);
77 blocked_cookies_tree_->set_auto_expand_children(true); 87 blocked_cookies_tree_->set_auto_expand_children(true);
78 88
79 using views::GridLayout; 89 using views::GridLayout;
80 90
81 GridLayout* layout = CreatePanelGridLayout(this); 91 GridLayout* layout = CreatePanelGridLayout(this);
82 SetLayoutManager(layout); 92 SetLayoutManager(layout);
83 93
84 const int single_column_layout_id = 0; 94 const int single_column_layout_id = 0;
85 views::ColumnSet* column_set = layout->AddColumnSet(single_column_layout_id); 95 views::ColumnSet* column_set = layout->AddColumnSet(single_column_layout_id);
86 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, 96 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1,
87 GridLayout::USE_PREF, 0, 0); 97 GridLayout::USE_PREF, 0, 0);
88 98
99 const int three_columns_layout_id = 1;
100 column_set = layout->AddColumnSet(three_columns_layout_id);
101 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
102 GridLayout::USE_PREF, 0, 0);
103 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing);
104 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
105 GridLayout::USE_PREF, 0, 0);
106
89 layout->StartRow(0, single_column_layout_id); 107 layout->StartRow(0, single_column_layout_id);
90 layout->AddView(allowed_label_); 108 layout->AddView(allowed_label_);
91 109
92 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); 110 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
93 layout->StartRow(1, single_column_layout_id); 111 layout->StartRow(1, single_column_layout_id);
94 layout->AddView( 112 layout->AddView(
95 allowed_cookies_tree_, 1, 1, GridLayout::FILL, GridLayout::FILL); 113 allowed_cookies_tree_, 1, 1, GridLayout::FILL, GridLayout::FILL);
114 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
115
116 layout->StartRow(0, single_column_layout_id);
117 block_allowed_button_ = new views::NativeButton(
118 this, l10n_util::GetString(IDS_COLLECTED_COOKIES_BLOCK_BUTTON));
119 layout->AddView(
120 block_allowed_button_, 1, 1, GridLayout::LEADING, GridLayout::CENTER);
96 layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing); 121 layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing);
97 122
98 layout->StartRow(0, single_column_layout_id); 123 layout->StartRow(0, single_column_layout_id);
99 layout->AddView(blocked_label_); 124 layout->AddView(blocked_label_);
100 125
101 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); 126 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
102 layout->StartRow(1, single_column_layout_id); 127 layout->StartRow(1, single_column_layout_id);
103 layout->AddView( 128 layout->AddView(
104 blocked_cookies_tree_, 1, 1, GridLayout::FILL, GridLayout::FILL); 129 blocked_cookies_tree_, 1, 1, GridLayout::FILL, GridLayout::FILL);
130 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
131
132 layout->StartRow(0, three_columns_layout_id);
133 allow_blocked_button_ = new views::NativeButton(
134 this, l10n_util::GetString(IDS_COLLECTED_COOKIES_ALLOW_BUTTON));
135 layout->AddView(allow_blocked_button_);
136 for_session_blocked_button_ = new views::NativeButton(
137 this, l10n_util::GetString(IDS_COLLECTED_COOKIES_SESSION_ONLY_BUTTON));
138 layout->AddView(for_session_blocked_button_);
139
140 EnableControls();
105 } 141 }
106 142
107 /////////////////////////////////////////////////////////////////////////////// 143 ///////////////////////////////////////////////////////////////////////////////
108 // views::DialogDelegate implementation. 144 // ConstrainedDialogDelegate implementation.
109 145
110 std::wstring CollectedCookiesWin::GetWindowTitle() const { 146 std::wstring CollectedCookiesWin::GetWindowTitle() const {
111 return l10n_util::GetString(IDS_COLLECTED_COOKIES_DIALOG_TITLE); 147 return l10n_util::GetString(IDS_COLLECTED_COOKIES_DIALOG_TITLE);
112 } 148 }
113 149
114 int CollectedCookiesWin::GetDialogButtons() const { 150 int CollectedCookiesWin::GetDialogButtons() const {
115 return MessageBoxFlags::DIALOGBUTTON_CANCEL; 151 return MessageBoxFlags::DIALOGBUTTON_CANCEL;
116 } 152 }
117 153
118 std::wstring CollectedCookiesWin::GetDialogButtonLabel( 154 std::wstring CollectedCookiesWin::GetDialogButtonLabel(
119 MessageBoxFlags::DialogButton button) const { 155 MessageBoxFlags::DialogButton button) const {
120 return l10n_util::GetString(IDS_CLOSE); 156 return l10n_util::GetString(IDS_CLOSE);
121 } 157 }
122 158
123 void CollectedCookiesWin::DeleteDelegate() { 159 void CollectedCookiesWin::DeleteDelegate() {
124 delete this; 160 delete this;
125 } 161 }
126 162
127 bool CollectedCookiesWin::Cancel() { 163 bool CollectedCookiesWin::Cancel() {
128 return true; 164 return true;
129 } 165 }
130 166
131 ///////////////////////////////////////////////////////////////////////////////
132 // views::WindowDelegate implementation.
133
134 views::View* CollectedCookiesWin::GetContentsView() { 167 views::View* CollectedCookiesWin::GetContentsView() {
135 return this; 168 return this;
136 } 169 }
137 170
138 /////////////////////////////////////////////////////////////////////////////// 171 ///////////////////////////////////////////////////////////////////////////////
172 // views::ButtonListener implementation.
173
174 void CollectedCookiesWin::ButtonPressed(views::Button* sender,
175 const views::Event& event) {
176 if (sender == block_allowed_button_)
177 AddContentException(allowed_cookies_tree_, CONTENT_SETTING_BLOCK);
178 else if (sender == allow_blocked_button_)
179 AddContentException(blocked_cookies_tree_, CONTENT_SETTING_ALLOW);
180 else if (sender == for_session_blocked_button_)
181 AddContentException(blocked_cookies_tree_, CONTENT_SETTING_SESSION_ONLY);
182 }
183
184 ///////////////////////////////////////////////////////////////////////////////
185 // views::View implementation.
186
187 void CollectedCookiesWin::OnTreeViewSelectionChanged(
188 views::TreeView* tree_view) {
189 EnableControls();
190 }
191
192 ///////////////////////////////////////////////////////////////////////////////
139 // views::View implementation. 193 // views::View implementation.
140 194
141 gfx::Size CollectedCookiesWin::GetPreferredSize() { 195 gfx::Size CollectedCookiesWin::GetPreferredSize() {
142 return gfx::Size(views::Window::GetLocalizedContentsSize( 196 return gfx::Size(views::Window::GetLocalizedContentsSize(
143 IDS_COOKIES_DIALOG_WIDTH_CHARS, 197 IDS_COOKIES_DIALOG_WIDTH_CHARS,
144 IDS_COOKIES_DIALOG_HEIGHT_LINES)); 198 IDS_COOKIES_DIALOG_HEIGHT_LINES));
145 } 199 }
146 200
147 /////////////////////////////////////////////////////////////////////////////// 201 ///////////////////////////////////////////////////////////////////////////////
202 // CollectedCookiesWin, private methods.
203
204 void CollectedCookiesWin::EnableControls() {
205 bool enable_allowed_buttons = false;
206 TreeModelNode* node = allowed_cookies_tree_->GetSelectedNode();
207 if (node) {
208 CookieTreeNode* cookie_node = static_cast<CookieTreeNode*>(node);
209 if (cookie_node->GetDetailedInfo().node_type ==
210 CookieTreeNode::DetailedInfo::TYPE_ORIGIN) {
211 enable_allowed_buttons = static_cast<CookieTreeOriginNode*>(
212 cookie_node)->CanCreateContentException();
213 }
214 }
215 block_allowed_button_->SetEnabled(enable_allowed_buttons);
216
217 bool enable_blocked_buttons = false;
218 node = blocked_cookies_tree_->GetSelectedNode();
219 if (node) {
220 CookieTreeNode* cookie_node = static_cast<CookieTreeNode*>(node);
221 if (cookie_node->GetDetailedInfo().node_type ==
222 CookieTreeNode::DetailedInfo::TYPE_ORIGIN) {
223 enable_blocked_buttons = static_cast<CookieTreeOriginNode*>(
224 cookie_node)->CanCreateContentException();
225 }
226 }
227 allow_blocked_button_->SetEnabled(enable_blocked_buttons);
228 for_session_blocked_button_->SetEnabled(enable_blocked_buttons);
229 }
230
231 void CollectedCookiesWin::AddContentException(views::TreeView* tree_view,
232 ContentSetting setting) {
233 CookieTreeOriginNode* origin_node =
234 static_cast<CookieTreeOriginNode*>(tree_view->GetSelectedNode());
235 origin_node->CreateContentException(
236 tab_contents_->profile()->GetHostContentSettingsMap(), setting);
237 }
238
239 ///////////////////////////////////////////////////////////////////////////////
148 // NotificationObserver implementation. 240 // NotificationObserver implementation.
149 241
150 void CollectedCookiesWin::Observe(NotificationType type, 242 void CollectedCookiesWin::Observe(NotificationType type,
151 const NotificationSource& source, 243 const NotificationSource& source,
152 const NotificationDetails& details) { 244 const NotificationDetails& details) {
153 DCHECK(type == NotificationType::COLLECTED_COOKIES_SHOWN); 245 DCHECK(type == NotificationType::COLLECTED_COOKIES_SHOWN);
154 DCHECK_EQ(Source<TabSpecificContentSettings>(source).ptr(), 246 DCHECK_EQ(Source<TabSpecificContentSettings>(source).ptr(),
155 tab_contents_->GetTabSpecificContentSettings()); 247 tab_contents_->GetTabSpecificContentSettings());
156 window_->CloseConstrainedWindow(); 248 window_->CloseConstrainedWindow();
157 } 249 }
OLDNEW
« no previous file with comments | « chrome/browser/views/collected_cookies_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698