Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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 file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | "use strict" |
michael@0 | 6 | |
michael@0 | 7 | const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; |
michael@0 | 8 | |
michael@0 | 9 | this.EXPORTED_SYMBOLS = ["DataStoreServiceInternal"]; |
michael@0 | 10 | |
michael@0 | 11 | function debug(s) { |
michael@0 | 12 | //dump('DEBUG DataStoreServiceInternal: ' + s + '\n'); |
michael@0 | 13 | } |
michael@0 | 14 | |
michael@0 | 15 | Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 16 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 17 | |
michael@0 | 18 | XPCOMUtils.defineLazyServiceGetter(this, "ppmm", |
michael@0 | 19 | "@mozilla.org/parentprocessmessagemanager;1", |
michael@0 | 20 | "nsIMessageBroadcaster"); |
michael@0 | 21 | |
michael@0 | 22 | XPCOMUtils.defineLazyServiceGetter(this, "dataStoreService", |
michael@0 | 23 | "@mozilla.org/datastore-service;1", |
michael@0 | 24 | "nsIDataStoreService"); |
michael@0 | 25 | |
michael@0 | 26 | this.DataStoreServiceInternal = { |
michael@0 | 27 | init: function() { |
michael@0 | 28 | debug("init"); |
michael@0 | 29 | |
michael@0 | 30 | let inParent = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime) |
michael@0 | 31 | .processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT; |
michael@0 | 32 | if (inParent) { |
michael@0 | 33 | ppmm.addMessageListener("DataStore:Get", this); |
michael@0 | 34 | } |
michael@0 | 35 | }, |
michael@0 | 36 | |
michael@0 | 37 | receiveMessage: function(aMessage) { |
michael@0 | 38 | debug("receiveMessage"); |
michael@0 | 39 | |
michael@0 | 40 | if (aMessage.name != 'DataStore:Get') { |
michael@0 | 41 | return; |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | let prefName = 'dom.testing.datastore_enabled_for_hosted_apps'; |
michael@0 | 45 | if ((Services.prefs.getPrefType(prefName) == Services.prefs.PREF_INVALID || |
michael@0 | 46 | !Services.prefs.getBoolPref(prefName)) && |
michael@0 | 47 | !aMessage.target.assertAppHasStatus(Ci.nsIPrincipal.APP_STATUS_CERTIFIED)) { |
michael@0 | 48 | return; |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | let msg = aMessage.data; |
michael@0 | 52 | |
michael@0 | 53 | if (!aMessage.principal || |
michael@0 | 54 | aMessage.principal.appId == Ci.nsIScriptSecurityManager.UNKNOWN_APP_ID) { |
michael@0 | 55 | aMessage.target.sendAsyncMessage("DataStore:Get:Return:KO"); |
michael@0 | 56 | return; |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | msg.stores = dataStoreService.getDataStoresInfo(msg.name, aMessage.principal.appId); |
michael@0 | 60 | if (msg.stores === null) { |
michael@0 | 61 | aMessage.target.sendAsyncMessage("DataStore:Get:Return:KO"); |
michael@0 | 62 | return; |
michael@0 | 63 | } |
michael@0 | 64 | aMessage.target.sendAsyncMessage("DataStore:Get:Return:OK", msg); |
michael@0 | 65 | } |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | DataStoreServiceInternal.init(); |