2012-03-26 14:49:38 -07: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/. */
|
|
|
|
|
2012-05-25 10:37:45 -07:00
|
|
|
"use strict";
|
2012-03-26 14:49:38 -07:00
|
|
|
|
2013-01-07 07:16:17 -08:00
|
|
|
const DEBUG = false;
|
2012-06-04 16:12:24 -07:00
|
|
|
function debug(s) {
|
2012-12-14 10:20:16 -08:00
|
|
|
if (DEBUG) dump("-*- SettingsManager: " + s + "\n");
|
2012-06-04 16:12:24 -07:00
|
|
|
}
|
2012-03-26 14:49:38 -07:00
|
|
|
|
2012-04-26 15:10:04 -07:00
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
|
2012-04-27 16:21:31 -07:00
|
|
|
Cu.import("resource://gre/modules/SettingsQueue.jsm");
|
|
|
|
Cu.import("resource://gre/modules/SettingsDB.jsm");
|
2012-03-26 14:49:38 -07:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2013-03-11 22:31:19 -07:00
|
|
|
Cu.import("resource://gre/modules/ObjectWrapper.jsm")
|
2012-03-26 14:49:38 -07:00
|
|
|
|
2012-08-27 07:13:02 -07:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
|
|
|
|
"@mozilla.org/childprocessmessagemanager;1",
|
|
|
|
"nsIMessageSender");
|
2012-06-04 16:12:24 -07:00
|
|
|
|
2013-07-15 18:17:46 -07:00
|
|
|
function SettingsLock(aSettingsManager) {
|
2012-03-26 14:49:38 -07:00
|
|
|
this._open = true;
|
2013-01-04 16:04:28 -08:00
|
|
|
this._isBusy = false;
|
2012-03-26 14:49:38 -07:00
|
|
|
this._requests = new Queue();
|
|
|
|
this._settingsManager = aSettingsManager;
|
|
|
|
this._transaction = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
SettingsLock.prototype = {
|
2013-01-15 19:32:49 -08:00
|
|
|
get closed() {
|
|
|
|
return !this._open;
|
|
|
|
},
|
|
|
|
|
2013-03-11 22:31:19 -07:00
|
|
|
_wrap: function _wrap(obj) {
|
|
|
|
return ObjectWrapper.wrap(obj, this._settingsManager._window);
|
|
|
|
},
|
|
|
|
|
2012-03-26 14:49:38 -07:00
|
|
|
process: function process() {
|
|
|
|
let lock = this;
|
|
|
|
lock._open = false;
|
2012-04-27 16:21:31 -07:00
|
|
|
let store = lock._transaction.objectStore(SETTINGSSTORE_NAME);
|
2012-03-26 14:49:38 -07:00
|
|
|
|
|
|
|
while (!lock._requests.isEmpty()) {
|
|
|
|
let info = lock._requests.dequeue();
|
2012-12-14 10:20:16 -08:00
|
|
|
if (DEBUG) debug("info: " + info.intent);
|
2012-03-26 14:49:38 -07:00
|
|
|
let request = info.request;
|
|
|
|
switch (info.intent) {
|
|
|
|
case "clear":
|
2013-01-04 16:04:28 -08:00
|
|
|
let clearReq = store.clear();
|
|
|
|
clearReq.onsuccess = function() {
|
|
|
|
this._open = true;
|
|
|
|
Services.DOMRequest.fireSuccess(request, 0);
|
|
|
|
this._open = false;
|
|
|
|
}.bind(lock);
|
|
|
|
clearReq.onerror = function() {
|
|
|
|
Services.DOMRequest.fireError(request, 0)
|
|
|
|
};
|
2012-03-26 14:49:38 -07:00
|
|
|
break;
|
|
|
|
case "set":
|
2012-12-13 16:46:13 -08:00
|
|
|
let keys = Object.getOwnPropertyNames(info.settings);
|
|
|
|
for (let i = 0; i < keys.length; i++) {
|
|
|
|
let key = keys[i];
|
|
|
|
let last = i === keys.length - 1;
|
2012-12-14 10:20:16 -08:00
|
|
|
if (DEBUG) debug("key: " + key + ", val: " + JSON.stringify(info.settings[key]) + ", type: " + typeof(info.settings[key]));
|
2013-01-04 16:04:28 -08:00
|
|
|
lock._isBusy = true;
|
2012-06-20 12:56:23 -07:00
|
|
|
let checkKeyRequest = store.get(key);
|
2013-01-04 16:04:28 -08:00
|
|
|
|
2012-06-20 12:56:23 -07:00
|
|
|
checkKeyRequest.onsuccess = function (event) {
|
2013-01-04 16:04:28 -08:00
|
|
|
let defaultValue;
|
|
|
|
let userValue = info.settings[key];
|
|
|
|
if (event.target.result) {
|
|
|
|
defaultValue = event.target.result.defaultValue;
|
|
|
|
} else {
|
|
|
|
defaultValue = null;
|
|
|
|
if (DEBUG) debug("MOZSETTINGS-SET-WARNING: " + key + " is not in the database.\n");
|
2012-06-20 12:56:23 -07:00
|
|
|
}
|
|
|
|
|
2013-03-11 22:31:15 -07:00
|
|
|
let obj = {settingName: key, defaultValue: defaultValue, userValue: userValue};
|
|
|
|
if (DEBUG) debug("store1: " + JSON.stringify(obj));
|
|
|
|
let setReq = store.put(obj);
|
2012-03-27 12:04:16 -07:00
|
|
|
|
2013-01-04 16:04:28 -08:00
|
|
|
setReq.onsuccess = function() {
|
|
|
|
lock._isBusy = false;
|
|
|
|
cpmm.sendAsyncMessage("Settings:Changed", { key: key, value: userValue });
|
|
|
|
if (last && !request.error) {
|
|
|
|
lock._open = true;
|
|
|
|
Services.DOMRequest.fireSuccess(request, 0);
|
|
|
|
lock._open = false;
|
|
|
|
if (!lock._requests.isEmpty()) {
|
|
|
|
lock.process();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
setReq.onerror = function() {
|
|
|
|
if (!request.error) {
|
|
|
|
Services.DOMRequest.fireError(request, setReq.error.name)
|
|
|
|
}
|
|
|
|
};
|
2013-03-11 22:31:15 -07:00
|
|
|
};
|
2013-01-07 06:03:26 -08:00
|
|
|
checkKeyRequest.onerror = function(event) {
|
|
|
|
if (!request.error) {
|
|
|
|
Services.DOMRequest.fireError(request, checkKeyRequest.error.name)
|
|
|
|
}
|
|
|
|
};
|
2012-03-26 14:49:38 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "get":
|
2013-01-04 16:04:28 -08:00
|
|
|
let getReq = (info.name === "*") ? store.mozGetAll()
|
|
|
|
: store.mozGetAll(info.name);
|
2012-06-06 05:19:33 -07:00
|
|
|
|
2013-01-04 16:04:28 -08:00
|
|
|
getReq.onsuccess = function(event) {
|
2013-03-11 22:31:19 -07:00
|
|
|
if (DEBUG) debug("Request for '" + info.name + "' successful. " +
|
2013-03-11 22:31:15 -07:00
|
|
|
"Record count: " + event.target.result.length);
|
2012-06-06 05:19:33 -07:00
|
|
|
|
2012-06-20 12:56:23 -07:00
|
|
|
if (event.target.result.length == 0) {
|
2013-01-04 16:04:28 -08:00
|
|
|
if (DEBUG) debug("MOZSETTINGS-GET-WARNING: " + info.name + " is not in the database.\n");
|
2012-06-20 12:56:23 -07:00
|
|
|
}
|
|
|
|
|
2013-03-11 22:31:19 -07:00
|
|
|
let results = {};
|
2012-06-06 05:19:33 -07:00
|
|
|
|
|
|
|
for (var i in event.target.result) {
|
|
|
|
let result = event.target.result[i];
|
2012-08-14 20:54:33 -07:00
|
|
|
var name = result.settingName;
|
2013-01-04 16:04:28 -08:00
|
|
|
if (DEBUG) debug("VAL: " + result.userValue +", " + result.defaultValue + "\n");
|
|
|
|
var value = result.userValue !== undefined ? result.userValue : result.defaultValue;
|
2013-03-11 22:31:19 -07:00
|
|
|
results[name] = this._wrap(value);
|
2012-06-06 05:19:33 -07:00
|
|
|
}
|
|
|
|
|
2012-03-26 14:49:38 -07:00
|
|
|
this._open = true;
|
2013-03-11 22:31:19 -07:00
|
|
|
Services.DOMRequest.fireSuccess(request, this._wrap(results));
|
2012-03-26 14:49:38 -07:00
|
|
|
this._open = false;
|
|
|
|
}.bind(lock);
|
2012-06-06 05:19:33 -07:00
|
|
|
|
2013-01-04 16:04:28 -08:00
|
|
|
getReq.onerror = function() {
|
2012-06-06 05:19:33 -07:00
|
|
|
Services.DOMRequest.fireError(request, 0)
|
|
|
|
};
|
2012-03-26 14:49:38 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lock._open = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
createTransactionAndProcess: function() {
|
2012-04-26 15:10:04 -07:00
|
|
|
if (this._settingsManager._settingsDB._db) {
|
2012-03-26 14:49:38 -07:00
|
|
|
var lock;
|
|
|
|
while (lock = this._settingsManager._locks.dequeue()) {
|
|
|
|
if (!lock._transaction) {
|
2012-11-01 14:31:29 -07:00
|
|
|
let transactionType = this._settingsManager.hasWritePrivileges ? "readwrite" : "readonly";
|
|
|
|
lock._transaction = lock._settingsManager._settingsDB._db.transaction(SETTINGSSTORE_NAME, transactionType);
|
2012-03-26 14:49:38 -07:00
|
|
|
}
|
2013-01-04 16:04:28 -08:00
|
|
|
if (!lock._isBusy) {
|
|
|
|
lock.process();
|
|
|
|
} else {
|
|
|
|
this._settingsManager._locks.enqueue(lock);
|
|
|
|
}
|
2012-03-26 14:49:38 -07:00
|
|
|
}
|
2013-01-04 16:04:28 -08:00
|
|
|
if (!this._requests.isEmpty() && !this._isBusy) {
|
2012-03-26 14:49:38 -07:00
|
|
|
this.process();
|
2013-01-04 16:04:28 -08:00
|
|
|
}
|
2012-03-26 14:49:38 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
get: function get(aName) {
|
2012-05-22 18:18:56 -07:00
|
|
|
if (!this._open) {
|
|
|
|
dump("Settings lock not open!\n");
|
2012-03-26 14:49:38 -07:00
|
|
|
throw Components.results.NS_ERROR_ABORT;
|
2012-05-22 18:18:56 -07:00
|
|
|
}
|
2012-03-26 14:49:38 -07:00
|
|
|
|
2012-10-31 17:26:05 -07:00
|
|
|
if (this._settingsManager.hasReadPrivileges) {
|
2012-03-26 14:49:38 -07:00
|
|
|
let req = Services.DOMRequest.createRequest(this._settingsManager._window);
|
|
|
|
this._requests.enqueue({ request: req, intent:"get", name: aName });
|
|
|
|
this.createTransactionAndProcess();
|
|
|
|
return req;
|
|
|
|
} else {
|
2012-12-14 10:20:16 -08:00
|
|
|
if (DEBUG) debug("get not allowed");
|
2012-03-26 14:49:38 -07:00
|
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-03-11 22:31:15 -07:00
|
|
|
_serializePreservingBinaries: function _serializePreservingBinaries(aObject) {
|
|
|
|
// We need to serialize settings objects, otherwise they can change between
|
|
|
|
// the set() call and the enqueued request being processed. We can't simply
|
|
|
|
// parse(stringify(obj)) because that breaks things like Blobs, Files and
|
|
|
|
// Dates, so we use stringify's replacer and parse's reviver parameters to
|
|
|
|
// preserve binaries.
|
|
|
|
let binaries = Object.create(null);
|
|
|
|
let stringified = JSON.stringify(aObject, function(key, value) {
|
|
|
|
let kind = ObjectWrapper.getObjectKind(value);
|
|
|
|
if (kind == "file" || kind == "blob" || kind == "date") {
|
|
|
|
let uuid = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator)
|
|
|
|
.generateUUID().toString();
|
|
|
|
binaries[uuid] = value;
|
|
|
|
return uuid;
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
});
|
|
|
|
return JSON.parse(stringified, function(key, value) {
|
|
|
|
if (value in binaries) {
|
|
|
|
return binaries[value];
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-03-26 14:49:38 -07:00
|
|
|
set: function set(aSettings) {
|
2012-05-22 18:18:56 -07:00
|
|
|
if (!this._open) {
|
2013-07-15 18:17:46 -07:00
|
|
|
throw "Settings lock not open";
|
2012-05-22 18:18:56 -07:00
|
|
|
}
|
2012-03-26 14:49:38 -07:00
|
|
|
|
2012-10-31 17:26:05 -07:00
|
|
|
if (this._settingsManager.hasWritePrivileges) {
|
2012-03-26 14:49:38 -07:00
|
|
|
let req = Services.DOMRequest.createRequest(this._settingsManager._window);
|
2012-12-14 10:20:16 -08:00
|
|
|
if (DEBUG) debug("send: " + JSON.stringify(aSettings));
|
2013-03-11 22:31:15 -07:00
|
|
|
let settings = this._serializePreservingBinaries(aSettings);
|
2013-03-12 02:14:46 -07:00
|
|
|
this._requests.enqueue({request: req, intent: "set", settings: settings});
|
2012-03-26 14:49:38 -07:00
|
|
|
this.createTransactionAndProcess();
|
|
|
|
return req;
|
|
|
|
} else {
|
2012-12-14 10:20:16 -08:00
|
|
|
if (DEBUG) debug("set not allowed");
|
2013-07-15 18:17:46 -07:00
|
|
|
throw "No permission to call set";
|
2012-03-26 14:49:38 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
clear: function clear() {
|
2012-05-22 18:18:56 -07:00
|
|
|
if (!this._open) {
|
2013-07-15 18:17:46 -07:00
|
|
|
throw "Settings lock not open";
|
2012-05-22 18:18:56 -07:00
|
|
|
}
|
2012-03-26 14:49:38 -07:00
|
|
|
|
2012-10-31 17:26:05 -07:00
|
|
|
if (this._settingsManager.hasWritePrivileges) {
|
2012-03-26 14:49:38 -07:00
|
|
|
let req = Services.DOMRequest.createRequest(this._settingsManager._window);
|
|
|
|
this._requests.enqueue({ request: req, intent: "clear"});
|
|
|
|
this.createTransactionAndProcess();
|
|
|
|
return req;
|
|
|
|
} else {
|
2012-12-14 10:20:16 -08:00
|
|
|
if (DEBUG) debug("clear not allowed");
|
2013-07-15 18:17:46 -07:00
|
|
|
throw "No permission to call clear";
|
2012-03-26 14:49:38 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-07-15 18:17:46 -07:00
|
|
|
classID: Components.ID("{60c9357c-3ae0-4222-8f55-da01428470d5}"),
|
|
|
|
contractID: "@mozilla.org/settingsLock;1",
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports]),
|
2012-03-26 14:49:38 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
let myGlobal = this;
|
|
|
|
|
2013-07-15 18:17:46 -07:00
|
|
|
function SettingsManager() {
|
2012-03-26 14:49:38 -07:00
|
|
|
this._locks = new Queue();
|
2012-08-29 11:52:48 -07:00
|
|
|
if (!("indexedDB" in myGlobal)) {
|
|
|
|
let idbManager = Components.classes["@mozilla.org/dom/indexeddb/manager;1"].getService(Ci.nsIIndexedDatabaseManager);
|
|
|
|
idbManager.initWindowless(myGlobal);
|
|
|
|
}
|
2012-03-26 14:49:38 -07:00
|
|
|
this._settingsDB = new SettingsDB();
|
2012-04-26 15:10:04 -07:00
|
|
|
this._settingsDB.init(myGlobal);
|
2012-03-26 14:49:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
SettingsManager.prototype = {
|
2012-06-10 16:44:50 -07:00
|
|
|
_callbacks: null,
|
2012-03-26 14:49:38 -07:00
|
|
|
|
2013-03-11 22:31:19 -07:00
|
|
|
_wrap: function _wrap(obj) {
|
|
|
|
return ObjectWrapper.wrap(obj, this._window);
|
|
|
|
},
|
|
|
|
|
2012-03-26 14:49:38 -07:00
|
|
|
nextTick: function nextTick(aCallback, thisObj) {
|
|
|
|
if (thisObj)
|
|
|
|
aCallback = aCallback.bind(thisObj);
|
|
|
|
|
|
|
|
Services.tm.currentThread.dispatch(aCallback, Ci.nsIThread.DISPATCH_NORMAL);
|
|
|
|
},
|
|
|
|
|
2013-07-15 18:17:46 -07:00
|
|
|
set onsettingchange(aHandler) {
|
|
|
|
this.__DOM_IMPL__.setEventHandler("onsettingchange", aHandler);
|
2012-03-26 14:49:38 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
get onsettingchange() {
|
2013-07-15 18:17:46 -07:00
|
|
|
return this.__DOM_IMPL__.getEventHandler("onsettingchange");
|
2012-03-26 14:49:38 -07:00
|
|
|
},
|
|
|
|
|
2012-09-05 17:33:03 -07:00
|
|
|
createLock: function() {
|
2012-12-14 10:20:16 -08:00
|
|
|
if (DEBUG) debug("get lock!");
|
2012-03-26 14:49:38 -07:00
|
|
|
var lock = new SettingsLock(this);
|
|
|
|
this._locks.enqueue(lock);
|
|
|
|
this._settingsDB.ensureDB(
|
|
|
|
function() { lock.createTransactionAndProcess(); },
|
2013-01-04 16:04:28 -08:00
|
|
|
function() { dump("Cannot open Settings DB. Trying to open an old version?\n"); },
|
2012-03-26 14:49:38 -07:00
|
|
|
myGlobal );
|
|
|
|
this.nextTick(function() { this._open = false; }, lock);
|
|
|
|
return lock;
|
|
|
|
},
|
|
|
|
|
2012-06-04 16:12:24 -07:00
|
|
|
receiveMessage: function(aMessage) {
|
2012-12-14 10:20:16 -08:00
|
|
|
if (DEBUG) debug("Settings::receiveMessage: " + aMessage.name);
|
2012-06-04 16:12:24 -07:00
|
|
|
let msg = aMessage.json;
|
|
|
|
|
|
|
|
switch (aMessage.name) {
|
|
|
|
case "Settings:Change:Return:OK":
|
2013-07-15 18:17:46 -07:00
|
|
|
if (DEBUG) debug('data:' + msg.key + ':' + msg.value + '\n');
|
|
|
|
|
|
|
|
let event = new this._window.MozSettingsEvent("settingchange", this._wrap({
|
|
|
|
settingName: msg.key,
|
|
|
|
settingValue: msg.value
|
|
|
|
}));
|
|
|
|
this.__DOM_IMPL__.dispatchEvent(event);
|
|
|
|
|
|
|
|
if (this._callbacks && this._callbacks[msg.key]) {
|
|
|
|
if (DEBUG) debug("observe callback called! " + msg.key + " " + this._callbacks[msg.key].length);
|
|
|
|
this._callbacks[msg.key].forEach(function(cb) {
|
|
|
|
cb(this._wrap({settingName: msg.key, settingValue: msg.value}));
|
|
|
|
}.bind(this));
|
2012-06-10 16:44:50 -07:00
|
|
|
} else {
|
2012-12-14 10:20:16 -08:00
|
|
|
if (DEBUG) debug("no observers stored!");
|
2012-06-10 16:44:50 -07:00
|
|
|
}
|
2012-06-04 16:12:24 -07:00
|
|
|
break;
|
2013-03-11 22:31:19 -07:00
|
|
|
default:
|
2012-12-14 10:20:16 -08:00
|
|
|
if (DEBUG) debug("Wrong message: " + aMessage.name);
|
2012-06-04 16:12:24 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
addObserver: function addObserver(aName, aCallback) {
|
2012-12-14 10:20:16 -08:00
|
|
|
if (DEBUG) debug("addObserver " + aName);
|
2012-09-26 14:10:32 -07:00
|
|
|
if (!this._callbacks) {
|
|
|
|
cpmm.sendAsyncMessage("Settings:RegisterForMessages");
|
2012-06-10 16:44:50 -07:00
|
|
|
this._callbacks = {};
|
2012-09-26 14:10:32 -07:00
|
|
|
}
|
2012-06-10 16:44:50 -07:00
|
|
|
if (!this._callbacks[aName]) {
|
|
|
|
this._callbacks[aName] = [aCallback];
|
|
|
|
} else {
|
|
|
|
this._callbacks[aName].push(aCallback);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
removeObserver: function removeObserver(aName, aCallback) {
|
2012-12-14 10:20:16 -08:00
|
|
|
if (DEBUG) debug("deleteObserver " + aName);
|
2012-06-10 16:44:50 -07:00
|
|
|
if (this._callbacks && this._callbacks[aName]) {
|
|
|
|
let index = this._callbacks[aName].indexOf(aCallback)
|
|
|
|
if (index != -1) {
|
|
|
|
this._callbacks[aName].splice(index, 1)
|
|
|
|
} else {
|
2012-12-14 10:20:16 -08:00
|
|
|
if (DEBUG) debug("Callback not found for: " + aName);
|
2012-06-10 16:44:50 -07:00
|
|
|
}
|
|
|
|
} else {
|
2012-12-14 10:20:16 -08:00
|
|
|
if (DEBUG) debug("No observers stored for " + aName);
|
2012-06-10 16:44:50 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-03-26 14:49:38 -07:00
|
|
|
init: function(aWindow) {
|
2012-06-04 16:12:24 -07:00
|
|
|
cpmm.addMessageListener("Settings:Change:Return:OK", this);
|
2012-03-26 14:49:38 -07:00
|
|
|
this._window = aWindow;
|
|
|
|
Services.obs.addObserver(this, "inner-window-destroyed", false);
|
|
|
|
let util = aWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
|
|
|
|
this.innerWindowID = util.currentInnerWindowID;
|
|
|
|
|
2012-10-31 17:26:05 -07:00
|
|
|
let readPerm = Services.perms.testExactPermissionFromPrincipal(aWindow.document.nodePrincipal, "settings-read");
|
|
|
|
let writePerm = Services.perms.testExactPermissionFromPrincipal(aWindow.document.nodePrincipal, "settings-write");
|
|
|
|
this.hasReadPrivileges = readPerm == Ci.nsIPermissionManager.ALLOW_ACTION;
|
|
|
|
this.hasWritePrivileges = writePerm == Ci.nsIPermissionManager.ALLOW_ACTION;
|
|
|
|
|
2013-07-15 18:17:46 -07:00
|
|
|
if (this.hasReadPrivileges) {
|
|
|
|
cpmm.sendAsyncMessage("Settings:RegisterForMessages");
|
|
|
|
}
|
|
|
|
|
2012-10-31 17:26:05 -07:00
|
|
|
if (!this.hasReadPrivileges && !this.hasWritePrivileges) {
|
2013-07-17 13:32:39 -07:00
|
|
|
dump("No settings permission for: " + aWindow.document.nodePrincipal.origin + "\n");
|
|
|
|
Cu.reportError("No settings permission for: " + aWindow.document.nodePrincipal.origin);
|
2012-10-31 17:26:05 -07:00
|
|
|
}
|
2012-03-26 14:49:38 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
observe: function(aSubject, aTopic, aData) {
|
2012-12-14 10:20:16 -08:00
|
|
|
if (DEBUG) debug("Topic: " + aTopic);
|
2012-03-26 14:49:38 -07:00
|
|
|
if (aTopic == "inner-window-destroyed") {
|
|
|
|
let wId = aSubject.QueryInterface(Ci.nsISupportsPRUint64).data;
|
|
|
|
if (wId == this.innerWindowID) {
|
|
|
|
Services.obs.removeObserver(this, "inner-window-destroyed");
|
2012-06-04 16:12:24 -07:00
|
|
|
cpmm.removeMessageListener("Settings:Change:Return:OK", this);
|
2012-03-26 14:49:38 -07:00
|
|
|
this._requests = null;
|
|
|
|
this._window = null;
|
|
|
|
this._innerWindowID = null;
|
|
|
|
this._settingsDB.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-07-15 18:17:46 -07:00
|
|
|
classID: Components.ID("{c40b1c70-00fb-11e2-a21f-0800200c9a66}"),
|
|
|
|
contractID: "@mozilla.org/settingsManager;1",
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports,
|
|
|
|
Ci.nsIDOMGlobalPropertyInitializer]),
|
|
|
|
};
|
2012-03-26 14:49:38 -07:00
|
|
|
|
2012-10-31 09:13:28 -07:00
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([SettingsManager, SettingsLock])
|