Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2882)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java

Issue 2336413002: Actually enable tab persistence for CCTs. (Closed)
Patch Set: Move tab model observer before tab creation Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/customtabs/SeparateTaskCustomTabActivity.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 379023e41253795a21b733c163f7a6f7101676ff..929791c020299497c81b314dea3573475ff00991 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
@@ -105,6 +105,8 @@ public class CustomTabActivity extends ChromeActivity {
// Whether a prerender is being used.
private boolean mHasPrerendered;
+ private boolean mIsClosing;
+
private static class PageLoadMetricsObserver implements PageLoadMetrics.Observer {
private final CustomTabsConnection mConnection;
private final CustomTabsSessionToken mSession;
@@ -217,6 +219,7 @@ public class CustomTabActivity extends ChromeActivity {
@Override
public void onStart() {
super.onStart();
+ mIsClosing = false;
CustomTabsConnection.getInstance(getApplication())
.keepAliveForSession(mIntentDataProvider.getSession(),
mIntentDataProvider.getKeepAliveServiceIntent());
@@ -246,7 +249,8 @@ public class CustomTabActivity extends ChromeActivity {
supportRequestWindowFeature(Window.FEATURE_ACTION_MODE_OVERLAY);
mHasPrerender = !TextUtils.isEmpty(
CustomTabsConnection.getInstance(getApplication()).getPrerenderedUrl(mSession));
- if (CustomTabsConnection.hasWarmUpBeenFinished(getApplication())) {
+ if (getSavedInstanceState() == null
+ && CustomTabsConnection.hasWarmUpBeenFinished(getApplication())) {
mMainTab = createMainTab();
loadUrlInTab(mMainTab, new LoadUrlParams(getUrlToLoad()),
IntentHandler.getTimestampFromIntent(getIntent()));
@@ -301,15 +305,31 @@ public class CustomTabActivity extends ChromeActivity {
if (IntentHandler.getExtraHeadersFromIntent(getIntent()) != null) {
connection.cancelPrerender(mSession);
}
- if (mHasCreatedTabEarly) {
- // When the tab is created early, we don't have the TabContentManager connected, since
- // compositor related controllers were not initialized at that point.
- mMainTab.attachTabContentManager(getTabContentManager());
- } else {
- mMainTab = createMainTab();
- }
+
getTabModelSelector().getModel(false).addObserver(mTabModelObserver);
- getTabModelSelector().getModel(false).addTab(mMainTab, 0, mMainTab.getLaunchType());
+
+ boolean successfulStateRestore = false;
+ // Attempt to restore the previous tab state if applicable.
+ if (getSavedInstanceState() != null) {
+ assert mMainTab == null;
+ getTabModelSelector().loadState(true);
+ getTabModelSelector().restoreTabs(true);
+ mMainTab = getTabModelSelector().getCurrentTab();
+ successfulStateRestore = mMainTab != null;
+ if (successfulStateRestore) initializeMainTab(mMainTab);
+ }
+
+ // If no tab was restored, create a new tab.
+ if (!successfulStateRestore) {
+ if (mHasCreatedTabEarly) {
+ // When the tab is created early, we don't have the TabContentManager connected,
+ // since compositor related controllers were not initialized at that point.
+ mMainTab.attachTabContentManager(getTabContentManager());
+ } else {
+ mMainTab = createMainTab();
+ }
+ getTabModelSelector().getModel(false).addTab(mMainTab, 0, mMainTab.getLaunchType());
+ }
ToolbarControlContainer controlContainer = (ToolbarControlContainer) findViewById(
R.id.control_container);
@@ -391,7 +411,7 @@ public class CustomTabActivity extends ChromeActivity {
}
DataUseTabUIManager.onCustomTabInitialNavigation(mMainTab, packageName, url);
- if (!mHasCreatedTabEarly) {
+ if (!mHasCreatedTabEarly && !successfulStateRestore) {
loadUrlInTab(mMainTab, new LoadUrlParams(url),
IntentHandler.getTimestampFromIntent(getIntent()));
}
@@ -434,6 +454,11 @@ public class CustomTabActivity extends ChromeActivity {
tab.initialize(webContents, getTabContentManager(),
new CustomTabDelegateFactory(mIntentDataProvider.shouldEnableUrlBarHiding()), false,
false);
+ initializeMainTab(tab);
+ return tab;
+ }
+
+ private void initializeMainTab(Tab tab) {
tab.getTabRedirectHandler().updateIntent(getIntent());
tab.getView().requestFocus();
mTabObserver = new CustomTabObserver(
@@ -442,7 +467,6 @@ public class CustomTabActivity extends ChromeActivity {
mMetricsObserver = new PageLoadMetricsObserver(
CustomTabsConnection.getInstance(getApplication()), mSession, tab);
tab.addObserver(mTabObserver);
- return tab;
}
@Override
@@ -504,6 +528,7 @@ public class CustomTabActivity extends ChromeActivity {
public void onStopWithNative() {
super.onStopWithNative();
setActiveContentHandler(null);
+ if (!mIsClosing) getTabModelSelector().saveState();
}
/**
@@ -599,7 +624,16 @@ public class CustomTabActivity extends ChromeActivity {
/**
* Finishes the activity and removes the reference from the Android recents.
*/
- public void finishAndClose() {
+ public final void finishAndClose() {
+ mIsClosing = true;
+ handleFinishAndClose();
+ }
+
+ /**
+ * Internal implementation that finishes the activity and removes the references from Android
+ * recents.
+ */
+ protected void handleFinishAndClose() {
// When on top of another app, finish is all that is required.
finish();
}
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/customtabs/SeparateTaskCustomTabActivity.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698