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

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, 11 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 "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 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 content::WebContents* web_contents,
41 scoped_ptr<password_manager::PasswordFormManager> form_to_update,
42 bool is_smartlock_branding_enabled)
43 : PasswordManagerInfoBarDelegate(),
44 is_smartlock_branding_enabled_(is_smartlock_branding_enabled) {
45 // TODO(crbug.com/577129): Add histograms.
46 passwords_data_.set_client(
47 ChromePasswordManagerClient::FromWebContents(web_contents));
48 passwords_data_.OnUpdatePassword(std::move(form_to_update));
49 if (is_smartlock_branding_enabled) {
50 base::string16 branding_ = l10n_util::GetStringUTF16(
51 IDS_PASSWORD_MANAGER_SMART_LOCK_FOR_PASSWORDS);
52 } else {
53 branding_ = l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_TITLE_BRAND);
54 }
55 }
56
57 UpdatePasswordInfoBarDelegate::~UpdatePasswordInfoBarDelegate() {}
58
59 bool UpdatePasswordInfoBarDelegate::ShowMultipleAccounts() const {
60 const password_manager::PasswordFormManager* form_manager =
61 passwords_data_.form_manager();
62 bool is_password_overriden =
63 form_manager ? form_manager->password_overridden() : false;
64 return GetCurrentForms().size() > 1 && !is_password_overriden;
65 }
66
67 base::string16 UpdatePasswordInfoBarDelegate::GetUsernameForOneAccountCase() {
68 password_manager::PasswordFormManager* form_manager =
69 passwords_data_.form_manager();
70 return form_manager->pending_credentials().username_value;
71 }
72
73 void UpdatePasswordInfoBarDelegate::UpdatePasswordInternal(int form_index) {
74 password_manager::PasswordFormManager* form_manager =
75 passwords_data_.form_manager();
76 if (form_index && ShowMultipleAccounts()) {
77 CHECK_GT(GetCurrentForms().size(), static_cast<unsigned int>(form_index));
vabr (Chromium) 2016/01/13 16:04:34 Instead of static_cast, please do a checked_cast (
vabr (Chromium) 2016/01/13 16:04:34 Please do an explicit CHECK_LE(0, form_index); to
78 form_manager->Update(*GetCurrentForms()[form_index]);
79 } else {
80 form_manager->Update(form_manager->pending_credentials());
81 }
82 }
83
84 infobars::InfoBarDelegate::InfoBarIdentifier
85 UpdatePasswordInfoBarDelegate::GetIdentifier() const {
86 return UPDATE_PASSWORD_INFOBAR_DELEGATE;
87 }
88
89 base::string16 UpdatePasswordInfoBarDelegate::GetButtonLabel(
90 InfoBarButton button) const {
91 return l10n_util::GetStringUTF16((button == BUTTON_OK)
92 ? IDS_PASSWORD_MANAGER_UPDATE_BUTTON
93 : IDS_PASSWORD_MANAGER_CANCEL_BUTTON);
94 }
95
96 bool UpdatePasswordInfoBarDelegate::Accept() {
97 CHECK(!ShowMultipleAccounts());
98 UpdatePasswordInternal(
vabr (Chromium) 2016/01/13 16:04:34 Please create a separate method, e.g. UpdatePasswo
99 -1 /* special case with only one pending credentials */);
100 return true;
101 }
102
103 bool UpdatePasswordInfoBarDelegate::Cancel() {
104 return true;
105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698