michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: const Cc = Components.classes; michael@0: const Ci = Components.interfaces; michael@0: const Cu = Components.utils; michael@0: michael@0: Cu.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: function CommandLineHandler() {} michael@0: michael@0: CommandLineHandler.prototype = { michael@0: classID: Components.ID("{6d69c782-40a3-469b-8bfd-3ee366105a4a}"), michael@0: michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]), michael@0: michael@0: handle: function handle(cmdLine) { michael@0: let args = Cc["@mozilla.org/hash-property-bag;1"]. michael@0: createInstance(Ci.nsIWritablePropertyBag); michael@0: let inTestMode = this._handleTestMode(cmdLine, args); michael@0: michael@0: let debugPort = this._handleDebugMode(cmdLine); michael@0: if (!isNaN(debugPort)) { michael@0: Cu.import("resource://webapprt/modules/RemoteDebugger.jsm"); michael@0: RemoteDebugger.init(debugPort); michael@0: } michael@0: michael@0: if (inTestMode) { michael@0: // Open the mochitest shim window, which configures the runtime for tests. michael@0: Services.ww.openWindow(null, michael@0: "chrome://webapprt/content/mochitest.xul", michael@0: "_blank", michael@0: "chrome,dialog=no", michael@0: args); michael@0: } else { michael@0: // We're opening the window here in order to show it as soon as possible. michael@0: let window = Services.ww.openWindow(null, michael@0: "chrome://webapprt/content/webapp.xul", michael@0: "_blank", michael@0: "chrome,dialog=no,resizable,scrollbars,centerscreen", michael@0: null); michael@0: // Load the module to start up the app michael@0: Cu.import("resource://webapprt/modules/Startup.jsm"); michael@0: startup(window).then(null, function (aError) { michael@0: dump("Error: " + aError + "\n"); michael@0: Services.startup.quit(Ci.nsIAppStartup.eAttemptQuit); michael@0: }); michael@0: } michael@0: }, michael@0: michael@0: /** michael@0: * Handle debug command line option. michael@0: * michael@0: * @param cmdLine A nsICommandLine object. michael@0: * michael@0: * @returns the port number if it's specified, the default port number if michael@0: * the debug option is specified, NaN if the debug option isn't michael@0: * specified or the port number isn't valid. michael@0: */ michael@0: _handleDebugMode: function(cmdLine) { michael@0: // -debug [port] michael@0: let idx = cmdLine.findFlag("debug", true); michael@0: if (idx < 0) { michael@0: return NaN; michael@0: } michael@0: michael@0: let port; michael@0: let portIdx = idx + 1; michael@0: if (portIdx < cmdLine.length) { michael@0: port = parseInt(cmdLine.getArgument(portIdx)); michael@0: if (port != NaN) { michael@0: return port; michael@0: } michael@0: } michael@0: michael@0: return Services.prefs.getIntPref('devtools.debugger.remote-port'); michael@0: }, michael@0: michael@0: _handleTestMode: function _handleTestMode(cmdLine, args) { michael@0: // -test-mode [url] michael@0: let idx = cmdLine.findFlag("test-mode", true); michael@0: if (idx < 0) michael@0: return false; michael@0: let url; michael@0: let urlIdx = idx + 1; michael@0: if (urlIdx < cmdLine.length) { michael@0: let potentialURL = cmdLine.getArgument(urlIdx); michael@0: if (potentialURL && potentialURL[0] != "-") { michael@0: try { michael@0: url = Services.io.newURI(potentialURL, null, null); michael@0: } catch (err) { michael@0: throw Components.Exception( michael@0: "-test-mode argument is not a valid URL: " + potentialURL, michael@0: Components.results.NS_ERROR_INVALID_ARG); michael@0: } michael@0: cmdLine.removeArguments(urlIdx, urlIdx); michael@0: args.setProperty("url", url.spec); michael@0: } michael@0: } michael@0: cmdLine.removeArguments(idx, idx); michael@0: return true; michael@0: }, michael@0: michael@0: helpInfo : "", michael@0: }; michael@0: michael@0: let components = [CommandLineHandler]; michael@0: this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components);