Bug 1261008 - Do not restore tabs pointing to about:home and with no history. r=janh,ahunt

If the browser is set to always restore the session (default) then we will never
start with an empty session. Even if the user closes all tabs we will re-create
a new tab pointing to about:home. So we will always at least restore this tab on
the next startup. As a consequence we will never open the 'homepage' on app start
because we will never have a non-empty session.

With this patch we won't restore tabs that point to about:home and do not contain
any other history. As a result we might restore an empty session and load the
homepage or about:home (depending on configuration) in a new tab.

In case we decide to not restore the currently selected tab, we just select the
first restored tab if there's any.

MozReview-Commit-ID: DuN03M60Gi8

--HG--
extra : rebase_source : 92ec12d32dfe62ebb0e7ae8e299f579dcd8c1a84
This commit is contained in:
Sebastian Kaspari 2016-07-06 16:04:01 +02:00
parent 78f04cd98f
commit 9a353f444c
3 changed files with 47 additions and 0 deletions

View File

@ -1688,8 +1688,31 @@ public abstract class GeckoApp
final JSONArray tabs = new JSONArray();
final JSONObject windowObject = new JSONObject();
SessionParser parser = new SessionParser() {
private boolean selectNextTab;
@Override
public void onTabRead(final SessionTab sessionTab) {
if (sessionTab.isAboutHomeWithoutHistory()) {
// This is a tab pointing to about:home with no history. We won't restore
// this tab. If we end up restoring no tabs then the browser will decide
// whether it needs to open about:home or a different 'homepage'. If we'd
// always restore about:home only tabs then we'd never open the homepage.
// See bug 1261008.
if (sessionTab.isSelected()) {
// Unfortunately this tab is the selected tab. Let's just try to select
// the first tab. If we haven't restored any tabs so far then remember
// to select the next tab that gets restored.
if (!Tabs.getInstance().selectLastTab()) {
selectNextTab = true;
}
}
// Do not restore this tab.
return;
}
JSONObject tabObject = sessionTab.getTabObject();
int flags = Tabs.LOADURL_NEW_TAB;
@ -1698,6 +1721,13 @@ public abstract class GeckoApp
flags |= (tabObject.optBoolean("isPrivate") ? Tabs.LOADURL_PRIVATE : 0);
final Tab tab = Tabs.getInstance().loadUrl(sessionTab.getUrl(), flags);
if (selectNextTab) {
// We did not restore the selected tab previously. Now let's select this tab.
Tabs.getInstance().selectTab(tab.getId());
selectNextTab = false;
}
ThreadUtils.postToUiThread(new Runnable() {
@Override
public void run() {

View File

@ -48,6 +48,14 @@ public abstract class SessionParser {
public JSONObject getTabObject() {
return mTabObject;
}
/**
* Is this tab pointing to about:home and does not contain any other history?
*/
public boolean isAboutHomeWithoutHistory() {
JSONArray entries = mTabObject.optJSONArray("entries");
return entries != null && entries.length() == 1 && AboutPages.isAboutHome(mUrl);
}
};
abstract public void onTabRead(SessionTab tab);

View File

@ -260,6 +260,15 @@ public class Tabs implements GeckoEventListener {
return tab;
}
public synchronized boolean selectLastTab() {
if (mOrder.isEmpty()) {
return false;
}
selectTab(mOrder.get(mOrder.size() - 1).getId());
return true;
}
private int getIndexOf(Tab tab) {
return mOrder.lastIndexOf(tab);
}