[Pkg-mozext-commits] [nosquint] 40/47: More thoroughly clean up on tab/window close

David Prévot taffit at moszumanska.debian.org
Tue Apr 28 01:41:20 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to annotated tag 2.1.6
in repository nosquint.

commit 7e794091844b256429300a0ba5ef5a9a29c59adc
Author: Jason Tackaberry <tack at urandom.ca>
Date:   Mon Jan 30 19:47:02 2012 -0500

    More thoroughly clean up on tab/window close
    
    Detach per-tab DOMFrameContentLoaded listener and remove per-window
    addon listener.
    
    Failing to do these _may_ theoretically cause memory leaks.  I haven't
    actually verified this, but it's not going to hurt to perform this
    cleanup.
---
 src/content/browser.js    | 41 +++++++++++++++++++++++------------------
 src/content/interfaces.js | 15 +++++----------
 2 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/src/content/browser.js b/src/content/browser.js
index e3e0853..4498901 100644
--- a/src/content/browser.js
+++ b/src/content/browser.js
@@ -64,15 +64,15 @@ NoSquint.browser = NoSquint.ns(function() { with (NoSquint) {
         if (NSQ.storage.dialogs.site)
             NSQ.storage.dialogs.site.die();
 
-        /* When the window is closed, the Tabclose event doesn't fire for each
+        /* When the window is closed, the TabClose event doesn't fire for each
          * browser tab automatically, so we must clean up explicitly.
          *
          * This fixes issue #1 which reports zombie compartments.
          */
-        for (let browser in iter(gBrowser.browsers)) {
-            browser.removeProgressListener(browser.getUserData('nosquint').listener);
-            browser.setUserData('nosquint', null, null);
-        }
+        for (let browser in iter(gBrowser.browsers))
+            this.detach(browser);
+
+        this.observer.unhook();
 
         gBrowser.tabContainer.removeEventListener('TabOpen', this.handleTabOpen, false);
         gBrowser.tabContainer.removeEventListener('TabSelect', this.handleTabSelect, false);
@@ -220,9 +220,7 @@ NoSquint.browser = NoSquint.ns(function() { with (NoSquint) {
     };
 
     this.handleTabClose = function(event) {
-        var browser = event.target.linkedBrowser;
-        browser.removeProgressListener(browser.getUserData('nosquint').listener);
-        browser.setUserData('nosquint', null, null);
+        NSQ.browser.detach(event.target.linkedBrowser);
     };
 
 
@@ -420,20 +418,27 @@ NoSquint.browser = NoSquint.ns(function() { with (NoSquint) {
 
         var userData = {
             listener: listener,
-            stylers: []
+            stylers: [],
+            handleDOMFrameContentLoaded: function(event) {
+                if (!event.target.contentWindow)
+                    return;
+                var styler = NSQ.browser.getDocumentStyler(browser, event.target.contentWindow.document);
+                styler();
+                browser.getUserData('nosquint').stylers.push(styler);
+            }
         };
         browser.setUserData('nosquint', userData, null);
-
-        browser.addEventListener('DOMFrameContentLoaded', function(event) {
-            if (!event.target.contentWindow)
-                return;
-            var styler = NSQ.browser.getDocumentStyler(browser, event.target.contentWindow.document);
-            styler();
-            browser.getUserData('nosquint').stylers.push(styler);
-        }, true);
-
+        browser.addEventListener('DOMFrameContentLoaded', userData.handleDOMFrameContentLoaded, true);
     };
 
+    /* Undoes an attach(); called from TabClose event and destroy()
+     */
+    this.detach = function(browser) {
+        var userData = browser.getUserData('nosquint');
+        browser.removeProgressListener(userData.listener);
+        browser.removeEventListener('DOMFrameContentLoaded', userData.handleDOMFrameContentLoaded, true);
+        browser.setUserData('nosquint', null, null);
+    };
 
     /* Zooms text and/or full zoom to the specified level.  If text or full is
      * null, the default for browser is used.  If it is false, it is
diff --git a/src/content/interfaces.js b/src/content/interfaces.js
index b97772c..6544c1a 100644
--- a/src/content/interfaces.js
+++ b/src/content/interfaces.js
@@ -191,16 +191,10 @@ NoSquint.interfaces = NoSquint.ns(function() { with (NoSquint) {
         _os: null,  
         _inPrivateBrowsing: false, // whether we are in private browsing mode  
         watcher: {}, // the watcher object  
-        _hooked: false,
        
         init: function () {  
-            this._inited = true;  
             this._os = Components.classes["@mozilla.org/observer-service;1"]  
                                  .getService(Components.interfaces.nsIObserverService);  
-            this._hook();
-        },
-
-        _hook: function() {
             this._os.addObserver(this, "private-browsing", false);  
             this._os.addObserver(this, "quit-application-granted", false);  
             if (is3x())
@@ -218,13 +212,15 @@ NoSquint.interfaces = NoSquint.ns(function() { with (NoSquint) {
                 // ignore exceptions in older versions of Firefox  
             }
 
-            this._hooked = true;
         },
 
-        _unhook: function() {
+        unhook: function() {
             this._os.removeObserver(this, "quit-application-granted");  
             this._os.removeObserver(this, "private-browsing");  
-            this._hooked = false;
+            if (is3x())
+                this._os.removeObserver(this, "em-action-requested");
+            else
+                AddonManager.removeAddonListener(this);
         },
 
         onDisabling: function(addon, needsRestart) {
@@ -269,7 +265,6 @@ NoSquint.interfaces = NoSquint.ns(function() { with (NoSquint) {
 
                 case "quit-application-granted":
                     NSQ.storage.quitting = true;
-                    this._unhook();
                     break;
 
                 // This is for ff 3.x; just dispatch to the 4.x handlers.

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/nosquint.git



More information about the Pkg-mozext-commits mailing list