[Pkg-mozext-commits] [adblock-plus] 210/464: Allow specifying when WindowObserver should notify the listener

David Prévot taffit at moszumanska.debian.org
Tue Jul 22 20:44:18 UTC 2014


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

taffit pushed a commit to branch master
in repository adblock-plus.

commit 3404e109d1ad3f01ee458cf5ece457216111a90d
Author: Wladimir Palant <trev at adblockplus.org>
Date:   Mon Jan 23 14:27:45 2012 +0100

    Allow specifying when WindowObserver should notify the listener
---
 windowObserver.js | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/windowObserver.js b/windowObserver.js
index ec346ba..a50bf09 100644
--- a/windowObserver.js
+++ b/windowObserver.js
@@ -17,11 +17,16 @@ exports.WindowObserver = WindowObserver;
  * This class will call listener's method applyToWindow() for all new chrome
  * windows being opened. It will also call listener's method removeFromWindow()
  * for all windows still open when the extension is shut down.
+ * @param {Object} listener
+ * @param {String} [when]   when to execute applyToWindow(). "start" means immediately
+ *                          when the window opens, "ready" when its contents are available
+ *                          and "end" (default) means to wait until the "load" event.
  * @constructor
  */
-function WindowObserver(/**Object*/ listener)
+function WindowObserver(listener, when)
 {
   this._listener  = listener;
+  this._when = when;
 
   let e = Services.ww.getWindowEnumerator();
   while (e.hasMoreElements())
@@ -42,6 +47,7 @@ function WindowObserver(/**Object*/ listener)
 WindowObserver.prototype =
 {
   _listener: null,
+  _when: null,
   _shutdownHandler: null,
 
   shutdown: function()
@@ -58,8 +64,14 @@ WindowObserver.prototype =
   {
     if (topic == "domwindowopened")
     {
+      if (this._when == "start")
+      {
+        this._listener.applyToWindow(window);
+        return;
+      }
+
       let window = subject.QueryInterface(Ci.nsIDOMWindow);
-      window.addEventListener("DOMContentLoaded", function()
+      window.addEventListener(this._when == "ready" ? "DOMContentLoaded" : "load", function()
       {
         if (this._shutdownHandler)
           this._listener.applyToWindow(window);

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



More information about the Pkg-mozext-commits mailing list