| OLD | NEW |
| 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" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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); |
| 138 if (observer_) | 139 if (observer_) |
| 139 observer_->OnModelChanged(); | 140 observer_->OnModelChanged(); |
| 140 } | 141 } |
| 141 | 142 |
| 142 void PasswordManagerTableModel::CancelLoginsQuery() { | 143 void PasswordManagerTableModel::CancelLoginsQuery() { |
| 143 if (pending_login_query_) { | 144 if (pending_login_query_) { |
| 144 web_data_service()->CancelRequest(pending_login_query_); | 145 web_data_service()->CancelRequest(pending_login_query_); |
| 145 pending_login_query_ = NULL; | 146 pending_login_query_ = NULL; |
| 146 } | 147 } |
| 147 } | 148 } |
| 148 | 149 |
| 149 PasswordForm* PasswordManagerTableModel::GetPasswordFormAt(int row) { | 150 PasswordForm* PasswordManagerTableModel::GetPasswordFormAt(int row) { |
| 150 DCHECK(row >= 0 && row < RowCount()); | 151 DCHECK(row >= 0 && row < RowCount()); |
| 151 return saved_signons_[row]->form.get(); | 152 return saved_signons_[row]->form.get(); |
| 152 } | 153 } |
| 153 | 154 |
| 154 void PasswordManagerTableModel::ForgetAndRemoveSignon(int row) { | 155 void PasswordManagerTableModel::ForgetAndRemoveSignon(int row) { |
| 155 DCHECK(row >= 0 && row < RowCount()); | 156 DCHECK(row >= 0 && row < RowCount()); |
| 156 PasswordRows::iterator target_iter = saved_signons_.begin() + row; | 157 PasswordRows::iterator target_iter = saved_signons_.begin() + row; |
| 157 // Remove from DB, memory, and vector. | 158 // Remove from DB, memory, and vector. |
| 158 PasswordRow* password_row = *target_iter; | 159 PasswordRow* password_row = *target_iter; |
| 159 web_data_service()->RemoveLogin(*(password_row->form.get())); | 160 web_data_service()->RemoveLogin(*(password_row->form.get())); |
| 160 delete password_row; | 161 delete password_row; |
| 161 saved_signons_.erase(target_iter); | 162 saved_signons_.erase(target_iter); |
| 163 instance_->SetRemoveAllEnabled(RowCount() != 0); |
| 162 if (observer_) | 164 if (observer_) |
| 163 observer_->OnItemsRemoved(row, 1); | 165 observer_->OnItemsRemoved(row, 1); |
| 164 } | 166 } |
| 165 | 167 |
| 166 void PasswordManagerTableModel::ForgetAndRemoveAllSignons() { | 168 void PasswordManagerTableModel::ForgetAndRemoveAllSignons() { |
| 167 PasswordRows::iterator iter = saved_signons_.begin(); | 169 PasswordRows::iterator iter = saved_signons_.begin(); |
| 168 while (iter != saved_signons_.end()) { | 170 while (iter != saved_signons_.end()) { |
| 169 // Remove from DB, memory, and vector. | 171 // Remove from DB, memory, and vector. |
| 170 PasswordRow* row = *iter; | 172 PasswordRow* row = *iter; |
| 171 web_data_service()->RemoveLogin(*(row->form.get())); | 173 web_data_service()->RemoveLogin(*(row->form.get())); |
| 172 delete row; | 174 delete row; |
| 173 iter = saved_signons_.erase(iter); | 175 iter = saved_signons_.erase(iter); |
| 174 } | 176 } |
| 177 instance_->SetRemoveAllEnabled(false); |
| 175 if (observer_) | 178 if (observer_) |
| 176 observer_->OnModelChanged(); | 179 observer_->OnModelChanged(); |
| 177 } | 180 } |
| 178 | 181 |
| 179 ////////////////////////////////////////////////////////////////////// | 182 ////////////////////////////////////////////////////////////////////// |
| 180 // PasswordManagerView | 183 // PasswordManagerView |
| 181 | 184 |
| 182 // static | 185 // static |
| 183 void PasswordManagerView::Show(Profile* profile) { | 186 void PasswordManagerView::Show(Profile* profile) { |
| 184 DCHECK(profile); | 187 DCHECK(profile); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 } | 351 } |
| 349 | 352 |
| 350 bool PasswordManagerView::HasAlwaysOnTopMenu() const { | 353 bool PasswordManagerView::HasAlwaysOnTopMenu() const { |
| 351 return false; | 354 return false; |
| 352 } | 355 } |
| 353 | 356 |
| 354 std::wstring PasswordManagerView::GetWindowTitle() const { | 357 std::wstring PasswordManagerView::GetWindowTitle() const { |
| 355 return l10n_util::GetString(IDS_PASSWORD_MANAGER_VIEW_TITLE); | 358 return l10n_util::GetString(IDS_PASSWORD_MANAGER_VIEW_TITLE); |
| 356 } | 359 } |
| 357 | 360 |
| 361 void PasswordManagerView::SetRemoveAllEnabled(bool enabled) { |
| 362 instance_->remove_all_button_.SetEnabled(enabled); |
| 363 } |
| 364 |
| 358 void PasswordManagerView::ButtonPressed(views::NativeButton* sender) { | 365 void PasswordManagerView::ButtonPressed(views::NativeButton* sender) { |
| 359 DCHECK(window()); | 366 DCHECK(window()); |
| 360 // Close will result in our destruction. | 367 // Close will result in our destruction. |
| 361 if (sender == &remove_all_button_) { | 368 if (sender == &remove_all_button_) { |
| 362 table_model_.ForgetAndRemoveAllSignons(); | 369 table_model_.ForgetAndRemoveAllSignons(); |
| 363 return; | 370 return; |
| 364 } | 371 } |
| 365 | 372 |
| 366 // The following require a selection (and only one, since table is single- | 373 // The following require a selection (and only one, since table is single- |
| 367 // select only). | 374 // select only). |
| (...skipping 24 matching lines...) Expand all Loading... |
| 392 table_view_->SetModel(NULL); | 399 table_view_->SetModel(NULL); |
| 393 | 400 |
| 394 // Clear the static instance so the next time Show() is called, a new | 401 // Clear the static instance so the next time Show() is called, a new |
| 395 // instance is created. | 402 // instance is created. |
| 396 instance_ = NULL; | 403 instance_ = NULL; |
| 397 } | 404 } |
| 398 | 405 |
| 399 views::View* PasswordManagerView::GetContentsView() { | 406 views::View* PasswordManagerView::GetContentsView() { |
| 400 return this; | 407 return this; |
| 401 } | 408 } |
| OLD | NEW |