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

Side by Side Diff: chrome/browser/password_manager/update_password_infobar_delegate.cc

Issue 1490193003: [Password Manager] Update Confirmation UI for saved password change for Chrome on Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
OLDNEW
(Empty)
1 // Copyright 2016 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/password_manager/update_password_infobar_delegate.h"
6
7 #include "base/numerics/safe_conversions.h"
8 #include "chrome/browser/infobars/infobar_service.h"
9 #include "chrome/browser/password_manager/chrome_password_manager_client.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/sync/profile_sync_service_factory.h"
12 #include "chrome/browser/ui/android/infobars/update_password_infobar.h"
13 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h"
14 #include "chrome/grit/chromium_strings.h"
15 #include "chrome/grit/generated_resources.h"
16 #include "components/browser_sync/browser/profile_sync_service.h"
17 #include "components/infobars/core/infobar.h"
18 #include "components/password_manager/core/browser/password_bubble_experiment.h"
19 #include "content/public/browser/web_contents.h"
20 #include "ui/base/l10n/l10n_util.h"
21
22 // static
23 void UpdatePasswordInfoBarDelegate::Create(
24 content::WebContents* web_contents,
25 scoped_ptr<password_manager::PasswordFormManager> form_to_save) {
26 const bool is_smartlock_branding_enabled =
27 password_bubble_experiment::IsSmartLockBrandingEnabled(
28 ProfileSyncServiceFactory::GetForProfile(
29 Profile::FromBrowserContext(web_contents->GetBrowserContext())));
30 InfoBarService::FromWebContents(web_contents)
31 ->AddInfoBar(make_scoped_ptr(new UpdatePasswordInfoBar(
32 make_scoped_ptr(new UpdatePasswordInfoBarDelegate(
33 web_contents, std::move(form_to_save),
34 is_smartlock_branding_enabled)))));
35 }
36
37 UpdatePasswordInfoBarDelegate::~UpdatePasswordInfoBarDelegate() {}
38
39 base::string16 UpdatePasswordInfoBarDelegate::GetBranding() const {
40 return l10n_util::GetStringUTF16(
41 is_smartlock_branding_enabled_
42 ? IDS_PASSWORD_MANAGER_SMART_LOCK_FOR_PASSWORDS
43 : IDS_PASSWORD_MANAGER_TITLE_BRAND);
44 }
45
46 bool UpdatePasswordInfoBarDelegate::ShowMultipleAccounts() const {
47 const password_manager::PasswordFormManager* form_manager =
48 passwords_state_.form_manager();
49 bool is_password_overriden =
50 form_manager && form_manager->password_overridden();
51 return GetCurrentForms().size() > 1 && !is_password_overriden;
52 }
53
54 const std::vector<const autofill::PasswordForm*>&
55 UpdatePasswordInfoBarDelegate::GetCurrentForms() const {
56 return passwords_state_.GetCurrentForms();
57 }
58
59 UpdatePasswordInfoBarDelegate::UpdatePasswordInfoBarDelegate(
60 content::WebContents* web_contents,
61 scoped_ptr<password_manager::PasswordFormManager> form_to_update,
62 bool is_smartlock_branding_enabled)
63 : is_smartlock_branding_enabled_(is_smartlock_branding_enabled) {
64 // TODO(melandory): Add histograms, crbug.com/577129
65 passwords_state_.set_client(
66 ChromePasswordManagerClient::FromWebContents(web_contents));
67 passwords_state_.OnUpdatePassword(std::move(form_to_update));
68 }
69
70 infobars::InfoBarDelegate::InfoBarIdentifier
71 UpdatePasswordInfoBarDelegate::GetIdentifier() const {
72 return UPDATE_PASSWORD_INFOBAR_DELEGATE;
73 }
74
75 base::string16 UpdatePasswordInfoBarDelegate::GetButtonLabel(
76 InfoBarButton button) const {
77 return l10n_util::GetStringUTF16((button == BUTTON_OK)
78 ? IDS_PASSWORD_MANAGER_UPDATE_BUTTON
79 : IDS_PASSWORD_MANAGER_CANCEL_BUTTON);
80 }
81
82 bool UpdatePasswordInfoBarDelegate::Accept() {
83 UpdatePasswordInfoBar* update_password_infobar =
84 static_cast<UpdatePasswordInfoBar*>(infobar());
85 password_manager::PasswordFormManager* form_manager =
86 passwords_state_.form_manager();
87 if (ShowMultipleAccounts()) {
88 int form_index = update_password_infobar->GetIdOfSelectedUsername();
89 DCHECK_GE(form_index, 0);
90 DCHECK_LT(static_cast<size_t>(form_index), GetCurrentForms().size());
91 form_manager->Update(*GetCurrentForms()[form_index]);
92 } else {
93 form_manager->Update(form_manager->pending_credentials());
94 }
95 return true;
96 }
97
98 bool UpdatePasswordInfoBarDelegate::Cancel() {
99 return true;
100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698