[Pkg-mozext-commits] [requestpolicy] 176/280: use the globalMM for loading frame scripts

David Prévot taffit at moszumanska.debian.org
Sat May 2 20:30:20 UTC 2015


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

taffit pushed a commit to branch master
in repository requestpolicy.

commit 3ecdab52daec2b6dd061bebdbeea7c6ea8c8953d
Author: Martin Kimmerle <dev at 256k.de>
Date:   Sun Jan 25 20:35:53 2015 +0100

    use the globalMM for loading frame scripts
    
    Before this commit, frame scripts have been loaded via the
    window's message manager. There was a strange bug, and
    using the global message manager instead fixed the bug.
    
    The issue was that in some tabs some event listeners haven't
    been registered correctly. As an example, the event
    "DOMContentLoaded" wasn't observed in some tabs so that in
    that tabs the red flag wasn't displayed for blocked content.
---
 src/content/lib/manager-for-event-listeners.jsm |  1 +
 src/content/main/window-manager.jsm             | 41 ++++++++++++-------------
 src/content/ui/frame.dom-content-loaded.js      |  4 +++
 src/content/ui/frame.js                         |  1 +
 4 files changed, 26 insertions(+), 21 deletions(-)

diff --git a/src/content/lib/manager-for-event-listeners.jsm b/src/content/lib/manager-for-event-listeners.jsm
index eca395d..584db8a 100644
--- a/src/content/lib/manager-for-event-listeners.jsm
+++ b/src/content/lib/manager-for-event-listeners.jsm
@@ -88,6 +88,7 @@ function addEvLis(listener) {
   listener.target.addEventListener(listener.eventType, listener.callback,
                                    listener.useCapture);
   listener.listening = true;
+  //Logger.dump("[RPC] event listener for '" + listener.eventType + "' added");
 };
 
 
diff --git a/src/content/main/window-manager.jsm b/src/content/main/window-manager.jsm
index 2ea349e..8f0210c 100644
--- a/src/content/main/window-manager.jsm
+++ b/src/content/main/window-manager.jsm
@@ -118,30 +118,9 @@ let rpWindowManager = (function(self) {
       Logger.warning(Logger.TYPE_ERROR,
                      "An error occurred while initializing the overlay: "+e, e);
     }
-
-    // ==================================
-    // # 6 : load frame scripts
-    try {
-      window.messageManager.loadFrameScript(frameScriptURI, true);
-    } catch (e) {
-      Logger.warning(Logger.TYPE_ERROR, "Error loading the frame script: "+e,e);
-    }
   }
 
   function unloadFromWindow(window) {
-    // # 6 : stop loading framescripts into new tabs
-    // --------------------------
-    // Note that it's not necessary to tell the framescripts'
-    // environments to shut down. Instead:
-    // - In case the window is closed, the will shut down on
-    //   the ContentFrameMessageManager's "unload" event.
-    // - In case the addon is being disabled or firefox gets quit,
-    //   the ParentProcessEnvironment will send a message to all
-    //   children.
-    let mm = window.messageManager;
-    mm.removeDelayedFrameScript(frameScriptURI);
-
-
     // # 5 : "shutdown" the overlay
     // ----------------------------
     if (window.requestpolicy) {
@@ -176,6 +155,13 @@ let rpWindowManager = (function(self) {
         WindowListener.setLoadFunction(loadIntoWindow);
         WindowListener.setUnloadFunction(unloadFromWindow);
         WindowListener.startListening();
+
+        // Load the framescript into all existing tabs.
+        // Also tell the globalMM to load it into each new
+        // tab from now on.
+        var globalMM = Cc["@mozilla.org/globalmessagemanager;1"]
+            .getService(Ci.nsIMessageListenerManager);
+        globalMM.loadFrameScript(frameScriptURI, true);
       });
 
   ProcessEnvironment.addStartupFunction(Environment.LEVELS.UI, loadStyleSheets);
@@ -183,6 +169,19 @@ let rpWindowManager = (function(self) {
   ProcessEnvironment.addShutdownFunction(
       Environment.LEVELS.INTERFACE,
       function() {
+        // Stop loading framescripts into new tabs.
+        // --------------------------
+        // Note that it's not necessary to tell the framescripts'
+        // environments to shut down. Instead:
+        // - In case the window is closed, the framescript will shut
+        //   down on the ContentFrameMessageManager's "unload" event.
+        // - In case the addon is being disabled or firefox gets quit,
+        //   the ParentProcessEnvironment will send a message to all
+        //   children.
+        var globalMM = Cc["@mozilla.org/globalmessagemanager;1"]
+            .getService(Ci.nsIMessageListenerManager);
+        globalMM.removeDelayedFrameScript(frameScriptURI);
+
         forEachOpenWindow(unloadFromWindow);
         WindowListener.stopListening();
       });
diff --git a/src/content/ui/frame.dom-content-loaded.js b/src/content/ui/frame.dom-content-loaded.js
index f2f1278..b37a945 100644
--- a/src/content/ui/frame.dom-content-loaded.js
+++ b/src/content/ui/frame.dom-content-loaded.js
@@ -72,6 +72,10 @@ let ManagerForDOMContentLoaded = (function() {
     let [answer] = mm.sendSyncMessage(C.MM_PREFIX + "notifyDocumentLoaded",
                                       {documentURI: doc.documentURI});
     var blockedURIs = answer.blockedURIs;
+    //console.debug("Received " +
+    //              Object.getOwnPropertyNames(blockedURIs).length +
+    //              " blocked URIs.");
+
     // Indicating blocked visible objects isn't an urgent task, so this should
     // be done async.
     Utils.runAsync(function() {
diff --git a/src/content/ui/frame.js b/src/content/ui/frame.js
index 2dae42f..66217a7 100644
--- a/src/content/ui/frame.js
+++ b/src/content/ui/frame.js
@@ -68,6 +68,7 @@ Components.utils.import("resource://gre/modules/devtools/Console.jsm");
     "ScriptLoader": ScriptLoader,
     "C": C,
     "Logger": Logger,
+    "console": console,
     "Environment": Environment,
 
     "framescriptEnv": framescriptEnv,

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



More information about the Pkg-mozext-commits mailing list