Index: chrome/browser/password_manager/save_password_infobar_delegate.cc |
diff --git a/chrome/browser/password_manager/save_password_infobar_delegate.cc b/chrome/browser/password_manager/save_password_infobar_delegate.cc |
index ef4836ad478e2e79843880d45978de3cad24925c..3744837ebdaed4d8d09418694d57cf1259d6cd0f 100644 |
--- a/chrome/browser/password_manager/save_password_infobar_delegate.cc |
+++ b/chrome/browser/password_manager/save_password_infobar_delegate.cc |
@@ -5,27 +5,48 @@ |
#include "chrome/browser/password_manager/save_password_infobar_delegate.h" |
#include "base/metrics/histogram.h" |
-#include "base/strings/utf_string_conversions.h" |
#include "chrome/browser/infobars/infobar_service.h" |
+#include "chrome/browser/ui/android/infobars/save_password_infobar.h" |
#include "chrome/grit/chromium_strings.h" |
#include "chrome/grit/generated_resources.h" |
-#include "components/infobars/core/infobar.h" |
-#include "components/password_manager/core/browser/password_form_manager.h" |
-#include "content/public/browser/navigation_entry.h" |
+#include "components/password_manager/core/browser/password_manager_client.h" |
#include "content/public/browser/web_contents.h" |
#include "grit/theme_resources.h" |
#include "ui/base/l10n/l10n_util.h" |
+namespace { |
+ |
+int GetCancelButtonText(password_manager::CredentialSourceType source_type) { |
+ return source_type == |
+ password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API |
+ ? IDS_PASSWORD_MANAGER_SAVE_PASSWORD_SMART_LOCK_NO_THANKS_BUTTON |
+ : IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON; |
+} |
+ |
+} // namespace |
+ |
// static |
void SavePasswordInfoBarDelegate::Create( |
content::WebContents* web_contents, |
scoped_ptr<password_manager::PasswordFormManager> form_to_save, |
- const std::string& uma_histogram_suffix) { |
+ const std::string& uma_histogram_suffix, |
+ password_manager::CredentialSourceType source_type) { |
InfoBarService* infobar_service = |
InfoBarService::FromWebContents(web_contents); |
- infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( |
- scoped_ptr<ConfirmInfoBarDelegate>(new SavePasswordInfoBarDelegate( |
- form_to_save.Pass(), uma_histogram_suffix)))); |
+ SavePasswordInfoBarDelegate* infobar_delegate = |
+ new SavePasswordInfoBarDelegate( |
+ form_to_save.Pass(), uma_histogram_suffix, source_type); |
+#if defined(OS_ANDROID) |
+ // For Android in case of smart lock we need different appearance of infobar. |
+ scoped_ptr<infobars::InfoBar> infobar = |
+ make_scoped_ptr(new SavePasswordInfoBar( |
+ scoped_ptr<SavePasswordInfoBarDelegate>(infobar_delegate))); |
+#else |
+ // For desktop we'll keep using the ConfirmInfobar. |
+ scoped_ptr<infobars::InfoBar> infobar = infobar_service->CreateConfirmInfoBar( |
+ scoped_ptr<ConfirmInfoBarDelegate>(infobar_delegate)); |
+#endif |
+ infobar_service->AddInfoBar(infobar.Pass()); |
} |
SavePasswordInfoBarDelegate::~SavePasswordInfoBarDelegate() { |
@@ -55,11 +76,13 @@ SavePasswordInfoBarDelegate::~SavePasswordInfoBarDelegate() { |
SavePasswordInfoBarDelegate::SavePasswordInfoBarDelegate( |
scoped_ptr<password_manager::PasswordFormManager> form_to_save, |
- const std::string& uma_histogram_suffix) |
+ const std::string& uma_histogram_suffix, |
+ password_manager::CredentialSourceType source_type) |
: ConfirmInfoBarDelegate(), |
form_to_save_(form_to_save.Pass()), |
infobar_response_(password_manager::metrics_util::NO_RESPONSE), |
- uma_histogram_suffix_(uma_histogram_suffix) { |
+ uma_histogram_suffix_(uma_histogram_suffix), |
+ source_type_(source_type) { |
if (!uma_histogram_suffix_.empty()) { |
password_manager::metrics_util::LogUMAHistogramBoolean( |
"PasswordManager.SavePasswordPromptDisplayed_" + uma_histogram_suffix_, |
@@ -67,6 +90,11 @@ SavePasswordInfoBarDelegate::SavePasswordInfoBarDelegate( |
} |
} |
+bool SavePasswordInfoBarDelegate::ShouldShowMoreButton() { |
+ return source_type_ == |
+ password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API; |
+} |
+ |
infobars::InfoBarDelegate::Type |
SavePasswordInfoBarDelegate::GetInfoBarType() const { |
return PAGE_ACTION_TYPE; |
@@ -93,13 +121,18 @@ void SavePasswordInfoBarDelegate::InfoBarDismissed() { |
} |
base::string16 SavePasswordInfoBarDelegate::GetMessageText() const { |
- return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_PASSWORD_PROMPT); |
+ return l10n_util::GetStringUTF16( |
+ (source_type_ == |
+ password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API) |
+ ? IDS_PASSWORD_MANAGER_SAVE_PASSWORD_SMART_LOCK_PROMPT |
+ : IDS_PASSWORD_MANAGER_SAVE_PASSWORD_PROMPT); |
} |
base::string16 SavePasswordInfoBarDelegate::GetButtonLabel( |
InfoBarButton button) const { |
- return l10n_util::GetStringUTF16((button == BUTTON_OK) ? |
- IDS_PASSWORD_MANAGER_SAVE_BUTTON : IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON); |
+ return l10n_util::GetStringUTF16((button == BUTTON_OK) |
+ ? IDS_PASSWORD_MANAGER_SAVE_BUTTON |
+ : GetCancelButtonText(source_type_)); |
} |
bool SavePasswordInfoBarDelegate::Accept() { |
@@ -111,7 +144,12 @@ bool SavePasswordInfoBarDelegate::Accept() { |
bool SavePasswordInfoBarDelegate::Cancel() { |
DCHECK(form_to_save_.get()); |
- form_to_save_->PermanentlyBlacklist(); |
- infobar_response_ = password_manager::metrics_util::NEVER_REMEMBER_PASSWORD; |
+ if (source_type_ == |
+ password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API) { |
+ form_to_save_->PermanentlyBlacklist(); |
+ infobar_response_ = password_manager::metrics_util::NEVER_REMEMBER_PASSWORD; |
+ } else { |
+ InfoBarDismissed(); |
+ } |
return true; |
} |