OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 1253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2340 if (!mWebContentsObserver.didEverCommitNavigation()) { | 2351 if (!mWebContentsObserver.didEverCommitNavigation()) { |
2341 // TODO(sgurun) write a test case for this condition crbug/605251 | 2352 // TODO(sgurun) write a test case for this condition crbug/605251 |
2342 structure.setChildCount(0); | 2353 structure.setChildCount(0); |
2343 return; | 2354 return; |
2344 } | 2355 } |
2345 // for webview, the platform already calculates the scroll (as it is a v
iew) in | 2356 // for webview, the platform already calculates the scroll (as it is a v
iew) in |
2346 // ViewStructure tree. Do not offset for it in the snapshop x,y position
calculations. | 2357 // ViewStructure tree. Do not offset for it in the snapshop x,y position
calculations. |
2347 mContentViewCore.onProvideVirtualStructure(structure, true); | 2358 mContentViewCore.onProvideVirtualStructure(structure, true); |
2348 } | 2359 } |
2349 | 2360 |
| 2361 public void onProvideAutoFillVirtualStructure(ViewStructure structure, int f
lags) { |
| 2362 if (mAutofillProvider != null) { |
| 2363 mAutofillProvider.onProvideAutoFillVirtualStructure(structure, flags
); |
| 2364 } |
| 2365 } |
| 2366 |
| 2367 public void autofill(final SparseArray<String> values) { |
| 2368 if (mAutofillProvider != null) { |
| 2369 mAutofillProvider.autofill(values); |
| 2370 } |
| 2371 } |
| 2372 |
2350 public boolean isSelectActionModeAllowed(int actionModeItem) { | 2373 public boolean isSelectActionModeAllowed(int actionModeItem) { |
2351 return (mSettings.getDisabledActionModeMenuItems() & actionModeItem) !=
actionModeItem; | 2374 return (mSettings.getDisabledActionModeMenuItems() & actionModeItem) !=
actionModeItem; |
2352 } | 2375 } |
2353 | 2376 |
2354 //--------------------------------------------------------------------------
------------------ | 2377 //--------------------------------------------------------------------------
------------------ |
2355 // View and ViewGroup method implementations | 2378 // View and ViewGroup method implementations |
2356 //--------------------------------------------------------------------------
------------------ | 2379 //--------------------------------------------------------------------------
------------------ |
2357 /** | 2380 /** |
2358 * Calls android.view.View#startActivityForResult. A RuntimeException will | 2381 * Calls android.view.View#startActivityForResult. A RuntimeException will |
2359 * be thrown by Android framework if startActivityForResult is called with | 2382 * be thrown by Android framework if startActivityForResult is called with |
(...skipping 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3459 private static native void nativeSetAwDrawSWFunctionTable(long functionTable
Pointer); | 3482 private static native void nativeSetAwDrawSWFunctionTable(long functionTable
Pointer); |
3460 private static native void nativeSetAwDrawGLFunctionTable(long functionTable
Pointer); | 3483 private static native void nativeSetAwDrawGLFunctionTable(long functionTable
Pointer); |
3461 private static native int nativeGetNativeInstanceCount(); | 3484 private static native int nativeGetNativeInstanceCount(); |
3462 private static native void nativeSetShouldDownloadFavicons(); | 3485 private static native void nativeSetShouldDownloadFavicons(); |
3463 private static native void nativeUpdateDefaultLocale(String locale, String l
ocaleList); | 3486 private static native void nativeUpdateDefaultLocale(String locale, String l
ocaleList); |
3464 | 3487 |
3465 private native void nativeCallProceedOnInterstitialForTesting(long nativeAwC
ontents); | 3488 private native void nativeCallProceedOnInterstitialForTesting(long nativeAwC
ontents); |
3466 private native void nativeCallDontProceedOnInterstitialForTesting(long nativ
eAwContents); | 3489 private native void nativeCallDontProceedOnInterstitialForTesting(long nativ
eAwContents); |
3467 private native void nativeSetJavaPeers(long nativeAwContents, AwContents awC
ontents, | 3490 private native void nativeSetJavaPeers(long nativeAwContents, AwContents awC
ontents, |
3468 AwWebContentsDelegate webViewWebContentsDelegate, | 3491 AwWebContentsDelegate webViewWebContentsDelegate, |
3469 AwContentsClientBridge contentsClientBridge, | 3492 AwContentsClientBridge contentsClientBridge, AwContentsIoThreadClien
t ioThreadClient, |
3470 AwContentsIoThreadClient ioThreadClient, | 3493 InterceptNavigationDelegate navigationInterceptionDelegate, |
3471 InterceptNavigationDelegate navigationInterceptionDelegate); | 3494 AutofillProvider autofillProvider); |
3472 private native WebContents nativeGetWebContents(long nativeAwContents); | 3495 private native WebContents nativeGetWebContents(long nativeAwContents); |
3473 private native void nativeSetAwGLFunctor(long nativeAwContents, long nativeA
wGLFunctor); | 3496 private native void nativeSetAwGLFunctor(long nativeAwContents, long nativeA
wGLFunctor); |
3474 | 3497 |
3475 private native void nativeDocumentHasImages(long nativeAwContents, Message m
essage); | 3498 private native void nativeDocumentHasImages(long nativeAwContents, Message m
essage); |
3476 private native void nativeGenerateMHTML( | 3499 private native void nativeGenerateMHTML( |
3477 long nativeAwContents, String path, ValueCallback<String> callback); | 3500 long nativeAwContents, String path, ValueCallback<String> callback); |
3478 | 3501 |
3479 private native void nativeAddVisitedLinks(long nativeAwContents, String[] vi
sitedLinks); | 3502 private native void nativeAddVisitedLinks(long nativeAwContents, String[] vi
sitedLinks); |
3480 private native void nativeZoomBy(long nativeAwContents, float delta); | 3503 private native void nativeZoomBy(long nativeAwContents, float delta); |
3481 private native void nativeOnComputeScroll( | 3504 private native void nativeOnComputeScroll( |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3542 | 3565 |
3543 private native void nativePreauthorizePermission(long nativeAwContents, Stri
ng origin, | 3566 private native void nativePreauthorizePermission(long nativeAwContents, Stri
ng origin, |
3544 long resources); | 3567 long resources); |
3545 | 3568 |
3546 private native void nativePostMessageToFrame(long nativeAwContents, String f
rameId, | 3569 private native void nativePostMessageToFrame(long nativeAwContents, String f
rameId, |
3547 String message, String targetOrigin, MessagePort[] ports); | 3570 String message, String targetOrigin, MessagePort[] ports); |
3548 | 3571 |
3549 private native void nativeGrantFileSchemeAccesstoChildProcess(long nativeAwC
ontents); | 3572 private native void nativeGrantFileSchemeAccesstoChildProcess(long nativeAwC
ontents); |
3550 private native void nativeResumeLoadingCreatedPopupWebContents(long nativeAw
Contents); | 3573 private native void nativeResumeLoadingCreatedPopupWebContents(long nativeAw
Contents); |
3551 } | 3574 } |
OLD | NEW |