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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/preferences/password/PasswordEntryEditor.java

Issue 2067323004: Allow copying and viewing account credentials in PasswordEntryEditor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Insert timer functionality Created 4 years, 5 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/preferences/password/PasswordEntryEditor.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/password/PasswordEntryEditor.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/password/PasswordEntryEditor.java
index c8e15c135c052bed3f06f81827f1f293741510b8..b26bf5450d8104564965df1b179902a1af5721c5 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/preferences/password/PasswordEntryEditor.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/password/PasswordEntryEditor.java
@@ -4,18 +4,30 @@
package org.chromium.chrome.browser.preferences.password;
+import android.annotation.TargetApi;
import android.app.Fragment;
+import android.app.KeyguardManager;
+import android.content.ClipData;
+import android.content.ClipboardManager;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Build;
+import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
+import android.widget.ImageButton;
import android.widget.TextView;
+import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.PasswordUIView;
import org.chromium.chrome.browser.PasswordUIView.PasswordListObserver;
+import org.chromium.chrome.browser.preferences.MainPreferences;
+import org.chromium.ui.widget.Toast;
/**
* Password entry editor that allows to view and delete passwords stored in Chrome.
@@ -29,8 +41,19 @@ public class PasswordEntryEditor extends Fragment {
// If false this represents a saved name/password.
private boolean mException;
+ @VisibleForTesting
public static final String VIEW_PASSWORDS = "view-passwords";
+ private ClipboardManager mClipboard;
+
+ public static final int REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS = 1;
+
+ private KeyguardManager mKeyguardManager;
+
+ private Bundle mExtras;
+
+ private View mView;
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -40,36 +63,57 @@ public class PasswordEntryEditor extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- View v;
- if (ChromeFeatureList.isEnabled(VIEW_PASSWORDS)) {
- v = inflater.inflate(R.layout.password_entry_editor_interactive, container, false);
+ if (!ChromeFeatureList.isEnabled(VIEW_PASSWORDS)) {
vabr (Chromium) 2016/07/28 09:44:33 Should this really be "if viewing passwords is NOT
dozsa 2016/07/28 14:00:32 Done.
+ mView = inflater.inflate(R.layout.password_entry_editor_interactive, container, false);
} else {
- v = inflater.inflate(R.layout.password_entry_editor, container, false);
+ mView = inflater.inflate(R.layout.password_entry_editor, container, false);
}
getActivity().setTitle(R.string.password_entry_editor_title);
-
+ mClipboard = (ClipboardManager) getActivity().getApplicationContext()
+ .getSystemService(Context.CLIPBOARD_SERVICE);
+ if (!ChromeFeatureList.isEnabled(VIEW_PASSWORDS)) {
vabr (Chromium) 2016/07/28 09:44:33 Also here: it seems that the setup in lines 75-80
dozsa 2016/07/28 14:00:32 Done.
+ mKeyguardManager = (KeyguardManager) getActivity()
+ .getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE);
+ ImageButton copyPasswordButton = (ImageButton) mView.findViewById(
+ R.id.password_entry_editor_copy_password);
+ ImageButton viewPasswordButton = (ImageButton) mView.findViewById(
+ R.id.password_entry_editor_view_password);
+ }
// Extras are set on this intent in class SavePasswordsPreferences.
- Bundle extras = getArguments();
- assert extras != null;
- mID = extras.getInt(SavePasswordsPreferences.PASSWORD_LIST_ID);
+ mExtras = getArguments();
+ assert mExtras != null;
+ mID = mExtras.getInt(SavePasswordsPreferences.PASSWORD_LIST_ID);
String name = null;
- if (extras.containsKey(SavePasswordsPreferences.PASSWORD_LIST_NAME)) {
- name = extras.getString(SavePasswordsPreferences.PASSWORD_LIST_NAME);
+ if (mExtras.containsKey(SavePasswordsPreferences.PASSWORD_LIST_NAME)) {
+ name = mExtras.getString(SavePasswordsPreferences.PASSWORD_LIST_NAME);
}
- TextView nameView = (TextView) v.findViewById(R.id.password_entry_editor_name);
+ TextView nameView = (TextView) mView.findViewById(R.id.password_entry_editor_name);
if (name != null) {
nameView.setText(name);
} else {
nameView.setText(R.string.section_saved_passwords_exceptions);
mException = true;
}
- String url = extras.getString(SavePasswordsPreferences.PASSWORD_LIST_URL);
- TextView urlView = (TextView) v.findViewById(R.id.password_entry_editor_url);
+ String url = mExtras.getString(SavePasswordsPreferences.PASSWORD_LIST_URL);
+ TextView urlView = (TextView) mView.findViewById(R.id.password_entry_editor_url);
+ String password = mExtras.getString(SavePasswordsPreferences.PASSWORD_LIST_PASSWORD);
+ TextView passwordView = (TextView) mView.findViewById(R.id.password_entry_editor_password);
urlView.setText(url);
- if (!ChromeFeatureList.isEnabled(VIEW_PASSWORDS)) {
- hookupCancelDeleteButtons(v);
+
+ if (System.currentTimeMillis() - MainPreferences.getStartTime() > 30000) {
vabr (Chromium) 2016/07/28 09:44:33 Here you use a slightly different condition than b
dozsa 2016/07/28 14:00:32 Done.
+ passwordView.setText("hidden");
+ } else {
+ passwordView.setText(password);
+ }
+
+ if (ChromeFeatureList.isEnabled(VIEW_PASSWORDS)) {
+ hookupCancelDeleteButtons(mView);
+ } else {
+ hookupPasswordButtons(mView);
+ hookupCopyUsernameButton(mView);
+ hookupCopySiteButton(mView);
}
- return v;
+ return mView;
}
// Delete was clicked.
@@ -104,19 +148,127 @@ public class PasswordEntryEditor extends Fragment {
final Button cancelButton = (Button) v.findViewById(R.id.password_entry_editor_cancel);
deleteButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- removeItem();
- deleteButton.setEnabled(false);
- cancelButton.setEnabled(false);
- }
- });
+ @Override
+ public void onClick(View v) {
+ removeItem();
+ deleteButton.setEnabled(false);
+ cancelButton.setEnabled(false);
+ }
+ });
cancelButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- getActivity().finish();
+ @Override
+ public void onClick(View v) {
+ getActivity().finish();
+ }
+ });
+ }
+
+ private void hookupCopyUsernameButton(View v) {
+ final ImageButton copyUsernameButton = (ImageButton) v.findViewById(
+ R.id.password_entry_editor_copy_username);
+ copyUsernameButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ ClipData clip = ClipData.newPlainText("username",
+ getArguments().getString(SavePasswordsPreferences.PASSWORD_LIST_NAME));
+ mClipboard.setPrimaryClip(clip);
+ Toast.makeText(getActivity().getApplicationContext(),
+ R.string.password_entry_editor_username_copied,
+ Toast.LENGTH_SHORT).show();
+ }
+ });
+ }
+
+ private void hookupCopySiteButton(View v) {
+ final ImageButton copySiteButton = (ImageButton) v.findViewById(
+ R.id.password_entry_editor_copy_site);
+ copySiteButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ ClipData clip = ClipData.newPlainText("site",
+ getArguments().getString(SavePasswordsPreferences.PASSWORD_LIST_URL));
+ mClipboard.setPrimaryClip(clip);
+ Toast.makeText(getActivity().getApplicationContext(),
+ R.string.password_entry_editor_site_copied,
+ Toast.LENGTH_SHORT).show();
+ }
+ });
+ }
+
+ private void hookupPasswordButtons(View v) {
+ final ImageButton copyPasswordButton = (ImageButton) v.findViewById(
+ R.id.password_entry_editor_copy_password);
+ final ImageButton viewPasswordButton = (ImageButton) v.findViewById(
+ R.id.password_entry_editor_view_password);
+ copyPasswordButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (!mKeyguardManager.isKeyguardSecure()) {
+ Toast.makeText(getActivity().getApplicationContext(),
+ R.string.password_entry_editor_set_lock_screen,
+ Toast.LENGTH_LONG).show();
+ } else if (MainPreferences.getStartTime() != 0
+ && System.currentTimeMillis() - MainPreferences.getStartTime() < 30000) {
vabr (Chromium) 2016/07/28 09:44:33 The 30000 should be a named constant, as long as y
dozsa 2016/07/28 14:00:32 Done.
+ ClipData clip = ClipData.newPlainText("password",
+ getArguments().getString(
+ SavePasswordsPreferences.PASSWORD_LIST_PASSWORD));
+ mClipboard.setPrimaryClip(clip);
+ Toast.makeText(getActivity().getApplicationContext(),
+ R.string.password_entry_editor_password_copied,
+ Toast.LENGTH_SHORT).show();
+ } else {
+ lockDeviceOnLollipop();
+ }
+ }
+ });
+ viewPasswordButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (!mKeyguardManager.isKeyguardSecure()) {
+ Toast.makeText(getActivity().getApplicationContext(),
+ R.string.password_entry_editor_set_lock_screen,
+ Toast.LENGTH_LONG).show();
+ } else if (MainPreferences.getStartTime() != 0
+ && System.currentTimeMillis() - MainPreferences.getStartTime() < 30000) {
+ viewPasswordButton.setEnabled(false);
+ } else {
+ lockDeviceOnLollipop();
}
- });
+ }
+ });
+ }
+
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ if (requestCode == REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS) {
+ if (resultCode == getActivity().RESULT_OK) {
+ TextView passwordView = (TextView)
+ mView.findViewById(R.id.password_entry_editor_password);
+ passwordView.setText(mExtras.getString(
+ SavePasswordsPreferences.PASSWORD_LIST_PASSWORD));
+ MainPreferences.setStartTime(System.currentTimeMillis());
+ }
+ }
+ }
+
+ /**
+ * Should only be called on Lollipop or above devices.
+ */
+ @TargetApi(VERSION_CODES.LOLLIPOP)
+ private void lockDeviceOnLollipop() {
+ // Use new L feature to lock screen.
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
+ throw new IllegalStateException("Must be called on L+ devices");
+ }
+ if (mKeyguardManager != null) {
+ Intent intent = mKeyguardManager.createConfirmDeviceCredentialIntent(null, null);
+ if (intent != null) {
+ startActivityForResult(intent,
+ REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS);
+ return;
+ }
+ }
}
}

Powered by Google App Engine
This is Rietveld 408576698