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 const WEBAPP_REGISTRY_DIR = "WebappRegD";
10 const NS_APP_CHROME_DIR_LIST = "AChromDL";
12 Cu.import("resource://gre/modules/FileUtils.jsm");
13 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
14 Cu.import("resource://webapprt/modules/WebappRT.jsm");
15 Cu.import("resource://gre/modules/Services.jsm");
17 let gInTestMode = false;
18 Services.obs.addObserver(function observe(subj, topic, data) {
19 Services.obs.removeObserver(observe, "webapprt-command-line");
20 let args = subj.QueryInterface(Ci.nsIPropertyBag2);
21 gInTestMode = args.hasKey("test-mode");
22 }, "webapprt-command-line", false);
24 function DirectoryProvider() {}
26 DirectoryProvider.prototype = {
27 classID: Components.ID("{e1799fda-4b2f-4457-b671-e0641d95698d}"),
29 QueryInterface: XPCOMUtils.generateQI([Ci.nsIDirectoryServiceProvider,
30 Ci.nsIDirectoryServiceProvider2]),
32 getFile: function(prop, persistent) {
33 if (prop == WEBAPP_REGISTRY_DIR) {
35 // In test mode, apps are registered in the runtime's profile. Note
36 // that in test mode WebappRT.config may not be valid at this point.
37 // It's only valid after WebappRT.jsm observes an app installation, and
38 // we can get here before any app is installed.
39 return FileUtils.getDir("ProfD", []);
41 let dir = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
42 dir.initWithPath(WebappRT.config.registryDir);
46 // We return null to show failure instead of throwing an error,
47 // which works with the way the interface is called (per bug 529077).
51 getFiles: function(prop, persistent) {
52 if (prop == NS_APP_CHROME_DIR_LIST) {
55 QueryInterface: XPCOMUtils.generateQI([Ci.nsISimpleEnumerator]),
56 hasMoreElements: function() {
61 return FileUtils.getDir("AppRegD", ["chrome"], false);
70 const NSGetFactory = XPCOMUtils.generateNSGetFactory([DirectoryProvider]);