Bug 773192: Only proxy drawing to a non-default target in BasicShadowableLayerManager...
[gecko.git] / webapprt / DirectoryProvider.js
blobdf669592dd482aab7f5e64d36fd7b3ce06a96c9f
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) {
34       if (gInTestMode) {
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", []);
40       }
41       let dir = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
42       dir.initWithPath(WebappRT.config.registryDir);
43       return dir;
44     }
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).
48     return null;
49   },
51   getFiles: function(prop, persistent) {
52     if (prop == NS_APP_CHROME_DIR_LIST) {
53       return {
54         _done: false,
55         QueryInterface: XPCOMUtils.generateQI([Ci.nsISimpleEnumerator]),
56         hasMoreElements: function() {
57           return !this._done;
58         },
59         getNext: function() {
60           this._done = true;
61           return FileUtils.getDir("AppRegD", ["chrome"], false);
62         }
63       };
64     }
66     return null;
67   },
70 const NSGetFactory = XPCOMUtils.generateNSGetFactory([DirectoryProvider]);