2012-04-17 18:11:53 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
|
|
|
|
function CommandLineHandler() {}
|
|
|
|
|
|
|
|
CommandLineHandler.prototype = {
|
|
|
|
classID: Components.ID("{6d69c782-40a3-469b-8bfd-3ee366105a4a}"),
|
|
|
|
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]),
|
|
|
|
|
|
|
|
handle: function handle(cmdLine) {
|
2012-06-30 02:52:43 +04:00
|
|
|
let args = Cc["@mozilla.org/hash-property-bag;1"].
|
|
|
|
createInstance(Ci.nsIWritablePropertyBag);
|
|
|
|
let inTestMode = this._handleTestMode(cmdLine, args);
|
|
|
|
|
2012-08-15 02:27:26 +04:00
|
|
|
if (inTestMode) {
|
|
|
|
// Open the mochitest shim window, which configures the runtime for tests.
|
|
|
|
Services.ww.openWindow(null,
|
|
|
|
"chrome://webapprt/content/mochitest.xul",
|
|
|
|
"_blank",
|
|
|
|
"chrome,dialog=no",
|
|
|
|
args);
|
2012-06-30 02:52:43 +04:00
|
|
|
} else {
|
2013-08-16 23:17:52 +04:00
|
|
|
// We're opening the window here in order to show it as soon as possible.
|
|
|
|
let window = Services.ww.openWindow(null,
|
|
|
|
"chrome://webapprt/content/webapp.xul",
|
|
|
|
"_blank",
|
|
|
|
"chrome,dialog=no,resizable,scrollbars,centerscreen",
|
|
|
|
null);
|
|
|
|
// Load the module to start up the app
|
|
|
|
Cu.import("resource://webapprt/modules/Startup.jsm");
|
2014-03-27 15:56:00 +04:00
|
|
|
startup(window).then(null, function (aError) {
|
|
|
|
dump("Error: " + aError + "\n");
|
|
|
|
Services.startup.quit(Ci.nsIAppStartup.eAttemptQuit);
|
|
|
|
});
|
2012-06-30 02:52:43 +04:00
|
|
|
}
|
|
|
|
},
|
2012-06-22 01:06:24 +04:00
|
|
|
|
2012-06-30 02:52:43 +04:00
|
|
|
_handleTestMode: function _handleTestMode(cmdLine, args) {
|
|
|
|
// -test-mode [url]
|
|
|
|
let idx = cmdLine.findFlag("test-mode", true);
|
|
|
|
if (idx < 0)
|
|
|
|
return false;
|
2012-08-15 02:27:26 +04:00
|
|
|
let url;
|
2012-06-30 02:52:43 +04:00
|
|
|
let urlIdx = idx + 1;
|
|
|
|
if (urlIdx < cmdLine.length) {
|
|
|
|
let potentialURL = cmdLine.getArgument(urlIdx);
|
|
|
|
if (potentialURL && potentialURL[0] != "-") {
|
|
|
|
try {
|
2012-08-15 02:27:26 +04:00
|
|
|
url = Services.io.newURI(potentialURL, null, null);
|
2012-06-30 02:52:43 +04:00
|
|
|
} catch (err) {
|
|
|
|
throw Components.Exception(
|
2012-08-15 02:27:26 +04:00
|
|
|
"-test-mode argument is not a valid URL: " + potentialURL,
|
2012-06-30 02:52:43 +04:00
|
|
|
Components.results.NS_ERROR_INVALID_ARG);
|
|
|
|
}
|
|
|
|
cmdLine.removeArguments(urlIdx, urlIdx);
|
2012-08-15 02:27:26 +04:00
|
|
|
args.setProperty("url", url.spec);
|
2012-06-30 02:52:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
cmdLine.removeArguments(idx, idx);
|
|
|
|
return true;
|
2012-04-17 18:11:53 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
helpInfo : "",
|
|
|
|
};
|
|
|
|
|
2015-09-15 21:19:45 +03:00
|
|
|
var components = [CommandLineHandler];
|
2012-10-31 20:13:28 +04:00
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
|