Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/views/passwords/manage_password_items_view.h" | 5 #include "chrome/browser/ui/views/passwords/manage_password_items_view.h" |
| 6 | 6 |
| 7 #include <numeric> | 7 #include <numeric> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | |
| 10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" | 12 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" |
| 12 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" | 13 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" |
| 13 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
| 14 #include "grit/components_strings.h" | 15 #include "grit/components_strings.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 16 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
| 17 #include "ui/resources/grit/ui_resources.h" | 18 #include "ui/resources/grit/ui_resources.h" |
| 18 #include "ui/views/controls/button/button.h" | 19 #include "ui/views/controls/button/button.h" |
| 19 #include "ui/views/controls/button/image_button.h" | 20 #include "ui/views/controls/button/image_button.h" |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 } | 261 } |
| 261 | 262 |
| 262 void ManagePasswordItemsView::PasswordFormRow::ResetControls() { | 263 void ManagePasswordItemsView::PasswordFormRow::ResetControls() { |
| 263 delete_button_ = nullptr; | 264 delete_button_ = nullptr; |
| 264 undo_link_ = nullptr; | 265 undo_link_ = nullptr; |
| 265 } | 266 } |
| 266 | 267 |
| 267 // ManagePasswordItemsView | 268 // ManagePasswordItemsView |
| 268 ManagePasswordItemsView::ManagePasswordItemsView( | 269 ManagePasswordItemsView::ManagePasswordItemsView( |
| 269 ManagePasswordsBubbleModel* manage_passwords_bubble_model, | 270 ManagePasswordsBubbleModel* manage_passwords_bubble_model, |
| 270 const std::vector<const autofill::PasswordForm*>& password_forms) | 271 const std::vector<autofill::PasswordForm>* password_forms) |
| 271 : model_(manage_passwords_bubble_model) { | 272 : model_(manage_passwords_bubble_model) { |
| 272 int fixed_height = PasswordFormRow::GetFixedHeight(model_->state()); | 273 int fixed_height = PasswordFormRow::GetFixedHeight(model_->state()); |
| 273 for (const autofill::PasswordForm* password_form : password_forms) { | 274 for (const auto& password_form : *password_forms) { |
| 274 if (!password_form->is_public_suffix_match) | 275 if (!password_form.is_public_suffix_match) |
| 275 password_forms_rows_.push_back( | 276 password_forms_rows_.push_back(base::WrapUnique( |
|
vabr (Chromium)
2016/08/18 18:39:19
Also here: what about MakeUnique or emplace_back?
vasilii
2016/08/19 09:52:30
Done.
| |
| 276 new PasswordFormRow(this, password_form, fixed_height)); | 277 new PasswordFormRow(this, &password_form, fixed_height))); |
| 277 } | 278 } |
| 278 AddRows(); | 279 AddRows(); |
| 279 } | 280 } |
| 280 | 281 |
| 282 ManagePasswordItemsView::ManagePasswordItemsView( | |
| 283 ManagePasswordsBubbleModel* manage_passwords_bubble_model, | |
| 284 const autofill::PasswordForm* password_form) | |
| 285 : model_(manage_passwords_bubble_model) { | |
| 286 password_forms_rows_.push_back( | |
| 287 base::WrapUnique(new PasswordFormRow(this, password_form, 0))); | |
| 288 AddRows(); | |
| 289 } | |
| 290 | |
| 281 ManagePasswordItemsView::~ManagePasswordItemsView() = default; | 291 ManagePasswordItemsView::~ManagePasswordItemsView() = default; |
| 282 | 292 |
| 283 void ManagePasswordItemsView::AddRows() { | 293 void ManagePasswordItemsView::AddRows() { |
| 284 views::GridLayout* layout = new views::GridLayout(this); | 294 views::GridLayout* layout = new views::GridLayout(this); |
| 285 SetLayoutManager(layout); | 295 SetLayoutManager(layout); |
| 286 for (auto* row : password_forms_rows_) { | 296 for (const std::unique_ptr<PasswordFormRow>& row : password_forms_rows_) { |
| 287 if (row != password_forms_rows_[0]) | 297 if (row != password_forms_rows_[0]) |
| 288 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 298 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 289 row->AddRow(layout); | 299 row->AddRow(layout); |
| 290 } | 300 } |
| 291 GetLayoutManager()->Layout(this); | 301 GetLayoutManager()->Layout(this); |
| 292 } | 302 } |
| 293 | 303 |
| 294 void ManagePasswordItemsView::NotifyPasswordFormStatusChanged( | 304 void ManagePasswordItemsView::NotifyPasswordFormStatusChanged( |
| 295 const autofill::PasswordForm& password_form, bool deleted) { | 305 const autofill::PasswordForm& password_form, bool deleted) { |
| 296 Refresh(); | 306 Refresh(); |
| 297 // After the view is consistent, notify the model that the password needs to | 307 // After the view is consistent, notify the model that the password needs to |
| 298 // be updated (either removed or put back into the store, as appropriate. | 308 // be updated (either removed or put back into the store, as appropriate. |
| 299 model_->OnPasswordAction(password_form, | 309 model_->OnPasswordAction(password_form, |
| 300 deleted | 310 deleted |
| 301 ? ManagePasswordsBubbleModel::REMOVE_PASSWORD | 311 ? ManagePasswordsBubbleModel::REMOVE_PASSWORD |
| 302 : ManagePasswordsBubbleModel::ADD_PASSWORD); | 312 : ManagePasswordsBubbleModel::ADD_PASSWORD); |
| 303 } | 313 } |
| 304 | 314 |
| 305 void ManagePasswordItemsView::Refresh() { | 315 void ManagePasswordItemsView::Refresh() { |
| 306 DCHECK_NE(password_manager::ui::PENDING_PASSWORD_STATE, model_->state()); | 316 DCHECK_NE(password_manager::ui::PENDING_PASSWORD_STATE, model_->state()); |
| 307 RemoveAllChildViews(true); | 317 RemoveAllChildViews(true); |
| 308 AddRows(); | 318 AddRows(); |
| 309 } | 319 } |
| OLD | NEW |