[Pkg-mozext-commits] [firetray] 122/399: cleaner fix to binding (unload eventListeners) problem
David Prévot
taffit at alioth.debian.org
Tue Oct 29 18:23:26 UTC 2013
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch dfsg-clean
in repository firetray.
commit 6b4fd546d259f043f77f2ff5e8125cfb22da3130
Author: foudfou <foudil.newbie+git at gmail.com>
Date: Thu Dec 29 23:41:12 2011 +0100
cleaner fix to binding (unload eventListeners) problem
« We need a separate namespace for the chrome because the chrome namespace
objects are repeated for each window, while the module namespace objects are
unique for all windows. » see:
https://developer.mozilla.org/en/XUL_School/JavaScript_Object_Management
Otherwise, by using firetray.Main=, we would be re-defining it with each
window, and for *all* other windows. So that, by closing the last window, we'd
remove objects attached to it (like the 'window' object), thus leaving other's
references pending. See:
https://groups.google.com/group/mozilla.dev.extensions/browse_thread/thread/e89e9c2a834ff2b6#
---
src/chrome/content/overlay.js | 34 +++++++++-------------------------
src/chrome/content/overlay.xul | 4 ++--
2 files changed, 11 insertions(+), 27 deletions(-)
diff --git a/src/chrome/content/overlay.js b/src/chrome/content/overlay.js
index e41aebd..72ff241 100644
--- a/src/chrome/content/overlay.js
+++ b/src/chrome/content/overlay.js
@@ -7,24 +7,17 @@ if ("undefined" == typeof(Cc)) var Cc = Components.classes;
if ("undefined" == typeof(Ci)) var Ci = Components.interfaces;
if ("undefined" == typeof(Cu)) var Cu = Components.utils;
-/**
- * firetray namespace.
- */
-if ("undefined" == typeof(firetray)) {
- var firetray = {};
-};
-
-firetray.Main = {
- self: function() { return this; },
+// https://groups.google.com/group/mozilla.dev.extensions/browse_thread/thread/e89e9c2a834ff2b6#
+var firetrayChrome = {
onLoad: function(win) {
- // initialization code
+ // strings a chrome-specific
this.strings = document.getElementById("firetray-strings");
try {
// Set up preference change observer
firetray.Utils.prefService.QueryInterface(Ci.nsIPrefBranch2);
- firetray.Utils.prefService.addObserver("", firetray.Main, false);
+ firetray.Utils.prefService.addObserver("", firetrayChrome, false);
}
catch (ex) {
ERROR(ex);
@@ -39,8 +32,8 @@ firetray.Main = {
firetray.Messaging.updateUnreadMsgCount();
// prevent window closing.
- win.addEventListener('close', firetray.Main.onClose, true);
- // NOTE: each new window gets a new firetray.Main, and hence listens to
+ win.addEventListener('close', firetrayChrome.onClose, true);
+ // NOTE: each new window gets a new firetrayChrome, and hence listens to
// pref changes
LOG('Firetray LOADED: ' + init);
@@ -49,7 +42,7 @@ firetray.Main = {
onQuit: function(win) {
// Remove observer
- firetray.Utils.prefService.removeObserver("", firetray.Main);
+ firetray.Utils.prefService.removeObserver("", firetrayChrome);
firetray.Handler.unregisterWindow(win);
@@ -87,22 +80,13 @@ firetray.Main = {
// should be sufficient for a delayed Startup (no need for window.setTimeout())
// https://developer.mozilla.org/en/XUL_School/JavaScript_Object_Management.html
// https://developer.mozilla.org/en/Extensions/Performance_best_practices_in_extensions#Removing_Event_Listeners
-/* NOTE: this is tricky: it seems we need to keep some reference to 'firetray'
- outside listeners. Otherwise the following will fail: open a new window
- twice, and close them (CTRL-w). On the second close, onQuit fails because
- globals ('firetray', 'Ci', ...) are undefined. THIS IS BECAUSE 'firetray'
- GETS DEFINED IN commons.js !! I could achieve the "linkage" in two ways:
- 1. bind some method of firetray.Main to itself, or 2. use handlers instead
- of an anonymous function in the listeners: window.addEventListener('load',
- firetray.Main.onLoad, false); */
-var firetrayMain = firetray.Main.self.bind(firetray.Main);
window.addEventListener(
'load', function (e) {
removeEventListener('load', arguments.callee, true);
- firetrayMain().onLoad(this); },
+ firetrayChrome.onLoad(this); },
false);
window.addEventListener(
'unload', function (e) {
removeEventListener('unload', arguments.callee, true);
- firetrayMain().onQuit(this); },
+ firetrayChrome.onQuit(this); },
false);
diff --git a/src/chrome/content/overlay.xul b/src/chrome/content/overlay.xul
index dca2fe2..085be73 100644
--- a/src/chrome/content/overlay.xul
+++ b/src/chrome/content/overlay.xul
@@ -9,9 +9,9 @@
</stringbundleset>
<keyset>
- <!-- otherwise window.addEventListener("keypress", firetray.Main.onKeyPress, true);
+ <!-- otherwise window.addEventListener("keypress", firetrayChrome.onKeyPress, true);
see https://addons.mozilla.org/en-US/firefox/addon/move-tabs/ -->
- <key id="key_close" key="W" modifiers="shift meta" oncommand="firetray.Handler.showHideToTray();" /> <!-- firetray.Main.onKeyClose(); -->
+ <key id="key_close" key="W" modifiers="shift meta" oncommand="firetray.Handler.showHideToTray();" /> <!-- firetrayChrome.onKeyClose(); -->
</keyset>
</overlay>
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/firetray.git
More information about the Pkg-mozext-commits
mailing list