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 "chrome/browser/infobars/infobar_service.h" | 8 #include "chrome/browser/infobars/infobar_service.h" |
9 #include "chrome/browser/profiles/profile.h" | |
10 #include "chrome/browser/ui/passwords/password_bubble_experiment.h" | |
9 #include "chrome/grit/chromium_strings.h" | 11 #include "chrome/grit/chromium_strings.h" |
10 #include "chrome/grit/generated_resources.h" | 12 #include "chrome/grit/generated_resources.h" |
11 #include "components/infobars/core/infobar.h" | 13 #include "components/infobars/core/infobar.h" |
12 #include "components/password_manager/core/browser/password_manager_client.h" | 14 #include "components/password_manager/core/browser/password_manager_client.h" |
13 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
14 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
15 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
16 | 18 |
17 #if defined(OS_ANDROID) | 19 #if defined(OS_ANDROID) |
18 #include "chrome/browser/ui/android/infobars/save_password_infobar.h" | 20 #include "chrome/browser/ui/android/infobars/save_password_infobar.h" |
(...skipping 12 matching lines...) Expand all Loading... | |
31 | 33 |
32 // static | 34 // static |
33 void SavePasswordInfoBarDelegate::Create( | 35 void SavePasswordInfoBarDelegate::Create( |
34 content::WebContents* web_contents, | 36 content::WebContents* web_contents, |
35 scoped_ptr<password_manager::PasswordFormManager> form_to_save, | 37 scoped_ptr<password_manager::PasswordFormManager> form_to_save, |
36 const std::string& uma_histogram_suffix, | 38 const std::string& uma_histogram_suffix, |
37 password_manager::CredentialSourceType source_type) { | 39 password_manager::CredentialSourceType source_type) { |
38 InfoBarService* infobar_service = | 40 InfoBarService* infobar_service = |
39 InfoBarService::FromWebContents(web_contents); | 41 InfoBarService::FromWebContents(web_contents); |
40 SavePasswordInfoBarDelegate* infobar_delegate = | 42 SavePasswordInfoBarDelegate* infobar_delegate = |
41 new SavePasswordInfoBarDelegate( | 43 new SavePasswordInfoBarDelegate(web_contents, form_to_save.Pass(), |
42 form_to_save.Pass(), uma_histogram_suffix, source_type); | 44 uma_histogram_suffix, source_type); |
43 #if defined(OS_ANDROID) | 45 #if defined(OS_ANDROID) |
44 // For Android in case of smart lock we need different appearance of infobar. | 46 // For Android in case of smart lock we need different appearance of infobar. |
45 scoped_ptr<infobars::InfoBar> infobar = | 47 scoped_ptr<infobars::InfoBar> infobar = |
46 make_scoped_ptr(new SavePasswordInfoBar( | 48 make_scoped_ptr(new SavePasswordInfoBar( |
47 scoped_ptr<SavePasswordInfoBarDelegate>(infobar_delegate))); | 49 scoped_ptr<SavePasswordInfoBarDelegate>(infobar_delegate))); |
48 #else | 50 #else |
49 // For desktop we'll keep using the ConfirmInfobar. | 51 // For desktop we'll keep using the ConfirmInfobar. |
50 scoped_ptr<infobars::InfoBar> infobar(infobar_service->CreateConfirmInfoBar( | 52 scoped_ptr<infobars::InfoBar> infobar(infobar_service->CreateConfirmInfoBar( |
51 scoped_ptr<ConfirmInfoBarDelegate>(infobar_delegate))); | 53 scoped_ptr<ConfirmInfoBarDelegate>(infobar_delegate))); |
52 #endif | 54 #endif |
(...skipping 19 matching lines...) Expand all Loading... | |
72 infobar_response_, | 74 infobar_response_, |
73 password_manager::metrics_util::NUM_RESPONSE_TYPES); | 75 password_manager::metrics_util::NUM_RESPONSE_TYPES); |
74 password_manager::metrics_util::LogUMAHistogramBoolean( | 76 password_manager::metrics_util::LogUMAHistogramBoolean( |
75 "PasswordManager.SavePasswordPromptDisappearedQuickly_" + | 77 "PasswordManager.SavePasswordPromptDisappearedQuickly_" + |
76 uma_histogram_suffix_, | 78 uma_histogram_suffix_, |
77 timer_.Elapsed() < kMinimumPromptDisplayTime); | 79 timer_.Elapsed() < kMinimumPromptDisplayTime); |
78 } | 80 } |
79 } | 81 } |
80 | 82 |
81 SavePasswordInfoBarDelegate::SavePasswordInfoBarDelegate( | 83 SavePasswordInfoBarDelegate::SavePasswordInfoBarDelegate( |
84 content::WebContents* web_contents, | |
82 scoped_ptr<password_manager::PasswordFormManager> form_to_save, | 85 scoped_ptr<password_manager::PasswordFormManager> form_to_save, |
83 const std::string& uma_histogram_suffix, | 86 const std::string& uma_histogram_suffix, |
84 password_manager::CredentialSourceType source_type) | 87 password_manager::CredentialSourceType source_type) |
85 : ConfirmInfoBarDelegate(), | 88 : ConfirmInfoBarDelegate(), |
86 form_to_save_(form_to_save.Pass()), | 89 form_to_save_(form_to_save.Pass()), |
87 infobar_response_(password_manager::metrics_util::NO_RESPONSE), | 90 infobar_response_(password_manager::metrics_util::NO_RESPONSE), |
88 uma_histogram_suffix_(uma_histogram_suffix), | 91 uma_histogram_suffix_(uma_histogram_suffix), |
89 source_type_(source_type) { | 92 source_type_(source_type), |
93 web_contents_(web_contents) { | |
90 if (!uma_histogram_suffix_.empty()) { | 94 if (!uma_histogram_suffix_.empty()) { |
91 password_manager::metrics_util::LogUMAHistogramBoolean( | 95 password_manager::metrics_util::LogUMAHistogramBoolean( |
92 "PasswordManager.SavePasswordPromptDisplayed_" + uma_histogram_suffix_, | 96 "PasswordManager.SavePasswordPromptDisplayed_" + uma_histogram_suffix_, |
93 true); | 97 true); |
94 } | 98 } |
95 } | 99 } |
96 | 100 |
97 bool SavePasswordInfoBarDelegate::ShouldShowMoreButton() { | 101 bool SavePasswordInfoBarDelegate::ShouldShowMoreButton() { |
98 return source_type_ == | 102 return source_type_ == |
99 password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API; | 103 password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API; |
(...skipping 18 matching lines...) Expand all Loading... | |
118 return !details.is_redirect && | 122 return !details.is_redirect && |
119 infobars::InfoBarDelegate::ShouldExpire(details); | 123 infobars::InfoBarDelegate::ShouldExpire(details); |
120 } | 124 } |
121 | 125 |
122 void SavePasswordInfoBarDelegate::InfoBarDismissed() { | 126 void SavePasswordInfoBarDelegate::InfoBarDismissed() { |
123 DCHECK(form_to_save_.get()); | 127 DCHECK(form_to_save_.get()); |
124 infobar_response_ = password_manager::metrics_util::INFOBAR_DISMISSED; | 128 infobar_response_ = password_manager::metrics_util::INFOBAR_DISMISSED; |
125 } | 129 } |
126 | 130 |
127 base::string16 SavePasswordInfoBarDelegate::GetMessageText() const { | 131 base::string16 SavePasswordInfoBarDelegate::GetMessageText() const { |
128 int brand_string_id = | 132 int brand_string_id = IDS_SAVE_PASSWORD_TITLE_BRAND; |
129 (source_type_ == | 133 Profile* profile = |
130 password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API) | 134 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
131 ? IDS_PASSWORD_MANAGER_SMART_LOCK | 135 if (source_type_ == |
132 : IDS_SAVE_PASSWORD_TITLE_BRAND; | 136 password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API || |
vabr (Chromium)
2015/05/11 15:29:10
Did you mean && instead of ||?
(At least that's wh
Mike West
2015/05/11 15:51:48
Moreover, why are we changing the branding based o
melandory
2015/05/12 09:07:23
I meant || here. Because my understanding was that
| |
137 password_bubble_experiment::IsEnabledSmartLockBranding(profile)) { | |
138 brand_string_id = IDS_PASSWORD_MANAGER_SMART_LOCK; | |
139 } | |
133 return l10n_util::GetStringFUTF16(IDS_SAVE_PASSWORD, | 140 return l10n_util::GetStringFUTF16(IDS_SAVE_PASSWORD, |
134 l10n_util::GetStringUTF16(brand_string_id)); | 141 l10n_util::GetStringUTF16(brand_string_id)); |
135 } | 142 } |
136 | 143 |
137 base::string16 SavePasswordInfoBarDelegate::GetButtonLabel( | 144 base::string16 SavePasswordInfoBarDelegate::GetButtonLabel( |
138 InfoBarButton button) const { | 145 InfoBarButton button) const { |
139 return l10n_util::GetStringUTF16((button == BUTTON_OK) | 146 return l10n_util::GetStringUTF16((button == BUTTON_OK) |
140 ? IDS_PASSWORD_MANAGER_SAVE_BUTTON | 147 ? IDS_PASSWORD_MANAGER_SAVE_BUTTON |
141 : GetCancelButtonText(source_type_)); | 148 : GetCancelButtonText(source_type_)); |
142 } | 149 } |
143 | 150 |
144 bool SavePasswordInfoBarDelegate::Accept() { | 151 bool SavePasswordInfoBarDelegate::Accept() { |
145 DCHECK(form_to_save_.get()); | 152 DCHECK(form_to_save_.get()); |
146 form_to_save_->Save(); | 153 form_to_save_->Save(); |
147 infobar_response_ = password_manager::metrics_util::REMEMBER_PASSWORD; | 154 infobar_response_ = password_manager::metrics_util::REMEMBER_PASSWORD; |
148 return true; | 155 return true; |
149 } | 156 } |
150 | 157 |
151 bool SavePasswordInfoBarDelegate::Cancel() { | 158 bool SavePasswordInfoBarDelegate::Cancel() { |
152 DCHECK(form_to_save_.get()); | 159 DCHECK(form_to_save_.get()); |
153 if (source_type_ == | 160 if (source_type_ == |
154 password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API) { | 161 password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API) { |
155 InfoBarDismissed(); | 162 InfoBarDismissed(); |
156 } else { | 163 } else { |
157 form_to_save_->PermanentlyBlacklist(); | 164 form_to_save_->PermanentlyBlacklist(); |
158 infobar_response_ = password_manager::metrics_util::NEVER_REMEMBER_PASSWORD; | 165 infobar_response_ = password_manager::metrics_util::NEVER_REMEMBER_PASSWORD; |
159 } | 166 } |
160 return true; | 167 return true; |
161 } | 168 } |
OLD | NEW |