webapprt/DirectoryProvider.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/webapprt/DirectoryProvider.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,56 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +const Cc = Components.classes;
     1.9 +const Ci = Components.interfaces;
    1.10 +const Cu = Components.utils;
    1.11 +
    1.12 +const WEBAPP_REGISTRY_DIR = "WebappRegD";
    1.13 +const NS_APP_CHROME_DIR_LIST = "AChromDL";
    1.14 +
    1.15 +Cu.import("resource://gre/modules/FileUtils.jsm");
    1.16 +Cu.import("resource://gre/modules/XPCOMUtils.jsm");
    1.17 +Cu.import("resource://webapprt/modules/WebappRT.jsm");
    1.18 +Cu.import("resource://gre/modules/Services.jsm");
    1.19 +
    1.20 +function DirectoryProvider() {}
    1.21 +
    1.22 +DirectoryProvider.prototype = {
    1.23 +  classID: Components.ID("{e1799fda-4b2f-4457-b671-e0641d95698d}"),
    1.24 +
    1.25 +  QueryInterface: XPCOMUtils.generateQI([Ci.nsIDirectoryServiceProvider,
    1.26 +                                         Ci.nsIDirectoryServiceProvider2]),
    1.27 +
    1.28 +  getFile: function(prop, persistent) {
    1.29 +    if (prop == WEBAPP_REGISTRY_DIR) {
    1.30 +      let dir = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
    1.31 +      dir.initWithPath(WebappRT.config.registryDir);
    1.32 +      return dir;
    1.33 +    }
    1.34 +
    1.35 +    // We return null to show failure instead of throwing an error,
    1.36 +    // which works with the way the interface is called (per bug 529077).
    1.37 +    return null;
    1.38 +  },
    1.39 +
    1.40 +  getFiles: function(prop, persistent) {
    1.41 +    if (prop == NS_APP_CHROME_DIR_LIST) {
    1.42 +      return {
    1.43 +        _done: false,
    1.44 +        QueryInterface: XPCOMUtils.generateQI([Ci.nsISimpleEnumerator]),
    1.45 +        hasMoreElements: function() {
    1.46 +          return !this._done;
    1.47 +        },
    1.48 +        getNext: function() {
    1.49 +          this._done = true;
    1.50 +          return FileUtils.getDir("AppRegD", ["chrome"], false);
    1.51 +        }
    1.52 +      };
    1.53 +    }
    1.54 +
    1.55 +    return null;
    1.56 +  },
    1.57 +};
    1.58 +
    1.59 +this.NSGetFactory = XPCOMUtils.generateNSGetFactory([DirectoryProvider]);

mercurial