[Pkg-mozext-commits] [tabmixplus] 114/123: [e10s] Update openMultipleLinks function to work with remote tabs. move the TreeWalker to modules and call it from our frame script

David Prévot taffit at moszumanska.debian.org
Wed Sep 17 21:16:33 UTC 2014


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

taffit pushed a commit to branch master
in repository tabmixplus.

commit 105a721502d9c42460c0bcf89bbb72ed1fbb7cac
Author: onemen <tabmix.onemen at gmail.com>
Date:   Tue Sep 16 19:56:34 2014 +0300

    [e10s] Update openMultipleLinks function to work with remote tabs. move the TreeWalker to modules and call it from our frame script
---
 chrome/content/click/click.js           | 79 +++++++--------------------------
 chrome/content/content.js               | 11 ++++-
 chrome/content/extensions/extensions.js | 19 ++++----
 modules/ContextMenu.jsm                 | 76 +++++++++++++++++++++++++++++++
 4 files changed, 111 insertions(+), 74 deletions(-)

diff --git a/chrome/content/click/click.js b/chrome/content/click/click.js
index fd5602d..33cf7b1 100644
--- a/chrome/content/click/click.js
+++ b/chrome/content/click/click.js
@@ -1,5 +1,8 @@
 "use strict";
 
+XPCOMUtils.defineLazyModuleGetter(Tabmix, "ContextMenu",
+  "resource://tabmixplus/ContextMenu.jsm");
+
 var TabmixTabClickOptions = {
   onDoubleClick: false,
   _blockDblClick: false,
@@ -662,74 +665,24 @@ var TabmixContext = {
   },
 
   openMultipleLinks: function TMP_openMultipleLinks(check) {
-    var focusedWindow = document.commandDispatcher.focusedWindow;
-    if (focusedWindow == window)
-      focusedWindow = gBrowser.selectedBrowser[TabmixSvc.contentWindowAsCPOW];
-
-    var nsISelectionObject = focusedWindow.getSelection();
-    if (nsISelectionObject.isCollapsed) // nothing selected
-      return true;
-
-    var myNodeFilter = {
-      acceptNode : function(n) {
-        if(n.nodeName == 'A' || n.nodeName == 'li') {
-          return NodeFilter.FILTER_ACCEPT;
-        }
-        else {
-          return NodeFilter.FILTER_SKIP;
-        }
-      }
-    };
-
-    // do urlSecurityCheck for each link in the treeWalker....
-    var _document = focusedWindow.document.documentElement.ownerDocument;
-    const nsIScriptSecurityManager = Components.interfaces.nsIScriptSecurityManager;
-    var secMan = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
-                          .getService(nsIScriptSecurityManager);
-    var flags = nsIScriptSecurityManager.STANDARD;
-    function links_urlSecurityCheck(url) {
-      if (!url)
-        return false;
-
-      if (!_document) // just in case....
-        return true;
-
+    let urls = [], browser = window.gBrowser.selectedBrowser;
+    if (Tabmix.isVersion(320)) {
       try {
-        secMan.checkLoadURIStrWithPrincipal(_document.nodePrincipal, url, flags);
-      } catch (e) {
-        return false;
+        let handler = TabmixSvc.syncHandlers.get(browser.permanentKey);
+        urls = handler.getSelectedLinks(check);
+      } catch(ex) {
+        Tabmix.log("unable to get syncHandlers for page " +
+                      browser.currentURI.spec + "\n" + ex);
       }
-      return true;
     }
+    // getSelectedLinks was not implemented for remote tabs before Firefox 32
+    else if (browser.getAttribute("remote") != "true")
+      urls = Tabmix.ContextMenu.getSelectedLinks(content, check);
 
-    var range = nsISelectionObject.getRangeAt(0);
-    var doc = window.gBrowser.selectedBrowser[TabmixSvc.contentDocumentAsCPOW]
-    var treeWalker = doc.createTreeWalker(
-         range.cloneContents(),
-         NodeFilter.SHOW_ELEMENT,
-         myNodeFilter,
-         true);
-    var nextEpisode = treeWalker.nextNode();
-    var urls = [];
-    while (nextEpisode != null) {
-      let url;
-      if (nextEpisode.nodeName == "li") {
-        let node = nextEpisode.firstChild;
-        url = node.nodeName == "p" ? node.firstChild.href : node.href;
-      }
-      else
-        url = nextEpisode.href;
-      if (links_urlSecurityCheck(url)) {
-        if (check)
-          return false;
-        if (urls.indexOf(url) == -1)
-          urls.push(url);
-      }
-      nextEpisode = treeWalker.nextNode();
+    if (!check && urls.length) {
+      Tabmix.loadTabs(urls, false);
     }
-    if (urls.length)
-     Tabmix.loadTabs(urls, false);
-    return true;
+    return urls.length == 0;
   }
 }
 
diff --git a/chrome/content/content.js b/chrome/content/content.js
index 6925dec..d301b51 100644
--- a/chrome/content/content.js
+++ b/chrome/content/content.js
@@ -11,9 +11,12 @@ XPCOMUtils.defineLazyModuleGetter(this, "DocShellCapabilities",
 XPCOMUtils.defineLazyModuleGetter(this, "TabmixSvc",
   "resource://tabmixplus/Services.jsm");
 
+XPCOMUtils.defineLazyModuleGetter(this, "ContextMenu",
+  "resource://tabmixplus/ContextMenu.jsm");
+
 let global = this;
 
-let TabmixPermissionsListener = {
+let TabmixContentHandler = {
   MESSAGES: [
     "Tabmix:restorePermissions",
     "Tabmix:collectPermissions",
@@ -46,6 +49,10 @@ let TabmixPermissionsListener = {
 
   getCapabilities: function() {
     return DocShellCapabilities.collect(docShell).join(",") || "";
+  },
+
+  getSelectedLinks: function(check) {
+    return ContextMenu.getSelectedLinks(content, check);
   }
 };
 
@@ -196,5 +203,5 @@ let TabmixClickEventHandler = {
   }
 };
 
-TabmixPermissionsListener.init();
+TabmixContentHandler.init();
 TabmixClickEventHandler.init();
diff --git a/chrome/content/extensions/extensions.js b/chrome/content/extensions/extensions.js
index e3900e8..5ea8bae 100644
--- a/chrome/content/extensions/extensions.js
+++ b/chrome/content/extensions/extensions.js
@@ -359,15 +359,6 @@ var TMP_extensionsCompatibility = {
       ).toCode();
     }
 
-    // Redirect Remover 2.6.4
-    if ("rdrb" in window && rdrb.delayedInit) {
-      Tabmix.changeCode(TabmixContext, "TabmixContext.openMultipleLinks")._replace(
-        'if (links_urlSecurityCheck(url))',
-        'url = rdrb.cleanLink(url);\
-         $&'
-      ).toCode();
-    }
-
     // override some of All-in-One Gestures function
     // override the duplicate tab function
     if (typeof aioDupTab == 'function')
@@ -442,6 +433,16 @@ var TMP_extensionsCompatibility = {
       if (sessionmanager)
         ctrBox.parentNode.insertBefore(sessionmanager, ctrBox.nextSibling);
     }
+
+    // Redirect Remover 2.6.4
+    // https://addons.mozilla.org/he/firefox/addon/redirect-remover/
+    if (window.rdrb && typeof rdrb.cleanLink == "function") {
+      Tabmix.changeCode(TabmixContext, "TabmixContext.openMultipleLinks")._replace(
+        'Tabmix.loadTabs(urls, false);',
+        'urls = urls.map(function(url) rdrb.cleanLink(url));\n' +
+        '      $&'
+      ).toCode(true);
+    }
   }
 
 }
diff --git a/modules/ContextMenu.jsm b/modules/ContextMenu.jsm
new file mode 100644
index 0000000..5425b54
--- /dev/null
+++ b/modules/ContextMenu.jsm
@@ -0,0 +1,76 @@
+"use strict";
+
+this.EXPORTED_SYMBOLS = ["ContextMenu"];
+
+const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
+Cu.import("resource://gre/modules/Services.jsm");
+
+XPCOMUtils.defineLazyModuleGetter(this, "TabmixSvc",
+  "resource://tabmixplus/Services.jsm");
+
+this.ContextMenu = {
+  getSelectedLinks: function(content, check) {
+    // get focused window selection
+    let fm = Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager);
+    let focusedWindow = {};
+    let elt = fm.getFocusedElementForWindow(content, true, focusedWindow);
+    let selectionObject = focusedWindow.value.getSelection();
+    if (selectionObject.isCollapsed) // nothing selected
+      return [];
+
+    let filter = {
+      acceptNode: function(n) {
+        if(n.nodeName == 'A' || n.nodeName == 'li') {
+          return Ci.nsIDOMNodeFilter.FILTER_ACCEPT;
+        }
+        else {
+          return Ci.nsIDOMNodeFilter.FILTER_SKIP;
+        }
+      }
+    };
+
+    // do urlSecurityCheck for each link in the treeWalker....
+    let doc = content.document;
+    let secMan = Services.scriptSecurityManager;
+    let securityCheck = function(url) {
+      if (!url)
+        return false;
+
+      if (!doc) // just in case....
+        return true;
+
+      try {
+        secMan.checkLoadURIStrWithPrincipal(
+            doc.nodePrincipal, url, secMan.STANDARD);
+      } catch (e) {
+        return false;
+      }
+      return true;
+    }
+
+    let range = selectionObject.getRangeAt(0).cloneContents();
+    let treeWalker = doc.createTreeWalker(range,
+                          Ci.nsIDOMNodeFilter.SHOW_ELEMENT, filter, true);
+    let nextEpisode = treeWalker.nextNode();
+    let urls = [];
+    while (nextEpisode != null) {
+      let url;
+      if (nextEpisode.nodeName == "li") {
+        let node = nextEpisode.firstChild;
+        url = node.nodeName == "p" ? node.firstChild.href : node.href;
+      }
+      else
+        url = nextEpisode.href;
+      if (securityCheck(url)) {
+        if (check)
+          return [true];
+        if (urls.indexOf(url) == -1)
+          urls.push(url);
+      }
+      nextEpisode = treeWalker.nextNode();
+    }
+    return urls;
+  }
+}

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