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

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

Issue 39313: Fix a crash in PasswordManagerExceptionsView (Closed)
Patch Set: more comments Created 11 years, 9 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/password_manager_view.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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "base/string_util.h" 5 #include "base/string_util.h"
6 #include "chrome/common/l10n_util.h" 6 #include "chrome/common/l10n_util.h"
7 #include "chrome/browser/profile.h" 7 #include "chrome/browser/profile.h"
8 #include "chrome/browser/views/password_manager_view.h" 8 #include "chrome/browser/views/password_manager_view.h"
9 #include "chrome/browser/views/standard_layout.h" 9 #include "chrome/browser/views/standard_layout.h"
10 #include "chrome/common/pref_names.h" 10 #include "chrome/common/pref_names.h"
11 #include "chrome/common/pref_service.h" 11 #include "chrome/common/pref_service.h"
12 #include "chrome/views/background.h" 12 #include "chrome/views/background.h"
13 #include "chrome/views/grid_layout.h" 13 #include "chrome/views/grid_layout.h"
14 #include "chrome/views/native_button.h" 14 #include "chrome/views/native_button.h"
15 #include "grit/generated_resources.h" 15 #include "grit/generated_resources.h"
16 16
17 using views::ColumnSet; 17 using views::ColumnSet;
18 using views::GridLayout; 18 using views::GridLayout;
19 19
20 // We can only have one PasswordManagerView at a time. 20 PasswordManagerView* PasswordManagerView::instance_ = NULL;
21 static PasswordManagerView* instance_ = NULL;
22 21
23 static const int kDefaultWindowWidth = 530; 22 static const int kDefaultWindowWidth = 530;
24 static const int kDefaultWindowHeight = 240; 23 static const int kDefaultWindowHeight = 240;
25 24
26 //////////////////////////////////////////////////////////////////////////////// 25 ////////////////////////////////////////////////////////////////////////////////
27 // MultiLabelButtons 26 // MultiLabelButtons
28 // 27 //
29 MultiLabelButtons::MultiLabelButtons(const std::wstring& label, 28 MultiLabelButtons::MultiLabelButtons(const std::wstring& label,
30 const std::wstring& alt_label) 29 const std::wstring& alt_label)
31 : NativeButton(label), 30 : NativeButton(label),
(...skipping 16 matching lines...) Expand all
48 std::max(pref_size_.height(), alt_pref_size.height())); 47 std::max(pref_size_.height(), alt_pref_size.height()));
49 } 48 }
50 return gfx::Size(pref_size_.width(), pref_size_.height()); 49 return gfx::Size(pref_size_.width(), pref_size_.height());
51 } 50 }
52 51
53 52
54 //////////////////////////////////////////////////////////////////// 53 ////////////////////////////////////////////////////////////////////
55 // PasswordManagerTableModel 54 // PasswordManagerTableModel
56 PasswordManagerTableModel::PasswordManagerTableModel(Profile* profile) 55 PasswordManagerTableModel::PasswordManagerTableModel(Profile* profile)
57 : observer_(NULL), 56 : observer_(NULL),
57 row_count_observer_(NULL),
58 pending_login_query_(NULL), 58 pending_login_query_(NULL),
59 saved_signons_cleanup_(&saved_signons_), 59 saved_signons_cleanup_(&saved_signons_),
60 profile_(profile) { 60 profile_(profile) {
61 DCHECK(profile && profile->GetWebDataService(Profile::EXPLICIT_ACCESS)); 61 DCHECK(profile && profile->GetWebDataService(Profile::EXPLICIT_ACCESS));
62 } 62 }
63 63
64 PasswordManagerTableModel::~PasswordManagerTableModel() { 64 PasswordManagerTableModel::~PasswordManagerTableModel() {
65 CancelLoginsQuery(); 65 CancelLoginsQuery();
66 } 66 }
67 67
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 static_cast<const WDResult<std::vector<PasswordForm*> >*>(result); 128 static_cast<const WDResult<std::vector<PasswordForm*> >*>(result);
129 std::vector<PasswordForm*> rows = r->GetValue(); 129 std::vector<PasswordForm*> rows = r->GetValue();
130 STLDeleteElements<PasswordRows>(&saved_signons_); 130 STLDeleteElements<PasswordRows>(&saved_signons_);
131 saved_signons_.resize(rows.size(), NULL); 131 saved_signons_.resize(rows.size(), NULL);
132 std::wstring languages = 132 std::wstring languages =
133 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); 133 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages);
134 for (size_t i = 0; i < rows.size(); ++i) { 134 for (size_t i = 0; i < rows.size(); ++i) {
135 saved_signons_[i] = new PasswordRow( 135 saved_signons_[i] = new PasswordRow(
136 gfx::SortedDisplayURL(rows[i]->origin, languages), rows[i]); 136 gfx::SortedDisplayURL(rows[i]->origin, languages), rows[i]);
137 } 137 }
138 instance_->SetRemoveAllEnabled(RowCount() != 0);
139 if (observer_) 138 if (observer_)
140 observer_->OnModelChanged(); 139 observer_->OnModelChanged();
140 if (row_count_observer_)
141 row_count_observer_->OnRowCountChanged(RowCount());
141 } 142 }
142 143
143 void PasswordManagerTableModel::CancelLoginsQuery() { 144 void PasswordManagerTableModel::CancelLoginsQuery() {
144 if (pending_login_query_) { 145 if (pending_login_query_) {
145 web_data_service()->CancelRequest(pending_login_query_); 146 web_data_service()->CancelRequest(pending_login_query_);
146 pending_login_query_ = NULL; 147 pending_login_query_ = NULL;
147 } 148 }
148 } 149 }
149 150
150 PasswordForm* PasswordManagerTableModel::GetPasswordFormAt(int row) { 151 PasswordForm* PasswordManagerTableModel::GetPasswordFormAt(int row) {
151 DCHECK(row >= 0 && row < RowCount()); 152 DCHECK(row >= 0 && row < RowCount());
152 return saved_signons_[row]->form.get(); 153 return saved_signons_[row]->form.get();
153 } 154 }
154 155
155 void PasswordManagerTableModel::ForgetAndRemoveSignon(int row) { 156 void PasswordManagerTableModel::ForgetAndRemoveSignon(int row) {
156 DCHECK(row >= 0 && row < RowCount()); 157 DCHECK(row >= 0 && row < RowCount());
157 PasswordRows::iterator target_iter = saved_signons_.begin() + row; 158 PasswordRows::iterator target_iter = saved_signons_.begin() + row;
158 // Remove from DB, memory, and vector. 159 // Remove from DB, memory, and vector.
159 PasswordRow* password_row = *target_iter; 160 PasswordRow* password_row = *target_iter;
160 web_data_service()->RemoveLogin(*(password_row->form.get())); 161 web_data_service()->RemoveLogin(*(password_row->form.get()));
161 delete password_row; 162 delete password_row;
162 saved_signons_.erase(target_iter); 163 saved_signons_.erase(target_iter);
163 instance_->SetRemoveAllEnabled(RowCount() != 0);
164 if (observer_) 164 if (observer_)
165 observer_->OnItemsRemoved(row, 1); 165 observer_->OnItemsRemoved(row, 1);
166 if (row_count_observer_)
167 row_count_observer_->OnRowCountChanged(RowCount());
166 } 168 }
167 169
168 void PasswordManagerTableModel::ForgetAndRemoveAllSignons() { 170 void PasswordManagerTableModel::ForgetAndRemoveAllSignons() {
169 PasswordRows::iterator iter = saved_signons_.begin(); 171 PasswordRows::iterator iter = saved_signons_.begin();
170 while (iter != saved_signons_.end()) { 172 while (iter != saved_signons_.end()) {
171 // Remove from DB, memory, and vector. 173 // Remove from DB, memory, and vector.
172 PasswordRow* row = *iter; 174 PasswordRow* row = *iter;
173 web_data_service()->RemoveLogin(*(row->form.get())); 175 web_data_service()->RemoveLogin(*(row->form.get()));
174 delete row; 176 delete row;
175 iter = saved_signons_.erase(iter); 177 iter = saved_signons_.erase(iter);
176 } 178 }
177 instance_->SetRemoveAllEnabled(false);
178 if (observer_) 179 if (observer_)
179 observer_->OnModelChanged(); 180 observer_->OnModelChanged();
181 if (row_count_observer_)
182 row_count_observer_->OnRowCountChanged(RowCount());
180 } 183 }
181 184
182 ////////////////////////////////////////////////////////////////////// 185 //////////////////////////////////////////////////////////////////////
183 // PasswordManagerView 186 // PasswordManagerView
184 187
185 // static 188 // static
186 void PasswordManagerView::Show(Profile* profile) { 189 void PasswordManagerView::Show(Profile* profile) {
187 DCHECK(profile); 190 DCHECK(profile);
188 if (!instance_) { 191 if (!instance_) {
189 instance_ = new PasswordManagerView(profile); 192 instance_ = new PasswordManagerView(profile);
(...skipping 14 matching lines...) Expand all
204 l10n_util::GetString(IDS_PASSWORD_MANAGER_VIEW_HIDE_BUTTON)), 207 l10n_util::GetString(IDS_PASSWORD_MANAGER_VIEW_HIDE_BUTTON)),
205 remove_button_(l10n_util::GetString( 208 remove_button_(l10n_util::GetString(
206 IDS_PASSWORD_MANAGER_VIEW_REMOVE_BUTTON)), 209 IDS_PASSWORD_MANAGER_VIEW_REMOVE_BUTTON)),
207 remove_all_button_(l10n_util::GetString( 210 remove_all_button_(l10n_util::GetString(
208 IDS_PASSWORD_MANAGER_VIEW_REMOVE_ALL_BUTTON)), 211 IDS_PASSWORD_MANAGER_VIEW_REMOVE_ALL_BUTTON)),
209 table_model_(profile) { 212 table_model_(profile) {
210 Init(); 213 Init();
211 } 214 }
212 215
213 void PasswordManagerView::SetupTable() { 216 void PasswordManagerView::SetupTable() {
217 // Tell the table model we are concern about how many rows it has.
218 table_model_.set_row_count_observer(this);
219
214 // Creates the different columns for the table. 220 // Creates the different columns for the table.
215 // The float resize values are the result of much tinkering. 221 // The float resize values are the result of much tinkering.
216 std::vector<views::TableColumn> columns; 222 std::vector<views::TableColumn> columns;
217 columns.push_back(views::TableColumn(IDS_PASSWORD_MANAGER_VIEW_SITE_COLUMN, 223 columns.push_back(views::TableColumn(IDS_PASSWORD_MANAGER_VIEW_SITE_COLUMN,
218 views::TableColumn::LEFT, -1, 0.55f)); 224 views::TableColumn::LEFT, -1, 0.55f));
219 columns.back().sortable = true; 225 columns.back().sortable = true;
220 columns.push_back(views::TableColumn( 226 columns.push_back(views::TableColumn(
221 IDS_PASSWORD_MANAGER_VIEW_USERNAME_COLUMN, views::TableColumn::RIGHT, 227 IDS_PASSWORD_MANAGER_VIEW_USERNAME_COLUMN, views::TableColumn::RIGHT,
222 -1, 0.37f)); 228 -1, 0.37f));
223 columns.back().sortable = true; 229 columns.back().sortable = true;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 } 357 }
352 358
353 bool PasswordManagerView::HasAlwaysOnTopMenu() const { 359 bool PasswordManagerView::HasAlwaysOnTopMenu() const {
354 return false; 360 return false;
355 } 361 }
356 362
357 std::wstring PasswordManagerView::GetWindowTitle() const { 363 std::wstring PasswordManagerView::GetWindowTitle() const {
358 return l10n_util::GetString(IDS_PASSWORD_MANAGER_VIEW_TITLE); 364 return l10n_util::GetString(IDS_PASSWORD_MANAGER_VIEW_TITLE);
359 } 365 }
360 366
361 void PasswordManagerView::SetRemoveAllEnabled(bool enabled) {
362 instance_->remove_all_button_.SetEnabled(enabled);
363 }
364
365 void PasswordManagerView::ButtonPressed(views::NativeButton* sender) { 367 void PasswordManagerView::ButtonPressed(views::NativeButton* sender) {
366 DCHECK(window()); 368 DCHECK(window());
367 // Close will result in our destruction. 369 // Close will result in our destruction.
368 if (sender == &remove_all_button_) { 370 if (sender == &remove_all_button_) {
369 table_model_.ForgetAndRemoveAllSignons(); 371 table_model_.ForgetAndRemoveAllSignons();
370 return; 372 return;
371 } 373 }
372 374
373 // The following require a selection (and only one, since table is single- 375 // The following require a selection (and only one, since table is single-
374 // select only). 376 // select only).
(...skipping 24 matching lines...) Expand all
399 table_view_->SetModel(NULL); 401 table_view_->SetModel(NULL);
400 402
401 // Clear the static instance so the next time Show() is called, a new 403 // Clear the static instance so the next time Show() is called, a new
402 // instance is created. 404 // instance is created.
403 instance_ = NULL; 405 instance_ = NULL;
404 } 406 }
405 407
406 views::View* PasswordManagerView::GetContentsView() { 408 views::View* PasswordManagerView::GetContentsView() {
407 return this; 409 return this;
408 } 410 }
411
412 void PasswordManagerView::OnRowCountChanged(size_t rows) {
413 remove_all_button_.SetEnabled(rows > 0);
414 }
OLDNEW
« no previous file with comments | « chrome/browser/views/password_manager_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698