Chromium Code Reviews| Index: chrome/browser/password_manager/update_password_infobar_delegate.cc |
| diff --git a/chrome/browser/password_manager/update_password_infobar_delegate.cc b/chrome/browser/password_manager/update_password_infobar_delegate.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..728095b45302589cd5b953253925956cbd87907c |
| --- /dev/null |
| +++ b/chrome/browser/password_manager/update_password_infobar_delegate.cc |
| @@ -0,0 +1,117 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/password_manager/update_password_infobar_delegate.h" |
| + |
| +#include "base/numerics/safe_conversions.h" |
| +#include "chrome/browser/infobars/infobar_service.h" |
| +#include "chrome/browser/password_manager/chrome_password_manager_client.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/sync/profile_sync_service_factory.h" |
| +#include "chrome/browser/ui/android/infobars/auto_signin_first_run_infobar.h" |
| +#include "chrome/browser/ui/android/infobars/update_password_infobar.h" |
| +#include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" |
| +#include "chrome/grit/chromium_strings.h" |
| +#include "chrome/grit/generated_resources.h" |
| +#include "components/browser_sync/browser/profile_sync_service.h" |
| +#include "components/infobars/core/infobar.h" |
| +#include "components/password_manager/core/browser/password_bubble_experiment.h" |
| +#include "content/public/browser/web_contents.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| + |
| +// static |
| +void UpdatePasswordInfoBarDelegate::Create( |
| + content::WebContents* web_contents, |
| + scoped_ptr<password_manager::PasswordFormManager> form_to_save) { |
| + Profile* profile = |
| + Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| + sync_driver::SyncService* sync_service = |
| + ProfileSyncServiceFactory::GetForProfile(profile); |
| + bool is_smartlock_branding_enabled = |
| + password_bubble_experiment::IsSmartLockBrandingEnabled(sync_service); |
| + InfoBarService::FromWebContents(web_contents) |
| + ->AddInfoBar(make_scoped_ptr(new UpdatePasswordInfoBar( |
| + make_scoped_ptr(new UpdatePasswordInfoBarDelegate( |
| + web_contents, std::move(form_to_save), |
| + is_smartlock_branding_enabled))))); |
| +} |
| + |
| +UpdatePasswordInfoBarDelegate::UpdatePasswordInfoBarDelegate( |
| + content::WebContents* web_contents, |
| + scoped_ptr<password_manager::PasswordFormManager> form_to_update, |
| + bool is_smartlock_branding_enabled) |
| + : PasswordManagerInfoBarDelegate(), |
| + is_smartlock_branding_enabled_(is_smartlock_branding_enabled) { |
| + // TODO(crbug.com/577129): Add histograms. |
| + passwords_data_.set_client( |
| + ChromePasswordManagerClient::FromWebContents(web_contents)); |
| + passwords_data_.OnUpdatePassword(std::move(form_to_update)); |
| + if (is_smartlock_branding_enabled) { |
| + base::string16 branding_ = l10n_util::GetStringUTF16( |
|
Peter Kasting
2016/02/03 00:56:27
This aliases the member. I don't think you intend
melandory
2016/02/12 19:19:36
Done.
|
| + IDS_PASSWORD_MANAGER_SMART_LOCK_FOR_PASSWORDS); |
| + } else { |
| + branding_ = l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_TITLE_BRAND); |
| + } |
|
Peter Kasting
2016/02/03 00:56:26
Nit: Shorter:
branding_ = l10n_util::GetStringU
melandory
2016/02/12 19:19:36
Done.
|
| +} |
| + |
| +UpdatePasswordInfoBarDelegate::~UpdatePasswordInfoBarDelegate() {} |
| + |
| +bool UpdatePasswordInfoBarDelegate::ShowMultipleAccounts() const { |
| + const password_manager::PasswordFormManager* form_manager = |
| + passwords_data_.form_manager(); |
| + bool is_password_overriden = |
| + form_manager ? form_manager->password_overridden() : false; |
| + return GetCurrentForms().size() > 1 && !is_password_overriden; |
|
Peter Kasting
2016/02/03 00:56:26
Nit: Shorter:
return GetCurrentForms().size() >
melandory
2016/02/12 19:19:36
I actually prefer current version, I think it's ea
Peter Kasting
2016/02/13 01:44:52
At least change the line above to:
const bool i
|
| +} |
| + |
| +base::string16 UpdatePasswordInfoBarDelegate::GetUsernameForOneAccountCase() { |
| + password_manager::PasswordFormManager* form_manager = |
| + passwords_data_.form_manager(); |
| + return form_manager->pending_credentials().username_value; |
| +} |
| + |
| +infobars::InfoBarDelegate::InfoBarIdentifier |
| +UpdatePasswordInfoBarDelegate::GetIdentifier() const { |
| + return UPDATE_PASSWORD_INFOBAR_DELEGATE; |
| +} |
| + |
| +base::string16 UpdatePasswordInfoBarDelegate::GetButtonLabel( |
| + InfoBarButton button) const { |
| + return l10n_util::GetStringUTF16((button == BUTTON_OK) |
| + ? IDS_PASSWORD_MANAGER_UPDATE_BUTTON |
| + : IDS_PASSWORD_MANAGER_CANCEL_BUTTON); |
| +} |
| + |
| +bool UpdatePasswordInfoBarDelegate::Accept() { |
| + UpdatePasswordInfoBar* update_password_infobar = |
| + static_cast<UpdatePasswordInfoBar*>(infobar()); |
| + UpdatePassword(update_password_infobar->GetIdOfSelectedUsername()); |
| + return true; |
| +} |
| + |
| +bool UpdatePasswordInfoBarDelegate::Cancel() { |
| + return true; |
| +} |
| + |
| +void UpdatePasswordInfoBarDelegate::UpdatePassword(int form_index) { |
| + if (ShowMultipleAccounts()) |
| + UpdatePasswordWithCurrentForm(form_index); |
| + else |
| + UpdatePasswordWithPending(); |
| +} |
| + |
| +void UpdatePasswordInfoBarDelegate::UpdatePasswordWithCurrentForm( |
|
Peter Kasting
2016/02/03 00:56:27
Nit: Function definition order should match declar
melandory
2016/02/12 19:19:36
Done.
|
| + int form_index) { |
| + CHECK_LT(base::checked_cast<unsigned int>(form_index), |
|
Peter Kasting
2016/02/03 00:56:27
Why is this a CHECK and not a DCHECK? We should n
melandory
2016/02/12 19:19:36
Done.
|
| + GetCurrentForms().size()); |
| + password_manager::PasswordFormManager* form_manager = |
| + passwords_data_.form_manager(); |
| + form_manager->Update(*GetCurrentForms()[form_index]); |
| +} |
| + |
| +void UpdatePasswordInfoBarDelegate::UpdatePasswordWithPending() { |
| + password_manager::PasswordFormManager* form_manager = |
| + passwords_data_.form_manager(); |
| + form_manager->Update(form_manager->pending_credentials()); |
| +} |