[Pkg-mozext-commits] [firetray] 22/399: * minimal platform check (work in progress) * best practice try: remove event listeners * minor refactoring

David Prévot taffit at alioth.debian.org
Tue Oct 29 18:23:07 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 46e0e2c5b67456a05f7098f4a24af230abfc5c29
Author: foudfou <foudil.newbie+git at gmail.com>
Date:   Sun Aug 14 15:38:20 2011 +0200

    * minimal platform check (work in progress)
    * best practice try: remove event listeners
    * minor refactoring
---
 TODO                          |    4 ++
 src/chrome/content/overlay.js |   18 +++++---
 src/install.rdf               |    1 +
 src/modules/MoztHandler.jsm   |   98 ++++++++++++++++++++++++-----------------
 4 files changed, 76 insertions(+), 45 deletions(-)

diff --git a/TODO b/TODO
new file mode 100644
index 0000000..e3b1431
--- /dev/null
+++ b/TODO
@@ -0,0 +1,4 @@
+* BUG: windows aren't restored at the same position, or with the same z-order
+https://developer.mozilla.org/en/nsIWindowMediator#getZOrderXULWindowEnumerator%28%29
+
+* make multi-platform. At least have js-ctypes library call dependant on OS detection. (best would be to have the OS-dependant modules loaded at startup) 
diff --git a/src/chrome/content/overlay.js b/src/chrome/content/overlay.js
index 4ba5aaf..d762366 100644
--- a/src/chrome/content/overlay.js
+++ b/src/chrome/content/overlay.js
@@ -20,9 +20,9 @@ mozt.Main = {
     }
 
     if (!mozt.Handler.initialized)
-      mozt.Handler.init();
+      var initOK = mozt.Handler.init();
 
-    mozt.Debug.debug('Moztray LOADED !');
+    mozt.Debug.debug('Moztray LOADED: ' + initOK);
     return true;
   },
 
@@ -52,6 +52,14 @@ mozt.Main = {
 // should be sufficient for a delayed Startup (no need for window.setTimeout())
 // https://developer.mozilla.org/en/Extensions/Performance_best_practices_in_extensions
 // https://developer.mozilla.org/en/XUL_School/JavaScript_Object_Management.html
-window.addEventListener("load", function (e) { mozt.Main.onLoad(); }, false);
-window.addEventListener("unload", function(e) { mozt.Main.onQuit(); }, false);
-// TODO: put all mozt into a module (jsm) so it's loaded only once
+// https://developer.mozilla.org/en/Extensions/Performance_best_practices_in_extensions#Removing_Event_Listeners
+window.addEventListener(
+  'load', function (e) {
+    removeEventListener('load', arguments.callee, true);
+    mozt.Main.onLoad(); },
+  false);
+window.addEventListener(
+  'unload', function (e) {
+    removeEventListener('unload', arguments.callee, true);
+    mozt.Main.onQuit(); },
+  false);
diff --git a/src/install.rdf b/src/install.rdf
index d026bba..ca6d5e0 100644
--- a/src/install.rdf
+++ b/src/install.rdf
@@ -12,6 +12,7 @@
     <em:description>A system tray extension for linux.</em:description>
     <!-- <em:optionsURL>chrome://moztray/content/options.xul</em:optionsURL> -->
     <em:iconURL>chrome://moztray/skin/icon32.png</em:iconURL>
+    <em:targetPlatform>Linux</em:targetPlatform> <!-- only Linux supported for now -->
 
     <em:targetApplication>
       <Description>
diff --git a/src/modules/MoztHandler.jsm b/src/modules/MoztHandler.jsm
index 3a54477..8393fd1 100644
--- a/src/modules/MoztHandler.jsm
+++ b/src/modules/MoztHandler.jsm
@@ -35,76 +35,83 @@ var mozt_activateCb;            // pointer to JS function. should not be eaten
 // (https://developer.mozilla.org/en/XUL_School/JavaScript_Object_Management)
 mozt.Handler = {
   initialized: false,
-
   _windowsHidden: false,
-
-  _getBaseWindow: function(win) {
-    var bw;
-    try { // thx Neil Deakin !!
-      bw = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-        .getInterface(Components.interfaces.nsIWebNavigation)
-        .QueryInterface(Components.interfaces.nsIDocShellTreeItem)
+  _handledDOMWindows: [],
+
+  _getBaseOrXULWindowFromDOMWindow: function(win, winType) {
+    let winInterface, winOut;
+    try {                       // thx Neil Deakin !!
+      winInterface =  win.QueryInterface(Ci.nsIInterfaceRequestor)
+        .getInterface(Ci.nsIWebNavigation)
+        .QueryInterface(Ci.nsIDocShellTreeItem)
         .treeOwner
-        .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-        .getInterface(Components.interfaces.nsIBaseWindow);
+        .QueryInterface(Ci.nsIInterfaceRequestor);
     } catch (ex) {
-      bw = null;
-      setTimeout(function() {throw ex; }, 0);
       // ignore no-interface exception
+      mozt.Debug.debug(ex);
+      Components.utils.reportError(ex);
+      return null;
     }
-    return bw;
-  },
 
-  _getAllWindows: function() {
-    mozt.Debug.debug("_getAllWindows");
-    var baseWindows = new Array();
-    var e = Services.wm.getEnumerator(null);
-    while (e.hasMoreElements()) {
-      var w = e.getNext();
-      baseWindows[baseWindows.length] = this._getBaseWindow(w);
+    if (winType == "BaseWindow")
+      winOut = winInterface.getInterface(Ci.nsIBaseWindow);
+    else if (winType == "XUL")
+      winOut = winInterface.getInterface(Ci.nsIXULWindow);
+    else {
+      Components.utils.reportError("MOZTRAY: unknown winType '" + winType + "'");
+      return null;
     }
-    return baseWindows;
+
+    return winOut;
   },
 
   /*
-   * might need to remember position...
-   * var outX = {}, outY = {}, outCX = {}, outCY = {};
-   * bw.getPositionAndSize(outX, outY, outCX, outCY);
-   * mozt.Debug.debug("pos: "
-   *                  + outX.value + ", "
-   *                  + outY.value + ", "
-   *                  + outCX.value + ", "
-   *                  + outCY.value
-   *                 );
+   * DAMN IT ! getZOrderDOMWindowEnumerator doesn't work on Linux :-(
+   * https://bugzilla.mozilla.org/show_bug.cgi?id=156333, and all windows
+   * seem to have the same zlevel ("normalZ") which is different from the
+   * z-order. There seems to be no means to get/set the z-order at this
+   * time...
    */
+  _updateHandledDOMWindows: function() {
+    mozt.Debug.debug("_updateHandledDOMWindows");
+    this._handledDOMWindows = [];
+    var windowsEnumerator = Services.wm.getEnumerator(null); // returns a nsIDOMWindow
+    while (windowsEnumerator.hasMoreElements()) {
+      this._handledDOMWindows[this._handledDOMWindows.length] =
+        windowsEnumerator.getNext();
+    }
+  },
+
   showHideToTray: function(a1, a2, a3) {
     mozt.Debug.debug("showHideToTray");
 
-    var baseWindows;
     try {
-      baseWindows = this._getAllWindows();
+      this._updateHandledDOMWindows();
     } catch (x) {
       mozt.Debug.debug(x);
     }
-    mozt.Debug.debug("baseWindows: " + baseWindows.length);
-    for(var i=0; i<baseWindows.length; i++) {
-      var bw = baseWindows[i];
+    mozt.Debug.debug("nb Windows: " + this._handledDOMWindows.length);
+
+    for(let i=0; i<this._handledDOMWindows.length; i++) {
+      let bw = this._getBaseOrXULWindowFromDOMWindow(
+        this._handledDOMWindows[i], "BaseWindow");
 
       mozt.Debug.debug('isHidden: ' + this._windowsHidden);
       mozt.Debug.debug("bw.visibility: " + bw.visibility);
       try {
-        if (this._windowsHidden) {
+        if (this._windowsHidden) { // show
           bw.visibility = true;
-        } else {
+        } else {                // hide
           bw.visibility = false;
+          let x = {}, y = {};
+          bw.getPosition(x, y);
+          mozt.Debug.debug("bw.position: " + x.value + ", " + y.value);
         }
       } catch (x) {
         mozt.Debug.debug(x);
       }
       mozt.Debug.debug("bw.visibility: " + bw.visibility);
-
       mozt.Debug.debug("bw.title: " + bw.title);
-      mozt.Debug.debug("bw.parentNativeWindow: " + bw.parentNativeWindow);
     }
 
     if (this._windowsHidden) {
@@ -116,6 +123,17 @@ mozt.Handler = {
   },
 
   init: function() {            // creates icon
+
+    // platform checks
+    let runtimeOS = Services.appinfo.OS; // "WINNT", "Linux", "Darwin"
+    let xulVer = Services.appinfo.platformVersion; // Services.vc.compare(xulVer,"2.0a")>=0 will be checked ing install, so we shouldn't need to care
+    mozt.Debug.debug("OS=" + runtimeOS + ", XULrunner=" + xulVer);
+    if (runtimeOS != "Linux") {
+      Components.utils.reportError("MOZTRAY: only Linux platform supported at this time. Moztray not loaded");
+      return;
+      // Cu.import("resource://moztray/MoztHandler-Linux.jsm");
+    }
+
     try {
 
       // instanciate tray icon

-- 
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