2012-04-17 07:11:53 -07: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-29 15:52:43 -07:00
|
|
|
let args = Cc["@mozilla.org/hash-property-bag;1"].
|
|
|
|
createInstance(Ci.nsIWritablePropertyBag);
|
|
|
|
let inTestMode = this._handleTestMode(cmdLine, args);
|
|
|
|
Services.obs.notifyObservers(args, "webapprt-command-line", null);
|
|
|
|
|
|
|
|
// Initialize DOMApplicationRegistry by importing Webapps.jsm, but only
|
|
|
|
// after broadcasting webapprt-command-line. Webapps.jsm calls
|
|
|
|
// DOMApplicationRegistry.init() when it's first imported. init() accesses
|
|
|
|
// the WebappRegD directory, which in test mode is special-cased by
|
|
|
|
// DirectoryProvider.js after it observes webapprt-command-line.
|
|
|
|
Cu.import("resource://gre/modules/Webapps.jsm");
|
|
|
|
|
|
|
|
if (!inTestMode) {
|
2012-07-10 15:07:31 -07:00
|
|
|
startUp(inTestMode);
|
2012-06-29 15:52:43 -07:00
|
|
|
} else {
|
2012-07-13 15:49:40 -07:00
|
|
|
DOMApplicationRegistry.allAppsLaunchable = true;
|
|
|
|
|
2012-06-29 15:52:43 -07:00
|
|
|
// startUp() accesses WebappRT.config, which in test mode is not valid
|
|
|
|
// until WebappRT.jsm observes an app installation.
|
|
|
|
Services.obs.addObserver(function onInstall(subj, topic, data) {
|
|
|
|
Services.obs.removeObserver(onInstall, "webapprt-test-did-install");
|
2012-07-10 15:07:31 -07:00
|
|
|
startUp(inTestMode);
|
2012-06-29 15:52:43 -07:00
|
|
|
}, "webapprt-test-did-install", false);
|
|
|
|
}
|
|
|
|
|
2012-04-26 16:55:25 -07:00
|
|
|
// Open the window with arguments to identify it as the main window
|
2012-04-17 07:11:53 -07:00
|
|
|
Services.ww.openWindow(null,
|
|
|
|
"chrome://webapprt/content/webapp.xul",
|
|
|
|
"_blank",
|
2012-06-28 22:27:09 -07:00
|
|
|
"chrome,dialog=no,resizable,scrollbars,centerscreen",
|
2012-06-29 15:52:43 -07:00
|
|
|
args);
|
|
|
|
},
|
2012-06-21 14:06:24 -07:00
|
|
|
|
2012-06-29 15:52:43 -07:00
|
|
|
_handleTestMode: function _handleTestMode(cmdLine, args) {
|
|
|
|
// -test-mode [url]
|
|
|
|
let idx = cmdLine.findFlag("test-mode", true);
|
|
|
|
if (idx < 0)
|
|
|
|
return false;
|
|
|
|
let url = null;
|
|
|
|
let urlIdx = idx + 1;
|
|
|
|
if (urlIdx < cmdLine.length) {
|
|
|
|
let potentialURL = cmdLine.getArgument(urlIdx);
|
|
|
|
if (potentialURL && potentialURL[0] != "-") {
|
|
|
|
url = potentialURL;
|
|
|
|
try {
|
|
|
|
Services.io.newURI(url, null, null);
|
|
|
|
} catch (err) {
|
|
|
|
throw Components.Exception(
|
|
|
|
"-test-mode argument is not a valid URL: " + url,
|
|
|
|
Components.results.NS_ERROR_INVALID_ARG);
|
|
|
|
}
|
|
|
|
cmdLine.removeArguments(urlIdx, urlIdx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cmdLine.removeArguments(idx, idx);
|
|
|
|
args.setProperty("test-mode", url);
|
|
|
|
return true;
|
2012-04-17 07:11:53 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
helpInfo : "",
|
|
|
|
};
|
|
|
|
|
|
|
|
let components = [CommandLineHandler];
|
|
|
|
let NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
|
2012-05-31 13:30:40 -07:00
|
|
|
|
|
|
|
/* There's some work we need to do on startup, before we load the webapp,
|
|
|
|
* and this seems as good a place as any to do it, although it's possible
|
|
|
|
* that in the future we will find a lazier place to do it.
|
|
|
|
*
|
|
|
|
* NOTE: it's very important that the stuff we do here doesn't prevent
|
|
|
|
* the command-line handler from being registered/accessible, since otherwise
|
|
|
|
* the app won't start, which is catastrophic failure. That's why it's all
|
|
|
|
* wrapped in a try/catch block. */
|
2012-06-29 15:52:43 -07:00
|
|
|
function startUp(inTestMode) {
|
|
|
|
try {
|
|
|
|
if (!inTestMode) {
|
|
|
|
// Initialize window-independent handling of webapps- notifications. Skip
|
|
|
|
// this in test mode, since it interferes with test app installations.
|
|
|
|
// We'll have to revisit this when we actually want to test installations
|
|
|
|
// and other functionality provided by WebappsHandler.
|
|
|
|
Cu.import("resource://webapprt/modules/WebappsHandler.jsm");
|
|
|
|
WebappsHandler.init();
|
|
|
|
}
|
2012-05-31 13:30:40 -07:00
|
|
|
|
2012-06-29 15:52:43 -07:00
|
|
|
// On firstrun, set permissions to their default values.
|
|
|
|
if (!Services.prefs.getBoolPref("webapprt.firstrun")) {
|
|
|
|
Cu.import("resource://webapprt/modules/WebappRT.jsm");
|
|
|
|
let uri = Services.io.newURI(WebappRT.config.app.origin, null, null);
|
2012-05-31 13:30:40 -07:00
|
|
|
|
2012-06-29 15:52:43 -07:00
|
|
|
// Set AppCache-related permissions.
|
|
|
|
Services.perms.add(uri, "pin-app",
|
|
|
|
Ci.nsIPermissionManager.ALLOW_ACTION);
|
|
|
|
Services.perms.add(uri, "offline-app",
|
|
|
|
Ci.nsIPermissionManager.ALLOW_ACTION);
|
2012-05-31 13:30:40 -07:00
|
|
|
|
2012-06-29 15:52:43 -07:00
|
|
|
Services.perms.add(uri, "indexedDB",
|
|
|
|
Ci.nsIPermissionManager.ALLOW_ACTION);
|
|
|
|
Services.perms.add(uri, "indexedDB-unlimited",
|
|
|
|
Ci.nsIPermissionManager.ALLOW_ACTION);
|
2012-05-31 13:30:40 -07:00
|
|
|
|
2012-06-29 15:52:43 -07:00
|
|
|
// Now that we've set the appropriate permissions, twiddle the firstrun
|
|
|
|
// flag so we don't try to do so again.
|
|
|
|
Services.prefs.setBoolPref("webapprt.firstrun", true);
|
|
|
|
}
|
|
|
|
} catch(ex) {
|
2012-05-31 13:30:40 -07:00
|
|
|
#ifdef MOZ_DEBUG
|
2012-06-29 15:52:43 -07:00
|
|
|
dump(ex + "\n");
|
2012-05-31 13:30:40 -07:00
|
|
|
#endif
|
2012-06-29 15:52:43 -07:00
|
|
|
}
|
2012-05-31 13:30:40 -07:00
|
|
|
}
|