OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/password_manager/save_password_infobar_delegate.h" | 5 #include "chrome/browser/password_manager/save_password_infobar_delegate.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/strings/utf_string_conversions.h" | |
9 #include "chrome/browser/infobars/infobar_service.h" | 8 #include "chrome/browser/infobars/infobar_service.h" |
9 #include "chrome/browser/ui/android/infobars/save_password_infobar.h" | |
10 #include "chrome/grit/chromium_strings.h" | 10 #include "chrome/grit/chromium_strings.h" |
11 #include "chrome/grit/generated_resources.h" | 11 #include "chrome/grit/generated_resources.h" |
12 #include "components/infobars/core/infobar.h" | 12 #include "components/password_manager/core/browser/password_manager_client.h" |
13 #include "components/password_manager/core/browser/password_form_manager.h" | |
14 #include "content/public/browser/navigation_entry.h" | |
15 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
16 #include "grit/theme_resources.h" | 14 #include "grit/theme_resources.h" |
17 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
18 | 16 |
17 namespace { | |
18 | |
19 int GetCancelButtonText(password_manager::CredentialSourceType source_type) { | |
20 return source_type == | |
Bernhard Bauer
2015/03/02 10:28:09
This seems to be indented a bit weirdly... Could y
Mike West
2015/03/02 11:54:27
It's weird enough that I have to assume clang-form
melandory
2015/03/03 11:55:46
Done.
melandory
2015/03/03 11:55:46
Yeah, Mike is right :)
| |
21 password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API | |
22 ? IDS_PASSWORD_MANAGER_SAVE_PASSWORD_SMART_LOCK_NO_THANKS_BUTTON | |
23 : IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON; | |
24 } | |
25 | |
26 } // namespace | |
27 | |
19 // static | 28 // static |
20 void SavePasswordInfoBarDelegate::Create( | 29 void SavePasswordInfoBarDelegate::Create( |
21 content::WebContents* web_contents, | 30 content::WebContents* web_contents, |
22 scoped_ptr<password_manager::PasswordFormManager> form_to_save, | 31 scoped_ptr<password_manager::PasswordFormManager> form_to_save, |
23 const std::string& uma_histogram_suffix) { | 32 const std::string& uma_histogram_suffix, |
33 password_manager::CredentialSourceType source_type) { | |
24 InfoBarService* infobar_service = | 34 InfoBarService* infobar_service = |
25 InfoBarService::FromWebContents(web_contents); | 35 InfoBarService::FromWebContents(web_contents); |
36 #if defined(OS_ANDROID) | |
37 // For android in case of smart lock we need different appearance of | |
Bernhard Bauer
2015/03/02 10:28:09
Nit: Capitalize Android (you're not talking about
melandory
2015/03/03 11:55:46
Done.
| |
38 // save password infobar. | |
39 infobar_service->AddInfoBar(make_scoped_ptr(new SavePasswordInfoBar( | |
40 scoped_ptr<SavePasswordInfoBarDelegate>(new SavePasswordInfoBarDelegate( | |
Bernhard Bauer
2015/03/02 10:28:09
Extract the delegate and the infobar into local va
melandory
2015/03/03 11:55:46
Done.
| |
41 form_to_save.Pass(), uma_histogram_suffix, source_type))))); | |
42 #else | |
43 // For desktop we'll keep using confirm ifobar. | |
Bernhard Bauer
2015/03/02 10:28:09
"[...] the infobar" (with an "n" and an article).
gone
2015/03/02 17:39:38
nit: may as well say ConfirmInfobar since it's a s
melandory
2015/03/03 11:55:46
Done.
melandory
2015/03/03 11:55:46
Done.
| |
26 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( | 44 infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( |
27 scoped_ptr<ConfirmInfoBarDelegate>(new SavePasswordInfoBarDelegate( | 45 scoped_ptr<ConfirmInfoBarDelegate>(new SavePasswordInfoBarDelegate( |
28 form_to_save.Pass(), uma_histogram_suffix)))); | 46 form_to_save.Pass(), uma_histogram_suffix, source_type)))); |
47 #endif | |
29 } | 48 } |
30 | 49 |
31 SavePasswordInfoBarDelegate::~SavePasswordInfoBarDelegate() { | 50 SavePasswordInfoBarDelegate::~SavePasswordInfoBarDelegate() { |
32 UMA_HISTOGRAM_ENUMERATION("PasswordManager.InfoBarResponse", | 51 UMA_HISTOGRAM_ENUMERATION("PasswordManager.InfoBarResponse", |
33 infobar_response_, | 52 infobar_response_, |
34 password_manager::metrics_util::NUM_RESPONSE_TYPES); | 53 password_manager::metrics_util::NUM_RESPONSE_TYPES); |
35 | 54 |
36 password_manager::metrics_util::LogUIDismissalReason(infobar_response_); | 55 password_manager::metrics_util::LogUIDismissalReason(infobar_response_); |
37 | 56 |
38 // The shortest period for which the prompt needs to live, so that we don't | 57 // The shortest period for which the prompt needs to live, so that we don't |
39 // consider it killed prematurely, as might happen, e.g., if a pre-rendered | 58 // consider it killed prematurely, as might happen, e.g., if a pre-rendered |
40 // page gets swapped in (and the current WebContents is destroyed). | 59 // page gets swapped in (and the current WebContents is destroyed). |
41 const base::TimeDelta kMinimumPromptDisplayTime = | 60 const base::TimeDelta kMinimumPromptDisplayTime = |
42 base::TimeDelta::FromSeconds(1); | 61 base::TimeDelta::FromSeconds(1); |
43 | 62 |
44 if (!uma_histogram_suffix_.empty()) { | 63 if (!uma_histogram_suffix_.empty()) { |
45 password_manager::metrics_util::LogUMAHistogramEnumeration( | 64 password_manager::metrics_util::LogUMAHistogramEnumeration( |
46 "PasswordManager.SavePasswordPromptResponse_" + uma_histogram_suffix_, | 65 "PasswordManager.SavePasswordPromptResponse_" + uma_histogram_suffix_, |
47 infobar_response_, | 66 infobar_response_, |
48 password_manager::metrics_util::NUM_RESPONSE_TYPES); | 67 password_manager::metrics_util::NUM_RESPONSE_TYPES); |
49 password_manager::metrics_util::LogUMAHistogramBoolean( | 68 password_manager::metrics_util::LogUMAHistogramBoolean( |
50 "PasswordManager.SavePasswordPromptDisappearedQuickly_" + | 69 "PasswordManager.SavePasswordPromptDisappearedQuickly_" + |
51 uma_histogram_suffix_, | 70 uma_histogram_suffix_, |
52 timer_.Elapsed() < kMinimumPromptDisplayTime); | 71 timer_.Elapsed() < kMinimumPromptDisplayTime); |
53 } | 72 } |
54 } | 73 } |
55 | 74 |
56 SavePasswordInfoBarDelegate::SavePasswordInfoBarDelegate( | 75 SavePasswordInfoBarDelegate::SavePasswordInfoBarDelegate( |
57 scoped_ptr<password_manager::PasswordFormManager> form_to_save, | 76 scoped_ptr<password_manager::PasswordFormManager> form_to_save, |
58 const std::string& uma_histogram_suffix) | 77 const std::string& uma_histogram_suffix, |
78 password_manager::CredentialSourceType source_type) | |
59 : ConfirmInfoBarDelegate(), | 79 : ConfirmInfoBarDelegate(), |
60 form_to_save_(form_to_save.Pass()), | 80 form_to_save_(form_to_save.Pass()), |
61 infobar_response_(password_manager::metrics_util::NO_RESPONSE), | 81 infobar_response_(password_manager::metrics_util::NO_RESPONSE), |
62 uma_histogram_suffix_(uma_histogram_suffix) { | 82 uma_histogram_suffix_(uma_histogram_suffix), |
83 source_type_(source_type) { | |
63 if (!uma_histogram_suffix_.empty()) { | 84 if (!uma_histogram_suffix_.empty()) { |
64 password_manager::metrics_util::LogUMAHistogramBoolean( | 85 password_manager::metrics_util::LogUMAHistogramBoolean( |
65 "PasswordManager.SavePasswordPromptDisplayed_" + uma_histogram_suffix_, | 86 "PasswordManager.SavePasswordPromptDisplayed_" + uma_histogram_suffix_, |
66 true); | 87 true); |
67 } | 88 } |
68 } | 89 } |
69 | 90 |
91 bool SavePasswordInfoBarDelegate::ShouldShowMoreButton() { | |
92 return source_type_ == | |
93 password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API; | |
94 } | |
95 | |
70 infobars::InfoBarDelegate::Type | 96 infobars::InfoBarDelegate::Type |
71 SavePasswordInfoBarDelegate::GetInfoBarType() const { | 97 SavePasswordInfoBarDelegate::GetInfoBarType() const { |
72 return PAGE_ACTION_TYPE; | 98 return PAGE_ACTION_TYPE; |
73 } | 99 } |
74 | 100 |
75 infobars::InfoBarDelegate::InfoBarAutomationType | 101 infobars::InfoBarDelegate::InfoBarAutomationType |
76 SavePasswordInfoBarDelegate::GetInfoBarAutomationType() const { | 102 SavePasswordInfoBarDelegate::GetInfoBarAutomationType() const { |
77 return PASSWORD_INFOBAR; | 103 return PASSWORD_INFOBAR; |
78 } | 104 } |
79 | 105 |
80 int SavePasswordInfoBarDelegate::GetIconID() const { | 106 int SavePasswordInfoBarDelegate::GetIconID() const { |
81 return IDR_INFOBAR_SAVE_PASSWORD; | 107 return IDR_INFOBAR_SAVE_PASSWORD; |
82 } | 108 } |
83 | 109 |
84 bool SavePasswordInfoBarDelegate::ShouldExpire( | 110 bool SavePasswordInfoBarDelegate::ShouldExpire( |
85 const NavigationDetails& details) const { | 111 const NavigationDetails& details) const { |
86 return !details.is_redirect && | 112 return !details.is_redirect && |
87 infobars::InfoBarDelegate::ShouldExpire(details); | 113 infobars::InfoBarDelegate::ShouldExpire(details); |
88 } | 114 } |
89 | 115 |
90 void SavePasswordInfoBarDelegate::InfoBarDismissed() { | 116 void SavePasswordInfoBarDelegate::InfoBarDismissed() { |
91 DCHECK(form_to_save_.get()); | 117 DCHECK(form_to_save_.get()); |
92 infobar_response_ = password_manager::metrics_util::INFOBAR_DISMISSED; | 118 infobar_response_ = password_manager::metrics_util::INFOBAR_DISMISSED; |
93 } | 119 } |
94 | 120 |
95 base::string16 SavePasswordInfoBarDelegate::GetMessageText() const { | 121 base::string16 SavePasswordInfoBarDelegate::GetMessageText() const { |
96 return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_PASSWORD_PROMPT); | 122 return l10n_util::GetStringUTF16( |
123 (source_type_ == | |
124 password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API) | |
125 ? IDS_PASSWORD_MANAGER_SAVE_PASSWORD_SMART_LOCK_PROMPT | |
126 : IDS_PASSWORD_MANAGER_SAVE_PASSWORD_PROMPT); | |
97 } | 127 } |
98 | 128 |
99 base::string16 SavePasswordInfoBarDelegate::GetButtonLabel( | 129 base::string16 SavePasswordInfoBarDelegate::GetButtonLabel( |
100 InfoBarButton button) const { | 130 InfoBarButton button) const { |
101 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? | 131 return l10n_util::GetStringUTF16((button == BUTTON_OK) |
102 IDS_PASSWORD_MANAGER_SAVE_BUTTON : IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON); | 132 ? IDS_PASSWORD_MANAGER_SAVE_BUTTON |
133 : GetCancelButtonText(source_type_)); | |
103 } | 134 } |
104 | 135 |
105 bool SavePasswordInfoBarDelegate::Accept() { | 136 bool SavePasswordInfoBarDelegate::Accept() { |
106 DCHECK(form_to_save_.get()); | 137 DCHECK(form_to_save_.get()); |
107 form_to_save_->Save(); | 138 form_to_save_->Save(); |
108 infobar_response_ = password_manager::metrics_util::REMEMBER_PASSWORD; | 139 infobar_response_ = password_manager::metrics_util::REMEMBER_PASSWORD; |
109 return true; | 140 return true; |
110 } | 141 } |
111 | 142 |
112 bool SavePasswordInfoBarDelegate::Cancel() { | 143 bool SavePasswordInfoBarDelegate::Cancel() { |
113 DCHECK(form_to_save_.get()); | 144 DCHECK(form_to_save_.get()); |
114 form_to_save_->PermanentlyBlacklist(); | 145 if (source_type_ == |
115 infobar_response_ = password_manager::metrics_util::NEVER_REMEMBER_PASSWORD; | 146 password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API) { |
147 form_to_save_->PermanentlyBlacklist(); | |
148 infobar_response_ = password_manager::metrics_util::NEVER_REMEMBER_PASSWORD; | |
149 } else { | |
150 InfoBarDismissed(); | |
151 } | |
116 return true; | 152 return true; |
117 } | 153 } |
OLD | NEW |