[Pkg-mozext-commits] [tabmixplus] 26/107: Replace eval of ContentClick.contentAreaClick with wrapped function to prevent incompatibility with BackTrack Tab History extension. Change whereToOpenLink function to return fixed 'where' when called from ContentClick.contentAreaClick

David Prévot taffit at moszumanska.debian.org
Tue Dec 29 19:02:46 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 3e5b40a310d02dffcbe9e478c940ec921eb693b8
Author: onemen <tabmix.onemen at gmail.com>
Date:   Sat Oct 24 14:39:46 2015 +0300

    Replace eval of ContentClick.contentAreaClick with wrapped function to prevent incompatibility with BackTrack Tab History extension. Change whereToOpenLink function to return fixed 'where' when called from ContentClick.contentAreaClick
---
 chrome/content/content.js       |  2 +-
 chrome/content/places/places.js |  6 +++++
 modules/ContentClick.jsm        | 55 +++++++++++++++++++++++------------------
 3 files changed, 38 insertions(+), 25 deletions(-)

diff --git a/chrome/content/content.js b/chrome/content/content.js
index 884cd6b..f5e3d1b 100644
--- a/chrome/content/content.js
+++ b/chrome/content/content.js
@@ -209,7 +209,7 @@ var TabmixClickEventHandler = {
     if (data.where == "handled")
       return;
 
-    json.tabmix = data;
+    json.tabmixContentClick = data;
     href = data._href;
 
     if (href) {
diff --git a/chrome/content/places/places.js b/chrome/content/places/places.js
index d4a164d..469a8a2 100644
--- a/chrome/content/places/places.js
+++ b/chrome/content/places/places.js
@@ -77,6 +77,12 @@ var TMP_Places = {
     // when we are in single window mode set the function to return "tab"
     let $LF = '\n  ';
     Tabmix.changeCode(window, "whereToOpenLink")._replace(
+      '{', '{\n' +
+      'if (e && e.tabmixContentClick) {\n' +
+      '  let {where, suppressTabsOnFileDownload} = e.tabmixContentClick;\n' +
+      '  return suppressTabsOnFileDownload ? "current" : where;\n' +
+      '}\n'
+    )._replace(
       'var middle = !ignoreButton && e.button == 1;',
       'var middle = !ignoreButton && e.button && e.button == 1;'
     )._replace(
diff --git a/modules/ContentClick.jsm b/modules/ContentClick.jsm
index 0123b41..a49b9c5 100644
--- a/modules/ContentClick.jsm
+++ b/modules/ContentClick.jsm
@@ -58,8 +58,6 @@ this.TabmixContentClick = {
 };
 Object.freeze(TabmixContentClick);
 
-var Tabmix = {};
-
 var ContentClickInternal = {
   _timer: null,
   _initialized: false,
@@ -69,16 +67,7 @@ var ContentClickInternal = {
       return;
     this._initialized = true;
 
-    try {
-      Cu.import("resource:///modules/ContentClick.jsm");
-      ContentClick.contentAreaClick.toString();
-    } catch (ex) {
-      this.functions = [];
-      return;
-    }
-
-    Tabmix._debugMode = TabmixSvc.debugMode();
-    Services.scriptloader.loadSubScript("chrome://tabmixplus/content/changecode.js");
+    Cu.import("resource:///modules/ContentClick.jsm");
 
     let mm = Cc["@mozilla.org/globalmessagemanager;1"].getService(Ci.nsIMessageListenerManager);
     mm.addMessageListener("TabmixContent:Click", this);
@@ -106,18 +95,36 @@ var ContentClickInternal = {
       ContentClick["tabmix_" + aFn] = ContentClick[aFn];
     });
 
-    Tabmix.changeCode(ContentClick, "ContentClick.contentAreaClick")._replace(
-      'var where = window.whereToOpenLink(json);',
-      'var data = json.tabmix || {where: window.whereToOpenLink(json)};\n' +
-      '    var {where, suppressTabsOnFileDownload} = data;'
-    )._replace(
-      'where == "current"',
-      '!json.tabmix && where == "current" || where == "default"'
-    )._replace(
-      'charset:',
-      'suppressTabsOnFileDownload: suppressTabsOnFileDownload || false,\n' +
-      '                   $&'
-    ).toCode();
+    ContentClick.contentAreaClick = function(json, browser) {
+      this.tabmix_contentAreaClick.apply(this, arguments);
+
+      // we add preventDefault in our content.js when 'where' is not the
+      // 'default', original ContentClick.contentAreaClick handle all casses
+      // except when 'where' equals 'current'
+      if (!json.tabmixContentClick || !json.href || json.bookmark) {
+        return;
+      }
+
+      let window = browser.ownerDocument.defaultView;
+      var where = window.whereToOpenLink(json);
+      if (where != "current") {
+        return;
+      }
+
+      let suppressTabsOnFileDownload =
+          json.tabmixContentClick.suppressTabsOnFileDownload || false;
+      let params = {charset: browser.characterSet,
+                    suppressTabsOnFileDownload: suppressTabsOnFileDownload,
+                    referrerURI: browser.documentURI,
+                    referrerPolicy: json.referrerPolicy,
+                    noReferrer: json.noReferrer};
+      window.openLinkIn(json.href, where, params);
+
+      try {
+        if (!PrivateBrowsingUtils.isWindowPrivate(window))
+          PlacesUIUtils.markPageAsFollowedLink(json.href);
+      } catch (ex) { /* Skip invalid URIs. */ }
+    };
   },
 
   receiveMessage: function(message) {

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