Commit 023aea51 authored by Matthew Cary's avatar Matthew Cary Committed by Commit Bot

Custom Tabs: permanently disable prerender from custom tabs.

Removes the ability to set a prerender speculation mode for custom tabs,
making the background (hidden) tab the only option. Where appropriate,
method names mentioning "prerender" have been changed to
generically refer to "speculation". In one case shims for
shouldPrerenderOnCellularForSession, etc, have been left in so that
downstream code can be changed in a future CL.

Bug: 755921,710720, 828968
Change-Id: I7234fad18a9616ae65f20af39da4a0261cf75935
Reviewed-on: https://chromium-review.googlesource.com/979992
Commit-Queue: Matthew Cary <mattcary@chromium.org>
Reviewed-by: default avatarBernhard Bauer <bauerb@chromium.org>
Reviewed-by: default avatarEgor Pasko <pasko@chromium.org>
Reviewed-by: default avatarBenoit L <lizeb@chromium.org>
Reviewed-by: default avatarGayane Petrosyan <gayane@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548717}
parent 51bf0eaf
......@@ -140,13 +140,13 @@ class ClientManager {
public boolean highConfidencePrediction;
private String mPackageName;
private boolean mShouldHideDomain;
private boolean mShouldPrerenderOnCellular;
private boolean mShouldSpeculateLoadOnCellular;
private boolean mShouldSendNavigationInfo;
private boolean mShouldSendBottomBarScrollState;
private KeepAliveServiceConnection mKeepAliveConnection;
private String mPredictedUrl;
private long mLastMayLaunchUrlTimestamp;
private int mSpeculationMode;
private boolean mCanUseHiddenTab;
private boolean mAllowParallelRequest;
public SessionParams(Context context, int uid, DisconnectCallback callback,
......@@ -156,7 +156,6 @@ class ClientManager {
disconnectCallback = callback;
this.postMessageHandler = postMessageHandler;
if (postMessageHandler != null) this.postMessageHandler.setPackageName(mPackageName);
this.mSpeculationMode = CustomTabsConnection.SpeculationParams.PRERENDER;
}
/**
......@@ -219,7 +218,7 @@ class ClientManager {
* @return Whether the default parameters are used for this session.
*/
public boolean isDefault() {
return !mIgnoreFragments && !mShouldPrerenderOnCellular;
return !mIgnoreFragments && !mShouldSpeculateLoadOnCellular;
}
}
......@@ -568,14 +567,14 @@ class ClientManager {
}
/**
* @return Whether the fragment should be ignored for prerender matching.
* @return Whether the fragment should be ignored for speculation matching.
*/
public synchronized boolean getIgnoreFragmentsForSession(CustomTabsSessionToken session) {
SessionParams params = mSessionParams.get(session);
return params == null ? false : params.mIgnoreFragments;
}
/** Sets whether the fragment should be ignored for prerender matching. */
/** Sets whether the fragment should be ignored for speculation matching. */
public synchronized void setIgnoreFragmentsForSession(
CustomTabsSessionToken session, boolean value) {
SessionParams params = mSessionParams.get(session);
......@@ -583,17 +582,17 @@ class ClientManager {
}
/**
* @return Whether prerender should be turned on for cellular networks for given session.
* @return Whether load speculation should be turned on for cellular networks for given session.
*/
public synchronized boolean shouldPrerenderOnCellularForSession(
public synchronized boolean shouldSpeculateLoadOnCellularForSession(
CustomTabsSessionToken session) {
SessionParams params = mSessionParams.get(session);
return params != null ? params.mShouldPrerenderOnCellular : false;
return params != null ? params.mShouldSpeculateLoadOnCellular : false;
}
/**
* @return Whether the session is using the default parameters (that is,
* don't ignore fragments and don't prerender on cellular connections).
* @return Whether the session is using the default parameters (that is, don't ignore
* fragments and don't speculate loads on cellular connections).
*/
public synchronized boolean usesDefaultSessionParameters(CustomTabsSessionToken session) {
SessionParams params = mSessionParams.get(session);
......@@ -601,31 +600,47 @@ class ClientManager {
}
/**
* Sets whether prerender should be turned on for mobile networks for given session.
* Sets whether speculation should be turned on for mobile networks for given session.
* If it is turned on, hidden tab speculation is turned on as well.
*/
public synchronized void setSpeculateLoadOnCellularForSession(
CustomTabsSessionToken session, boolean shouldSpeculate) {
SessionParams params = mSessionParams.get(session);
if (params != null) {
params.mShouldSpeculateLoadOnCellular = shouldSpeculate;
params.mCanUseHiddenTab = shouldSpeculate;
}
}
/** TODO(mattcary): remove when downstream uses are removed. **/
public synchronized void setPrerenderCellularForSession(
CustomTabsSessionToken session, boolean prerender) {
SessionParams params = mSessionParams.get(session);
if (params != null) params.mShouldPrerenderOnCellular = prerender;
setSpeculateLoadOnCellularForSession(session, prerender);
}
/** TODO(mattcary): remove when downstream uses are removed. **/
public synchronized void setSpeculationModeForSession(
CustomTabsSessionToken session, int mode) {
// No-op.
}
/**
* Sets the speculation mode to be used by default for given session.
* Sets whether hidden tab speculation can be used.
*/
public synchronized void setSpeculationModeForSession(
CustomTabsSessionToken session, int speculationMode) {
public synchronized void setCanUseHiddenTab(
CustomTabsSessionToken session, boolean canUseHiddenTab) {
SessionParams params = mSessionParams.get(session);
if (params != null) params.mSpeculationMode = speculationMode;
if (params != null) {
params.mCanUseHiddenTab = canUseHiddenTab;
}
}
/**
* Get the speculation mode to be used by default for the given session.
* If no value has been set will default to PRERENDER mode.
* Get whether hidden tab speculation can be used. The default is false.
*/
public synchronized int getSpeculationModeForSession(CustomTabsSessionToken session) {
public synchronized boolean getCanUseHiddenTab(CustomTabsSessionToken session) {
SessionParams params = mSessionParams.get(session);
return params == null ? CustomTabsConnection.SpeculationParams.PRERENDER
: params.mSpeculationMode;
return params == null ? false : params.mCanUseHiddenTab;
}
public synchronized void setAllowParallelRequestForSession(
......
......@@ -138,14 +138,13 @@ public class CustomTabActivity extends ChromeActivity {
private String mSpeculatedUrl;
private boolean mUsingPrerender;
private boolean mUsingHiddenTab;
private boolean mIsClosing;
private boolean mIsKeepAlive;
// This boolean is used to do a hack in navigation history for
// prerender and hidden tab loads with unmatching fragments.
// This boolean is used to do a hack in navigation history for hidden tab loads with
// unmatching fragments.
private boolean mIsFirstLoad;
private final CustomTabsConnection mConnection = CustomTabsConnection.getInstance();
......@@ -401,8 +400,8 @@ public class CustomTabActivity extends ChromeActivity {
public void finishNativeInitialization() {
if (!mIntentDataProvider.isInfoPage()) FirstRunSignInProcessor.start(this);
// If extra headers have been passed, cancel any current prerender, as
// prerendering doesn't support extra headers.
// If extra headers have been passed, cancel any current speculation, as
// speculation doesn't support extra headers.
if (IntentHandler.getExtraHeadersFromIntent(getIntent()) != null) {
mConnection.cancelSpeculation(mSession);
}
......@@ -612,42 +611,30 @@ public class CustomTabActivity extends ChromeActivity {
}
private WebContents takeWebContents() {
mUsingPrerender = true;
int webContentsStateOnLaunch = WEBCONTENTS_STATE_PRERENDERED_WEBCONTENTS;
WebContents webContents = takePrerenderedWebContents();
if (webContents == null) {
mUsingPrerender = false;
webContents = takeAsyncWebContents();
WebContents webContents = takeAsyncWebContents();
if (webContents != null) {
webContentsStateOnLaunch = WEBCONTENTS_STATE_TRANSFERRED_WEBCONTENTS;
webContents.resumeLoadingCreatedWebContents();
} else {
webContents = WarmupManager.getInstance().takeSpareWebContents(false, false);
if (webContents != null) {
webContentsStateOnLaunch = WEBCONTENTS_STATE_TRANSFERRED_WEBCONTENTS;
webContents.resumeLoadingCreatedWebContents();
webContentsStateOnLaunch = WEBCONTENTS_STATE_SPARE_WEBCONTENTS;
} else {
webContents = WarmupManager.getInstance().takeSpareWebContents(false, false);
if (webContents != null) {
webContentsStateOnLaunch = WEBCONTENTS_STATE_SPARE_WEBCONTENTS;
} else {
webContents =
WebContentsFactory.createWebContentsWithWarmRenderer(false, false);
webContentsStateOnLaunch = WEBCONTENTS_STATE_NO_WEBCONTENTS;
}
webContents = WebContentsFactory.createWebContentsWithWarmRenderer(false, false);
webContentsStateOnLaunch = WEBCONTENTS_STATE_NO_WEBCONTENTS;
}
}
RecordHistogram.recordEnumeratedHistogram("CustomTabs.WebContentsStateOnLaunch",
webContentsStateOnLaunch, WEBCONTENTS_STATE_MAX);
if (!mUsingPrerender) mConnection.resetPostMessageHandlerForSession(mSession, webContents);
mConnection.resetPostMessageHandlerForSession(mSession, webContents);
return webContents;
}
private WebContents takePrerenderedWebContents() {
String url = getUrlToLoad();
String referrerUrl = mConnection.getReferrer(mSession, getIntent());
return mConnection.takePrerenderedUrl(mSession, url, referrerUrl);
}
private WebContents takeAsyncWebContents() {
int assignedTabId = IntentUtils.safeGetIntExtra(
getIntent(), IntentHandler.EXTRA_TAB_ID, Tab.INVALID_TAB_ID);
......@@ -774,11 +761,6 @@ public class CustomTabActivity extends ChromeActivity {
// the wrong fragment. Does an extra pageload and replaces history.
if (mHasSpeculated && isFirstLoad
&& UrlUtilities.urlsFragmentsDiffer(mSpeculatedUrl, url)) {
if (mUsingPrerender) {
LoadUrlParams temporaryParams = new LoadUrlParams(mSpeculatedUrl);
IntentHandler.addReferrerAndHeaders(temporaryParams, intent);
tab.loadUrl(temporaryParams);
}
params.setShouldReplaceCurrentEntry(true);
}
......
......@@ -13660,6 +13660,9 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
<histogram name="CustomTabs.NonDefaultSessionPrerenderMatched"
enum="BooleanMatched">
<obsolete>
Deprecated 4/2018 when prerender was removed from Custom Tabs.
</obsolete>
<owner>lizeb@chromium.org</owner>
<summary>
Android: When there is a prerender for a session with non-default
......@@ -13685,6 +13688,9 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
<histogram name="CustomTabs.PrerenderSessionUsesDefaultParameters"
enum="BooleanDefault">
<obsolete>
Deprecated 4/2018 when prerender was removed from Custom Tabs.
</obsolete>
<owner>lizeb@chromium.org</owner>
<summary>
Android: When prerendering a URL for Custom Tabs, whether the client session
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment