| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.chrome.browser.prerender; | 5 package org.chromium.chrome.browser.prerender; |
| 6 | 6 |
| 7 import android.app.Application; | 7 import android.app.Application; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.content.res.Resources; | 9 import android.content.res.Resources; |
| 10 import android.graphics.Point; | 10 import android.graphics.Point; |
| 11 import android.graphics.Rect; |
| 11 import android.view.WindowManager; | 12 import android.view.WindowManager; |
| 12 | 13 |
| 13 import org.chromium.base.VisibleForTesting; | 14 import org.chromium.base.VisibleForTesting; |
| 14 import org.chromium.base.annotations.JNINamespace; | 15 import org.chromium.base.annotations.JNINamespace; |
| 15 import org.chromium.chrome.R; | 16 import org.chromium.chrome.R; |
| 16 import org.chromium.chrome.browser.WebContentsFactory; | 17 import org.chromium.chrome.browser.WebContentsFactory; |
| 17 import org.chromium.chrome.browser.profiles.Profile; | 18 import org.chromium.chrome.browser.profiles.Profile; |
| 18 import org.chromium.content_public.browser.WebContents; | 19 import org.chromium.content_public.browser.WebContents; |
| 19 | 20 |
| 20 /** | 21 /** |
| (...skipping 10 matching lines...) Expand all Loading... |
| 31 | 32 |
| 32 /** | 33 /** |
| 33 * Add a prerender for the given url and given content view dimensions. | 34 * Add a prerender for the given url and given content view dimensions. |
| 34 * <p> | 35 * <p> |
| 35 * The generated {@link WebContents} does not actually contain the prerender
ed contents but | 36 * The generated {@link WebContents} does not actually contain the prerender
ed contents but |
| 36 * must be used as the container that you load the prerendered URL into. | 37 * must be used as the container that you load the prerendered URL into. |
| 37 * | 38 * |
| 38 * @param profile The profile to use for the prerender. | 39 * @param profile The profile to use for the prerender. |
| 39 * @param url The url to prerender. | 40 * @param url The url to prerender. |
| 40 * @param referrer The referrer for the prerender request. | 41 * @param referrer The referrer for the prerender request. |
| 41 * @param width The width for the content view (render widget host view) for
the prerender. | 42 * @param bounds The bounds for the content view (render widget host view) f
or the prerender. |
| 42 * @param height The height for the content view (render widget host view) f
or the prerender. | |
| 43 * @param prerenderOnCellular Whether the prerender should happen if the dev
ice has a cellular | 43 * @param prerenderOnCellular Whether the prerender should happen if the dev
ice has a cellular |
| 44 * connection. | 44 * connection. |
| 45 * @return The {@link WebContents} that is linked to this prerender. {@code
null} if | 45 * @return The {@link WebContents} that is linked to this prerender. {@code
null} if |
| 46 * unsuccessful. | 46 * unsuccessful. |
| 47 */ | 47 */ |
| 48 public WebContents addPrerender(Profile profile, String url, String referrer
, int width, | 48 public WebContents addPrerender(Profile profile, String url, String referrer
, |
| 49 int height, boolean prerenderOnCellular) { | 49 Rect bounds, boolean prerenderOnCellular) { |
| 50 WebContents webContents = WebContentsFactory.createWebContents(false, fa
lse); | 50 WebContents webContents = WebContentsFactory.createWebContents(false, fa
lse); |
| 51 if (addPrerender(profile, webContents, url, referrer, width, height, pre
renderOnCellular)) { | 51 if (addPrerender(profile, webContents, url, referrer, bounds, prerenderO
nCellular)) { |
| 52 return webContents; | 52 return webContents; |
| 53 } | 53 } |
| 54 if (webContents != null) webContents.destroy(); | 54 if (webContents != null) webContents.destroy(); |
| 55 return null; | 55 return null; |
| 56 } | 56 } |
| 57 | 57 |
| 58 /** | 58 /** |
| 59 * Adds a prerender for the given URL to an existing {@link WebContents} wit
h the given | 59 * Adds a prerender for the given URL to an existing {@link WebContents} wit
h the given |
| 60 * dimensions. | 60 * dimensions. |
| 61 * | 61 * |
| 62 * @param profile The profile to use for the prerender. | 62 * @param profile The profile to use for the prerender. |
| 63 * @param webContents The WebContents to add the prerender to. | 63 * @param webContents The WebContents to add the prerender to. |
| 64 * @param url The url to prerender. | 64 * @param url The url to prerender. |
| 65 * @param referrer The referrer for the prerender request. | 65 * @param referrer The referrer for the prerender request. |
| 66 * @param width The width for the content view (render widget host view) for
the prerender. | 66 * @param bounds The bounds for the content view (render widget host view) f
or the prerender. |
| 67 * @param height The height for the content view (render widget host view) f
or the prerender. | |
| 68 * @param prerenderOnCellular Whether the prerender should happen if the dev
ice has a cellular | 67 * @param prerenderOnCellular Whether the prerender should happen if the dev
ice has a cellular |
| 69 * connection. | 68 * connection. |
| 70 * @return Whether the prerender was successful. | 69 * @return Whether the prerender was successful. |
| 71 */ | 70 */ |
| 72 public boolean addPrerender(Profile profile, WebContents webContents, String
url, | 71 public boolean addPrerender(Profile profile, WebContents webContents, String
url, |
| 73 String referrer, int width, int height, boolean prerenderOnCellular)
{ | 72 String referrer, Rect bounds, boolean prerenderOnCellular) { |
| 74 return nativeAddPrerender(mNativeExternalPrerenderHandler, profile, webC
ontents, | 73 return nativeAddPrerender(mNativeExternalPrerenderHandler, profile, webC
ontents, url, |
| 75 url, referrer, width, height, prerenderOnCellular); | 74 referrer, bounds.top, bounds.left, bounds.bottom, bounds.right, |
| 75 prerenderOnCellular); |
| 76 } | 76 } |
| 77 | 77 |
| 78 /** | 78 /** |
| 79 * Cancel the current prerender action on this {@link ExternalPrerenderHandl
er}. | 79 * Cancel the current prerender action on this {@link ExternalPrerenderHandl
er}. |
| 80 */ | 80 */ |
| 81 public void cancelCurrentPrerender() { | 81 public void cancelCurrentPrerender() { |
| 82 nativeCancelCurrentPrerender(mNativeExternalPrerenderHandler); | 82 nativeCancelCurrentPrerender(mNativeExternalPrerenderHandler); |
| 83 } | 83 } |
| 84 | 84 |
| 85 /** | 85 /** |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 screenSize.x = (int) Math.ceil(screenSize.x / density); | 141 screenSize.x = (int) Math.ceil(screenSize.x / density); |
| 142 screenSize.y = (int) Math.ceil(screenSize.y / density); | 142 screenSize.y = (int) Math.ceil(screenSize.y / density); |
| 143 } | 143 } |
| 144 return screenSize; | 144 return screenSize; |
| 145 } | 145 } |
| 146 | 146 |
| 147 private static native long nativeInit(); | 147 private static native long nativeInit(); |
| 148 private static native boolean nativeAddPrerender( | 148 private static native boolean nativeAddPrerender( |
| 149 long nativeExternalPrerenderHandlerAndroid, Profile profile, | 149 long nativeExternalPrerenderHandlerAndroid, Profile profile, |
| 150 WebContents webContents, String url, String referrer, | 150 WebContents webContents, String url, String referrer, |
| 151 int width, int height, boolean prerenderOnCellular); | 151 int top, int left, int bottom, int right, boolean prerenderOnCellula
r); |
| 152 private static native boolean nativeHasPrerenderedUrl( | 152 private static native boolean nativeHasPrerenderedUrl( |
| 153 Profile profile, String url, WebContents webContents); | 153 Profile profile, String url, WebContents webContents); |
| 154 private static native boolean nativeHasPrerenderedAndFinishedLoadingUrl( | 154 private static native boolean nativeHasPrerenderedAndFinishedLoadingUrl( |
| 155 Profile profile, String url, WebContents webContents); | 155 Profile profile, String url, WebContents webContents); |
| 156 private static native void nativeCancelCurrentPrerender( | 156 private static native void nativeCancelCurrentPrerender( |
| 157 long nativeExternalPrerenderHandlerAndroid); | 157 long nativeExternalPrerenderHandlerAndroid); |
| 158 } | 158 } |
| OLD | NEW |