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;
}
Aggregations