Skip to content

Commit

Permalink
Properly shutdown when the extension is uninstalled/disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
janodvarko committed May 7, 2012
1 parent 68bf076 commit db2ea57
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
24 changes: 21 additions & 3 deletions bootstrap.js
Expand Up @@ -58,8 +58,14 @@ function shutdown(data, reason)
// Remove "new window" listener.
Services.ww.unregisterNotification(windowWatcher);

// xxxHonza: close the XUL window if it's opened.
// xxxHonza: shutdown the server (in case we are in server mode)
// Close all HTTP Monitor windows
var win;
while (win = Services.wm.getMostRecentWindow("HTTPMonitor"))
win.close();

// Shutdown the server (in case we are in server mode).
unloadServer();

// xxxHonza: remove all default preferences
// xxxHonza: remove all loaded *.jsm modules (those from modules directory)
}
Expand Down Expand Up @@ -108,6 +114,8 @@ function unloadBrowserOverlay(win)
// ********************************************************************************************* //
// Server

var serverScope = {};

function loadServer()
{
var serverMode = false;
Expand All @@ -124,14 +132,24 @@ function loadServer()
try
{
if (serverMode)
Services.scriptloader.loadSubScript("chrome://httpmonitor/content/server/main.js");
{
Services.scriptloader.loadSubScript(
"chrome://httpmonitor/content/server/main.js",
serverScope);
}
}
catch (e)
{
Cu.reportError(e);
}
}

function unloadServer()
{
if (serverScope.HttpServer)
serverScope.HttpServer.shutdown();
}

// ********************************************************************************************* //
// Window Listener

Expand Down
5 changes: 4 additions & 1 deletion content/httpmonitor/server/httpServer.js
Expand Up @@ -47,7 +47,6 @@ var HttpServer =
if (typeof(RemoteDebugger) != "undefined")
{
RemoteDebugger._start();
dump("--> httpServer; RemoteDebugger started at: " + RemoteDebugger._getPort());
}
// Otherwise initialize the browser debugger.
else if (!DebuggerServer.initialized)
Expand Down Expand Up @@ -81,6 +80,10 @@ var HttpServer =

shutdown: function()
{
FBTrace.sysout("HttpServer; shutdown");

// xxxHonza: what if there are other tools sharing the connection?
DebuggerServer.closeListener();
},
}

Expand Down
7 changes: 5 additions & 2 deletions content/httpmonitor/server/main.js
@@ -1,6 +1,6 @@
/* See license.txt for terms of usage */

(function() {
(function(scope) {

// ********************************************************************************************* //

Expand Down Expand Up @@ -42,11 +42,14 @@ try
], function() {
consoleService.logStringMessage("HttpServer; Running at port: 2929");
});

// Set back-reference for the bootstrap.js so, shutdown can be sent to HttpServer object.
scope.HttpServer = HttpServer;
}
catch (e)
{
FBTrace.sysout("main.initialize; EXCEPTION " + e, e);
}

// ********************************************************************************************* //
})})();
})})(this);

0 comments on commit db2ea57

Please sign in to comment.