Bug 1314855 - keep a strong reference to the listener for background thumbnail pages, r=markh
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Thu, 02 Mar 2017 16:05:49 +0000
changeset 493328 06464864d84f4400bd0ab6e37a89a820747f34ec
parent 493327 bcc6b0e45020b1f2fe6b160ace1ecc5b24e3cf3e
child 493329 15651f8268b74f12d6db4b4949bcf2bdbef63809
push id47743
push userbzbarsky@mozilla.com
push dateFri, 03 Mar 2017 21:15:16 +0000
reviewersmarkh
bugs1314855
milestone54.0a1
Bug 1314855 - keep a strong reference to the listener for background thumbnail pages, r=markh MozReview-Commit-ID: 1mWv4kpmqwE
toolkit/components/thumbnails/BackgroundPageThumbs.jsm
--- a/toolkit/components/thumbnails/BackgroundPageThumbs.jsm
+++ b/toolkit/components/thumbnails/BackgroundPageThumbs.jsm
@@ -160,34 +160,35 @@ const BackgroundPageThumbs = {
 
     this._startedParentWinInit = true;
 
     // Create a windowless browser and load our hosting
     // (privileged) document in it.
     let wlBrowser = Services.appShell.createWindowlessBrowser(true);
     wlBrowser.QueryInterface(Ci.nsIInterfaceRequestor);
     let webProgress = wlBrowser.getInterface(Ci.nsIWebProgress);
-    let listener = {
+    this._listener = {
       QueryInterface: XPCOMUtils.generateQI([
         Ci.nsIWebProgressListener, Ci.nsIWebProgressListener2,
         Ci.nsISupportsWeakReference]),
     };
-    listener.onStateChange = (wbp, request, stateFlags, status) => {
+    this._listener.onStateChange = (wbp, request, stateFlags, status) => {
       if (!request) {
         return;
       }
       if (stateFlags & Ci.nsIWebProgressListener.STATE_STOP &&
           stateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK) {
-        webProgress.removeProgressListener(listener);
+        webProgress.removeProgressListener(this._listener);
+        delete this._listener;
         // Get the window reference via the document.
         this._parentWin = wlBrowser.document.defaultView;
         this._processCaptureQueue();
       }
     };
-    webProgress.addProgressListener(listener, Ci.nsIWebProgress.NOTIFY_STATE_ALL);
+    webProgress.addProgressListener(this._listener, Ci.nsIWebProgress.NOTIFY_STATE_ALL);
     wlBrowser.loadURI("chrome://global/content/backgroundPageThumbs.xhtml", 0, null, null, null);
     this._windowlessContainer = wlBrowser;
 
     return false;
   },
 
   /**
    * Destroys the service.  Queued and pending captures will never complete, and
@@ -198,16 +199,17 @@ const BackgroundPageThumbs = {
       this._captureQueue.forEach(cap => cap.destroy());
     this._destroyBrowser();
     if (this._windowlessContainer)
       this._windowlessContainer.close();
     delete this._captureQueue;
     delete this._windowlessContainer;
     delete this._startedParentWinInit;
     delete this._parentWin;
+    delete this._listener;
   },
 
   /**
    * Creates the thumbnail browser if it doesn't already exist.
    */
   _ensureBrowser() {
     if (this._thumbBrowser && !this._renewThumbBrowser)
       return;