webapprt/CommandLineHandler.js

Wed, 31 Dec 2014 07:53:36 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:53:36 +0100
branch
TOR_BUG_3246
changeset 5
4ab42b5ab56c
permissions
-rw-r--r--

Correct small whitespace inconsistency, lost while renaming variables.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 const Cc = Components.classes;
michael@0 6 const Ci = Components.interfaces;
michael@0 7 const Cu = Components.utils;
michael@0 8
michael@0 9 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
michael@0 10 Cu.import("resource://gre/modules/Services.jsm");
michael@0 11
michael@0 12 function CommandLineHandler() {}
michael@0 13
michael@0 14 CommandLineHandler.prototype = {
michael@0 15 classID: Components.ID("{6d69c782-40a3-469b-8bfd-3ee366105a4a}"),
michael@0 16
michael@0 17 QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]),
michael@0 18
michael@0 19 handle: function handle(cmdLine) {
michael@0 20 let args = Cc["@mozilla.org/hash-property-bag;1"].
michael@0 21 createInstance(Ci.nsIWritablePropertyBag);
michael@0 22 let inTestMode = this._handleTestMode(cmdLine, args);
michael@0 23
michael@0 24 let debugPort = this._handleDebugMode(cmdLine);
michael@0 25 if (!isNaN(debugPort)) {
michael@0 26 Cu.import("resource://webapprt/modules/RemoteDebugger.jsm");
michael@0 27 RemoteDebugger.init(debugPort);
michael@0 28 }
michael@0 29
michael@0 30 if (inTestMode) {
michael@0 31 // Open the mochitest shim window, which configures the runtime for tests.
michael@0 32 Services.ww.openWindow(null,
michael@0 33 "chrome://webapprt/content/mochitest.xul",
michael@0 34 "_blank",
michael@0 35 "chrome,dialog=no",
michael@0 36 args);
michael@0 37 } else {
michael@0 38 // We're opening the window here in order to show it as soon as possible.
michael@0 39 let window = Services.ww.openWindow(null,
michael@0 40 "chrome://webapprt/content/webapp.xul",
michael@0 41 "_blank",
michael@0 42 "chrome,dialog=no,resizable,scrollbars,centerscreen",
michael@0 43 null);
michael@0 44 // Load the module to start up the app
michael@0 45 Cu.import("resource://webapprt/modules/Startup.jsm");
michael@0 46 startup(window).then(null, function (aError) {
michael@0 47 dump("Error: " + aError + "\n");
michael@0 48 Services.startup.quit(Ci.nsIAppStartup.eAttemptQuit);
michael@0 49 });
michael@0 50 }
michael@0 51 },
michael@0 52
michael@0 53 /**
michael@0 54 * Handle debug command line option.
michael@0 55 *
michael@0 56 * @param cmdLine A nsICommandLine object.
michael@0 57 *
michael@0 58 * @returns the port number if it's specified, the default port number if
michael@0 59 * the debug option is specified, NaN if the debug option isn't
michael@0 60 * specified or the port number isn't valid.
michael@0 61 */
michael@0 62 _handleDebugMode: function(cmdLine) {
michael@0 63 // -debug [port]
michael@0 64 let idx = cmdLine.findFlag("debug", true);
michael@0 65 if (idx < 0) {
michael@0 66 return NaN;
michael@0 67 }
michael@0 68
michael@0 69 let port;
michael@0 70 let portIdx = idx + 1;
michael@0 71 if (portIdx < cmdLine.length) {
michael@0 72 port = parseInt(cmdLine.getArgument(portIdx));
michael@0 73 if (port != NaN) {
michael@0 74 return port;
michael@0 75 }
michael@0 76 }
michael@0 77
michael@0 78 return Services.prefs.getIntPref('devtools.debugger.remote-port');
michael@0 79 },
michael@0 80
michael@0 81 _handleTestMode: function _handleTestMode(cmdLine, args) {
michael@0 82 // -test-mode [url]
michael@0 83 let idx = cmdLine.findFlag("test-mode", true);
michael@0 84 if (idx < 0)
michael@0 85 return false;
michael@0 86 let url;
michael@0 87 let urlIdx = idx + 1;
michael@0 88 if (urlIdx < cmdLine.length) {
michael@0 89 let potentialURL = cmdLine.getArgument(urlIdx);
michael@0 90 if (potentialURL && potentialURL[0] != "-") {
michael@0 91 try {
michael@0 92 url = Services.io.newURI(potentialURL, null, null);
michael@0 93 } catch (err) {
michael@0 94 throw Components.Exception(
michael@0 95 "-test-mode argument is not a valid URL: " + potentialURL,
michael@0 96 Components.results.NS_ERROR_INVALID_ARG);
michael@0 97 }
michael@0 98 cmdLine.removeArguments(urlIdx, urlIdx);
michael@0 99 args.setProperty("url", url.spec);
michael@0 100 }
michael@0 101 }
michael@0 102 cmdLine.removeArguments(idx, idx);
michael@0 103 return true;
michael@0 104 },
michael@0 105
michael@0 106 helpInfo : "",
michael@0 107 };
michael@0 108
michael@0 109 let components = [CommandLineHandler];
michael@0 110 this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components);

mercurial