Bug 480080 - updateStatusBar not defined in gSelectionListener in viewSource.js (when it's getting notified of a selection change after the window has already closed), r=gavin
authorPhil Ringnalda <philringnalda@gmail.com>
Fri, 08 May 2009 21:36:55 -0700
changeset 28149 53351b69bbbd3014782236343b1bcb8dc740d9ee
parent 28148 c60c37d487cae83cbcbb7db59b1b867d6eba27e2
child 28151 db33722ec5d0016eec2c59aba2dc7697dd884959
push id6914
push userdbaron@mozilla.com
push dateSat, 09 May 2009 04:38:50 +0000
treeherdermozilla-central@db33722ec5d0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgavin
bugs480080
milestone1.9.2a1pre
Bug 480080 - updateStatusBar not defined in gSelectionListener in viewSource.js (when it's getting notified of a selection change after the window has already closed), r=gavin
toolkit/components/viewsource/content/viewSource.js
--- a/toolkit/components/viewsource/content/viewSource.js
+++ b/toolkit/components/viewsource/content/viewSource.js
@@ -54,16 +54,17 @@ try {
   var prefService = Components.classes["@mozilla.org/preferences-service;1"]
                               .getService(Components.interfaces.nsIPrefService);
   gPrefs = prefService.getBranch(null);
 } catch (ex) {
 }
 
 var gSelectionListener = {
   timeout: 0,
+  attached: false,
   notifySelectionChanged: function(doc, sel, reason)
   {
     // Coalesce notifications within 100ms intervals.
     if (!this.timeout)
       this.timeout = setTimeout(updateStatusBar, 100);
   }
 }
 
@@ -290,25 +291,35 @@ function onLoadContent()
     gGoToLine = 0;
   }
   document.getElementById('cmd_goToLine').removeAttribute('disabled');
 
   // Register a listener so that we can show the caret position on the status bar.
   window.content.getSelection()
    .QueryInterface(nsISelectionPrivate)
    .addSelectionListener(gSelectionListener);
+  gSelectionListener.attached = true;
 }
 
 function onUnloadContent()
 {
   //
   // Disable "go to line" while reloading due to e.g. change of charset
   // or toggling of syntax highlighting.
   //
   document.getElementById('cmd_goToLine').setAttribute('disabled', 'true');
+
+  // If we're not just unloading the initial "about:blank" which doesn't have
+  // a selection listener, get rid of it so it doesn't try to fire after the
+  // window has gone away.
+  if (gSelectionListener.attached) {
+    window.content.getSelection().QueryInterface(nsISelectionPrivate)
+          .removeSelectionListener(gSelectionListener);
+    gSelectionListener.attached = false;
+  }
 }
 
 function HandleAppCommandEvent(evt)
 {
   evt.stopPropagation();
   switch (evt.command) {
     case "Back":
       BrowserBack();