Chromium Code Reviews| 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..320c03fa848f3f4999cae7ba3220677955c1ebc2 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,54 @@ 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(); |
| + int displayHeight = displayAndroid.getDisplayHeight(); |
|
sgurun-gerrit only
2017/04/24 22:44:10
nit: inline
Nate Fischer
2017/04/24 23:00:53
done
|
| + int displayWidth = displayAndroid.getDisplayWidth(); |
|
sgurun-gerrit only
2017/04/24 22:44:10
nit:inline
Nate Fischer
2017/04/24 23:00:53
done
|
| + if (x < 0 || y < 0 || x + mContainerView.getWidth() > displayWidth |
| + || y + mContainerView.getHeight() > displayHeight) { |
| + 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 |
| + */ |
| + @CalledByNative |
| + protected boolean canShowInterstitial() { |
| + return mContainerView.getVisibility() == View.VISIBLE; |
| + } |
| + |
| + /** |
| + * 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 |
| + */ |
| + @CalledByNative |
| + protected boolean canShowBigInterstitial() { |
| + if (!canShowInterstitial()) return false; |
| + if (extendsOffDeviceScreen()) return false; |
| + |
| + DisplayAndroid displayAndroid = mWindowAndroid.getWindowAndroid().getDisplay(); |
| + int displayHeight = displayAndroid.getDisplayHeight(); |
| + int displayWidth = displayAndroid.getDisplayWidth(); |
| + double percentOfScreenHeight = (double) mContainerView.getHeight() / displayHeight; |
| + |
| + // If the WebView is full width and most of the height, it's probably the main UI. |
| + return mContainerView.getWidth() == displayWidth |
| + && percentOfScreenHeight >= MIN_SCREEN_PERCENTAGE_FOR_INTERSTITIAL; |
| } |
| @VisibleForTesting |