Permalink
Browse files

Allow setting the context wherein the repl should start, via command-…

…line (for automatically started repl) or prefs (for the rest), by window type.
  • Loading branch information...
1 parent db558d7 commit 81a55bb5406ca8e4e2e494cec226bdb53b9e28a4 @bard bard committed Aug 9, 2011
Showing with 37 additions and 12 deletions.
  1. +13 −5 chrome/content/server.js
  2. +23 −7 components/CommandLine.js
  3. +1 −0 defaults/preferences/mozrepl.js
View
18 chrome/content/server.js
@@ -58,6 +58,7 @@ loader.loadSubScript('chrome://mozrepl/content/repl.js', REPL.prototype);
// ----------------------------------------------------------------------
var serv;
+var contextWindowType;
// CODE
@@ -115,12 +116,11 @@ function onSocketAccepted(serv, transport) {
} catch(e) {
log('E, MOZREPL : Error : ' + e);
}
- log('I, MOZREPL : Client connected : ' + transport.host + ':' + transport.port);
- var window = Cc['@mozilla.org/appshell/window-mediator;1']
+ var context = Cc['@mozilla.org/appshell/window-mediator;1']
.getService(Ci.nsIWindowMediator)
- .getMostRecentWindow('');
-
+ .getMostRecentWindow(typeof(contextWindowType) !== 'undefined' ?
+ contextWindowType : pref.getCharPref('startingContext'));
var session = new REPL();
session.onOutput = function(string) {
outstream.write(string, string.length);
@@ -131,7 +131,11 @@ function onSocketAccepted(serv, transport) {
outstream.close();
sessions.remove(session);
};
- session.init(window);
+ session.init(context);
+
+ log('I, MOZREPL : Client connected : ' + transport.host + ':' + transport.port +
+ ' : ' + (context instanceof Ci.nsIDOMWindow ?
+ context.document.location.href : context));
var pump = Cc['@mozilla.org/network/input-stream-pump;1']
.createInstance(Ci.nsIInputStreamPump);
@@ -194,6 +198,10 @@ function observe(subject, topic, data) {
}
}
+function setContextWindowType(windowType) {
+ contextWindowType = windowType;
+}
+
// UTILITIES
// ----------------------------------------------------------------------
View
30 components/CommandLine.js
@@ -24,18 +24,34 @@ MozReplCommandLineHandler.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]),
handle: function(cmdLine) {
- var port;
+ var start;
try {
- port = parseInt(cmdLine.handleFlagWithParam('repl', false));
+ start = cmdLine.handleFlag('repl', false);
} catch (e) {}
- if(port || cmdLine.handleFlag('repl', false))
- Cc['@hyperstruct.net/mozlab/mozrepl;1']
- .getService(Ci.nsIMozRepl)
- .start(port || srvPref.getIntPref('port'));
+ var contextWindowType;
+ try {
+ contextWindowType = cmdLine.handleFlagWithParam('repl-context', false);
+ } catch(e) {}
+
+ if(start || contextWindowType) {
+ var port = Number(cmdLine.handleFlagWithParam('repl', false)) ||
+ srvPref.getIntPref('port');
+
+ var service = Cc['@hyperstruct.net/mozlab/mozrepl;1']
+ .getService(Ci.nsIMozRepl)
+ .wrappedJSObject;
+
+ if(contextWindowType)
+ service.setContextWindowType(contextWindowType);
+
+ service.start(port);
+ }
},
- helpInfo: '-repl Start REPL.\n'
+ helpInfo: ['-repl Start REPL.\n',
+ '-repl-context Start in the context gives as window type (see XUL windowtype attribute).\n'].join('')
+
};
/**
View
1 defaults/preferences/mozrepl.js
@@ -5,3 +5,4 @@ pref("extensions.mozrepl.loopbackOnly", true);
pref("extensions.mozrepl.version", "");
pref("extensions.mozrepl.defaultInteractor", "javascript");
pref("extensions.mozrepl.interactor.javascript.printWelcome", true);
+pref("extensions.mozrepl.startingContext", "");

0 comments on commit 81a55bb

Please sign in to comment.