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.content.pm.PackageManager; | 7 import android.content.pm.PackageManager; |
8 import android.content.res.Configuration; | 8 import android.content.res.Configuration; |
9 import android.graphics.Bitmap; | 9 import android.graphics.Bitmap; |
10 import android.graphics.Canvas; | 10 import android.graphics.Canvas; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 private final AwContentsIoThreadClient mIoThreadClient; | 126 private final AwContentsIoThreadClient mIoThreadClient; |
127 private final InterceptNavigationDelegateImpl mInterceptNavigationDelegate; | 127 private final InterceptNavigationDelegateImpl mInterceptNavigationDelegate; |
128 private final InternalAccessDelegate mInternalAccessAdapter; | 128 private final InternalAccessDelegate mInternalAccessAdapter; |
129 private final AwLayoutSizer mLayoutSizer; | 129 private final AwLayoutSizer mLayoutSizer; |
130 private final AwScrollOffsetManager mScrollOffsetManager; | 130 private final AwScrollOffsetManager mScrollOffsetManager; |
131 private final AwZoomControls mZoomControls; | 131 private final AwZoomControls mZoomControls; |
132 // This can be accessed on any thread after construction. See AwContentsIoTh
readClient. | 132 // This can be accessed on any thread after construction. See AwContentsIoTh
readClient. |
133 private final AwSettings mSettings; | 133 private final AwSettings mSettings; |
134 | 134 |
135 private boolean mIsPaused; | 135 private boolean mIsPaused; |
| 136 private boolean mIsVisible; // Equivalent to windowVisible && viewVisible &
& !mIsPaused. |
136 private Bitmap mFavicon; | 137 private Bitmap mFavicon; |
137 private boolean mHasRequestedVisitedHistoryFromClient; | 138 private boolean mHasRequestedVisitedHistoryFromClient; |
138 // TODO(boliu): This should be in a global context, not per webview. | 139 // TODO(boliu): This should be in a global context, not per webview. |
139 private final double mDIPScale; | 140 private final double mDIPScale; |
140 | 141 |
141 // Must call nativeUpdateLastHitTestData first to update this before use. | 142 // Must call nativeUpdateLastHitTestData first to update this before use. |
142 private final HitTestData mPossiblyStaleHitTestData = new HitTestData(); | 143 private final HitTestData mPossiblyStaleHitTestData = new HitTestData(); |
143 | 144 |
144 private DefaultVideoPosterRequestHandler mDefaultVideoPosterRequestHandler; | 145 private DefaultVideoPosterRequestHandler mDefaultVideoPosterRequestHandler; |
145 | 146 |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 | 480 |
480 // Recap: supplyContentsForPopup() is called on the parent window's content,
this method is | 481 // Recap: supplyContentsForPopup() is called on the parent window's content,
this method is |
481 // called on the popup window's content. | 482 // called on the popup window's content. |
482 private void receivePopupContents(int popupNativeAwContents) { | 483 private void receivePopupContents(int popupNativeAwContents) { |
483 setNewAwContents(popupNativeAwContents); | 484 setNewAwContents(popupNativeAwContents); |
484 | 485 |
485 // Finally refresh view size and visibility, to poke new values into Con
tentViewCore. | 486 // Finally refresh view size and visibility, to poke new values into Con
tentViewCore. |
486 mLastGlobalVisibleWidth = 0; | 487 mLastGlobalVisibleWidth = 0; |
487 mLastGlobalVisibleHeight = 0; | 488 mLastGlobalVisibleHeight = 0; |
488 onSizeChanged(mContainerView.getWidth(), mContainerView.getHeight(), 0,
0); | 489 onSizeChanged(mContainerView.getWidth(), mContainerView.getHeight(), 0,
0); |
489 updateVisiblityState(); | 490 updateVisibilityStateForced(); |
490 onWindowFocusChanged(mWindowFocused); | 491 onWindowFocusChanged(mWindowFocused); |
491 } | 492 } |
492 | 493 |
493 public void destroy() { | 494 public void destroy() { |
494 mContentViewCore.destroy(); | 495 mContentViewCore.destroy(); |
495 // We explicitly do not null out the mContentViewCore reference here | 496 // We explicitly do not null out the mContentViewCore reference here |
496 // because ContentViewCore already has code to deal with the case | 497 // because ContentViewCore already has code to deal with the case |
497 // methods are called on it after it's been destroyed, and other | 498 // methods are called on it after it's been destroyed, and other |
498 // code relies on AwContents.mContentViewCore to be non-null. | 499 // code relies on AwContents.mContentViewCore to be non-null. |
499 | 500 |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 // TODO(kristianm): Remove | 847 // TODO(kristianm): Remove |
847 public void resumeTimers() { | 848 public void resumeTimers() { |
848 ContentViewStatics.setWebKitSharedTimersSuspended(false); | 849 ContentViewStatics.setWebKitSharedTimersSuspended(false); |
849 } | 850 } |
850 | 851 |
851 /** | 852 /** |
852 * @see android.webkit.WebView#onPause() | 853 * @see android.webkit.WebView#onPause() |
853 */ | 854 */ |
854 public void onPause() { | 855 public void onPause() { |
855 mIsPaused = true; | 856 mIsPaused = true; |
856 mContentViewCore.onHide(); | 857 updateVisibilityState(); |
857 } | 858 } |
858 | 859 |
859 /** | 860 /** |
860 * @see android.webkit.WebView#onResume() | 861 * @see android.webkit.WebView#onResume() |
861 */ | 862 */ |
862 public void onResume() { | 863 public void onResume() { |
863 mContentViewCore.onShow(); | |
864 mIsPaused = false; | 864 mIsPaused = false; |
| 865 updateVisibilityState(); |
865 } | 866 } |
866 | 867 |
867 /** | 868 /** |
868 * @see android.webkit.WebView#isPaused() | 869 * @see android.webkit.WebView#isPaused() |
869 */ | 870 */ |
870 public boolean isPaused() { | 871 public boolean isPaused() { |
871 return mIsPaused; | 872 return mIsPaused; |
872 } | 873 } |
873 | 874 |
874 /** | 875 /** |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1194 if (mNativeAwContents == 0) return; | 1195 if (mNativeAwContents == 0) return; |
1195 updatePhysicalBackingSizeIfNeeded(); | 1196 updatePhysicalBackingSizeIfNeeded(); |
1196 mContentViewCore.onSizeChanged(w, h, ow, oh); | 1197 mContentViewCore.onSizeChanged(w, h, ow, oh); |
1197 nativeOnSizeChanged(mNativeAwContents, w, h, ow, oh); | 1198 nativeOnSizeChanged(mNativeAwContents, w, h, ow, oh); |
1198 } | 1199 } |
1199 | 1200 |
1200 /** | 1201 /** |
1201 * @see android.view.View#onVisibilityChanged() | 1202 * @see android.view.View#onVisibilityChanged() |
1202 */ | 1203 */ |
1203 public void onVisibilityChanged(View changedView, int visibility) { | 1204 public void onVisibilityChanged(View changedView, int visibility) { |
1204 updateVisiblityState(); | 1205 updateVisibilityState(); |
1205 } | 1206 } |
1206 | 1207 |
1207 /** | 1208 /** |
1208 * @see android.view.View#onWindowVisibilityChanged() | 1209 * @see android.view.View#onWindowVisibilityChanged() |
1209 */ | 1210 */ |
1210 public void onWindowVisibilityChanged(int visibility) { | 1211 public void onWindowVisibilityChanged(int visibility) { |
1211 updateVisiblityState(); | 1212 updateVisibilityState(); |
1212 } | 1213 } |
1213 | 1214 |
1214 private void updateVisiblityState() { | 1215 private void updateVisibilityState() { |
1215 if (mNativeAwContents == 0 || mIsPaused) return; | 1216 doUpdateVisibilityState(false); |
| 1217 } |
| 1218 |
| 1219 private void updateVisibilityStateForced() { |
| 1220 doUpdateVisibilityState(true); |
| 1221 } |
| 1222 |
| 1223 private void doUpdateVisibilityState(boolean forced) { |
| 1224 if (mNativeAwContents == 0) return; |
1216 boolean windowVisible = mContainerView.getWindowVisibility() == View.VIS
IBLE; | 1225 boolean windowVisible = mContainerView.getWindowVisibility() == View.VIS
IBLE; |
1217 boolean viewVisible = mContainerView.getVisibility() == View.VISIBLE; | 1226 boolean viewVisible = mContainerView.getVisibility() == View.VISIBLE; |
1218 nativeSetWindowViewVisibility(mNativeAwContents, windowVisible, viewVisi
ble); | |
1219 | 1227 |
1220 if (viewVisible) { | 1228 boolean visible = windowVisible && viewVisible && !mIsPaused; |
1221 mContentViewCore.onShow(); | 1229 if (mIsVisible == visible && !forced) return; |
| 1230 |
| 1231 mIsVisible = visible; |
| 1232 if (mIsVisible) { |
| 1233 mContentViewCore.onShow(); |
1222 } else { | 1234 } else { |
1223 mContentViewCore.onHide(); | 1235 mContentViewCore.onHide(); |
1224 } | 1236 } |
| 1237 nativeSetVisibility(mNativeAwContents, mIsVisible); |
1225 } | 1238 } |
1226 | 1239 |
1227 | 1240 |
1228 /** | 1241 /** |
1229 * Key for opaque state in bundle. Note this is only public for tests. | 1242 * Key for opaque state in bundle. Note this is only public for tests. |
1230 */ | 1243 */ |
1231 public static final String SAVE_RESTORE_STATE_KEY = "WEBVIEW_CHROMIUM_STATE"
; | 1244 public static final String SAVE_RESTORE_STATE_KEY = "WEBVIEW_CHROMIUM_STATE"
; |
1232 | 1245 |
1233 /** | 1246 /** |
1234 * Save the state of this AwContents into provided Bundle. | 1247 * Save the state of this AwContents into provided Bundle. |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1526 private native void nativeClearMatches(int nativeAwContents); | 1539 private native void nativeClearMatches(int nativeAwContents); |
1527 private native void nativeClearCache(int nativeAwContents, boolean includeDi
skFiles); | 1540 private native void nativeClearCache(int nativeAwContents, boolean includeDi
skFiles); |
1528 private native byte[] nativeGetCertificate(int nativeAwContents); | 1541 private native byte[] nativeGetCertificate(int nativeAwContents); |
1529 | 1542 |
1530 // Coordinates in desity independent pixels. | 1543 // Coordinates in desity independent pixels. |
1531 private native void nativeRequestNewHitTestDataAt(int nativeAwContents, int
x, int y); | 1544 private native void nativeRequestNewHitTestDataAt(int nativeAwContents, int
x, int y); |
1532 private native void nativeUpdateLastHitTestData(int nativeAwContents); | 1545 private native void nativeUpdateLastHitTestData(int nativeAwContents); |
1533 | 1546 |
1534 private native void nativeOnSizeChanged(int nativeAwContents, int w, int h,
int ow, int oh); | 1547 private native void nativeOnSizeChanged(int nativeAwContents, int w, int h,
int ow, int oh); |
1535 private native void nativeScrollTo(int nativeAwContents, int x, int y); | 1548 private native void nativeScrollTo(int nativeAwContents, int x, int y); |
1536 private native void nativeSetWindowViewVisibility(int nativeAwContents, bool
ean windowVisible, | 1549 private native void nativeSetVisibility(int nativeAwContents, boolean visibl
e); |
1537 boolean viewVisible); | |
1538 private native void nativeOnAttachedToWindow(int nativeAwContents, int w, in
t h); | 1550 private native void nativeOnAttachedToWindow(int nativeAwContents, int w, in
t h); |
1539 private native void nativeOnDetachedFromWindow(int nativeAwContents); | 1551 private native void nativeOnDetachedFromWindow(int nativeAwContents); |
1540 private native void nativeSetDipScale(int nativeAwContents, float dipScale); | 1552 private native void nativeSetDipScale(int nativeAwContents, float dipScale); |
1541 | 1553 |
1542 // Returns null if save state fails. | 1554 // Returns null if save state fails. |
1543 private native byte[] nativeGetOpaqueState(int nativeAwContents); | 1555 private native byte[] nativeGetOpaqueState(int nativeAwContents); |
1544 | 1556 |
1545 // Returns false if restore state fails. | 1557 // Returns false if restore state fails. |
1546 private native boolean nativeRestoreFromOpaqueState(int nativeAwContents, by
te[] state); | 1558 private native boolean nativeRestoreFromOpaqueState(int nativeAwContents, by
te[] state); |
1547 | 1559 |
1548 private native int nativeReleasePopupAwContents(int nativeAwContents); | 1560 private native int nativeReleasePopupAwContents(int nativeAwContents); |
1549 private native void nativeFocusFirstNode(int nativeAwContents); | 1561 private native void nativeFocusFirstNode(int nativeAwContents); |
1550 | 1562 |
1551 private native int nativeGetAwDrawGLViewContext(int nativeAwContents); | 1563 private native int nativeGetAwDrawGLViewContext(int nativeAwContents); |
1552 private native Picture nativeCapturePicture(int nativeAwContents); | 1564 private native Picture nativeCapturePicture(int nativeAwContents); |
1553 private native void nativeEnableOnNewPicture(int nativeAwContents, boolean e
nabled); | 1565 private native void nativeEnableOnNewPicture(int nativeAwContents, boolean e
nabled); |
1554 | 1566 |
1555 private native void nativeInvokeGeolocationCallback( | 1567 private native void nativeInvokeGeolocationCallback( |
1556 int nativeAwContents, boolean value, String requestingFrame); | 1568 int nativeAwContents, boolean value, String requestingFrame); |
1557 } | 1569 } |
OLD | NEW |