зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1332501, r=bholley,jld
MozReview-Commit-ID: BpR0emUsbLL --HG-- extra : rebase_source : 83080777e94def83343509ecc5dc96ce8dd44973
This commit is contained in:
Родитель
3e3d621e59
Коммит
6934f00e4c
|
@ -113,86 +113,10 @@ var ContentPrefServiceChild = {
|
|||
this._requests.set(requestId, new CallbackCaller(callback));
|
||||
},
|
||||
|
||||
getByName(name, context, callback) {
|
||||
return this._callFunction("getByName",
|
||||
[ name, contextArg(context) ],
|
||||
callback);
|
||||
},
|
||||
|
||||
getByDomainAndName(domain, name, context, callback) {
|
||||
return this._callFunction("getByDomainAndName",
|
||||
[ domain, name, contextArg(context) ],
|
||||
callback);
|
||||
},
|
||||
|
||||
getBySubdomainAndName(domain, name, context, callback) {
|
||||
return this._callFunction("getBySubdomainAndName",
|
||||
[ domain, name, contextArg(context) ],
|
||||
callback);
|
||||
},
|
||||
|
||||
getGlobal(name, context, callback) {
|
||||
return this._callFunction("getGlobal",
|
||||
[ name, contextArg(context) ],
|
||||
callback);
|
||||
},
|
||||
|
||||
getCachedByDomainAndName: NYI,
|
||||
getCachedBySubdomainAndName: NYI,
|
||||
getCachedGlobal: NYI,
|
||||
|
||||
set(domain, name, value, context, callback) {
|
||||
this._callFunction("set",
|
||||
[ domain, name, value, contextArg(context) ],
|
||||
callback);
|
||||
},
|
||||
|
||||
setGlobal(name, value, context, callback) {
|
||||
this._callFunction("setGlobal",
|
||||
[ name, value, contextArg(context) ],
|
||||
callback);
|
||||
},
|
||||
|
||||
removeByDomainAndName(domain, name, context, callback) {
|
||||
this._callFunction("removeByDomainAndName",
|
||||
[ domain, name, contextArg(context) ],
|
||||
callback);
|
||||
},
|
||||
|
||||
removeBySubdomainAndName(domain, name, context, callback) {
|
||||
this._callFunction("removeBySubdomainAndName",
|
||||
[ domain, name, contextArg(context) ],
|
||||
callback);
|
||||
},
|
||||
|
||||
removeGlobal(name, context, callback) {
|
||||
this._callFunction("removeGlobal", [ name, contextArg(context) ], callback);
|
||||
},
|
||||
|
||||
removeByDomain(domain, context, callback) {
|
||||
this._callFunction("removeByDomain", [ domain, contextArg(context) ],
|
||||
callback);
|
||||
},
|
||||
|
||||
removeBySubdomain(domain, context, callback) {
|
||||
this._callFunction("removeBySubdomain", [ domain, contextArg(context) ],
|
||||
callback);
|
||||
},
|
||||
|
||||
removeByName(name, context, callback) {
|
||||
this._callFunction("removeByName", [ name, value, contextArg(context) ],
|
||||
callback);
|
||||
},
|
||||
|
||||
removeAllDomains(context, callback) {
|
||||
this._callFunction("removeAllDomains", [ contextArg(context) ], callback);
|
||||
},
|
||||
|
||||
removeAllGlobals(context, callback) {
|
||||
this._callFunction("removeAllGlobals", [ contextArg(context) ],
|
||||
callback);
|
||||
},
|
||||
|
||||
addObserverForName(name, observer) {
|
||||
let set = this._observers.get(name);
|
||||
if (!set) {
|
||||
|
@ -233,4 +157,26 @@ var ContentPrefServiceChild = {
|
|||
extractDomain: NYI
|
||||
};
|
||||
|
||||
function forwardMethodToParent(method, signature, ...args) {
|
||||
// Ignore superfluous arguments
|
||||
args = args.slice(0, signature.length);
|
||||
|
||||
// Process context argument for forwarding
|
||||
let contextIndex = signature.indexOf("context");
|
||||
if (contextIndex > -1) {
|
||||
args[contextIndex] = contextArg(args[contextIndex]);
|
||||
}
|
||||
// Take out the callback argument, if present.
|
||||
let callbackIndex = signature.indexOf("callback");
|
||||
let callback = null;
|
||||
if (callbackIndex > -1 && args.length > callbackIndex) {
|
||||
callback = args.splice(callbackIndex, 1)[0];
|
||||
}
|
||||
this._callFunction(method, args, callback);
|
||||
}
|
||||
|
||||
for (let [method, signature] of _methodsCallableFromChild) {
|
||||
ContentPrefServiceChild[method] = forwardMethodToParent.bind(ContentPrefServiceChild, method, signature);
|
||||
}
|
||||
|
||||
ContentPrefServiceChild.init();
|
||||
|
|
|
@ -11,6 +11,8 @@ const Cc = Components.classes;
|
|||
const Ci = Components.interfaces;
|
||||
const Cu = Components.utils;
|
||||
|
||||
Cu.import("resource://gre/modules/ContentPrefUtils.jsm");
|
||||
|
||||
var ContentPrefServiceParent = {
|
||||
_cps2: null,
|
||||
|
||||
|
@ -95,6 +97,10 @@ var ContentPrefServiceParent = {
|
|||
receiveMessage(msg) {
|
||||
let data = msg.data;
|
||||
|
||||
if (!_methodsCallableFromChild.some(([method, args]) => method == data.call)) {
|
||||
throw new Error(`Can't call ${data.call} from child!`);
|
||||
}
|
||||
|
||||
let args = data.args;
|
||||
let requestId = data.requestId;
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ this.EXPORTED_SYMBOLS = [
|
|||
"cbHandleError",
|
||||
"cbHandleCompletion",
|
||||
"safeCallback",
|
||||
"_methodsCallableFromChild",
|
||||
];
|
||||
|
||||
const { interfaces: Ci, classes: Cc, results: Cr, utils: Cu } = Components;
|
||||
|
@ -49,3 +50,20 @@ function safeCallback(callbackObj, methodName, args) {
|
|||
Cu.reportError(err);
|
||||
}
|
||||
}
|
||||
|
||||
const _methodsCallableFromChild = Object.freeze([
|
||||
["getByName", ["name", "context", "callback"]],
|
||||
["getByDomainAndName", ["domain", "name", "context", "callback"]],
|
||||
["getBySubdomainAndName", ["domain", "name", "context", "callback"]],
|
||||
["getGlobal", ["name", "context", "callback"]],
|
||||
["set", ["domain", "name", "value", "context", "callback"]],
|
||||
["setGlobal", ["name", "value", "context", "callback"]],
|
||||
["removeByDomainAndName", ["domain", "name", "context", "callback"]],
|
||||
["removeBySubdomainAndName", ["domain", "name", "context", "callback"]],
|
||||
["removeGlobal", ["name", "context", "callback"]],
|
||||
["removeByDomain", ["domain", "context", "callback"]],
|
||||
["removeBySubdomain", ["domain", "context", "callback"]],
|
||||
["removeByName", ["name", "context", "callback"]],
|
||||
["removeAllDomains", ["context", "callback"]],
|
||||
["removeAllGlobals", ["context", "callback"]],
|
||||
]);
|
||||
|
|
Загрузка…
Ссылка в новой задаче