Bug 1391594 - If a browser window unloads, make sure ProcessHangMonitor removes event handlers. r?billm draft
authorMike Conley <mconley@mozilla.com>
Mon, 02 Oct 2017 18:38:12 -0400
changeset 673840 84a06de1c0a237551f5350e9670ba0352d9d9fba
parent 671089 35fbf14b96a633c3f66ea13c1a163a3f3a4219b9
child 673841 2ed617ce1f6c7fb3698ab92c2aae0ba7e712dfe5
child 673843 edcae2cdda202a9fb69d89559167561ac026cfb2
child 673847 3af4eeeed0f2609387a05b572a038aed921c1186
push id82666
push usermconley@mozilla.com
push dateMon, 02 Oct 2017 22:48:53 +0000
reviewersbillm
bugs1391594
milestone58.0a1
Bug 1391594 - If a browser window unloads, make sure ProcessHangMonitor removes event handlers. r?billm MozReview-Commit-ID: IgA7vQSOCtp
browser/modules/ProcessHangMonitor.jsm
--- a/browser/modules/ProcessHangMonitor.jsm
+++ b/browser/modules/ProcessHangMonitor.jsm
@@ -391,31 +391,41 @@ var ProcessHangMonitor = {
 
   /**
    * Install event handlers on |win| to watch for events that would
    * cause a different hang report to be displayed.
    */
   trackWindow(win) {
     win.gBrowser.tabContainer.addEventListener("TabSelect", this, true);
     win.gBrowser.tabContainer.addEventListener("TabRemotenessChange", this, true);
+    win.addEventListener("unload", this, true);
   },
 
   untrackWindow(win) {
     win.gBrowser.tabContainer.removeEventListener("TabSelect", this, true);
     win.gBrowser.tabContainer.removeEventListener("TabRemotenessChange", this, true);
+    win.removeEventListener("unload", this, true);
   },
 
   handleEvent(event) {
     let win = event.target.ownerGlobal;
 
-    // If a new tab is selected or if a tab changes remoteness, then
-    // we may need to show or hide a hang notification.
-
-    if (event.type == "TabSelect" || event.type == "TabRemotenessChange") {
-      this.updateWindow(win);
+    switch (event.type) {
+      // If a new tab is selected or if a tab changes remoteness, then
+      // we may need to show or hide a hang notification.
+      case "TabSelect":
+        // intentional fall-through
+      case "TabRemotenessChange": {
+        this.updateWindow(win);
+        break;
+      }
+      case "unload": {
+        this.untrackWindow(win);
+        break;
+      }
     }
   },
 
   /**
    * Handle a potentially new hang report. If it hasn't been seen
    * before, show a notification for it in all open XUL windows.
    */
   reportHang(report) {