зеркало из https://github.com/mozilla/gecko-dev.git
Bug 849616 - Use ObjectWrapper.jsm instead of __exposedProps__ in Settings API. r=gwagner
--HG-- extra : rebase_source : b6f492515c0735e8d16fb3f9e903389b09ae3943
This commit is contained in:
Родитель
356c0e84be
Коммит
e4e518e0f3
|
@ -17,6 +17,7 @@ Cu.import("resource://gre/modules/SettingsQueue.jsm");
|
||||||
Cu.import("resource://gre/modules/SettingsDB.jsm");
|
Cu.import("resource://gre/modules/SettingsDB.jsm");
|
||||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||||
Cu.import("resource://gre/modules/Services.jsm");
|
Cu.import("resource://gre/modules/Services.jsm");
|
||||||
|
Cu.import("resource://gre/modules/ObjectWrapper.jsm")
|
||||||
|
|
||||||
XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
|
XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
|
||||||
"@mozilla.org/childprocessmessagemanager;1",
|
"@mozilla.org/childprocessmessagemanager;1",
|
||||||
|
@ -42,6 +43,10 @@ SettingsLock.prototype = {
|
||||||
return !this._open;
|
return !this._open;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_wrap: function _wrap(obj) {
|
||||||
|
return ObjectWrapper.wrap(obj, this._settingsManager._window);
|
||||||
|
},
|
||||||
|
|
||||||
process: function process() {
|
process: function process() {
|
||||||
let lock = this;
|
let lock = this;
|
||||||
lock._open = false;
|
lock._open = false;
|
||||||
|
@ -127,35 +132,25 @@ SettingsLock.prototype = {
|
||||||
: store.mozGetAll(info.name);
|
: store.mozGetAll(info.name);
|
||||||
|
|
||||||
getReq.onsuccess = function(event) {
|
getReq.onsuccess = function(event) {
|
||||||
if (DEBUG) debug("Request for '" + info.name + "' successful. " +
|
if (DEBUG) debug("Request for '" + info.name + "' successful. " +
|
||||||
"Record count: " + event.target.result.length);
|
"Record count: " + event.target.result.length);
|
||||||
|
|
||||||
if (event.target.result.length == 0) {
|
if (event.target.result.length == 0) {
|
||||||
if (DEBUG) debug("MOZSETTINGS-GET-WARNING: " + info.name + " is not in the database.\n");
|
if (DEBUG) debug("MOZSETTINGS-GET-WARNING: " + info.name + " is not in the database.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
let results = {
|
let results = {};
|
||||||
__exposedProps__: {
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
for (var i in event.target.result) {
|
for (var i in event.target.result) {
|
||||||
let result = event.target.result[i];
|
let result = event.target.result[i];
|
||||||
var name = result.settingName;
|
var name = result.settingName;
|
||||||
if (DEBUG) debug("VAL: " + result.userValue +", " + result.defaultValue + "\n");
|
if (DEBUG) debug("VAL: " + result.userValue +", " + result.defaultValue + "\n");
|
||||||
var value = result.userValue !== undefined ? result.userValue : result.defaultValue;
|
var value = result.userValue !== undefined ? result.userValue : result.defaultValue;
|
||||||
results[name] = value;
|
results[name] = this._wrap(value);
|
||||||
results.__exposedProps__[name] = "r";
|
|
||||||
// If the value itself is an object, expose the properties.
|
|
||||||
if (typeof value == "object" && value != null) {
|
|
||||||
var exposed = {};
|
|
||||||
Object.keys(value).forEach(function(key) { exposed[key] = 'r'; });
|
|
||||||
results[name].__exposedProps__ = exposed;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this._open = true;
|
this._open = true;
|
||||||
Services.DOMRequest.fireSuccess(request, results);
|
Services.DOMRequest.fireSuccess(request, this._wrap(results));
|
||||||
this._open = false;
|
this._open = false;
|
||||||
}.bind(lock);
|
}.bind(lock);
|
||||||
|
|
||||||
|
@ -272,6 +267,10 @@ SettingsManager.prototype = {
|
||||||
_onsettingchange: null,
|
_onsettingchange: null,
|
||||||
_callbacks: null,
|
_callbacks: null,
|
||||||
|
|
||||||
|
_wrap: function _wrap(obj) {
|
||||||
|
return ObjectWrapper.wrap(obj, this._window);
|
||||||
|
},
|
||||||
|
|
||||||
nextTick: function nextTick(aCallback, thisObj) {
|
nextTick: function nextTick(aCallback, thisObj) {
|
||||||
if (thisObj)
|
if (thisObj)
|
||||||
aCallback = aCallback.bind(thisObj);
|
aCallback = aCallback.bind(thisObj);
|
||||||
|
@ -326,15 +325,14 @@ SettingsManager.prototype = {
|
||||||
if (this._callbacks && this._callbacks[msg.key]) {
|
if (this._callbacks && this._callbacks[msg.key]) {
|
||||||
if (DEBUG) debug("observe callback called! " + msg.key + " " + this._callbacks[msg.key].length);
|
if (DEBUG) debug("observe callback called! " + msg.key + " " + this._callbacks[msg.key].length);
|
||||||
this._callbacks[msg.key].forEach(function(cb) {
|
this._callbacks[msg.key].forEach(function(cb) {
|
||||||
cb({settingName: msg.key, settingValue: msg.value,
|
cb(this._wrap({settingName: msg.key, settingValue: msg.value}));
|
||||||
__exposedProps__: {settingName: 'r', settingValue: 'r'}});
|
}.bind(this));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (DEBUG) debug("no observers stored!");
|
if (DEBUG) debug("no observers stored!");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (DEBUG) debug("Wrong message: " + aMessage.name);
|
if (DEBUG) debug("Wrong message: " + aMessage.name);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -308,7 +308,7 @@ var steps = [
|
||||||
is(req2.result["screen.brightness"], 0.7, "same Value");
|
is(req2.result["screen.brightness"], 0.7, "same Value");
|
||||||
}
|
}
|
||||||
req2.onerror = onFailure;
|
req2.onerror = onFailure;
|
||||||
|
|
||||||
var lock2 = mozSettings.createLock();
|
var lock2 = mozSettings.createLock();
|
||||||
req5 = lock2.get("screen.brightness");
|
req5 = lock2.get("screen.brightness");
|
||||||
req5.onsuccess = function () {
|
req5.onsuccess = function () {
|
||||||
|
@ -465,7 +465,7 @@ var steps = [
|
||||||
}.bind({testObj: testObj, request: req5});
|
}.bind({testObj: testObj, request: req5});
|
||||||
req5.onerror = onFailure;
|
req5.onerror = onFailure;
|
||||||
}
|
}
|
||||||
|
|
||||||
var lock5 = mozSettings.createLock();
|
var lock5 = mozSettings.createLock();
|
||||||
req6 = lock5.clear();
|
req6 = lock5.clear();
|
||||||
req6.onsuccess = function () {
|
req6.onsuccess = function () {
|
||||||
|
@ -495,14 +495,14 @@ var steps = [
|
||||||
function () {
|
function () {
|
||||||
ok(true, "Test locking result");
|
ok(true, "Test locking result");
|
||||||
var lock = mozSettings.createLock();
|
var lock = mozSettings.createLock();
|
||||||
|
|
||||||
req = lock.get("wifi.enabled");
|
req = lock.get("wifi.enabled");
|
||||||
req.onsuccess = function() {
|
req.onsuccess = function() {
|
||||||
check(req.result, wifiEnabled);
|
check(req.result, wifiEnabled);
|
||||||
ok(true, "Test2 locking result done");
|
ok(true, "Test2 locking result done");
|
||||||
}
|
}
|
||||||
req.onerror = onFailure;
|
req.onerror = onFailure;
|
||||||
|
|
||||||
req2 = lock.clear();
|
req2 = lock.clear();
|
||||||
req2.onsuccess = function () {
|
req2.onsuccess = function () {
|
||||||
ok(true, "Deleted the database");
|
ok(true, "Deleted the database");
|
||||||
|
@ -515,7 +515,7 @@ var steps = [
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
req3.onerror = onFailure;
|
req3.onerror = onFailure;
|
||||||
|
|
||||||
},
|
},
|
||||||
function () {
|
function () {
|
||||||
ok(true, "Get all settings");
|
ok(true, "Get all settings");
|
||||||
|
@ -734,6 +734,32 @@ var steps = [
|
||||||
};
|
};
|
||||||
req.onerror = onFailure;
|
req.onerror = onFailure;
|
||||||
},
|
},
|
||||||
|
function() {
|
||||||
|
ok(true, "Set object value");
|
||||||
|
var lock = mozSettings.createLock();
|
||||||
|
req = lock.set({"setting-obj": {foo: {bar: 23}}});
|
||||||
|
req.onsuccess = function() {
|
||||||
|
req2 = lock.get("setting-obj");
|
||||||
|
req2.onsuccess = function(event) {
|
||||||
|
var result = event.target.result["setting-obj"];
|
||||||
|
ok(result, "Got valid result");
|
||||||
|
ok(typeof result == "object", "Result is object");
|
||||||
|
ok("foo" in result && "bar" in result.foo, "Result has properties");
|
||||||
|
ok(result.foo.bar == 23, "Result properties are set");
|
||||||
|
next();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
},
|
||||||
|
function() {
|
||||||
|
ok(true, "Clear DB");
|
||||||
|
var lock = mozSettings.createLock();
|
||||||
|
req = lock.clear();
|
||||||
|
req.onsuccess = function () {
|
||||||
|
ok(true, "Deleted the database");
|
||||||
|
next();
|
||||||
|
};
|
||||||
|
req.onerror = onFailure;
|
||||||
|
},
|
||||||
function () {
|
function () {
|
||||||
ok(true, "all done!\n");
|
ok(true, "all done!\n");
|
||||||
SimpleTest.finish();
|
SimpleTest.finish();
|
||||||
|
|
Загрузка…
Ссылка в новой задаче