Bug 1543071 - Implement Target.targetDestroyed event r=ato
authorAlexandre Poirot <poirot.alex@gmail.com>
Wed, 19 Jun 2019 12:22:34 +0000
changeset 479199 f24caf8d9666393bcaceb167a9f62fe2cf67bf0a
parent 479198 cdb8199134d6c4dd535cca3bbc03a604065f21f0
child 479200 430bb08ecd6872db4566caf39380685f53be78b5
push id36173
push userrgurzau@mozilla.com
push dateWed, 19 Jun 2019 15:50:11 +0000
treeherdermozilla-central@10e3ed789e2b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato
bugs1543071
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1543071 - Implement Target.targetDestroyed event r=ato Differential Revision: https://phabricator.services.mozilla.com/D35106
remote/domains/parent/Target.jsm
--- a/remote/domains/parent/Target.jsm
+++ b/remote/domains/parent/Target.jsm
@@ -12,48 +12,57 @@ const {TabSession} = ChromeUtils.import(
 
 let sessionIds = 1;
 
 class Target extends Domain {
   constructor(session) {
     super(session);
 
     this.onTargetCreated = this.onTargetCreated.bind(this);
+    this.onTargetDestroyed = this.onTargetDestroyed.bind(this);
   }
 
   getBrowserContexts() {
     return {
       browserContextIds: [],
     };
   }
 
   setDiscoverTargets({ discover }) {
     const { targets } = this.session.target;
     if (discover) {
       targets.on("connect", this.onTargetCreated);
+      targets.on("disconnect", this.onTargetDestroyed);
     } else {
       targets.off("connect", this.onTargetCreated);
+      targets.off("disconnect", this.onTargetDestroyed);
     }
     for (const target of targets) {
       this.onTargetCreated("connect", target);
     }
   }
 
   onTargetCreated(eventName, target) {
     this.emit("Target.targetCreated", {
       targetInfo: {
         browserContextId: target.id,
         targetId: target.id,
         type: "page",
       },
     });
   }
 
+  onTargetDestroyed(eventName, target) {
+    this.emit("Target.targetDestroyed", {
+      targetId: target.id,
+    });
+  }
+
   async createTarget() {
-    const {targets} = this.session.target;
+    const { targets } = this.session.target;
     const onTarget = targets.once("connect");
     const tab = TabManager.addTab();
     const target = await onTarget;
     if (tab.linkedBrowser != target.browser) {
       throw new Error("Unexpected tab opened: " + tab.linkedBrowser.currentURI.spec);
     }
     return {targetId: target.id};
   }