michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict" michael@0: michael@0: const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; michael@0: michael@0: this.EXPORTED_SYMBOLS = ["DataStoreServiceInternal"]; michael@0: michael@0: function debug(s) { michael@0: //dump('DEBUG DataStoreServiceInternal: ' + s + '\n'); michael@0: } michael@0: michael@0: Cu.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: XPCOMUtils.defineLazyServiceGetter(this, "ppmm", michael@0: "@mozilla.org/parentprocessmessagemanager;1", michael@0: "nsIMessageBroadcaster"); michael@0: michael@0: XPCOMUtils.defineLazyServiceGetter(this, "dataStoreService", michael@0: "@mozilla.org/datastore-service;1", michael@0: "nsIDataStoreService"); michael@0: michael@0: this.DataStoreServiceInternal = { michael@0: init: function() { michael@0: debug("init"); michael@0: michael@0: let inParent = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime) michael@0: .processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT; michael@0: if (inParent) { michael@0: ppmm.addMessageListener("DataStore:Get", this); michael@0: } michael@0: }, michael@0: michael@0: receiveMessage: function(aMessage) { michael@0: debug("receiveMessage"); michael@0: michael@0: if (aMessage.name != 'DataStore:Get') { michael@0: return; michael@0: } michael@0: michael@0: let prefName = 'dom.testing.datastore_enabled_for_hosted_apps'; michael@0: if ((Services.prefs.getPrefType(prefName) == Services.prefs.PREF_INVALID || michael@0: !Services.prefs.getBoolPref(prefName)) && michael@0: !aMessage.target.assertAppHasStatus(Ci.nsIPrincipal.APP_STATUS_CERTIFIED)) { michael@0: return; michael@0: } michael@0: michael@0: let msg = aMessage.data; michael@0: michael@0: if (!aMessage.principal || michael@0: aMessage.principal.appId == Ci.nsIScriptSecurityManager.UNKNOWN_APP_ID) { michael@0: aMessage.target.sendAsyncMessage("DataStore:Get:Return:KO"); michael@0: return; michael@0: } michael@0: michael@0: msg.stores = dataStoreService.getDataStoresInfo(msg.name, aMessage.principal.appId); michael@0: if (msg.stores === null) { michael@0: aMessage.target.sendAsyncMessage("DataStore:Get:Return:KO"); michael@0: return; michael@0: } michael@0: aMessage.target.sendAsyncMessage("DataStore:Get:Return:OK", msg); michael@0: } michael@0: } michael@0: michael@0: DataStoreServiceInternal.init();