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

Side by Side Diff: chrome/browser/views/options/exceptions_page_view.cc

Issue 67055: Use tab to group "Show saved passwords" and "Exceptions"... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/views/options/exceptions_page_view.h"
6
7 #include "base/string_util.h"
8 #include "chrome/browser/profile.h"
9 #include "chrome/browser/views/standard_layout.h"
10 #include "chrome/common/l10n_util.h"
11 #include "chrome/common/pref_names.h"
12 #include "chrome/common/pref_service.h"
13 #include "chrome/views/background.h"
14 #include "chrome/views/controls/button/native_button.h"
15 #include "chrome/views/grid_layout.h"
16 #include "grit/generated_resources.h"
17
18 using views::ColumnSet;
19 using views::GridLayout;
20
21 ///////////////////////////////////////////////////////////////////////////////
22 // ExceptionsTableModel
23 ExceptionsTableModel::ExceptionsTableModel(Profile* profile)
24 : PasswordsTableModel(profile) {
25 }
26
27 ExceptionsTableModel::~ExceptionsTableModel() {
28 }
29
30 std::wstring ExceptionsTableModel::GetText(int row, int col_id) {
31 DCHECK_EQ(col_id, IDS_PASSWORDS_PAGE_VIEW_SITE_COLUMN);
32 return PasswordsTableModel::GetText(row, col_id);
33 }
34
35 int ExceptionsTableModel::CompareValues(int row1, int row2,
36 int col_id) {
37 DCHECK_EQ(col_id, IDS_PASSWORDS_PAGE_VIEW_SITE_COLUMN);
38 return PasswordsTableModel::CompareValues(row1, row2, col_id);
39 }
40
41 void ExceptionsTableModel::GetAllExceptionsForProfile() {
42 DCHECK(!pending_login_query_);
43 pending_login_query_ = web_data_service()->GetAllLogins(this);
44 }
45
46 void ExceptionsTableModel::OnWebDataServiceRequestDone(
47 WebDataService::Handle h,
48 const WDTypedResult* result) {
49 DCHECK_EQ(pending_login_query_, h);
50 pending_login_query_ = NULL;
51
52 if (!result)
53 return;
54
55 DCHECK(result->GetType() == PASSWORD_RESULT);
56
57 // Get the result from the database into a useable form.
58 const WDResult<std::vector<PasswordForm*> >* r =
59 static_cast<const WDResult<std::vector<PasswordForm*> >*>(result);
60 std::vector<PasswordForm*> rows = r->GetValue();
61 STLDeleteElements<PasswordRows>(&saved_signons_);
62 std::wstring languages =
63 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages);
64 for (size_t i = 0; i < rows.size(); ++i) {
65 if (rows[i]->blacklisted_by_user) {
66 saved_signons_.push_back(new PasswordRow(
67 gfx::SortedDisplayURL(rows[i]->origin, languages), rows[i]));
68 }
69 }
70 if (observer_)
71 observer_->OnModelChanged();
72 if (row_count_observer_)
73 row_count_observer_->OnRowCountChanged(RowCount());
74 }
75
76 ///////////////////////////////////////////////////////////////////////////////
77 // ExceptionsPageView, public
78 ExceptionsPageView::ExceptionsPageView(Profile* profile)
79 : OptionsPageView(profile),
80 remove_button_(this, l10n_util::GetString(
81 IDS_EXCEPTIONS_PAGE_VIEW_REMOVE_BUTTON)),
82 remove_all_button_(this, l10n_util::GetString(
83 IDS_EXCEPTIONS_PAGE_VIEW_REMOVE_ALL_BUTTON)),
84 table_model_(profile),
85 table_view_(NULL) {
86 }
87
88 void ExceptionsPageView::OnSelectionChanged() {
89 bool has_selection = table_view_->SelectedRowCount() > 0;
90 remove_button_.SetEnabled(has_selection);
91 }
92
93 void ExceptionsPageView::ButtonPressed(views::Button* sender) {
94 // Close will result in our destruction.
95 if (sender == &remove_all_button_) {
96 table_model_.ForgetAndRemoveAllSignons();
97 return;
98 }
99
100 // The following require a selection (and only one, since table is single-
101 // select only).
102 views::TableSelectionIterator iter = table_view_->SelectionBegin();
103 int row = *iter;
104 PasswordForm* selected = table_model_.GetPasswordFormAt(row);
105 DCHECK(++iter == table_view_->SelectionEnd());
106
107 if (sender == &remove_button_) {
108 table_model_.ForgetAndRemoveSignon(row);
109 } else {
110 NOTREACHED() << "Invalid button.";
111 }
112 }
113
114 void ExceptionsPageView::OnRowCountChanged(size_t rows) {
115 remove_all_button_.SetEnabled(rows > 0);
116 }
117
118 ///////////////////////////////////////////////////////////////////////////////
119 // ExceptionsPageView, protected
120 void ExceptionsPageView::InitControlLayout() {
121 SetupButtons();
122 SetupTable();
123
124 // Do the layout thing.
125 const int column_set_id = 0;
126 GridLayout* layout = CreatePanelGridLayout(this);
127 SetLayoutManager(layout);
128
129 // Design the grid.
130 ColumnSet* column_set = layout->AddColumnSet(column_set_id);
131 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
132 GridLayout::FIXED, 300, 0);
133 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing);
134 column_set->AddColumn(GridLayout::FILL, GridLayout::LEADING, 0,
135 GridLayout::USE_PREF, 0, 0);
136
137 // Fill the grid.
138 layout->StartRow(0.05f, column_set_id);
139 layout->AddView(table_view_, 1, 2);
140 layout->AddView(&remove_button_);
141 layout->StartRow(0.80f, column_set_id);
142 layout->SkipColumns(1);
143 layout->AddView(&remove_all_button_);
144 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
145
146 // Ask the database for exception data.
147 table_model_.GetAllExceptionsForProfile();
148 }
149
150 ///////////////////////////////////////////////////////////////////////////////
151 // ExceptionsPageView, private
152 void ExceptionsPageView::SetupButtons() {
153 remove_button_.SetParentOwned(false);
154 remove_button_.SetEnabled(false);
155
156 remove_all_button_.SetParentOwned(false);
157 remove_all_button_.SetEnabled(false);
158 }
159
160 void ExceptionsPageView::SetupTable() {
161 // Tell the table model we are concerned about how many rows it has.
162 table_model_.set_row_count_observer(this);
163
164 // Creates the different columns for the table.
165 // The float resize values are the result of much tinkering.
166 std::vector<views::TableColumn> columns;
167 columns.push_back(views::TableColumn(
168 IDS_PASSWORDS_PAGE_VIEW_SITE_COLUMN,
169 views::TableColumn::LEFT, -1, 0.55f));
170 columns.back().sortable = true;
171 table_view_ = new views::TableView(&table_model_, columns, views::TEXT_ONLY,
172 true, true, true);
173 // Make the table initially sorted by host.
174 views::TableView::SortDescriptors sort;
175 sort.push_back(views::TableView::SortDescriptor(
176 IDS_PASSWORDS_PAGE_VIEW_SITE_COLUMN, true));
177 table_view_->SetSortDescriptors(sort);
178 table_view_->SetObserver(this);
179 }
OLDNEW
« no previous file with comments | « chrome/browser/views/options/exceptions_page_view.h ('k') | chrome/browser/views/options/fonts_page_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698