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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
352 // we are a child of a ListView. This may cause many toggles of View focus, which we suppress | 352 // we are a child of a ListView. This may cause many toggles of View focus, which we suppress |
353 // when in this state. | 353 // when in this state. |
354 private boolean mTemporarilyDetached; | 354 private boolean mTemporarilyDetached; |
355 | 355 |
356 private Handler mHandler; | 356 private Handler mHandler; |
357 | 357 |
358 // True when this AwContents has been destroyed. | 358 // True when this AwContents has been destroyed. |
359 // Do not use directly, call isDestroyed() instead. | 359 // Do not use directly, call isDestroyed() instead. |
360 private boolean mIsDestroyed; | 360 private boolean mIsDestroyed; |
361 | 361 |
362 // True if this AwContents is in no operation state. | |
363 // Do not use directly, call isNoOperation() instead. | |
364 private boolean mIsNoOperation; | |
365 | |
362 private static String sCurrentLocales = ""; | 366 private static String sCurrentLocales = ""; |
363 | 367 |
364 private static final class AwContentsDestroyRunnable implements Runnable { | 368 private static final class AwContentsDestroyRunnable implements Runnable { |
365 private final long mNativeAwContents; | 369 private final long mNativeAwContents; |
366 // Hold onto a reference to the window (via its wrapper), so that it is not destroyed | 370 // Hold onto a reference to the window (via its wrapper), so that it is not destroyed |
367 // until we are done here. | 371 // until we are done here. |
368 private final WindowAndroidWrapper mWindowAndroid; | 372 private final WindowAndroidWrapper mWindowAndroid; |
369 | 373 |
370 private AwContentsDestroyRunnable( | 374 private AwContentsDestroyRunnable( |
371 long nativeAwContents, WindowAndroidWrapper windowAndroid) { | 375 long nativeAwContents, WindowAndroidWrapper windowAndroid) { |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
573 scrollRangeX, scrollRangeY, 0, 0, isTouchEvent); | 577 scrollRangeX, scrollRangeY, 0, 0, isTouchEvent); |
574 } | 578 } |
575 | 579 |
576 @Override | 580 @Override |
577 public void scrollContainerViewTo(int x, int y) { | 581 public void scrollContainerViewTo(int x, int y) { |
578 mInternalAccessAdapter.super_scrollTo(x, y); | 582 mInternalAccessAdapter.super_scrollTo(x, y); |
579 } | 583 } |
580 | 584 |
581 @Override | 585 @Override |
582 public void scrollNativeTo(int x, int y) { | 586 public void scrollNativeTo(int x, int y) { |
583 if (!isDestroyed(NO_WARN)) nativeScrollTo(mNativeAwContents, x, y); | 587 if (!isDestroyedOrNoOperation(NO_WARN)) nativeScrollTo(mNativeAwCont ents, x, y); |
584 } | 588 } |
585 | 589 |
586 @Override | 590 @Override |
587 public void smoothScroll(int targetX, int targetY, long durationMs) { | 591 public void smoothScroll(int targetX, int targetY, long durationMs) { |
588 if (!isDestroyed(NO_WARN)) nativeSmoothScroll( | 592 if (!isDestroyedOrNoOperation(NO_WARN)) { |
589 mNativeAwContents, targetX, targetY, durationMs); | 593 nativeSmoothScroll(mNativeAwContents, targetX, targetY, duration Ms); |
594 } | |
590 } | 595 } |
591 | 596 |
592 @Override | 597 @Override |
593 public int getContainerViewScrollX() { | 598 public int getContainerViewScrollX() { |
594 return mContainerView.getScrollX(); | 599 return mContainerView.getScrollX(); |
595 } | 600 } |
596 | 601 |
597 @Override | 602 @Override |
598 public int getContainerViewScrollY() { | 603 public int getContainerViewScrollY() { |
599 return mContainerView.getScrollY(); | 604 return mContainerView.getScrollY(); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
652 | 657 |
653 //-------------------------------------------------------------------------- ------------------ | 658 //-------------------------------------------------------------------------- ------------------ |
654 private class AwComponentCallbacks implements ComponentCallbacks2 { | 659 private class AwComponentCallbacks implements ComponentCallbacks2 { |
655 @Override | 660 @Override |
656 public void onTrimMemory(final int level) { | 661 public void onTrimMemory(final int level) { |
657 boolean visibleRectEmpty = getGlobalVisibleRect().isEmpty(); | 662 boolean visibleRectEmpty = getGlobalVisibleRect().isEmpty(); |
658 final boolean visible = mIsViewVisible && mIsWindowVisible && !visib leRectEmpty; | 663 final boolean visible = mIsViewVisible && mIsWindowVisible && !visib leRectEmpty; |
659 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 664 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
660 @Override | 665 @Override |
661 public void run() { | 666 public void run() { |
662 if (isDestroyed(NO_WARN)) return; | 667 if (isDestroyedOrNoOperation(NO_WARN)) return; |
663 if (level >= TRIM_MEMORY_MODERATE) { | 668 if (level >= TRIM_MEMORY_MODERATE) { |
664 mInitialFunctor.deleteHardwareRenderer(); | 669 mInitialFunctor.deleteHardwareRenderer(); |
665 if (mFullScreenFunctor != null) { | 670 if (mFullScreenFunctor != null) { |
666 mFullScreenFunctor.deleteHardwareRenderer(); | 671 mFullScreenFunctor.deleteHardwareRenderer(); |
667 } | 672 } |
668 } | 673 } |
669 nativeTrimMemory(mNativeAwContents, level, visible); | 674 nativeTrimMemory(mNativeAwContents, level, visible); |
670 } | 675 } |
671 }); | 676 }); |
672 } | 677 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
743 mAppTargetSdkVersion = mContext.getApplicationInfo().targetSdkVersion; | 748 mAppTargetSdkVersion = mContext.getApplicationInfo().targetSdkVersion; |
744 mInternalAccessAdapter = internalAccessAdapter; | 749 mInternalAccessAdapter = internalAccessAdapter; |
745 mNativeDrawGLFunctorFactory = nativeDrawGLFunctorFactory; | 750 mNativeDrawGLFunctorFactory = nativeDrawGLFunctorFactory; |
746 mInitialFunctor = new AwGLFunctor(mNativeDrawGLFunctorFactory, mContaine rView); | 751 mInitialFunctor = new AwGLFunctor(mNativeDrawGLFunctorFactory, mContaine rView); |
747 mCurrentFunctor = mInitialFunctor; | 752 mCurrentFunctor = mInitialFunctor; |
748 mContentsClient = contentsClient; | 753 mContentsClient = contentsClient; |
749 mContentsClient.getCallbackHelper().setCancelCallbackPoller( | 754 mContentsClient.getCallbackHelper().setCancelCallbackPoller( |
750 new AwContentsClientCallbackHelper.CancelCallbackPoller() { | 755 new AwContentsClientCallbackHelper.CancelCallbackPoller() { |
751 @Override | 756 @Override |
752 public boolean cancelAllCallbacks() { | 757 public boolean cancelAllCallbacks() { |
753 return AwContents.this.isDestroyed(NO_WARN); | 758 return AwContents.this.isDestroyedOrNoOperation(NO_WARN) ; |
754 } | 759 } |
755 }); | 760 }); |
756 mAwViewMethods = new AwViewMethodsImpl(); | 761 mAwViewMethods = new AwViewMethodsImpl(); |
757 mFullScreenTransitionsState = new FullScreenTransitionsState( | 762 mFullScreenTransitionsState = new FullScreenTransitionsState( |
758 mContainerView, mInternalAccessAdapter, mAwViewMethods); | 763 mContainerView, mInternalAccessAdapter, mAwViewMethods); |
759 mContentViewClient = new AwContentViewClient(contentsClient, settings, t his, mContext); | 764 mContentViewClient = new AwContentViewClient(contentsClient, settings, t his, mContext); |
760 mLayoutSizer = dependencyFactory.createLayoutSizer(); | 765 mLayoutSizer = dependencyFactory.createLayoutSizer(); |
761 mSettings = settings; | 766 mSettings = settings; |
762 mLayoutSizer.setDelegate(new AwLayoutSizerDelegate()); | 767 mLayoutSizer.setDelegate(new AwLayoutSizerDelegate()); |
763 mWebContentsDelegate = new AwWebContentsDelegateAdapter( | 768 mWebContentsDelegate = new AwWebContentsDelegateAdapter( |
(...skipping 10 matching lines...) Expand all Loading... | |
774 public void run() { | 779 public void run() { |
775 updateContentViewCoreVisibility(); | 780 updateContentViewCoreVisibility(); |
776 } | 781 } |
777 }; | 782 }; |
778 | 783 |
779 AwSettings.ZoomSupportChangeListener zoomListener = | 784 AwSettings.ZoomSupportChangeListener zoomListener = |
780 new AwSettings.ZoomSupportChangeListener() { | 785 new AwSettings.ZoomSupportChangeListener() { |
781 @Override | 786 @Override |
782 public void onGestureZoomSupportChanged( | 787 public void onGestureZoomSupportChanged( |
783 boolean supportsDoubleTapZoom, boolean supportsMulti TouchZoom) { | 788 boolean supportsDoubleTapZoom, boolean supportsMulti TouchZoom) { |
784 if (isDestroyed(NO_WARN)) return; | 789 if (isDestroyedOrNoOperation(NO_WARN)) return; |
785 mContentViewCore.updateDoubleTapSupport(supportsDoubleTa pZoom); | 790 mContentViewCore.updateDoubleTapSupport(supportsDoubleTa pZoom); |
786 mContentViewCore.updateMultiTouchZoomSupport(supportsMul tiTouchZoom); | 791 mContentViewCore.updateMultiTouchZoomSupport(supportsMul tiTouchZoom); |
787 } | 792 } |
788 | 793 |
789 }; | 794 }; |
790 mSettings.setZoomListener(zoomListener); | 795 mSettings.setZoomListener(zoomListener); |
791 mDefaultVideoPosterRequestHandler = new DefaultVideoPosterRequestHandler (mContentsClient); | 796 mDefaultVideoPosterRequestHandler = new DefaultVideoPosterRequestHandler (mContentsClient); |
792 mSettings.setDefaultVideoPosterURL( | 797 mSettings.setDefaultVideoPosterURL( |
793 mDefaultVideoPosterRequestHandler.getDefaultVideoPosterURL()); | 798 mDefaultVideoPosterRequestHandler.getDefaultVideoPosterURL()); |
794 mScrollOffsetManager = | 799 mScrollOffsetManager = |
(...skipping 25 matching lines...) Expand all Loading... | |
820 return mFullScreenTransitionsState.isFullScreen(); | 825 return mFullScreenTransitionsState.isFullScreen(); |
821 } | 826 } |
822 | 827 |
823 /** | 828 /** |
824 * Transitions this {@link AwContents} to fullscreen mode and returns the | 829 * Transitions this {@link AwContents} to fullscreen mode and returns the |
825 * {@link View} where the contents will be drawn while in fullscreen, or nul l | 830 * {@link View} where the contents will be drawn while in fullscreen, or nul l |
826 * if this AwContents has already been destroyed. | 831 * if this AwContents has already been destroyed. |
827 */ | 832 */ |
828 View enterFullScreen() { | 833 View enterFullScreen() { |
829 assert !isFullScreen(); | 834 assert !isFullScreen(); |
830 if (isDestroyed(NO_WARN)) return null; | 835 if (isDestroyedOrNoOperation(NO_WARN)) return null; |
831 | 836 |
832 // Detach to tear down the GL functor if this is still associated with t he old | 837 // Detach to tear down the GL functor if this is still associated with t he old |
833 // container view. It will be recreated during the next call to onDraw a ttached to | 838 // container view. It will be recreated during the next call to onDraw a ttached to |
834 // the new container view. | 839 // the new container view. |
835 onDetachedFromWindow(); | 840 onDetachedFromWindow(); |
836 | 841 |
837 // In fullscreen mode FullScreenView owns the AwViewMethodsImpl and AwCo ntents | 842 // In fullscreen mode FullScreenView owns the AwViewMethodsImpl and AwCo ntents |
838 // a NullAwViewMethods. | 843 // a NullAwViewMethods. |
839 FullScreenView fullScreenView = new FullScreenView(mContext, mAwViewMeth ods, this); | 844 FullScreenView fullScreenView = new FullScreenView(mContext, mAwViewMeth ods, this); |
840 fullScreenView.setFocusable(true); | 845 fullScreenView.setFocusable(true); |
(...skipping 10 matching lines...) Expand all Loading... | |
851 setInternalAccessAdapter(fullScreenView.getInternalAccessAdapter()); | 856 setInternalAccessAdapter(fullScreenView.getInternalAccessAdapter()); |
852 setContainerView(fullScreenView, mFullScreenFunctor); | 857 setContainerView(fullScreenView, mFullScreenFunctor); |
853 | 858 |
854 return fullScreenView; | 859 return fullScreenView; |
855 } | 860 } |
856 | 861 |
857 /** | 862 /** |
858 * Called when the app has requested to exit fullscreen. | 863 * Called when the app has requested to exit fullscreen. |
859 */ | 864 */ |
860 void requestExitFullscreen() { | 865 void requestExitFullscreen() { |
861 if (!isDestroyed(NO_WARN)) mContentViewCore.getWebContents().exitFullscr een(); | 866 if (!isDestroyedOrNoOperation(NO_WARN)) mContentViewCore.getWebContents( ).exitFullscreen(); |
862 } | 867 } |
863 | 868 |
864 /** | 869 /** |
865 * Returns this {@link AwContents} to embedded mode, where the {@link AwCont ents} are drawn | 870 * Returns this {@link AwContents} to embedded mode, where the {@link AwCont ents} are drawn |
866 * in the WebView. | 871 * in the WebView. |
867 */ | 872 */ |
868 void exitFullScreen() { | 873 void exitFullScreen() { |
869 if (!isFullScreen() || isDestroyed(NO_WARN)) { | 874 if (!isFullScreen() || isDestroyedOrNoOperation(NO_WARN)) { |
870 // exitFullScreen() can be called without a prior call to enterFullS creen() if a | 875 // exitFullScreen() can be called without a prior call to enterFullS creen() if a |
871 // "misbehave" app overrides onShowCustomView but does not add the c ustom view to | 876 // "misbehave" app overrides onShowCustomView but does not add the c ustom view to |
872 // the window. Exiting avoids a crash. | 877 // the window. Exiting avoids a crash. |
873 return; | 878 return; |
874 } | 879 } |
875 | 880 |
876 // Detach to tear down the GL functor if this is still associated with t he old | 881 // Detach to tear down the GL functor if this is still associated with t he old |
877 // container view. It will be recreated during the next call to onDraw a ttached to | 882 // container view. It will be recreated during the next call to onDraw a ttached to |
878 // the new container view. | 883 // the new container view. |
879 // NOTE: we cannot use mAwViewMethods here because its type is NullAwVie wMethods. | 884 // NOTE: we cannot use mAwViewMethods here because its type is NullAwVie wMethods. |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1077 mWebContentsObserver.destroy(); | 1082 mWebContentsObserver.destroy(); |
1078 } | 1083 } |
1079 mWebContentsObserver = new AwWebContentsObserver(mWebContents, this, mCo ntentsClient); | 1084 mWebContentsObserver = new AwWebContentsObserver(mWebContents, this, mCo ntentsClient); |
1080 } | 1085 } |
1081 | 1086 |
1082 /** | 1087 /** |
1083 * Called on the "source" AwContents that is opening the popup window to | 1088 * Called on the "source" AwContents that is opening the popup window to |
1084 * provide the AwContents to host the pop up content. | 1089 * provide the AwContents to host the pop up content. |
1085 */ | 1090 */ |
1086 public void supplyContentsForPopup(AwContents newContents) { | 1091 public void supplyContentsForPopup(AwContents newContents) { |
1087 if (isDestroyed(WARN)) return; | 1092 if (isDestroyedOrNoOperation(WARN)) return; |
1088 long popupNativeAwContents = nativeReleasePopupAwContents(mNativeAwConte nts); | 1093 long popupNativeAwContents = nativeReleasePopupAwContents(mNativeAwConte nts); |
1089 if (popupNativeAwContents == 0) { | 1094 if (popupNativeAwContents == 0) { |
1090 Log.w(TAG, "Popup WebView bind failed: no pending content."); | 1095 Log.w(TAG, "Popup WebView bind failed: no pending content."); |
1091 if (newContents != null) newContents.destroy(); | 1096 if (newContents != null) newContents.destroy(); |
1092 return; | 1097 return; |
1093 } | 1098 } |
1094 if (newContents == null) { | 1099 if (newContents == null) { |
1095 nativeDestroy(popupNativeAwContents); | 1100 nativeDestroy(popupNativeAwContents); |
1096 return; | 1101 return; |
1097 } | 1102 } |
1098 | 1103 |
1099 newContents.receivePopupContents(popupNativeAwContents); | 1104 newContents.receivePopupContents(popupNativeAwContents); |
1100 } | 1105 } |
1101 | 1106 |
1102 // Recap: supplyContentsForPopup() is called on the parent window's content, this method is | 1107 // Recap: supplyContentsForPopup() is called on the parent window's content, this method is |
1103 // called on the popup window's content. | 1108 // called on the popup window's content. |
1104 private void receivePopupContents(long popupNativeAwContents) { | 1109 private void receivePopupContents(long popupNativeAwContents) { |
1105 if (isDestroyed(WARN)) return; | 1110 if (isDestroyedOrNoOperation(WARN)) return; |
1106 mDeferredShouldOverrideUrlLoadingIsPendingForPopup = true; | 1111 mDeferredShouldOverrideUrlLoadingIsPendingForPopup = true; |
1107 // Save existing view state. | 1112 // Save existing view state. |
1108 final boolean wasAttached = mIsAttachedToWindow; | 1113 final boolean wasAttached = mIsAttachedToWindow; |
1109 final boolean wasViewVisible = mIsViewVisible; | 1114 final boolean wasViewVisible = mIsViewVisible; |
1110 final boolean wasWindowVisible = mIsWindowVisible; | 1115 final boolean wasWindowVisible = mIsWindowVisible; |
1111 final boolean wasPaused = mIsPaused; | 1116 final boolean wasPaused = mIsPaused; |
1112 final boolean wasFocused = mContainerViewFocused; | 1117 final boolean wasFocused = mContainerViewFocused; |
1113 final boolean wasWindowFocused = mWindowFocused; | 1118 final boolean wasWindowFocused = mWindowFocused; |
1114 | 1119 |
1115 // Properly clean up existing mContentViewCore and mNativeAwContents. | 1120 // Properly clean up existing mContentViewCore and mNativeAwContents. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1150 for (Map.Entry<String, Pair<Object, Class>> entry : javascriptInterfaces .entrySet()) { | 1155 for (Map.Entry<String, Pair<Object, Class>> entry : javascriptInterfaces .entrySet()) { |
1151 @SuppressWarnings("unchecked") | 1156 @SuppressWarnings("unchecked") |
1152 Class<? extends Annotation> requiredAnnotation = entry.getValue().se cond; | 1157 Class<? extends Annotation> requiredAnnotation = entry.getValue().se cond; |
1153 mContentViewCore.addPossiblyUnsafeJavascriptInterface( | 1158 mContentViewCore.addPossiblyUnsafeJavascriptInterface( |
1154 entry.getValue().first, | 1159 entry.getValue().first, |
1155 entry.getKey(), | 1160 entry.getKey(), |
1156 requiredAnnotation); | 1161 requiredAnnotation); |
1157 } | 1162 } |
1158 } | 1163 } |
1159 | 1164 |
1165 @CalledByNative | |
1166 private void onRenderProcessGone(int childProcessID) { | |
1167 // This is the first callback we got for render process gone, we can't d estroy the WebView | |
1168 // now because we need to get next callback onRenderProcessGoneWithDetai l() to know whether | |
1169 // render process crashed or was killed. | |
1170 // However, we should make WebView no operation to avoid being in weird states. | |
1171 // TODO: We might be able to combine destroyed and no operation states. | |
1172 mIsNoOperation = true; | |
1173 } | |
1174 | |
1175 @CalledByNative | |
1176 private boolean onRenderProcessGoneDetail(int childProcessID, boolean crashe d) { | |
1177 if (isDestroyed(NO_WARN)) return false; | |
1178 return mContentsClient.onRenderProcessGone(new AwRenderProcessGoneDetail (crashed)); | |
1179 } | |
1180 | |
1181 private boolean isNoOperation() { | |
1182 return mIsNoOperation; | |
1183 } | |
1184 | |
1185 private boolean isDestroyedOrNoOperation(int warnIfDestroyed) { | |
1186 return isDestroyed(warnIfDestroyed) || isNoOperation(); | |
1187 } | |
1188 | |
1160 /** | 1189 /** |
1161 * Destroys this object and deletes its native counterpart. | 1190 * Destroys this object and deletes its native counterpart. |
1162 */ | 1191 */ |
1163 public void destroy() { | 1192 public void destroy() { |
1164 if (TRACE) Log.i(TAG, "%s destroy", this); | 1193 if (TRACE) Log.i(TAG, "%s destroy", this); |
1165 if (isDestroyed(NO_WARN)) return; | 1194 if (isDestroyed(NO_WARN)) return; |
1166 | 1195 |
1167 // Remove pending messages | 1196 // Remove pending messages |
1168 mContentsClient.getCallbackHelper().removeCallbacksAndMessages(); | 1197 mContentsClient.getCallbackHelper().removeCallbacksAndMessages(); |
1169 | 1198 |
1170 if (mPostMessageSender != null) { | 1199 if (mPostMessageSender != null) { |
1171 mBrowserContext.getMessagePortService().removeObserver(mPostMessageS ender); | 1200 mBrowserContext.getMessagePortService().removeObserver(mPostMessageS ender); |
1172 mPostMessageSender = null; | 1201 mPostMessageSender = null; |
1173 } | 1202 } |
1174 | 1203 |
1175 if (mIsAttachedToWindow) { | 1204 if (mIsAttachedToWindow) { |
1176 Log.w(TAG, "WebView.destroy() called while WebView is still attached to window."); | 1205 Log.w(TAG, "WebView.destroy() called while WebView is still attached to window."); |
1177 // Need to call detach to avoid leaks because the real detach later will be ignored. | 1206 // Need to call detach to avoid leaks because the real detach later will be ignored. |
1178 onDetachedFromWindow(); | 1207 onDetachedFromWindow(); |
1179 } | 1208 } |
1209 mIsNoOperation = true; | |
1180 mIsDestroyed = true; | 1210 mIsDestroyed = true; |
1181 mHandler.post(new Runnable() { | 1211 mHandler.post(new Runnable() { |
1182 @Override | 1212 @Override |
1183 public void run() { | 1213 public void run() { |
1184 destroyNatives(); | 1214 destroyNatives(); |
1185 } | 1215 } |
1186 }); | 1216 }); |
1187 } | 1217 } |
1188 | 1218 |
1189 /** | 1219 /** |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1248 public NavigationController getNavigationController() { | 1278 public NavigationController getNavigationController() { |
1249 return mNavigationController; | 1279 return mNavigationController; |
1250 } | 1280 } |
1251 | 1281 |
1252 // Can be called from any thread. | 1282 // Can be called from any thread. |
1253 public AwSettings getSettings() { | 1283 public AwSettings getSettings() { |
1254 return mSettings; | 1284 return mSettings; |
1255 } | 1285 } |
1256 | 1286 |
1257 public AwPdfExporter getPdfExporter() { | 1287 public AwPdfExporter getPdfExporter() { |
1258 if (isDestroyed(WARN)) return null; | 1288 if (isDestroyedOrNoOperation(WARN)) return null; |
1259 if (mAwPdfExporter == null) { | 1289 if (mAwPdfExporter == null) { |
1260 mAwPdfExporter = new AwPdfExporter(mContainerView); | 1290 mAwPdfExporter = new AwPdfExporter(mContainerView); |
1261 nativeCreatePdfExporter(mNativeAwContents, mAwPdfExporter); | 1291 nativeCreatePdfExporter(mNativeAwContents, mAwPdfExporter); |
1262 } | 1292 } |
1263 return mAwPdfExporter; | 1293 return mAwPdfExporter; |
1264 } | 1294 } |
1265 | 1295 |
1266 public static void setAwDrawSWFunctionTable(long functionTablePointer) { | 1296 public static void setAwDrawSWFunctionTable(long functionTablePointer) { |
1267 nativeSetAwDrawSWFunctionTable(functionTablePointer); | 1297 nativeSetAwDrawSWFunctionTable(functionTablePointer); |
1268 // Force auxiliary bitmap rendering in emulators. | 1298 // Force auxiliary bitmap rendering in emulators. |
(...skipping 15 matching lines...) Expand all Loading... | |
1284 public static Activity activityFromContext(Context context) { | 1314 public static Activity activityFromContext(Context context) { |
1285 return WindowAndroid.activityFromContext(context); | 1315 return WindowAndroid.activityFromContext(context); |
1286 } | 1316 } |
1287 /** | 1317 /** |
1288 * Disables contents of JS-to-Java bridge objects to be inspectable using | 1318 * Disables contents of JS-to-Java bridge objects to be inspectable using |
1289 * Object.keys() method and "for .. in" loops. This is intended for applicat ions | 1319 * Object.keys() method and "for .. in" loops. This is intended for applicat ions |
1290 * targeting earlier Android releases where this was not possible, and we wa nt | 1320 * targeting earlier Android releases where this was not possible, and we wa nt |
1291 * to ensure backwards compatible behavior. | 1321 * to ensure backwards compatible behavior. |
1292 */ | 1322 */ |
1293 public void disableJavascriptInterfacesInspection() { | 1323 public void disableJavascriptInterfacesInspection() { |
1294 if (!isDestroyed(WARN)) mContentViewCore.setAllowJavascriptInterfacesIns pection(false); | 1324 if (!isDestroyedOrNoOperation(WARN)) { |
1325 mContentViewCore.setAllowJavascriptInterfacesInspection(false); | |
1326 } | |
1295 } | 1327 } |
1296 | 1328 |
1297 /** | 1329 /** |
1298 * Intended for test code. | 1330 * Intended for test code. |
1299 * @return the number of native instances of this class. | 1331 * @return the number of native instances of this class. |
1300 */ | 1332 */ |
1301 @VisibleForTesting | 1333 @VisibleForTesting |
1302 public static int getNativeInstanceCount() { | 1334 public static int getNativeInstanceCount() { |
1303 return nativeGetNativeInstanceCount(); | 1335 return nativeGetNativeInstanceCount(); |
1304 } | 1336 } |
(...skipping 24 matching lines...) Expand all Loading... | |
1329 | 1361 |
1330 public void setLayoutParams(final ViewGroup.LayoutParams layoutParams) { | 1362 public void setLayoutParams(final ViewGroup.LayoutParams layoutParams) { |
1331 mLayoutSizer.onLayoutParamsChange(); | 1363 mLayoutSizer.onLayoutParamsChange(); |
1332 } | 1364 } |
1333 | 1365 |
1334 public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | 1366 public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
1335 mAwViewMethods.onMeasure(widthMeasureSpec, heightMeasureSpec); | 1367 mAwViewMethods.onMeasure(widthMeasureSpec, heightMeasureSpec); |
1336 } | 1368 } |
1337 | 1369 |
1338 public int getContentHeightCss() { | 1370 public int getContentHeightCss() { |
1339 if (isDestroyed(WARN)) return 0; | 1371 if (isDestroyedOrNoOperation(WARN)) return 0; |
1340 return (int) Math.ceil(mContentHeightDip); | 1372 return (int) Math.ceil(mContentHeightDip); |
1341 } | 1373 } |
1342 | 1374 |
1343 public int getContentWidthCss() { | 1375 public int getContentWidthCss() { |
1344 if (isDestroyed(WARN)) return 0; | 1376 if (isDestroyedOrNoOperation(WARN)) return 0; |
1345 return (int) Math.ceil(mContentWidthDip); | 1377 return (int) Math.ceil(mContentWidthDip); |
1346 } | 1378 } |
1347 | 1379 |
1348 public Picture capturePicture() { | 1380 public Picture capturePicture() { |
1349 if (TRACE) Log.i(TAG, "%s capturePicture", this); | 1381 if (TRACE) Log.i(TAG, "%s capturePicture", this); |
1350 if (isDestroyed(WARN)) return null; | 1382 if (isDestroyedOrNoOperation(WARN)) return null; |
1351 return new AwPicture(nativeCapturePicture(mNativeAwContents, | 1383 return new AwPicture(nativeCapturePicture(mNativeAwContents, |
1352 mScrollOffsetManager.computeHorizontalScrollRange(), | 1384 mScrollOffsetManager.computeHorizontalScrollRange(), |
1353 mScrollOffsetManager.computeVerticalScrollRange())); | 1385 mScrollOffsetManager.computeVerticalScrollRange())); |
1354 } | 1386 } |
1355 | 1387 |
1356 public void clearView() { | 1388 public void clearView() { |
1357 if (TRACE) Log.i(TAG, "%s clearView", this); | 1389 if (TRACE) Log.i(TAG, "%s clearView", this); |
1358 if (!isDestroyed(WARN)) nativeClearView(mNativeAwContents); | 1390 if (!isDestroyedOrNoOperation(WARN)) nativeClearView(mNativeAwContents); |
1359 } | 1391 } |
1360 | 1392 |
1361 /** | 1393 /** |
1362 * Enable the onNewPicture callback. | 1394 * Enable the onNewPicture callback. |
1363 * @param enabled Flag to enable the callback. | 1395 * @param enabled Flag to enable the callback. |
1364 * @param invalidationOnly Flag to call back only on invalidation without pr oviding a picture. | 1396 * @param invalidationOnly Flag to call back only on invalidation without pr oviding a picture. |
1365 */ | 1397 */ |
1366 public void enableOnNewPicture(boolean enabled, boolean invalidationOnly) { | 1398 public void enableOnNewPicture(boolean enabled, boolean invalidationOnly) { |
1367 if (TRACE) Log.i(TAG, "%s enableOnNewPicture=%s", this, enabled); | 1399 if (TRACE) Log.i(TAG, "%s enableOnNewPicture=%s", this, enabled); |
1368 if (isDestroyed(WARN)) return; | 1400 if (isDestroyedOrNoOperation(WARN)) return; |
1369 if (invalidationOnly) { | 1401 if (invalidationOnly) { |
1370 mPictureListenerContentProvider = null; | 1402 mPictureListenerContentProvider = null; |
1371 } else if (enabled && mPictureListenerContentProvider == null) { | 1403 } else if (enabled && mPictureListenerContentProvider == null) { |
1372 mPictureListenerContentProvider = new Callable<Picture>() { | 1404 mPictureListenerContentProvider = new Callable<Picture>() { |
1373 @Override | 1405 @Override |
1374 public Picture call() { | 1406 public Picture call() { |
1375 return capturePicture(); | 1407 return capturePicture(); |
1376 } | 1408 } |
1377 }; | 1409 }; |
1378 } | 1410 } |
1379 nativeEnableOnNewPicture(mNativeAwContents, enabled); | 1411 nativeEnableOnNewPicture(mNativeAwContents, enabled); |
1380 } | 1412 } |
1381 | 1413 |
1382 public void findAllAsync(String searchString) { | 1414 public void findAllAsync(String searchString) { |
1383 if (TRACE) Log.i(TAG, "%s findAllAsync", this); | 1415 if (TRACE) Log.i(TAG, "%s findAllAsync", this); |
1384 if (!isDestroyed(WARN)) nativeFindAllAsync(mNativeAwContents, searchStri ng); | 1416 if (!isDestroyedOrNoOperation(WARN)) nativeFindAllAsync(mNativeAwContent s, searchString); |
1385 } | 1417 } |
1386 | 1418 |
1387 public void findNext(boolean forward) { | 1419 public void findNext(boolean forward) { |
1388 if (TRACE) Log.i(TAG, "%s findNext", this); | 1420 if (TRACE) Log.i(TAG, "%s findNext", this); |
1389 if (!isDestroyed(WARN)) nativeFindNext(mNativeAwContents, forward); | 1421 if (!isDestroyedOrNoOperation(WARN)) nativeFindNext(mNativeAwContents, f orward); |
1390 } | 1422 } |
1391 | 1423 |
1392 public void clearMatches() { | 1424 public void clearMatches() { |
1393 if (TRACE) Log.i(TAG, "%s clearMatches", this); | 1425 if (TRACE) Log.i(TAG, "%s clearMatches", this); |
1394 if (!isDestroyed(WARN)) nativeClearMatches(mNativeAwContents); | 1426 if (!isDestroyedOrNoOperation(WARN)) nativeClearMatches(mNativeAwContent s); |
1395 } | 1427 } |
1396 | 1428 |
1397 /** | 1429 /** |
1398 * @return load progress of the WebContents. | 1430 * @return load progress of the WebContents. |
1399 */ | 1431 */ |
1400 public int getMostRecentProgress() { | 1432 public int getMostRecentProgress() { |
1401 if (isDestroyed(WARN)) return 0; | 1433 if (isDestroyedOrNoOperation(WARN)) return 0; |
1402 // WebContentsDelegateAndroid conveniently caches the most recent notifi ed value for us. | 1434 // WebContentsDelegateAndroid conveniently caches the most recent notifi ed value for us. |
1403 return mWebContentsDelegate.getMostRecentProgress(); | 1435 return mWebContentsDelegate.getMostRecentProgress(); |
1404 } | 1436 } |
1405 | 1437 |
1406 public Bitmap getFavicon() { | 1438 public Bitmap getFavicon() { |
1407 if (isDestroyed(WARN)) return null; | 1439 if (isDestroyedOrNoOperation(WARN)) return null; |
1408 return mFavicon; | 1440 return mFavicon; |
1409 } | 1441 } |
1410 | 1442 |
1411 private void requestVisitedHistoryFromClient() { | 1443 private void requestVisitedHistoryFromClient() { |
1412 ValueCallback<String[]> callback = new ValueCallback<String[]>() { | 1444 ValueCallback<String[]> callback = new ValueCallback<String[]>() { |
1413 @Override | 1445 @Override |
1414 public void onReceiveValue(final String[] value) { | 1446 public void onReceiveValue(final String[] value) { |
1415 if (value != null) { | 1447 if (value != null) { |
1416 // Replace null values with empty strings, because they can' t be represented as | 1448 // Replace null values with empty strings, because they can' t be represented as |
1417 // native strings. | 1449 // native strings. |
1418 for (int i = 0; i < value.length; i++) { | 1450 for (int i = 0; i < value.length; i++) { |
1419 if (value[i] == null) value[i] = ""; | 1451 if (value[i] == null) value[i] = ""; |
1420 } | 1452 } |
1421 } | 1453 } |
1422 | 1454 |
1423 ThreadUtils.runOnUiThread(new Runnable() { | 1455 ThreadUtils.runOnUiThread(new Runnable() { |
1424 @Override | 1456 @Override |
1425 public void run() { | 1457 public void run() { |
1426 if (!isDestroyed(NO_WARN)) nativeAddVisitedLinks(mNative AwContents, value); | 1458 if (!isDestroyedOrNoOperation(NO_WARN)) { |
1459 nativeAddVisitedLinks(mNativeAwContents, value); | |
1460 } | |
1427 } | 1461 } |
1428 }); | 1462 }); |
1429 } | 1463 } |
1430 }; | 1464 }; |
1431 mContentsClient.getVisitedHistory(callback); | 1465 mContentsClient.getVisitedHistory(callback); |
1432 } | 1466 } |
1433 | 1467 |
1434 /** | 1468 /** |
1435 * WebView.loadUrl. | 1469 * WebView.loadUrl. |
1436 */ | 1470 */ |
1437 public void loadUrl(String url, Map<String, String> additionalHttpHeaders) { | 1471 public void loadUrl(String url, Map<String, String> additionalHttpHeaders) { |
1438 if (TRACE) Log.i(TAG, "%s loadUrl(extra headers)=%s", this, url); | 1472 if (TRACE) Log.i(TAG, "%s loadUrl(extra headers)=%s", this, url); |
1439 if (isDestroyed(WARN)) return; | 1473 if (isDestroyedOrNoOperation(WARN)) return; |
1440 // TODO: We may actually want to do some sanity checks here (like filter about://chrome). | 1474 // TODO: We may actually want to do some sanity checks here (like filter about://chrome). |
1441 | 1475 |
1442 // For backwards compatibility, apps targeting less than K will have JS URLs evaluated | 1476 // For backwards compatibility, apps targeting less than K will have JS URLs evaluated |
1443 // directly and any result of the evaluation will not replace the curren t page content. | 1477 // directly and any result of the evaluation will not replace the curren t page content. |
1444 // Matching Chrome behavior more closely; apps targetting >= K that load a JS URL will | 1478 // Matching Chrome behavior more closely; apps targetting >= K that load a JS URL will |
1445 // have the result of that URL replace the content of the current page. | 1479 // have the result of that URL replace the content of the current page. |
1446 final String javaScriptScheme = "javascript:"; | 1480 final String javaScriptScheme = "javascript:"; |
1447 if (mAppTargetSdkVersion < Build.VERSION_CODES.KITKAT && url != null | 1481 if (mAppTargetSdkVersion < Build.VERSION_CODES.KITKAT && url != null |
1448 && url.startsWith(javaScriptScheme)) { | 1482 && url.startsWith(javaScriptScheme)) { |
1449 evaluateJavaScript(url.substring(javaScriptScheme.length()), null); | 1483 evaluateJavaScript(url.substring(javaScriptScheme.length()), null); |
1450 return; | 1484 return; |
1451 } | 1485 } |
1452 | 1486 |
1453 LoadUrlParams params = new LoadUrlParams(url); | 1487 LoadUrlParams params = new LoadUrlParams(url); |
1454 if (additionalHttpHeaders != null) { | 1488 if (additionalHttpHeaders != null) { |
1455 params.setExtraHeaders(new HashMap<String, String>(additionalHttpHea ders)); | 1489 params.setExtraHeaders(new HashMap<String, String>(additionalHttpHea ders)); |
1456 } | 1490 } |
1457 loadUrl(params); | 1491 loadUrl(params); |
1458 } | 1492 } |
1459 | 1493 |
1460 /** | 1494 /** |
1461 * WebView.loadUrl. | 1495 * WebView.loadUrl. |
1462 */ | 1496 */ |
1463 public void loadUrl(String url) { | 1497 public void loadUrl(String url) { |
1464 if (TRACE) Log.i(TAG, "%s loadUrl=%s", this, url); | 1498 if (TRACE) Log.i(TAG, "%s loadUrl=%s", this, url); |
1465 if (isDestroyed(WARN)) return; | 1499 if (isDestroyedOrNoOperation(WARN)) return; |
1466 // Early out to match old WebView implementation | 1500 // Early out to match old WebView implementation |
1467 if (url == null) { | 1501 if (url == null) { |
1468 return; | 1502 return; |
1469 } | 1503 } |
1470 loadUrl(url, null); | 1504 loadUrl(url, null); |
1471 } | 1505 } |
1472 | 1506 |
1473 /** | 1507 /** |
1474 * WebView.postUrl. | 1508 * WebView.postUrl. |
1475 */ | 1509 */ |
1476 public void postUrl(String url, byte[] postData) { | 1510 public void postUrl(String url, byte[] postData) { |
1477 if (TRACE) Log.i(TAG, "%s postUrl=%s", this, url); | 1511 if (TRACE) Log.i(TAG, "%s postUrl=%s", this, url); |
1478 if (isDestroyed(WARN)) return; | 1512 if (isDestroyedOrNoOperation(WARN)) return; |
1479 LoadUrlParams params = LoadUrlParams.createLoadHttpPostParams(url, postD ata); | 1513 LoadUrlParams params = LoadUrlParams.createLoadHttpPostParams(url, postD ata); |
1480 Map<String, String> headers = new HashMap<String, String>(); | 1514 Map<String, String> headers = new HashMap<String, String>(); |
1481 headers.put("Content-Type", "application/x-www-form-urlencoded"); | 1515 headers.put("Content-Type", "application/x-www-form-urlencoded"); |
1482 params.setExtraHeaders(headers); | 1516 params.setExtraHeaders(headers); |
1483 loadUrl(params); | 1517 loadUrl(params); |
1484 } | 1518 } |
1485 | 1519 |
1486 private static String fixupMimeType(String mimeType) { | 1520 private static String fixupMimeType(String mimeType) { |
1487 return TextUtils.isEmpty(mimeType) ? "text/html" : mimeType; | 1521 return TextUtils.isEmpty(mimeType) ? "text/html" : mimeType; |
1488 } | 1522 } |
(...skipping 12 matching lines...) Expand all Loading... | |
1501 | 1535 |
1502 private static boolean isBase64Encoded(String encoding) { | 1536 private static boolean isBase64Encoded(String encoding) { |
1503 return "base64".equals(encoding); | 1537 return "base64".equals(encoding); |
1504 } | 1538 } |
1505 | 1539 |
1506 /** | 1540 /** |
1507 * WebView.loadData. | 1541 * WebView.loadData. |
1508 */ | 1542 */ |
1509 public void loadData(String data, String mimeType, String encoding) { | 1543 public void loadData(String data, String mimeType, String encoding) { |
1510 if (TRACE) Log.i(TAG, "%s loadData", this); | 1544 if (TRACE) Log.i(TAG, "%s loadData", this); |
1511 if (isDestroyed(WARN)) return; | 1545 if (isDestroyedOrNoOperation(WARN)) return; |
1512 loadUrl(LoadUrlParams.createLoadDataParams( | 1546 loadUrl(LoadUrlParams.createLoadDataParams( |
1513 fixupData(data), fixupMimeType(mimeType), isBase64Encoded(encodi ng))); | 1547 fixupData(data), fixupMimeType(mimeType), isBase64Encoded(encodi ng))); |
1514 } | 1548 } |
1515 | 1549 |
1516 /** | 1550 /** |
1517 * WebView.loadDataWithBaseURL. | 1551 * WebView.loadDataWithBaseURL. |
1518 */ | 1552 */ |
1519 public void loadDataWithBaseURL( | 1553 public void loadDataWithBaseURL( |
1520 String baseUrl, String data, String mimeType, String encoding, Strin g historyUrl) { | 1554 String baseUrl, String data, String mimeType, String encoding, Strin g historyUrl) { |
1521 if (TRACE) Log.i(TAG, "%s loadDataWithBaseURL=%s", this, baseUrl); | 1555 if (TRACE) Log.i(TAG, "%s loadDataWithBaseURL=%s", this, baseUrl); |
1522 if (isDestroyed(WARN)) return; | 1556 if (isDestroyedOrNoOperation(WARN)) return; |
1523 | 1557 |
1524 data = fixupData(data); | 1558 data = fixupData(data); |
1525 mimeType = fixupMimeType(mimeType); | 1559 mimeType = fixupMimeType(mimeType); |
1526 LoadUrlParams loadUrlParams; | 1560 LoadUrlParams loadUrlParams; |
1527 baseUrl = fixupBase(baseUrl); | 1561 baseUrl = fixupBase(baseUrl); |
1528 historyUrl = fixupHistory(historyUrl); | 1562 historyUrl = fixupHistory(historyUrl); |
1529 | 1563 |
1530 if (baseUrl.startsWith("data:")) { | 1564 if (baseUrl.startsWith("data:")) { |
1531 // For backwards compatibility with WebViewClassic, we use the value of |encoding| | 1565 // For backwards compatibility with WebViewClassic, we use the value of |encoding| |
1532 // as the charset, as long as it's not "base64". | 1566 // as the charset, as long as it's not "base64". |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1618 mContentsClient.getCallbackHelper().postOnPageStarted(params.getBase Url()); | 1652 mContentsClient.getCallbackHelper().postOnPageStarted(params.getBase Url()); |
1619 } | 1653 } |
1620 } | 1654 } |
1621 | 1655 |
1622 /** | 1656 /** |
1623 * Get the URL of the current page. | 1657 * Get the URL of the current page. |
1624 * | 1658 * |
1625 * @return The URL of the current page or null if it's empty. | 1659 * @return The URL of the current page or null if it's empty. |
1626 */ | 1660 */ |
1627 public String getUrl() { | 1661 public String getUrl() { |
1628 if (isDestroyed(WARN)) return null; | 1662 if (isDestroyedOrNoOperation(WARN)) return null; |
1629 String url = mWebContents.getUrl(); | 1663 String url = mWebContents.getUrl(); |
1630 if (url == null || url.trim().isEmpty()) return null; | 1664 if (url == null || url.trim().isEmpty()) return null; |
1631 return url; | 1665 return url; |
1632 } | 1666 } |
1633 | 1667 |
1634 /** | 1668 /** |
1635 * Gets the last committed URL. It represents the current page that is | 1669 * Gets the last committed URL. It represents the current page that is |
1636 * displayed in WebContents. It represents the current security context. | 1670 * displayed in WebContents. It represents the current security context. |
1637 * | 1671 * |
1638 * @return The URL of the current page or null if it's empty. | 1672 * @return The URL of the current page or null if it's empty. |
1639 */ | 1673 */ |
1640 public String getLastCommittedUrl() { | 1674 public String getLastCommittedUrl() { |
1641 if (isDestroyed(NO_WARN)) return null; | 1675 if (isDestroyedOrNoOperation(NO_WARN)) return null; |
1642 String url = mWebContents.getLastCommittedUrl(); | 1676 String url = mWebContents.getLastCommittedUrl(); |
1643 if (url == null || url.trim().isEmpty()) return null; | 1677 if (url == null || url.trim().isEmpty()) return null; |
1644 return url; | 1678 return url; |
1645 } | 1679 } |
1646 | 1680 |
1647 public void requestFocus() { | 1681 public void requestFocus() { |
1648 mAwViewMethods.requestFocus(); | 1682 mAwViewMethods.requestFocus(); |
1649 } | 1683 } |
1650 | 1684 |
1651 public void setBackgroundColor(int color) { | 1685 public void setBackgroundColor(int color) { |
1652 mBaseBackgroundColor = color; | 1686 mBaseBackgroundColor = color; |
1653 if (!isDestroyed(WARN)) nativeSetBackgroundColor(mNativeAwContents, colo r); | 1687 if (!isDestroyedOrNoOperation(WARN)) nativeSetBackgroundColor(mNativeAwC ontents, color); |
1654 } | 1688 } |
1655 | 1689 |
1656 /** | 1690 /** |
1657 * @see android.view.View#setLayerType() | 1691 * @see android.view.View#setLayerType() |
1658 */ | 1692 */ |
1659 public void setLayerType(int layerType, Paint paint) { | 1693 public void setLayerType(int layerType, Paint paint) { |
1660 mAwViewMethods.setLayerType(layerType, paint); | 1694 mAwViewMethods.setLayerType(layerType, paint); |
1661 } | 1695 } |
1662 | 1696 |
1663 int getEffectiveBackgroundColor() { | 1697 int getEffectiveBackgroundColor() { |
1664 // Do not ask the ContentViewCore for the background color, as it will a lways | 1698 // Do not ask the ContentViewCore for the background color, as it will a lways |
1665 // report white prior to initial navigation or post destruction, wherea s we want | 1699 // report white prior to initial navigation or post destruction, wherea s we want |
1666 // to use the client supplied base value in those cases. | 1700 // to use the client supplied base value in those cases. |
1667 if (isDestroyed(NO_WARN) || !mContentsClient.isCachedRendererBackgroundC olorValid()) { | 1701 if (isDestroyedOrNoOperation(NO_WARN) |
1702 || !mContentsClient.isCachedRendererBackgroundColorValid()) { | |
1668 return mBaseBackgroundColor; | 1703 return mBaseBackgroundColor; |
1669 } | 1704 } |
1670 return mContentsClient.getCachedRendererBackgroundColor(); | 1705 return mContentsClient.getCachedRendererBackgroundColor(); |
1671 } | 1706 } |
1672 | 1707 |
1673 public boolean isMultiTouchZoomSupported() { | 1708 public boolean isMultiTouchZoomSupported() { |
1674 return mSettings.supportsMultiTouchZoom(); | 1709 return mSettings.supportsMultiTouchZoom(); |
1675 } | 1710 } |
1676 | 1711 |
1677 public View getZoomControlsForTest() { | 1712 public View getZoomControlsForTest() { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1753 */ | 1788 */ |
1754 public void onContainerViewOverScrolled(int scrollX, int scrollY, boolean cl ampedX, | 1789 public void onContainerViewOverScrolled(int scrollX, int scrollY, boolean cl ampedX, |
1755 boolean clampedY) { | 1790 boolean clampedY) { |
1756 mAwViewMethods.onContainerViewOverScrolled(scrollX, scrollY, clampedX, c lampedY); | 1791 mAwViewMethods.onContainerViewOverScrolled(scrollX, scrollY, clampedX, c lampedY); |
1757 } | 1792 } |
1758 | 1793 |
1759 /** | 1794 /** |
1760 * @see android.webkit.WebView#requestChildRectangleOnScreen(View, Rect, boo lean) | 1795 * @see android.webkit.WebView#requestChildRectangleOnScreen(View, Rect, boo lean) |
1761 */ | 1796 */ |
1762 public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) { | 1797 public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) { |
1763 if (isDestroyed(WARN)) return false; | 1798 if (isDestroyedOrNoOperation(WARN)) return false; |
1764 return mScrollOffsetManager.requestChildRectangleOnScreen( | 1799 return mScrollOffsetManager.requestChildRectangleOnScreen( |
1765 child.getLeft() - child.getScrollX(), child.getTop() - child.get ScrollY(), | 1800 child.getLeft() - child.getScrollX(), child.getTop() - child.get ScrollY(), |
1766 rect, immediate); | 1801 rect, immediate); |
1767 } | 1802 } |
1768 | 1803 |
1769 /** | 1804 /** |
1770 * @see View#computeHorizontalScrollRange() | 1805 * @see View#computeHorizontalScrollRange() |
1771 */ | 1806 */ |
1772 public int computeHorizontalScrollRange() { | 1807 public int computeHorizontalScrollRange() { |
1773 return mAwViewMethods.computeHorizontalScrollRange(); | 1808 return mAwViewMethods.computeHorizontalScrollRange(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1806 */ | 1841 */ |
1807 public void computeScroll() { | 1842 public void computeScroll() { |
1808 mAwViewMethods.computeScroll(); | 1843 mAwViewMethods.computeScroll(); |
1809 } | 1844 } |
1810 | 1845 |
1811 /** | 1846 /** |
1812 * @see android.webkit.WebView#stopLoading() | 1847 * @see android.webkit.WebView#stopLoading() |
1813 */ | 1848 */ |
1814 public void stopLoading() { | 1849 public void stopLoading() { |
1815 if (TRACE) Log.i(TAG, "%s stopLoading", this); | 1850 if (TRACE) Log.i(TAG, "%s stopLoading", this); |
1816 if (!isDestroyed(WARN)) mWebContents.stop(); | 1851 if (!isDestroyedOrNoOperation(WARN)) mWebContents.stop(); |
1817 } | 1852 } |
1818 | 1853 |
1819 /** | 1854 /** |
1820 * @see android.webkit.WebView#reload() | 1855 * @see android.webkit.WebView#reload() |
1821 */ | 1856 */ |
1822 public void reload() { | 1857 public void reload() { |
1823 if (TRACE) Log.i(TAG, "%s reload", this); | 1858 if (TRACE) Log.i(TAG, "%s reload", this); |
1824 if (!isDestroyed(WARN)) mNavigationController.reload(true); | 1859 if (!isDestroyedOrNoOperation(WARN)) mNavigationController.reload(true); |
1825 } | 1860 } |
1826 | 1861 |
1827 /** | 1862 /** |
1828 * @see android.webkit.WebView#canGoBack() | 1863 * @see android.webkit.WebView#canGoBack() |
1829 */ | 1864 */ |
1830 public boolean canGoBack() { | 1865 public boolean canGoBack() { |
1831 return isDestroyed(WARN) ? false : mNavigationController.canGoBack(); | 1866 return isDestroyedOrNoOperation(WARN) ? false : mNavigationController.ca nGoBack(); |
1832 } | 1867 } |
1833 | 1868 |
1834 /** | 1869 /** |
1835 * @see android.webkit.WebView#goBack() | 1870 * @see android.webkit.WebView#goBack() |
1836 */ | 1871 */ |
1837 public void goBack() { | 1872 public void goBack() { |
1838 if (TRACE) Log.i(TAG, "%s goBack", this); | 1873 if (TRACE) Log.i(TAG, "%s goBack", this); |
1839 if (!isDestroyed(WARN)) mNavigationController.goBack(); | 1874 if (!isDestroyedOrNoOperation(WARN)) mNavigationController.goBack(); |
1840 } | 1875 } |
1841 | 1876 |
1842 /** | 1877 /** |
1843 * @see android.webkit.WebView#canGoForward() | 1878 * @see android.webkit.WebView#canGoForward() |
1844 */ | 1879 */ |
1845 public boolean canGoForward() { | 1880 public boolean canGoForward() { |
1846 return isDestroyed(WARN) ? false : mNavigationController.canGoForward(); | 1881 return isDestroyedOrNoOperation(WARN) ? false : mNavigationController.ca nGoForward(); |
1847 } | 1882 } |
1848 | 1883 |
1849 /** | 1884 /** |
1850 * @see android.webkit.WebView#goForward() | 1885 * @see android.webkit.WebView#goForward() |
1851 */ | 1886 */ |
1852 public void goForward() { | 1887 public void goForward() { |
1853 if (TRACE) Log.i(TAG, "%s goForward", this); | 1888 if (TRACE) Log.i(TAG, "%s goForward", this); |
1854 if (!isDestroyed(WARN)) mNavigationController.goForward(); | 1889 if (!isDestroyedOrNoOperation(WARN)) mNavigationController.goForward(); |
1855 } | 1890 } |
1856 | 1891 |
1857 /** | 1892 /** |
1858 * @see android.webkit.WebView#canGoBackOrForward(int) | 1893 * @see android.webkit.WebView#canGoBackOrForward(int) |
1859 */ | 1894 */ |
1860 public boolean canGoBackOrForward(int steps) { | 1895 public boolean canGoBackOrForward(int steps) { |
1861 return isDestroyed(WARN) ? false : mNavigationController.canGoToOffset(s teps); | 1896 return isDestroyedOrNoOperation(WARN) ? false : mNavigationController.ca nGoToOffset(steps); |
1862 } | 1897 } |
1863 | 1898 |
1864 /** | 1899 /** |
1865 * @see android.webkit.WebView#goBackOrForward(int) | 1900 * @see android.webkit.WebView#goBackOrForward(int) |
1866 */ | 1901 */ |
1867 public void goBackOrForward(int steps) { | 1902 public void goBackOrForward(int steps) { |
1868 if (TRACE) Log.i(TAG, "%s goBackOrForwad=%d", this, steps); | 1903 if (TRACE) Log.i(TAG, "%s goBackOrForwad=%d", this, steps); |
1869 if (!isDestroyed(WARN)) mNavigationController.goToOffset(steps); | 1904 if (!isDestroyedOrNoOperation(WARN)) mNavigationController.goToOffset(st eps); |
1870 } | 1905 } |
1871 | 1906 |
1872 /** | 1907 /** |
1873 * @see android.webkit.WebView#pauseTimers() | 1908 * @see android.webkit.WebView#pauseTimers() |
1874 */ | 1909 */ |
1875 public void pauseTimers() { | 1910 public void pauseTimers() { |
1876 if (TRACE) Log.i(TAG, "%s pauseTimers", this); | 1911 if (TRACE) Log.i(TAG, "%s pauseTimers", this); |
1877 if (!isDestroyed(WARN)) ContentViewStatics.setWebKitSharedTimersSuspende d(true); | 1912 if (!isDestroyedOrNoOperation(WARN)) { |
1913 ContentViewStatics.setWebKitSharedTimersSuspended(true); | |
1914 } | |
1878 } | 1915 } |
1879 | 1916 |
1880 /** | 1917 /** |
1881 * @see android.webkit.WebView#resumeTimers() | 1918 * @see android.webkit.WebView#resumeTimers() |
1882 */ | 1919 */ |
1883 public void resumeTimers() { | 1920 public void resumeTimers() { |
1884 if (TRACE) Log.i(TAG, "%s resumeTimers", this); | 1921 if (TRACE) Log.i(TAG, "%s resumeTimers", this); |
1885 if (!isDestroyed(WARN)) ContentViewStatics.setWebKitSharedTimersSuspende d(false); | 1922 if (!isDestroyedOrNoOperation(WARN)) { |
1923 ContentViewStatics.setWebKitSharedTimersSuspended(false); | |
1924 } | |
1886 } | 1925 } |
1887 | 1926 |
1888 /** | 1927 /** |
1889 * @see android.webkit.WebView#onPause() | 1928 * @see android.webkit.WebView#onPause() |
1890 */ | 1929 */ |
1891 public void onPause() { | 1930 public void onPause() { |
1892 if (TRACE) Log.i(TAG, "%s onPause", this); | 1931 if (TRACE) Log.i(TAG, "%s onPause", this); |
1893 if (mIsPaused || isDestroyed(NO_WARN)) return; | 1932 if (mIsPaused || isDestroyedOrNoOperation(NO_WARN)) return; |
1894 mIsPaused = true; | 1933 mIsPaused = true; |
1895 nativeSetIsPaused(mNativeAwContents, mIsPaused); | 1934 nativeSetIsPaused(mNativeAwContents, mIsPaused); |
1896 | 1935 |
1897 // Geolocation is paused/resumed via the page visibility mechanism. | 1936 // Geolocation is paused/resumed via the page visibility mechanism. |
1898 updateContentViewCoreVisibility(); | 1937 updateContentViewCoreVisibility(); |
1899 } | 1938 } |
1900 | 1939 |
1901 /** | 1940 /** |
1902 * @see android.webkit.WebView#onResume() | 1941 * @see android.webkit.WebView#onResume() |
1903 */ | 1942 */ |
1904 public void onResume() { | 1943 public void onResume() { |
1905 if (TRACE) Log.i(TAG, "%s onResume", this); | 1944 if (TRACE) Log.i(TAG, "%s onResume", this); |
1906 if (!mIsPaused || isDestroyed(NO_WARN)) return; | 1945 if (!mIsPaused || isDestroyedOrNoOperation(NO_WARN)) return; |
1907 mIsPaused = false; | 1946 mIsPaused = false; |
1908 nativeSetIsPaused(mNativeAwContents, mIsPaused); | 1947 nativeSetIsPaused(mNativeAwContents, mIsPaused); |
1909 updateContentViewCoreVisibility(); | 1948 updateContentViewCoreVisibility(); |
1910 } | 1949 } |
1911 | 1950 |
1912 /** | 1951 /** |
1913 * @see android.webkit.WebView#isPaused() | 1952 * @see android.webkit.WebView#isPaused() |
1914 */ | 1953 */ |
1915 public boolean isPaused() { | 1954 public boolean isPaused() { |
1916 return isDestroyed(WARN) ? false : mIsPaused; | 1955 return isDestroyedOrNoOperation(WARN) ? false : mIsPaused; |
1917 } | 1956 } |
1918 | 1957 |
1919 /** | 1958 /** |
1920 * @see android.webkit.WebView#onCreateInputConnection(EditorInfo) | 1959 * @see android.webkit.WebView#onCreateInputConnection(EditorInfo) |
1921 */ | 1960 */ |
1922 public InputConnection onCreateInputConnection(EditorInfo outAttrs) { | 1961 public InputConnection onCreateInputConnection(EditorInfo outAttrs) { |
1923 return mAwViewMethods.onCreateInputConnection(outAttrs); | 1962 return mAwViewMethods.onCreateInputConnection(outAttrs); |
1924 } | 1963 } |
1925 | 1964 |
1926 /** | 1965 /** |
(...skipping 18 matching lines...) Expand all Loading... | |
1945 } | 1984 } |
1946 | 1985 |
1947 /** | 1986 /** |
1948 * Clears the resource cache. Note that the cache is per-application, so thi s will clear the | 1987 * Clears the resource cache. Note that the cache is per-application, so thi s will clear the |
1949 * cache for all WebViews used. | 1988 * cache for all WebViews used. |
1950 * | 1989 * |
1951 * @param includeDiskFiles if false, only the RAM cache is cleared | 1990 * @param includeDiskFiles if false, only the RAM cache is cleared |
1952 */ | 1991 */ |
1953 public void clearCache(boolean includeDiskFiles) { | 1992 public void clearCache(boolean includeDiskFiles) { |
1954 if (TRACE) Log.i(TAG, "%s clearCache", this); | 1993 if (TRACE) Log.i(TAG, "%s clearCache", this); |
1955 if (!isDestroyed(WARN)) nativeClearCache(mNativeAwContents, includeDiskF iles); | 1994 if (!isDestroyedOrNoOperation(WARN)) nativeClearCache(mNativeAwContents, includeDiskFiles); |
1956 } | 1995 } |
1957 | 1996 |
1958 public void documentHasImages(Message message) { | 1997 public void documentHasImages(Message message) { |
1959 if (!isDestroyed(WARN)) nativeDocumentHasImages(mNativeAwContents, messa ge); | 1998 if (!isDestroyedOrNoOperation(WARN)) nativeDocumentHasImages(mNativeAwCo ntents, message); |
1960 } | 1999 } |
1961 | 2000 |
1962 public void saveWebArchive( | 2001 public void saveWebArchive( |
1963 final String basename, boolean autoname, final ValueCallback<String> callback) { | 2002 final String basename, boolean autoname, final ValueCallback<String> callback) { |
1964 if (TRACE) Log.i(TAG, "%s saveWebArchive=%s", this, basename); | 2003 if (TRACE) Log.i(TAG, "%s saveWebArchive=%s", this, basename); |
1965 if (!autoname) { | 2004 if (!autoname) { |
1966 saveWebArchiveInternal(basename, callback); | 2005 saveWebArchiveInternal(basename, callback); |
1967 return; | 2006 return; |
1968 } | 2007 } |
1969 // If auto-generating the file name, handle the name generation on a bac kground thread | 2008 // If auto-generating the file name, handle the name generation on a bac kground thread |
1970 // as it will require I/O access for checking whether previous files exi sted. | 2009 // as it will require I/O access for checking whether previous files exi sted. |
1971 new AsyncTask<Void, Void, String>() { | 2010 new AsyncTask<Void, Void, String>() { |
1972 @Override | 2011 @Override |
1973 protected String doInBackground(Void... params) { | 2012 protected String doInBackground(Void... params) { |
1974 return generateArchiveAutoNamePath(getOriginalUrl(), basename); | 2013 return generateArchiveAutoNamePath(getOriginalUrl(), basename); |
1975 } | 2014 } |
1976 | 2015 |
1977 @Override | 2016 @Override |
1978 protected void onPostExecute(String result) { | 2017 protected void onPostExecute(String result) { |
1979 saveWebArchiveInternal(result, callback); | 2018 saveWebArchiveInternal(result, callback); |
1980 } | 2019 } |
1981 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); | 2020 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
1982 } | 2021 } |
1983 | 2022 |
1984 public String getOriginalUrl() { | 2023 public String getOriginalUrl() { |
1985 if (isDestroyed(WARN)) return null; | 2024 if (isDestroyedOrNoOperation(WARN)) return null; |
1986 NavigationHistory history = mNavigationController.getNavigationHistory() ; | 2025 NavigationHistory history = mNavigationController.getNavigationHistory() ; |
1987 int currentIndex = history.getCurrentEntryIndex(); | 2026 int currentIndex = history.getCurrentEntryIndex(); |
1988 if (currentIndex >= 0 && currentIndex < history.getEntryCount()) { | 2027 if (currentIndex >= 0 && currentIndex < history.getEntryCount()) { |
1989 return history.getEntryAtIndex(currentIndex).getOriginalUrl(); | 2028 return history.getEntryAtIndex(currentIndex).getOriginalUrl(); |
1990 } | 2029 } |
1991 return null; | 2030 return null; |
1992 } | 2031 } |
1993 | 2032 |
1994 /** | 2033 /** |
1995 * @see ContentViewCore#getNavigationHistory() | 2034 * @see ContentViewCore#getNavigationHistory() |
1996 */ | 2035 */ |
1997 public NavigationHistory getNavigationHistory() { | 2036 public NavigationHistory getNavigationHistory() { |
1998 return isDestroyed(WARN) ? null : mNavigationController.getNavigationHis tory(); | 2037 return isDestroyedOrNoOperation(WARN) ? null : mNavigationController.get NavigationHistory(); |
1999 } | 2038 } |
2000 | 2039 |
2001 /** | 2040 /** |
2002 * @see android.webkit.WebView#getTitle() | 2041 * @see android.webkit.WebView#getTitle() |
2003 */ | 2042 */ |
2004 public String getTitle() { | 2043 public String getTitle() { |
2005 return isDestroyed(WARN) ? null : mWebContents.getTitle(); | 2044 return isDestroyedOrNoOperation(WARN) ? null : mWebContents.getTitle(); |
2006 } | 2045 } |
2007 | 2046 |
2008 /** | 2047 /** |
2009 * @see android.webkit.WebView#clearHistory() | 2048 * @see android.webkit.WebView#clearHistory() |
2010 */ | 2049 */ |
2011 public void clearHistory() { | 2050 public void clearHistory() { |
2012 if (TRACE) Log.i(TAG, "%s clearHistory", this); | 2051 if (TRACE) Log.i(TAG, "%s clearHistory", this); |
2013 if (!isDestroyed(WARN)) mNavigationController.clearHistory(); | 2052 if (!isDestroyedOrNoOperation(WARN)) mNavigationController.clearHistory( ); |
2014 } | 2053 } |
2015 | 2054 |
2016 /** | 2055 /** |
2017 * @see android.webkit.WebView#getCertificate() | 2056 * @see android.webkit.WebView#getCertificate() |
2018 */ | 2057 */ |
2019 public SslCertificate getCertificate() { | 2058 public SslCertificate getCertificate() { |
2020 return isDestroyed(WARN) ? null | 2059 return isDestroyedOrNoOperation(WARN) ? null |
2021 : SslUtil.getCertificateFromDerBytes(nativeGetCertificate(mNativ eAwContents)); | 2060 : SslUtil.getCertificateFromDerBytes(nativeGetCertificate(mNativ eAwContents)); |
2022 } | 2061 } |
2023 | 2062 |
2024 /** | 2063 /** |
2025 * @see android.webkit.WebView#clearSslPreferences() | 2064 * @see android.webkit.WebView#clearSslPreferences() |
2026 */ | 2065 */ |
2027 public void clearSslPreferences() { | 2066 public void clearSslPreferences() { |
2028 if (TRACE) Log.i(TAG, "%s clearSslPreferences", this); | 2067 if (TRACE) Log.i(TAG, "%s clearSslPreferences", this); |
2029 if (!isDestroyed(WARN)) mNavigationController.clearSslPreferences(); | 2068 if (!isDestroyedOrNoOperation(WARN)) mNavigationController.clearSslPrefe rences(); |
2030 } | 2069 } |
2031 | 2070 |
2032 /** | 2071 /** |
2033 * Method to return all hit test values relevant to public WebView API. | 2072 * Method to return all hit test values relevant to public WebView API. |
2034 * Note that this expose more data than needed for WebView.getHitTestResult. | 2073 * Note that this expose more data than needed for WebView.getHitTestResult. |
2035 * Unsafely returning reference to mutable internal object to avoid excessiv e | 2074 * Unsafely returning reference to mutable internal object to avoid excessiv e |
2036 * garbage allocation on repeated calls. | 2075 * garbage allocation on repeated calls. |
2037 */ | 2076 */ |
2038 public HitTestData getLastHitTestResult() { | 2077 public HitTestData getLastHitTestResult() { |
2039 if (TRACE) Log.i(TAG, "%s getLastHitTestResult", this); | 2078 if (TRACE) Log.i(TAG, "%s getLastHitTestResult", this); |
2040 if (isDestroyed(WARN)) return null; | 2079 if (isDestroyedOrNoOperation(WARN)) return null; |
2041 nativeUpdateLastHitTestData(mNativeAwContents); | 2080 nativeUpdateLastHitTestData(mNativeAwContents); |
2042 return mPossiblyStaleHitTestData; | 2081 return mPossiblyStaleHitTestData; |
2043 } | 2082 } |
2044 | 2083 |
2045 /** | 2084 /** |
2046 * @see android.webkit.WebView#requestFocusNodeHref() | 2085 * @see android.webkit.WebView#requestFocusNodeHref() |
2047 */ | 2086 */ |
2048 public void requestFocusNodeHref(Message msg) { | 2087 public void requestFocusNodeHref(Message msg) { |
2049 if (TRACE) Log.i(TAG, "%s requestFocusNodeHref", this); | 2088 if (TRACE) Log.i(TAG, "%s requestFocusNodeHref", this); |
2050 if (msg == null || isDestroyed(WARN)) return; | 2089 if (msg == null || isDestroyedOrNoOperation(WARN)) return; |
2051 | 2090 |
2052 nativeUpdateLastHitTestData(mNativeAwContents); | 2091 nativeUpdateLastHitTestData(mNativeAwContents); |
2053 Bundle data = msg.getData(); | 2092 Bundle data = msg.getData(); |
2054 | 2093 |
2055 // In order to maintain compatibility with the old WebView's implementat ion, | 2094 // In order to maintain compatibility with the old WebView's implementat ion, |
2056 // the absolute (full) url is passed in the |url| field, not only the hr ef attribute. | 2095 // the absolute (full) url is passed in the |url| field, not only the hr ef attribute. |
2057 // Note: HitTestData could be cleaned up at this point. See http://crbug .com/290992. | 2096 // Note: HitTestData could be cleaned up at this point. See http://crbug .com/290992. |
2058 data.putString("url", mPossiblyStaleHitTestData.href); | 2097 data.putString("url", mPossiblyStaleHitTestData.href); |
2059 data.putString("title", mPossiblyStaleHitTestData.anchorText); | 2098 data.putString("title", mPossiblyStaleHitTestData.anchorText); |
2060 data.putString("src", mPossiblyStaleHitTestData.imgSrc); | 2099 data.putString("src", mPossiblyStaleHitTestData.imgSrc); |
2061 msg.setData(data); | 2100 msg.setData(data); |
2062 msg.sendToTarget(); | 2101 msg.sendToTarget(); |
2063 } | 2102 } |
2064 | 2103 |
2065 /** | 2104 /** |
2066 * @see android.webkit.WebView#requestImageRef() | 2105 * @see android.webkit.WebView#requestImageRef() |
2067 */ | 2106 */ |
2068 public void requestImageRef(Message msg) { | 2107 public void requestImageRef(Message msg) { |
2069 if (TRACE) Log.i(TAG, "%s requestImageRef", this); | 2108 if (TRACE) Log.i(TAG, "%s requestImageRef", this); |
2070 if (msg == null || isDestroyed(WARN)) return; | 2109 if (msg == null || isDestroyedOrNoOperation(WARN)) return; |
2071 | 2110 |
2072 nativeUpdateLastHitTestData(mNativeAwContents); | 2111 nativeUpdateLastHitTestData(mNativeAwContents); |
2073 Bundle data = msg.getData(); | 2112 Bundle data = msg.getData(); |
2074 data.putString("url", mPossiblyStaleHitTestData.imgSrc); | 2113 data.putString("url", mPossiblyStaleHitTestData.imgSrc); |
2075 msg.setData(data); | 2114 msg.setData(data); |
2076 msg.sendToTarget(); | 2115 msg.sendToTarget(); |
2077 } | 2116 } |
2078 | 2117 |
2079 @VisibleForTesting | 2118 @VisibleForTesting |
2080 public float getPageScaleFactor() { | 2119 public float getPageScaleFactor() { |
2081 return mPageScaleFactor; | 2120 return mPageScaleFactor; |
2082 } | 2121 } |
2083 | 2122 |
2084 /** | 2123 /** |
2085 * @see android.webkit.WebView#getScale() | 2124 * @see android.webkit.WebView#getScale() |
2086 * | 2125 * |
2087 * Please note that the scale returned is the page scale multiplied by | 2126 * Please note that the scale returned is the page scale multiplied by |
2088 * the screen density factor. See CTS WebViewTest.testSetInitialScale. | 2127 * the screen density factor. See CTS WebViewTest.testSetInitialScale. |
2089 */ | 2128 */ |
2090 public float getScale() { | 2129 public float getScale() { |
2091 if (isDestroyed(WARN)) return 1; | 2130 if (isDestroyedOrNoOperation(WARN)) return 1; |
2092 return mPageScaleFactor * mContentViewCore.getDeviceScaleFactor(); | 2131 return mPageScaleFactor * mContentViewCore.getDeviceScaleFactor(); |
2093 } | 2132 } |
2094 | 2133 |
2095 /** | 2134 /** |
2096 * @see android.webkit.WebView#flingScroll(int, int) | 2135 * @see android.webkit.WebView#flingScroll(int, int) |
2097 */ | 2136 */ |
2098 public void flingScroll(int velocityX, int velocityY) { | 2137 public void flingScroll(int velocityX, int velocityY) { |
2099 if (TRACE) Log.i(TAG, "%s flingScroll", this); | 2138 if (TRACE) Log.i(TAG, "%s flingScroll", this); |
2100 if (isDestroyed(WARN)) return; | 2139 if (isDestroyedOrNoOperation(WARN)) return; |
2101 mContentViewCore.flingViewport(SystemClock.uptimeMillis(), -velocityX, - velocityY); | 2140 mContentViewCore.flingViewport(SystemClock.uptimeMillis(), -velocityX, - velocityY); |
2102 } | 2141 } |
2103 | 2142 |
2104 /** | 2143 /** |
2105 * @see android.webkit.WebView#pageUp(boolean) | 2144 * @see android.webkit.WebView#pageUp(boolean) |
2106 */ | 2145 */ |
2107 public boolean pageUp(boolean top) { | 2146 public boolean pageUp(boolean top) { |
2108 if (TRACE) Log.i(TAG, "%s pageUp", this); | 2147 if (TRACE) Log.i(TAG, "%s pageUp", this); |
2109 if (isDestroyed(WARN)) return false; | 2148 if (isDestroyedOrNoOperation(WARN)) return false; |
2110 return mScrollOffsetManager.pageUp(top); | 2149 return mScrollOffsetManager.pageUp(top); |
2111 } | 2150 } |
2112 | 2151 |
2113 /** | 2152 /** |
2114 * @see android.webkit.WebView#pageDown(boolean) | 2153 * @see android.webkit.WebView#pageDown(boolean) |
2115 */ | 2154 */ |
2116 public boolean pageDown(boolean bottom) { | 2155 public boolean pageDown(boolean bottom) { |
2117 if (TRACE) Log.i(TAG, "%s pageDown", this); | 2156 if (TRACE) Log.i(TAG, "%s pageDown", this); |
2118 if (isDestroyed(WARN)) return false; | 2157 if (isDestroyedOrNoOperation(WARN)) return false; |
2119 return mScrollOffsetManager.pageDown(bottom); | 2158 return mScrollOffsetManager.pageDown(bottom); |
2120 } | 2159 } |
2121 | 2160 |
2122 /** | 2161 /** |
2123 * @see android.webkit.WebView#canZoomIn() | 2162 * @see android.webkit.WebView#canZoomIn() |
2124 */ | 2163 */ |
2125 // This method uses the term 'zoom' for legacy reasons, but relates | 2164 // This method uses the term 'zoom' for legacy reasons, but relates |
2126 // to what chrome calls the 'page scale factor'. | 2165 // to what chrome calls the 'page scale factor'. |
2127 public boolean canZoomIn() { | 2166 public boolean canZoomIn() { |
2128 if (isDestroyed(WARN)) return false; | 2167 if (isDestroyedOrNoOperation(WARN)) return false; |
2129 final float zoomInExtent = mMaxPageScaleFactor - mPageScaleFactor; | 2168 final float zoomInExtent = mMaxPageScaleFactor - mPageScaleFactor; |
2130 return zoomInExtent > ZOOM_CONTROLS_EPSILON; | 2169 return zoomInExtent > ZOOM_CONTROLS_EPSILON; |
2131 } | 2170 } |
2132 | 2171 |
2133 /** | 2172 /** |
2134 * @see android.webkit.WebView#canZoomOut() | 2173 * @see android.webkit.WebView#canZoomOut() |
2135 */ | 2174 */ |
2136 // This method uses the term 'zoom' for legacy reasons, but relates | 2175 // This method uses the term 'zoom' for legacy reasons, but relates |
2137 // to what chrome calls the 'page scale factor'. | 2176 // to what chrome calls the 'page scale factor'. |
2138 public boolean canZoomOut() { | 2177 public boolean canZoomOut() { |
2139 if (isDestroyed(WARN)) return false; | 2178 if (isDestroyedOrNoOperation(WARN)) return false; |
2140 final float zoomOutExtent = mPageScaleFactor - mMinPageScaleFactor; | 2179 final float zoomOutExtent = mPageScaleFactor - mMinPageScaleFactor; |
2141 return zoomOutExtent > ZOOM_CONTROLS_EPSILON; | 2180 return zoomOutExtent > ZOOM_CONTROLS_EPSILON; |
2142 } | 2181 } |
2143 | 2182 |
2144 /** | 2183 /** |
2145 * @see android.webkit.WebView#zoomIn() | 2184 * @see android.webkit.WebView#zoomIn() |
2146 */ | 2185 */ |
2147 // This method uses the term 'zoom' for legacy reasons, but relates | 2186 // This method uses the term 'zoom' for legacy reasons, but relates |
2148 // to what chrome calls the 'page scale factor'. | 2187 // to what chrome calls the 'page scale factor'. |
2149 public boolean zoomIn() { | 2188 public boolean zoomIn() { |
(...skipping 16 matching lines...) Expand all Loading... | |
2166 zoomBy(0.8f); | 2205 zoomBy(0.8f); |
2167 return true; | 2206 return true; |
2168 } | 2207 } |
2169 | 2208 |
2170 /** | 2209 /** |
2171 * @see android.webkit.WebView#zoomBy() | 2210 * @see android.webkit.WebView#zoomBy() |
2172 */ | 2211 */ |
2173 // This method uses the term 'zoom' for legacy reasons, but relates | 2212 // This method uses the term 'zoom' for legacy reasons, but relates |
2174 // to what chrome calls the 'page scale factor'. | 2213 // to what chrome calls the 'page scale factor'. |
2175 public void zoomBy(float delta) { | 2214 public void zoomBy(float delta) { |
2176 if (isDestroyed(WARN)) return; | 2215 if (isDestroyedOrNoOperation(WARN)) return; |
2177 if (delta < 0.01f || delta > 100.0f) { | 2216 if (delta < 0.01f || delta > 100.0f) { |
2178 throw new IllegalStateException("zoom delta value outside [0.01, 100 ] range."); | 2217 throw new IllegalStateException("zoom delta value outside [0.01, 100 ] range."); |
2179 } | 2218 } |
2180 nativeZoomBy(mNativeAwContents, delta); | 2219 nativeZoomBy(mNativeAwContents, delta); |
2181 } | 2220 } |
2182 | 2221 |
2183 /** | 2222 /** |
2184 * @see android.webkit.WebView#invokeZoomPicker() | 2223 * @see android.webkit.WebView#invokeZoomPicker() |
2185 */ | 2224 */ |
2186 public void invokeZoomPicker() { | 2225 public void invokeZoomPicker() { |
2187 if (TRACE) Log.i(TAG, "%s invokeZoomPicker", this); | 2226 if (TRACE) Log.i(TAG, "%s invokeZoomPicker", this); |
2188 if (!isDestroyed(WARN)) mZoomControls.invokeZoomPicker(); | 2227 if (!isDestroyedOrNoOperation(WARN)) mZoomControls.invokeZoomPicker(); |
2189 } | 2228 } |
2190 | 2229 |
2191 /** | 2230 /** |
2192 * @see android.webkit.WebView#preauthorizePermission(Uri, long) | 2231 * @see android.webkit.WebView#preauthorizePermission(Uri, long) |
2193 */ | 2232 */ |
2194 public void preauthorizePermission(Uri origin, long resources) { | 2233 public void preauthorizePermission(Uri origin, long resources) { |
2195 if (isDestroyed(NO_WARN)) return; | 2234 if (isDestroyedOrNoOperation(NO_WARN)) return; |
2196 nativePreauthorizePermission(mNativeAwContents, origin.toString(), resou rces); | 2235 nativePreauthorizePermission(mNativeAwContents, origin.toString(), resou rces); |
2197 } | 2236 } |
2198 | 2237 |
2199 /** | 2238 /** |
2200 * @see ContentViewCore.evaluateJavaScript(String, JavaScriptCallback) | 2239 * @see ContentViewCore.evaluateJavaScript(String, JavaScriptCallback) |
2201 */ | 2240 */ |
2202 public void evaluateJavaScript(String script, final ValueCallback<String> ca llback) { | 2241 public void evaluateJavaScript(String script, final ValueCallback<String> ca llback) { |
2203 if (TRACE) Log.i(TAG, "%s evaluateJavascript=%s", this, script); | 2242 if (TRACE) Log.i(TAG, "%s evaluateJavascript=%s", this, script); |
2204 if (isDestroyed(WARN)) return; | 2243 if (isDestroyedOrNoOperation(WARN)) return; |
2205 JavaScriptCallback jsCallback = null; | 2244 JavaScriptCallback jsCallback = null; |
2206 if (callback != null) { | 2245 if (callback != null) { |
2207 jsCallback = new JavaScriptCallback() { | 2246 jsCallback = new JavaScriptCallback() { |
2208 @Override | 2247 @Override |
2209 public void handleJavaScriptResult(String jsonResult) { | 2248 public void handleJavaScriptResult(String jsonResult) { |
2210 callback.onReceiveValue(jsonResult); | 2249 callback.onReceiveValue(jsonResult); |
2211 } | 2250 } |
2212 }; | 2251 }; |
2213 } | 2252 } |
2214 | 2253 |
2215 mWebContents.evaluateJavaScript(script, jsCallback); | 2254 mWebContents.evaluateJavaScript(script, jsCallback); |
2216 } | 2255 } |
2217 | 2256 |
2218 public void evaluateJavaScriptForTests(String script, final ValueCallback<St ring> callback) { | 2257 public void evaluateJavaScriptForTests(String script, final ValueCallback<St ring> callback) { |
2219 if (TRACE) Log.i(TAG, "%s evaluateJavascriptForTests=%s", this, script); | 2258 if (TRACE) Log.i(TAG, "%s evaluateJavascriptForTests=%s", this, script); |
2220 if (isDestroyed(NO_WARN)) return; | 2259 if (isDestroyedOrNoOperation(NO_WARN)) return; |
2221 JavaScriptCallback jsCallback = null; | 2260 JavaScriptCallback jsCallback = null; |
2222 if (callback != null) { | 2261 if (callback != null) { |
2223 jsCallback = new JavaScriptCallback() { | 2262 jsCallback = new JavaScriptCallback() { |
2224 @Override | 2263 @Override |
2225 public void handleJavaScriptResult(String jsonResult) { | 2264 public void handleJavaScriptResult(String jsonResult) { |
2226 callback.onReceiveValue(jsonResult); | 2265 callback.onReceiveValue(jsonResult); |
2227 } | 2266 } |
2228 }; | 2267 }; |
2229 } | 2268 } |
2230 | 2269 |
2231 mWebContents.evaluateJavaScriptForTests(script, jsCallback); | 2270 mWebContents.evaluateJavaScriptForTests(script, jsCallback); |
2232 } | 2271 } |
2233 | 2272 |
2234 /** | 2273 /** |
2235 * Post a message to a frame. | 2274 * Post a message to a frame. |
2236 * | 2275 * |
2237 * @param frameName The name of the frame. If the name is null the message i s posted | 2276 * @param frameName The name of the frame. If the name is null the message i s posted |
2238 * to the main frame. | 2277 * to the main frame. |
2239 * @param message The message | 2278 * @param message The message |
2240 * @param targetOrigin The target origin | 2279 * @param targetOrigin The target origin |
2241 * @param sentPorts The sent message ports, if any. Pass null if there is no | 2280 * @param sentPorts The sent message ports, if any. Pass null if there is no |
2242 * message ports to pass. | 2281 * message ports to pass. |
2243 */ | 2282 */ |
2244 public void postMessageToFrame( | 2283 public void postMessageToFrame( |
2245 String frameName, String message, String targetOrigin, MessagePort[] sentPorts) { | 2284 String frameName, String message, String targetOrigin, MessagePort[] sentPorts) { |
2246 if (isDestroyed(WARN)) return; | 2285 if (isDestroyedOrNoOperation(WARN)) return; |
2247 if (mPostMessageSender == null) { | 2286 if (mPostMessageSender == null) { |
2248 AppWebMessagePortService service = mBrowserContext.getMessagePortSer vice(); | 2287 AppWebMessagePortService service = mBrowserContext.getMessagePortSer vice(); |
2249 mPostMessageSender = new PostMessageSender(this, service); | 2288 mPostMessageSender = new PostMessageSender(this, service); |
2250 service.addObserver(mPostMessageSender); | 2289 service.addObserver(mPostMessageSender); |
2251 } | 2290 } |
2252 mPostMessageSender.postMessage(frameName, message, targetOrigin, | 2291 mPostMessageSender.postMessage(frameName, message, targetOrigin, |
2253 (AppWebMessagePort[]) sentPorts); | 2292 (AppWebMessagePort[]) sentPorts); |
2254 } | 2293 } |
2255 | 2294 |
2256 // Implements PostMessageSender.PostMessageSenderDelegate interface method. | 2295 // Implements PostMessageSender.PostMessageSenderDelegate interface method. |
2257 @Override | 2296 @Override |
2258 public boolean isPostMessageSenderReady() { | 2297 public boolean isPostMessageSenderReady() { |
2259 return true; | 2298 return true; |
2260 } | 2299 } |
2261 | 2300 |
2262 // Implements PostMessageSender.PostMessageSenderDelegate interface method. | 2301 // Implements PostMessageSender.PostMessageSenderDelegate interface method. |
2263 @Override | 2302 @Override |
2264 public void onPostMessageQueueEmpty() { } | 2303 public void onPostMessageQueueEmpty() { } |
2265 | 2304 |
2266 // Implements PostMessageSender.PostMessageSenderDelegate interface method. | 2305 // Implements PostMessageSender.PostMessageSenderDelegate interface method. |
2267 @Override | 2306 @Override |
2268 public void postMessageToWeb(String frameName, String message, String target Origin, | 2307 public void postMessageToWeb(String frameName, String message, String target Origin, |
2269 int[] sentPortIds) { | 2308 int[] sentPortIds) { |
2270 if (TRACE) Log.i(TAG, "%s postMessageToWeb. TargetOrigin=%s", this, targ etOrigin); | 2309 if (TRACE) Log.i(TAG, "%s postMessageToWeb. TargetOrigin=%s", this, targ etOrigin); |
2271 if (isDestroyed(NO_WARN)) return; | 2310 if (isDestroyedOrNoOperation(NO_WARN)) return; |
2272 nativePostMessageToFrame(mNativeAwContents, frameName, message, targetOr igin, | 2311 nativePostMessageToFrame(mNativeAwContents, frameName, message, targetOr igin, |
2273 sentPortIds); | 2312 sentPortIds); |
2274 } | 2313 } |
2275 | 2314 |
2276 /** | 2315 /** |
2277 * Creates a message channel and returns the ports for each end of the chann el. | 2316 * Creates a message channel and returns the ports for each end of the chann el. |
2278 */ | 2317 */ |
2279 public AppWebMessagePort[] createMessageChannel() { | 2318 public AppWebMessagePort[] createMessageChannel() { |
2280 if (TRACE) Log.i(TAG, "%s createMessageChannel", this); | 2319 if (TRACE) Log.i(TAG, "%s createMessageChannel", this); |
2281 if (isDestroyed(WARN)) return null; | 2320 if (isDestroyedOrNoOperation(WARN)) return null; |
2282 AppWebMessagePort[] ports = mBrowserContext.getMessagePortService().crea teMessageChannel(); | 2321 AppWebMessagePort[] ports = mBrowserContext.getMessagePortService().crea teMessageChannel(); |
2283 nativeCreateMessageChannel(mNativeAwContents, ports); | 2322 nativeCreateMessageChannel(mNativeAwContents, ports); |
2284 return ports; | 2323 return ports; |
2285 } | 2324 } |
2286 | 2325 |
2287 public boolean hasAccessedInitialDocument() { | 2326 public boolean hasAccessedInitialDocument() { |
2288 if (isDestroyed(NO_WARN)) return false; | 2327 if (isDestroyedOrNoOperation(NO_WARN)) return false; |
2289 return mWebContents.hasAccessedInitialDocument(); | 2328 return mWebContents.hasAccessedInitialDocument(); |
2290 } | 2329 } |
2291 | 2330 |
2292 @TargetApi(Build.VERSION_CODES.M) | 2331 @TargetApi(Build.VERSION_CODES.M) |
2293 public void onProvideVirtualStructure(ViewStructure structure) { | 2332 public void onProvideVirtualStructure(ViewStructure structure) { |
2294 if (isDestroyed(WARN)) return; | 2333 if (isDestroyedOrNoOperation(WARN)) return; |
2295 if (!mWebContentsObserver.didEverCommitNavigation()) { | 2334 if (!mWebContentsObserver.didEverCommitNavigation()) { |
2296 // TODO(sgurun) write a test case for this condition crbug/605251 | 2335 // TODO(sgurun) write a test case for this condition crbug/605251 |
2297 structure.setChildCount(0); | 2336 structure.setChildCount(0); |
2298 return; | 2337 return; |
2299 } | 2338 } |
2300 // for webview, the platform already calculates the scroll (as it is a v iew) in | 2339 // for webview, the platform already calculates the scroll (as it is a v iew) in |
2301 // ViewStructure tree. Do not offset for it in the snapshop x,y position calculations. | 2340 // ViewStructure tree. Do not offset for it in the snapshop x,y position calculations. |
2302 mContentViewCore.onProvideVirtualStructure(structure, true); | 2341 mContentViewCore.onProvideVirtualStructure(structure, true); |
2303 } | 2342 } |
2304 | 2343 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2358 * @see android.view.View#onHoverEvent() | 2397 * @see android.view.View#onHoverEvent() |
2359 */ | 2398 */ |
2360 public boolean onHoverEvent(MotionEvent event) { | 2399 public boolean onHoverEvent(MotionEvent event) { |
2361 return mAwViewMethods.onHoverEvent(event); | 2400 return mAwViewMethods.onHoverEvent(event); |
2362 } | 2401 } |
2363 | 2402 |
2364 /** | 2403 /** |
2365 * @see android.view.View#onGenericMotionEvent() | 2404 * @see android.view.View#onGenericMotionEvent() |
2366 */ | 2405 */ |
2367 public boolean onGenericMotionEvent(MotionEvent event) { | 2406 public boolean onGenericMotionEvent(MotionEvent event) { |
2368 return isDestroyed(NO_WARN) ? false : mContentViewCore.onGenericMotionEv ent(event); | 2407 return isDestroyedOrNoOperation(NO_WARN) ? false : |
2408 mContentViewCore.onGenericMotionEvent(event); | |
2369 } | 2409 } |
2370 | 2410 |
2371 /** | 2411 /** |
2372 * @see android.view.View#onConfigurationChanged() | 2412 * @see android.view.View#onConfigurationChanged() |
2373 */ | 2413 */ |
2374 public void onConfigurationChanged(Configuration newConfig) { | 2414 public void onConfigurationChanged(Configuration newConfig) { |
2375 mAwViewMethods.onConfigurationChanged(newConfig); | 2415 mAwViewMethods.onConfigurationChanged(newConfig); |
2376 } | 2416 } |
2377 | 2417 |
2378 /** | 2418 /** |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2441 | 2481 |
2442 /** | 2482 /** |
2443 * @see android.view.View#onWindowVisibilityChanged() | 2483 * @see android.view.View#onWindowVisibilityChanged() |
2444 */ | 2484 */ |
2445 public void onWindowVisibilityChanged(int visibility) { | 2485 public void onWindowVisibilityChanged(int visibility) { |
2446 mAwViewMethods.onWindowVisibilityChanged(visibility); | 2486 mAwViewMethods.onWindowVisibilityChanged(visibility); |
2447 } | 2487 } |
2448 | 2488 |
2449 private void setViewVisibilityInternal(boolean visible) { | 2489 private void setViewVisibilityInternal(boolean visible) { |
2450 mIsViewVisible = visible; | 2490 mIsViewVisible = visible; |
2451 if (!isDestroyed(NO_WARN)) nativeSetViewVisibility(mNativeAwContents, mI sViewVisible); | 2491 if (!isDestroyedOrNoOperation(NO_WARN)) { |
2492 nativeSetViewVisibility(mNativeAwContents, mIsViewVisible); | |
2493 } | |
2452 updateContentViewCoreVisibility(); | 2494 updateContentViewCoreVisibility(); |
2453 } | 2495 } |
2454 | 2496 |
2455 private void setWindowVisibilityInternal(boolean visible) { | 2497 private void setWindowVisibilityInternal(boolean visible) { |
2456 mInvalidateRootViewOnNextDraw |= Build.VERSION.SDK_INT <= Build.VERSION_ CODES.LOLLIPOP | 2498 mInvalidateRootViewOnNextDraw |= Build.VERSION.SDK_INT <= Build.VERSION_ CODES.LOLLIPOP |
2457 && visible && !mIsWindowVisible; | 2499 && visible && !mIsWindowVisible; |
2458 mIsWindowVisible = visible; | 2500 mIsWindowVisible = visible; |
2459 if (!isDestroyed(NO_WARN)) nativeSetWindowVisibility(mNativeAwContents, mIsWindowVisible); | 2501 if (!isDestroyedOrNoOperation(NO_WARN)) { |
2502 nativeSetWindowVisibility(mNativeAwContents, mIsWindowVisible); | |
2503 } | |
2460 postUpdateContentViewCoreVisibility(); | 2504 postUpdateContentViewCoreVisibility(); |
2461 } | 2505 } |
2462 | 2506 |
2463 private void postUpdateContentViewCoreVisibility() { | 2507 private void postUpdateContentViewCoreVisibility() { |
2464 if (mIsUpdateVisibilityTaskPending) return; | 2508 if (mIsUpdateVisibilityTaskPending) return; |
2465 // When WebView is attached to a visible window, WebView will be | 2509 // When WebView is attached to a visible window, WebView will be |
2466 // attached to a window whose visibility is initially invisible, then | 2510 // attached to a window whose visibility is initially invisible, then |
2467 // the window visibility will be updated to true. This means CVC | 2511 // the window visibility will be updated to true. This means CVC |
2468 // visibility will be set to false then true immediately, in the same | 2512 // visibility will be set to false then true immediately, in the same |
2469 // function call of View#dispatchAttachedToWindow. DetachedFromWindow | 2513 // function call of View#dispatchAttachedToWindow. DetachedFromWindow |
2470 // is a similar case, where window visibility changes before AwContents | 2514 // is a similar case, where window visibility changes before AwContents |
2471 // is detached from window. | 2515 // is detached from window. |
2472 // | 2516 // |
2473 // To prevent this flip of CVC visibility, post the task to update CVC | 2517 // To prevent this flip of CVC visibility, post the task to update CVC |
2474 // visibility during attach, detach and window visibility change. | 2518 // visibility during attach, detach and window visibility change. |
2475 mIsUpdateVisibilityTaskPending = true; | 2519 mIsUpdateVisibilityTaskPending = true; |
2476 mHandler.post(mUpdateVisibilityRunnable); | 2520 mHandler.post(mUpdateVisibilityRunnable); |
2477 } | 2521 } |
2478 | 2522 |
2479 private void updateContentViewCoreVisibility() { | 2523 private void updateContentViewCoreVisibility() { |
2480 mIsUpdateVisibilityTaskPending = false; | 2524 mIsUpdateVisibilityTaskPending = false; |
2481 if (isDestroyed(NO_WARN)) return; | 2525 if (isDestroyedOrNoOperation(NO_WARN)) return; |
2482 boolean contentViewCoreVisible = nativeIsVisible(mNativeAwContents); | 2526 boolean contentViewCoreVisible = nativeIsVisible(mNativeAwContents); |
2483 | 2527 |
2484 if (contentViewCoreVisible && !mIsContentViewCoreVisible) { | 2528 if (contentViewCoreVisible && !mIsContentViewCoreVisible) { |
2485 mContentViewCore.onShow(); | 2529 mContentViewCore.onShow(); |
2486 } else if (!contentViewCoreVisible && mIsContentViewCoreVisible) { | 2530 } else if (!contentViewCoreVisible && mIsContentViewCoreVisible) { |
2487 mContentViewCore.onHide(); | 2531 mContentViewCore.onHide(); |
2488 } | 2532 } |
2489 mIsContentViewCoreVisible = contentViewCoreVisible; | 2533 mIsContentViewCoreVisible = contentViewCoreVisible; |
2490 } | 2534 } |
2491 | 2535 |
2492 /** | 2536 /** |
2493 * Returns true if the page is visible according to DOM page visibility API. | 2537 * Returns true if the page is visible according to DOM page visibility API. |
2494 * See http://www.w3.org/TR/page-visibility/ | 2538 * See http://www.w3.org/TR/page-visibility/ |
2495 * This method is only called by tests and will return the supposed CVC | 2539 * This method is only called by tests and will return the supposed CVC |
2496 * visibility without waiting a pending mUpdateVisibilityRunnable to run. | 2540 * visibility without waiting a pending mUpdateVisibilityRunnable to run. |
2497 */ | 2541 */ |
2498 @VisibleForTesting | 2542 @VisibleForTesting |
2499 public boolean isPageVisible() { | 2543 public boolean isPageVisible() { |
2500 if (isDestroyed(NO_WARN)) return mIsContentViewCoreVisible; | 2544 if (isDestroyedOrNoOperation(NO_WARN)) return mIsContentViewCoreVisible; |
2501 return nativeIsVisible(mNativeAwContents); | 2545 return nativeIsVisible(mNativeAwContents); |
2502 } | 2546 } |
2503 | 2547 |
2504 /** | 2548 /** |
2505 * Key for opaque state in bundle. Note this is only public for tests. | 2549 * Key for opaque state in bundle. Note this is only public for tests. |
2506 */ | 2550 */ |
2507 public static final String SAVE_RESTORE_STATE_KEY = "WEBVIEW_CHROMIUM_STATE" ; | 2551 public static final String SAVE_RESTORE_STATE_KEY = "WEBVIEW_CHROMIUM_STATE" ; |
2508 | 2552 |
2509 /** | 2553 /** |
2510 * Save the state of this AwContents into provided Bundle. | 2554 * Save the state of this AwContents into provided Bundle. |
2511 * @return False if saving state failed. | 2555 * @return False if saving state failed. |
2512 */ | 2556 */ |
2513 public boolean saveState(Bundle outState) { | 2557 public boolean saveState(Bundle outState) { |
2514 if (TRACE) Log.i(TAG, "%s saveState", this); | 2558 if (TRACE) Log.i(TAG, "%s saveState", this); |
2515 if (isDestroyed(WARN) || outState == null) return false; | 2559 if (isDestroyedOrNoOperation(WARN) || outState == null) return false; |
2516 | 2560 |
2517 byte[] state = nativeGetOpaqueState(mNativeAwContents); | 2561 byte[] state = nativeGetOpaqueState(mNativeAwContents); |
2518 if (state == null) return false; | 2562 if (state == null) return false; |
2519 | 2563 |
2520 outState.putByteArray(SAVE_RESTORE_STATE_KEY, state); | 2564 outState.putByteArray(SAVE_RESTORE_STATE_KEY, state); |
2521 return true; | 2565 return true; |
2522 } | 2566 } |
2523 | 2567 |
2524 /** | 2568 /** |
2525 * Restore the state of this AwContents into provided Bundle. | 2569 * Restore the state of this AwContents into provided Bundle. |
2526 * @param inState Must be a bundle returned by saveState. | 2570 * @param inState Must be a bundle returned by saveState. |
2527 * @return False if restoring state failed. | 2571 * @return False if restoring state failed. |
2528 */ | 2572 */ |
2529 public boolean restoreState(Bundle inState) { | 2573 public boolean restoreState(Bundle inState) { |
2530 if (TRACE) Log.i(TAG, "%s restoreState", this); | 2574 if (TRACE) Log.i(TAG, "%s restoreState", this); |
2531 if (isDestroyed(WARN) || inState == null) return false; | 2575 if (isDestroyedOrNoOperation(WARN) || inState == null) return false; |
2532 | 2576 |
2533 byte[] state = inState.getByteArray(SAVE_RESTORE_STATE_KEY); | 2577 byte[] state = inState.getByteArray(SAVE_RESTORE_STATE_KEY); |
2534 if (state == null) return false; | 2578 if (state == null) return false; |
2535 | 2579 |
2536 boolean result = nativeRestoreFromOpaqueState(mNativeAwContents, state); | 2580 boolean result = nativeRestoreFromOpaqueState(mNativeAwContents, state); |
2537 | 2581 |
2538 // The onUpdateTitle callback normally happens when a page is loaded, | 2582 // The onUpdateTitle callback normally happens when a page is loaded, |
2539 // but is optimized out in the restoreState case because the title is | 2583 // but is optimized out in the restoreState case because the title is |
2540 // already restored. See WebContentsImpl::UpdateTitleForEntry. So we | 2584 // already restored. See WebContentsImpl::UpdateTitleForEntry. So we |
2541 // call the callback explicitly here. | 2585 // call the callback explicitly here. |
2542 if (result) mContentsClient.onReceivedTitle(mWebContents.getTitle()); | 2586 if (result) mContentsClient.onReceivedTitle(mWebContents.getTitle()); |
2543 | 2587 |
2544 return result; | 2588 return result; |
2545 } | 2589 } |
2546 | 2590 |
2547 /** | 2591 /** |
2548 * @see ContentViewCore#addPossiblyUnsafeJavascriptInterface(Object, String, Class) | 2592 * @see ContentViewCore#addPossiblyUnsafeJavascriptInterface(Object, String, Class) |
2549 */ | 2593 */ |
2550 @SuppressLint("NewApi") // JavascriptInterface requires API level 17. | 2594 @SuppressLint("NewApi") // JavascriptInterface requires API level 17. |
2551 public void addJavascriptInterface(Object object, String name) { | 2595 public void addJavascriptInterface(Object object, String name) { |
2552 if (TRACE) Log.i(TAG, "%s addJavascriptInterface=%s", this, name); | 2596 if (TRACE) Log.i(TAG, "%s addJavascriptInterface=%s", this, name); |
2553 if (isDestroyed(WARN)) return; | 2597 if (isDestroyedOrNoOperation(WARN)) return; |
2554 Class<? extends Annotation> requiredAnnotation = null; | 2598 Class<? extends Annotation> requiredAnnotation = null; |
2555 if (mAppTargetSdkVersion >= Build.VERSION_CODES.JELLY_BEAN_MR1) { | 2599 if (mAppTargetSdkVersion >= Build.VERSION_CODES.JELLY_BEAN_MR1) { |
2556 requiredAnnotation = JavascriptInterface.class; | 2600 requiredAnnotation = JavascriptInterface.class; |
2557 } | 2601 } |
2558 mContentViewCore.addPossiblyUnsafeJavascriptInterface(object, name, requ iredAnnotation); | 2602 mContentViewCore.addPossiblyUnsafeJavascriptInterface(object, name, requ iredAnnotation); |
2559 } | 2603 } |
2560 | 2604 |
2561 /** | 2605 /** |
2562 * @see android.webkit.WebView#removeJavascriptInterface(String) | 2606 * @see android.webkit.WebView#removeJavascriptInterface(String) |
2563 */ | 2607 */ |
2564 public void removeJavascriptInterface(String interfaceName) { | 2608 public void removeJavascriptInterface(String interfaceName) { |
2565 if (TRACE) Log.i(TAG, "%s removeJavascriptInterface=%s", this, interface Name); | 2609 if (TRACE) Log.i(TAG, "%s removeJavascriptInterface=%s", this, interface Name); |
2566 if (!isDestroyed(WARN)) mContentViewCore.removeJavascriptInterface(inter faceName); | 2610 if (!isDestroyedOrNoOperation(WARN)) { |
2611 mContentViewCore.removeJavascriptInterface(interfaceName); | |
2612 } | |
2567 } | 2613 } |
2568 | 2614 |
2569 /** | 2615 /** |
2570 * If native accessibility (not script injection) is enabled, and if this is | 2616 * If native accessibility (not script injection) is enabled, and if this is |
2571 * running on JellyBean or later, returns an AccessibilityNodeProvider that | 2617 * running on JellyBean or later, returns an AccessibilityNodeProvider that |
2572 * implements native accessibility for this view. Returns null otherwise. | 2618 * implements native accessibility for this view. Returns null otherwise. |
2573 * @return The AccessibilityNodeProvider, if available, or null otherwise. | 2619 * @return The AccessibilityNodeProvider, if available, or null otherwise. |
2574 */ | 2620 */ |
2575 public AccessibilityNodeProvider getAccessibilityNodeProvider() { | 2621 public AccessibilityNodeProvider getAccessibilityNodeProvider() { |
2576 return isDestroyed(WARN) ? null : mContentViewCore.getAccessibilityNodeP rovider(); | 2622 return isDestroyedOrNoOperation(WARN) ? null |
2623 : mContentViewCore.getAccessibilityNodeProvider(); | |
2577 } | 2624 } |
2578 | 2625 |
2579 /** | 2626 /** |
2580 * @see android.webkit.WebView#onInitializeAccessibilityNodeInfo(Accessibili tyNodeInfo) | 2627 * @see android.webkit.WebView#onInitializeAccessibilityNodeInfo(Accessibili tyNodeInfo) |
2581 */ | 2628 */ |
2582 public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { | 2629 public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { |
2583 // TODO(boliu): remove this method. | 2630 // TODO(boliu): remove this method. |
2584 } | 2631 } |
2585 | 2632 |
2586 /** | 2633 /** |
2587 * @see android.webkit.WebView#onInitializeAccessibilityEvent(AccessibilityE vent) | 2634 * @see android.webkit.WebView#onInitializeAccessibilityEvent(AccessibilityE vent) |
2588 */ | 2635 */ |
2589 public void onInitializeAccessibilityEvent(AccessibilityEvent event) { | 2636 public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
2590 // TODO(boliu): remove this method. | 2637 // TODO(boliu): remove this method. |
2591 } | 2638 } |
2592 | 2639 |
2593 public boolean supportsAccessibilityAction(int action) { | 2640 public boolean supportsAccessibilityAction(int action) { |
2594 return isDestroyed(WARN) ? false : mContentViewCore.supportsAccessibilit yAction(action); | 2641 return isDestroyedOrNoOperation(WARN) ? false |
2642 : mContentViewCore.supportsAccessibilityAction(action); | |
2595 } | 2643 } |
2596 | 2644 |
2597 /** | 2645 /** |
2598 * @see android.webkit.WebView#performAccessibilityAction(int, Bundle) | 2646 * @see android.webkit.WebView#performAccessibilityAction(int, Bundle) |
2599 */ | 2647 */ |
2600 public boolean performAccessibilityAction(int action, Bundle arguments) { | 2648 public boolean performAccessibilityAction(int action, Bundle arguments) { |
2601 return isDestroyed(WARN) ? false | 2649 return isDestroyedOrNoOperation(WARN) ? false |
2602 : mContentViewCore.performAccessibilityAction(action, arguments) ; | 2650 : mContentViewCore.performAccessibilityAction(action, arguments) ; |
2603 } | 2651 } |
2604 | 2652 |
2605 /** | 2653 /** |
2606 * @see android.webkit.WebView#clearFormData() | 2654 * @see android.webkit.WebView#clearFormData() |
2607 */ | 2655 */ |
2608 public void hideAutofillPopup() { | 2656 public void hideAutofillPopup() { |
2609 if (TRACE) Log.i(TAG, "%s hideAutofillPopup", this); | 2657 if (TRACE) Log.i(TAG, "%s hideAutofillPopup", this); |
2610 if (mAwAutofillClient != null) { | 2658 if (mAwAutofillClient != null) { |
2611 mAwAutofillClient.hideAutofillPopup(); | 2659 mAwAutofillClient.hideAutofillPopup(); |
2612 } | 2660 } |
2613 } | 2661 } |
2614 | 2662 |
2615 public void setNetworkAvailable(boolean networkUp) { | 2663 public void setNetworkAvailable(boolean networkUp) { |
2616 if (TRACE) Log.i(TAG, "%s setNetworkAvailable=%s", this, networkUp); | 2664 if (TRACE) Log.i(TAG, "%s setNetworkAvailable=%s", this, networkUp); |
2617 if (!isDestroyed(WARN)) { | 2665 if (!isDestroyedOrNoOperation(WARN)) { |
2618 // For backward compatibility when an app uses this API disable the | 2666 // For backward compatibility when an app uses this API disable the |
2619 // Network Information API to prevent inconsistencies, | 2667 // Network Information API to prevent inconsistencies, |
2620 // see crbug.com/520088. | 2668 // see crbug.com/520088. |
2621 NetworkChangeNotifier.setAutoDetectConnectivityState(false); | 2669 NetworkChangeNotifier.setAutoDetectConnectivityState(false); |
2622 nativeSetJsOnlineProperty(mNativeAwContents, networkUp); | 2670 nativeSetJsOnlineProperty(mNativeAwContents, networkUp); |
2623 } | 2671 } |
2624 } | 2672 } |
2625 | 2673 |
2626 /** | 2674 /** |
2627 * Inserts a {@link VisualStateCallback}. | 2675 * Inserts a {@link VisualStateCallback}. |
2628 * | 2676 * |
2629 * The {@link VisualStateCallback} will be inserted in Blink and will be inv oked when the | 2677 * The {@link VisualStateCallback} will be inserted in Blink and will be inv oked when the |
2630 * contents of the DOM tree at the moment that the callback was inserted (or later) are drawn | 2678 * contents of the DOM tree at the moment that the callback was inserted (or later) are drawn |
2631 * into the screen. In other words, the following events need to happen befo re the callback is | 2679 * into the screen. In other words, the following events need to happen befo re the callback is |
2632 * invoked: | 2680 * invoked: |
2633 * 1. The DOM tree is committed becoming the pending tree - see ThreadProxy: :BeginMainFrame | 2681 * 1. The DOM tree is committed becoming the pending tree - see ThreadProxy: :BeginMainFrame |
2634 * 2. The pending tree is activated becoming the active tree | 2682 * 2. The pending tree is activated becoming the active tree |
2635 * 3. A frame swap happens that draws the active tree into the screen | 2683 * 3. A frame swap happens that draws the active tree into the screen |
2636 * | 2684 * |
2637 * @param requestId an id that will be returned from the callback invocation to allow | 2685 * @param requestId an id that will be returned from the callback invocation to allow |
2638 * callers to match requests with callbacks. | 2686 * callers to match requests with callbacks. |
2639 * @param callback the callback to be inserted | 2687 * @param callback the callback to be inserted |
2640 * @throw IllegalStateException if this method is invoked after {@link #dest roy()} has been | 2688 * @throw IllegalStateException if this method is invoked after {@link #dest roy()} has been |
2641 * called. | 2689 * called. |
2642 */ | 2690 */ |
2643 public void insertVisualStateCallback(long requestId, VisualStateCallback ca llback) { | 2691 public void insertVisualStateCallback(long requestId, VisualStateCallback ca llback) { |
2644 if (TRACE) Log.i(TAG, "%s insertVisualStateCallback", this); | 2692 if (TRACE) Log.i(TAG, "%s insertVisualStateCallback", this); |
2645 if (isDestroyed(NO_WARN)) throw new IllegalStateException( | 2693 if (isDestroyed(NO_WARN)) throw new IllegalStateException( |
2646 "insertVisualStateCallback cannot be called after the WebView ha s been destroyed"); | 2694 "insertVisualStateCallback cannot be called after the WebView ha s been destroyed"); |
2647 nativeInsertVisualStateCallback(mNativeAwContents, requestId, callback); | 2695 nativeInsertVisualStateCallback(mNativeAwContents, requestId, callback); |
Tobias Sargeant
2017/01/19 17:28:03
You need to change this to fire the callback immed
michaelbai
2017/01/19 17:33:31
So, nativeInsertVisualStateCallback doesn't fire c
| |
2648 } | 2696 } |
2649 | 2697 |
2650 public boolean isPopupWindow() { | 2698 public boolean isPopupWindow() { |
2651 return mIsPopupWindow; | 2699 return mIsPopupWindow; |
2652 } | 2700 } |
2653 | 2701 |
2654 //-------------------------------------------------------------------------- ------------------ | 2702 //-------------------------------------------------------------------------- ------------------ |
2655 // Methods called from native via JNI | 2703 // Methods called from native via JNI |
2656 //-------------------------------------------------------------------------- ------------------ | 2704 //-------------------------------------------------------------------------- ------------------ |
2657 | 2705 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2690 @CalledByNative | 2738 @CalledByNative |
2691 private void onReceivedHttpAuthRequest(AwHttpAuthHandler handler, String hos t, String realm) { | 2739 private void onReceivedHttpAuthRequest(AwHttpAuthHandler handler, String hos t, String realm) { |
2692 mContentsClient.onReceivedHttpAuthRequest(handler, host, realm); | 2740 mContentsClient.onReceivedHttpAuthRequest(handler, host, realm); |
2693 } | 2741 } |
2694 | 2742 |
2695 public AwGeolocationPermissions getGeolocationPermissions() { | 2743 public AwGeolocationPermissions getGeolocationPermissions() { |
2696 return mBrowserContext.getGeolocationPermissions(); | 2744 return mBrowserContext.getGeolocationPermissions(); |
2697 } | 2745 } |
2698 | 2746 |
2699 public void invokeGeolocationCallback(boolean value, String requestingFrame) { | 2747 public void invokeGeolocationCallback(boolean value, String requestingFrame) { |
2700 if (isDestroyed(NO_WARN)) return; | 2748 if (isDestroyedOrNoOperation(NO_WARN)) return; |
2701 nativeInvokeGeolocationCallback(mNativeAwContents, value, requestingFram e); | 2749 nativeInvokeGeolocationCallback(mNativeAwContents, value, requestingFram e); |
2702 } | 2750 } |
2703 | 2751 |
2704 @CalledByNative | 2752 @CalledByNative |
2705 private void onGeolocationPermissionsShowPrompt(String origin) { | 2753 private void onGeolocationPermissionsShowPrompt(String origin) { |
2706 if (isDestroyed(NO_WARN)) return; | 2754 if (isDestroyedOrNoOperation(NO_WARN)) return; |
2707 AwGeolocationPermissions permissions = mBrowserContext.getGeolocationPer missions(); | 2755 AwGeolocationPermissions permissions = mBrowserContext.getGeolocationPer missions(); |
2708 // Reject if geoloaction is disabled, or the origin has a retained deny | 2756 // Reject if geoloaction is disabled, or the origin has a retained deny |
2709 if (!mSettings.getGeolocationEnabled()) { | 2757 if (!mSettings.getGeolocationEnabled()) { |
2710 nativeInvokeGeolocationCallback(mNativeAwContents, false, origin); | 2758 nativeInvokeGeolocationCallback(mNativeAwContents, false, origin); |
2711 return; | 2759 return; |
2712 } | 2760 } |
2713 // Allow if the origin has a retained allow | 2761 // Allow if the origin has a retained allow |
2714 if (permissions.hasOrigin(origin)) { | 2762 if (permissions.hasOrigin(origin)) { |
2715 nativeInvokeGeolocationCallback(mNativeAwContents, permissions.isOri ginAllowed(origin), | 2763 nativeInvokeGeolocationCallback(mNativeAwContents, permissions.isOri ginAllowed(origin), |
2716 origin); | 2764 origin); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2869 if (mPageScaleFactor != pageScaleFactor) { | 2917 if (mPageScaleFactor != pageScaleFactor) { |
2870 float oldPageScaleFactor = mPageScaleFactor; | 2918 float oldPageScaleFactor = mPageScaleFactor; |
2871 mPageScaleFactor = pageScaleFactor; | 2919 mPageScaleFactor = pageScaleFactor; |
2872 float dipScale = mContentViewCore.getDeviceScaleFactor(); | 2920 float dipScale = mContentViewCore.getDeviceScaleFactor(); |
2873 mContentsClient.getCallbackHelper().postOnScaleChangedScaled( | 2921 mContentsClient.getCallbackHelper().postOnScaleChangedScaled( |
2874 oldPageScaleFactor * dipScale, mPageScaleFactor * dipScale); | 2922 oldPageScaleFactor * dipScale, mPageScaleFactor * dipScale); |
2875 } | 2923 } |
2876 } | 2924 } |
2877 | 2925 |
2878 private void saveWebArchiveInternal(String path, final ValueCallback<String> callback) { | 2926 private void saveWebArchiveInternal(String path, final ValueCallback<String> callback) { |
2879 if (path == null || isDestroyed(WARN)) { | 2927 if (path == null || isDestroyedOrNoOperation(WARN)) { |
2880 ThreadUtils.runOnUiThread(new Runnable() { | 2928 ThreadUtils.runOnUiThread(new Runnable() { |
2881 @Override | 2929 @Override |
2882 public void run() { | 2930 public void run() { |
2883 callback.onReceiveValue(null); | 2931 callback.onReceiveValue(null); |
2884 } | 2932 } |
2885 }); | 2933 }); |
2886 } else { | 2934 } else { |
2887 nativeGenerateMHTML(mNativeAwContents, path, callback); | 2935 nativeGenerateMHTML(mNativeAwContents, path, callback); |
2888 } | 2936 } |
2889 } | 2937 } |
(...skipping 27 matching lines...) Expand all Loading... | |
2917 testName = baseName + name + "-" + i + WEB_ARCHIVE_EXTENSION; | 2965 testName = baseName + name + "-" + i + WEB_ARCHIVE_EXTENSION; |
2918 if (!new File(testName).exists()) return testName; | 2966 if (!new File(testName).exists()) return testName; |
2919 } | 2967 } |
2920 | 2968 |
2921 Log.e(TAG, "Unable to auto generate archive name for path: %s", baseName ); | 2969 Log.e(TAG, "Unable to auto generate archive name for path: %s", baseName ); |
2922 return null; | 2970 return null; |
2923 } | 2971 } |
2924 | 2972 |
2925 @Override | 2973 @Override |
2926 public void extractSmartClipData(int x, int y, int width, int height) { | 2974 public void extractSmartClipData(int x, int y, int width, int height) { |
2927 if (!isDestroyed(WARN)) mContentViewCore.extractSmartClipData(x, y, widt h, height); | 2975 if (!isDestroyedOrNoOperation(WARN)) { |
2976 mContentViewCore.extractSmartClipData(x, y, width, height); | |
2977 } | |
2928 } | 2978 } |
2929 | 2979 |
2930 @Override | 2980 @Override |
2931 public void setSmartClipResultHandler(final Handler resultHandler) { | 2981 public void setSmartClipResultHandler(final Handler resultHandler) { |
2932 if (isDestroyed(WARN)) return; | 2982 if (isDestroyedOrNoOperation(WARN)) return; |
2933 | 2983 |
2934 if (resultHandler == null) { | 2984 if (resultHandler == null) { |
2935 mContentViewCore.setSmartClipDataListener(null); | 2985 mContentViewCore.setSmartClipDataListener(null); |
2936 return; | 2986 return; |
2937 } | 2987 } |
2938 mContentViewCore.setSmartClipDataListener(new ContentViewCore.SmartClipD ataListener() { | 2988 mContentViewCore.setSmartClipDataListener(new ContentViewCore.SmartClipD ataListener() { |
2939 @Override | 2989 @Override |
2940 public void onSmartClipDataExtracted(String text, String html, Rect clipRect) { | 2990 public void onSmartClipDataExtracted(String text, String html, Rect clipRect) { |
2941 Bundle bundle = new Bundle(); | 2991 Bundle bundle = new Bundle(); |
2942 bundle.putString("url", mContentViewCore.getWebContents().getVis ibleUrl()); | 2992 bundle.putString("url", mContentViewCore.getWebContents().getVis ibleUrl()); |
2943 bundle.putString("title", mContentViewCore.getWebContents().getT itle()); | 2993 bundle.putString("title", mContentViewCore.getWebContents().getT itle()); |
2944 bundle.putParcelable("rect", clipRect); | 2994 bundle.putParcelable("rect", clipRect); |
2945 bundle.putString("text", text); | 2995 bundle.putString("text", text); |
2946 bundle.putString("html", html); | 2996 bundle.putString("html", html); |
2947 try { | 2997 try { |
2948 Message msg = Message.obtain(resultHandler, 0); | 2998 Message msg = Message.obtain(resultHandler, 0); |
2949 msg.setData(bundle); | 2999 msg.setData(bundle); |
2950 msg.sendToTarget(); | 3000 msg.sendToTarget(); |
2951 } catch (Exception e) { | 3001 } catch (Exception e) { |
2952 Log.e(TAG, "Error calling handler for smart clip data: ", e) ; | 3002 Log.e(TAG, "Error calling handler for smart clip data: ", e) ; |
2953 } | 3003 } |
2954 } | 3004 } |
2955 }); | 3005 }); |
2956 } | 3006 } |
2957 | 3007 |
2958 protected void insertVisualStateCallbackIfNotDestroyed( | 3008 protected void insertVisualStateCallbackIfNotDestroyed( |
2959 long requestId, VisualStateCallback callback) { | 3009 long requestId, VisualStateCallback callback) { |
2960 if (TRACE) Log.i(TAG, "%s insertVisualStateCallbackIfNotDestroyed", this ); | 3010 if (TRACE) Log.i(TAG, "%s insertVisualStateCallbackIfNotDestroyed", this ); |
2961 if (isDestroyed(NO_WARN)) return; | 3011 if (isDestroyedOrNoOperation(NO_WARN)) return; |
2962 nativeInsertVisualStateCallback(mNativeAwContents, requestId, callback); | 3012 nativeInsertVisualStateCallback(mNativeAwContents, requestId, callback); |
2963 } | 3013 } |
2964 | 3014 |
2965 // ------------------------------------------------------------------------- ------------------- | 3015 // ------------------------------------------------------------------------- ------------------- |
2966 // This is the AwViewMethods implementation that does real work. The AwViewM ethodsImpl is | 3016 // This is the AwViewMethods implementation that does real work. The AwViewM ethodsImpl is |
2967 // hooked up to the WebView in embedded mode and to the FullScreenView in fu llscreen mode, | 3017 // hooked up to the WebView in embedded mode and to the FullScreenView in fu llscreen mode, |
2968 // but not to both at the same time. | 3018 // but not to both at the same time. |
2969 private class AwViewMethodsImpl implements AwViewMethods { | 3019 private class AwViewMethodsImpl implements AwViewMethods { |
2970 private int mLayerType = View.LAYER_TYPE_NONE; | 3020 private int mLayerType = View.LAYER_TYPE_NONE; |
2971 private ComponentCallbacks2 mComponentCallbacks; | 3021 private ComponentCallbacks2 mComponentCallbacks; |
2972 | 3022 |
2973 // Only valid within software onDraw(). | 3023 // Only valid within software onDraw(). |
2974 private final Rect mClipBoundsTemporary = new Rect(); | 3024 private final Rect mClipBoundsTemporary = new Rect(); |
2975 | 3025 |
2976 @Override | 3026 @Override |
2977 public void onDraw(Canvas canvas) { | 3027 public void onDraw(Canvas canvas) { |
2978 if (isDestroyed(NO_WARN)) { | 3028 if (isDestroyedOrNoOperation(NO_WARN)) { |
2979 TraceEvent.instant("EarlyOut_destroyed"); | 3029 TraceEvent.instant("EarlyOut_destroyed"); |
2980 canvas.drawColor(getEffectiveBackgroundColor()); | 3030 canvas.drawColor(getEffectiveBackgroundColor()); |
2981 return; | 3031 return; |
2982 } | 3032 } |
2983 | 3033 |
2984 // For hardware draws, the clip at onDraw time could be different | 3034 // For hardware draws, the clip at onDraw time could be different |
2985 // from the clip during DrawGL. | 3035 // from the clip during DrawGL. |
2986 if (!canvas.isHardwareAccelerated() && !canvas.getClipBounds(mClipBo undsTemporary)) { | 3036 if (!canvas.isHardwareAccelerated() && !canvas.getClipBounds(mClipBo undsTemporary)) { |
2987 TraceEvent.instant("EarlyOut_software_empty_clip"); | 3037 TraceEvent.instant("EarlyOut_software_empty_clip"); |
2988 return; | 3038 return; |
(...skipping 30 matching lines...) Expand all Loading... | |
3019 } | 3069 } |
3020 } | 3070 } |
3021 | 3071 |
3022 @Override | 3072 @Override |
3023 public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | 3073 public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
3024 mLayoutSizer.onMeasure(widthMeasureSpec, heightMeasureSpec); | 3074 mLayoutSizer.onMeasure(widthMeasureSpec, heightMeasureSpec); |
3025 } | 3075 } |
3026 | 3076 |
3027 @Override | 3077 @Override |
3028 public void requestFocus() { | 3078 public void requestFocus() { |
3029 if (isDestroyed(NO_WARN)) return; | 3079 if (isDestroyedOrNoOperation(NO_WARN)) return; |
3030 if (!mContainerView.isInTouchMode() && mSettings.shouldFocusFirstNod e()) { | 3080 if (!mContainerView.isInTouchMode() && mSettings.shouldFocusFirstNod e()) { |
3031 nativeFocusFirstNode(mNativeAwContents); | 3081 nativeFocusFirstNode(mNativeAwContents); |
3032 } | 3082 } |
3033 } | 3083 } |
3034 | 3084 |
3035 @Override | 3085 @Override |
3036 public void setLayerType(int layerType, Paint paint) { | 3086 public void setLayerType(int layerType, Paint paint) { |
3037 mLayerType = layerType; | 3087 mLayerType = layerType; |
3038 updateHardwareAcceleratedFeaturesToggle(); | 3088 updateHardwareAcceleratedFeaturesToggle(); |
3039 } | 3089 } |
3040 | 3090 |
3041 private void updateHardwareAcceleratedFeaturesToggle() { | 3091 private void updateHardwareAcceleratedFeaturesToggle() { |
3042 mSettings.setEnableSupportedHardwareAcceleratedFeatures( | 3092 mSettings.setEnableSupportedHardwareAcceleratedFeatures( |
3043 mIsAttachedToWindow && mContainerView.isHardwareAccelerated( ) | 3093 mIsAttachedToWindow && mContainerView.isHardwareAccelerated( ) |
3044 && (mLayerType == View.LAYER_TYPE_NONE | 3094 && (mLayerType == View.LAYER_TYPE_NONE |
3045 || mLayerType == View.LAYER_TYPE_HARDWARE)); | 3095 || mLayerType == View.LAYER_TYPE_HARDWARE)); |
3046 } | 3096 } |
3047 | 3097 |
3048 @Override | 3098 @Override |
3049 public InputConnection onCreateInputConnection(EditorInfo outAttrs) { | 3099 public InputConnection onCreateInputConnection(EditorInfo outAttrs) { |
3050 return isDestroyed(NO_WARN) ? null : mContentViewCore.onCreateInputC onnection(outAttrs); | 3100 return isDestroyedOrNoOperation(NO_WARN) ? null |
3101 : mContentViewCore.onCreateInputConnection(outAttrs); | |
3051 } | 3102 } |
3052 | 3103 |
3053 @Override | 3104 @Override |
3054 public boolean onDragEvent(DragEvent event) { | 3105 public boolean onDragEvent(DragEvent event) { |
3055 return mContentViewCore.onDragEvent(event); | 3106 return mContentViewCore.onDragEvent(event); |
3056 } | 3107 } |
3057 | 3108 |
3058 @Override | 3109 @Override |
3059 public boolean onKeyUp(int keyCode, KeyEvent event) { | 3110 public boolean onKeyUp(int keyCode, KeyEvent event) { |
3060 return isDestroyed(NO_WARN) ? false : mContentViewCore.onKeyUp(keyCo de, event); | 3111 return isDestroyedOrNoOperation(NO_WARN) ? false |
3112 : mContentViewCore.onKeyUp(keyCode, event); | |
3061 } | 3113 } |
3062 | 3114 |
3063 @Override | 3115 @Override |
3064 public boolean dispatchKeyEvent(KeyEvent event) { | 3116 public boolean dispatchKeyEvent(KeyEvent event) { |
3065 if (isDestroyed(NO_WARN)) return false; | 3117 if (isDestroyedOrNoOperation(NO_WARN)) return false; |
3066 if (isDpadEvent(event)) { | 3118 if (isDpadEvent(event)) { |
3067 mSettings.setSpatialNavigationEnabled(true); | 3119 mSettings.setSpatialNavigationEnabled(true); |
3068 } | 3120 } |
3069 return mContentViewCore.dispatchKeyEvent(event); | 3121 return mContentViewCore.dispatchKeyEvent(event); |
3070 } | 3122 } |
3071 | 3123 |
3072 private boolean isDpadEvent(KeyEvent event) { | 3124 private boolean isDpadEvent(KeyEvent event) { |
3073 if (event.getAction() == KeyEvent.ACTION_DOWN) { | 3125 if (event.getAction() == KeyEvent.ACTION_DOWN) { |
3074 switch (event.getKeyCode()) { | 3126 switch (event.getKeyCode()) { |
3075 case KeyEvent.KEYCODE_DPAD_CENTER: | 3127 case KeyEvent.KEYCODE_DPAD_CENTER: |
3076 case KeyEvent.KEYCODE_DPAD_DOWN: | 3128 case KeyEvent.KEYCODE_DPAD_DOWN: |
3077 case KeyEvent.KEYCODE_DPAD_UP: | 3129 case KeyEvent.KEYCODE_DPAD_UP: |
3078 case KeyEvent.KEYCODE_DPAD_LEFT: | 3130 case KeyEvent.KEYCODE_DPAD_LEFT: |
3079 case KeyEvent.KEYCODE_DPAD_RIGHT: | 3131 case KeyEvent.KEYCODE_DPAD_RIGHT: |
3080 return true; | 3132 return true; |
3081 } | 3133 } |
3082 } | 3134 } |
3083 return false; | 3135 return false; |
3084 } | 3136 } |
3085 | 3137 |
3086 @Override | 3138 @Override |
3087 public boolean onTouchEvent(MotionEvent event) { | 3139 public boolean onTouchEvent(MotionEvent event) { |
3088 if (isDestroyed(NO_WARN)) return false; | 3140 if (isDestroyedOrNoOperation(NO_WARN)) return false; |
3089 if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { | 3141 if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { |
3090 mSettings.setSpatialNavigationEnabled(false); | 3142 mSettings.setSpatialNavigationEnabled(false); |
3091 } | 3143 } |
3092 | 3144 |
3093 mScrollOffsetManager.setProcessingTouchEvent(true); | 3145 mScrollOffsetManager.setProcessingTouchEvent(true); |
3094 boolean rv = mContentViewCore.onTouchEvent(event); | 3146 boolean rv = mContentViewCore.onTouchEvent(event); |
3095 mScrollOffsetManager.setProcessingTouchEvent(false); | 3147 mScrollOffsetManager.setProcessingTouchEvent(false); |
3096 | 3148 |
3097 if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { | 3149 if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { |
3098 // Note this will trigger IPC back to browser even if nothing is | 3150 // Note this will trigger IPC back to browser even if nothing is |
(...skipping 12 matching lines...) Expand all Loading... | |
3111 mOverScrollGlow.setShouldPull(false); | 3163 mOverScrollGlow.setShouldPull(false); |
3112 mOverScrollGlow.releaseAll(); | 3164 mOverScrollGlow.releaseAll(); |
3113 } | 3165 } |
3114 } | 3166 } |
3115 | 3167 |
3116 return rv; | 3168 return rv; |
3117 } | 3169 } |
3118 | 3170 |
3119 @Override | 3171 @Override |
3120 public boolean onHoverEvent(MotionEvent event) { | 3172 public boolean onHoverEvent(MotionEvent event) { |
3121 return isDestroyed(NO_WARN) ? false : mContentViewCore.onHoverEvent( event); | 3173 return isDestroyedOrNoOperation(NO_WARN) ? false : mContentViewCore. onHoverEvent(event); |
3122 } | 3174 } |
3123 | 3175 |
3124 @Override | 3176 @Override |
3125 public boolean onGenericMotionEvent(MotionEvent event) { | 3177 public boolean onGenericMotionEvent(MotionEvent event) { |
3126 return isDestroyed(NO_WARN) ? false : mContentViewCore.onGenericMoti onEvent(event); | 3178 return isDestroyedOrNoOperation(NO_WARN) ? false |
3179 : mContentViewCore.onGenericMotionEvent(event); | |
3127 } | 3180 } |
3128 | 3181 |
3129 @Override | 3182 @Override |
3130 public void onConfigurationChanged(Configuration newConfig) { | 3183 public void onConfigurationChanged(Configuration newConfig) { |
3131 if (!isDestroyed(NO_WARN)) mContentViewCore.onConfigurationChanged(n ewConfig); | 3184 if (!isDestroyedOrNoOperation(NO_WARN)) { |
3185 mContentViewCore.onConfigurationChanged(newConfig); | |
3186 } | |
3132 } | 3187 } |
3133 | 3188 |
3134 @Override | 3189 @Override |
3135 public void onAttachedToWindow() { | 3190 public void onAttachedToWindow() { |
3136 if (isDestroyed(NO_WARN)) return; | 3191 if (isDestroyedOrNoOperation(NO_WARN)) return; |
3137 if (mIsAttachedToWindow) { | 3192 if (mIsAttachedToWindow) { |
3138 Log.w(TAG, "onAttachedToWindow called when already attached. Ign oring"); | 3193 Log.w(TAG, "onAttachedToWindow called when already attached. Ign oring"); |
3139 return; | 3194 return; |
3140 } | 3195 } |
3141 mIsAttachedToWindow = true; | 3196 mIsAttachedToWindow = true; |
3142 | 3197 |
3143 mContentViewCore.onAttachedToWindow(); | 3198 mContentViewCore.onAttachedToWindow(); |
3144 nativeOnAttachedToWindow(mNativeAwContents, mContainerView.getWidth( ), | 3199 nativeOnAttachedToWindow(mNativeAwContents, mContainerView.getWidth( ), |
3145 mContainerView.getHeight()); | 3200 mContainerView.getHeight()); |
3146 updateHardwareAcceleratedFeaturesToggle(); | 3201 updateHardwareAcceleratedFeaturesToggle(); |
3147 postUpdateContentViewCoreVisibility(); | 3202 postUpdateContentViewCoreVisibility(); |
3148 mCurrentFunctor.onAttachedToWindow(); | 3203 mCurrentFunctor.onAttachedToWindow(); |
3149 | 3204 |
3150 updateDefaultLocale(); | 3205 updateDefaultLocale(); |
3151 mSettings.updateAcceptLanguages(); | 3206 mSettings.updateAcceptLanguages(); |
3152 | 3207 |
3153 if (mComponentCallbacks != null) return; | 3208 if (mComponentCallbacks != null) return; |
3154 mComponentCallbacks = new AwComponentCallbacks(); | 3209 mComponentCallbacks = new AwComponentCallbacks(); |
3155 mContext.registerComponentCallbacks(mComponentCallbacks); | 3210 mContext.registerComponentCallbacks(mComponentCallbacks); |
3156 } | 3211 } |
3157 | 3212 |
3158 @Override | 3213 @Override |
3159 public void onDetachedFromWindow() { | 3214 public void onDetachedFromWindow() { |
3160 if (isDestroyed(NO_WARN)) return; | 3215 if (isDestroyedOrNoOperation(NO_WARN)) return; |
3161 if (!mIsAttachedToWindow) { | 3216 if (!mIsAttachedToWindow) { |
3162 Log.w(TAG, "onDetachedFromWindow called when already detached. I gnoring"); | 3217 Log.w(TAG, "onDetachedFromWindow called when already detached. I gnoring"); |
3163 return; | 3218 return; |
3164 } | 3219 } |
3165 mIsAttachedToWindow = false; | 3220 mIsAttachedToWindow = false; |
3166 hideAutofillPopup(); | 3221 hideAutofillPopup(); |
3167 nativeOnDetachedFromWindow(mNativeAwContents); | 3222 nativeOnDetachedFromWindow(mNativeAwContents); |
3168 | 3223 |
3169 mContentViewCore.onDetachedFromWindow(); | 3224 mContentViewCore.onDetachedFromWindow(); |
3170 updateHardwareAcceleratedFeaturesToggle(); | 3225 updateHardwareAcceleratedFeaturesToggle(); |
3171 postUpdateContentViewCoreVisibility(); | 3226 postUpdateContentViewCoreVisibility(); |
3172 mCurrentFunctor.onDetachedFromWindow(); | 3227 mCurrentFunctor.onDetachedFromWindow(); |
3173 | 3228 |
3174 if (mComponentCallbacks != null) { | 3229 if (mComponentCallbacks != null) { |
3175 mContext.unregisterComponentCallbacks(mComponentCallbacks); | 3230 mContext.unregisterComponentCallbacks(mComponentCallbacks); |
3176 mComponentCallbacks = null; | 3231 mComponentCallbacks = null; |
3177 } | 3232 } |
3178 | 3233 |
3179 mScrollAccessibilityHelper.removePostedCallbacks(); | 3234 mScrollAccessibilityHelper.removePostedCallbacks(); |
3180 mZoomControls.dismissZoomPicker(); | 3235 mZoomControls.dismissZoomPicker(); |
3181 } | 3236 } |
3182 | 3237 |
3183 @Override | 3238 @Override |
3184 public void onWindowFocusChanged(boolean hasWindowFocus) { | 3239 public void onWindowFocusChanged(boolean hasWindowFocus) { |
3185 if (isDestroyed(NO_WARN)) return; | 3240 if (isDestroyedOrNoOperation(NO_WARN)) return; |
3186 mWindowFocused = hasWindowFocus; | 3241 mWindowFocused = hasWindowFocus; |
3187 mContentViewCore.onWindowFocusChanged(hasWindowFocus); | 3242 mContentViewCore.onWindowFocusChanged(hasWindowFocus); |
3188 } | 3243 } |
3189 | 3244 |
3190 @Override | 3245 @Override |
3191 public void onFocusChanged(boolean focused, int direction, Rect previous lyFocusedRect) { | 3246 public void onFocusChanged(boolean focused, int direction, Rect previous lyFocusedRect) { |
3192 if (isDestroyed(NO_WARN)) return; | 3247 if (isDestroyedOrNoOperation(NO_WARN)) return; |
3193 mContainerViewFocused = focused; | 3248 mContainerViewFocused = focused; |
3194 mContentViewCore.onFocusChanged(focused); | 3249 mContentViewCore.onFocusChanged(focused); |
3195 } | 3250 } |
3196 | 3251 |
3197 @Override | 3252 @Override |
3198 public void onSizeChanged(int w, int h, int ow, int oh) { | 3253 public void onSizeChanged(int w, int h, int ow, int oh) { |
3199 if (isDestroyed(NO_WARN)) return; | 3254 if (isDestroyedOrNoOperation(NO_WARN)) return; |
3200 mScrollOffsetManager.setContainerViewSize(w, h); | 3255 mScrollOffsetManager.setContainerViewSize(w, h); |
3201 // The AwLayoutSizer needs to go first so that if we're in | 3256 // The AwLayoutSizer needs to go first so that if we're in |
3202 // fixedLayoutSize mode the update | 3257 // fixedLayoutSize mode the update |
3203 // to enter fixedLayoutSize mode is sent before the first resize | 3258 // to enter fixedLayoutSize mode is sent before the first resize |
3204 // update. | 3259 // update. |
3205 mLayoutSizer.onSizeChanged(w, h, ow, oh); | 3260 mLayoutSizer.onSizeChanged(w, h, ow, oh); |
3206 mContentViewCore.onPhysicalBackingSizeChanged(w, h); | 3261 mContentViewCore.onPhysicalBackingSizeChanged(w, h); |
3207 mContentViewCore.onSizeChanged(w, h, ow, oh); | 3262 mContentViewCore.onSizeChanged(w, h, ow, oh); |
3208 nativeOnSizeChanged(mNativeAwContents, w, h, ow, oh); | 3263 nativeOnSizeChanged(mNativeAwContents, w, h, ow, oh); |
3209 } | 3264 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3267 return mScrollOffsetManager.computeVerticalScrollOffset(); | 3322 return mScrollOffsetManager.computeVerticalScrollOffset(); |
3268 } | 3323 } |
3269 | 3324 |
3270 @Override | 3325 @Override |
3271 public int computeVerticalScrollExtent() { | 3326 public int computeVerticalScrollExtent() { |
3272 return mScrollOffsetManager.computeVerticalScrollExtent(); | 3327 return mScrollOffsetManager.computeVerticalScrollExtent(); |
3273 } | 3328 } |
3274 | 3329 |
3275 @Override | 3330 @Override |
3276 public void computeScroll() { | 3331 public void computeScroll() { |
3277 if (isDestroyed(NO_WARN)) return; | 3332 if (isDestroyedOrNoOperation(NO_WARN)) return; |
3278 nativeOnComputeScroll(mNativeAwContents, AnimationUtils.currentAnima tionTimeMillis()); | 3333 nativeOnComputeScroll(mNativeAwContents, AnimationUtils.currentAnima tionTimeMillis()); |
3279 } | 3334 } |
3280 } | 3335 } |
3281 | 3336 |
3282 // Return true if the GeolocationPermissionAPI should be used. | 3337 // Return true if the GeolocationPermissionAPI should be used. |
3283 @CalledByNative | 3338 @CalledByNative |
3284 private boolean useLegacyGeolocationPermissionAPI() { | 3339 private boolean useLegacyGeolocationPermissionAPI() { |
3285 // Always return true since we are not ready to swap the geolocation yet . | 3340 // Always return true since we are not ready to swap the geolocation yet . |
3286 // TODO: If we decide not to migrate the geolocation, there are some unr eachable | 3341 // TODO: If we decide not to migrate the geolocation, there are some unr eachable |
3287 // code need to remove. http://crbug.com/396184. | 3342 // code need to remove. http://crbug.com/396184. |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3376 | 3431 |
3377 private native void nativePostMessageToFrame(long nativeAwContents, String f rameId, | 3432 private native void nativePostMessageToFrame(long nativeAwContents, String f rameId, |
3378 String message, String targetOrigin, int[] msgPorts); | 3433 String message, String targetOrigin, int[] msgPorts); |
3379 | 3434 |
3380 private native void nativeCreateMessageChannel( | 3435 private native void nativeCreateMessageChannel( |
3381 long nativeAwContents, AppWebMessagePort[] ports); | 3436 long nativeAwContents, AppWebMessagePort[] ports); |
3382 | 3437 |
3383 private native void nativeGrantFileSchemeAccesstoChildProcess(long nativeAwC ontents); | 3438 private native void nativeGrantFileSchemeAccesstoChildProcess(long nativeAwC ontents); |
3384 private native void nativeResumeLoadingCreatedPopupWebContents(long nativeAw Contents); | 3439 private native void nativeResumeLoadingCreatedPopupWebContents(long nativeAw Contents); |
3385 } | 3440 } |
OLD | NEW |