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