Search in sources :

Example 1 with ExternalPrerenderHandler

use of org.chromium.chrome.browser.prerender.ExternalPrerenderHandler in project AndroidChromium by JackyAndroid.

the class CustomTabsConnection method prerenderUrl.

/**
     * Tries to request a prerender for a given URL.
     *
     * @param session Session the request comes from.
     * @param url URL to prerender.
     * @param extras extra parameters.
     * @param uid UID of the caller.
     * @return true if a prerender has been initiated.
     */
private boolean prerenderUrl(CustomTabsSessionToken session, String url, Bundle extras, int uid) {
    ThreadUtils.assertOnUiThread();
    // Ignores mayPrerender() for an empty URL, since it cancels an existing prerender.
    if (!mayPrerender(session) && !TextUtils.isEmpty(url))
        return false;
    if (!mWarmupHasBeenCalled.get())
        return false;
    // Last one wins and cancels the previous prerender.
    cancelPrerender(null);
    if (TextUtils.isEmpty(url))
        return false;
    boolean throttle = !shouldPrerenderOnCellularForSession(session);
    if (throttle && !mClientManager.isPrerenderingAllowed(uid))
        return false;
    // A prerender will be requested. Time to destroy the spare WebContents.
    WarmupManager.getInstance().destroySpareWebContents();
    Intent extrasIntent = new Intent();
    if (extras != null)
        extrasIntent.putExtras(extras);
    if (IntentHandler.getExtraHeadersFromIntent(extrasIntent) != null)
        return false;
    if (mExternalPrerenderHandler == null) {
        mExternalPrerenderHandler = new ExternalPrerenderHandler();
    }
    Rect contentBounds = ExternalPrerenderHandler.estimateContentSize(mApplication, true);
    Context context = mApplication.getApplicationContext();
    String referrer = IntentHandler.getReferrerUrlIncludingExtraHeaders(extrasIntent, context);
    if (referrer == null && getReferrerForSession(session) != null) {
        referrer = getReferrerForSession(session).getUrl();
    }
    if (referrer == null)
        referrer = "";
    WebContents webContents = mExternalPrerenderHandler.addPrerender(Profile.getLastUsedProfile(), url, referrer, contentBounds, shouldPrerenderOnCellularForSession(session));
    if (webContents == null)
        return false;
    if (throttle)
        mClientManager.registerPrerenderRequest(uid, url);
    mPrerender = new PrerenderedUrlParams(session, webContents, url, referrer, extras);
    RecordHistogram.recordBooleanHistogram("CustomTabs.PrerenderSessionUsesDefaultParameters", mClientManager.usesDefaultSessionParameters(session));
    return true;
}
Also used : Context(android.content.Context) WebContents(org.chromium.content_public.browser.WebContents) ExternalPrerenderHandler(org.chromium.chrome.browser.prerender.ExternalPrerenderHandler) Rect(android.graphics.Rect) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

Aggregations

PendingIntent (android.app.PendingIntent)1 Context (android.content.Context)1 Intent (android.content.Intent)1 Rect (android.graphics.Rect)1 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)1 ExternalPrerenderHandler (org.chromium.chrome.browser.prerender.ExternalPrerenderHandler)1 WebContents (org.chromium.content_public.browser.WebContents)1