Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Side by Side Diff: android_webview/java/src/org/chromium/android_webview/AwContents.java

Issue 2839023003: WebView autofill implementation (Closed)
Patch Set: sync Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.android_webview; 5 package org.chromium.android_webview;
6 6
7 import android.annotation.SuppressLint; 7 import android.annotation.SuppressLint;
8 import android.annotation.TargetApi; 8 import android.annotation.TargetApi;
9 import android.app.Activity; 9 import android.app.Activity;
10 import android.content.ComponentCallbacks2; 10 import android.content.ComponentCallbacks2;
(...skipping 12 matching lines...) Expand all
23 import android.net.http.SslCertificate; 23 import android.net.http.SslCertificate;
24 import android.os.AsyncTask; 24 import android.os.AsyncTask;
25 import android.os.Build; 25 import android.os.Build;
26 import android.os.Bundle; 26 import android.os.Bundle;
27 import android.os.Handler; 27 import android.os.Handler;
28 import android.os.Message; 28 import android.os.Message;
29 import android.os.SystemClock; 29 import android.os.SystemClock;
30 import android.text.TextUtils; 30 import android.text.TextUtils;
31 import android.util.Base64; 31 import android.util.Base64;
32 import android.util.Pair; 32 import android.util.Pair;
33 import android.util.SparseArray;
33 import android.view.DragEvent; 34 import android.view.DragEvent;
34 import android.view.KeyEvent; 35 import android.view.KeyEvent;
35 import android.view.MotionEvent; 36 import android.view.MotionEvent;
36 import android.view.View; 37 import android.view.View;
37 import android.view.ViewGroup; 38 import android.view.ViewGroup;
38 import android.view.ViewStructure; 39 import android.view.ViewStructure;
39 import android.view.accessibility.AccessibilityEvent; 40 import android.view.accessibility.AccessibilityEvent;
40 import android.view.accessibility.AccessibilityNodeInfo; 41 import android.view.accessibility.AccessibilityNodeInfo;
41 import android.view.accessibility.AccessibilityNodeProvider; 42 import android.view.accessibility.AccessibilityNodeProvider;
42 import android.view.animation.AnimationUtils; 43 import android.view.animation.AnimationUtils;
43 import android.view.inputmethod.EditorInfo; 44 import android.view.inputmethod.EditorInfo;
44 import android.view.inputmethod.InputConnection; 45 import android.view.inputmethod.InputConnection;
45 import android.webkit.JavascriptInterface; 46 import android.webkit.JavascriptInterface;
46 import android.webkit.ValueCallback; 47 import android.webkit.ValueCallback;
47 48
48 import org.chromium.android_webview.permission.AwGeolocationCallback; 49 import org.chromium.android_webview.permission.AwGeolocationCallback;
49 import org.chromium.android_webview.permission.AwPermissionRequest; 50 import org.chromium.android_webview.permission.AwPermissionRequest;
50 import org.chromium.android_webview.renderer_priority.RendererPriority; 51 import org.chromium.android_webview.renderer_priority.RendererPriority;
51 import org.chromium.base.LocaleUtils; 52 import org.chromium.base.LocaleUtils;
52 import org.chromium.base.Log; 53 import org.chromium.base.Log;
53 import org.chromium.base.ObserverList; 54 import org.chromium.base.ObserverList;
54 import org.chromium.base.ThreadUtils; 55 import org.chromium.base.ThreadUtils;
55 import org.chromium.base.TraceEvent; 56 import org.chromium.base.TraceEvent;
56 import org.chromium.base.VisibleForTesting; 57 import org.chromium.base.VisibleForTesting;
57 import org.chromium.base.annotations.CalledByNative; 58 import org.chromium.base.annotations.CalledByNative;
58 import org.chromium.base.annotations.JNINamespace; 59 import org.chromium.base.annotations.JNINamespace;
59 import org.chromium.base.annotations.SuppressFBWarnings; 60 import org.chromium.base.annotations.SuppressFBWarnings;
61 import org.chromium.components.autofill.AutofillProvider;
60 import org.chromium.components.navigation_interception.InterceptNavigationDelega te; 62 import org.chromium.components.navigation_interception.InterceptNavigationDelega te;
61 import org.chromium.components.navigation_interception.NavigationParams; 63 import org.chromium.components.navigation_interception.NavigationParams;
62 import org.chromium.content.browser.AppWebMessagePort; 64 import org.chromium.content.browser.AppWebMessagePort;
63 import org.chromium.content.browser.ContentViewCore; 65 import org.chromium.content.browser.ContentViewCore;
64 import org.chromium.content.browser.ContentViewStatics; 66 import org.chromium.content.browser.ContentViewStatics;
65 import org.chromium.content.browser.SmartClipProvider; 67 import org.chromium.content.browser.SmartClipProvider;
66 import org.chromium.content_public.browser.GestureStateListener; 68 import org.chromium.content_public.browser.GestureStateListener;
67 import org.chromium.content_public.browser.JavaScriptCallback; 69 import org.chromium.content_public.browser.JavaScriptCallback;
68 import org.chromium.content_public.browser.LoadUrlParams; 70 import org.chromium.content_public.browser.LoadUrlParams;
69 import org.chromium.content_public.browser.MessagePort; 71 import org.chromium.content_public.browser.MessagePort;
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 */ 242 */
241 public static class DependencyFactory { 243 public static class DependencyFactory {
242 public AwLayoutSizer createLayoutSizer() { 244 public AwLayoutSizer createLayoutSizer() {
243 return new AwLayoutSizer(); 245 return new AwLayoutSizer();
244 } 246 }
245 247
246 public AwScrollOffsetManager createScrollOffsetManager( 248 public AwScrollOffsetManager createScrollOffsetManager(
247 AwScrollOffsetManager.Delegate delegate) { 249 AwScrollOffsetManager.Delegate delegate) {
248 return new AwScrollOffsetManager(delegate); 250 return new AwScrollOffsetManager(delegate);
249 } 251 }
252
253 public AutofillProvider createAutofillProvider(Context context, ViewGrou p containerView) {
254 return null;
255 }
250 } 256 }
251 257
252 /** 258 /**
253 * Visual state callback, see {@link #insertVisualStateCallback} for details . 259 * Visual state callback, see {@link #insertVisualStateCallback} for details .
254 * 260 *
255 */ 261 */
256 @VisibleForTesting 262 @VisibleForTesting
257 public abstract static class VisualStateCallback { 263 public abstract static class VisualStateCallback {
258 /** 264 /**
259 * @param requestId the id passed to {@link AwContents#insertVisualState Callback} 265 * @param requestId the id passed to {@link AwContents#insertVisualState Callback}
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 private Handler mHandler; 363 private Handler mHandler;
358 364
359 // True when this AwContents has been destroyed. 365 // True when this AwContents has been destroyed.
360 // Do not use directly, call isDestroyed() instead. 366 // Do not use directly, call isDestroyed() instead.
361 private boolean mIsDestroyed; 367 private boolean mIsDestroyed;
362 368
363 // True if this AwContents is in no operation state. 369 // True if this AwContents is in no operation state.
364 // Do not use directly, call isNoOperation() instead. 370 // Do not use directly, call isNoOperation() instead.
365 private boolean mIsNoOperation; 371 private boolean mIsNoOperation;
366 372
373 private AutofillProvider mAutofillProvider;
374
367 private static String sCurrentLocales = ""; 375 private static String sCurrentLocales = "";
368 376
369 private Paint mPaintForNWorkaround; 377 private Paint mPaintForNWorkaround;
370 378
371 private static final class AwContentsDestroyRunnable implements Runnable { 379 private static final class AwContentsDestroyRunnable implements Runnable {
372 private final long mNativeAwContents; 380 private final long mNativeAwContents;
373 // Hold onto a reference to the window (via its wrapper), so that it is not destroyed 381 // Hold onto a reference to the window (via its wrapper), so that it is not destroyed
374 // until we are done here. 382 // until we are done here.
375 private final WindowAndroidWrapper mWindowAndroid; 383 private final WindowAndroidWrapper mWindowAndroid;
376 384
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 mBrowserContext = browserContext; 754 mBrowserContext = browserContext;
747 755
748 // setWillNotDraw(false) is required since WebView draws it's own conten ts using it's 756 // setWillNotDraw(false) is required since WebView draws it's own conten ts using it's
749 // container view. If this is ever not the case we should remove this, a s it removes 757 // container view. If this is ever not the case we should remove this, a s it removes
750 // Android's gatherTransparentRegion optimization for the view. 758 // Android's gatherTransparentRegion optimization for the view.
751 mContainerView = containerView; 759 mContainerView = containerView;
752 mContainerView.setWillNotDraw(false); 760 mContainerView.setWillNotDraw(false);
753 761
754 mHandler = new Handler(); 762 mHandler = new Handler();
755 mContext = context; 763 mContext = context;
764 mAutofillProvider = dependencyFactory.createAutofillProvider(context, mC ontainerView);
756 mAppTargetSdkVersion = mContext.getApplicationInfo().targetSdkVersion; 765 mAppTargetSdkVersion = mContext.getApplicationInfo().targetSdkVersion;
757 mInternalAccessAdapter = internalAccessAdapter; 766 mInternalAccessAdapter = internalAccessAdapter;
758 mNativeDrawGLFunctorFactory = nativeDrawGLFunctorFactory; 767 mNativeDrawGLFunctorFactory = nativeDrawGLFunctorFactory;
759 mInitialFunctor = new AwGLFunctor(mNativeDrawGLFunctorFactory, mContaine rView); 768 mInitialFunctor = new AwGLFunctor(mNativeDrawGLFunctorFactory, mContaine rView);
760 mCurrentFunctor = mInitialFunctor; 769 mCurrentFunctor = mInitialFunctor;
761 mContentsClient = contentsClient; 770 mContentsClient = contentsClient;
762 mContentsClient.getCallbackHelper().setCancelCallbackPoller( 771 mContentsClient.getCallbackHelper().setCancelCallbackPoller(
763 new AwContentsClientCallbackHelper.CancelCallbackPoller() { 772 new AwContentsClientCallbackHelper.CancelCallbackPoller() {
764 @Override 773 @Override
765 public boolean cancelAllCallbacks() { 774 public boolean cancelAllCallbacks() {
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
955 if (containerViewAttached && !mIsAttachedToWindow) { 964 if (containerViewAttached && !mIsAttachedToWindow) {
956 awViewMethodsImpl.onAttachedToWindow(); 965 awViewMethodsImpl.onAttachedToWindow();
957 } else if (!containerViewAttached && mIsAttachedToWindow) { 966 } else if (!containerViewAttached && mIsAttachedToWindow) {
958 awViewMethodsImpl.onDetachedFromWindow(); 967 awViewMethodsImpl.onDetachedFromWindow();
959 } 968 }
960 awViewMethodsImpl.onSizeChanged( 969 awViewMethodsImpl.onSizeChanged(
961 mContainerView.getWidth(), mContainerView.getHeight(), 0, 0); 970 mContainerView.getWidth(), mContainerView.getHeight(), 0, 0);
962 awViewMethodsImpl.onWindowFocusChanged(mContainerView.hasWindowFocus()); 971 awViewMethodsImpl.onWindowFocusChanged(mContainerView.hasWindowFocus());
963 awViewMethodsImpl.onFocusChanged(mContainerView.hasFocus(), 0, null); 972 awViewMethodsImpl.onFocusChanged(mContainerView.hasFocus(), 0, null);
964 mContainerView.requestLayout(); 973 mContainerView.requestLayout();
974 if (mAutofillProvider != null) mAutofillProvider.onContainerViewChanged( mContainerView);
965 } 975 }
966 976
967 // This class destroys the WindowAndroid when after it is gc-ed. 977 // This class destroys the WindowAndroid when after it is gc-ed.
968 private static class WindowAndroidWrapper { 978 private static class WindowAndroidWrapper {
969 private final WindowAndroid mWindowAndroid; 979 private final WindowAndroid mWindowAndroid;
970 private final CleanupReference mCleanupReference; 980 private final CleanupReference mCleanupReference;
971 981
972 private static final class DestroyRunnable implements Runnable { 982 private static final class DestroyRunnable implements Runnable {
973 private final WindowAndroid mWindowAndroid; 983 private final WindowAndroid mWindowAndroid;
974 private DestroyRunnable(WindowAndroid windowAndroid) { 984 private DestroyRunnable(WindowAndroid windowAndroid) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1062 WebContents webContents = nativeGetWebContents(mNativeAwContents); 1072 WebContents webContents = nativeGetWebContents(mNativeAwContents);
1063 1073
1064 mWindowAndroid = getWindowAndroid(mContext); 1074 mWindowAndroid = getWindowAndroid(mContext);
1065 mContentViewCore = new ContentViewCore(mContext, PRODUCT_VERSION); 1075 mContentViewCore = new ContentViewCore(mContext, PRODUCT_VERSION);
1066 mViewAndroidDelegate = new AwViewAndroidDelegate( 1076 mViewAndroidDelegate = new AwViewAndroidDelegate(
1067 mContainerView, mContentsClient, mContentViewCore.getRenderCoord inates()); 1077 mContainerView, mContentsClient, mContentViewCore.getRenderCoord inates());
1068 initializeContentViewCore(mContentViewCore, mContext, mViewAndroidDelega te, 1078 initializeContentViewCore(mContentViewCore, mContext, mViewAndroidDelega te,
1069 mInternalAccessAdapter, webContents, new AwGestureStateListener( ), 1079 mInternalAccessAdapter, webContents, new AwGestureStateListener( ),
1070 mWindowAndroid.getWindowAndroid()); 1080 mWindowAndroid.getWindowAndroid());
1071 nativeSetJavaPeers(mNativeAwContents, this, mWebContentsDelegate, mConte ntsClientBridge, 1081 nativeSetJavaPeers(mNativeAwContents, this, mWebContentsDelegate, mConte ntsClientBridge,
1072 mIoThreadClient, mInterceptNavigationDelegate); 1082 mIoThreadClient, mInterceptNavigationDelegate, mAutofillProvider );
1073 mWebContents = mContentViewCore.getWebContents(); 1083 mWebContents = mContentViewCore.getWebContents();
1074 mNavigationController = mWebContents.getNavigationController(); 1084 mNavigationController = mWebContents.getNavigationController();
1075 installWebContentsObserver(); 1085 installWebContentsObserver();
1076 mSettings.setWebContents(webContents); 1086 mSettings.setWebContents(webContents);
1087 if (mAutofillProvider != null) mAutofillProvider.setWebContents(webConte nts);
1077 1088
1078 if (textClassifier != null) mContentViewCore.setTextClassifier(textClass ifier); 1089 if (textClassifier != null) mContentViewCore.setTextClassifier(textClass ifier);
1079 1090
1080 final float dipScale = mWindowAndroid.getWindowAndroid().getDisplay().ge tDipScale(); 1091 final float dipScale = mWindowAndroid.getWindowAndroid().getDisplay().ge tDipScale();
1081 mDisplayObserver.onDIPScaleChanged(dipScale); 1092 mDisplayObserver.onDIPScaleChanged(dipScale);
1082 1093
1083 updateContentViewCoreVisibility(); 1094 updateContentViewCoreVisibility();
1084 1095
1085 // The native side object has been bound to this java instance, so now i s the time to 1096 // The native side object has been bound to this java instance, so now i s the time to
1086 // bind all the native->java relationships. 1097 // bind all the native->java relationships.
(...skipping 1242 matching lines...) Expand 10 before | Expand all | Expand 10 after
2329 if (!mWebContentsObserver.didEverCommitNavigation()) { 2340 if (!mWebContentsObserver.didEverCommitNavigation()) {
2330 // TODO(sgurun) write a test case for this condition crbug/605251 2341 // TODO(sgurun) write a test case for this condition crbug/605251
2331 structure.setChildCount(0); 2342 structure.setChildCount(0);
2332 return; 2343 return;
2333 } 2344 }
2334 // for webview, the platform already calculates the scroll (as it is a v iew) in 2345 // for webview, the platform already calculates the scroll (as it is a v iew) in
2335 // ViewStructure tree. Do not offset for it in the snapshop x,y position calculations. 2346 // ViewStructure tree. Do not offset for it in the snapshop x,y position calculations.
2336 mContentViewCore.onProvideVirtualStructure(structure, true); 2347 mContentViewCore.onProvideVirtualStructure(structure, true);
2337 } 2348 }
2338 2349
2350 public void onProvideAutoFillVirtualStructure(ViewStructure structure, int f lags) {
2351 if (mAutofillProvider != null) {
2352 mAutofillProvider.onProvideAutoFillVirtualStructure(structure, flags );
2353 }
2354 }
2355
2356 public void autofill(final SparseArray<String> values) {
2357 if (mAutofillProvider != null) {
2358 mAutofillProvider.autofill(values);
2359 }
2360 }
2361
2339 public boolean isSelectActionModeAllowed(int actionModeItem) { 2362 public boolean isSelectActionModeAllowed(int actionModeItem) {
2340 return (mSettings.getDisabledActionModeMenuItems() & actionModeItem) != actionModeItem; 2363 return (mSettings.getDisabledActionModeMenuItems() & actionModeItem) != actionModeItem;
2341 } 2364 }
2342 2365
2343 //-------------------------------------------------------------------------- ------------------ 2366 //-------------------------------------------------------------------------- ------------------
2344 // View and ViewGroup method implementations 2367 // View and ViewGroup method implementations
2345 //-------------------------------------------------------------------------- ------------------ 2368 //-------------------------------------------------------------------------- ------------------
2346 /** 2369 /**
2347 * Calls android.view.View#startActivityForResult. A RuntimeException will 2370 * Calls android.view.View#startActivityForResult. A RuntimeException will
2348 * be thrown by Android framework if startActivityForResult is called with 2371 * be thrown by Android framework if startActivityForResult is called with
(...skipping 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after
3456 private static native void nativeSetAwDrawSWFunctionTable(long functionTable Pointer); 3479 private static native void nativeSetAwDrawSWFunctionTable(long functionTable Pointer);
3457 private static native void nativeSetAwDrawGLFunctionTable(long functionTable Pointer); 3480 private static native void nativeSetAwDrawGLFunctionTable(long functionTable Pointer);
3458 private static native int nativeGetNativeInstanceCount(); 3481 private static native int nativeGetNativeInstanceCount();
3459 private static native void nativeSetShouldDownloadFavicons(); 3482 private static native void nativeSetShouldDownloadFavicons();
3460 private static native void nativeUpdateDefaultLocale(String locale, String l ocaleList); 3483 private static native void nativeUpdateDefaultLocale(String locale, String l ocaleList);
3461 3484
3462 private native void nativeCallProceedOnInterstitialForTesting(long nativeAwC ontents); 3485 private native void nativeCallProceedOnInterstitialForTesting(long nativeAwC ontents);
3463 private native void nativeCallDontProceedOnInterstitialForTesting(long nativ eAwContents); 3486 private native void nativeCallDontProceedOnInterstitialForTesting(long nativ eAwContents);
3464 private native void nativeSetJavaPeers(long nativeAwContents, AwContents awC ontents, 3487 private native void nativeSetJavaPeers(long nativeAwContents, AwContents awC ontents,
3465 AwWebContentsDelegate webViewWebContentsDelegate, 3488 AwWebContentsDelegate webViewWebContentsDelegate,
3466 AwContentsClientBridge contentsClientBridge, 3489 AwContentsClientBridge contentsClientBridge, AwContentsIoThreadClien t ioThreadClient,
3467 AwContentsIoThreadClient ioThreadClient, 3490 InterceptNavigationDelegate navigationInterceptionDelegate,
3468 InterceptNavigationDelegate navigationInterceptionDelegate); 3491 AutofillProvider autofillProvider);
3469 private native WebContents nativeGetWebContents(long nativeAwContents); 3492 private native WebContents nativeGetWebContents(long nativeAwContents);
3470 private native void nativeSetAwGLFunctor(long nativeAwContents, long nativeA wGLFunctor); 3493 private native void nativeSetAwGLFunctor(long nativeAwContents, long nativeA wGLFunctor);
3471 3494
3472 private native void nativeDocumentHasImages(long nativeAwContents, Message m essage); 3495 private native void nativeDocumentHasImages(long nativeAwContents, Message m essage);
3473 private native void nativeGenerateMHTML( 3496 private native void nativeGenerateMHTML(
3474 long nativeAwContents, String path, ValueCallback<String> callback); 3497 long nativeAwContents, String path, ValueCallback<String> callback);
3475 3498
3476 private native void nativeAddVisitedLinks(long nativeAwContents, String[] vi sitedLinks); 3499 private native void nativeAddVisitedLinks(long nativeAwContents, String[] vi sitedLinks);
3477 private native void nativeZoomBy(long nativeAwContents, float delta); 3500 private native void nativeZoomBy(long nativeAwContents, float delta);
3478 private native void nativeOnComputeScroll( 3501 private native void nativeOnComputeScroll(
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
3536 private native void nativeTrimMemory(long nativeAwContents, int level, boole an visible); 3559 private native void nativeTrimMemory(long nativeAwContents, int level, boole an visible);
3537 3560
3538 private native void nativeCreatePdfExporter(long nativeAwContents, AwPdfExpo rter awPdfExporter); 3561 private native void nativeCreatePdfExporter(long nativeAwContents, AwPdfExpo rter awPdfExporter);
3539 3562
3540 private native void nativePreauthorizePermission(long nativeAwContents, Stri ng origin, 3563 private native void nativePreauthorizePermission(long nativeAwContents, Stri ng origin,
3541 long resources); 3564 long resources);
3542 3565
3543 private native void nativeGrantFileSchemeAccesstoChildProcess(long nativeAwC ontents); 3566 private native void nativeGrantFileSchemeAccesstoChildProcess(long nativeAwC ontents);
3544 private native void nativeResumeLoadingCreatedPopupWebContents(long nativeAw Contents); 3567 private native void nativeResumeLoadingCreatedPopupWebContents(long nativeAw Contents);
3545 } 3568 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698