Skip to content

Commit

Permalink
Implement the autofill UI for chromium powered android webview.
Browse files Browse the repository at this point in the history
This CL depends on https://codereview.chromium.org/15097004/.

Bug: b/5013406

TBR=battre@chromium.org, palmer@chromium.org
NOTRY=true

contributed by sgurun@chromium.org

Review URL: https://chromiumcodereview.appspot.com/16212007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@208986 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
sgurun@chromium.org committed Jun 27, 2013
1 parent b17e31d commit 32d9fe2
Show file tree
Hide file tree
Showing 29 changed files with 426 additions and 138 deletions.
2 changes: 0 additions & 2 deletions android_webview/android_webview.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@
'<(SHARED_INTERMEDIATE_DIR)/ui/ui_resources/',
],
'sources': [
'browser/aw_autofill_manager_delegate.cc',
'browser/aw_autofill_manager_delegate.h',
'browser/aw_browser_context.cc',
'browser/aw_browser_context.h',
'browser/aw_browser_main_parts.cc',
Expand Down
116 changes: 0 additions & 116 deletions android_webview/browser/aw_autofill_manager_delegate.cc

This file was deleted.

2 changes: 0 additions & 2 deletions android_webview/browser/aw_browser_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include <vector>

#include "android_webview/browser/aw_autofill_manager_delegate.h"
#include "android_webview/browser/aw_download_manager_delegate.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
Expand Down Expand Up @@ -110,7 +109,6 @@ class AwBrowserContext : public content::BrowserContext,
geolocation_permission_context_;
scoped_ptr<AwQuotaManagerBridge> quota_manager_bridge_;
scoped_ptr<AwFormDatabaseService> form_database_service_;
scoped_ptr<AwAutofillManagerDelegate> autofill_manager_delegate_;

AwDownloadManagerDelegate download_manager_delegate_;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// Copyright 2013 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.android_webview;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsoluteLayout;

import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace;
import org.chromium.content.browser.ContentViewCore;
import org.chromium.ui.ViewAndroidDelegate;
import org.chromium.ui.autofill.AutofillPopup;
import org.chromium.ui.autofill.AutofillSuggestion;

// Java counterpart to the AwAutofillManagerDelegate. This class is owned by
// AwContents and has a weak reference from native side.
@JNINamespace("android_webview")
public class AwAutofillManagerDelegate {

private final int mNativeAwAutofillManagerDelegate;
private AutofillPopup mAutofillPopup;
private ViewGroup mContainerView;
private double mDIPScale;
private ContentViewCore mContentViewCore;

@CalledByNative
public static AwAutofillManagerDelegate create(int nativeDelegate) {
return new AwAutofillManagerDelegate(nativeDelegate);
}

private AwAutofillManagerDelegate(int nativeAwAutofillManagerDelegate) {
mNativeAwAutofillManagerDelegate = nativeAwAutofillManagerDelegate;
}

public void init(ContentViewCore contentViewCore, double DIPScale) {
mContentViewCore = contentViewCore;
mContainerView = contentViewCore.getContainerView();
mDIPScale = DIPScale;
}

@CalledByNative
private void showAutofillPopup(float x, float y, float width, float height,
AutofillSuggestion[] suggestions) {

if (mContentViewCore == null) return;

if (mAutofillPopup == null) {
mAutofillPopup = new AutofillPopup(
mContentViewCore.getContext(),
getViewAndroidDelegate(),
new AutofillPopup.AutofillPopupDelegate() {
public void requestHide() { }
public void suggestionSelected(int listIndex) {
nativeSuggestionSelected(mNativeAwAutofillManagerDelegate, listIndex);
}
});
}
mAutofillPopup.setAnchorRect(x, y, width, height);
mAutofillPopup.show(suggestions);
}

@CalledByNative
public void hideAutofillPopup() {
if (mAutofillPopup == null)
return;
mAutofillPopup.hide();
mAutofillPopup = null;
}

private ViewAndroidDelegate getViewAndroidDelegate() {
return new ViewAndroidDelegate() {
@Override
public View acquireAnchorView() {
View anchorView = new View(mContentViewCore.getContext());
mContainerView.addView(anchorView);
return anchorView;
}

@Override
public void setAnchorViewPosition(
View view, float x, float y, float width, float height) {
assert(view.getParent() == mContainerView);

int leftMargin = (int)Math.round(x * mDIPScale);
int topMargin = (int)mContentViewCore.getRenderCoordinates().getContentOffsetYPix()
+ (int)Math.round(y * mDIPScale);

AbsoluteLayout.LayoutParams lp = new AbsoluteLayout.LayoutParams((int)width,
(int)height, leftMargin, topMargin);
view.setLayoutParams(lp);
}

@Override
public void releaseAnchorView(View anchorView) {
mContainerView.removeView(anchorView);
}
};
}

@CalledByNative
private static AutofillSuggestion[] createAutofillSuggestionArray(int size) {
return new AutofillSuggestion[size];
}

/**
* @param array AutofillSuggestion array that should get a new suggestion added.
* @param index Index in the array where to place a new suggestion.
* @param name Name of the suggestion.
* @param label Label of the suggestion.
* @param uniqueId Unique suggestion id.
*/
@CalledByNative
private static void addToAutofillSuggestionArray(AutofillSuggestion[] array, int index,
String name, String label, int uniqueId) {
array[index] = new AutofillSuggestion(name, label, uniqueId);
}

private native void nativeSuggestionSelected(int nativeAwAutofillManagerDelegate, int position);
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ public interface InternalAccessDelegate extends ContentViewCore.InternalAccessDe
private boolean mContainerViewFocused;
private boolean mWindowFocused;

private AwAutofillManagerDelegate mAwAutofillManagerDelegate;

private static final class DestroyRunnable implements Runnable {
private int mNativeAwContents;
private DestroyRunnable(int nativeAwContents) {
Expand Down Expand Up @@ -1330,6 +1332,14 @@ public boolean performAccessibilityAction(int action, Bundle arguments) {
return mContentViewCore.performAccessibilityAction(action, arguments);
}

/**
* @see android.webkit.WebView#clearFormData()
*/
public void hideAutofillPopup() {
if (mAwAutofillManagerDelegate != null)
mAwAutofillManagerDelegate.hideAutofillPopup();
}

//--------------------------------------------------------------------------------------------
// Methods called from native via JNI
//--------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -1469,6 +1479,12 @@ private void scrollContainerViewTo(int x, int y) {
mScrollOffsetManager.scrollContainerViewTo(x, y);
}

@CalledByNative
private void setAwAutofillManagerDelegate(AwAutofillManagerDelegate delegate) {
mAwAutofillManagerDelegate = delegate;
delegate.init(mContentViewCore, mDIPScale);
}

// -------------------------------------------------------------------------------------------
// Helper methods
// -------------------------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions android_webview/native/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ include_rules = [
# Components that Android WebView depends on.
"+components/autofill/content/browser",
"+components/autofill/core/browser",
"+components/autofill/core/common",
"+components/navigation_interception",
"+components/user_prefs",
"+components/web_contents_delegate_android",
]
2 changes: 2 additions & 0 deletions android_webview/native/android_webview_jni_registrar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "android_webview/native/android_webview_jni_registrar.h"

#include "android_webview/native/android_protocol_handler.h"
#include "android_webview/native/aw_autofill_manager_delegate.h"
#include "android_webview/native/aw_contents.h"
#include "android_webview/native/aw_contents_client_bridge.h"
#include "android_webview/native/aw_contents_io_thread_client_impl.h"
Expand All @@ -27,6 +28,7 @@ namespace android_webview {
static base::android::RegistrationMethod kWebViewRegisteredMethods[] = {
// Register JNI for android_webview classes.
{ "AndroidProtocolHandler", RegisterAndroidProtocolHandler },
{ "AwAutofillManagerDelegate", RegisterAwAutofillManagerDelegate },
{ "AwContents", RegisterAwContents },
{ "AwContentsClientBridge", RegisterAwContentsClientBridge },
{ "AwContentsIoThreadClientImpl", RegisterAwContentsIoThreadClientImpl},
Expand Down
Loading

0 comments on commit 32d9fe2

Please sign in to comment.