| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 import org.chromium.content_public.browser.WebContents; | 71 import org.chromium.content_public.browser.WebContents; |
| 72 import org.chromium.content_public.browser.navigation_controller.LoadURLType; | 72 import org.chromium.content_public.browser.navigation_controller.LoadURLType; |
| 73 import org.chromium.content_public.browser.navigation_controller.UserAgentOverri
deOption; | 73 import org.chromium.content_public.browser.navigation_controller.UserAgentOverri
deOption; |
| 74 import org.chromium.content_public.common.Referrer; | 74 import org.chromium.content_public.common.Referrer; |
| 75 import org.chromium.net.NetError; | 75 import org.chromium.net.NetError; |
| 76 import org.chromium.net.NetworkChangeNotifier; | 76 import org.chromium.net.NetworkChangeNotifier; |
| 77 import org.chromium.ui.base.ActivityWindowAndroid; | 77 import org.chromium.ui.base.ActivityWindowAndroid; |
| 78 import org.chromium.ui.base.PageTransition; | 78 import org.chromium.ui.base.PageTransition; |
| 79 import org.chromium.ui.base.ViewAndroidDelegate; | 79 import org.chromium.ui.base.ViewAndroidDelegate; |
| 80 import org.chromium.ui.base.WindowAndroid; | 80 import org.chromium.ui.base.WindowAndroid; |
| 81 import org.chromium.ui.display.DisplayAndroid.DisplayAndroidObserver; |
| 81 | 82 |
| 82 import java.io.File; | 83 import java.io.File; |
| 83 import java.lang.annotation.Annotation; | 84 import java.lang.annotation.Annotation; |
| 84 import java.net.MalformedURLException; | 85 import java.net.MalformedURLException; |
| 85 import java.net.URL; | 86 import java.net.URL; |
| 86 import java.util.HashMap; | 87 import java.util.HashMap; |
| 87 import java.util.Locale; | 88 import java.util.Locale; |
| 88 import java.util.Map; | 89 import java.util.Map; |
| 89 import java.util.Map.Entry; | 90 import java.util.Map.Entry; |
| 90 import java.util.WeakHashMap; | 91 import java.util.WeakHashMap; |
| 91 import java.util.concurrent.Callable; | 92 import java.util.concurrent.Callable; |
| 92 | 93 |
| 93 /** | 94 /** |
| 94 * Exposes the native AwContents class, and together these classes wrap the Cont
entViewCore | 95 * Exposes the native AwContents class, and together these classes wrap the Cont
entViewCore |
| 95 * and Browser components that are required to implement Android WebView API. Th
is is the | 96 * and Browser components that are required to implement Android WebView API. Th
is is the |
| 96 * primary entry point for the WebViewProvider implementation; it holds a 1:1 ob
ject | 97 * primary entry point for the WebViewProvider implementation; it holds a 1:1 ob
ject |
| 97 * relationship with application WebView instances. | 98 * relationship with application WebView instances. |
| 98 * (We define this class independent of the hidden WebViewProvider interfaces, t
o allow | 99 * (We define this class independent of the hidden WebViewProvider interfaces, t
o allow |
| 99 * continuous build & test in the open source SDK-based tree). | 100 * continuous build & test in the open source SDK-based tree). |
| 100 */ | 101 */ |
| 101 @JNINamespace("android_webview") | 102 @JNINamespace("android_webview") |
| 102 public class AwContents implements SmartClipProvider, | 103 public class AwContents implements SmartClipProvider, PostMessageSender.PostMess
ageSenderDelegate { |
| 103 PostMessageSender.PostMessageSenderDelegate { | |
| 104 private static final String TAG = "AwContents"; | 104 private static final String TAG = "AwContents"; |
| 105 private static final boolean TRACE = false; | 105 private static final boolean TRACE = false; |
| 106 private static final int NO_WARN = 0; | 106 private static final int NO_WARN = 0; |
| 107 private static final int WARN = 1; | 107 private static final int WARN = 1; |
| 108 private static final String PRODUCT_VERSION = AwContentsStatics.getProductVe
rsion(); | 108 private static final String PRODUCT_VERSION = AwContentsStatics.getProductVe
rsion(); |
| 109 | 109 |
| 110 private static final String WEB_ARCHIVE_EXTENSION = ".mht"; | 110 private static final String WEB_ARCHIVE_EXTENSION = ".mht"; |
| 111 // The request code should be unique per WebView/AwContents object. | 111 // The request code should be unique per WebView/AwContents object. |
| 112 private static final int PROCESS_TEXT_REQUEST_CODE = 100; | 112 private static final int PROCESS_TEXT_REQUEST_CODE = 100; |
| 113 | 113 |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 private final AwWebContentsDelegateAdapter mWebContentsDelegate; | 280 private final AwWebContentsDelegateAdapter mWebContentsDelegate; |
| 281 private final AwContentsBackgroundThreadClient mBackgroundThreadClient; | 281 private final AwContentsBackgroundThreadClient mBackgroundThreadClient; |
| 282 private final AwContentsIoThreadClient mIoThreadClient; | 282 private final AwContentsIoThreadClient mIoThreadClient; |
| 283 private final InterceptNavigationDelegateImpl mInterceptNavigationDelegate; | 283 private final InterceptNavigationDelegateImpl mInterceptNavigationDelegate; |
| 284 private InternalAccessDelegate mInternalAccessAdapter; | 284 private InternalAccessDelegate mInternalAccessAdapter; |
| 285 private final NativeDrawGLFunctorFactory mNativeDrawGLFunctorFactory; | 285 private final NativeDrawGLFunctorFactory mNativeDrawGLFunctorFactory; |
| 286 private final AwLayoutSizer mLayoutSizer; | 286 private final AwLayoutSizer mLayoutSizer; |
| 287 private final AwZoomControls mZoomControls; | 287 private final AwZoomControls mZoomControls; |
| 288 private final AwScrollOffsetManager mScrollOffsetManager; | 288 private final AwScrollOffsetManager mScrollOffsetManager; |
| 289 private OverScrollGlow mOverScrollGlow; | 289 private OverScrollGlow mOverScrollGlow; |
| 290 private final DisplayAndroidObserver mDisplayObserver; |
| 290 // This can be accessed on any thread after construction. See AwContentsIoTh
readClient. | 291 // This can be accessed on any thread after construction. See AwContentsIoTh
readClient. |
| 291 private final AwSettings mSettings; | 292 private final AwSettings mSettings; |
| 292 private final ScrollAccessibilityHelper mScrollAccessibilityHelper; | 293 private final ScrollAccessibilityHelper mScrollAccessibilityHelper; |
| 293 | 294 |
| 294 private final ObserverList<PopupTouchHandleDrawable> mTouchHandleDrawables = | 295 private final ObserverList<PopupTouchHandleDrawable> mTouchHandleDrawables = |
| 295 new ObserverList<>(); | 296 new ObserverList<>(); |
| 296 | 297 |
| 297 private boolean mIsPaused; | 298 private boolean mIsPaused; |
| 298 private boolean mIsViewVisible; | 299 private boolean mIsViewVisible; |
| 299 private boolean mIsWindowVisible; | 300 private boolean mIsWindowVisible; |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 public void onLowMemory() {} | 705 public void onLowMemory() {} |
| 705 | 706 |
| 706 @Override | 707 @Override |
| 707 public void onConfigurationChanged(Configuration configuration) { | 708 public void onConfigurationChanged(Configuration configuration) { |
| 708 setLocale(LocaleUtils.getLocale(configuration.locale)); | 709 setLocale(LocaleUtils.getLocale(configuration.locale)); |
| 709 mSettings.updateAcceptLanguages(); | 710 mSettings.updateAcceptLanguages(); |
| 710 } | 711 } |
| 711 }; | 712 }; |
| 712 | 713 |
| 713 //--------------------------------------------------------------------------
------------------ | 714 //--------------------------------------------------------------------------
------------------ |
| 715 private class AwDisplayAndroidObserver implements DisplayAndroidObserver { |
| 716 @Override |
| 717 public void onRotationChanged(int rotation) {} |
| 718 |
| 719 @Override |
| 720 public void onDIPScaleChanged(float dipScale) { |
| 721 if (TRACE) Log.i(TAG, "%s onDIPScaleChanged dipScale=%f", this, dipS
cale); |
| 722 |
| 723 nativeSetDipScale(mNativeAwContents, dipScale); |
| 724 mLayoutSizer.setDIPScale(dipScale); |
| 725 mSettings.setDIPScale(dipScale); |
| 726 } |
| 727 }; |
| 728 |
| 729 //--------------------------------------------------------------------------
------------------ |
| 714 /** | 730 /** |
| 715 * @param browserContext the browsing context to associate this view content
s with. | 731 * @param browserContext the browsing context to associate this view content
s with. |
| 716 * @param containerView the view-hierarchy item this object will be bound to
. | 732 * @param containerView the view-hierarchy item this object will be bound to
. |
| 717 * @param context the context to use, usually containerView.getContext(). | 733 * @param context the context to use, usually containerView.getContext(). |
| 718 * @param internalAccessAdapter to access private methods on containerView. | 734 * @param internalAccessAdapter to access private methods on containerView. |
| 719 * @param nativeGLDelegate to access the GL functor provided by the WebView. | 735 * @param nativeGLDelegate to access the GL functor provided by the WebView. |
| 720 * @param contentsClient will receive API callbacks from this WebView Conten
ts. | 736 * @param contentsClient will receive API callbacks from this WebView Conten
ts. |
| 721 * @param awSettings AwSettings instance used to configure the AwContents. | 737 * @param awSettings AwSettings instance used to configure the AwContents. |
| 722 * | 738 * |
| 723 * This constructor uses the default view sizing policy. | 739 * This constructor uses the default view sizing policy. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 mSettings = settings; | 791 mSettings = settings; |
| 776 mLayoutSizer.setDelegate(new AwLayoutSizerDelegate()); | 792 mLayoutSizer.setDelegate(new AwLayoutSizerDelegate()); |
| 777 mWebContentsDelegate = new AwWebContentsDelegateAdapter( | 793 mWebContentsDelegate = new AwWebContentsDelegateAdapter( |
| 778 this, contentsClient, settings, mContext, mContainerView); | 794 this, contentsClient, settings, mContext, mContainerView); |
| 779 mContentsClientBridge = new AwContentsClientBridge(mContext, contentsCli
ent, | 795 mContentsClientBridge = new AwContentsClientBridge(mContext, contentsCli
ent, |
| 780 AwContentsStatics.getClientCertLookupTable()); | 796 AwContentsStatics.getClientCertLookupTable()); |
| 781 mZoomControls = new AwZoomControls(this); | 797 mZoomControls = new AwZoomControls(this); |
| 782 mBackgroundThreadClient = new BackgroundThreadClientImpl(); | 798 mBackgroundThreadClient = new BackgroundThreadClientImpl(); |
| 783 mIoThreadClient = new IoThreadClientImpl(); | 799 mIoThreadClient = new IoThreadClientImpl(); |
| 784 mInterceptNavigationDelegate = new InterceptNavigationDelegateImpl(); | 800 mInterceptNavigationDelegate = new InterceptNavigationDelegateImpl(); |
| 801 mDisplayObserver = new AwDisplayAndroidObserver(); |
| 785 mUpdateVisibilityRunnable = new Runnable() { | 802 mUpdateVisibilityRunnable = new Runnable() { |
| 786 @Override | 803 @Override |
| 787 public void run() { | 804 public void run() { |
| 788 updateContentViewCoreVisibility(); | 805 updateContentViewCoreVisibility(); |
| 789 } | 806 } |
| 790 }; | 807 }; |
| 791 | 808 |
| 792 AwSettings.ZoomSupportChangeListener zoomListener = | 809 AwSettings.ZoomSupportChangeListener zoomListener = |
| 793 new AwSettings.ZoomSupportChangeListener() { | 810 new AwSettings.ZoomSupportChangeListener() { |
| 794 @Override | 811 @Override |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1058 initializeContentViewCore(mContentViewCore, mContext, mViewAndroidDelega
te, | 1075 initializeContentViewCore(mContentViewCore, mContext, mViewAndroidDelega
te, |
| 1059 mInternalAccessAdapter, webContents, new AwGestureStateListener(
), | 1076 mInternalAccessAdapter, webContents, new AwGestureStateListener(
), |
| 1060 mContentViewClient, mZoomControls, mWindowAndroid.getWindowAndro
id()); | 1077 mContentViewClient, mZoomControls, mWindowAndroid.getWindowAndro
id()); |
| 1061 nativeSetJavaPeers(mNativeAwContents, this, mWebContentsDelegate, mConte
ntsClientBridge, | 1078 nativeSetJavaPeers(mNativeAwContents, this, mWebContentsDelegate, mConte
ntsClientBridge, |
| 1062 mIoThreadClient, mInterceptNavigationDelegate); | 1079 mIoThreadClient, mInterceptNavigationDelegate); |
| 1063 mWebContents = mContentViewCore.getWebContents(); | 1080 mWebContents = mContentViewCore.getWebContents(); |
| 1064 mNavigationController = mWebContents.getNavigationController(); | 1081 mNavigationController = mWebContents.getNavigationController(); |
| 1065 installWebContentsObserver(); | 1082 installWebContentsObserver(); |
| 1066 mSettings.setWebContents(webContents); | 1083 mSettings.setWebContents(webContents); |
| 1067 | 1084 |
| 1068 float dipScale = mContentViewCore.getDeviceScaleFactor(); | 1085 final float dipScale = mWindowAndroid.getWindowAndroid().getDisplay().ge
tDIPScale(); |
| 1069 nativeSetDipScale(mNativeAwContents, dipScale); | 1086 mDisplayObserver.onDIPScaleChanged(dipScale); |
| 1070 mLayoutSizer.setDIPScale(dipScale); | |
| 1071 mSettings.setDIPScale(dipScale); | |
| 1072 | 1087 |
| 1073 updateContentViewCoreVisibility(); | 1088 updateContentViewCoreVisibility(); |
| 1074 | 1089 |
| 1075 // The native side object has been bound to this java instance, so now i
s the time to | 1090 // The native side object has been bound to this java instance, so now i
s the time to |
| 1076 // bind all the native->java relationships. | 1091 // bind all the native->java relationships. |
| 1077 mCleanupReference = new CleanupReference( | 1092 mCleanupReference = new CleanupReference( |
| 1078 this, new AwContentsDestroyRunnable(mNativeAwContents, mWindowAn
droid)); | 1093 this, new AwContentsDestroyRunnable(mNativeAwContents, mWindowAn
droid)); |
| 1079 } | 1094 } |
| 1080 | 1095 |
| 1081 private void installWebContentsObserver() { | 1096 private void installWebContentsObserver() { |
| (...skipping 1295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2377 mAwViewMethods.onConfigurationChanged(newConfig); | 2392 mAwViewMethods.onConfigurationChanged(newConfig); |
| 2378 } | 2393 } |
| 2379 | 2394 |
| 2380 /** | 2395 /** |
| 2381 * @see android.view.View#onAttachedToWindow() | 2396 * @see android.view.View#onAttachedToWindow() |
| 2382 */ | 2397 */ |
| 2383 public void onAttachedToWindow() { | 2398 public void onAttachedToWindow() { |
| 2384 if (TRACE) Log.i(TAG, "%s onAttachedToWindow", this); | 2399 if (TRACE) Log.i(TAG, "%s onAttachedToWindow", this); |
| 2385 mTemporarilyDetached = false; | 2400 mTemporarilyDetached = false; |
| 2386 mAwViewMethods.onAttachedToWindow(); | 2401 mAwViewMethods.onAttachedToWindow(); |
| 2402 mWindowAndroid.getWindowAndroid().getDisplay().addObserver(mDisplayObser
ver); |
| 2387 } | 2403 } |
| 2388 | 2404 |
| 2389 /** | 2405 /** |
| 2390 * @see android.view.View#onDetachedFromWindow() | 2406 * @see android.view.View#onDetachedFromWindow() |
| 2391 */ | 2407 */ |
| 2392 @SuppressLint("MissingSuperCall") | 2408 @SuppressLint("MissingSuperCall") |
| 2393 public void onDetachedFromWindow() { | 2409 public void onDetachedFromWindow() { |
| 2394 if (TRACE) Log.i(TAG, "%s onDetachedFromWindow", this); | 2410 if (TRACE) Log.i(TAG, "%s onDetachedFromWindow", this); |
| 2411 mWindowAndroid.getWindowAndroid().getDisplay().removeObserver(mDisplayOb
server); |
| 2395 mAwViewMethods.onDetachedFromWindow(); | 2412 mAwViewMethods.onDetachedFromWindow(); |
| 2396 } | 2413 } |
| 2397 | 2414 |
| 2398 /** | 2415 /** |
| 2399 * @see android.view.View#onWindowFocusChanged() | 2416 * @see android.view.View#onWindowFocusChanged() |
| 2400 */ | 2417 */ |
| 2401 public void onWindowFocusChanged(boolean hasWindowFocus) { | 2418 public void onWindowFocusChanged(boolean hasWindowFocus) { |
| 2402 mAwViewMethods.onWindowFocusChanged(hasWindowFocus); | 2419 mAwViewMethods.onWindowFocusChanged(hasWindowFocus); |
| 2403 } | 2420 } |
| 2404 | 2421 |
| (...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3375 | 3392 |
| 3376 private native void nativePostMessageToFrame(long nativeAwContents, String f
rameId, | 3393 private native void nativePostMessageToFrame(long nativeAwContents, String f
rameId, |
| 3377 String message, String targetOrigin, int[] msgPorts); | 3394 String message, String targetOrigin, int[] msgPorts); |
| 3378 | 3395 |
| 3379 private native void nativeCreateMessageChannel( | 3396 private native void nativeCreateMessageChannel( |
| 3380 long nativeAwContents, AppWebMessagePort[] ports); | 3397 long nativeAwContents, AppWebMessagePort[] ports); |
| 3381 | 3398 |
| 3382 private native void nativeGrantFileSchemeAccesstoChildProcess(long nativeAwC
ontents); | 3399 private native void nativeGrantFileSchemeAccesstoChildProcess(long nativeAwC
ontents); |
| 3383 private native void nativeResumeLoadingCreatedPopupWebContents(long nativeAw
Contents); | 3400 private native void nativeResumeLoadingCreatedPopupWebContents(long nativeAw
Contents); |
| 3384 } | 3401 } |
| OLD | NEW |