browser/metro/components/DirectoryProvider.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/metro/components/DirectoryProvider.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,44 @@
     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
     1.6 + * file, 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 +
    1.11 +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
    1.12 +
    1.13 +// -----------------------------------------------------------------------
    1.14 +// Directory Provider for special browser folders and files
    1.15 +// -----------------------------------------------------------------------
    1.16 +
    1.17 +const NS_APP_CACHE_PARENT_DIR = "cachePDir";
    1.18 +
    1.19 +function DirectoryProvider() {}
    1.20 +
    1.21 +DirectoryProvider.prototype = {
    1.22 +  classID: Components.ID("{ef0f7a87-c1ee-45a8-8d67-26f586e46a4b}"),
    1.23 +  
    1.24 +  QueryInterface: XPCOMUtils.generateQI([Ci.nsIDirectoryServiceProvider]),
    1.25 +
    1.26 +  getFile: function(prop, persistent) {
    1.27 +    if (prop == NS_APP_CACHE_PARENT_DIR) {
    1.28 +      let dirsvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
    1.29 +      let profile = dirsvc.get("ProfD", Ci.nsIFile);
    1.30 +
    1.31 +      let sysInfo = Cc["@mozilla.org/system-info;1"].getService(Ci.nsIPropertyBag2);
    1.32 +      let device = sysInfo.get("device");
    1.33 +      switch (device) {
    1.34 +        default:
    1.35 +          return profile;
    1.36 +      }
    1.37 +    }
    1.38 +
    1.39 +    // We are retuning null to show failure instead for throwing an error. The
    1.40 +    // interface is called quite a bit and throwing an error is noisy. Returning
    1.41 +    // null works with the way the interface is called [see bug 529077]
    1.42 +    return null;
    1.43 +  }
    1.44 +};
    1.45 +
    1.46 +this.NSGetFactory = XPCOMUtils.generateNSGetFactory([DirectoryProvider]);
    1.47 +

mercurial