Commit 343aeab7 authored by Ioana Pandele's avatar Ioana Pandele Committed by Commit Bot

Modal dialog for password generation on Android

This dialog is prompted when the user taps the password generation
button in the keyboard accessory or in the accessory sheet and is meant
to replace the password generation popup.

It is currently made to display the generated password and 2 buttons to
accept and reject it. It will (not included in this CL) also display
the explanatory text that is currently present in the generation popup.

Bug:835234

Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_slimming_paint_v2;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I98107745678c153819f00555ebdb61917121606a
Reviewed-on: https://chromium-review.googlesource.com/1064611
Commit-Queue: Ioana Pandele <ioanap@chromium.org>
Reviewed-by: default avatarBernhard Bauer <bauerb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567985}
parent bc8fa3fc
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 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. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/AlertDialogContent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/generated_password"
android:textAppearance="@style/BlackHint1"/>
</LinearLayout>
\ No newline at end of file
// Copyright 2018 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.password_manager;
import android.support.annotation.NonNull;
import org.chromium.base.Callback;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.modaldialog.ModalDialogManager;
/**
* The coordinator for the password generation modal dialog. Manages the sub-component objects
* and handles communication with the {@link ModalDialogManager}.
*/
public class PasswordGenerationDialogCoordinator {
private final ModalDialogManager mModalDialogManager;
private final PasswordGenerationDialogModel mModel;
private final PasswordGenerationDialogViewHolder mViewHolder;
public PasswordGenerationDialogCoordinator(@NonNull ChromeActivity activity) {
mModel = new PasswordGenerationDialogModel();
mViewHolder = new PasswordGenerationDialogViewHolder(activity);
mModalDialogManager = activity.getModalDialogManager();
}
public void showDialog(
String generatedPassword, Callback<Boolean> onPasswordAcceptedOrRejected) {
PasswordGenerationDialogMediator.initializeState(
mModel, generatedPassword, onPasswordAcceptedOrRejected);
PasswordGenerationDialogViewBinder.bind(mModel, mViewHolder);
mModalDialogManager.showDialog(mViewHolder.getView(), ModalDialogManager.APP_MODAL);
}
public void dismissDialog() {
mModalDialogManager.dismissDialog(mViewHolder.getView());
}
}
// Copyright 2018 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.password_manager;
import org.chromium.base.Callback;
/** Mediator class responsible for initializing the model state. */
public class PasswordGenerationDialogMediator {
public static void initializeState(PasswordGenerationDialogModel model, String password,
Callback<Boolean> onPasswordAcceptedOrRejected) {
model.setValue(PasswordGenerationDialogModel.GENERATED_PASSWORD, password);
model.setValue(PasswordGenerationDialogModel.PASSWORD_ACTION_CALLBACK,
onPasswordAcceptedOrRejected);
}
}
// Copyright 2018 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.password_manager;
import org.chromium.base.Callback;
import org.chromium.chrome.browser.modelutil.PropertyModel;
/**
* Data model for the password generation modal dialog.
*/
class PasswordGenerationDialogModel extends PropertyModel {
/** The generated password to be displayed in the dialog. */
public static final ObjectPropertyKey<String> GENERATED_PASSWORD = new ObjectPropertyKey<>();
/** Callback invoked when the password is accepted or rejected by the user. */
public static final ObjectPropertyKey<Callback<Boolean>> PASSWORD_ACTION_CALLBACK =
new ObjectPropertyKey<>();
/** Default constructor */
public PasswordGenerationDialogModel() {
super(GENERATED_PASSWORD, PASSWORD_ACTION_CALLBACK);
}
}
// Copyright 2018 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.password_manager;
import org.chromium.base.Callback;
import org.chromium.chrome.browser.modaldialog.ModalDialogView;
/** Class responsible for binding the model and the view. On bind, it lazily initializes the view
* since all the needed data was made available at this point.
*/
public class PasswordGenerationDialogViewBinder {
private static class PasswordGenerationDialogController implements ModalDialogView.Controller {
private final Callback<Boolean> mPasswordActionCallback;
public PasswordGenerationDialogController(Callback<Boolean> passwordActionCallback) {
mPasswordActionCallback = passwordActionCallback;
}
@Override
public void onClick(int buttonType) {
switch (buttonType) {
case ModalDialogView.BUTTON_POSITIVE:
mPasswordActionCallback.onResult(true);
break;
case ModalDialogView.BUTTON_NEGATIVE:
mPasswordActionCallback.onResult(false);
break;
default:
assert false : "Unexpected button pressed in dialog: " + buttonType;
}
}
@Override
public void onCancel() {
mPasswordActionCallback.onResult(false);
}
@Override
public void onDismiss() {
mPasswordActionCallback.onResult(false);
}
}
public static void bind(
PasswordGenerationDialogModel model, PasswordGenerationDialogViewHolder viewHolder) {
viewHolder.setController(new PasswordGenerationDialogController(
model.getValue(PasswordGenerationDialogModel.PASSWORD_ACTION_CALLBACK)));
viewHolder.setGeneratedPassword(
model.getValue(PasswordGenerationDialogModel.GENERATED_PASSWORD));
viewHolder.initializeView();
}
}
// Copyright 2018 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.password_manager;
import android.content.Context;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.widget.TextView;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.modaldialog.ModalDialogView;
/** Class holding a {@link ModalDialogView} that is lazily created after all the data is made
* available.
*/
public class PasswordGenerationDialogViewHolder {
private ModalDialogView mView;
private String mGeneratedPassword;
private Context mContext;
private ModalDialogView.Controller mController;
// TODO(ioanap): Change to a text label for now.
private TextView mGeneratedPasswordText;
public PasswordGenerationDialogViewHolder(Context context) {
mContext = context;
}
public void setGeneratedPassword(String generatedPassword) {
mGeneratedPassword = generatedPassword;
}
public void setController(ModalDialogView.Controller controller) {
mController = controller;
}
public void initializeView() {
ModalDialogView.Params params = new ModalDialogView.Params();
params.title = mContext.getString(R.string.password_generation_dialog_title);
params.positiveButtonTextId = R.string.password_generation_dialog_use_password_button;
params.negativeButtonTextId = R.string.password_generation_dialog_cancel_button;
params.customView =
LayoutInflater.from(mContext).inflate(R.layout.password_generation_dialog, null);
mGeneratedPasswordText = params.customView.findViewById(R.id.generated_password);
mGeneratedPasswordText.setText(mGeneratedPassword);
mView = new ModalDialogView(mController, params);
}
@Nullable
public ModalDialogView getView() {
return mView;
}
}
......@@ -1832,6 +1832,17 @@ To obtain new licenses, connect to the internet and play your downloaded content
Web View
</message>
<!-- Password manager dialogs -->
<message name="IDS_PASSWORD_GENERATION_DIALOG_TITLE" desc="Text shown in a modal dialog that displays a generated password. This dialog is triggered by the user requesting to generate a password.">
Suggested password
</message>
<message name="IDS_PASSWORD_GENERATION_DIALOG_CANCEL_BUTTON" desc="Text for the cancel button belonging to the modal dialog that displays a generated password. Can be used by the user to cancel the password generation flow.">
Cancel
</message>
<message name="IDS_PASSWORD_GENERATION_DIALOG_USE_PASSWORD_BUTTON" desc="Text for a button belonging to the modal dialog that displayes a generated password. Can be used by the user to accept the generated password.">
Use password
</message>
<!-- Runtime permission strings -->
<message name="IDS_INFOBAR_MISSING_CAMERA_PERMISSION_TEXT" desc="Text shown in an infobar when a website has requested access to the camera capabilities, but Chrome is missing the Android camera permission.">
Chrome needs permission to access your camera for this site.
......
......@@ -943,6 +943,11 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/partnercustomizations/PartnerBrowserCustomizations.java",
"java/src/org/chromium/chrome/browser/password_manager/AccountChooserDialog.java",
"java/src/org/chromium/chrome/browser/password_manager/AutoSigninFirstRunDialog.java",
"java/src/org/chromium/chrome/browser/password_manager/PasswordGenerationDialogCoordinator.java",
"java/src/org/chromium/chrome/browser/password_manager/PasswordGenerationDialogMediator.java",
"java/src/org/chromium/chrome/browser/password_manager/PasswordGenerationDialogModel.java",
"java/src/org/chromium/chrome/browser/password_manager/PasswordGenerationDialogViewBinder.java",
"java/src/org/chromium/chrome/browser/password_manager/PasswordGenerationDialogViewHolder.java",
"java/src/org/chromium/chrome/browser/password_manager/Credential.java",
"java/src/org/chromium/chrome/browser/payments/AddressEditor.java",
"java/src/org/chromium/chrome/browser/payments/AndroidPaymentAppFactory.java",
......
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