blob: 3609eddc8f98a4879c49b9c8790757bb9e33ace0 [file] [log] [blame]
// 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 org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.touch_to_fill.data.Credential;
import org.chromium.ui.base.WindowAndroid;
import java.util.Arrays;
/**
* This bridge creates and initializes a {@link TouchToFillComponent} on construction and forwards
* native calls to it.
*/
class TouchToFillBridge implements TouchToFillComponent.Delegate {
private long mNativeView;
private final TouchToFillComponent mTouchToFillComponent;
private TouchToFillBridge(long nativeView, WindowAndroid windowAndroid) {
mNativeView = nativeView;
ChromeActivity activity = (ChromeActivity) windowAndroid.getActivity().get();
mTouchToFillComponent = new TouchToFillCoordinator();
mTouchToFillComponent.initialize(activity, activity.getBottomSheetController(), this);
}
@CalledByNative
private static TouchToFillBridge create(long nativeView, WindowAndroid windowAndroid) {
return new TouchToFillBridge(nativeView, windowAndroid);
}
@CalledByNative
private void destroy() {
mNativeView = 0;
}
@CalledByNative
private static Credential[] createCredentialArray(int size) {
return new Credential[size];
}
@CalledByNative
private static void insertCredential(Credential[] credentials, int index, String username,
String password, String formattedUsername, String originUrl,
boolean isPublicSuffixMatch) {
credentials[index] = new Credential(
username, password, formattedUsername, originUrl, isPublicSuffixMatch);
}
@CalledByNative
private void showCredentials(
String formattedUrl, boolean isOriginSecure, Credential[] credentials) {
mTouchToFillComponent.showCredentials(
formattedUrl, isOriginSecure, Arrays.asList(credentials));
}
@Override
public void onDismissed() {
if (mNativeView != 0) TouchToFillBridgeJni.get().onDismiss(mNativeView);
}
@Override
public void onCredentialSelected(Credential credential) {
assert mNativeView != 0 : "The native side is already dismissed";
TouchToFillBridgeJni.get().onCredentialSelected(mNativeView, credential);
}
@NativeMethods
interface Natives {
void onCredentialSelected(long nativeTouchToFillViewImpl, Credential credential);
void onDismiss(long nativeTouchToFillViewImpl);
}
}