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 @@ ...@@ -4,6 +4,11 @@
package org.chromium.chrome.browser.infobar; 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.base.CalledByNative;
import org.chromium.chrome.browser.ResourceId; import org.chromium.chrome.browser.ResourceId;
...@@ -14,19 +19,28 @@ import org.chromium.chrome.browser.ResourceId; ...@@ -14,19 +19,28 @@ import org.chromium.chrome.browser.ResourceId;
*/ */
public class SavePasswordInfoBar extends ConfirmInfoBar { public class SavePasswordInfoBar extends ConfirmInfoBar {
private final boolean mIsMoreButtonNeeded; private final boolean mIsMoreButtonNeeded;
private final int mTitleLinkRangeStart;
private final int mTitleLinkRangeEnd;
private final String mTitle;
@CalledByNative @CalledByNative
private static InfoBar show(long nativeInfoBar, int enumeratedIconId, String message, 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), 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, 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, super(nativeInfoBar, null, iconDrawbleId, null, message, null, primaryButtonText,
secondaryButtonText); secondaryButtonText);
mIsMoreButtonNeeded = isMoreButtonNeeded; mIsMoreButtonNeeded = isMoreButtonNeeded;
mTitleLinkRangeStart = titleLinkStart;
mTitleLinkRangeEnd = titleLinkEnd;
mTitle = message;
} }
@Override @Override
...@@ -35,5 +49,15 @@ public class SavePasswordInfoBar extends ConfirmInfoBar { ...@@ -35,5 +49,15 @@ public class SavePasswordInfoBar extends ConfirmInfoBar {
if (mIsMoreButtonNeeded) { if (mIsMoreButtonNeeded) {
layout.setCustomViewInButtonRow(OverflowSelector.createOverflowSelector(getContext())); 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( ...@@ -98,11 +98,18 @@ SavePasswordInfoBarDelegate::SavePasswordInfoBarDelegate(
"PasswordManager.SavePasswordPromptDisplayed_" + uma_histogram_suffix_, "PasswordManager.SavePasswordPromptDisplayed_" + uma_histogram_suffix_,
true); true);
} }
int brand_string_id = is_smartlock_branding_enabled title_link_range_ = gfx::Range();
? IDS_PASSWORD_MANAGER_SMART_LOCK if (is_smartlock_branding_enabled) {
: IDS_SAVE_PASSWORD_TITLE_BRAND; size_t offset = 0;
title_ = l10n_util::GetStringFUTF16( base::string16 title_link =
IDS_SAVE_PASSWORD, l10n_util::GetStringUTF16(brand_string_id)); 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(IDS_SAVE_PASSWORD_TITLE_BRAND));
}
} }
bool SavePasswordInfoBarDelegate::ShouldShowMoreButton() { bool SavePasswordInfoBarDelegate::ShouldShowMoreButton() {
...@@ -164,3 +171,15 @@ bool SavePasswordInfoBarDelegate::Cancel() { ...@@ -164,3 +171,15 @@ bool SavePasswordInfoBarDelegate::Cancel() {
} }
return true; 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 @@ ...@@ -11,6 +11,7 @@
#include "components/infobars/core/confirm_infobar_delegate.h" #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_form_manager.h"
#include "components/password_manager/core/browser/password_manager_metrics_util.h" #include "components/password_manager/core/browser/password_manager_metrics_util.h"
#include "ui/gfx/range/range.h"
namespace content { namespace content {
class WebContents; class WebContents;
...@@ -46,6 +47,8 @@ class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate { ...@@ -46,6 +47,8 @@ class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate {
// Android it should display the "More" button. // Android it should display the "More" button.
bool ShouldShowMoreButton(); bool ShouldShowMoreButton();
const gfx::Range& title_link_range() const { return title_link_range_; }
// ConfirmInfoBarDelegate: // ConfirmInfoBarDelegate:
Type GetInfoBarType() const override; Type GetInfoBarType() const override;
InfoBarAutomationType GetInfoBarAutomationType() const override; InfoBarAutomationType GetInfoBarAutomationType() const override;
...@@ -54,6 +57,7 @@ class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate { ...@@ -54,6 +57,7 @@ class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate {
void InfoBarDismissed() override; void InfoBarDismissed() override;
base::string16 GetMessageText() const override; base::string16 GetMessageText() const override;
base::string16 GetButtonLabel(InfoBarButton button) const override; base::string16 GetButtonLabel(InfoBarButton button) const override;
bool LinkClicked(WindowOpenDisposition disposition) override;
bool Accept() override; bool Accept() override;
bool Cancel() override; bool Cancel() override;
...@@ -89,6 +93,10 @@ class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate { ...@@ -89,6 +93,10 @@ class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate {
// users. // users.
base::string16 title_; 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); DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegate);
}; };
......
...@@ -31,8 +31,13 @@ SavePasswordInfoBar::CreateRenderInfoBar(JNIEnv* env) { ...@@ -31,8 +31,13 @@ SavePasswordInfoBar::CreateRenderInfoBar(JNIEnv* env) {
return Java_SavePasswordInfoBar_show( return Java_SavePasswordInfoBar_show(
env, reinterpret_cast<intptr_t>(this), GetEnumeratedIconId(), env, reinterpret_cast<intptr_t>(this), GetEnumeratedIconId(),
message_text.obj(), ok_button_text.obj(), cancel_button_text.obj(), message_text.obj(), save_password_delegate->title_link_range().start(),
save_password_delegate->ShouldShowMoreButton()); 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) { bool SavePasswordInfoBar::Register(JNIEnv* env) {
......
...@@ -23,6 +23,7 @@ class SavePasswordInfoBar : public ConfirmInfoBar { ...@@ -23,6 +23,7 @@ class SavePasswordInfoBar : public ConfirmInfoBar {
// ConfirmInfoBar: // ConfirmInfoBar:
base::android::ScopedJavaLocalRef<jobject> CreateRenderInfoBar( base::android::ScopedJavaLocalRef<jobject> CreateRenderInfoBar(
JNIEnv* env) override; JNIEnv* env) override;
void OnLinkClicked(JNIEnv* env, jobject obj) override;
DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBar); 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