webapprt/DirectoryProvider.js

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     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 function DirectoryProvider() {}
    19 DirectoryProvider.prototype = {
    20   classID: Components.ID("{e1799fda-4b2f-4457-b671-e0641d95698d}"),
    22   QueryInterface: XPCOMUtils.generateQI([Ci.nsIDirectoryServiceProvider,
    23                                          Ci.nsIDirectoryServiceProvider2]),
    25   getFile: function(prop, persistent) {
    26     if (prop == WEBAPP_REGISTRY_DIR) {
    27       let dir = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
    28       dir.initWithPath(WebappRT.config.registryDir);
    29       return dir;
    30     }
    32     // We return null to show failure instead of throwing an error,
    33     // which works with the way the interface is called (per bug 529077).
    34     return null;
    35   },
    37   getFiles: function(prop, persistent) {
    38     if (prop == NS_APP_CHROME_DIR_LIST) {
    39       return {
    40         _done: false,
    41         QueryInterface: XPCOMUtils.generateQI([Ci.nsISimpleEnumerator]),
    42         hasMoreElements: function() {
    43           return !this._done;
    44         },
    45         getNext: function() {
    46           this._done = true;
    47           return FileUtils.getDir("AppRegD", ["chrome"], false);
    48         }
    49       };
    50     }
    52     return null;
    53   },
    54 };
    56 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([DirectoryProvider]);

mercurial