Tue, 06 Jan 2015 21:39:09 +0100
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 "use strict"
7 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
9 this.EXPORTED_SYMBOLS = ["DataStoreServiceInternal"];
11 function debug(s) {
12 //dump('DEBUG DataStoreServiceInternal: ' + s + '\n');
13 }
15 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
16 Cu.import("resource://gre/modules/Services.jsm");
18 XPCOMUtils.defineLazyServiceGetter(this, "ppmm",
19 "@mozilla.org/parentprocessmessagemanager;1",
20 "nsIMessageBroadcaster");
22 XPCOMUtils.defineLazyServiceGetter(this, "dataStoreService",
23 "@mozilla.org/datastore-service;1",
24 "nsIDataStoreService");
26 this.DataStoreServiceInternal = {
27 init: function() {
28 debug("init");
30 let inParent = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime)
31 .processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
32 if (inParent) {
33 ppmm.addMessageListener("DataStore:Get", this);
34 }
35 },
37 receiveMessage: function(aMessage) {
38 debug("receiveMessage");
40 if (aMessage.name != 'DataStore:Get') {
41 return;
42 }
44 let prefName = 'dom.testing.datastore_enabled_for_hosted_apps';
45 if ((Services.prefs.getPrefType(prefName) == Services.prefs.PREF_INVALID ||
46 !Services.prefs.getBoolPref(prefName)) &&
47 !aMessage.target.assertAppHasStatus(Ci.nsIPrincipal.APP_STATUS_CERTIFIED)) {
48 return;
49 }
51 let msg = aMessage.data;
53 if (!aMessage.principal ||
54 aMessage.principal.appId == Ci.nsIScriptSecurityManager.UNKNOWN_APP_ID) {
55 aMessage.target.sendAsyncMessage("DataStore:Get:Return:KO");
56 return;
57 }
59 msg.stores = dataStoreService.getDataStoresInfo(msg.name, aMessage.principal.appId);
60 if (msg.stores === null) {
61 aMessage.target.sendAsyncMessage("DataStore:Get:Return:KO");
62 return;
63 }
64 aMessage.target.sendAsyncMessage("DataStore:Get:Return:OK", msg);
65 }
66 }
68 DataStoreServiceInternal.init();