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");
11 Cu.import("resource://webapprt/modules/WebappRT.jsm");
13 function CommandLineHandler() {}
15 CommandLineHandler.prototype = {
16 classID: Components.ID("{6d69c782-40a3-469b-8bfd-3ee366105a4a}"),
18 QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]),
20 handle: function handle(cmdLine) {
21 let args = Cc["@mozilla.org/hash-property-bag;1"].
22 createInstance(Ci.nsIWritablePropertyBag);
23 let inTestMode = this._handleTestMode(cmdLine, args);
26 // Open the mochitest shim window, which configures the runtime for tests.
27 Services.ww.openWindow(null,
28 "chrome://webapprt/content/mochitest.xul",
33 args.setProperty("url", WebappRT.launchURI.spec);
34 Services.ww.openWindow(null,
35 "chrome://webapprt/content/webapp.xul",
37 "chrome,dialog=no,resizable,scrollbars,centerscreen",
42 _handleTestMode: function _handleTestMode(cmdLine, args) {
44 let idx = cmdLine.findFlag("test-mode", true);
49 if (urlIdx < cmdLine.length) {
50 let potentialURL = cmdLine.getArgument(urlIdx);
51 if (potentialURL && potentialURL[0] != "-") {
53 url = Services.io.newURI(potentialURL, null, null);
55 throw Components.Exception(
56 "-test-mode argument is not a valid URL: " + potentialURL,
57 Components.results.NS_ERROR_INVALID_ARG);
59 cmdLine.removeArguments(urlIdx, urlIdx);
60 args.setProperty("url", url.spec);
63 cmdLine.removeArguments(idx, idx);
70 let components = [CommandLineHandler];
71 this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components);