Bug 1543151 - Implement DOM.getContentQuads. r=remote-protocol-reviewers,ato

Differential Revision: https://phabricator.services.mozilla.com/D27519

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alexandre Poirot 2019-06-25 19:34:05 +00:00
parent 160eb39ab9
commit c96f5c4244

View File

@ -8,4 +8,52 @@ var EXPORTED_SYMBOLS = ["DOM"];
const {ContentProcessDomain} = ChromeUtils.import("chrome://remote/content/domains/ContentProcessDomain.jsm");
class DOM extends ContentProcessDomain {}
class DOM extends ContentProcessDomain {
constructor(session) {
super(session);
this.enabled = false;
}
destructor() {
this.disable();
}
// commands
async enable() {
if (!this.enabled) {
this.enabled = true;
}
}
disable() {
if (this.enabled) {
this.enabled = false;
}
}
getContentQuads({ objectId }) {
const Runtime = this.session.domains.get("Runtime");
if (!Runtime) {
throw new Error("Runtime domain is not instantiated");
}
const obj = Runtime.getRemoteObject(objectId);
if (!obj) {
throw new Error("Cannot find object with id = " + objectId);
}
const unsafeObject = obj.unsafeDereference();
if (!unsafeObject.getBoxQuads) {
throw new Error("RemoteObject is not a node");
}
let quads = unsafeObject.getBoxQuads({ relativeTo: this.content.document });
quads = quads.map(quad => {
return [
quad.p1.x, quad.p1.y,
quad.p2.x, quad.p2.y,
quad.p3.x, quad.p3.y,
quad.p4.x, quad.p4.y,
].map(Math.round);
});
return { quads };
}
}