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

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 Profile* profile =
27 Profile::FromBrowserContext(web_contents->GetBrowserContext());
28 sync_driver::SyncService* sync_service =
29 ProfileSyncServiceFactory::GetForProfile(profile);
30 bool is_smartlock_branding_enabled =
31 password_bubble_experiment::IsSmartLockBrandingEnabled(sync_service);
Peter Kasting 2016/02/22 22:38:13 Nit: Could save a couple lines by just inlining:
melandory 2016/02/23 16:35:07 Done.
32 InfoBarService::FromWebContents(web_contents)
33 ->AddInfoBar(make_scoped_ptr(new UpdatePasswordInfoBar(
34 make_scoped_ptr(new UpdatePasswordInfoBarDelegate(
35 web_contents, std::move(form_to_save),
36 is_smartlock_branding_enabled)))));
37 }
38
39 UpdatePasswordInfoBarDelegate::~UpdatePasswordInfoBarDelegate() {}
40
41 bool UpdatePasswordInfoBarDelegate::ShowMultipleAccounts() const {
42 const password_manager::PasswordFormManager* form_manager =
43 passwords_data_.form_manager();
44 bool is_password_overriden =
45 form_manager ? form_manager->password_overridden() : false;
Peter Kasting 2016/02/22 22:38:13 Simpler: const bool is_password_overriden =
melandory 2016/02/23 16:35:07 Done.
46 return GetCurrentForms().size() > 1 && !is_password_overriden;
47 }
48
49 const std::vector<const autofill::PasswordForm*>&
50 UpdatePasswordInfoBarDelegate::GetCurrentForms() const {
51 return passwords_data_.GetCurrentForms();
52 }
53
54 base::string16
55 UpdatePasswordInfoBarDelegate::GetUsernameForSingleAccountCase() {
56 password_manager::PasswordFormManager* form_manager =
57 passwords_data_.form_manager();
58 return form_manager->pending_credentials().username_value;
Peter Kasting 2016/02/22 22:38:13 Nit: Just inline: return passwords_data_.form_m
melandory 2016/02/23 16:35:07 Done.
59 }
60
61 UpdatePasswordInfoBarDelegate::UpdatePasswordInfoBarDelegate(
62 content::WebContents* web_contents,
63 scoped_ptr<password_manager::PasswordFormManager> form_to_update,
64 bool is_smartlock_branding_enabled)
65 : PasswordManagerInfoBarDelegate(),
Peter Kasting 2016/02/22 22:38:13 Nit: Explicit call to parent null constructor not
melandory 2016/02/23 16:35:07 Done.
66 is_smartlock_branding_enabled_(is_smartlock_branding_enabled) {
67 // TODO(crbug.com/577129): Add histograms.
Peter Kasting 2016/02/22 22:38:13 Nit: TODO form is to list a username in the parens
melandory 2016/02/23 16:35:07 Done.
68 passwords_data_.set_client(
69 ChromePasswordManagerClient::FromWebContents(web_contents));
70 passwords_data_.OnUpdatePassword(std::move(form_to_update));
71 branding_ = l10n_util::GetStringUTF16(
Peter Kasting 2016/02/22 22:38:12 Why do we need a member for this? Why not change
melandory 2016/02/23 16:35:07 Done.
72 is_smartlock_branding_enabled
73 ? IDS_PASSWORD_MANAGER_SMART_LOCK_FOR_PASSWORDS
74 : IDS_PASSWORD_MANAGER_TITLE_BRAND);
75 }
76
77 infobars::InfoBarDelegate::InfoBarIdentifier
78 UpdatePasswordInfoBarDelegate::GetIdentifier() const {
79 return UPDATE_PASSWORD_INFOBAR_DELEGATE;
80 }
81
82 base::string16 UpdatePasswordInfoBarDelegate::GetButtonLabel(
83 InfoBarButton button) const {
84 return l10n_util::GetStringUTF16((button == BUTTON_OK)
85 ? IDS_PASSWORD_MANAGER_UPDATE_BUTTON
86 : IDS_PASSWORD_MANAGER_CANCEL_BUTTON);
87 }
88
89 bool UpdatePasswordInfoBarDelegate::Accept() {
90 UpdatePasswordInfoBar* update_password_infobar =
91 static_cast<UpdatePasswordInfoBar*>(infobar());
92 password_manager::PasswordFormManager* form_manager =
93 passwords_data_.form_manager();
94 if (ShowMultipleAccounts()) {
95 int form_index = update_password_infobar->GetIdOfSelectedUsername();
96 DCHECK_GE(form_index, 0);
97 DCHECK_LT(static_cast<size_t>(form_index), GetCurrentForms().size());
98 form_manager->Update(*GetCurrentForms()[form_index]);
99 } else {
100 form_manager->Update(form_manager->pending_credentials());
101 }
102 return true;
103 }
104
105 bool UpdatePasswordInfoBarDelegate::Cancel() {
106 return true;
107 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698