Commit 05edf9ed authored by Vaclav Brozek's avatar Vaclav Brozek Committed by Commit Bot

[Android password settings] Display warning before export

This CL adds a warning to be displayed before the user can export
their passwords.

Mocks:
https://docs.google.com/presentation/d/1nIm5OmaOnb85ZAwMZPSVqHT0vkFbsRYZhOzbmznWU_c/edit#slide=id.g289b1efcd8_0_21

Note: the mock shows slightly different styling, but with the UX
designer we settled on using a standard dialog style already existing
in Chromium and checking separately whether that style needs fixing,
rather than introducing inconsistent styling among Chrome's dialogs.

Design: go chrome-pwd-export

Screenshot: https://crbug.com/788701#c7

Bug: 788701
Change-Id: I3a2dbdc24429c5662fdc2b178630a8e45ba603a1
Reviewed-on: https://chromium-review.googlesource.com/803955
Commit-Queue: Vaclav Brozek <vabr@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#522062}
parent 06c20788
// Copyright 2017 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.preferences.password;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import org.chromium.chrome.R;
/**
* Shows the dialog that gives the user some tips for how to treat the exported passwords securely.
*/
public class ExportWarningDialogFragment extends DialogFragment {
// This handler is used to answer the user actions on the dialog.
private DialogInterface.OnClickListener mHandler;
public void setExportWarningHandler(DialogInterface.OnClickListener handler) {
mHandler = handler;
}
/**
* Opens the dialog with the warning and sets the button listener to a fragment identified by ID
* passed in arguments.
*/
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getActivity(), R.style.SimpleDialog)
.setPositiveButton(R.string.save_password_preferences_export_action_title, mHandler)
.setNegativeButton(R.string.cancel, mHandler)
.setMessage(getActivity().getResources().getString(
R.string.settings_passwords_export_description))
.create();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// If there is savedInstanceState, then the dialog is being recreated by Android and will
// lack the necessary callbacks. Dismiss immediately as the settings page will need to be
// recreated anyway.
if (savedInstanceState != null) {
dismiss();
return;
}
}
}
......@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.preferences.password;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
......@@ -12,6 +13,7 @@ import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceCategory;
import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;
import android.support.v7.app.AlertDialog;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.view.Menu;
......@@ -127,7 +129,21 @@ public class SavePasswordsPreferences
/** Continues with the password export flow after the user successfully reauthenticated. */
private void exportAfterReauth() {
// TODO(crbug.com/788701): Show the warning, start the export.
ExportWarningDialogFragment exportWarningDialogFragment = new ExportWarningDialogFragment();
exportWarningDialogFragment.setExportWarningHandler(new DialogInterface.OnClickListener() {
/** On positive button response asks the parent to continue with the export flow. */
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == AlertDialog.BUTTON_POSITIVE) {
exportAfterWarning();
}
}
});
exportWarningDialogFragment.show(getFragmentManager(), null);
}
private void exportAfterWarning() {
// TODO(crbug.com/788701): Start the export.
}
/**
......
......@@ -485,6 +485,9 @@ CHAR-LIMIT guidelines:
<message name="IDS_SAVE_PASSWORD_PREFERENCES_EXPORT_ACTION_DESCRIPTION" desc="The description of a menu item to trigger exporting passwords from the password settings.">
Export passwords stored with Chrome
</message>
<message name="IDS_SETTINGS_PASSWORDS_EXPORT_DESCRIPTION" desc="Text shown to the user who initiated exporting passwords, as a warning before any passwords have been exported.">
Your passwords will be visible to anyone who can see the exported passwords file.
</message>
<!-- Lock Screen Fragment -->
<message name="IDS_LOCKSCREEN_DESCRIPTION_COPY" desc="When a user attempts to copy a password for a particular website into clipboard in Chrome's settings, Chrome launches a lock screen to verify the user's identity and displays the following explanation.">
......
......@@ -968,6 +968,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/preferences/languages/LanguageItem.java",
"java/src/org/chromium/chrome/browser/preferences/languages/LanguageListBaseAdapter.java",
"java/src/org/chromium/chrome/browser/preferences/languages/LanguageListPreference.java",
"java/src/org/chromium/chrome/browser/preferences/password/ExportWarningDialogFragment.java",
"java/src/org/chromium/chrome/browser/preferences/password/PasswordEntryEditor.java",
"java/src/org/chromium/chrome/browser/preferences/password/PasswordManagerHandlerProvider.java",
"java/src/org/chromium/chrome/browser/preferences/password/PasswordReauthenticationFragment.java",
......
......@@ -244,7 +244,8 @@ public class SavePasswordsPreferencesTest {
}
/**
* Ensure that the export menu item is included and hidden behind the overflow menu.
* Check that the export menu item is included and hidden behind the overflow menu. Check that
* the menu displays the warning before letting the user export passwords.
*/
@Test
@SmallTest
......@@ -261,8 +262,14 @@ public class SavePasswordsPreferencesTest {
Espresso.openActionBarOverflowOrOptionsMenu(
InstrumentationRegistry.getInstrumentation().getTargetContext());
// Before tapping the menu item for export, pretend that the last successful
// reauthentication just happened. This will allow the export flow to continue.
ReauthenticationManager.setLastReauthTimeMillis(System.currentTimeMillis());
Espresso.onView(withText(R.string.save_password_preferences_export_action_title))
.perform(click());
Espresso.onView(withText(R.string.settings_passwords_export_description))
.check(matches(isDisplayed()));
}
/**
......
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