зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1817639 - [devtools] Use abortController to relay target actor events in highlighters.js r=nchevobbe,devtools-reviewers
Depends on D170293 Differential Revision: https://phabricator.services.mozilla.com/D170294
This commit is contained in:
Родитель
37af8302a5
Коммит
7610716776
|
@ -177,22 +177,18 @@ exports.CustomHighlighterActor = class CustomHighligherActor extends Actor {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class HighlighterEnvironment extends EventEmitter {
|
class HighlighterEnvironment extends EventEmitter {
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
this.relayTargetActorWindowReady = this.relayTargetActorWindowReady.bind(
|
|
||||||
this
|
|
||||||
);
|
|
||||||
this.relayTargetActorNavigate = this.relayTargetActorNavigate.bind(this);
|
|
||||||
this.relayTargetActorWillNavigate = this.relayTargetActorWillNavigate.bind(
|
|
||||||
this
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
initFromTargetActor(targetActor) {
|
initFromTargetActor(targetActor) {
|
||||||
this._targetActor = targetActor;
|
this._targetActor = targetActor;
|
||||||
this._targetActor.on("window-ready", this.relayTargetActorWindowReady);
|
|
||||||
this._targetActor.on("navigate", this.relayTargetActorNavigate);
|
const relayedEvents = ["window-ready", "navigate", "will-navigate"];
|
||||||
this._targetActor.on("will-navigate", this.relayTargetActorWillNavigate);
|
|
||||||
|
this._abortController = new AbortController();
|
||||||
|
const signal = this._abortController.signal;
|
||||||
|
for (const event of relayedEvents) {
|
||||||
|
this._targetActor.on(event, this.relayTargetEvent.bind(this, event), {
|
||||||
|
signal,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
initFromWindow(win) {
|
initFromWindow(win) {
|
||||||
|
@ -302,23 +298,14 @@ class HighlighterEnvironment extends EventEmitter {
|
||||||
return this.docShell && this.docShell.chromeEventHandler;
|
return this.docShell && this.docShell.chromeEventHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
relayTargetActorWindowReady(data) {
|
relayTargetEvent(name, data) {
|
||||||
this.emit("window-ready", data);
|
this.emit(name, data);
|
||||||
}
|
|
||||||
|
|
||||||
relayTargetActorNavigate(data) {
|
|
||||||
this.emit("navigate", data);
|
|
||||||
}
|
|
||||||
|
|
||||||
relayTargetActorWillNavigate(data) {
|
|
||||||
this.emit("will-navigate", data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
if (this._targetActor) {
|
if (this._abortController) {
|
||||||
this._targetActor.off("window-ready", this.relayTargetActorWindowReady);
|
this._abortController.abort();
|
||||||
this._targetActor.off("navigate", this.relayTargetActorNavigate);
|
this._abortController = null;
|
||||||
this._targetActor.off("will-navigate", this.relayTargetActorWillNavigate);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// In case the environment was initialized from a window, we need to remove
|
// In case the environment was initialized from a window, we need to remove
|
||||||
|
|
Загрузка…
Ссылка в новой задаче