Bug 1359531 - Part 8 - Handle tabs selected while all GeckoApps were in background. r=sebastian,walkingice

Activity switching is now handled by the currently active GeckoApp instance, which obviously doesn't work if all of them are currently backgrounded.

To fix this, we track for each tab whether its selection was handled by a foregrounded GeckoApp instance. If it wasn't, we catch up with any possibly necessary activity switches during the next resume.

MozReview-Commit-ID: JEjQUuDJw5Q

--HG--
extra : rebase_source : b7a9f5a4ad4811c1c9e9d24eaae61f3757c64442
This commit is contained in:
Jan Henning 2017-05-05 21:07:29 +02:00
parent 0ba05f0abf
commit dc8e9d0635
3 changed files with 37 additions and 16 deletions

View File

@ -1181,13 +1181,6 @@ public class BrowserApp extends GeckoApp
@Override
protected void restoreLastSelectedTab() {
if (mIgnoreLastSelectedTab) {
// We're either the first activity to run, so our startup code will (have) handle(d) tab
// selection, or else we've received a new intent and want to open and select a new tab
// as well.
return;
}
if (mLastSelectedTabId < 0) {
// Normally, session restore will select the correct tab when starting up, however this
// is linked to Gecko powering up. If we're not the first activity to launch, the

View File

@ -437,6 +437,10 @@ public abstract class GeckoApp extends GeckoActivity
resetOptionsMenu();
resetFormAssistPopup();
if (foregrounded) {
tab.setWasSelectedInForeground(true);
}
if (mLastSelectedTabId != INVALID_TAB_ID && foregrounded &&
// mSuppressActivitySwitch implies that we want to defer a pending
// activity switch because we're actually about to leave the app.
@ -2284,16 +2288,31 @@ public abstract class GeckoApp extends GeckoActivity
GeckoAppShell.setGeckoInterface(this);
GeckoAppShell.setScreenOrientationDelegate(this);
// When backing out of the app triggers a tab close and therefore selects another tab, we
// don't switch activities even if the new selected tab is of a different type, because
// doing so would bring us into the foreground again.
// As this means that the currently selected tab doesn't match the last active GeckoApp, we
// need to check mSuppressActivitySwitch as well here.
if (mLastActiveGeckoApp == null || mLastActiveGeckoApp.get() != this ||
mSuppressActivitySwitch) {
mSuppressActivitySwitch = false;
restoreLastSelectedTab();
// If mIgnoreLastSelectedTab is set, we're either the first activity to run, so our startup
// code will (have) handle(d) tab selection, or else we've received a new intent and want to
// open and select a new tab as well.
if (!mIgnoreLastSelectedTab) {
Tab selectedTab = Tabs.getInstance().getSelectedTab();
// We need to check if we've selected a different tab while no GeckoApp-based activity
// was in foreground and catch up with any activity switches that might be needed.
if (selectedTab != null && !selectedTab.getWasSelectedInForeground()) {
selectedTab.setWasSelectedInForeground(true);
if (!selectedTab.matchesActivity(this)) {
startActivity(IntentHelper.getTabSwitchIntent(selectedTab));
}
// When backing out of the app closes the current tab and therefore selects
// another tab, we don't switch activities even if the newly selected tab has a
// different type, because doing so would bring us into the foreground again.
// As this means that the currently selected tab doesn't match the last active
// GeckoApp, we need to check mSuppressActivitySwitch here as well.
} else if (mLastActiveGeckoApp == null || mLastActiveGeckoApp.get() != this ||
mSuppressActivitySwitch) {
restoreLastSelectedTab();
}
}
mSuppressActivitySwitch = false;
mIgnoreLastSelectedTab = false;
int newOrientation = getResources().getConfiguration().orientation;

View File

@ -90,6 +90,7 @@ public class Tab {
private volatile boolean mIsMediaPlaying;
private String mMostRecentHomePanel;
private boolean mShouldShowToolbarWithoutAnimationOnFirstSelection;
private boolean mWasSelectedInForeground;
/*
* Bundle containing restore data for the panel referenced in mMostRecentHomePanel. This can be
@ -793,6 +794,14 @@ public class Tab {
return false;
}
public void setWasSelectedInForeground(boolean state) {
mWasSelectedInForeground = state;
}
public boolean getWasSelectedInForeground() {
return mWasSelectedInForeground;
}
public TabType getType() {
return mType;
}