2014-01-16 23:43:40 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2018-02-23 22:50:01 +03:00
|
|
|
var EXPORTED_SYMBOLS = ["ContentRestore"];
|
2014-01-16 23:43:40 +04:00
|
|
|
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.import("resource://gre/modules/Services.jsm", this);
|
2014-01-16 23:43:40 +04:00
|
|
|
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.defineModuleGetter(this, "FormData",
|
2014-02-19 20:28:00 +04:00
|
|
|
"resource://gre/modules/FormData.jsm");
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.defineModuleGetter(this, "SessionHistory",
|
2017-02-18 22:54:09 +03:00
|
|
|
"resource://gre/modules/sessionstore/SessionHistory.jsm");
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.defineModuleGetter(this, "SessionStorage",
|
2014-01-16 23:43:40 +04:00
|
|
|
"resource:///modules/sessionstore/SessionStorage.jsm");
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.defineModuleGetter(this, "Utils",
|
2016-11-02 19:56:20 +03:00
|
|
|
"resource://gre/modules/sessionstore/Utils.jsm");
|
2014-01-16 23:43:40 +04:00
|
|
|
|
2017-08-02 20:08:04 +03:00
|
|
|
const ssu = Cc["@mozilla.org/browser/sessionstore/utils;1"]
|
|
|
|
.getService(Ci.nsISessionStoreUtils);
|
|
|
|
|
2014-01-16 23:43:40 +04:00
|
|
|
/**
|
|
|
|
* This module implements the content side of session restoration. The chrome
|
|
|
|
* side is handled by SessionStore.jsm. The functions in this module are called
|
|
|
|
* by content-sessionStore.js based on messages received from SessionStore.jsm
|
|
|
|
* (or, in one case, based on a "load" event). Each tab has its own
|
|
|
|
* ContentRestore instance, constructed by content-sessionStore.js.
|
|
|
|
*
|
|
|
|
* In a typical restore, content-sessionStore.js will call the following based
|
|
|
|
* on messages and events it receives:
|
|
|
|
*
|
2015-05-06 12:55:20 +03:00
|
|
|
* restoreHistory(tabData, loadArguments, callbacks)
|
2014-01-16 23:43:40 +04:00
|
|
|
* Restores the tab's history and session cookies.
|
2015-05-06 12:55:20 +03:00
|
|
|
* restoreTabContent(loadArguments, finishCallback)
|
2014-01-16 23:43:40 +04:00
|
|
|
* Starts loading the data for the current page to restore.
|
|
|
|
* restoreDocument()
|
|
|
|
* Restore form and scroll data.
|
|
|
|
*
|
|
|
|
* When the page has been loaded from the network, we call finishCallback. It
|
|
|
|
* should send a message to SessionStore.jsm, which may cause other tabs to be
|
|
|
|
* restored.
|
|
|
|
*
|
|
|
|
* When the page has finished loading, a "load" event will trigger in
|
|
|
|
* content-sessionStore.js, which will call restoreDocument. At that point,
|
|
|
|
* form data is restored and the restore is complete.
|
|
|
|
*
|
|
|
|
* At any time, SessionStore.jsm can cancel the ongoing restore by sending a
|
|
|
|
* reset message, which causes resetRestore to be called. At that point it's
|
|
|
|
* legal to begin another restore.
|
|
|
|
*/
|
|
|
|
function ContentRestore(chromeGlobal) {
|
|
|
|
let internal = new ContentRestoreInternal(chromeGlobal);
|
|
|
|
let external = {};
|
|
|
|
|
|
|
|
let EXPORTED_METHODS = ["restoreHistory",
|
|
|
|
"restoreTabContent",
|
|
|
|
"restoreDocument",
|
2018-08-31 08:59:17 +03:00
|
|
|
"resetRestore",
|
2014-01-16 23:43:40 +04:00
|
|
|
];
|
|
|
|
|
|
|
|
for (let method of EXPORTED_METHODS) {
|
|
|
|
external[method] = internal[method].bind(internal);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Object.freeze(external);
|
|
|
|
}
|
|
|
|
|
|
|
|
function ContentRestoreInternal(chromeGlobal) {
|
|
|
|
this.chromeGlobal = chromeGlobal;
|
|
|
|
|
|
|
|
// The following fields are only valid during certain phases of the restore
|
|
|
|
// process.
|
|
|
|
|
|
|
|
// The tabData for the restore. Set in restoreHistory and removed in
|
|
|
|
// restoreTabContent.
|
|
|
|
this._tabData = null;
|
|
|
|
|
2017-07-21 11:35:20 +03:00
|
|
|
// Contains {entry, scrollPositions, formdata}, where entry is a
|
2014-01-16 23:43:40 +04:00
|
|
|
// single entry from the tabData.entries array. Set in
|
|
|
|
// restoreTabContent and removed in restoreDocument.
|
|
|
|
this._restoringDocument = null;
|
|
|
|
|
|
|
|
// This listener is used to detect reloads on restoring tabs. Set in
|
|
|
|
// restoreHistory and removed in restoreTabContent.
|
|
|
|
this._historyListener = null;
|
|
|
|
|
2015-02-24 22:29:36 +03:00
|
|
|
// This listener detects when a pending tab starts loading (when not
|
|
|
|
// initiated by sessionstore) and when a restoring tab has finished loading
|
|
|
|
// data from the network. Set in restoreHistory() and restoreTabContent(),
|
|
|
|
// removed in resetRestore().
|
2014-01-16 23:43:40 +04:00
|
|
|
this._progressListener = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The API for the ContentRestore module. Methods listed in EXPORTED_METHODS are
|
|
|
|
* public.
|
|
|
|
*/
|
|
|
|
ContentRestoreInternal.prototype = {
|
|
|
|
|
|
|
|
get docShell() {
|
|
|
|
return this.chromeGlobal.docShell;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Starts the process of restoring a tab. The tabData to be restored is passed
|
|
|
|
* in here and used throughout the restoration. The epoch (which must be
|
2015-02-24 22:29:36 +03:00
|
|
|
* non-zero) is passed through to all the callbacks. If a load in the tab
|
|
|
|
* is started while it is pending, the appropriate callbacks are called.
|
2014-01-16 23:43:40 +04:00
|
|
|
*/
|
2015-05-06 12:55:20 +03:00
|
|
|
restoreHistory(tabData, loadArguments, callbacks) {
|
2014-01-16 23:43:40 +04:00
|
|
|
this._tabData = tabData;
|
|
|
|
|
|
|
|
// In case about:blank isn't done yet.
|
|
|
|
let webNavigation = this.docShell.QueryInterface(Ci.nsIWebNavigation);
|
|
|
|
webNavigation.stop(Ci.nsIWebNavigation.STOP_ALL);
|
|
|
|
|
|
|
|
// Make sure currentURI is set so that switch-to-tab works before the tab is
|
|
|
|
// restored. We'll reset this to about:blank when we try to restore the tab
|
2015-04-15 04:03:40 +03:00
|
|
|
// to ensure that docshell doeesn't get confused. Don't bother doing this if
|
|
|
|
// we're restoring immediately due to a process switch. It just causes the
|
|
|
|
// URL bar to be temporarily blank.
|
2014-01-16 23:43:40 +04:00
|
|
|
let activeIndex = tabData.index - 1;
|
|
|
|
let activePageData = tabData.entries[activeIndex] || {};
|
|
|
|
let uri = activePageData.url || null;
|
2015-04-15 04:03:40 +03:00
|
|
|
if (uri && !loadArguments) {
|
2018-08-29 11:31:20 +03:00
|
|
|
webNavigation.setCurrentURI(Services.io.newURI(uri));
|
2014-01-16 23:43:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
SessionHistory.restore(this.docShell, tabData);
|
|
|
|
|
|
|
|
// Add a listener to watch for reloads.
|
2015-05-30 11:13:52 +03:00
|
|
|
let listener = new HistoryListener(this.docShell, () => {
|
|
|
|
// On reload, restore tab contents.
|
2016-04-21 19:55:42 +03:00
|
|
|
this.restoreTabContent(null, false, callbacks.onLoadFinished);
|
2015-05-30 11:13:52 +03:00
|
|
|
});
|
|
|
|
|
2018-02-02 01:17:00 +03:00
|
|
|
webNavigation.sessionHistory.legacySHistory.addSHistoryListener(listener);
|
2014-01-16 23:43:40 +04:00
|
|
|
this._historyListener = listener;
|
|
|
|
|
|
|
|
// Make sure to reset the capabilities and attributes in case this tab gets
|
|
|
|
// reused.
|
2018-10-23 11:15:56 +03:00
|
|
|
ssu.restoreDocShellCapabilities(this.docShell, tabData.disallow);
|
2014-01-16 23:43:40 +04:00
|
|
|
|
2014-12-20 01:10:43 +03:00
|
|
|
if (tabData.storage && this.docShell instanceof Ci.nsIDocShell) {
|
2014-01-16 23:43:40 +04:00
|
|
|
SessionStorage.restore(this.docShell, tabData.storage);
|
2014-12-20 01:10:43 +03:00
|
|
|
delete tabData.storage;
|
|
|
|
}
|
2015-02-24 22:29:36 +03:00
|
|
|
|
|
|
|
// Add a progress listener to correctly handle browser.loadURI()
|
|
|
|
// calls from foreign code.
|
|
|
|
this._progressListener = new ProgressListener(this.docShell, {
|
|
|
|
onStartRequest: () => {
|
|
|
|
// Some code called browser.loadURI() on a pending tab. It's safe to
|
|
|
|
// assume we don't care about restoring scroll or form data.
|
|
|
|
this._tabData = null;
|
|
|
|
|
|
|
|
// Listen for the tab to finish loading.
|
|
|
|
this.restoreTabContentStarted(callbacks.onLoadFinished);
|
|
|
|
|
|
|
|
// Notify the parent.
|
|
|
|
callbacks.onLoadStarted();
|
2018-08-31 08:59:17 +03:00
|
|
|
},
|
2015-02-24 22:29:36 +03:00
|
|
|
});
|
2014-01-16 23:43:40 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start loading the current page. When the data has finished loading from the
|
|
|
|
* network, finishCallback is called. Returns true if the load was successful.
|
|
|
|
*/
|
2017-03-10 22:51:20 +03:00
|
|
|
restoreTabContent(loadArguments, isRemotenessUpdate, finishCallback) {
|
2014-01-16 23:43:40 +04:00
|
|
|
let tabData = this._tabData;
|
|
|
|
this._tabData = null;
|
|
|
|
|
|
|
|
let webNavigation = this.docShell.QueryInterface(Ci.nsIWebNavigation);
|
2018-02-02 01:17:00 +03:00
|
|
|
let history = webNavigation.sessionHistory.legacySHistory;
|
2014-01-16 23:43:40 +04:00
|
|
|
|
2015-11-26 18:07:27 +03:00
|
|
|
// Listen for the tab to finish loading.
|
|
|
|
this.restoreTabContentStarted(finishCallback);
|
2014-01-16 23:43:40 +04:00
|
|
|
|
|
|
|
// Reset the current URI to about:blank. We changed it above for
|
|
|
|
// switch-to-tab, but now it must go back to the correct value before the
|
2015-04-15 04:03:40 +03:00
|
|
|
// load happens. Don't bother doing this if we're restoring immediately
|
|
|
|
// due to a process switch.
|
2016-04-21 19:55:42 +03:00
|
|
|
if (!isRemotenessUpdate) {
|
2018-08-29 11:31:20 +03:00
|
|
|
webNavigation.setCurrentURI(Services.io.newURI("about:blank"));
|
2015-04-15 04:03:40 +03:00
|
|
|
}
|
2014-01-16 23:43:40 +04:00
|
|
|
|
|
|
|
try {
|
2014-10-29 23:26:14 +03:00
|
|
|
if (loadArguments) {
|
|
|
|
// A load has been redirected to a new process so get history into the
|
|
|
|
// same state it was before the load started then trigger the load.
|
|
|
|
let referrer = loadArguments.referrer ?
|
2018-08-29 11:31:20 +03:00
|
|
|
Services.io.newURI(loadArguments.referrer) : null;
|
2017-03-10 22:51:20 +03:00
|
|
|
let referrerPolicy = ("referrerPolicy" in loadArguments
|
2015-03-05 10:29:55 +03:00
|
|
|
? loadArguments.referrerPolicy
|
2017-01-05 06:29:56 +03:00
|
|
|
: Ci.nsIHttpChannel.REFERRER_POLICY_UNSET);
|
2015-07-09 20:18:11 +03:00
|
|
|
let postData = loadArguments.postData ?
|
|
|
|
Utils.makeInputStream(loadArguments.postData) : null;
|
2017-01-18 10:24:55 +03:00
|
|
|
let triggeringPrincipal = loadArguments.triggeringPrincipal
|
|
|
|
? Utils.deserializePrincipal(loadArguments.triggeringPrincipal)
|
2018-11-05 17:05:19 +03:00
|
|
|
: Services.scriptSecurityManager.createNullPrincipal({});
|
2016-06-07 20:59:22 +03:00
|
|
|
|
|
|
|
if (loadArguments.userContextId) {
|
|
|
|
webNavigation.setOriginAttributesBeforeLoading({ userContextId: loadArguments.userContextId });
|
|
|
|
}
|
|
|
|
|
2015-03-05 10:29:55 +03:00
|
|
|
webNavigation.loadURIWithOptions(loadArguments.uri, loadArguments.flags,
|
2015-07-09 20:18:11 +03:00
|
|
|
referrer, referrerPolicy, postData,
|
2017-01-18 10:24:55 +03:00
|
|
|
null, null, triggeringPrincipal);
|
2014-10-29 23:26:14 +03:00
|
|
|
} else if (tabData.userTypedValue && tabData.userTypedClear) {
|
2014-01-16 23:43:40 +04:00
|
|
|
// If the user typed a URL into the URL bar and hit enter right before
|
|
|
|
// we crashed, we want to start loading that page again. A non-zero
|
|
|
|
// userTypedClear value means that the load had started.
|
|
|
|
// Load userTypedValue and fix up the URL if it's partial/broken.
|
|
|
|
webNavigation.loadURI(tabData.userTypedValue,
|
|
|
|
Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP,
|
2017-05-03 11:23:59 +03:00
|
|
|
null, null, null,
|
|
|
|
Services.scriptSecurityManager.getSystemPrincipal());
|
2014-01-16 23:43:40 +04:00
|
|
|
} else if (tabData.entries.length) {
|
|
|
|
// Stash away the data we need for restoreDocument.
|
|
|
|
let activeIndex = tabData.index - 1;
|
|
|
|
this._restoringDocument = {entry: tabData.entries[activeIndex] || {},
|
2013-12-03 21:56:33 +04:00
|
|
|
formdata: tabData.formdata || {},
|
2014-01-16 23:43:40 +04:00
|
|
|
scrollPositions: tabData.scroll || {}};
|
|
|
|
|
|
|
|
// In order to work around certain issues in session history, we need to
|
|
|
|
// force session history to update its internal index and call reload
|
|
|
|
// instead of gotoIndex. See bug 597315.
|
|
|
|
history.reloadCurrentEntry();
|
|
|
|
} else {
|
|
|
|
// If there's nothing to restore, we should still blank the page.
|
|
|
|
webNavigation.loadURI("about:blank",
|
|
|
|
Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_HISTORY,
|
2017-05-03 11:23:59 +03:00
|
|
|
null, null, null,
|
|
|
|
Services.scriptSecurityManager.getSystemPrincipal());
|
2014-01-16 23:43:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2016-10-28 00:18:50 +03:00
|
|
|
} catch (ex) {
|
|
|
|
if (ex instanceof Ci.nsIException) {
|
|
|
|
// Ignore page load errors, but return false to signal that the load never
|
|
|
|
// happened.
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-16 23:43:40 +04:00
|
|
|
}
|
2016-10-28 00:18:50 +03:00
|
|
|
return null;
|
2014-01-16 23:43:40 +04:00
|
|
|
},
|
|
|
|
|
2015-02-24 22:29:36 +03:00
|
|
|
/**
|
|
|
|
* To be called after restoreHistory(). Removes all listeners needed for
|
|
|
|
* pending tabs and makes sure to notify when the tab finished loading.
|
|
|
|
*/
|
|
|
|
restoreTabContentStarted(finishCallback) {
|
|
|
|
// The reload listener is no longer needed.
|
2015-11-26 18:07:27 +03:00
|
|
|
this._historyListener.uninstall();
|
|
|
|
this._historyListener = null;
|
2015-02-24 22:29:36 +03:00
|
|
|
|
|
|
|
// Remove the old progress listener.
|
2015-11-26 18:07:27 +03:00
|
|
|
this._progressListener.uninstall();
|
2015-02-24 22:29:36 +03:00
|
|
|
|
|
|
|
// We're about to start a load. This listener will be called when the load
|
|
|
|
// has finished getting everything from the network.
|
|
|
|
this._progressListener = new ProgressListener(this.docShell, {
|
2015-11-26 18:07:27 +03:00
|
|
|
onStopRequest: () => {
|
2015-02-24 22:29:36 +03:00
|
|
|
// Call resetRestore() to reset the state back to normal. The data
|
|
|
|
// needed for restoreDocument() (which hasn't happened yet) will
|
|
|
|
// remain in _restoringDocument.
|
|
|
|
this.resetRestore();
|
|
|
|
|
2015-11-26 18:07:27 +03:00
|
|
|
finishCallback();
|
2018-08-31 08:59:17 +03:00
|
|
|
},
|
2015-02-24 22:29:36 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-01-16 23:43:40 +04:00
|
|
|
/**
|
|
|
|
* Finish restoring the tab by filling in form data and setting the scroll
|
|
|
|
* position. The restore is complete when this function exits. It should be
|
|
|
|
* called when the "load" event fires for the restoring tab.
|
|
|
|
*/
|
2017-03-10 22:51:20 +03:00
|
|
|
restoreDocument() {
|
2014-01-16 23:43:40 +04:00
|
|
|
if (!this._restoringDocument) {
|
|
|
|
return;
|
|
|
|
}
|
2017-07-21 11:35:20 +03:00
|
|
|
let {formdata, scrollPositions} = this._restoringDocument;
|
2014-01-16 23:43:40 +04:00
|
|
|
this._restoringDocument = null;
|
|
|
|
|
2018-05-21 04:10:16 +03:00
|
|
|
let window = this.docShell.domWindow;
|
2014-01-16 23:43:40 +04:00
|
|
|
|
2017-08-02 20:08:04 +03:00
|
|
|
// Restore form data.
|
2018-10-23 11:17:51 +03:00
|
|
|
Utils.restoreFrameTreeData(window, formdata, (frame, data) => {
|
2017-08-02 20:08:04 +03:00
|
|
|
// restore() will return false, and thus abort restoration for the
|
|
|
|
// current |frame| and its descendants, if |data.url| is given but
|
|
|
|
// doesn't match the loaded document's URL.
|
|
|
|
return FormData.restore(frame, data);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Restore scroll data.
|
2018-10-23 11:17:51 +03:00
|
|
|
Utils.restoreFrameTreeData(window, scrollPositions, (frame, data) => {
|
2017-08-02 20:08:04 +03:00
|
|
|
if (data.scroll) {
|
2018-10-23 11:15:56 +03:00
|
|
|
ssu.restoreScrollPosition(frame, data.scroll);
|
2017-08-02 20:08:04 +03:00
|
|
|
}
|
|
|
|
});
|
2014-01-16 23:43:40 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cancel an ongoing restore. This function can be called any time between
|
|
|
|
* restoreHistory and restoreDocument.
|
|
|
|
*
|
|
|
|
* This function is called externally (if a restore is canceled) and
|
|
|
|
* internally (when the loads for a restore have finished). In the latter
|
|
|
|
* case, it's called before restoreDocument, so it cannot clear
|
|
|
|
* _restoringDocument.
|
|
|
|
*/
|
2017-03-10 22:51:20 +03:00
|
|
|
resetRestore() {
|
2014-01-16 23:43:40 +04:00
|
|
|
this._tabData = null;
|
|
|
|
|
|
|
|
if (this._historyListener) {
|
|
|
|
this._historyListener.uninstall();
|
|
|
|
}
|
|
|
|
this._historyListener = null;
|
|
|
|
|
|
|
|
if (this._progressListener) {
|
|
|
|
this._progressListener.uninstall();
|
|
|
|
}
|
|
|
|
this._progressListener = null;
|
2018-08-31 08:59:17 +03:00
|
|
|
},
|
2014-01-16 23:43:40 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This listener detects when a page being restored is reloaded. It triggers a
|
|
|
|
* callback and cancels the reload. The callback will send a message to
|
|
|
|
* SessionStore.jsm so that it can restore the content immediately.
|
|
|
|
*/
|
|
|
|
function HistoryListener(docShell, callback) {
|
|
|
|
let webNavigation = docShell.QueryInterface(Ci.nsIWebNavigation);
|
2018-02-02 01:17:00 +03:00
|
|
|
webNavigation.sessionHistory.legacySHistory.addSHistoryListener(this);
|
2014-01-16 23:43:40 +04:00
|
|
|
|
|
|
|
this.webNavigation = webNavigation;
|
|
|
|
this.callback = callback;
|
|
|
|
}
|
|
|
|
HistoryListener.prototype = {
|
2018-04-23 06:55:06 +03:00
|
|
|
QueryInterface: ChromeUtils.generateQI([
|
2014-01-16 23:43:40 +04:00
|
|
|
Ci.nsISHistoryListener,
|
2018-08-31 08:59:17 +03:00
|
|
|
Ci.nsISupportsWeakReference,
|
2014-01-16 23:43:40 +04:00
|
|
|
]),
|
|
|
|
|
2017-03-10 22:51:20 +03:00
|
|
|
uninstall() {
|
2018-02-02 01:17:00 +03:00
|
|
|
let shistory = this.webNavigation.sessionHistory.legacySHistory;
|
2014-06-18 16:48:12 +04:00
|
|
|
if (shistory) {
|
|
|
|
shistory.removeSHistoryListener(this);
|
|
|
|
}
|
2014-01-16 23:43:40 +04:00
|
|
|
},
|
|
|
|
|
2018-09-06 09:51:58 +03:00
|
|
|
OnHistoryGotoIndex(index, gotoURI) {},
|
|
|
|
OnHistoryPurge(numEntries) {},
|
2017-03-10 22:51:20 +03:00
|
|
|
OnHistoryReplaceEntry(index) {},
|
2014-01-16 23:43:40 +04:00
|
|
|
|
2015-02-24 22:29:36 +03:00
|
|
|
// This will be called for a pending tab when loadURI(uri) is called where
|
|
|
|
// the given |uri| only differs in the fragment.
|
|
|
|
OnHistoryNewEntry(newURI) {
|
2015-06-10 15:53:07 +03:00
|
|
|
let currentURI = this.webNavigation.currentURI;
|
|
|
|
|
|
|
|
// Ignore new SHistory entries with the same URI as those do not indicate
|
|
|
|
// a navigation inside a document by changing the #hash part of the URL.
|
|
|
|
// We usually hit this when purging session history for browsers.
|
|
|
|
if (currentURI && (currentURI.spec == newURI.spec)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-24 22:29:36 +03:00
|
|
|
// Reset the tab's URL to what it's actually showing. Without this loadURI()
|
|
|
|
// would use the current document and change the displayed URL only.
|
2018-08-29 11:31:20 +03:00
|
|
|
this.webNavigation.setCurrentURI(Services.io.newURI("about:blank"));
|
2015-02-24 22:29:36 +03:00
|
|
|
|
|
|
|
// Kick off a new load so that we navigate away from about:blank to the
|
|
|
|
// new URL that was passed to loadURI(). The new load will cause a
|
|
|
|
// STATE_START notification to be sent and the ProgressListener will then
|
|
|
|
// notify the parent and do the rest.
|
|
|
|
let flags = Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP;
|
2017-05-03 11:23:59 +03:00
|
|
|
this.webNavigation.loadURI(newURI.spec, flags,
|
|
|
|
null, null, null,
|
|
|
|
Services.scriptSecurityManager.getSystemPrincipal());
|
2015-02-24 22:29:36 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
OnHistoryReload(reloadURI, reloadFlags) {
|
2014-01-16 23:43:40 +04:00
|
|
|
this.callback();
|
|
|
|
|
|
|
|
// Cancel the load.
|
|
|
|
return false;
|
|
|
|
},
|
2017-10-15 21:50:30 +03:00
|
|
|
};
|
2014-01-16 23:43:40 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This class informs SessionStore.jsm whenever the network requests for a
|
|
|
|
* restoring page have completely finished. We only restore three tabs
|
|
|
|
* simultaneously, so this is the signal for SessionStore.jsm to kick off
|
|
|
|
* another restore (if there are more to do).
|
2015-02-24 22:29:36 +03:00
|
|
|
*
|
|
|
|
* The progress listener is also used to be notified when a load not initiated
|
|
|
|
* by sessionstore starts. Pending tabs will then need to be marked as no
|
|
|
|
* longer pending.
|
2014-01-16 23:43:40 +04:00
|
|
|
*/
|
2015-02-24 22:29:36 +03:00
|
|
|
function ProgressListener(docShell, callbacks) {
|
2014-01-16 23:43:40 +04:00
|
|
|
let webProgress = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebProgress);
|
|
|
|
webProgress.addProgressListener(this, Ci.nsIWebProgress.NOTIFY_STATE_WINDOW);
|
|
|
|
|
|
|
|
this.webProgress = webProgress;
|
2015-02-24 22:29:36 +03:00
|
|
|
this.callbacks = callbacks;
|
2014-01-16 23:43:40 +04:00
|
|
|
}
|
2015-02-24 22:29:36 +03:00
|
|
|
|
2014-01-16 23:43:40 +04:00
|
|
|
ProgressListener.prototype = {
|
2018-04-23 06:55:06 +03:00
|
|
|
QueryInterface: ChromeUtils.generateQI([
|
2014-01-16 23:43:40 +04:00
|
|
|
Ci.nsIWebProgressListener,
|
2018-08-31 08:59:17 +03:00
|
|
|
Ci.nsISupportsWeakReference,
|
2014-01-16 23:43:40 +04:00
|
|
|
]),
|
|
|
|
|
2017-03-10 22:51:20 +03:00
|
|
|
uninstall() {
|
2014-01-16 23:43:40 +04:00
|
|
|
this.webProgress.removeProgressListener(this);
|
|
|
|
},
|
|
|
|
|
2017-03-10 22:51:20 +03:00
|
|
|
onStateChange(webProgress, request, stateFlags, status) {
|
2015-02-24 22:29:36 +03:00
|
|
|
let {STATE_IS_WINDOW, STATE_STOP, STATE_START} = Ci.nsIWebProgressListener;
|
|
|
|
if (!webProgress.isTopLevel || !(stateFlags & STATE_IS_WINDOW)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stateFlags & STATE_START && this.callbacks.onStartRequest) {
|
|
|
|
this.callbacks.onStartRequest();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stateFlags & STATE_STOP && this.callbacks.onStopRequest) {
|
2015-11-26 18:07:27 +03:00
|
|
|
this.callbacks.onStopRequest();
|
2014-01-16 23:43:40 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|