DevTools - Browser Console - restore sessions

https://github.com/MoonchildProductions/moebius/pull/112
This commit is contained in:
janekptacijarabaci 2018-03-01 07:17:50 +01:00 committed by Roy Tam
commit 63ba51f58e
17 changed files with 135 additions and 46 deletions

View file

@ -51,6 +51,23 @@ HUD_SERVICE.prototype =
*/
consoles: null,
_browerConsoleSessionState: false,
storeBrowserConsoleSessionState() {
this._browerConsoleSessionState = !!this.getBrowserConsole();
},
getBrowserConsoleSessionState() {
return this._browerConsoleSessionState;
},
/**
* Restore the Browser Console as provided by SessionStore.
*/
restoreBrowserConsoleSession: function HS_restoreBrowserConsoleSession() {
if (!HUDService.getBrowserConsole()) {
HUDService.toggleBrowserConsole();
}
},
/**
* Assign a function to this property to listen for every request that
* completes. Used by unit tests. The callback takes one argument: the HTTP
@ -647,6 +664,9 @@ BrowserConsole.prototype = extend(WebConsole.prototype, {
return this._bc_init;
}
// Only add the shutdown observer if we've opened a Browser Console window.
ShutdownObserver.init();
this.ui._filterPrefsPrefix = BROWSER_CONSOLE_FILTER_PREFS_PREFIX;
let window = this.iframeWindow;
@ -702,17 +722,32 @@ BrowserConsole.prototype = extend(WebConsole.prototype, {
},
});
const HUDService = new HUD_SERVICE();
exports.HUDService = HUDService;
(() => {
let methods = ["openWebConsole", "openBrowserConsole",
"toggleBrowserConsole", "getOpenWebConsole",
"getBrowserConsole", "getHudByWindow",
"openBrowserConsoleOrFocus", "getHudReferenceById"];
for (let method of methods) {
exports[method] = HUDService[method].bind(HUDService);
/**
* The ShutdownObserver listens for app shutdown and saves the current state
* of the Browser Console for session restore.
*/
var ShutdownObserver = {
_initialized: false,
init() {
if (this._initialized) {
return;
}
Services.obs.addObserver(this, "quit-application-granted", false);
this._initialized = true;
},
observe(message, topic) {
if (topic == "quit-application-granted") {
HUDService.storeBrowserConsoleSessionState();
this.uninit();
}
},
uninit() {
Services.obs.removeObserver(this, "quit-application-granted");
}
exports.consoles = HUDService.consoles;
exports.lastFinishedRequest = HUDService.lastFinishedRequest;
})();
};