Commit 875df60e authored by jdoerrie's avatar jdoerrie Committed by Commit bot

Add Information Tooltip for Public Suffix List Matches

Similarly as done for Desktop this change adds an information tooltip for PSL
matches. This tooltip shows the origin URL when tapped on.

BUG=666340
R=bauerb@chromium.org,vasilii@chromium.org
CC=vabr@chromium.org,melandory@chromium.org

Review-Url: https://codereview.chromium.org/2541693004
Cr-Commit-Position: refs/heads/master@{#439098}
parent 8054f79a
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2016 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. -->
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="2dp"/>
<padding
android:left="16dp"
android:right="16dp"/>
<solid android:color="#e6616161"/>
</shape>
......@@ -7,6 +7,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="64dp"
android:paddingStart="@dimen/account_chooser_dialog_item_margin"
android:paddingEnd="@dimen/account_chooser_dialog_item_margin"
......@@ -15,12 +16,10 @@
android:id="@+id/profile_image"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_vertical"
android:contentDescription="@null"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_margin="8dp"
android:layout_marginStart="16dp"
android:orientation="vertical">
......@@ -43,4 +42,18 @@
android:textColor="@color/descriptive_text_color"
android:textSize="@dimen/account_chooser_dialog_title_descriptive_text_size"/>
</LinearLayout>
<!-- Needed to make the following ImageButton align to the right. -->
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<ImageButton
android:id="@+id/psl_info_btn"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="?attr/selectableItemBackground"
android:contentDescription="@null"
android:padding="4dp"
android:src="@drawable/btn_info"
android:visibility="gone"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2016 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. -->
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/material_tooltip_text"
android:background="@drawable/material_tooltip_background"
android:ellipsize="start"
android:fontFamily="sans-serif"
android:gravity="center"
android:minHeight="32dp"
android:singleLine="true"
android:textColor="@android:color/white"
android:textSize="14sp"/>
......@@ -339,10 +339,13 @@
<!-- Account chooser dialog dimensions -->
<dimen name="account_chooser_dialog_margin">24dp</dimen>
<dimen name="account_chooser_dialog_item_margin">20dp</dimen>
<dimen name="account_chooser_dialog_item_margin">24dp</dimen>
<dimen name="account_chooser_dialog_title_main_text_size">18sp</dimen>
<dimen name="account_chooser_dialog_title_descriptive_text_size">16sp</dimen>
<!-- Public Suffix List (PSL) info button and tooltip dimensions -->
<dimen name="psl_info_tooltip_margin">8dp</dimen>
<!-- Clear browsing data preferences dimensions -->
<dimen name="clear_browsing_data_checkbox_height">56dp</dimen>
......
......@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.password_manager;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.support.v7.app.AlertDialog;
import android.text.SpannableString;
......@@ -14,18 +15,23 @@ import android.text.Spanned;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.signin.AccountManagementFragment;
import org.chromium.components.url_formatter.UrlFormatter;
import org.chromium.ui.base.WindowAndroid;
import org.chromium.ui.widget.Toast;
/**
* A dialog offers the user the ability to choose credentials for authentication. User is
......@@ -138,6 +144,24 @@ public class AccountChooserDialog
secondaryNameView.setVisibility(View.VISIBLE);
}
ImageButton pslInfoButton =
(ImageButton) convertView.findViewById(R.id.psl_info_btn);
final String originUrl = credential.getOriginUrl();
if (!originUrl.isEmpty()) {
pslInfoButton.setVisibility(View.VISIBLE);
pslInfoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showTooltip(
view,
UrlFormatter.formatUrlForSecurityDisplay(
originUrl, true /* showScheme */),
R.layout.material_tooltip);
}
});
}
return convertView;
}
};
......@@ -181,6 +205,39 @@ public class AccountChooserDialog
mDialog.show();
}
private void showTooltip(View view, String message, int layoutId) {
Context context = view.getContext();
Resources resources = context.getResources();
LayoutInflater inflater = LayoutInflater.from(context);
TextView text = (TextView) inflater.inflate(layoutId, null);
text.setText(message);
text.announceForAccessibility(message);
final int screenWidth = resources.getDisplayMetrics().widthPixels;
final int screenHeight = resources.getDisplayMetrics().heightPixels;
final int[] screenPos = new int[2];
view.getLocationOnScreen(screenPos);
final int width = view.getWidth();
final int tooltipMargin = resources.getDimensionPixelSize(R.dimen.psl_info_tooltip_margin);
// The toast should be shown above and to the left (right for RTL) of the info button.
// In order to avoid measuring the size of the toast offsets are specified with regard
// to the bottom right / left corner of the screen.
final int xOffset = ApiCompatibilityUtils.isLayoutRtl(view)
? screenPos[0]
: screenWidth - screenPos[0] - width;
final int yOffset = screenHeight - screenPos[1] + tooltipMargin;
Toast toast = new Toast(context);
toast.setGravity(Gravity.BOTTOM | Gravity.END, xOffset, yOffset);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(text);
toast.show();
}
@CalledByNative
private void imageFetchComplete(int index, Bitmap avatarBitmap) {
if (mIsDestroyed) return;
......
......@@ -15,6 +15,7 @@ import org.chromium.base.annotations.CalledByNative;
public class Credential {
private final String mUsername;
private final String mDisplayName;
private final String mOriginUrl;
private final String mFederation;
private final int mIndex;
private Bitmap mAvatar;
......@@ -24,12 +25,15 @@ public class Credential {
* The value is PasswordForm::username_value.
* @param displayName user friendly name to show in the UI. It can be empty.
* The value is PasswordForm::display_name.
* @param originUrl The origin URL for this credential, only set for PSL matches.
* @param federation Identity provider name for this credential (empty for local credentials).
* @param index position in array of credentials.
*/
public Credential(String username, String displayName, String federation, int index) {
public Credential(String username, String displayName, String originUrl, String federation,
int index) {
mUsername = username;
mDisplayName = displayName;
mOriginUrl = originUrl;
mFederation = federation;
mIndex = index;
mAvatar = null;
......@@ -43,6 +47,10 @@ public class Credential {
return mDisplayName;
}
public String getOriginUrl() {
return mOriginUrl;
}
public String getFederation() {
return mFederation;
}
......@@ -61,8 +69,8 @@ public class Credential {
@CalledByNative
private static Credential createCredential(
String username, String displayName, String federation, int index) {
return new Credential(username, displayName, federation, index);
String username, String displayName, String originUrl, String federation, int index) {
return new Credential(username, displayName, originUrl, federation, index);
}
@CalledByNative
......
......@@ -17,6 +17,10 @@ base::android::ScopedJavaLocalRef<jobject> CreateNativeCredential(
int position) {
using base::android::ConvertUTF16ToJavaString;
using base::android::ConvertUTF8ToJavaString;
std::string origin_url =
password_form.is_public_suffix_match
? password_form.origin.GetOrigin().spec()
: std::string();
std::string federation =
password_form.federation_origin.unique()
? std::string()
......@@ -26,6 +30,7 @@ base::android::ScopedJavaLocalRef<jobject> CreateNativeCredential(
return Java_Credential_createCredential(
env, ConvertUTF16ToJavaString(env, password_form.username_value),
ConvertUTF16ToJavaString(env, password_form.display_name),
ConvertUTF8ToJavaString(env, origin_url),
ConvertUTF8ToJavaString(env, federation), position);
}
......
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