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

[Smart Lock] Brading string (Google Smart Lock) in save password infobar...

[Smart Lock] Brading string (Google Smart Lock) in save password infobar should be link to help center article.

Google Smart Lock in save password infobar should be a link to help
center article. Link is open in new tab, infobar is not dismissed when
link is clicked.

BUG=454815,486739

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

Cr-Commit-Position: refs/heads/master@{#329737}
parent c3ab203e
......@@ -4,6 +4,11 @@
package org.chromium.chrome.browser.infobar;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ClickableSpan;
import android.view.View;
import org.chromium.base.CalledByNative;
import org.chromium.chrome.browser.ResourceId;
......@@ -14,19 +19,28 @@ import org.chromium.chrome.browser.ResourceId;
*/
public class SavePasswordInfoBar extends ConfirmInfoBar {
private final boolean mIsMoreButtonNeeded;
private final int mTitleLinkRangeStart;
private final int mTitleLinkRangeEnd;
private final String mTitle;
@CalledByNative
private static InfoBar show(long nativeInfoBar, int enumeratedIconId, String message,
String primaryButtonText, String secondaryButtonText, boolean isMoreButtonNeeded) {
int titleLinkStart, int titleLinkEnd, String primaryButtonText,
String secondaryButtonText, boolean isMoreButtonNeeded) {
return new SavePasswordInfoBar(nativeInfoBar, ResourceId.mapToDrawableId(enumeratedIconId),
message, primaryButtonText, secondaryButtonText, isMoreButtonNeeded);
message, titleLinkStart, titleLinkEnd, primaryButtonText, secondaryButtonText,
isMoreButtonNeeded);
}
private SavePasswordInfoBar(long nativeInfoBar, int iconDrawbleId, String message,
String primaryButtonText, String secondaryButtonText, boolean isMoreButtonNeeded) {
int titleLinkStart, int titleLinkEnd, String primaryButtonText,
String secondaryButtonText, boolean isMoreButtonNeeded) {
super(nativeInfoBar, null, iconDrawbleId, null, message, null, primaryButtonText,
secondaryButtonText);
mIsMoreButtonNeeded = isMoreButtonNeeded;
mTitleLinkRangeStart = titleLinkStart;
mTitleLinkRangeEnd = titleLinkEnd;
mTitle = message;
}
@Override
......@@ -35,5 +49,15 @@ public class SavePasswordInfoBar extends ConfirmInfoBar {
if (mIsMoreButtonNeeded) {
layout.setCustomViewInButtonRow(OverflowSelector.createOverflowSelector(getContext()));
}
if (mTitleLinkRangeStart != 0 && mTitleLinkRangeEnd != 0) {
SpannableString title = new SpannableString(mTitle);
title.setSpan(new ClickableSpan() {
@Override
public void onClick(View view) {
onLinkClicked();
}
}, mTitleLinkRangeStart, mTitleLinkRangeEnd, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
layout.setMessage(title);
}
}
}
......@@ -98,11 +98,18 @@ SavePasswordInfoBarDelegate::SavePasswordInfoBarDelegate(
"PasswordManager.SavePasswordPromptDisplayed_" + uma_histogram_suffix_,
true);
}
int brand_string_id = is_smartlock_branding_enabled
? IDS_PASSWORD_MANAGER_SMART_LOCK
: IDS_SAVE_PASSWORD_TITLE_BRAND;
title_link_range_ = gfx::Range();
if (is_smartlock_branding_enabled) {
size_t offset = 0;
base::string16 title_link =
l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SMART_LOCK);
title_ = l10n_util::GetStringFUTF16(IDS_SAVE_PASSWORD, title_link, &offset);
title_link_range_ = gfx::Range(offset, offset + title_link.length());
} else {
title_ = l10n_util::GetStringFUTF16(
IDS_SAVE_PASSWORD, l10n_util::GetStringUTF16(brand_string_id));
IDS_SAVE_PASSWORD,
l10n_util::GetStringUTF16(IDS_SAVE_PASSWORD_TITLE_BRAND));
}
}
bool SavePasswordInfoBarDelegate::ShouldShowMoreButton() {
......@@ -164,3 +171,15 @@ bool SavePasswordInfoBarDelegate::Cancel() {
}
return true;
}
bool SavePasswordInfoBarDelegate::LinkClicked(
WindowOpenDisposition disposition) {
InfoBarService::WebContentsFromInfoBar(infobar())
->OpenURL(content::OpenURLParams(
GURL(l10n_util::GetStringUTF16(
IDS_PASSWORD_MANAGER_SMART_LOCK_ARTICLE)),
content::Referrer(),
(disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition,
ui::PAGE_TRANSITION_LINK, false));
return true;
}
......@@ -11,6 +11,7 @@
#include "components/infobars/core/confirm_infobar_delegate.h"
#include "components/password_manager/core/browser/password_form_manager.h"
#include "components/password_manager/core/browser/password_manager_metrics_util.h"
#include "ui/gfx/range/range.h"
namespace content {
class WebContents;
......@@ -46,6 +47,8 @@ class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate {
// Android it should display the "More" button.
bool ShouldShowMoreButton();
const gfx::Range& title_link_range() const { return title_link_range_; }
// ConfirmInfoBarDelegate:
Type GetInfoBarType() const override;
InfoBarAutomationType GetInfoBarAutomationType() const override;
......@@ -54,6 +57,7 @@ class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate {
void InfoBarDismissed() override;
base::string16 GetMessageText() const override;
base::string16 GetButtonLabel(InfoBarButton button) const override;
bool LinkClicked(WindowOpenDisposition disposition) override;
bool Accept() override;
bool Cancel() override;
......@@ -89,6 +93,10 @@ class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate {
// users.
base::string16 title_;
// If set, describes the location of the link to the help center article for
// Smart Lock.
gfx::Range title_link_range_;
DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegate);
};
......
......@@ -31,8 +31,13 @@ SavePasswordInfoBar::CreateRenderInfoBar(JNIEnv* env) {
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());
message_text.obj(), save_password_delegate->title_link_range().start(),
save_password_delegate->title_link_range().end(), ok_button_text.obj(),
cancel_button_text.obj(), save_password_delegate->ShouldShowMoreButton());
}
void SavePasswordInfoBar::OnLinkClicked(JNIEnv* env, jobject obj) {
GetDelegate()->LinkClicked(NEW_FOREGROUND_TAB);
}
bool SavePasswordInfoBar::Register(JNIEnv* env) {
......
......@@ -23,6 +23,7 @@ class SavePasswordInfoBar : public ConfirmInfoBar {
// ConfirmInfoBar:
base::android::ScopedJavaLocalRef<jobject> CreateRenderInfoBar(
JNIEnv* env) override;
void OnLinkClicked(JNIEnv* env, jobject obj) override;
DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBar);
};
......
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