| 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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 public abstract static class VisualStateCallback { | 249 public abstract static class VisualStateCallback { |
| 250 /** | 250 /** |
| 251 * @param requestId the id passed to {@link AwContents#insertVisualState
Callback} | 251 * @param requestId the id passed to {@link AwContents#insertVisualState
Callback} |
| 252 * which can be used to match requests with the corresponding callbacks. | 252 * which can be used to match requests with the corresponding callbacks. |
| 253 */ | 253 */ |
| 254 public abstract void onComplete(long requestId); | 254 public abstract void onComplete(long requestId); |
| 255 } | 255 } |
| 256 | 256 |
| 257 private long mNativeAwContents; | 257 private long mNativeAwContents; |
| 258 private final AwBrowserContext mBrowserContext; | 258 private final AwBrowserContext mBrowserContext; |
| 259 // mContainerView and mCurrentFunctor form a pair that needs to stay in sync
. |
| 259 private ViewGroup mContainerView; | 260 private ViewGroup mContainerView; |
| 260 private AwGLFunctor mAwGLFunctor; | 261 private AwGLFunctor mCurrentFunctor; |
| 262 private AwGLFunctor mInitialFunctor; |
| 263 private AwGLFunctor mFullScreenFunctor; // Only non-null when in fullscreen
mode. |
| 261 private final Context mContext; | 264 private final Context mContext; |
| 262 private final int mAppTargetSdkVersion; | 265 private final int mAppTargetSdkVersion; |
| 263 private ContentViewCore mContentViewCore; | 266 private ContentViewCore mContentViewCore; |
| 264 private WindowAndroidWrapper mWindowAndroid; | 267 private WindowAndroidWrapper mWindowAndroid; |
| 265 private WebContents mWebContents; | 268 private WebContents mWebContents; |
| 266 private NavigationController mNavigationController; | 269 private NavigationController mNavigationController; |
| 267 private final AwContentsClient mContentsClient; | 270 private final AwContentsClient mContentsClient; |
| 268 private final AwContentViewClient mContentViewClient; | 271 private final AwContentViewClient mContentViewClient; |
| 269 private AwWebContentsObserver mWebContentsObserver; | 272 private AwWebContentsObserver mWebContentsObserver; |
| 270 private final AwContentsClientBridge mContentsClientBridge; | 273 private final AwContentsClientBridge mContentsClientBridge; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 private boolean mTemporarilyDetached; | 347 private boolean mTemporarilyDetached; |
| 345 | 348 |
| 346 private Handler mHandler; | 349 private Handler mHandler; |
| 347 | 350 |
| 348 // True when this AwContents has been destroyed. | 351 // True when this AwContents has been destroyed. |
| 349 // Do not use directly, call isDestroyed() instead. | 352 // Do not use directly, call isDestroyed() instead. |
| 350 private boolean mIsDestroyed = false; | 353 private boolean mIsDestroyed = false; |
| 351 | 354 |
| 352 private static String sCurrentLocale = ""; | 355 private static String sCurrentLocale = ""; |
| 353 | 356 |
| 354 private static final class DestroyRunnable implements Runnable { | 357 private static final class AwContentsDestroyRunnable implements Runnable { |
| 355 private final long mNativeAwContents; | 358 private final long mNativeAwContents; |
| 356 // Hold onto a reference to the window (via its wrapper), so that it is
not destroyed | 359 // Hold onto a reference to the window (via its wrapper), so that it is
not destroyed |
| 357 // until we are done here. | 360 // until we are done here. |
| 358 private final WindowAndroidWrapper mWindowAndroid; | 361 private final WindowAndroidWrapper mWindowAndroid; |
| 359 private final Object mAwGLFunctorNativeLifetimeObject; | |
| 360 | 362 |
| 361 private DestroyRunnable(long nativeAwContents, WindowAndroidWrapper wind
owAndroid, | 363 private AwContentsDestroyRunnable( |
| 362 AwGLFunctor awGLFunctor) { | 364 long nativeAwContents, WindowAndroidWrapper windowAndroid) { |
| 363 mNativeAwContents = nativeAwContents; | 365 mNativeAwContents = nativeAwContents; |
| 364 mWindowAndroid = windowAndroid; | 366 mWindowAndroid = windowAndroid; |
| 365 mAwGLFunctorNativeLifetimeObject = awGLFunctor.getNativeLifetimeObje
ct(); | |
| 366 } | 367 } |
| 368 |
| 367 @Override | 369 @Override |
| 368 public void run() { | 370 public void run() { |
| 369 nativeDestroy(mNativeAwContents); | 371 nativeDestroy(mNativeAwContents); |
| 370 } | 372 } |
| 371 } | 373 } |
| 372 | 374 |
| 373 /** | 375 /** |
| 374 * A class that stores the state needed to enter and exit fullscreen. | 376 * A class that stores the state needed to enter and exit fullscreen. |
| 375 */ | 377 */ |
| 376 private static class FullScreenTransitionsState { | 378 private static class FullScreenTransitionsState { |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 private class AwComponentCallbacks implements ComponentCallbacks2 { | 674 private class AwComponentCallbacks implements ComponentCallbacks2 { |
| 673 @Override | 675 @Override |
| 674 public void onTrimMemory(final int level) { | 676 public void onTrimMemory(final int level) { |
| 675 if (isDestroyed(NO_WARN)) return; | 677 if (isDestroyed(NO_WARN)) return; |
| 676 boolean visibleRectEmpty = getGlobalVisibleRect().isEmpty(); | 678 boolean visibleRectEmpty = getGlobalVisibleRect().isEmpty(); |
| 677 final boolean visible = mIsViewVisible && mIsWindowVisible && !visib
leRectEmpty; | 679 final boolean visible = mIsViewVisible && mIsWindowVisible && !visib
leRectEmpty; |
| 678 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 680 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 679 @Override | 681 @Override |
| 680 public void run() { | 682 public void run() { |
| 681 if (level >= TRIM_MEMORY_MODERATE) { | 683 if (level >= TRIM_MEMORY_MODERATE) { |
| 682 mAwGLFunctor.deleteHardwareRenderer(); | 684 mInitialFunctor.deleteHardwareRenderer(); |
| 685 if (mFullScreenFunctor != null) { |
| 686 mFullScreenFunctor.deleteHardwareRenderer(); |
| 687 } |
| 683 } | 688 } |
| 684 nativeTrimMemory(mNativeAwContents, level, visible); | 689 nativeTrimMemory(mNativeAwContents, level, visible); |
| 685 } | 690 } |
| 686 }); | 691 }); |
| 687 } | 692 } |
| 688 | 693 |
| 689 @Override | 694 @Override |
| 690 public void onLowMemory() {} | 695 public void onLowMemory() {} |
| 691 | 696 |
| 692 @Override | 697 @Override |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 // container view. If this is ever not the case we should remove this, a
s it removes | 741 // container view. If this is ever not the case we should remove this, a
s it removes |
| 737 // Android's gatherTransparentRegion optimization for the view. | 742 // Android's gatherTransparentRegion optimization for the view. |
| 738 mContainerView = containerView; | 743 mContainerView = containerView; |
| 739 mContainerView.setWillNotDraw(false); | 744 mContainerView.setWillNotDraw(false); |
| 740 | 745 |
| 741 mHandler = new Handler(); | 746 mHandler = new Handler(); |
| 742 mContext = context; | 747 mContext = context; |
| 743 mAppTargetSdkVersion = mContext.getApplicationInfo().targetSdkVersion; | 748 mAppTargetSdkVersion = mContext.getApplicationInfo().targetSdkVersion; |
| 744 mInternalAccessAdapter = internalAccessAdapter; | 749 mInternalAccessAdapter = internalAccessAdapter; |
| 745 mNativeDrawGLFunctorFactory = nativeDrawGLFunctorFactory; | 750 mNativeDrawGLFunctorFactory = nativeDrawGLFunctorFactory; |
| 751 mInitialFunctor = new AwGLFunctor(mNativeDrawGLFunctorFactory, mContaine
rView); |
| 752 mCurrentFunctor = mInitialFunctor; |
| 746 mContentsClient = contentsClient; | 753 mContentsClient = contentsClient; |
| 747 mAwViewMethods = new AwViewMethodsImpl(); | 754 mAwViewMethods = new AwViewMethodsImpl(); |
| 748 mFullScreenTransitionsState = new FullScreenTransitionsState( | 755 mFullScreenTransitionsState = new FullScreenTransitionsState( |
| 749 mContainerView, mInternalAccessAdapter, mAwViewMethods); | 756 mContainerView, mInternalAccessAdapter, mAwViewMethods); |
| 750 mContentViewClient = new AwContentViewClient(contentsClient, settings, t
his, mContext); | 757 mContentViewClient = new AwContentViewClient(contentsClient, settings, t
his, mContext); |
| 751 mLayoutSizer = dependencyFactory.createLayoutSizer(); | 758 mLayoutSizer = dependencyFactory.createLayoutSizer(); |
| 752 mSettings = settings; | 759 mSettings = settings; |
| 753 mDIPScale = DeviceDisplayInfo.create(mContext).getDIPScale(); | 760 mDIPScale = DeviceDisplayInfo.create(mContext).getDIPScale(); |
| 754 mLayoutSizer.setDelegate(new AwLayoutSizerDelegate()); | 761 mLayoutSizer.setDelegate(new AwLayoutSizerDelegate()); |
| 755 mLayoutSizer.setDIPScale(mDIPScale); | 762 mLayoutSizer.setDIPScale(mDIPScale); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 | 838 |
| 832 // In fullscreen mode FullScreenView owns the AwViewMethodsImpl and AwCo
ntents | 839 // In fullscreen mode FullScreenView owns the AwViewMethodsImpl and AwCo
ntents |
| 833 // a NullAwViewMethods. | 840 // a NullAwViewMethods. |
| 834 FullScreenView fullScreenView = new FullScreenView(mContext, mAwViewMeth
ods, this); | 841 FullScreenView fullScreenView = new FullScreenView(mContext, mAwViewMeth
ods, this); |
| 835 fullScreenView.setFocusable(true); | 842 fullScreenView.setFocusable(true); |
| 836 fullScreenView.setFocusableInTouchMode(true); | 843 fullScreenView.setFocusableInTouchMode(true); |
| 837 boolean wasInitialContainerViewFocused = mContainerView.isFocused(); | 844 boolean wasInitialContainerViewFocused = mContainerView.isFocused(); |
| 838 if (wasInitialContainerViewFocused) { | 845 if (wasInitialContainerViewFocused) { |
| 839 fullScreenView.requestFocus(); | 846 fullScreenView.requestFocus(); |
| 840 } | 847 } |
| 848 mFullScreenFunctor = new AwGLFunctor(mNativeDrawGLFunctorFactory, fullSc
reenView); |
| 841 mFullScreenTransitionsState.enterFullScreen(fullScreenView, wasInitialCo
ntainerViewFocused); | 849 mFullScreenTransitionsState.enterFullScreen(fullScreenView, wasInitialCo
ntainerViewFocused); |
| 842 mAwViewMethods = new NullAwViewMethods(this, mInternalAccessAdapter, mCo
ntainerView); | 850 mAwViewMethods = new NullAwViewMethods(this, mInternalAccessAdapter, mCo
ntainerView); |
| 843 | 851 |
| 844 // Associate this AwContents with the FullScreenView. | 852 // Associate this AwContents with the FullScreenView. |
| 845 setInternalAccessAdapter(fullScreenView.getInternalAccessAdapter()); | 853 setInternalAccessAdapter(fullScreenView.getInternalAccessAdapter()); |
| 846 setContainerView(fullScreenView); | 854 setContainerView(fullScreenView, mFullScreenFunctor); |
| 847 | 855 |
| 848 return fullScreenView; | 856 return fullScreenView; |
| 849 } | 857 } |
| 850 | 858 |
| 851 /** | 859 /** |
| 852 * Called when the app has requested to exit fullscreen. | 860 * Called when the app has requested to exit fullscreen. |
| 853 */ | 861 */ |
| 854 void requestExitFullscreen() { | 862 void requestExitFullscreen() { |
| 855 if (!isDestroyed(NO_WARN)) mContentViewCore.getWebContents().exitFullscr
een(); | 863 if (!isDestroyed(NO_WARN)) mContentViewCore.getWebContents().exitFullscr
een(); |
| 856 } | 864 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 877 // Swap the view delegates. In embedded mode the FullScreenView owns a | 885 // Swap the view delegates. In embedded mode the FullScreenView owns a |
| 878 // NullAwViewMethods and AwContents the AwViewMethodsImpl. | 886 // NullAwViewMethods and AwContents the AwViewMethodsImpl. |
| 879 FullScreenView fullscreenView = mFullScreenTransitionsState.getFullScree
nView(); | 887 FullScreenView fullscreenView = mFullScreenTransitionsState.getFullScree
nView(); |
| 880 fullscreenView.setAwViewMethods(new NullAwViewMethods( | 888 fullscreenView.setAwViewMethods(new NullAwViewMethods( |
| 881 this, fullscreenView.getInternalAccessAdapter(), fullscreenView)
); | 889 this, fullscreenView.getInternalAccessAdapter(), fullscreenView)
); |
| 882 mAwViewMethods = awViewMethodsImpl; | 890 mAwViewMethods = awViewMethodsImpl; |
| 883 ViewGroup initialContainerView = mFullScreenTransitionsState.getInitialC
ontainerView(); | 891 ViewGroup initialContainerView = mFullScreenTransitionsState.getInitialC
ontainerView(); |
| 884 | 892 |
| 885 // Re-associate this AwContents with the WebView. | 893 // Re-associate this AwContents with the WebView. |
| 886 setInternalAccessAdapter(mFullScreenTransitionsState.getInitialInternalA
ccessDelegate()); | 894 setInternalAccessAdapter(mFullScreenTransitionsState.getInitialInternalA
ccessDelegate()); |
| 887 setContainerView(initialContainerView); | 895 setContainerView(initialContainerView, mInitialFunctor); |
| 888 | 896 |
| 889 // Return focus to the WebView. | 897 // Return focus to the WebView. |
| 890 if (mFullScreenTransitionsState.wasInitialContainerViewFocused()) { | 898 if (mFullScreenTransitionsState.wasInitialContainerViewFocused()) { |
| 891 mContainerView.requestFocus(); | 899 mContainerView.requestFocus(); |
| 892 } | 900 } |
| 893 mFullScreenTransitionsState.exitFullScreen(); | 901 mFullScreenTransitionsState.exitFullScreen(); |
| 902 // Drop AwContents last reference to this functor. AwGLFunctor is respon
sible for cleanup. |
| 903 mFullScreenFunctor = null; |
| 894 } | 904 } |
| 895 | 905 |
| 896 private void setInternalAccessAdapter(InternalAccessDelegate internalAccessA
dapter) { | 906 private void setInternalAccessAdapter(InternalAccessDelegate internalAccessA
dapter) { |
| 897 mInternalAccessAdapter = internalAccessAdapter; | 907 mInternalAccessAdapter = internalAccessAdapter; |
| 898 mContentViewCore.setContainerViewInternals(mInternalAccessAdapter); | 908 mContentViewCore.setContainerViewInternals(mInternalAccessAdapter); |
| 899 } | 909 } |
| 900 | 910 |
| 901 private void setContainerView(ViewGroup newContainerView) { | 911 private void setContainerView(ViewGroup newContainerView, AwGLFunctor curren
tFunctor) { |
| 902 // setWillNotDraw(false) is required since WebView draws it's own conten
ts using it's | 912 // setWillNotDraw(false) is required since WebView draws it's own conten
ts using it's |
| 903 // container view. If this is ever not the case we should remove this, a
s it removes | 913 // container view. If this is ever not the case we should remove this, a
s it removes |
| 904 // Android's gatherTransparentRegion optimization for the view. | 914 // Android's gatherTransparentRegion optimization for the view. |
| 905 mContainerView = newContainerView; | 915 mContainerView = newContainerView; |
| 916 mCurrentFunctor = currentFunctor; |
| 917 updateNativeAwGLFunctor(); |
| 906 mContainerView.setWillNotDraw(false); | 918 mContainerView.setWillNotDraw(false); |
| 907 | 919 |
| 908 mContentViewCore.setContainerView(mContainerView); | 920 mContentViewCore.setContainerView(mContainerView); |
| 909 if (mAwPdfExporter != null) { | 921 if (mAwPdfExporter != null) { |
| 910 mAwPdfExporter.setContainerView(mContainerView); | 922 mAwPdfExporter.setContainerView(mContainerView); |
| 911 } | 923 } |
| 912 mWebContentsDelegate.setContainerView(mContainerView); | 924 mWebContentsDelegate.setContainerView(mContainerView); |
| 913 onContainerViewChanged(); | 925 onContainerViewChanged(); |
| 914 } | 926 } |
| 915 | 927 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 987 } | 999 } |
| 988 | 1000 |
| 989 @VisibleForTesting | 1001 @VisibleForTesting |
| 990 public static void setLocale(String locale) { | 1002 public static void setLocale(String locale) { |
| 991 if (!sCurrentLocale.equals(locale)) { | 1003 if (!sCurrentLocale.equals(locale)) { |
| 992 sCurrentLocale = locale; | 1004 sCurrentLocale = locale; |
| 993 nativeSetLocale(sCurrentLocale); | 1005 nativeSetLocale(sCurrentLocale); |
| 994 } | 1006 } |
| 995 } | 1007 } |
| 996 | 1008 |
| 1009 private void updateNativeAwGLFunctor() { |
| 1010 nativeSetAwGLFunctor(mNativeAwContents, |
| 1011 mCurrentFunctor != null ? mCurrentFunctor.getNativeAwGLFunctor()
: 0); |
| 1012 } |
| 1013 |
| 997 /* Common initialization routine for adopting a native AwContents instance i
nto this | 1014 /* Common initialization routine for adopting a native AwContents instance i
nto this |
| 998 * java instance. | 1015 * java instance. |
| 999 * | 1016 * |
| 1000 * TAKE CARE! This method can get called multiple times per java instance. C
ode accordingly. | 1017 * TAKE CARE! This method can get called multiple times per java instance. C
ode accordingly. |
| 1001 * ^^^^^^^^^ See the native class declaration for more details on relative
object lifetimes. | 1018 * ^^^^^^^^^ See the native class declaration for more details on relative
object lifetimes. |
| 1002 */ | 1019 */ |
| 1003 private void setNewAwContents(long newAwContentsPtr) { | 1020 private void setNewAwContents(long newAwContentsPtr) { |
| 1004 if (mNativeAwContents != 0) { | 1021 if (mNativeAwContents != 0) { |
| 1005 destroyNatives(); | 1022 destroyNatives(); |
| 1006 mContentViewCore = null; | 1023 mContentViewCore = null; |
| 1007 mWebContents = null; | 1024 mWebContents = null; |
| 1008 mNavigationController = null; | 1025 mNavigationController = null; |
| 1009 } | 1026 } |
| 1010 | 1027 |
| 1011 assert mNativeAwContents == 0 && mCleanupReference == null && mContentVi
ewCore == null; | 1028 assert mNativeAwContents == 0 && mCleanupReference == null && mContentVi
ewCore == null; |
| 1012 | 1029 |
| 1013 mNativeAwContents = newAwContentsPtr; | 1030 mNativeAwContents = newAwContentsPtr; |
| 1031 nativeSetAwGLFunctor(mNativeAwContents, mInitialFunctor.getNativeAwGLFun
ctor()); |
| 1032 updateNativeAwGLFunctor(); |
| 1014 // TODO(joth): when the native and java counterparts of AwBrowserContext
are hooked up to | 1033 // TODO(joth): when the native and java counterparts of AwBrowserContext
are hooked up to |
| 1015 // each other, we should update |mBrowserContext| according to the newly
received native | 1034 // each other, we should update |mBrowserContext| according to the newly
received native |
| 1016 // WebContent's browser context. | 1035 // WebContent's browser context. |
| 1017 | 1036 |
| 1018 WebContents webContents = nativeGetWebContents(mNativeAwContents); | 1037 WebContents webContents = nativeGetWebContents(mNativeAwContents); |
| 1019 | 1038 |
| 1020 mWindowAndroid = getWindowAndroid(mContext); | 1039 mWindowAndroid = getWindowAndroid(mContext); |
| 1021 mContentViewCore = createAndInitializeContentViewCore(mContainerView, mC
ontext, | 1040 mContentViewCore = createAndInitializeContentViewCore(mContainerView, mC
ontext, |
| 1022 mInternalAccessAdapter, webContents, new AwGestureStateListener(
), | 1041 mInternalAccessAdapter, webContents, new AwGestureStateListener(
), |
| 1023 mContentViewClient, mZoomControls, mWindowAndroid.getWindowAndro
id()); | 1042 mContentViewClient, mZoomControls, mWindowAndroid.getWindowAndro
id()); |
| 1024 mAwGLFunctor = new AwGLFunctor(mNativeDrawGLFunctorFactory, mContainerVi
ew); | |
| 1025 nativeSetAwGLFunctor(mNativeAwContents, mAwGLFunctor.getNativeAwGLFuncto
r()); | |
| 1026 nativeSetJavaPeers(mNativeAwContents, this, mWebContentsDelegate, mConte
ntsClientBridge, | 1043 nativeSetJavaPeers(mNativeAwContents, this, mWebContentsDelegate, mConte
ntsClientBridge, |
| 1027 mIoThreadClient, mInterceptNavigationDelegate); | 1044 mIoThreadClient, mInterceptNavigationDelegate); |
| 1028 mWebContents = mContentViewCore.getWebContents(); | 1045 mWebContents = mContentViewCore.getWebContents(); |
| 1029 mNavigationController = mWebContents.getNavigationController(); | 1046 mNavigationController = mWebContents.getNavigationController(); |
| 1030 installWebContentsObserver(); | 1047 installWebContentsObserver(); |
| 1031 mSettings.setWebContents(webContents); | 1048 mSettings.setWebContents(webContents); |
| 1032 nativeSetDipScale(mNativeAwContents, (float) mDIPScale); | 1049 nativeSetDipScale(mNativeAwContents, (float) mDIPScale); |
| 1033 updateContentViewCoreVisibility(); | 1050 updateContentViewCoreVisibility(); |
| 1034 | 1051 |
| 1035 // The native side object has been bound to this java instance, so now i
s the time to | 1052 // The native side object has been bound to this java instance, so now i
s the time to |
| 1036 // bind all the native->java relationships. | 1053 // bind all the native->java relationships. |
| 1037 mCleanupReference = new CleanupReference( | 1054 mCleanupReference = new CleanupReference( |
| 1038 this, new DestroyRunnable(mNativeAwContents, mWindowAndroid, mAw
GLFunctor)); | 1055 this, new AwContentsDestroyRunnable(mNativeAwContents, mWindowAn
droid)); |
| 1039 } | 1056 } |
| 1040 | 1057 |
| 1041 private void installWebContentsObserver() { | 1058 private void installWebContentsObserver() { |
| 1042 if (mWebContentsObserver != null) { | 1059 if (mWebContentsObserver != null) { |
| 1043 mWebContentsObserver.destroy(); | 1060 mWebContentsObserver.destroy(); |
| 1044 } | 1061 } |
| 1045 mWebContentsObserver = new AwWebContentsObserver(mWebContents, this, mCo
ntentsClient); | 1062 mWebContentsObserver = new AwWebContentsObserver(mWebContents, this, mCo
ntentsClient); |
| 1046 } | 1063 } |
| 1047 | 1064 |
| 1048 /** | 1065 /** |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1134 | 1151 |
| 1135 if (mPostMessageSender != null) { | 1152 if (mPostMessageSender != null) { |
| 1136 mBrowserContext.getMessagePortService().removeObserver(mPostMessageS
ender); | 1153 mBrowserContext.getMessagePortService().removeObserver(mPostMessageS
ender); |
| 1137 mPostMessageSender = null; | 1154 mPostMessageSender = null; |
| 1138 } | 1155 } |
| 1139 | 1156 |
| 1140 // If we are attached, we have to call native detach to clean up | 1157 // If we are attached, we have to call native detach to clean up |
| 1141 // hardware resources. | 1158 // hardware resources. |
| 1142 if (mIsAttachedToWindow) { | 1159 if (mIsAttachedToWindow) { |
| 1143 Log.w(TAG, "WebView.destroy() called while WebView is still attached
to window."); | 1160 Log.w(TAG, "WebView.destroy() called while WebView is still attached
to window."); |
| 1144 mAwGLFunctor.deleteHardwareRenderer(); | |
| 1145 nativeOnDetachedFromWindow(mNativeAwContents); | 1161 nativeOnDetachedFromWindow(mNativeAwContents); |
| 1146 } | 1162 } |
| 1147 mIsDestroyed = true; | 1163 mIsDestroyed = true; |
| 1148 mHandler.post(new Runnable() { | 1164 mHandler.post(new Runnable() { |
| 1149 @Override | 1165 @Override |
| 1150 public void run() { | 1166 public void run() { |
| 1151 destroyNatives(); | 1167 destroyNatives(); |
| 1152 } | 1168 } |
| 1153 }); | 1169 }); |
| 1154 } | 1170 } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1262 | 1278 |
| 1263 /** | 1279 /** |
| 1264 * Intended for test code. | 1280 * Intended for test code. |
| 1265 * @return the number of native instances of this class. | 1281 * @return the number of native instances of this class. |
| 1266 */ | 1282 */ |
| 1267 @VisibleForTesting | 1283 @VisibleForTesting |
| 1268 public static int getNativeInstanceCount() { | 1284 public static int getNativeInstanceCount() { |
| 1269 return nativeGetNativeInstanceCount(); | 1285 return nativeGetNativeInstanceCount(); |
| 1270 } | 1286 } |
| 1271 | 1287 |
| 1272 public long getAwDrawGLViewContext() { | |
| 1273 // Only called during early construction, so client should not have had
a chance to | |
| 1274 // call destroy yet. | |
| 1275 assert !isDestroyed(NO_WARN); | |
| 1276 return mAwGLFunctor.getAwDrawGLViewContext(); | |
| 1277 } | |
| 1278 | |
| 1279 // This is only to avoid heap allocations inside getGlobalVisibleRect. It sh
ould treated | 1288 // This is only to avoid heap allocations inside getGlobalVisibleRect. It sh
ould treated |
| 1280 // as a local variable in the function and not used anywhere else. | 1289 // as a local variable in the function and not used anywhere else. |
| 1281 private static final Rect sLocalGlobalVisibleRect = new Rect(); | 1290 private static final Rect sLocalGlobalVisibleRect = new Rect(); |
| 1282 | 1291 |
| 1283 private Rect getGlobalVisibleRect() { | 1292 private Rect getGlobalVisibleRect() { |
| 1284 if (!mContainerView.getGlobalVisibleRect(sLocalGlobalVisibleRect)) { | 1293 if (!mContainerView.getGlobalVisibleRect(sLocalGlobalVisibleRect)) { |
| 1285 sLocalGlobalVisibleRect.setEmpty(); | 1294 sLocalGlobalVisibleRect.setEmpty(); |
| 1286 } | 1295 } |
| 1287 return sLocalGlobalVisibleRect; | 1296 return sLocalGlobalVisibleRect; |
| 1288 } | 1297 } |
| (...skipping 1670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2959 } | 2968 } |
| 2960 | 2969 |
| 2961 mScrollOffsetManager.syncScrollOffsetFromOnDraw(); | 2970 mScrollOffsetManager.syncScrollOffsetFromOnDraw(); |
| 2962 int scrollX = mContainerView.getScrollX(); | 2971 int scrollX = mContainerView.getScrollX(); |
| 2963 int scrollY = mContainerView.getScrollY(); | 2972 int scrollY = mContainerView.getScrollY(); |
| 2964 Rect globalVisibleRect = getGlobalVisibleRect(); | 2973 Rect globalVisibleRect = getGlobalVisibleRect(); |
| 2965 boolean did_draw = nativeOnDraw(mNativeAwContents, canvas, | 2974 boolean did_draw = nativeOnDraw(mNativeAwContents, canvas, |
| 2966 canvas.isHardwareAccelerated(), scrollX, scrollY, globalVisi
bleRect.left, | 2975 canvas.isHardwareAccelerated(), scrollX, scrollY, globalVisi
bleRect.left, |
| 2967 globalVisibleRect.top, globalVisibleRect.right, globalVisibl
eRect.bottom); | 2976 globalVisibleRect.top, globalVisibleRect.right, globalVisibl
eRect.bottom); |
| 2968 if (did_draw && canvas.isHardwareAccelerated() && !FORCE_AUXILIARY_B
ITMAP_RENDERING) { | 2977 if (did_draw && canvas.isHardwareAccelerated() && !FORCE_AUXILIARY_B
ITMAP_RENDERING) { |
| 2969 did_draw = mAwGLFunctor.requestDrawGLForCanvas(canvas); | 2978 did_draw = mCurrentFunctor.requestDrawGL(canvas); |
| 2970 } | 2979 } |
| 2971 if (did_draw) { | 2980 if (did_draw) { |
| 2972 int scrollXDiff = mContainerView.getScrollX() - scrollX; | 2981 int scrollXDiff = mContainerView.getScrollX() - scrollX; |
| 2973 int scrollYDiff = mContainerView.getScrollY() - scrollY; | 2982 int scrollYDiff = mContainerView.getScrollY() - scrollY; |
| 2974 canvas.translate(-scrollXDiff, -scrollYDiff); | 2983 canvas.translate(-scrollXDiff, -scrollYDiff); |
| 2975 } else { | 2984 } else { |
| 2976 TraceEvent.instant("NativeDrawFailed"); | 2985 TraceEvent.instant("NativeDrawFailed"); |
| 2977 canvas.drawColor(getEffectiveBackgroundColor()); | 2986 canvas.drawColor(getEffectiveBackgroundColor()); |
| 2978 } | 2987 } |
| 2979 | 2988 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3109 Log.w(TAG, "onAttachedToWindow called when already attached. Ign
oring"); | 3118 Log.w(TAG, "onAttachedToWindow called when already attached. Ign
oring"); |
| 3110 return; | 3119 return; |
| 3111 } | 3120 } |
| 3112 mIsAttachedToWindow = true; | 3121 mIsAttachedToWindow = true; |
| 3113 | 3122 |
| 3114 mContentViewCore.onAttachedToWindow(); | 3123 mContentViewCore.onAttachedToWindow(); |
| 3115 nativeOnAttachedToWindow(mNativeAwContents, mContainerView.getWidth(
), | 3124 nativeOnAttachedToWindow(mNativeAwContents, mContainerView.getWidth(
), |
| 3116 mContainerView.getHeight()); | 3125 mContainerView.getHeight()); |
| 3117 updateHardwareAcceleratedFeaturesToggle(); | 3126 updateHardwareAcceleratedFeaturesToggle(); |
| 3118 postUpdateContentViewCoreVisibility(); | 3127 postUpdateContentViewCoreVisibility(); |
| 3128 mCurrentFunctor.onAttachedToWindow(); |
| 3119 | 3129 |
| 3120 setLocale(LocaleUtils.getDefaultLocale()); | 3130 setLocale(LocaleUtils.getDefaultLocale()); |
| 3121 mSettings.updateAcceptLanguages(); | 3131 mSettings.updateAcceptLanguages(); |
| 3122 | 3132 |
| 3123 if (mComponentCallbacks != null) return; | 3133 if (mComponentCallbacks != null) return; |
| 3124 mComponentCallbacks = new AwComponentCallbacks(); | 3134 mComponentCallbacks = new AwComponentCallbacks(); |
| 3125 mContext.registerComponentCallbacks(mComponentCallbacks); | 3135 mContext.registerComponentCallbacks(mComponentCallbacks); |
| 3126 } | 3136 } |
| 3127 | 3137 |
| 3128 @Override | 3138 @Override |
| 3129 public void onDetachedFromWindow() { | 3139 public void onDetachedFromWindow() { |
| 3130 if (isDestroyed(NO_WARN)) return; | 3140 if (isDestroyed(NO_WARN)) return; |
| 3131 if (!mIsAttachedToWindow) { | 3141 if (!mIsAttachedToWindow) { |
| 3132 Log.w(TAG, "onDetachedFromWindow called when already detached. I
gnoring"); | 3142 Log.w(TAG, "onDetachedFromWindow called when already detached. I
gnoring"); |
| 3133 return; | 3143 return; |
| 3134 } | 3144 } |
| 3135 mIsAttachedToWindow = false; | 3145 mIsAttachedToWindow = false; |
| 3136 hideAutofillPopup(); | 3146 hideAutofillPopup(); |
| 3137 mAwGLFunctor.deleteHardwareRenderer(); | |
| 3138 nativeOnDetachedFromWindow(mNativeAwContents); | 3147 nativeOnDetachedFromWindow(mNativeAwContents); |
| 3139 | 3148 |
| 3140 mContentViewCore.onDetachedFromWindow(); | 3149 mContentViewCore.onDetachedFromWindow(); |
| 3141 updateHardwareAcceleratedFeaturesToggle(); | 3150 updateHardwareAcceleratedFeaturesToggle(); |
| 3142 postUpdateContentViewCoreVisibility(); | 3151 postUpdateContentViewCoreVisibility(); |
| 3152 mCurrentFunctor.onDetachedFromWindow(); |
| 3143 | 3153 |
| 3144 if (mComponentCallbacks != null) { | 3154 if (mComponentCallbacks != null) { |
| 3145 mContext.unregisterComponentCallbacks(mComponentCallbacks); | 3155 mContext.unregisterComponentCallbacks(mComponentCallbacks); |
| 3146 mComponentCallbacks = null; | 3156 mComponentCallbacks = null; |
| 3147 } | 3157 } |
| 3148 | 3158 |
| 3149 mScrollAccessibilityHelper.removePostedCallbacks(); | 3159 mScrollAccessibilityHelper.removePostedCallbacks(); |
| 3150 } | 3160 } |
| 3151 | 3161 |
| 3152 @Override | 3162 @Override |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3344 long resources); | 3354 long resources); |
| 3345 | 3355 |
| 3346 private native void nativePostMessageToFrame(long nativeAwContents, String f
rameId, | 3356 private native void nativePostMessageToFrame(long nativeAwContents, String f
rameId, |
| 3347 String message, String targetOrigin, int[] msgPorts); | 3357 String message, String targetOrigin, int[] msgPorts); |
| 3348 | 3358 |
| 3349 private native void nativeCreateMessageChannel(long nativeAwContents, AwMess
agePort[] ports); | 3359 private native void nativeCreateMessageChannel(long nativeAwContents, AwMess
agePort[] ports); |
| 3350 | 3360 |
| 3351 private native void nativeGrantFileSchemeAccesstoChildProcess(long nativeAwC
ontents); | 3361 private native void nativeGrantFileSchemeAccesstoChildProcess(long nativeAwC
ontents); |
| 3352 private native void nativeResumeLoadingCreatedPopupWebContents(long nativeAw
Contents); | 3362 private native void nativeResumeLoadingCreatedPopupWebContents(long nativeAw
Contents); |
| 3353 } | 3363 } |
| OLD | NEW |