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