| Index: android_webview/java/src/org/chromium/android_webview/AwContents.java
|
| diff --git a/android_webview/java/src/org/chromium/android_webview/AwContents.java b/android_webview/java/src/org/chromium/android_webview/AwContents.java
|
| index 9ebbb5b57ef8576cac1111b73192d98c93ad29ca..95ef94d1a9e1d92b56eab66af4cf7cd624b2090c 100644
|
| --- a/android_webview/java/src/org/chromium/android_webview/AwContents.java
|
| +++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java
|
| @@ -80,6 +80,7 @@ import org.chromium.ui.base.ActivityWindowAndroid;
|
| import org.chromium.ui.base.PageTransition;
|
| import org.chromium.ui.base.ViewAndroidDelegate;
|
| import org.chromium.ui.base.WindowAndroid;
|
| +import org.chromium.ui.display.DisplayAndroid;
|
| import org.chromium.ui.display.DisplayAndroid.DisplayAndroidObserver;
|
|
|
| import java.io.File;
|
| @@ -119,6 +120,8 @@ public class AwContents implements SmartClipProvider {
|
| private static final boolean FORCE_AUXILIARY_BITMAP_RENDERING =
|
| "goldfish".equals(Build.HARDWARE) || "ranchu".equals(Build.HARDWARE);
|
|
|
| + private static final double MIN_SCREEN_PERCENTAGE_FOR_INTERSTITIAL = 0.7;
|
| +
|
| /**
|
| * WebKit hit test related data structure. These are used to implement
|
| * getHitTestResult, requestFocusNodeHref, requestImageRef methods in WebView.
|
| @@ -2913,20 +2916,52 @@ public class AwContents implements SmartClipProvider {
|
| }
|
| }
|
|
|
| - @CalledByNative
|
| - private boolean canShowInterstitial() {
|
| + /**
|
| + * Determine if at least one edge of the WebView extends over the edge of the device screen.
|
| + */
|
| + private boolean extendsOffDeviceScreen() {
|
| int loc[] = new int[2];
|
| mContainerView.getLocationOnScreen(loc);
|
| - // TODO(sgurun) implement a better strategy here.
|
| - if (mContainerView.getWidth() < 500 || mContainerView.getHeight() < 500) {
|
| - return false;
|
| + int x = loc[0];
|
| + int y = loc[1];
|
| + DisplayAndroid displayAndroid = mWindowAndroid.getWindowAndroid().getDisplay();
|
| + if (x < 0 || y < 0 || x + mContainerView.getWidth() > displayAndroid.getDisplayWidth()
|
| + || y + mContainerView.getHeight() > displayAndroid.getDisplayHeight()) {
|
| + return true;
|
| }
|
| - if (mContainerView.getVisibility() != View.VISIBLE) {
|
| - return false;
|
| - }
|
| - // TODO(timvolodine) other potential improvements mentioned:
|
| - // consider content, not attached webviews, giant webviews, ..
|
| - return true;
|
| + return false;
|
| + }
|
| +
|
| + /**
|
| + * Determine if it's reasonable to show any sort of interstitial. If the WebView is not visible,
|
| + * the user may not be able to interact with the UI.
|
| + * @return true if the WebView is visible
|
| + */
|
| + @VisibleForTesting
|
| + protected boolean canShowInterstitial() {
|
| + return mIsAttachedToWindow && mIsViewVisible;
|
| + }
|
| +
|
| + /**
|
| + * Determine if it's suitable to show the interstitial for browsers and main UIs. If the WebView
|
| + * is close to full-screen, we assume the app is using it as the main UI, so we show the same
|
| + * interstital Chrome uses. Otherwise, we assume the WebView is part of a larger composed page,
|
| + * and will show a different interstitial.
|
| + * @return true if the WebView should display the large interstitial
|
| + */
|
| + @VisibleForTesting
|
| + @CalledByNative
|
| + protected boolean canShowBigInterstitial() {
|
| + if (!canShowInterstitial()) return false;
|
| + if (extendsOffDeviceScreen()) return false;
|
| +
|
| + DisplayAndroid displayAndroid = mWindowAndroid.getWindowAndroid().getDisplay();
|
| + double percentOfScreenHeight =
|
| + (double) mContainerView.getHeight() / displayAndroid.getDisplayHeight();
|
| +
|
| + // If the WebView is full width and most of the height, it's probably the main UI.
|
| + return mContainerView.getWidth() == displayAndroid.getDisplayWidth()
|
| + && percentOfScreenHeight >= MIN_SCREEN_PERCENTAGE_FOR_INTERSTITIAL;
|
| }
|
|
|
| @VisibleForTesting
|
|
|