Commit f49fd4cf authored by Friedrich Horschig's avatar Friedrich Horschig Committed by Commit Bot

[Passwords TTF] Add interface and factory to construct coordinator

This CL adds the interface which will be implemented by bridge and
coordinator. The build file currently doesn't add the public_java
target to chrome_java since this would cause a cyclic dependency.


The interface allows to request that the TouchToFill component shows
a set of credentials and ensures that the delegate is notified when
users dismiss the sheet without selecting anything.

Bug: 957532,1004415
Change-Id: Icbba0471febb88dfb4f87d33a1ea4a53992767ff
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1798707
Commit-Queue: Friedrich [CET] <fhorschig@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarJan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697960}
parent da9d289c
...@@ -510,6 +510,7 @@ java_group("chrome_all_java") { ...@@ -510,6 +510,7 @@ java_group("chrome_all_java") {
"//chrome/android/features/keyboard_accessory:internal_java", "//chrome/android/features/keyboard_accessory:internal_java",
"//chrome/android/features/media_router:java", "//chrome/android/features/media_router:java",
"//chrome/android/features/test_dummy/internal:base_module_java", "//chrome/android/features/test_dummy/internal:base_module_java",
"//chrome/browser/touch_to_fill/android/internal:java",
] ]
if (disable_autofill_assistant_dfm) { if (disable_autofill_assistant_dfm) {
...@@ -535,6 +536,7 @@ group("jni_headers") { ...@@ -535,6 +536,7 @@ group("jni_headers") {
"//chrome/android/features/media_router:jni_headers", "//chrome/android/features/media_router:jni_headers",
"//chrome/android/public/profiles:jni_headers", "//chrome/android/public/profiles:jni_headers",
"//chrome/browser/image_fetcher:jni_headers", "//chrome/browser/image_fetcher:jni_headers",
"//chrome/browser/touch_to_fill/android:jni_headers",
"//chrome/lib/util/public/android:jni_headers", "//chrome/lib/util/public/android:jni_headers",
] ]
} }
......
include_rules = [
"+chrome/android",
]
# Copyright 2019 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.
import("//build/config/android/rules.gni")
import("//chrome/android/features/android_library_factory_tmpl.gni")
generate_jni("jni_headers") {
sources = [
"java/src/org/chromium/chrome/browser/touch_to_fill/data/Credential.java",
]
}
android_library("public_java") {
deps = [
# TODO(crbug.com/1004415): Remove dependency on chrome_java and depend on
# bottomsheet directly. Add public_java to chrome_java target instead.
"//chrome/android:chrome_java",
"//chrome/android:chrome_public_java",
"//ui/android:ui_java",
]
java_files = [
"java/src/org/chromium/chrome/browser/touch_to_fill/data/Credential.java",
"java/src/org/chromium/chrome/browser/touch_to_fill/TouchToFillComponent.java",
]
}
...@@ -15,18 +15,35 @@ will be shown instead (i.e. by changing the focus). ...@@ -15,18 +15,35 @@ will be shown instead (i.e. by changing the focus).
## Folder Structure ## Folder Structure
#### / #### java/
The root folder contains the public interface of this component and data that is The root folder contains the public interface of this component and data that is
used to fill it with content, e.g. Crendentials. This folder also contains the used to fill it with content, e.g. Crendentials. This folder also contains the
code to instantiate the component. factory to instantiate the component. The factory has two implementations:
* an auto-generated one returning null which is used in tests and targets that
don't directly depend on this component
* one that provides the actual implementation
Add `chrome/browser/touch_to_fill/android:public_java` as dependency to use the
interface and classes defined here.
#### java/internal/
Contains the actual implementation. Don't try to use any class defined here
outside of this package. If you need access to any method, consider making it
part of the public interface as defined in `TouchToFillComponent`
This folder contains a separate [README](internal/README.md) that explains in
detail how the architecture looks like and how to extend the component further.
## Example usage ## Example usage
``` java ``` java
// Use factory to instantiate the component: // Currently, you need access to internal/ to instantiate the component:
TouchToFillComponent component = TouchToFillComponentFactory.createComponent(); TouchToFillComponent component = new TouchToFillCoordinator(/*...*/);
component.initialize(activity, activity.getBottomSheetController(), () -> { component.initialize(activity, activity.getBottomSheetController(), () -> {
// Things to do when the component is dismissed. // Things to do when the component is dismissed.
......
# Copyright 2019 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.
import("//build/config/android/rules.gni")
import("//chrome/common/features.gni")
android_library("java") {
deps = [
"//base:base_java",
"//chrome/android:chrome_java",
"//chrome/browser/touch_to_fill/android:public_java",
"//ui/android:ui_java",
]
java_files = [ "java/src/org/chromium/chrome/browser/touch_to_fill/TouchToFillCoordinator.java" ]
}
# Touch To Fill Android Feature
This folder contains the internal parts of the Touch To Fill component. Files,
classes and methods defined in here are not meant to be used outside of this
package.
This document provides a brief overview of the architecture.
[TOC]
## Component structure
This component follows the typical
[MVC](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller)
structure that is widely used in Chrome on Android. The MVC structures separates
logic from representation:
* The [controller](#Controller) creates and connects all subcomponents and
performs logic that affects the visual appearance of the component.
* The [model](#Model) keeps all state that affects the visual appearance of the
component. Changes made to it are automatically propagated to the view by a
Model-Change-Processor (MCP) as defined in
`//src/ui/android/java/src/org/chromium/ui/modelutil/`
* The [view](#View) is the representation of the component. It enforces styles
and is mostly called by a view binder to set mutable properties.
A typical request to the Touch to Fill component API that intends to change the
visible appearance involves all component parts. For example if the API caller
requests to show new credentials:
1. The API caller asks the controller to show a set of
`credentials`.
1. The controller prepares and filters the `credentials` for display.
2. The controller writes the prepared credentials into the [model](#Model).
2. The MCP picks up model changes.
1. The MCP identifies that the `CREDENTIAL_LIST` property was changed.
2. The MCP uses a ViewBinder to bind each changed credential to the
corresponding view (e.g. a TextView inside a RecyclerView).
3. The view renders the changed credential list.
1. The view may apply style, RTL settings and event handlers for click events.
// Copyright 2019 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.touch_to_fill;
import android.content.Context;
import org.chromium.base.Callback;
import org.chromium.chrome.browser.touch_to_fill.data.Credential;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController;
import java.util.List;
/**
* Creates the TouchToFill component. TouchToFill uses a bottom sheet to let the
* user select a set of credentials and fills it into the focused form.
*/
public class TouchToFillCoordinator implements TouchToFillComponent {
TouchToFillCoordinator() {}
@Override
public void initialize(Context context, BottomSheetController sheetController,
TouchToFillComponent.Delegate delegate) {
// TODO(crbug.com/957532): Implement.
}
@Override
public void showCredentials(
String formattedUrl, List<Credential> credentials, Callback<Credential> callback) {
// TODO(crbug.com/957532): Implement.
}
}
// Copyright 2019 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.touch_to_fill;
import android.content.Context;
import org.chromium.base.Callback;
import org.chromium.chrome.browser.touch_to_fill.data.Credential;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController;
import java.util.List;
/**
* This component allows to fill credentials into a form. It suppresses the keyboard until dismissed
* and acts as a safe surface to fill credentials from.
*/
public interface TouchToFillComponent {
/**
* This delegate is called when the TouchToFill component is interacted with (e.g. dismissed or
* a suggestion was selected).
*/
interface Delegate {
/**
* Called when the user dismisses the TouchToFillComponent. Not called if a suggestion was
* selected.
*/
void onDismissed();
}
/**
* Initializes the component.
* @param context A {@link Context} to create views and retrieve resources.
* @param sheetController A {@link BottomSheetController} used to show/hide the sheet.
* @param delegate A {@link Delegate} that handles dismiss events.
*/
void initialize(Context context, BottomSheetController sheetController, Delegate delegate);
/**
* Displays the given credentials in a new bottom sheet.
* @param formattedUrl A {@link String} that contains the URL to display credentials for.
* @param credentials A list of {@link Credential}s that will be displayed.
* @param callback A {@link Callback} called when the user selects a credential to be filled.
*/
void showCredentials(
String formattedUrl, List<Credential> credentials, Callback<Credential> callback);
}
// Copyright 2019 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.touch_to_fill.data;
import org.chromium.base.annotations.CalledByNative;
/**
* This class holds the data used to represent a selectable credential in the Touch To Fill sheet.
*/
public class Credential {
private final String mUsername;
private final String mPassword;
private final String mOriginUrl;
private final boolean mIsPublicSuffixMatch;
/**
* @param username Username shown to the user.
* @param password Password shown to the user.
* @param originUrl Origin URL shown to the user in case this credential is a PSL match.
* @param isPublicSuffixMatch Indicating whether the credential is a PSL match.
*/
public Credential(
String username, String password, String originUrl, boolean isPublicSuffixMatch) {
mUsername = username;
mPassword = password;
mOriginUrl = originUrl;
mIsPublicSuffixMatch = isPublicSuffixMatch;
}
@CalledByNative
public String getUsername() {
return mUsername;
}
@CalledByNative
public String getPassword() {
return mPassword;
}
@CalledByNative
public String getOriginUrl() {
return mOriginUrl;
}
@CalledByNative
public boolean isPublicSuffixMatch() {
return mIsPublicSuffixMatch;
}
}
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