зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1015516 - Save closedTabs when saving session to disk. r=bnicholson
This commit is contained in:
Родитель
d17a17e989
Коммит
092f4014ef
|
@ -1650,6 +1650,7 @@ public abstract class GeckoApp
|
||||||
// updated before Gecko has restored.
|
// updated before Gecko has restored.
|
||||||
if (mShouldRestore) {
|
if (mShouldRestore) {
|
||||||
final JSONArray tabs = new JSONArray();
|
final JSONArray tabs = new JSONArray();
|
||||||
|
final JSONObject windowObject = new JSONObject();
|
||||||
SessionParser parser = new SessionParser() {
|
SessionParser parser = new SessionParser() {
|
||||||
@Override
|
@Override
|
||||||
public void onTabRead(SessionTab sessionTab) {
|
public void onTabRead(SessionTab sessionTab) {
|
||||||
|
@ -1670,6 +1671,11 @@ public abstract class GeckoApp
|
||||||
}
|
}
|
||||||
tabs.put(tabObject);
|
tabs.put(tabObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClosedTabsRead(final JSONArray closedTabData) throws JSONException {
|
||||||
|
windowObject.put("closedTabs", closedTabData);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (mPrivateBrowsingSession == null) {
|
if (mPrivateBrowsingSession == null) {
|
||||||
|
@ -1679,7 +1685,8 @@ public abstract class GeckoApp
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tabs.length() > 0) {
|
if (tabs.length() > 0) {
|
||||||
sessionString = new JSONObject().put("windows", new JSONArray().put(new JSONObject().put("tabs", tabs))).toString();
|
windowObject.put("tabs", tabs);
|
||||||
|
sessionString = new JSONObject().put("windows", new JSONArray().put(windowObject)).toString();
|
||||||
} else {
|
} else {
|
||||||
throw new SessionRestoreException("No tabs could be read from session file");
|
throw new SessionRestoreException("No tabs could be read from session file");
|
||||||
}
|
}
|
||||||
|
@ -1688,7 +1695,6 @@ public abstract class GeckoApp
|
||||||
JSONObject restoreData = new JSONObject();
|
JSONObject restoreData = new JSONObject();
|
||||||
restoreData.put("sessionString", sessionString);
|
restoreData.put("sessionString", sessionString);
|
||||||
return restoreData.toString();
|
return restoreData.toString();
|
||||||
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
throw new SessionRestoreException(e);
|
throw new SessionRestoreException(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,15 @@ public abstract class SessionParser {
|
||||||
|
|
||||||
abstract public void onTabRead(SessionTab tab);
|
abstract public void onTabRead(SessionTab tab);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Placeholder method that must be overloaded to handle closedTabs while parsing session data.
|
||||||
|
*
|
||||||
|
* @param closedTabs, JSONArray of recently closed tab entries.
|
||||||
|
* @throws JSONException
|
||||||
|
*/
|
||||||
|
public void onClosedTabsRead(final JSONArray closedTabs) throws JSONException{
|
||||||
|
}
|
||||||
|
|
||||||
public void parse(String... sessionStrings) {
|
public void parse(String... sessionStrings) {
|
||||||
final LinkedList<SessionTab> sessionTabs = new LinkedList<SessionTab>();
|
final LinkedList<SessionTab> sessionTabs = new LinkedList<SessionTab>();
|
||||||
int totalCount = 0;
|
int totalCount = 0;
|
||||||
|
@ -61,6 +70,10 @@ public abstract class SessionParser {
|
||||||
final JSONObject window = new JSONObject(sessionString).getJSONArray("windows").getJSONObject(0);
|
final JSONObject window = new JSONObject(sessionString).getJSONArray("windows").getJSONObject(0);
|
||||||
final JSONArray tabs = window.getJSONArray("tabs");
|
final JSONArray tabs = window.getJSONArray("tabs");
|
||||||
final int optSelected = window.optInt("selected", -1);
|
final int optSelected = window.optInt("selected", -1);
|
||||||
|
final JSONArray closedTabs = window.optJSONArray("closedTabs");
|
||||||
|
if (closedTabs != null) {
|
||||||
|
onClosedTabsRead(closedTabs);
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < tabs.length(); i++) {
|
for (int i = 0; i < tabs.length(); i++) {
|
||||||
final JSONObject tab = tabs.getJSONObject(i);
|
final JSONObject tab = tabs.getJSONObject(i);
|
||||||
|
|
|
@ -434,6 +434,10 @@ SessionStore.prototype = {
|
||||||
normalWin[prop] = data[prop];
|
normalWin[prop] = data[prop];
|
||||||
}
|
}
|
||||||
normalWin.tabs = [];
|
normalWin.tabs = [];
|
||||||
|
|
||||||
|
// Save normal closed tabs. Forget about private closed tabs.
|
||||||
|
normalWin.closedTabs = win.closedTabs.filter(tab => !tab.isPrivate);
|
||||||
|
|
||||||
normalData.windows.push(normalWin);
|
normalData.windows.push(normalWin);
|
||||||
privateData.windows.push({ tabs: [] });
|
privateData.windows.push({ tabs: [] });
|
||||||
|
|
||||||
|
@ -865,6 +869,11 @@ SessionStore.prototype = {
|
||||||
|
|
||||||
tab.browser.__SS_extdata = tabData.extData;
|
tab.browser.__SS_extdata = tabData.extData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Restore the closed tabs array on the current window.
|
||||||
|
if (state.windows[0].closedTabs) {
|
||||||
|
this._windows[window.__SSID].closedTabs = state.windows[0].closedTabs;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getClosedTabCount: function ss_getClosedTabCount(aWindow) {
|
getClosedTabCount: function ss_getClosedTabCount(aWindow) {
|
||||||
|
@ -994,26 +1003,9 @@ SessionStore.prototype = {
|
||||||
let notifyMessage = "";
|
let notifyMessage = "";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Normally, we'll receive the session string from Java, but there are
|
this._restoreWindow(aSessionString);
|
||||||
// cases where we may want to restore that Java cannot detect (e.g., if
|
|
||||||
// browser.sessionstore.resume_session_once is true). In these cases, the
|
|
||||||
// session will be read from sessionstore.bak (which is also used for
|
|
||||||
// "tabs from last time").
|
|
||||||
let data = aSessionString;
|
|
||||||
|
|
||||||
if (data == null) {
|
|
||||||
let bytes = yield OS.File.read(this._sessionFileBackup.path);
|
|
||||||
data = JSON.parse(new TextDecoder().decode(bytes) || "");
|
|
||||||
}
|
|
||||||
|
|
||||||
this._restoreWindow(data);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof OS.File.Error) {
|
Cu.reportError("SessionStore: " + e);
|
||||||
Cu.reportError("SessionStore: " + e.message);
|
|
||||||
} else {
|
|
||||||
Cu.reportError("SessionStore: " + e);
|
|
||||||
}
|
|
||||||
|
|
||||||
notifyMessage = "fail";
|
notifyMessage = "fail";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче