Bug 783551 - Get tooltool running on the b2g on OS X builds. r=respindola
[gecko.git] / webapprt / CommandLineHandler.js
bloba90e46e6de7fee300e704b5cdb57fd46d847eb98
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);
25     if (inTestMode) {
26       // Open the mochitest shim window, which configures the runtime for tests.
27       Services.ww.openWindow(null,
28                              "chrome://webapprt/content/mochitest.xul",
29                              "_blank",
30                              "chrome,dialog=no",
31                              args);
32     } else {
33       args.setProperty("url", WebappRT.launchURI.spec);
34       Services.ww.openWindow(null,
35                              "chrome://webapprt/content/webapp.xul",
36                              "_blank",
37                              "chrome,dialog=no,resizable,scrollbars,centerscreen",
38                              args);
39     }
40   },
42   _handleTestMode: function _handleTestMode(cmdLine, args) {
43     // -test-mode [url]
44     let idx = cmdLine.findFlag("test-mode", true);
45     if (idx < 0)
46       return false;
47     let url;
48     let urlIdx = idx + 1;
49     if (urlIdx < cmdLine.length) {
50       let potentialURL = cmdLine.getArgument(urlIdx);
51       if (potentialURL && potentialURL[0] != "-") {
52         try {
53           url = Services.io.newURI(potentialURL, null, null);
54         } catch (err) {
55           throw Components.Exception(
56             "-test-mode argument is not a valid URL: " + potentialURL,
57             Components.results.NS_ERROR_INVALID_ARG);
58         }
59         cmdLine.removeArguments(urlIdx, urlIdx);
60         args.setProperty("url", url.spec);
61       }
62     }
63     cmdLine.removeArguments(idx, idx);
64     return true;
65   },
67   helpInfo : "",
70 let components = [CommandLineHandler];
71 let NSGetFactory = XPCOMUtils.generateNSGetFactory(components);