Chromium Code Reviews| 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..e7783e08e43333ec6375469e28fdc62fe068c6f2 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,15 @@ 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 final int REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS = 1; |
|
vabr (Chromium)
2016/07/26 20:03:18
nit: Also static.
dozsa
2016/07/27 19:04:44
Done.
|
| + |
| + private KeyguardManager mKeyguardManager; |
| + |
| @Override |
| public void onCreate(Bundle savedInstanceState) { |
| super.onCreate(savedInstanceState); |
| @@ -47,7 +66,16 @@ public class PasswordEntryEditor extends Fragment { |
| v = 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)) { |
| + mKeyguardManager = (KeyguardManager) getActivity() |
| + .getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE); |
| + ImageButton copyPasswordButton = (ImageButton) v.findViewById( |
| + R.id.password_entry_editor_copy_password); |
| + ImageButton viewPasswordButton = (ImageButton) v.findViewById( |
| + R.id.password_entry_editor_view_password); |
| + } |
| // Extras are set on this intent in class SavePasswordsPreferences. |
| Bundle extras = getArguments(); |
| assert extras != null; |
| @@ -66,8 +94,13 @@ public class PasswordEntryEditor extends Fragment { |
| String url = extras.getString(SavePasswordsPreferences.PASSWORD_LIST_URL); |
| TextView urlView = (TextView) v.findViewById(R.id.password_entry_editor_url); |
| urlView.setText(url); |
| + |
| if (!ChromeFeatureList.isEnabled(VIEW_PASSWORDS)) { |
| hookupCancelDeleteButtons(v); |
| + } else { |
| + hookupPasswordButtons(v); |
| + hookupCopyUsernameButton(v); |
| + hookupCopySiteButton(v); |
| } |
| return v; |
| } |
| @@ -100,23 +133,118 @@ public class PasswordEntryEditor extends Fragment { |
| } |
| private void hookupCancelDeleteButtons(View v) { |
| + |
|
melandory
2016/07/26 22:27:29
nit: remove line
dozsa
2016/07/27 19:04:44
Done.
|
| final Button deleteButton = (Button) v.findViewById(R.id.password_entry_editor_delete); |
| 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() { |
|
melandory
2016/07/26 22:27:29
Shouldn't we use OnLongClickListener? I think it's
dozsa
2016/07/27 19:04:44
I will ask Hwi!
vabr (Chromium)
2016/07/29 12:08:56
If Hwi responds, then great. If she does not, I pr
|
| + @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 { |
| + 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 { |
| + 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) { |
| + 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; |
| + } |
| + } |
| } |
| } |
| + |
|
vabr (Chromium)
2016/07/26 20:03:18
nit: Please remove.
dozsa
2016/07/27 19:04:45
Done.
|
| + |
|
melandory
2016/07/26 22:27:29
nit: remove
dozsa
2016/07/27 19:04:44
Done.
|