OLD | NEW |
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/options/exceptions_view.h" | 5 #include "chrome/browser/views/options/exceptions_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| 11 #include "chrome/browser/views/options/content_exceptions_table_view.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 "gfx/rect.h" | 14 #include "gfx/rect.h" |
14 #include "views/controls/button/native_button.h" | 15 #include "views/controls/button/native_button.h" |
| 16 #include "views/controls/label.h" |
15 #include "views/controls/table/table_view.h" | 17 #include "views/controls/table/table_view.h" |
16 #include "views/grid_layout.h" | 18 #include "views/grid_layout.h" |
17 #include "views/standard_layout.h" | 19 #include "views/standard_layout.h" |
18 #include "views/window/window.h" | 20 #include "views/window/window.h" |
19 | 21 |
20 static const int kExceptionsViewInsetSize = 5; | 22 static const int kExceptionsViewInsetSize = 5; |
21 static ExceptionsView* instances[CONTENT_SETTINGS_NUM_TYPES] = { NULL }; | 23 static ExceptionsView* instances[CONTENT_SETTINGS_NUM_TYPES] = { NULL }; |
22 | 24 |
23 // static | 25 // static |
24 void ExceptionsView::ShowExceptionsWindow(gfx::NativeWindow parent, | 26 void ExceptionsView::ShowExceptionsWindow( |
25 HostContentSettingsMap* map, | 27 gfx::NativeWindow parent, |
26 ContentSettingsType content_type) { | 28 HostContentSettingsMap* map, |
| 29 HostContentSettingsMap* off_the_record_map, |
| 30 ContentSettingsType content_type) { |
27 if (!instances[content_type]) { | 31 if (!instances[content_type]) { |
28 instances[content_type] = new ExceptionsView(map, content_type); | 32 instances[content_type] = |
| 33 new ExceptionsView(map, off_the_record_map, content_type); |
29 views::Window::CreateChromeWindow(parent, gfx::Rect(), | 34 views::Window::CreateChromeWindow(parent, gfx::Rect(), |
30 instances[content_type]); | 35 instances[content_type]); |
31 } | 36 } |
32 | 37 |
33 // This will show invisible windows and bring visible windows to the front. | 38 // This will show invisible windows and bring visible windows to the front. |
34 instances[content_type]->window()->Show(); | 39 instances[content_type]->window()->Show(); |
35 } | 40 } |
36 | 41 |
37 ExceptionsView::~ExceptionsView() { | 42 ExceptionsView::~ExceptionsView() { |
38 instances[model_.content_type()] = NULL; | 43 instances[model_.content_type()] = NULL; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 return l10n_util::GetString(IDS_POPUP_EXCEPTION_TITLE); | 123 return l10n_util::GetString(IDS_POPUP_EXCEPTION_TITLE); |
119 default: | 124 default: |
120 NOTREACHED(); | 125 NOTREACHED(); |
121 } | 126 } |
122 return std::wstring(); | 127 return std::wstring(); |
123 } | 128 } |
124 | 129 |
125 void ExceptionsView::AcceptExceptionEdit( | 130 void ExceptionsView::AcceptExceptionEdit( |
126 const HostContentSettingsMap::Pattern& pattern, | 131 const HostContentSettingsMap::Pattern& pattern, |
127 ContentSetting setting, | 132 ContentSetting setting, |
| 133 bool is_off_the_record, |
128 int index, | 134 int index, |
129 bool is_new) { | 135 bool is_new) { |
| 136 DCHECK(!is_off_the_record || allow_off_the_record_); |
| 137 |
130 if (!is_new) | 138 if (!is_new) |
131 model_.RemoveException(index); | 139 model_.RemoveException(index); |
132 model_.AddException(pattern, setting); | 140 model_.AddException(pattern, setting, is_off_the_record); |
133 | 141 |
134 int new_index = model_.IndexOfExceptionByPattern(pattern); | 142 int new_index = model_.IndexOfExceptionByPattern(pattern, is_off_the_record); |
135 DCHECK(new_index != -1); | 143 DCHECK(new_index != -1); |
136 table_->Select(new_index); | 144 table_->Select(new_index); |
137 } | 145 } |
138 | 146 |
139 ExceptionsView::ExceptionsView(HostContentSettingsMap* map, | 147 ExceptionsView::ExceptionsView(HostContentSettingsMap* map, |
| 148 HostContentSettingsMap* off_the_record_map, |
140 ContentSettingsType type) | 149 ContentSettingsType type) |
141 : model_(map, type), | 150 : model_(map, off_the_record_map, type), |
| 151 allow_off_the_record_(off_the_record_map != NULL), |
142 table_(NULL), | 152 table_(NULL), |
143 add_button_(NULL), | 153 add_button_(NULL), |
144 edit_button_(NULL), | 154 edit_button_(NULL), |
145 remove_button_(NULL), | 155 remove_button_(NULL), |
146 remove_all_button_(NULL) { | 156 remove_all_button_(NULL) { |
147 } | 157 } |
148 | 158 |
149 void ExceptionsView::Init() { | 159 void ExceptionsView::Init() { |
150 if (table_) | 160 if (table_) |
151 return; // We've already Init'd. | 161 return; // We've already Init'd. |
152 | 162 |
153 using views::GridLayout; | 163 using views::GridLayout; |
154 | 164 |
155 std::vector<TableColumn> columns; | 165 std::vector<TableColumn> columns; |
156 columns.push_back( | 166 columns.push_back( |
157 TableColumn(IDS_EXCEPTIONS_PATTERN_HEADER, TableColumn::LEFT, -1, .75)); | 167 TableColumn(IDS_EXCEPTIONS_PATTERN_HEADER, TableColumn::LEFT, -1, .75)); |
158 columns.back().sortable = true; | 168 columns.back().sortable = true; |
159 columns.push_back( | 169 columns.push_back( |
160 TableColumn(IDS_EXCEPTIONS_ACTION_HEADER, TableColumn::LEFT, -1, .25)); | 170 TableColumn(IDS_EXCEPTIONS_ACTION_HEADER, TableColumn::LEFT, -1, .25)); |
161 columns.back().sortable = true; | 171 columns.back().sortable = true; |
162 table_ = new views::TableView(&model_, columns, views::TEXT_ONLY, false, true, | 172 table_ = new ContentExceptionsTableView(&model_, columns); |
163 false); | |
164 views::TableView::SortDescriptors sort; | 173 views::TableView::SortDescriptors sort; |
165 sort.push_back( | 174 sort.push_back( |
166 views::TableView::SortDescriptor(IDS_EXCEPTIONS_PATTERN_HEADER, true)); | 175 views::TableView::SortDescriptor(IDS_EXCEPTIONS_PATTERN_HEADER, true)); |
167 table_->SetSortDescriptors(sort); | 176 table_->SetSortDescriptors(sort); |
168 table_->SetObserver(this); | 177 table_->SetObserver(this); |
169 | 178 |
170 add_button_ = new views::NativeButton( | 179 add_button_ = new views::NativeButton( |
171 this, l10n_util::GetString(IDS_EXCEPTIONS_ADD_BUTTON)); | 180 this, l10n_util::GetString(IDS_EXCEPTIONS_ADD_BUTTON)); |
172 add_button_->set_tag(IDS_EXCEPTIONS_ADD_BUTTON); | 181 add_button_->set_tag(IDS_EXCEPTIONS_ADD_BUTTON); |
173 edit_button_ = new views::NativeButton( | 182 edit_button_ = new views::NativeButton( |
(...skipping 21 matching lines...) Expand all Loading... |
195 views::ColumnSet* column_set = layout->AddColumnSet(single_column_layout_id); | 204 views::ColumnSet* column_set = layout->AddColumnSet(single_column_layout_id); |
196 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); | 205 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
197 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, | 206 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, |
198 GridLayout::USE_PREF, 0, 0); | 207 GridLayout::USE_PREF, 0, 0); |
199 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 208 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
200 | 209 |
201 layout->StartRow(1, single_column_layout_id); | 210 layout->StartRow(1, single_column_layout_id); |
202 layout->AddView(table_); | 211 layout->AddView(table_); |
203 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 212 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
204 | 213 |
| 214 if (allow_off_the_record_) { |
| 215 views::Label* label = new views::Label(l10n_util::GetString( |
| 216 IDS_EXCEPTIONS_OTR_IN_ITALICS)); |
| 217 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 218 layout->StartRow(0, single_column_layout_id); |
| 219 layout->AddView(label, 1, 1, GridLayout::LEADING, GridLayout::CENTER); |
| 220 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
| 221 } |
| 222 |
205 UpdateButtonState(); | 223 UpdateButtonState(); |
206 } | 224 } |
207 | 225 |
208 void ExceptionsView::UpdateButtonState() { | 226 void ExceptionsView::UpdateButtonState() { |
209 int selected_row_count = table_->SelectedRowCount(); | 227 int selected_row_count = table_->SelectedRowCount(); |
210 // TODO: 34177, support editing of more than one entry at a time. | 228 // TODO: 34177, support editing of more than one entry at a time. |
211 edit_button_->SetEnabled(selected_row_count == 1); | 229 edit_button_->SetEnabled(selected_row_count == 1); |
212 remove_button_->SetEnabled(selected_row_count >= 1); | 230 remove_button_->SetEnabled(selected_row_count >= 1); |
213 remove_all_button_->SetEnabled(model_.RowCount() > 0); | 231 remove_all_button_->SetEnabled(model_.RowCount() > 0); |
214 } | 232 } |
215 | 233 |
216 void ExceptionsView::Add() { | 234 void ExceptionsView::Add() { |
217 ExceptionEditorView* view = | 235 ExceptionEditorView* view = |
218 new ExceptionEditorView(this, &model_, -1, | 236 new ExceptionEditorView(this, &model_, allow_off_the_record_, -1, |
219 HostContentSettingsMap::Pattern(), | 237 HostContentSettingsMap::Pattern(), |
220 CONTENT_SETTING_BLOCK); | 238 CONTENT_SETTING_BLOCK, false); |
221 view->Show(window()->GetNativeWindow()); | 239 view->Show(window()->GetNativeWindow()); |
222 | 240 |
223 UpdateButtonState(); | 241 UpdateButtonState(); |
224 } | 242 } |
225 | 243 |
226 void ExceptionsView::Edit() { | 244 void ExceptionsView::Edit() { |
227 DCHECK(table_->FirstSelectedRow() != -1); | 245 DCHECK(table_->FirstSelectedRow() != -1); |
228 int index = table_->FirstSelectedRow(); | 246 int index = table_->FirstSelectedRow(); |
229 const HostContentSettingsMap::PatternSettingPair& entry = | 247 const HostContentSettingsMap::PatternSettingPair& entry = |
230 model_.entry_at(index); | 248 model_.entry_at(index); |
231 ExceptionEditorView* view = | 249 ExceptionEditorView* view = |
232 new ExceptionEditorView(this, &model_, index, entry.first, entry.second); | 250 new ExceptionEditorView(this, &model_, allow_off_the_record_, index, |
| 251 entry.first, entry.second, |
| 252 model_.entry_is_off_the_record(index)); |
233 view->Show(window()->GetNativeWindow()); | 253 view->Show(window()->GetNativeWindow()); |
234 } | 254 } |
235 | 255 |
236 void ExceptionsView::Remove() { | 256 void ExceptionsView::Remove() { |
237 std::vector<int> indices; | 257 std::vector<int> indices; |
238 for (views::TableView::iterator i = table_->SelectionBegin(); | 258 for (views::TableView::iterator i = table_->SelectionBegin(); |
239 i != table_->SelectionEnd(); ++i) { | 259 i != table_->SelectionEnd(); ++i) { |
240 indices.push_back(*i); | 260 indices.push_back(*i); |
241 } | 261 } |
242 std::sort(indices.begin(), indices.end()); | 262 std::sort(indices.begin(), indices.end()); |
243 for (std::vector<int>::reverse_iterator i = indices.rbegin(); | 263 for (std::vector<int>::reverse_iterator i = indices.rbegin(); |
244 i != indices.rend(); ++i) { | 264 i != indices.rend(); ++i) { |
245 model_.RemoveException(*i); | 265 model_.RemoveException(*i); |
246 } | 266 } |
247 | 267 |
248 UpdateButtonState(); | 268 UpdateButtonState(); |
249 } | 269 } |
250 | 270 |
251 void ExceptionsView::RemoveAll() { | 271 void ExceptionsView::RemoveAll() { |
252 model_.RemoveAll(); | 272 model_.RemoveAll(); |
253 | 273 |
254 UpdateButtonState(); | 274 UpdateButtonState(); |
255 } | 275 } |
OLD | NEW |