Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1998)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/infobar/UpdatePasswordInfoBar.java

Issue 1490193003: [Password Manager] Update Confirmation UI for saved password change for Chrome on Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/infobar/UpdatePasswordInfoBar.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/infobar/UpdatePasswordInfoBar.java b/chrome/android/java/src/org/chromium/chrome/browser/infobar/UpdatePasswordInfoBar.java
new file mode 100644
index 0000000000000000000000000000000000000000..692fb67f7c243c75335b83ce62596e811da1c2ee
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/infobar/UpdatePasswordInfoBar.java
@@ -0,0 +1,133 @@
+// 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.
+
+package org.chromium.chrome.browser.infobar;
+
+import android.text.Spannable;
+import android.text.SpannableString;
+import android.text.TextUtils;
+import android.text.style.ClickableSpan;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.PopupMenu;
+import android.widget.TextView;
+
+import org.chromium.base.annotations.CalledByNative;
+import org.chromium.chrome.R;
+import org.chromium.chrome.browser.ResourceId;
+
+/**
+ * The Update Password infobar offers the user the ability to update a password for the site.
+ */
+public class UpdatePasswordInfoBar
+ extends ConfirmInfoBar implements PopupMenu.OnMenuItemClickListener {
+ private long mNativePtr;
gone 2016/01/26 19:59:22 private final long mNativePtr; final everywhere e
melandory 2016/01/29 15:56:14 Done.
+ private String[] mUsernames;
+ private boolean mShowMultipleAccounts;
+ private boolean mIsSmartLockEnabled;
+ private int mSelectedUsername;
+ private SpannableString mBrandingSpan;
+ private TextView mMessageView;
+
+ @CalledByNative
+ private static InfoBar show(long nativePtr, int enumeratedIconId, String[] usernames,
+ String primaryButtonText, String secondaryButtonText, String branding,
+ boolean showMultipleAccounts, boolean isSmartLockEnabled) {
+ return new UpdatePasswordInfoBar(nativePtr, ResourceId.mapToDrawableId(enumeratedIconId),
+ usernames, primaryButtonText, secondaryButtonText, branding, showMultipleAccounts,
+ isSmartLockEnabled);
+ }
+
+ private UpdatePasswordInfoBar(long nativePtr, int iconDrawbleId, String[] usernames,
+ String primaryButtonText, String secondaryButtonText, String branding,
+ boolean showMultipleAccounts, boolean isSmartLockEnabled) {
+ super(iconDrawbleId, null, null, null, primaryButtonText, secondaryButtonText);
+ mNativePtr = nativePtr;
+ mUsernames = usernames;
+ mShowMultipleAccounts = showMultipleAccounts;
+ mIsSmartLockEnabled = isSmartLockEnabled;
+ mBrandingSpan = new SpannableString(branding);
+ }
+
+ private void onUsernameLinkClicked(View v) {
+ PopupMenu popup = new PopupMenu(getContext(), v);
+ for (int i = 0; i < mUsernames.length; ++i) {
+ MenuItem item = popup.getMenu().add(Menu.NONE, i, i, mUsernames[i]);
+ }
+ popup.setOnMenuItemClickListener(this);
+ popup.show();
+ }
+
+ /**
+ * Returns the infobar message for the case when PasswordManager has a guess which credentials
+ * pair should be updated. There are two cases possible: there is only one credential pair that
+ * should be updated and there several guesses available. In the first case user is presented
+ * with the username of the credentials that should be updated in the second case user is able
+ * to choose which of the available credentials to update.
+ * It also remembered the choice made.
+ */
+ private CharSequence createUsernameMessageText(int selectedUsername) {
+ CharSequence message;
+ mSelectedUsername = selectedUsername;
+ final String template = getContext().getString(R.string.update_password_for_account);
+ final String usernameToDisplay = mUsernames[mSelectedUsername];
+ final String downPointingArrow = " \u25BE";
+ if (mShowMultipleAccounts) {
+ SpannableString username = new SpannableString(usernameToDisplay + downPointingArrow);
gone 2016/01/26 19:59:22 nit: this isn't really just the username, since it
melandory 2016/01/29 15:56:14 Done.
+ username.setSpan(new ClickableSpan() {
+ @Override
+ public void onClick(View view) {
+ onUsernameLinkClicked(view);
+ }
+ }, 0, username.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
gone 2016/01/26 19:59:22 Shouldn't this be SPAN_INCLUSIVE_EXCLUSIVE?
melandory 2016/01/29 15:56:14 Yep, thanks
+ message = TextUtils.expandTemplate(template, mBrandingSpan, username);
+ } else {
+ message = TextUtils.expandTemplate(template, mBrandingSpan, usernameToDisplay);
+ }
+
+ return message;
+ }
+
+ @Override
+ public void onButtonClicked(final boolean isPrimaryButton) {
+ super.onButtonClicked(isPrimaryButton);
+ if (isPrimaryButton) nativeOnUpdateClicked(mNativePtr, mSelectedUsername);
gone 2016/01/26 19:59:22 This would use the infobar/delegate framework more
melandory 2016/01/29 15:56:14 Done.
+ }
+
+ /**
+ * If user have chosen different than was shown username to update, then we need to change the
+ * infobar message in order to reflect this choice.
+ */
+ public boolean onMenuItemClick(MenuItem item) {
+ mMessageView.setText(
+ createUsernameMessageText(item.getItemId()), TextView.BufferType.SPANNABLE);
gone 2016/01/26 19:59:22 Why isn't this updating mSelectedUsername?
melandory 2016/01/29 15:56:14 Yes, it is. This is the idea. If menu item is sele
gone 2016/01/29 18:31:24 Blarg, I see it now. I mistook the body of create
+ return false;
+ }
+
+ @Override
+ public void createContent(InfoBarLayout layout) {
+ super.createContent(layout);
+ CharSequence message;
+ if (mIsSmartLockEnabled) {
+ mBrandingSpan.setSpan(new ClickableSpan() {
+ @Override
+ public void onClick(View view) {
+ onLinkClicked();
+ }
+ }, 0, mBrandingSpan.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ }
+ if (mShowMultipleAccounts || mUsernames.length != 0) {
+ message = createUsernameMessageText(0);
+ } else {
+ String template = getContext().getString(R.string.update_password);
+ message = TextUtils.expandTemplate(template, mBrandingSpan);
+ }
+
+ mMessageView = layout.getMessageTextView();
+ mMessageView.setText(message, TextView.BufferType.SPANNABLE);
+ }
+
+ private static native void nativeOnUpdateClicked(long nativeUpdatePasswordInfoBar, int formId);
+}

Powered by Google App Engine
This is Rietveld 408576698