[Pkg-mozext-commits] [tabmixplus] 13/34: Move all message manager listeners to Tabmix.Utils

David Prévot taffit at moszumanska.debian.org
Mon Mar 9 23:28:07 UTC 2015


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

taffit pushed a commit to branch master
in repository tabmixplus.

commit 71c61ae2c0e8f9e49d7e6b90a8524f90c14c351b
Author: onemen <tabmix.onemen at gmail.com>
Date:   Fri Feb 20 13:24:19 2015 +0200

    Move all message manager listeners to Tabmix.Utils
---
 chrome/content/tabmix.js         | 20 +++-----------------
 modules/DocShellCapabilities.jsm | 32 ++++++++------------------------
 modules/Utils.jsm                | 36 +++++++++++++++++++++++++++++++++++-
 3 files changed, 46 insertions(+), 42 deletions(-)

diff --git a/chrome/content/tabmix.js b/chrome/content/tabmix.js
index 925fc29..b9a6e0f 100644
--- a/chrome/content/tabmix.js
+++ b/chrome/content/tabmix.js
@@ -307,15 +307,6 @@ var TMP_eventListener = {
     }
   },
 
-  receiveMessage: function(message) {
-    let browser = message.target;
-    switch (message.name) {
-      case "Tabmix:SetSyncHandler":
-        TabmixSvc.syncHandlers.set(browser.permanentKey, message.objects.syncHandler);
-        break;
-    }
-  },
-
   toggleEventListener: function(aObj, aArray, aEnable, aHandler) {
     var handler = aHandler || this;
     var eventListener = aEnable ? "addEventListener" : "removeEventListener";
@@ -360,7 +351,7 @@ var TMP_eventListener = {
       Tabmix.lazy_import(Tabmix, "renameTab", "RenameTab", "RenameTab");
       Tabmix.lazy_import(TabmixSessionManager, "_decode", "Decode", "Decode");
       Tabmix.lazy_import(Tabmix, "docShellCapabilities",
-        "DocShellCapabilities", "DocShellCapabilities", true, [window]);
+        "DocShellCapabilities", "DocShellCapabilities");
       Tabmix.lazy_import(Tabmix, "Utils", "Utils", "TabmixUtils");
     } catch (ex) {Tabmix.assert(ex);}
 
@@ -456,9 +447,7 @@ var TMP_eventListener = {
     window.addEventListener("fullscreen", this, true);
 
     if (Tabmix.isVersion(320)) {
-      let mm = window.getGroupMessageManager("browsers");
-      mm.addMessageListener("Tabmix:SetSyncHandler", this);
-      mm.loadFrameScript("chrome://tabmixplus/content/content.js", true);
+      Tabmix.Utils.initMessageManager(window);
     }
 
     var tabBar = gBrowser.tabContainer;
@@ -1078,12 +1067,9 @@ var TMP_eventListener = {
       Tabmix.flst.cancel();
 
     Tabmix.navToolbox.deinit();
-    if (Tabmix.DocShellCapabilitiesInitialized)
-      Tabmix.docShellCapabilities.deinit(window);
 
     if (Tabmix.isVersion(320)) {
-      let mm = window.getGroupMessageManager("browsers");
-      mm.removeMessageListener("Tabmix:SetSyncHandler", this);
+      Tabmix.Utils.deinit(window);
     }
 
     Tabmix.tabsUtils.onUnload();
diff --git a/modules/DocShellCapabilities.jsm b/modules/DocShellCapabilities.jsm
index 647566e..1aef9fd 100644
--- a/modules/DocShellCapabilities.jsm
+++ b/modules/DocShellCapabilities.jsm
@@ -14,33 +14,17 @@ XPCOMUtils.defineLazyModuleGetter(this, "TabmixSvc",
   "resource://tabmixplus/Services.jsm");
 
 this.DocShellCapabilities = {
-  init: function(window) {
+  init: function() {
     this.useFrameScript = TabmixSvc.version(320);
-    if (this.useFrameScript) {
-      let mm = window.getGroupMessageManager("browsers");
-      mm.addMessageListener("Tabmix:restorePermissionsComplete", this);
-    }
   },
 
-  deinit: function(window) {
-    if (this.useFrameScript) {
-      let mm = window.getGroupMessageManager("browsers");
-      mm.removeMessageListener("Tabmix:restorePermissionsComplete", this);
-    }
-  },
-
-  receiveMessage: function(message) {
-    let browser = message.target;
-    switch (message.name) {
-      case "Tabmix:restorePermissionsComplete":
-        // Update the persistent tab state cache
-        TabStateCache.update(browser, {
-          disallow: message.data.disallow || null
-        });
-        if (message.data.reload)
-          browser.reload();
-        break;
-    }
+  update: function(browser, data) {
+    // Update the persistent tab state cache
+    TabStateCache.update(browser, {
+      disallow: data.disallow || null
+    });
+    if (data.reload)
+      browser.reload();
   },
 
   caps: ["Images","Subframes","MetaRedirects","Plugins","Javascript"],
diff --git a/modules/Utils.jsm b/modules/Utils.jsm
index ef111de..f59a8c2 100644
--- a/modules/Utils.jsm
+++ b/modules/Utils.jsm
@@ -4,13 +4,47 @@ var EXPORTED_SYMBOLS = ["TabmixUtils"];
 
 const {interfaces: Ci, utils: Cu} = Components;
 
+// Messages that will be received via the Frame Message Manager.
+const FMM_MESSAGES = [
+  "Tabmix:SetSyncHandler",
+  "Tabmix:restorePermissionsComplete",
+];
+
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "Services",
   "resource://gre/modules/Services.jsm");
-
+XPCOMUtils.defineLazyModuleGetter(this, "TabmixSvc",
+  "resource://tabmixplus/Services.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "DocShellCapabilities",
+  "resource://tabmixplus/DocShellCapabilities.jsm");
 
 this.TabmixUtils = {
+  initMessageManager: function(window) {
+    let mm = window.getGroupMessageManager("browsers");
+    FMM_MESSAGES.forEach(function(msg) mm.addMessageListener(msg, this), this);
+
+    // Load the frame script after registering listeners.
+    mm.loadFrameScript("chrome://tabmixplus/content/content.js", true);
+  },
+
+  deinit: function(window) {
+    let mm = window.getGroupMessageManager("browsers");
+    FMM_MESSAGES.forEach(function(msg) mm.removeMessageListener(msg, this), this);
+  },
+
+  receiveMessage: function(message) {
+    let browser = message.target;
+    switch (message.name) {
+      case "Tabmix:SetSyncHandler":
+        TabmixSvc.syncHandlers.set(browser.permanentKey, message.objects.syncHandler);
+        break;
+      case "Tabmix:restorePermissionsComplete":
+        DocShellCapabilities.update(browser, message.data);
+        break;
+    }
+  },
+
   // change current history title
   updateHistoryTitle: function(history, title) {
     var shEntry = history.getEntryAtIndex(history.index, false).QueryInterface(Ci.nsISHEntry);

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



More information about the Pkg-mozext-commits mailing list