Commit 2ca77c1b authored by melandory's avatar melandory Committed by Commit bot

[Smart Lock, UI] Display origin in account chooser dialog.

BUG=454815

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

Cr-Commit-Position: refs/heads/master@{#371488}
parent b24cb488
...@@ -15,4 +15,11 @@ ...@@ -15,4 +15,11 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:ellipsize="end" android:ellipsize="end"
android:textAppearance="?android:attr/textAppearanceLarge"/> android:textAppearance="?android:attr/textAppearanceLarge"/>
<TextView
android:id="@+id/origin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:textAppearance="@style/TextAppearance.AppCompat.Small"/>
</LinearLayout> </LinearLayout>
...@@ -46,6 +46,7 @@ public class AccountChooserDialog ...@@ -46,6 +46,7 @@ public class AccountChooserDialog
private final String mTitle; private final String mTitle;
private final int mTitleLinkStart; private final int mTitleLinkStart;
private final int mTitleLinkEnd; private final int mTitleLinkEnd;
private final String mOrigin;
private ArrayAdapter<Credential> mAdapter; private ArrayAdapter<Credential> mAdapter;
/** /**
...@@ -56,7 +57,8 @@ public class AccountChooserDialog ...@@ -56,7 +57,8 @@ public class AccountChooserDialog
private AlertDialog mDialog; private AlertDialog mDialog;
private AccountChooserDialog(Context context, long nativeAccountChooserDialog, private AccountChooserDialog(Context context, long nativeAccountChooserDialog,
Credential[] credentials, String title, int titleLinkStart, int titleLinkEnd) { Credential[] credentials, String title, int titleLinkStart, int titleLinkEnd,
String origin) {
mNativeAccountChooserDialog = nativeAccountChooserDialog; mNativeAccountChooserDialog = nativeAccountChooserDialog;
mContext = context; mContext = context;
mCredentials = credentials.clone(); mCredentials = credentials.clone();
...@@ -64,6 +66,7 @@ public class AccountChooserDialog ...@@ -64,6 +66,7 @@ public class AccountChooserDialog
mTitle = title; mTitle = title;
mTitleLinkStart = titleLinkStart; mTitleLinkStart = titleLinkStart;
mTitleLinkEnd = titleLinkEnd; mTitleLinkEnd = titleLinkEnd;
mOrigin = origin;
} }
/** /**
...@@ -72,15 +75,17 @@ public class AccountChooserDialog ...@@ -72,15 +75,17 @@ public class AccountChooserDialog
* @param title Title message for the dialog, which can contain Smart Lock branding. * @param title Title message for the dialog, which can contain Smart Lock branding.
* @param titleLinkStart Start of a link in case title contains Smart Lock branding. * @param titleLinkStart Start of a link in case title contains Smart Lock branding.
* @param titleLinkEnd End of a link in case title contains Smart Lock branding. * @param titleLinkEnd End of a link in case title contains Smart Lock branding.
* @param origin Address of the web page, where dialog was triggered.
*/ */
@CalledByNative @CalledByNative
private static AccountChooserDialog createAccountChooser(WindowAndroid windowAndroid, private static AccountChooserDialog createAccountChooser(WindowAndroid windowAndroid,
long nativeAccountChooserDialog, Credential[] credentials, String title, long nativeAccountChooserDialog, Credential[] credentials, String title,
int titleLinkStart, int titleLinkEnd) { int titleLinkStart, int titleLinkEnd, String origin) {
Activity activity = windowAndroid.getActivity().get(); Activity activity = windowAndroid.getActivity().get();
if (activity == null) return null; if (activity == null) return null;
AccountChooserDialog chooser = new AccountChooserDialog(activity, AccountChooserDialog chooser =
nativeAccountChooserDialog, credentials, title, titleLinkStart, titleLinkEnd); new AccountChooserDialog(activity, nativeAccountChooserDialog, credentials, title,
titleLinkStart, titleLinkEnd, origin);
chooser.show(activity.getFragmentManager(), null); chooser.show(activity.getFragmentManager(), null);
return chooser; return chooser;
} }
...@@ -129,8 +134,9 @@ public class AccountChooserDialog ...@@ -129,8 +134,9 @@ public class AccountChooserDialog
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
View titleView = View titleView =
LayoutInflater.from(mContext).inflate(R.layout.account_chooser_dialog_title, null); LayoutInflater.from(mContext).inflate(R.layout.account_chooser_dialog_title, null);
TextView origin = (TextView) titleView.findViewById(R.id.origin);
origin.setText(mOrigin);
TextView titleMessageText = (TextView) titleView.findViewById(R.id.title); TextView titleMessageText = (TextView) titleView.findViewById(R.id.title);
// TODO(melandory): add support for showing site origin in the title.
if (mTitleLinkStart != 0 && mTitleLinkEnd != 0) { if (mTitleLinkStart != 0 && mTitleLinkEnd != 0) {
SpannableString spanableTitle = new SpannableString(mTitle); SpannableString spanableTitle = new SpannableString(mTitle);
spanableTitle.setSpan(new ClickableSpan() { spanableTitle.setSpan(new ClickableSpan() {
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "components/browser_sync/browser/profile_sync_service.h" #include "components/browser_sync/browser/profile_sync_service.h"
#include "components/password_manager/core/browser/password_bubble_experiment.h" #include "components/password_manager/core/browser/password_bubble_experiment.h"
#include "components/password_manager/core/browser/password_manager_constants.h" #include "components/password_manager/core/browser/password_manager_constants.h"
#include "components/password_manager/core/browser/password_ui_utils.h"
#include "components/password_manager/core/common/credential_manager_types.h" #include "components/password_manager/core/common/credential_manager_types.h"
#include "jni/AccountChooserDialog_jni.h" #include "jni/AccountChooserDialog_jni.h"
#include "ui/android/window_android.h" #include "ui/android/window_android.h"
...@@ -109,7 +110,7 @@ AccountChooserDialogAndroid::AccountChooserDialogAndroid( ...@@ -109,7 +110,7 @@ AccountChooserDialogAndroid::AccountChooserDialogAndroid(
ScopedVector<autofill::PasswordForm> federated_credentials, ScopedVector<autofill::PasswordForm> federated_credentials,
const GURL& origin, const GURL& origin,
const ManagePasswordsState::CredentialsCallback& callback) const ManagePasswordsState::CredentialsCallback& callback)
: web_contents_(web_contents) { : web_contents_(web_contents), origin_(origin) {
passwords_data_.set_client( passwords_data_.set_client(
ChromePasswordManagerClient::FromWebContents(web_contents_)); ChromePasswordManagerClient::FromWebContents(web_contents_));
passwords_data_.OnRequestCredentials( passwords_data_.OnRequestCredentials(
...@@ -146,7 +147,10 @@ void AccountChooserDialogAndroid::ShowDialog() { ...@@ -146,7 +147,10 @@ void AccountChooserDialogAndroid::ShowDialog() {
env, native_window->GetJavaObject().obj(), env, native_window->GetJavaObject().obj(),
reinterpret_cast<intptr_t>(this), java_credentials_array.obj(), reinterpret_cast<intptr_t>(this), java_credentials_array.obj(),
base::android::ConvertUTF16ToJavaString(env, title).obj(), base::android::ConvertUTF16ToJavaString(env, title).obj(),
title_link_range.start(), title_link_range.end())); title_link_range.start(), title_link_range.end(),
base::android::ConvertUTF8ToJavaString(
env, password_manager::GetShownOrigin(origin_, std::string()))
.obj()));
base::android::ScopedJavaLocalRef<jobject> java_dialog(java_dialog_global); base::android::ScopedJavaLocalRef<jobject> java_dialog(java_dialog_global);
net::URLRequestContextGetter* request_context = net::URLRequestContextGetter* request_context =
Profile::FromBrowserContext(web_contents_->GetBrowserContext()) Profile::FromBrowserContext(web_contents_->GetBrowserContext())
......
...@@ -63,6 +63,7 @@ class AccountChooserDialogAndroid { ...@@ -63,6 +63,7 @@ class AccountChooserDialogAndroid {
content::WebContents* web_contents_; content::WebContents* web_contents_;
ManagePasswordsState passwords_data_; ManagePasswordsState passwords_data_;
GURL origin_;
DISALLOW_COPY_AND_ASSIGN(AccountChooserDialogAndroid); DISALLOW_COPY_AND_ASSIGN(AccountChooserDialogAndroid);
}; };
......
...@@ -33,9 +33,12 @@ std::string GetShownOrigin(const autofill::PasswordForm& password_form, ...@@ -33,9 +33,12 @@ std::string GetShownOrigin(const autofill::PasswordForm& password_form,
if (*is_android_uri) if (*is_android_uri)
return GetHumanReadableOriginForAndroidUri(facet_uri); return GetHumanReadableOriginForAndroidUri(facet_uri);
std::string original = return GetShownOrigin(password_form.origin, languages);
base::UTF16ToUTF8(url_formatter::FormatUrlForSecurityDisplayOmitScheme( }
password_form.origin, languages));
std::string GetShownOrigin(const GURL& origin, const std::string& languages) {
std::string original = base::UTF16ToUTF8(
url_formatter::FormatUrlForSecurityDisplayOmitScheme(origin, languages));
base::StringPiece result = original; base::StringPiece result = original;
for (base::StringPiece prefix : kRemovedPrefixes) { for (base::StringPiece prefix : kRemovedPrefixes) {
if (base::StartsWith(result, prefix, if (base::StartsWith(result, prefix,
......
...@@ -27,6 +27,11 @@ std::string GetShownOrigin(const autofill::PasswordForm& password_form, ...@@ -27,6 +27,11 @@ std::string GetShownOrigin(const autofill::PasswordForm& password_form,
const std::string& languages, const std::string& languages,
bool* is_android_uri); bool* is_android_uri);
// Returns a string suitable for security display to the user (just like
// |FormatUrlForSecurityDisplayOmitScheme| based on origin of |password_form|
// and |languages|) and without prefixes "m.", "mobile." or "www.".
std::string GetShownOrigin(const GURL& origin, const std::string& languages);
} // namespace password_manager } // namespace password_manager
#endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_UI_UTILS_H_ #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_UI_UTILS_H_
...@@ -38,6 +38,7 @@ TEST(GetShownOriginTest, RemovePrefixes) { ...@@ -38,6 +38,7 @@ TEST(GetShownOriginTest, RemovePrefixes) {
GetShownOrigin(password_form, "", &is_android_uri)) GetShownOrigin(password_form, "", &is_android_uri))
<< "for input " << test_case.input; << "for input " << test_case.input;
EXPECT_FALSE(is_android_uri) << "for input " << test_case.input; EXPECT_FALSE(is_android_uri) << "for input " << test_case.input;
EXPECT_EQ(test_case.output, GetShownOrigin(password_form.origin, ""));
} }
} }
......
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