Commit e508b5d1 authored by melandory's avatar melandory Committed by Commit bot

Credential saving clank infobar for Smart Lock.

In case infobar is triggered by credential management API
infobar should have different appearance.

BUG=454815

Review URL: https://codereview.chromium.org/967193002

Cr-Commit-Position: refs/heads/master@{#319892}
parent de769b31
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.infobar;
import org.chromium.base.CalledByNative;
import org.chromium.chrome.browser.ResourceId;
/**
* The Save Password infobar offers the user the ability to save a password for the site.
* Appearance and behaviour of infobar buttons depends on from where infobar was
* triggered.
*/
public class SavePasswordInfoBar extends ConfirmInfoBar {
private final boolean mIsMoreButtonNeeded;
@CalledByNative
private static InfoBar show(long nativeInfoBar, int enumeratedIconId, String message,
String primaryButtonText, String secondaryButtonText, boolean isMoreButtonNeeded) {
return new SavePasswordInfoBar(nativeInfoBar, ResourceId.mapToDrawableId(enumeratedIconId),
message, primaryButtonText, secondaryButtonText, isMoreButtonNeeded);
}
private SavePasswordInfoBar(long nativeInfoBar, int iconDrawbleId, String message,
String primaryButtonText, String secondaryButtonText, boolean isMoreButtonNeeded) {
super(nativeInfoBar, null, iconDrawbleId, null, message, null, primaryButtonText,
secondaryButtonText);
mIsMoreButtonNeeded = isMoreButtonNeeded;
}
@Override
public void createContent(InfoBarLayout layout) {
super.createContent(layout);
if (mIsMoreButtonNeeded) {
layout.setCustomViewInButtonRow(OverflowSelector.createOverflowSelector(getContext()));
}
}
}
......@@ -6437,6 +6437,12 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_FLAGS_PASSWORD_MANAGER_LINK_DESCRIPTION" desc="Description of the flag to enable showing a link to account central on password settings page">
Show a link in the password manager settings page to manage your synced passwords online.
</message>
<message name="IDS_PASSWORD_MANAGER_SAVE_PASSWORD_SMART_LOCK_PROMPT" desc="Message to save a password to Smart Lock.">
Save password for this site with Google Smart Lock?
</message>
<message name="IDS_PASSWORD_MANAGER_SAVE_PASSWORD_SMART_LOCK_NO_THANKS_BUTTON" desc="Text for the button the user clicks to dismiss save password bubble.">
No thanks
</message>
<message name="IDS_FLAGS_ENABLE_SAVE_PASSOWRD_ON_IN_PAGE_NAVIGATION_NAME" desc="Name of the flag to enable showing of the password save prompt on in-page navigations">
Enable showing of password prompt on in-page navigations.
</message>
......
......@@ -90,6 +90,7 @@
#include "chrome/browser/ui/android/infobars/generated_password_saved_infobar.h"
#include "chrome/browser/ui/android/infobars/infobar_android.h"
#include "chrome/browser/ui/android/infobars/infobar_container_android.h"
#include "chrome/browser/ui/android/infobars/save_password_infobar.h"
#include "chrome/browser/ui/android/infobars/translate_infobar.h"
#include "chrome/browser/ui/android/javascript_app_modal_dialog_android.h"
#include "chrome/browser/ui/android/navigation_popup.h"
......@@ -219,6 +220,7 @@ static base::android::RegistrationMethod kChromeRegisteredMethods[] = {
{"ProfileDownloader", RegisterProfileDownloader},
{"ProfileSyncService", ProfileSyncServiceAndroid::Register},
{"RecentlyClosedBridge", RecentlyClosedTabsBridge::Register},
{"SavePasswordInfoBar", SavePasswordInfoBar::Register},
{"SceneLayer", chrome::android::RegisterSceneLayer},
{"ServiceTabLauncher", ServiceTabLauncher::RegisterServiceTabLauncher},
{"SigninManager", SigninManagerAndroid::Register},
......
......@@ -190,7 +190,7 @@ bool ChromePasswordManagerClient::PromptUserToSavePassword(
password_manager::metrics_util::MonitoredDomainGroupId(
form_to_save->realm(), GetPrefs())));
SavePasswordInfoBarDelegate::Create(
web_contents(), form_to_save.Pass(), uma_histogram_suffix);
web_contents(), form_to_save.Pass(), uma_histogram_suffix, type);
}
return true;
}
......
......@@ -5,27 +5,52 @@
#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/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"
#if defined(OS_ANDROID)
#include "chrome/browser/ui/android/infobars/save_password_infobar.h"
#endif
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 +80,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 +94,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 +125,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 +148,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;
}
......@@ -6,11 +6,9 @@
#define CHROME_BROWSER_PASSWORD_MANAGER_SAVE_PASSWORD_INFOBAR_DELEGATE_H_
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/timer/elapsed_timer.h"
#include "components/infobars/core/confirm_infobar_delegate.h"
#include "components/infobars/core/infobar_delegate.h"
#include "components/password_manager/core/browser/password_form_manager.h"
#include "components/password_manager/core/browser/password_manager_metrics_util.h"
......@@ -18,6 +16,10 @@ namespace content {
class WebContents;
}
namespace password_manager {
enum class CredentialSourceType;
}
// After a successful *new* login attempt, we take the PasswordFormManager in
// provisional_save_manager_ and move it to a SavePasswordInfoBarDelegate while
// the user makes up their mind with the "save password" infobar. Note if the
......@@ -35,15 +37,15 @@ class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate {
static void Create(
content::WebContents* web_contents,
scoped_ptr<password_manager::PasswordFormManager> form_to_save,
const std::string& uma_histogram_suffix);
private:
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);
~SavePasswordInfoBarDelegate() override;
// If the infobar was triggered by the Credential management API, then on
// Android it should display the "More" button.
bool ShouldShowMoreButton();
// ConfirmInfoBarDelegate:
Type GetInfoBarType() const override;
InfoBarAutomationType GetInfoBarAutomationType() const override;
......@@ -55,6 +57,12 @@ class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate {
bool Accept() override;
bool Cancel() override;
private:
SavePasswordInfoBarDelegate(
scoped_ptr<password_manager::PasswordFormManager> form_to_save,
const std::string& uma_histogram_suffix,
password_manager::CredentialSourceType source_type);
// The PasswordFormManager managing the form we're asking the user about,
// and should update as per her decision.
scoped_ptr<password_manager::PasswordFormManager> form_to_save_;
......@@ -70,6 +78,10 @@ class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate {
// form is on a monitored domain. Otherwise, an empty string.
const std::string uma_histogram_suffix_;
// Records source from where infobar was triggered.
// Infobar appearance (title, buttons) depends on value of this parameter.
password_manager::CredentialSourceType source_type_;
DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegate);
};
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/android/infobars/save_password_infobar.h"
#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "jni/SavePasswordInfoBar_jni.h"
SavePasswordInfoBar::SavePasswordInfoBar(
scoped_ptr<SavePasswordInfoBarDelegate> delegate)
: ConfirmInfoBar(delegate.Pass()) {
}
SavePasswordInfoBar::~SavePasswordInfoBar() {
}
base::android::ScopedJavaLocalRef<jobject>
SavePasswordInfoBar::CreateRenderInfoBar(JNIEnv* env) {
using base::android::ConvertUTF16ToJavaString;
using base::android::ScopedJavaLocalRef;
SavePasswordInfoBarDelegate* save_password_delegate =
static_cast<SavePasswordInfoBarDelegate*>(delegate());
ScopedJavaLocalRef<jstring> ok_button_text = ConvertUTF16ToJavaString(
env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_OK));
ScopedJavaLocalRef<jstring> cancel_button_text = ConvertUTF16ToJavaString(
env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_CANCEL));
ScopedJavaLocalRef<jstring> message_text = ConvertUTF16ToJavaString(
env, save_password_delegate->GetMessageText());
return Java_SavePasswordInfoBar_show(
env, reinterpret_cast<intptr_t>(this), GetEnumeratedIconId(),
message_text.obj(), ok_button_text.obj(), cancel_button_text.obj(),
save_password_delegate->ShouldShowMoreButton());
}
bool SavePasswordInfoBar::Register(JNIEnv* env) {
return RegisterNativesImpl(env);
}
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_ANDROID_INFOBARS_SAVE_PASSWORD_INFOBAR_H_
#define CHROME_BROWSER_UI_ANDROID_INFOBARS_SAVE_PASSWORD_INFOBAR_H_
#include "chrome/browser/password_manager/save_password_infobar_delegate.h"
#include "chrome/browser/ui/android/infobars/confirm_infobar.h"
// The Android infobar that offers the user the ability to save a password
// for the site.
class SavePasswordInfoBar : public ConfirmInfoBar {
public:
explicit SavePasswordInfoBar(
scoped_ptr<SavePasswordInfoBarDelegate> delegate);
~SavePasswordInfoBar() override;
static bool Register(JNIEnv* env);
private:
// ConfirmInfoBar:
base::android::ScopedJavaLocalRef<jobject> CreateRenderInfoBar(
JNIEnv* env) override;
DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBar);
};
#endif // CHROME_BROWSER_UI_ANDROID_INFOBARS_SAVE_PASSWORD_INFOBAR_H_
......@@ -1677,6 +1677,7 @@
'android/java/src/org/chromium/chrome/browser/infobar/InfoBar.java',
'android/java/src/org/chromium/chrome/browser/infobar/InfoBarContainer.java',
'android/java/src/org/chromium/chrome/browser/infobar/TranslateInfoBarDelegate.java',
'android/java/src/org/chromium/chrome/browser/infobar/SavePasswordInfoBar.java',
'android/java/src/org/chromium/chrome/browser/invalidation/InvalidationServiceFactory.java',
'android/java/src/org/chromium/chrome/browser/metrics/LaunchMetrics.java',
'android/java/src/org/chromium/chrome/browser/toolbar/ToolbarModel.java',
......
......@@ -45,6 +45,8 @@
'browser/ui/android/infobars/infobar_android.h',
'browser/ui/android/infobars/infobar_container_android.cc',
'browser/ui/android/infobars/infobar_container_android.h',
'browser/ui/android/infobars/save_password_infobar.cc',
'browser/ui/android/infobars/save_password_infobar.h',
'browser/ui/android/infobars/translate_infobar.cc',
'browser/ui/android/infobars/translate_infobar.h',
'browser/ui/android/javascript_app_modal_dialog_android.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment