2023-01-23 11:29:48 -08:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const { Helper } = ChromeUtils.import('chrome://juggler/content/Helper.js');
|
|
|
|
const { initialize } = ChromeUtils.import('chrome://juggler/content/content/main.js');
|
|
|
|
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const helper = new Helper();
|
|
|
|
|
|
|
|
let sameProcessInstanceNumber = 0;
|
|
|
|
|
2024-07-29 10:30:28 +02:00
|
|
|
const topBrowingContextToAgents = new Map();
|
|
|
|
|
2023-01-23 11:29:48 -08:00
|
|
|
class JugglerFrameChild extends JSWindowActorChild {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this._eventListeners = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
handleEvent(aEvent) {
|
2024-07-29 10:30:28 +02:00
|
|
|
const agents = this._agents();
|
|
|
|
if (!agents)
|
|
|
|
return;
|
|
|
|
if (aEvent.type === 'DOMWillOpenModalDialog') {
|
|
|
|
agents.channel.pause();
|
2023-03-21 01:23:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2024-07-29 10:30:28 +02:00
|
|
|
if (aEvent.type === 'DOMModalDialogClosed') {
|
|
|
|
agents.channel.resumeSoon();
|
2023-03-21 01:23:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2024-07-29 10:30:28 +02:00
|
|
|
if (aEvent.target === this.document) {
|
|
|
|
agents.pageAgent.onWindowEvent(aEvent);
|
|
|
|
agents.frameTree.onWindowEvent(aEvent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_agents() {
|
|
|
|
return topBrowingContextToAgents.get(this.browsingContext.top);
|
2023-01-23 11:29:48 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
actorCreated() {
|
|
|
|
this.actorName = `content::${this.browsingContext.browserId}/${this.browsingContext.id}/${++sameProcessInstanceNumber}`;
|
|
|
|
|
|
|
|
this._eventListeners.push(helper.addEventListener(this.contentWindow, 'load', event => {
|
2024-07-29 10:30:28 +02:00
|
|
|
this._agents()?.pageAgent.onWindowEvent(event);
|
2023-01-23 11:29:48 -08:00
|
|
|
}));
|
|
|
|
|
|
|
|
if (this.document.documentURI.startsWith('moz-extension://'))
|
|
|
|
return;
|
|
|
|
|
2024-07-29 10:30:28 +02:00
|
|
|
// Child frame events will be forwarded to related top-level agents.
|
|
|
|
if (this.browsingContext.parent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let agents = topBrowingContextToAgents.get(this.browsingContext);
|
|
|
|
if (!agents) {
|
|
|
|
agents = initialize(this.browsingContext, this.docShell);
|
|
|
|
topBrowingContextToAgents.set(this.browsingContext, agents);
|
|
|
|
}
|
|
|
|
agents.channel.bindToActor(this);
|
|
|
|
agents.actor = this;
|
2023-01-23 11:29:48 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
didDestroy() {
|
2024-07-29 10:30:28 +02:00
|
|
|
helper.removeListeners(this._eventListeners);
|
|
|
|
|
|
|
|
if (this.browsingContext.parent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const agents = topBrowingContextToAgents.get(this.browsingContext);
|
|
|
|
// The agents are already re-bound to a new actor.
|
2024-09-05 13:44:58 +02:00
|
|
|
if (agents?.actor !== this)
|
2024-07-29 10:30:28 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
topBrowingContextToAgents.delete(this.browsingContext);
|
|
|
|
|
|
|
|
agents.channel.resetTransport();
|
|
|
|
agents.pageAgent.dispose();
|
|
|
|
agents.frameTree.dispose();
|
2023-01-23 11:29:48 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
receiveMessage() { }
|
|
|
|
}
|
|
|
|
|
|
|
|
var EXPORTED_SYMBOLS = ['JugglerFrameChild'];
|