Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | const Cc = Components.classes; |
michael@0 | 6 | const Ci = Components.interfaces; |
michael@0 | 7 | |
michael@0 | 8 | Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 9 | |
michael@0 | 10 | // ----------------------------------------------------------------------- |
michael@0 | 11 | // Directory Provider for special browser folders and files |
michael@0 | 12 | // ----------------------------------------------------------------------- |
michael@0 | 13 | |
michael@0 | 14 | const NS_APP_CACHE_PARENT_DIR = "cachePDir"; |
michael@0 | 15 | |
michael@0 | 16 | function DirectoryProvider() {} |
michael@0 | 17 | |
michael@0 | 18 | DirectoryProvider.prototype = { |
michael@0 | 19 | classID: Components.ID("{ef0f7a87-c1ee-45a8-8d67-26f586e46a4b}"), |
michael@0 | 20 | |
michael@0 | 21 | QueryInterface: XPCOMUtils.generateQI([Ci.nsIDirectoryServiceProvider]), |
michael@0 | 22 | |
michael@0 | 23 | getFile: function(prop, persistent) { |
michael@0 | 24 | if (prop == NS_APP_CACHE_PARENT_DIR) { |
michael@0 | 25 | let dirsvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties); |
michael@0 | 26 | let profile = dirsvc.get("ProfD", Ci.nsIFile); |
michael@0 | 27 | |
michael@0 | 28 | let sysInfo = Cc["@mozilla.org/system-info;1"].getService(Ci.nsIPropertyBag2); |
michael@0 | 29 | let device = sysInfo.get("device"); |
michael@0 | 30 | switch (device) { |
michael@0 | 31 | default: |
michael@0 | 32 | return profile; |
michael@0 | 33 | } |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | // We are retuning null to show failure instead for throwing an error. The |
michael@0 | 37 | // interface is called quite a bit and throwing an error is noisy. Returning |
michael@0 | 38 | // null works with the way the interface is called [see bug 529077] |
michael@0 | 39 | return null; |
michael@0 | 40 | } |
michael@0 | 41 | }; |
michael@0 | 42 | |
michael@0 | 43 | this.NSGetFactory = XPCOMUtils.generateNSGetFactory([DirectoryProvider]); |
michael@0 | 44 |