OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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 "chrome/browser/infobars/infobar_service.h" | |
8 #include "chrome/browser/password_manager/chrome_password_manager_client.h" | |
9 #include "chrome/browser/profiles/profile.h" | |
10 #include "chrome/browser/sync/profile_sync_service_factory.h" | |
11 #include "chrome/browser/ui/android/infobars/auto_signin_first_run_infobar.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); | |
32 UpdatePasswordInfoBarDelegate* update_password_infobar_delegate = | |
vabr (Chromium)
2016/01/13 09:44:45
Please make this a scoped_ptr instead of waiting u
melandory
2016/01/13 15:11:36
With scoped ptr it's too long in my taste. I'd bet
vabr (Chromium)
2016/01/13 16:04:34
Your inlining looks good to me. Just as an alterna
| |
33 new UpdatePasswordInfoBarDelegate(web_contents, std::move(form_to_save), | |
34 is_smartlock_branding_enabled); | |
35 InfoBarService::FromWebContents(web_contents) | |
36 ->AddInfoBar(make_scoped_ptr(new UpdatePasswordInfoBar( | |
37 make_scoped_ptr(update_password_infobar_delegate)))); | |
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(melandory): Add histograms. | |
vabr (Chromium)
2016/01/13 09:44:45
optional: It is better to create a bug for the TOD
melandory
2016/01/13 15:11:36
Done.
| |
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( | |
52 IDS_PASSWORD_MANAGER_SMART_LOCK_FOR_PASSWORDS); | |
53 } else { | |
54 branding_ = l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_TITLE_BRAND); | |
55 } | |
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; | |
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 void UpdatePasswordInfoBarDelegate::UpdatePasswordInternal( | |
75 unsigned int form_index) { | |
76 if (ShowMultipleAccounts()) { | |
77 CHECK_GE(GetCurrentForms().size(), form_index); // +-1 error; | |
vabr (Chromium)
2016/01/13 09:44:45
Should this be CHECK_GT? I don't think form_index
melandory
2016/01/13 15:11:36
My comment is actually saying that I should change
| |
78 password_manager::PasswordFormManager* form_manager = | |
79 passwords_data_.form_manager(); | |
80 | |
81 form_manager->Update(*GetCurrentForms()[form_index]); | |
82 } | |
83 } | |
84 | |
85 infobars::InfoBarDelegate::InfoBarIdentifier | |
86 UpdatePasswordInfoBarDelegate::GetIdentifier() const { | |
87 return UPDATE_PASSWORD_INFOBAR_DELEGATE; | |
88 } | |
89 | |
90 base::string16 UpdatePasswordInfoBarDelegate::GetButtonLabel( | |
91 InfoBarButton button) const { | |
92 return l10n_util::GetStringUTF16((button == BUTTON_OK) | |
93 ? IDS_PASSWORD_MANAGER_UPDATE_BUTTON | |
94 : IDS_PASSWORD_MANAGER_CANCEL_BUTTON); | |
95 } | |
96 | |
97 bool UpdatePasswordInfoBarDelegate::Accept() { | |
98 password_manager::PasswordFormManager* form_manager = | |
99 passwords_data_.form_manager(); | |
100 if (!ShowMultipleAccounts()) | |
vabr (Chromium)
2016/01/13 09:44:45
nit: Add a comment explaining what happens if Show
melandory
2016/01/13 15:11:36
I also change a code a bit, so it reflects the upd
| |
101 form_manager->Update(form_manager->pending_credentials()); | |
102 return true; | |
103 } | |
104 | |
105 bool UpdatePasswordInfoBarDelegate::Cancel() { | |
106 return true; | |
107 } | |
OLD | NEW |