Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java |
| index 01dbb160a98d396b012d316c95cec8376378bf8b..80f013dce651a80335dbb43ce21c4f7e0e72e287 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java |
| @@ -65,6 +65,7 @@ import org.chromium.chrome.browser.rappor.RapporServiceBridge; |
| import org.chromium.chrome.browser.tab.EmptyTabObserver; |
| import org.chromium.chrome.browser.tab.Tab; |
| import org.chromium.chrome.browser.tab.TabDelegateFactory; |
| +import org.chromium.chrome.browser.tabmodel.AsyncTabParams; |
| import org.chromium.chrome.browser.tabmodel.AsyncTabParamsManager; |
| import org.chromium.chrome.browser.tabmodel.ChromeTabCreator; |
| import org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver; |
| @@ -98,7 +99,8 @@ public class CustomTabActivity extends ChromeActivity { |
| private static final int WEBCONTENTS_STATE_NO_WEBCONTENTS = 0; |
| private static final int WEBCONTENTS_STATE_PRERENDERED_WEBCONTENTS = 1; |
| private static final int WEBCONTENTS_STATE_SPARE_WEBCONTENTS = 2; |
| - private static final int WEBCONTENTS_STATE_MAX = 3; |
| + private static final int WEBCONTENTS_STATE_TRANSFERRED_WEBCONTENTS = 3; |
| + private static final int WEBCONTENTS_STATE_MAX = 4; |
| private static CustomTabContentHandler sActiveContentHandler; |
| @@ -574,28 +576,15 @@ public class CustomTabActivity extends ChromeActivity { |
| private Tab createMainTab() { |
| CustomTabsConnection connection = CustomTabsConnection.getInstance(getApplication()); |
| - String url = getUrlToLoad(); |
| - String referrerUrl = connection.getReferrer(mSession, getIntent()); |
| - Tab tab = new Tab(Tab.INVALID_TAB_ID, Tab.INVALID_TAB_ID, false, this, getWindowAndroid(), |
| + WebContents webContents = takeWebContents(connection); |
| + |
| + int assignedTabId = IntentUtils.safeGetIntExtra( |
| + getIntent(), IntentHandler.EXTRA_TAB_ID, Tab.INVALID_TAB_ID); |
| + int parentTabId = IntentUtils.safeGetIntExtra( |
| + getIntent(), IntentHandler.EXTRA_PARENT_TAB_ID, Tab.INVALID_TAB_ID); |
| + Tab tab = new Tab(assignedTabId, parentTabId, false, this, getWindowAndroid(), |
| TabLaunchType.FROM_EXTERNAL_APP, null, null); |
| tab.setAppAssociatedWith(connection.getClientPackageNameForSession(mSession)); |
| - |
| - int webContentsStateOnLaunch = WEBCONTENTS_STATE_NO_WEBCONTENTS; |
| - WebContents webContents = connection.takePrerenderedUrl(mSession, url, referrerUrl); |
| - mUsingPrerender = webContents != null; |
| - if (mUsingPrerender) webContentsStateOnLaunch = WEBCONTENTS_STATE_PRERENDERED_WEBCONTENTS; |
| - if (!mUsingPrerender) { |
| - webContents = WarmupManager.getInstance().takeSpareWebContents(false, false); |
| - if (webContents != null) webContentsStateOnLaunch = WEBCONTENTS_STATE_SPARE_WEBCONTENTS; |
| - } |
| - RecordHistogram.recordEnumeratedHistogram("CustomTabs.WebContentsStateOnLaunch", |
| - webContentsStateOnLaunch, WEBCONTENTS_STATE_MAX); |
| - if (webContents == null) { |
| - webContents = WebContentsFactory.createWebContentsWithWarmRenderer(false, false); |
| - } |
| - if (!mUsingPrerender) { |
| - connection.resetPostMessageHandlerForSession(mSession, webContents); |
| - } |
| tab.initialize( |
| webContents, getTabContentManager(), |
| new CustomTabDelegateFactory( |
| @@ -612,6 +601,49 @@ public class CustomTabActivity extends ChromeActivity { |
| return tab; |
| } |
| + private WebContents takeWebContents(CustomTabsConnection connection) { |
| + WebContents webContents; |
| + int webContentsStateOnLaunch; |
| + mUsingPrerender = false; |
| + |
| + if ((webContents = takePrerenderedWebContents(connection)) != null) { |
| + webContentsStateOnLaunch = WEBCONTENTS_STATE_PRERENDERED_WEBCONTENTS; |
| + mUsingPrerender = true; |
| + } else if ((webContents = takeAsyncWebContents()) != null) { |
|
Yusuf
2017/06/15 16:15:56
I know it will make you have a slightly worse nest
piotrs
2017/06/15 23:28:21
Done.
|
| + webContentsStateOnLaunch = WEBCONTENTS_STATE_TRANSFERRED_WEBCONTENTS; |
| + } else if ((webContents = WarmupManager.getInstance().takeSpareWebContents(false, false)) |
| + != null) { |
| + webContentsStateOnLaunch = WEBCONTENTS_STATE_SPARE_WEBCONTENTS; |
| + } else { |
| + webContents = WebContentsFactory.createWebContentsWithWarmRenderer(false, false); |
| + webContentsStateOnLaunch = WEBCONTENTS_STATE_NO_WEBCONTENTS; |
| + } |
| + RecordHistogram.recordEnumeratedHistogram("CustomTabs.WebContentsStateOnLaunch", |
| + webContentsStateOnLaunch, WEBCONTENTS_STATE_MAX); |
| + |
| + if (!mUsingPrerender) { |
| + connection.resetPostMessageHandlerForSession(mSession, webContents); |
| + } |
| + |
| + return webContents; |
| + } |
| + |
| + private WebContents takePrerenderedWebContents(CustomTabsConnection connection) { |
| + String url = getUrlToLoad(); |
| + String referrerUrl = connection.getReferrer(mSession, getIntent()); |
| + return connection.takePrerenderedUrl(mSession, url, referrerUrl); |
| + } |
| + |
| + private WebContents takeAsyncWebContents() { |
| + int assignedTabId = IntentUtils.safeGetIntExtra( |
| + getIntent(), IntentHandler.EXTRA_TAB_ID, Tab.INVALID_TAB_ID); |
| + AsyncTabParams asyncParams = AsyncTabParamsManager.remove(assignedTabId); |
| + if (asyncParams == null) { |
|
Yusuf
2017/06/15 16:15:56
one line
piotrs
2017/06/15 23:28:21
Done.
|
| + return null; |
| + } |
| + return asyncParams.getWebContents(); |
| + } |
| + |
| private void initializeMainTab(Tab tab) { |
| tab.getTabRedirectHandler().updateIntent(getIntent()); |
| tab.getView().requestFocus(); |