| 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 11 matching lines...) Expand all Loading... |
| 30 } // namespace | 32 } // namespace |
| 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); |
| 42 Profile* profile = |
| 43 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 40 SavePasswordInfoBarDelegate* infobar_delegate = | 44 SavePasswordInfoBarDelegate* infobar_delegate = |
| 41 new SavePasswordInfoBarDelegate( | 45 new SavePasswordInfoBarDelegate( |
| 42 form_to_save.Pass(), uma_histogram_suffix, source_type); | 46 form_to_save.Pass(), uma_histogram_suffix, source_type, |
| 47 password_bubble_experiment::IsEnabledSmartLockBranding(profile)); |
| 43 #if defined(OS_ANDROID) | 48 #if defined(OS_ANDROID) |
| 44 // For Android in case of smart lock we need different appearance of infobar. | 49 // For Android in case of smart lock we need different appearance of infobar. |
| 45 scoped_ptr<infobars::InfoBar> infobar = | 50 scoped_ptr<infobars::InfoBar> infobar = |
| 46 make_scoped_ptr(new SavePasswordInfoBar( | 51 make_scoped_ptr(new SavePasswordInfoBar( |
| 47 scoped_ptr<SavePasswordInfoBarDelegate>(infobar_delegate))); | 52 scoped_ptr<SavePasswordInfoBarDelegate>(infobar_delegate))); |
| 48 #else | 53 #else |
| 49 // For desktop we'll keep using the ConfirmInfobar. | 54 // For desktop we'll keep using the ConfirmInfobar. |
| 50 scoped_ptr<infobars::InfoBar> infobar(infobar_service->CreateConfirmInfoBar( | 55 scoped_ptr<infobars::InfoBar> infobar(infobar_service->CreateConfirmInfoBar( |
| 51 scoped_ptr<ConfirmInfoBarDelegate>(infobar_delegate))); | 56 scoped_ptr<ConfirmInfoBarDelegate>(infobar_delegate))); |
| 52 #endif | 57 #endif |
| (...skipping 21 matching lines...) Expand all Loading... |
| 74 password_manager::metrics_util::LogUMAHistogramBoolean( | 79 password_manager::metrics_util::LogUMAHistogramBoolean( |
| 75 "PasswordManager.SavePasswordPromptDisappearedQuickly_" + | 80 "PasswordManager.SavePasswordPromptDisappearedQuickly_" + |
| 76 uma_histogram_suffix_, | 81 uma_histogram_suffix_, |
| 77 timer_.Elapsed() < kMinimumPromptDisplayTime); | 82 timer_.Elapsed() < kMinimumPromptDisplayTime); |
| 78 } | 83 } |
| 79 } | 84 } |
| 80 | 85 |
| 81 SavePasswordInfoBarDelegate::SavePasswordInfoBarDelegate( | 86 SavePasswordInfoBarDelegate::SavePasswordInfoBarDelegate( |
| 82 scoped_ptr<password_manager::PasswordFormManager> form_to_save, | 87 scoped_ptr<password_manager::PasswordFormManager> form_to_save, |
| 83 const std::string& uma_histogram_suffix, | 88 const std::string& uma_histogram_suffix, |
| 84 password_manager::CredentialSourceType source_type) | 89 password_manager::CredentialSourceType source_type, |
| 90 bool is_smartlock_branding_enabled) |
| 85 : ConfirmInfoBarDelegate(), | 91 : ConfirmInfoBarDelegate(), |
| 86 form_to_save_(form_to_save.Pass()), | 92 form_to_save_(form_to_save.Pass()), |
| 87 infobar_response_(password_manager::metrics_util::NO_RESPONSE), | 93 infobar_response_(password_manager::metrics_util::NO_RESPONSE), |
| 88 uma_histogram_suffix_(uma_histogram_suffix), | 94 uma_histogram_suffix_(uma_histogram_suffix), |
| 89 source_type_(source_type) { | 95 source_type_(source_type) { |
| 90 if (!uma_histogram_suffix_.empty()) { | 96 if (!uma_histogram_suffix_.empty()) { |
| 91 password_manager::metrics_util::LogUMAHistogramBoolean( | 97 password_manager::metrics_util::LogUMAHistogramBoolean( |
| 92 "PasswordManager.SavePasswordPromptDisplayed_" + uma_histogram_suffix_, | 98 "PasswordManager.SavePasswordPromptDisplayed_" + uma_histogram_suffix_, |
| 93 true); | 99 true); |
| 94 } | 100 } |
| 101 int brand_string_id = is_smartlock_branding_enabled |
| 102 ? IDS_PASSWORD_MANAGER_SMART_LOCK |
| 103 : IDS_SAVE_PASSWORD_TITLE_BRAND; |
| 104 title_ = l10n_util::GetStringFUTF16( |
| 105 IDS_SAVE_PASSWORD, l10n_util::GetStringUTF16(brand_string_id)); |
| 95 } | 106 } |
| 96 | 107 |
| 97 bool SavePasswordInfoBarDelegate::ShouldShowMoreButton() { | 108 bool SavePasswordInfoBarDelegate::ShouldShowMoreButton() { |
| 98 return source_type_ == | 109 return source_type_ == |
| 99 password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API; | 110 password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API; |
| 100 } | 111 } |
| 101 | 112 |
| 102 infobars::InfoBarDelegate::Type | 113 infobars::InfoBarDelegate::Type |
| 103 SavePasswordInfoBarDelegate::GetInfoBarType() const { | 114 SavePasswordInfoBarDelegate::GetInfoBarType() const { |
| 104 return PAGE_ACTION_TYPE; | 115 return PAGE_ACTION_TYPE; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 118 return !details.is_redirect && | 129 return !details.is_redirect && |
| 119 infobars::InfoBarDelegate::ShouldExpire(details); | 130 infobars::InfoBarDelegate::ShouldExpire(details); |
| 120 } | 131 } |
| 121 | 132 |
| 122 void SavePasswordInfoBarDelegate::InfoBarDismissed() { | 133 void SavePasswordInfoBarDelegate::InfoBarDismissed() { |
| 123 DCHECK(form_to_save_.get()); | 134 DCHECK(form_to_save_.get()); |
| 124 infobar_response_ = password_manager::metrics_util::INFOBAR_DISMISSED; | 135 infobar_response_ = password_manager::metrics_util::INFOBAR_DISMISSED; |
| 125 } | 136 } |
| 126 | 137 |
| 127 base::string16 SavePasswordInfoBarDelegate::GetMessageText() const { | 138 base::string16 SavePasswordInfoBarDelegate::GetMessageText() const { |
| 128 int brand_string_id = | 139 return title_; |
| 129 (source_type_ == | |
| 130 password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API) | |
| 131 ? IDS_PASSWORD_MANAGER_SMART_LOCK | |
| 132 : IDS_SAVE_PASSWORD_TITLE_BRAND; | |
| 133 return l10n_util::GetStringFUTF16(IDS_SAVE_PASSWORD, | |
| 134 l10n_util::GetStringUTF16(brand_string_id)); | |
| 135 } | 140 } |
| 136 | 141 |
| 137 base::string16 SavePasswordInfoBarDelegate::GetButtonLabel( | 142 base::string16 SavePasswordInfoBarDelegate::GetButtonLabel( |
| 138 InfoBarButton button) const { | 143 InfoBarButton button) const { |
| 139 return l10n_util::GetStringUTF16((button == BUTTON_OK) | 144 return l10n_util::GetStringUTF16((button == BUTTON_OK) |
| 140 ? IDS_PASSWORD_MANAGER_SAVE_BUTTON | 145 ? IDS_PASSWORD_MANAGER_SAVE_BUTTON |
| 141 : GetCancelButtonText(source_type_)); | 146 : GetCancelButtonText(source_type_)); |
| 142 } | 147 } |
| 143 | 148 |
| 144 bool SavePasswordInfoBarDelegate::Accept() { | 149 bool SavePasswordInfoBarDelegate::Accept() { |
| 145 DCHECK(form_to_save_.get()); | 150 DCHECK(form_to_save_.get()); |
| 146 form_to_save_->Save(); | 151 form_to_save_->Save(); |
| 147 infobar_response_ = password_manager::metrics_util::REMEMBER_PASSWORD; | 152 infobar_response_ = password_manager::metrics_util::REMEMBER_PASSWORD; |
| 148 return true; | 153 return true; |
| 149 } | 154 } |
| 150 | 155 |
| 151 bool SavePasswordInfoBarDelegate::Cancel() { | 156 bool SavePasswordInfoBarDelegate::Cancel() { |
| 152 DCHECK(form_to_save_.get()); | 157 DCHECK(form_to_save_.get()); |
| 153 if (source_type_ == | 158 if (source_type_ == |
| 154 password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API) { | 159 password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API) { |
| 155 InfoBarDismissed(); | 160 InfoBarDismissed(); |
| 156 } else { | 161 } else { |
| 157 form_to_save_->PermanentlyBlacklist(); | 162 form_to_save_->PermanentlyBlacklist(); |
| 158 infobar_response_ = password_manager::metrics_util::NEVER_REMEMBER_PASSWORD; | 163 infobar_response_ = password_manager::metrics_util::NEVER_REMEMBER_PASSWORD; |
| 159 } | 164 } |
| 160 return true; | 165 return true; |
| 161 } | 166 } |
| OLD | NEW |