1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 ChromeUtils.defineESModuleGetters(lazy, {
8 E10SUtils: "resource://gre/modules/E10SUtils.sys.mjs",
11 var SessionMigrationInternal = {
13 * Convert the original session restore state into a minimal state. It will
17 * - with history entries with only title, url, triggeringPrincipal
19 * - with tab group info (hidden + group id)
20 * - with selected tab info
21 * - with selected window info
23 * The complete state is then wrapped into the "about:welcomeback" page as
24 * form field info to be restored when restoring the state.
26 convertState(aStateObj) {
28 selectedWindow: aStateObj.selectedWindow,
31 state.windows = aStateObj.windows.map(function (oldWin) {
32 var win = { extData: {} };
33 win.tabs = oldWin.tabs.map(function (oldTab) {
35 // Keep only titles, urls and triggeringPrincipals for history entries
36 tab.entries = oldTab.entries.map(function (entry) {
39 triggeringPrincipal_base64: entry.triggeringPrincipal_base64,
43 tab.index = oldTab.index;
44 tab.hidden = oldTab.hidden;
45 tab.pinned = oldTab.pinned;
48 win.selected = oldWin.selected;
52 let url = "about:welcomeback";
53 let formdata = { id: { sessionData: state }, url };
56 triggeringPrincipal_base64: lazy.E10SUtils.SERIALIZED_SYSTEMPRINCIPAL,
58 return { windows: [{ tabs: [{ entries: [entry], formdata }] }] };
61 * Asynchronously read session restore state (JSON) from a path
64 return IOUtils.readJSON(aPath, { decompress: true });
67 * Asynchronously write session restore state as JSON to a path
69 writeState(aPath, aState) {
70 return IOUtils.writeJSON(aPath, aState, {
72 tmpPath: `${aPath}.tmp`,
77 export var SessionMigration = {
79 * Migrate a limited set of session data from one path to another.
81 migrate(aFromPath, aToPath) {
82 return (async function () {
83 let inState = await SessionMigrationInternal.readState(aFromPath);
84 let outState = SessionMigrationInternal.convertState(inState);
85 // Unfortunately, we can't use SessionStore's own SessionFile to
86 // write out the data because it has a dependency on the profile dir
87 // being known. When the migration runs, there is no guarantee that
89 await SessionMigrationInternal.writeState(aToPath, outState);