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