|
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/. */ |
|
4 |
|
5 "use strict" |
|
6 |
|
7 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; |
|
8 |
|
9 this.EXPORTED_SYMBOLS = ["DataStoreServiceInternal"]; |
|
10 |
|
11 function debug(s) { |
|
12 //dump('DEBUG DataStoreServiceInternal: ' + s + '\n'); |
|
13 } |
|
14 |
|
15 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
|
16 Cu.import("resource://gre/modules/Services.jsm"); |
|
17 |
|
18 XPCOMUtils.defineLazyServiceGetter(this, "ppmm", |
|
19 "@mozilla.org/parentprocessmessagemanager;1", |
|
20 "nsIMessageBroadcaster"); |
|
21 |
|
22 XPCOMUtils.defineLazyServiceGetter(this, "dataStoreService", |
|
23 "@mozilla.org/datastore-service;1", |
|
24 "nsIDataStoreService"); |
|
25 |
|
26 this.DataStoreServiceInternal = { |
|
27 init: function() { |
|
28 debug("init"); |
|
29 |
|
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 }, |
|
36 |
|
37 receiveMessage: function(aMessage) { |
|
38 debug("receiveMessage"); |
|
39 |
|
40 if (aMessage.name != 'DataStore:Get') { |
|
41 return; |
|
42 } |
|
43 |
|
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 } |
|
50 |
|
51 let msg = aMessage.data; |
|
52 |
|
53 if (!aMessage.principal || |
|
54 aMessage.principal.appId == Ci.nsIScriptSecurityManager.UNKNOWN_APP_ID) { |
|
55 aMessage.target.sendAsyncMessage("DataStore:Get:Return:KO"); |
|
56 return; |
|
57 } |
|
58 |
|
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 } |
|
67 |
|
68 DataStoreServiceInternal.init(); |