Bug 1641839 - [remote] Only emit Page.frameAttached and Page.frameAttached for frames. r=remote-protocol-reviewers,maja_zf

Differential Revision: https://phabricator.services.mozilla.com/D77483
This commit is contained in:
Henrik Skupin 2020-06-02 16:00:26 +00:00
parent 9c23d852e1
commit c0b000a0ed
2 changed files with 41 additions and 18 deletions

View file

@ -64,8 +64,14 @@ class Page extends ContentProcessDomain {
async enable() {
if (!this.enabled) {
this.session.contextObserver.on("frame-attached", this._onFrameAttached);
this.session.contextObserver.on("frame-detached", this._onFrameDetached);
this.session.contextObserver.on(
"docshell-created",
this._onFrameAttached
);
this.session.contextObserver.on(
"docshell-destroyed",
this._onFrameDetached
);
this.session.contextObserver.on(
"frame-navigated",
this._onFrameNavigated
@ -99,8 +105,14 @@ class Page extends ContentProcessDomain {
disable() {
if (this.enabled) {
this.session.contextObserver.off("frame-attached", this._onFrameAttached);
this.session.contextObserver.off("frame-detached", this._onFrameDetached);
this.session.contextObserver.off(
"docshell-created",
this._onFrameAttached
);
this.session.contextObserver.off(
"docshell-destroyed",
this._onFrameDetached
);
this.session.contextObserver.off(
"frame-navigated",
this._onFrameNavigated
@ -256,16 +268,32 @@ class Page extends ContentProcessDomain {
return this.content.location.href;
}
_onFrameAttached(name, { frameId, parentFrameId }) {
_onFrameAttached(name, { id }) {
const bc = BrowsingContext.get(id);
// Don't emit for top-level browsing contexts
if (!bc.parent) {
return;
}
// TODO: Use a unique identifier for frames (bug 1605359)
this.emit("Page.frameAttached", {
frameId,
parentFrameId,
frameId: bc.id.toString(),
parentFrameId: bc.parent.id.toString(),
stack: null,
});
}
_onFrameDetached(name, { frameId }) {
this.emit("Page.frameDetached", { frameId });
_onFrameDetached(name, { id }) {
const bc = BrowsingContext.get(id);
// Don't emit for top-level browsing contexts
if (!bc.parent) {
return;
}
// TODO: Use a unique identifier for frames (bug 1605359)
this.emit("Page.frameDetached", { frameId: bc.id.toString() });
}
_onFrameNavigated(name, { frameId, window }) {

View file

@ -145,19 +145,14 @@ class ContextObserver {
}
onDocShellCreated(docShell) {
const parent = docShell.browsingContext.parent;
// TODO: Use a unique identifier for frames (bug 1605359)
this.emit("frame-attached", {
frameId: docShell.browsingContext.id.toString(),
parentFrameId: parent ? parent.id.toString() : null,
this.emit("docshell-created", {
id: docShell.browsingContext.id,
});
}
onDocShellDestroyed(docShell) {
// TODO: Use a unique identifier for frames (bug 1605359)
this.emit("frame-detached", {
frameId: docShell.browsingContext.id.toString(),
this.emit("docshell-destroyed", {
id: docShell.browsingContext.id,
});
}
}