mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-12 06:52:25 +00:00
Bug 1400256 - Serialise IPC messages with evaluate.toJSON. r=whimboo
Instead of having commands serialising their own JSON-safe messages when communicating with the content frame script, this patch changes the AsyncMessageChannel to use evaluate.toJSON. MozReview-Commit-ID: LmAVGEjqMTB --HG-- extra : rebase_source : 7f39cccc1468217a8a6bcf107241fd5648cb24d2
This commit is contained in:
parent
3e13cd2cbc
commit
936135f0ac
@ -13,6 +13,7 @@ const {
|
||||
error,
|
||||
WebDriverError,
|
||||
} = Cu.import("chrome://marionette/content/error.js", {});
|
||||
Cu.import("chrome://marionette/content/evaluate.js");
|
||||
Cu.import("chrome://marionette/content/modal.js");
|
||||
|
||||
this.EXPORTED_SYMBOLS = ["proxy"];
|
||||
@ -126,30 +127,31 @@ proxy.AsyncMessageChannel = class {
|
||||
let path = proxy.AsyncMessageChannel.makePath(uuid);
|
||||
let cb = msg => {
|
||||
this.activeMessageId = null;
|
||||
let {data, type} = msg.json;
|
||||
|
||||
switch (msg.json.type) {
|
||||
case proxy.AsyncMessageChannel.ReplyType.Ok:
|
||||
case proxy.AsyncMessageChannel.ReplyType.Value:
|
||||
resolve(msg.json.data);
|
||||
let payload = evaluate.fromJSON(data);
|
||||
resolve(payload);
|
||||
break;
|
||||
|
||||
case proxy.AsyncMessageChannel.ReplyType.Error:
|
||||
let err = WebDriverError.fromJSON(msg.json.data);
|
||||
let err = WebDriverError.fromJSON(data);
|
||||
reject(err);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new TypeError(
|
||||
`Unknown async response type: ${msg.json.type}`);
|
||||
throw new TypeError(`Unknown async response type: ${type}`);
|
||||
}
|
||||
};
|
||||
|
||||
// The currently selected tab or window has been closed. No clean-up
|
||||
// is necessary to do because all loaded listeners are gone.
|
||||
this.closeHandler = event => {
|
||||
logger.debug(`Received DOM event ${event.type} for ${event.target}`);
|
||||
this.closeHandler = ({type, target}) => {
|
||||
logger.debug(`Received DOM event ${type} for ${target}`);
|
||||
|
||||
switch (event.type) {
|
||||
switch (type) {
|
||||
case "TabClose":
|
||||
case "unload":
|
||||
this.removeHandlers();
|
||||
@ -162,7 +164,7 @@ proxy.AsyncMessageChannel = class {
|
||||
// the active command has to be aborted. Therefore remove all handlers,
|
||||
// and cancel any ongoing requests in the listener.
|
||||
this.dialogueObserver_ = (subject, topic) => {
|
||||
logger.debug(`Received observer notification "${topic}"`);
|
||||
logger.debug(`Received observer notification ${topic}`);
|
||||
|
||||
this.removeAllListeners_();
|
||||
// TODO(ato): It's not ideal to have listener specific behaviour here:
|
||||
@ -259,17 +261,11 @@ proxy.AsyncMessageChannel = class {
|
||||
}
|
||||
}
|
||||
|
||||
sendReply_(uuid, type, data = undefined) {
|
||||
sendReply_(uuid, type, payload = undefined) {
|
||||
const path = proxy.AsyncMessageChannel.makePath(uuid);
|
||||
|
||||
let payload;
|
||||
if (data && typeof data.toJSON == "function") {
|
||||
payload = data.toJSON();
|
||||
} else {
|
||||
payload = data;
|
||||
}
|
||||
|
||||
const msg = {type, data: payload};
|
||||
let data = evaluate.toJSON(payload);
|
||||
const msg = {type, data};
|
||||
|
||||
// here sendAsync is actually the content frame's
|
||||
// sendAsyncMessage(path, message) global
|
||||
|
Loading…
x
Reference in New Issue
Block a user