Chromium Code Reviews| 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.app.Activity; | 8 import android.app.Activity; |
| 9 import android.content.ComponentCallbacks2; | 9 import android.content.ComponentCallbacks2; |
| 10 import android.content.Context; | 10 import android.content.Context; |
| (...skipping 954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 965 mContentViewCore = createAndInitializeContentViewCore(mContainerView, mC ontext, | 965 mContentViewCore = createAndInitializeContentViewCore(mContainerView, mC ontext, |
| 966 mInternalAccessAdapter, webContents, new AwGestureStateListener( ), | 966 mInternalAccessAdapter, webContents, new AwGestureStateListener( ), |
| 967 mContentViewClient, mZoomControls, mWindowAndroid.getWindowAndro id()); | 967 mContentViewClient, mZoomControls, mWindowAndroid.getWindowAndro id()); |
| 968 nativeSetJavaPeers(mNativeAwContents, this, mWebContentsDelegate, mConte ntsClientBridge, | 968 nativeSetJavaPeers(mNativeAwContents, this, mWebContentsDelegate, mConte ntsClientBridge, |
| 969 mIoThreadClient, mInterceptNavigationDelegate); | 969 mIoThreadClient, mInterceptNavigationDelegate); |
| 970 mWebContents = mContentViewCore.getWebContents(); | 970 mWebContents = mContentViewCore.getWebContents(); |
| 971 mNavigationController = mWebContents.getNavigationController(); | 971 mNavigationController = mWebContents.getNavigationController(); |
| 972 installWebContentsObserver(); | 972 installWebContentsObserver(); |
| 973 mSettings.setWebContents(webContents); | 973 mSettings.setWebContents(webContents); |
| 974 nativeSetDipScale(mNativeAwContents, (float) mDIPScale); | 974 nativeSetDipScale(mNativeAwContents, (float) mDIPScale); |
| 975 updateContentViewCoreVisibility(); | 975 postUpdateContentViewCoreVisibility(); |
| 976 | 976 |
| 977 // The native side object has been bound to this java instance, so now i s the time to | 977 // The native side object has been bound to this java instance, so now i s the time to |
| 978 // bind all the native->java relationships. | 978 // bind all the native->java relationships. |
| 979 mCleanupReference = | 979 mCleanupReference = |
| 980 new CleanupReference(this, new DestroyRunnable(mNativeAwContents )); | 980 new CleanupReference(this, new DestroyRunnable(mNativeAwContents )); |
| 981 } | 981 } |
| 982 | 982 |
| 983 private void installWebContentsObserver() { | 983 private void installWebContentsObserver() { |
| 984 if (mWebContentsObserver != null) { | 984 if (mWebContentsObserver != null) { |
| 985 mWebContentsObserver.destroy(); | 985 mWebContentsObserver.destroy(); |
| (...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1791 } | 1791 } |
| 1792 | 1792 |
| 1793 /** | 1793 /** |
| 1794 * @see android.webkit.WebView#onPause() | 1794 * @see android.webkit.WebView#onPause() |
| 1795 */ | 1795 */ |
| 1796 public void onPause() { | 1796 public void onPause() { |
| 1797 if (TRACE) Log.d(TAG, "onPause"); | 1797 if (TRACE) Log.d(TAG, "onPause"); |
| 1798 if (mIsPaused || isDestroyed(NO_WARN)) return; | 1798 if (mIsPaused || isDestroyed(NO_WARN)) return; |
| 1799 mIsPaused = true; | 1799 mIsPaused = true; |
| 1800 nativeSetIsPaused(mNativeAwContents, mIsPaused); | 1800 nativeSetIsPaused(mNativeAwContents, mIsPaused); |
| 1801 updateContentViewCoreVisibility(); | 1801 postUpdateContentViewCoreVisibility(); |
| 1802 } | 1802 } |
| 1803 | 1803 |
| 1804 /** | 1804 /** |
| 1805 * @see android.webkit.WebView#onResume() | 1805 * @see android.webkit.WebView#onResume() |
| 1806 */ | 1806 */ |
| 1807 public void onResume() { | 1807 public void onResume() { |
| 1808 if (TRACE) Log.d(TAG, "onResume"); | 1808 if (TRACE) Log.d(TAG, "onResume"); |
| 1809 if (!mIsPaused || isDestroyed(NO_WARN)) return; | 1809 if (!mIsPaused || isDestroyed(NO_WARN)) return; |
| 1810 mIsPaused = false; | 1810 mIsPaused = false; |
| 1811 nativeSetIsPaused(mNativeAwContents, mIsPaused); | 1811 nativeSetIsPaused(mNativeAwContents, mIsPaused); |
| 1812 updateContentViewCoreVisibility(); | 1812 postUpdateContentViewCoreVisibility(); |
| 1813 } | 1813 } |
| 1814 | 1814 |
| 1815 /** | 1815 /** |
| 1816 * @see android.webkit.WebView#isPaused() | 1816 * @see android.webkit.WebView#isPaused() |
| 1817 */ | 1817 */ |
| 1818 public boolean isPaused() { | 1818 public boolean isPaused() { |
| 1819 return isDestroyed(WARN) ? false : mIsPaused; | 1819 return isDestroyed(WARN) ? false : mIsPaused; |
| 1820 } | 1820 } |
| 1821 | 1821 |
| 1822 /** | 1822 /** |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2341 /** | 2341 /** |
| 2342 * @see android.view.View#onWindowVisibilityChanged() | 2342 * @see android.view.View#onWindowVisibilityChanged() |
| 2343 */ | 2343 */ |
| 2344 public void onWindowVisibilityChanged(int visibility) { | 2344 public void onWindowVisibilityChanged(int visibility) { |
| 2345 mAwViewMethods.onWindowVisibilityChanged(visibility); | 2345 mAwViewMethods.onWindowVisibilityChanged(visibility); |
| 2346 } | 2346 } |
| 2347 | 2347 |
| 2348 private void setViewVisibilityInternal(boolean visible) { | 2348 private void setViewVisibilityInternal(boolean visible) { |
| 2349 mIsViewVisible = visible; | 2349 mIsViewVisible = visible; |
| 2350 if (!isDestroyed(NO_WARN)) nativeSetViewVisibility(mNativeAwContents, mI sViewVisible); | 2350 if (!isDestroyed(NO_WARN)) nativeSetViewVisibility(mNativeAwContents, mI sViewVisible); |
| 2351 updateContentViewCoreVisibility(); | 2351 postUpdateContentViewCoreVisibility(); |
| 2352 } | 2352 } |
| 2353 | 2353 |
| 2354 private void setWindowVisibilityInternal(boolean visible) { | 2354 private void setWindowVisibilityInternal(boolean visible) { |
| 2355 mInvalidateRootViewOnNextDraw |= Build.VERSION.SDK_INT <= Build.VERSION_ CODES.LOLLIPOP | 2355 mInvalidateRootViewOnNextDraw |= Build.VERSION.SDK_INT <= Build.VERSION_ CODES.LOLLIPOP |
| 2356 && visible && !mIsWindowVisible; | 2356 && visible && !mIsWindowVisible; |
| 2357 mIsWindowVisible = visible; | 2357 mIsWindowVisible = visible; |
| 2358 if (!isDestroyed(NO_WARN)) nativeSetWindowVisibility(mNativeAwContents, mIsWindowVisible); | 2358 if (!isDestroyed(NO_WARN)) nativeSetWindowVisibility(mNativeAwContents, mIsWindowVisible); |
| 2359 updateContentViewCoreVisibility(); | 2359 postUpdateContentViewCoreVisibility(); |
| 2360 } | |
| 2361 | |
| 2362 private void postUpdateContentViewCoreVisibility() { | |
| 2363 // When WebView is attached to a visible window, WebView will be | |
| 2364 // attached to a window whose visibility is initially invisible, then | |
| 2365 // the window visibility will be updated to true. This means CVC | |
| 2366 // visibility will be set to false then true immediately, in the same | |
| 2367 // function call of View#dispatchAttachedToWindow. To prevent this flip | |
| 2368 // of CVC visibility, post the task to update CVC visibility. | |
| 2369 mHandler.post(new Runnable() { | |
|
boliu
2015/11/03 22:05:46
Can you not post more than you need to?
Also don'
| |
| 2370 @Override | |
| 2371 public void run() { | |
| 2372 updateContentViewCoreVisibility(); | |
| 2373 } | |
| 2374 }); | |
| 2360 } | 2375 } |
| 2361 | 2376 |
| 2362 private void updateContentViewCoreVisibility() { | 2377 private void updateContentViewCoreVisibility() { |
| 2363 if (isDestroyed(NO_WARN)) return; | 2378 if (isDestroyed(NO_WARN)) return; |
| 2364 boolean contentViewCoreVisible = nativeIsVisible(mNativeAwContents); | 2379 boolean contentViewCoreVisible = nativeIsVisible(mNativeAwContents); |
| 2365 | 2380 |
| 2366 if (contentViewCoreVisible && !mIsContentViewCoreVisible) { | 2381 if (contentViewCoreVisible && !mIsContentViewCoreVisible) { |
| 2367 mContentViewCore.onShow(); | 2382 mContentViewCore.onShow(); |
| 2368 } else if (!contentViewCoreVisible && mIsContentViewCoreVisible) { | 2383 } else if (!contentViewCoreVisible && mIsContentViewCoreVisible) { |
| 2369 mContentViewCore.onHide(); | 2384 mContentViewCore.onHide(); |
| (...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2998 if (mIsAttachedToWindow) { | 3013 if (mIsAttachedToWindow) { |
| 2999 Log.w(TAG, "onAttachedToWindow called when already attached. Ign oring"); | 3014 Log.w(TAG, "onAttachedToWindow called when already attached. Ign oring"); |
| 3000 return; | 3015 return; |
| 3001 } | 3016 } |
| 3002 mIsAttachedToWindow = true; | 3017 mIsAttachedToWindow = true; |
| 3003 | 3018 |
| 3004 mContentViewCore.onAttachedToWindow(); | 3019 mContentViewCore.onAttachedToWindow(); |
| 3005 nativeOnAttachedToWindow(mNativeAwContents, mContainerView.getWidth( ), | 3020 nativeOnAttachedToWindow(mNativeAwContents, mContainerView.getWidth( ), |
| 3006 mContainerView.getHeight()); | 3021 mContainerView.getHeight()); |
| 3007 updateHardwareAcceleratedFeaturesToggle(); | 3022 updateHardwareAcceleratedFeaturesToggle(); |
| 3023 postUpdateContentViewCoreVisibility(); | |
| 3008 | 3024 |
| 3009 setLocale(LocaleUtils.getDefaultLocale()); | 3025 setLocale(LocaleUtils.getDefaultLocale()); |
| 3010 | 3026 |
| 3011 if (mComponentCallbacks != null) return; | 3027 if (mComponentCallbacks != null) return; |
| 3012 mComponentCallbacks = new AwComponentCallbacks(); | 3028 mComponentCallbacks = new AwComponentCallbacks(); |
| 3013 mContext.registerComponentCallbacks(mComponentCallbacks); | 3029 mContext.registerComponentCallbacks(mComponentCallbacks); |
| 3014 } | 3030 } |
| 3015 | 3031 |
| 3016 @Override | 3032 @Override |
| 3017 public void onDetachedFromWindow() { | 3033 public void onDetachedFromWindow() { |
| 3018 if (isDestroyed(NO_WARN)) return; | 3034 if (isDestroyed(NO_WARN)) return; |
| 3019 if (!mIsAttachedToWindow) { | 3035 if (!mIsAttachedToWindow) { |
| 3020 Log.w(TAG, "onDetachedFromWindow called when already detached. I gnoring"); | 3036 Log.w(TAG, "onDetachedFromWindow called when already detached. I gnoring"); |
| 3021 return; | 3037 return; |
| 3022 } | 3038 } |
| 3023 mIsAttachedToWindow = false; | 3039 mIsAttachedToWindow = false; |
| 3024 hideAutofillPopup(); | 3040 hideAutofillPopup(); |
| 3025 nativeOnDetachedFromWindow(mNativeAwContents); | 3041 nativeOnDetachedFromWindow(mNativeAwContents); |
| 3026 | 3042 |
| 3027 mContentViewCore.onDetachedFromWindow(); | 3043 mContentViewCore.onDetachedFromWindow(); |
| 3028 updateHardwareAcceleratedFeaturesToggle(); | 3044 updateHardwareAcceleratedFeaturesToggle(); |
| 3045 postUpdateContentViewCoreVisibility(); | |
| 3029 | 3046 |
| 3030 if (mComponentCallbacks != null) { | 3047 if (mComponentCallbacks != null) { |
| 3031 mContext.unregisterComponentCallbacks(mComponentCallbacks); | 3048 mContext.unregisterComponentCallbacks(mComponentCallbacks); |
| 3032 mComponentCallbacks = null; | 3049 mComponentCallbacks = null; |
| 3033 } | 3050 } |
| 3034 | 3051 |
| 3035 mScrollAccessibilityHelper.removePostedCallbacks(); | 3052 mScrollAccessibilityHelper.removePostedCallbacks(); |
| 3036 } | 3053 } |
| 3037 | 3054 |
| 3038 @Override | 3055 @Override |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3229 private native void nativePreauthorizePermission(long nativeAwContents, Stri ng origin, | 3246 private native void nativePreauthorizePermission(long nativeAwContents, Stri ng origin, |
| 3230 long resources); | 3247 long resources); |
| 3231 | 3248 |
| 3232 private native void nativePostMessageToFrame(long nativeAwContents, String f rameId, | 3249 private native void nativePostMessageToFrame(long nativeAwContents, String f rameId, |
| 3233 String message, String targetOrigin, int[] msgPorts); | 3250 String message, String targetOrigin, int[] msgPorts); |
| 3234 | 3251 |
| 3235 private native void nativeCreateMessageChannel(long nativeAwContents, AwMess agePort[] ports); | 3252 private native void nativeCreateMessageChannel(long nativeAwContents, AwMess agePort[] ports); |
| 3236 | 3253 |
| 3237 private native void nativeGrantFileSchemeAccesstoChildProcess(long nativeAwC ontents); | 3254 private native void nativeGrantFileSchemeAccesstoChildProcess(long nativeAwC ontents); |
| 3238 } | 3255 } |
| OLD | NEW |