OLD | NEW |
---|---|
(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/auto_signin_first_run_infobar.h" | |
13 #include "chrome/browser/ui/android/infobars/update_password_infobar.h" | |
14 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" | |
15 #include "chrome/grit/chromium_strings.h" | |
16 #include "chrome/grit/generated_resources.h" | |
17 #include "components/browser_sync/browser/profile_sync_service.h" | |
18 #include "components/infobars/core/infobar.h" | |
19 #include "components/password_manager/core/browser/password_bubble_experiment.h" | |
20 #include "content/public/browser/web_contents.h" | |
21 #include "ui/base/l10n/l10n_util.h" | |
22 | |
23 // static | |
24 void UpdatePasswordInfoBarDelegate::Create( | |
25 content::WebContents* web_contents, | |
26 scoped_ptr<password_manager::PasswordFormManager> form_to_save) { | |
27 Profile* profile = | |
28 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | |
29 sync_driver::SyncService* sync_service = | |
30 ProfileSyncServiceFactory::GetForProfile(profile); | |
31 bool is_smartlock_branding_enabled = | |
32 password_bubble_experiment::IsSmartLockBrandingEnabled(sync_service); | |
33 InfoBarService::FromWebContents(web_contents) | |
34 ->AddInfoBar(make_scoped_ptr(new UpdatePasswordInfoBar( | |
35 make_scoped_ptr(new UpdatePasswordInfoBarDelegate( | |
36 web_contents, std::move(form_to_save), | |
37 is_smartlock_branding_enabled))))); | |
38 } | |
39 | |
40 UpdatePasswordInfoBarDelegate::UpdatePasswordInfoBarDelegate( | |
41 content::WebContents* web_contents, | |
42 scoped_ptr<password_manager::PasswordFormManager> form_to_update, | |
43 bool is_smartlock_branding_enabled) | |
44 : PasswordManagerInfoBarDelegate(), | |
45 is_smartlock_branding_enabled_(is_smartlock_branding_enabled) { | |
46 // TODO(crbug.com/577129): Add histograms. | |
47 passwords_data_.set_client( | |
48 ChromePasswordManagerClient::FromWebContents(web_contents)); | |
49 passwords_data_.OnUpdatePassword(std::move(form_to_update)); | |
50 if (is_smartlock_branding_enabled) { | |
51 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.
| |
52 IDS_PASSWORD_MANAGER_SMART_LOCK_FOR_PASSWORDS); | |
53 } else { | |
54 branding_ = l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_TITLE_BRAND); | |
55 } | |
Peter Kasting
2016/02/03 00:56:26
Nit: Shorter:
branding_ = l10n_util::GetStringU
melandory
2016/02/12 19:19:36
Done.
| |
56 } | |
57 | |
58 UpdatePasswordInfoBarDelegate::~UpdatePasswordInfoBarDelegate() {} | |
59 | |
60 bool UpdatePasswordInfoBarDelegate::ShowMultipleAccounts() const { | |
61 const password_manager::PasswordFormManager* form_manager = | |
62 passwords_data_.form_manager(); | |
63 bool is_password_overriden = | |
64 form_manager ? form_manager->password_overridden() : false; | |
65 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
| |
66 } | |
67 | |
68 base::string16 UpdatePasswordInfoBarDelegate::GetUsernameForOneAccountCase() { | |
69 password_manager::PasswordFormManager* form_manager = | |
70 passwords_data_.form_manager(); | |
71 return form_manager->pending_credentials().username_value; | |
72 } | |
73 | |
74 infobars::InfoBarDelegate::InfoBarIdentifier | |
75 UpdatePasswordInfoBarDelegate::GetIdentifier() const { | |
76 return UPDATE_PASSWORD_INFOBAR_DELEGATE; | |
77 } | |
78 | |
79 base::string16 UpdatePasswordInfoBarDelegate::GetButtonLabel( | |
80 InfoBarButton button) const { | |
81 return l10n_util::GetStringUTF16((button == BUTTON_OK) | |
82 ? IDS_PASSWORD_MANAGER_UPDATE_BUTTON | |
83 : IDS_PASSWORD_MANAGER_CANCEL_BUTTON); | |
84 } | |
85 | |
86 bool UpdatePasswordInfoBarDelegate::Accept() { | |
87 UpdatePasswordInfoBar* update_password_infobar = | |
88 static_cast<UpdatePasswordInfoBar*>(infobar()); | |
89 UpdatePassword(update_password_infobar->GetIdOfSelectedUsername()); | |
90 return true; | |
91 } | |
92 | |
93 bool UpdatePasswordInfoBarDelegate::Cancel() { | |
94 return true; | |
95 } | |
96 | |
97 void UpdatePasswordInfoBarDelegate::UpdatePassword(int form_index) { | |
98 if (ShowMultipleAccounts()) | |
99 UpdatePasswordWithCurrentForm(form_index); | |
100 else | |
101 UpdatePasswordWithPending(); | |
102 } | |
103 | |
104 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.
| |
105 int form_index) { | |
106 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.
| |
107 GetCurrentForms().size()); | |
108 password_manager::PasswordFormManager* form_manager = | |
109 passwords_data_.form_manager(); | |
110 form_manager->Update(*GetCurrentForms()[form_index]); | |
111 } | |
112 | |
113 void UpdatePasswordInfoBarDelegate::UpdatePasswordWithPending() { | |
114 password_manager::PasswordFormManager* form_manager = | |
115 passwords_data_.form_manager(); | |
116 form_manager->Update(form_manager->pending_credentials()); | |
117 } | |
OLD | NEW |