Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/autofill/PasswordGenerationPopupBridge.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/autofill/PasswordGenerationPopupBridge.java b/chrome/android/java/src/org/chromium/chrome/browser/autofill/PasswordGenerationPopupBridge.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..70c615473e96f31959373f206625174d26ec86c0 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/autofill/PasswordGenerationPopupBridge.java |
| @@ -0,0 +1,215 @@ |
| +// Copyright 2014 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.autofill; |
| + |
| +import android.app.Activity; |
| +import android.os.Handler; |
| + |
| +import org.chromium.base.CalledByNative; |
| +import org.chromium.base.JNINamespace; |
| +import org.chromium.ui.base.ViewAndroid; |
| +import org.chromium.ui.base.ViewAndroidDelegate; |
| +import org.chromium.ui.base.WindowAndroid; |
| + |
| +/** |
| + * JNI call glue for password generation between native and Java objects. |
| + */ |
| +@JNINamespace("autofill") |
| +public class PasswordGenerationPopupBridge implements PasswordGenerationPopup.Delegate { |
| + private final long mNativePasswordGenerationPopupViewAndroid; |
| + private final PasswordGenerationPopup mPopup; |
| + private boolean mRtl; |
| + private int mMinimumWidth; |
| + private boolean mPasswordDisplayed; |
| + private String mPassword; |
| + private String mSuggestionTitle; |
| + private String mExplanationText; |
| + private int mExplanationTextLinkRangeStart; |
| + private int mExplanationTextLinkRangeEnd; |
| + |
| + /** |
| + * A convenience method for the constructor to be invoked from the native counterpart. |
| + * @param nativePopup The pointer to the native counterpart. |
| + * @param windowAndroid The browser window. |
| + * @param containerViewDelegate Interface to acquire and release anchors. |
| + */ |
| + @CalledByNative |
| + private static PasswordGenerationPopupBridge create(long nativePopup, |
| + WindowAndroid windowAndroid, ViewAndroid viewAndroid) { |
| + return new PasswordGenerationPopupBridge(nativePopup, windowAndroid, |
| + viewAndroid.getViewAndroidDelegate()); |
| + } |
| + |
| + /** |
| + * Builds the bridge between native and Java objects. |
| + */ |
| + public PasswordGenerationPopupBridge(long nativePopup, WindowAndroid windowAndroid, |
| + ViewAndroidDelegate containerViewDelegate) { |
| + mNativePasswordGenerationPopupViewAndroid = nativePopup; |
| + Activity activity = windowAndroid.getActivity().get(); |
| + if (activity == null) { |
| + mPopup = null; |
| + new Handler().post(new Runnable() { |
| + @Override |
| + public void run() { |
| + onDismissed(); |
| + } |
| + }); |
| + } else { |
| + mPopup = new PasswordGenerationPopup(activity, containerViewDelegate, this); |
| + } |
| + } |
| + |
| + /** |
| + * Sets the location and size of the popup anchor (password input field). |
| + * @param x X coordinate. |
| + * @param y Y coordinate. |
| + * @param width The width of the anchor. |
| + * @param height The height of the anchor. |
| + */ |
| + @CalledByNative |
| + private void setAnchorRect(float x, float y, float width, float height) { |
| + if (mPopup != null) { |
| + mPopup.setAnchorRect(x, y, width, height); |
| + } |
| + } |
| + |
| + /** |
| + * Shows a password generation popup with specified data. |
| + * @param isRtl True if the popup should be RTL. |
| + * @param mimiumWidth The minimum width for the popup. |
| + * @param passwordDisplayed Whether the generated password should be displayed. |
| + * @param password The auto-generated password to suggest. |
| + * @param suggestionTitle The translated title of the suggestion part of the popup. |
| + * @param explanationText The translated text that explains the popup. |
| + * @param explanationTextLinkRangeStart The start of the range in the explanation text that |
| + * should be a link to the saved passwords. |
| + * @param explanationTextLinkRangeEnd The end of the range in the explanation text that should |
| + * be a link to the saved passwords. |
| + */ |
| + @CalledByNative |
| + private void show(boolean isRtl, int minimumWidth, boolean passwordDisplayed, String password, |
|
aurimas (slooooooooow)
2014/10/16 01:40:18
Can you explain your reasoning why the bridge clas
please use gerrit instead
2014/10/16 03:31:33
I agree that exposing the data through a delegate
|
| + String suggestionTitle, String explanationText, int explanationTextLinkRangeStart, |
| + int explanationTextLinkRangeEnd) { |
| + mRtl = isRtl; |
| + mMinimumWidth = minimumWidth; |
| + mPasswordDisplayed = passwordDisplayed; |
| + mPassword = password; |
| + mSuggestionTitle = suggestionTitle; |
| + mExplanationText = explanationText; |
| + mExplanationTextLinkRangeStart = explanationTextLinkRangeStart; |
| + mExplanationTextLinkRangeEnd = explanationTextLinkRangeEnd; |
| + if (mPopup != null) { |
| + mPopup.show(); |
| + } |
| + } |
| + |
| + /** |
| + * Hides the password generation popup. |
| + */ |
| + @CalledByNative |
| + private void hide() { |
| + if (mPopup != null) { |
| + mPopup.dismiss(); |
| + } |
| + } |
| + |
| + /** |
| + * Native call to opens the "saved passwords" link. |
| + */ |
| + @Override |
| + public void onSavedPasswordsLinkClicked() { |
| + nativeSavedPasswordsLinkClicked(mNativePasswordGenerationPopupViewAndroid); |
| + } |
| + |
| + private native void nativeSavedPasswordsLinkClicked( |
| + long nativePasswordGenerationPopupViewAndroid); |
| + |
| + /** |
| + * Native call to inform the controller that the popup was hidden. |
| + */ |
| + @Override |
| + public void onDismissed() { |
| + nativeDismissed(mNativePasswordGenerationPopupViewAndroid); |
| + } |
| + |
| + private native void nativeDismissed(long nativePasswordGenerationPopupViewAndroid); |
| + |
| + /** |
| + * Native callback to handle the selection of the suggested password in the popup. |
| + */ |
| + @Override |
| + public void onPasswordSelected() { |
| + nativePasswordSelected(mNativePasswordGenerationPopupViewAndroid); |
| + } |
| + |
| + private native void nativePasswordSelected(long nativePasswordGenerationPopupViewAndroid); |
| + |
| + /** |
| + * Returns true of the popup is RTL. |
| + */ |
| + @Override |
| + public boolean isRtl() { |
| + return mRtl; |
| + } |
| + |
| + /** |
| + * Returns the minimum width of the popup. |
| + */ |
| + @Override |
| + public int getMinimumWidth() { |
| + return mMinimumWidth; |
| + } |
| + |
| + /** |
| + * If true, then the generated password should be displayed. |
| + */ |
| + @Override |
| + public boolean isPasswordDisplayed() { |
| + return mPasswordDisplayed; |
| + } |
| + |
| + /** |
| + * Returns the suggested auto-generated password. |
| + */ |
| + @Override |
| + public String getPassword() { |
| + return mPassword; |
| + } |
| + |
| + /** |
| + * Returns the translated text for the title of the popup. |
| + */ |
| + @Override |
| + public String getSuggestionTitle() { |
| + return mSuggestionTitle; |
| + } |
| + |
| + /** |
| + * Returns the translated text of the explanation of the popup. |
| + */ |
| + @Override |
| + public String getExplanationText() { |
| + return mExplanationText; |
| + } |
| + |
| + /** |
| + * Returns the start of the range in the explanation text that should be a link to the saved |
| + * password. |
| + */ |
| + @Override |
| + public int getExplanationTextLinkRangeStart() { |
| + return mExplanationTextLinkRangeStart; |
| + } |
| + |
| + /** |
| + * Returns the end of the range in the explanation text that should be a link to the saved |
| + * passwords. |
| + */ |
| + @Override |
| + public int getExplanationTextLinkRangeEnd() { |
| + return mExplanationTextLinkRangeEnd; |
| + } |
| + } |