[Pkg-mozext-commits] [tabmixplus] 03/123: Prevent onclick function that start with 'window.location=' when we force new tab from link

David Prévot taffit at moszumanska.debian.org
Wed Sep 17 21:16:21 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 ddb85e4d36bb29a51e6f2553b1049a022e13ab69
Author: onemen <tabmix.onemen at gmail.com>
Date:   Tue Aug 5 16:30:09 2014 +0300

    Prevent onclick function that start with 'window.location=' when we force new tab from link
---
 chrome/content/links/contentLinks.js | 72 +++++++++++++++++++++++-------------
 1 file changed, 46 insertions(+), 26 deletions(-)

diff --git a/chrome/content/links/contentLinks.js b/chrome/content/links/contentLinks.js
index ba58183..70df07d 100644
--- a/chrome/content/links/contentLinks.js
+++ b/chrome/content/links/contentLinks.js
@@ -240,27 +240,6 @@ Tabmix.contentAreaClick = {
     this.getData(aEvent, href, linkNode, targetAttr);
 
     var currentHref = gBrowser.currentURI ? gBrowser.currentURI.spec : "";
-    try {
-      // for the moment just do it for Google and Yahoo....
-      // and tvguide.com - added 2013-07-20
-      var blocked = /tvguide.com|google|yahoo.com\/search|my.yahoo.com/.test(currentHref);
-      // youtube.com - added 2013-11-15
-      if (!blocked && /youtube.com/.test(currentHref) &&
-         (!this.isGMEnabled() || decodeURI(href).indexOf("return false;") == -1))
-        blocked = true;
-    } catch (ex) {blocked = false;}
-    if (!blocked) {
-      // replace onclick function with the form javascript:top.location.href = url
-      // if the tab is locked or we force new tab from link
-      let {onclick} = this._data;
-      if ((this.currentTabLocked || this.targetPref == 1) && onclick) {
-        let code = "javascript:top.location.href="
-        if (this.checkAttr(href, "javascript:void(0)") && this.checkAttr(onclick, code))
-          linkNode.setAttribute("onclick", onclick.replace(code, "var __tabmix.href="));
-      }
-      return;
-    }
-
     // don't do anything on mail.google or google.com/reader
     var isGmail = /^(http|https):\/\/mail.google.com/.test(currentHref) || /^(http|https):\/\/\w*.google.com\/reader/.test(currentHref);
     if (isGmail)
@@ -315,17 +294,30 @@ Tabmix.contentAreaClick = {
     if (this.divertTargetedLink())
       return;
 
-    // open links to other sites in a tab only if certain conditions are met. See the
-    // function comment for more details.
     var openNewTab = null;
-    if (this.openExSiteLink())
-      openNewTab = true;
     // when a tab is locked or preference is to open in new tab
     // we check that link is not a Javascript or have a onclick function
-    else if (this.currentTabLocked || this.targetPref == 1)
+    if (this.currentTabLocked || this.targetPref == 1)
       openNewTab = this.openTabfromLink();
+    // open links to other sites in a tab only if certain conditions are met. See the
+    // function comment for more details.
+    else if (this.openExSiteLink())
+      openNewTab = true;
 
     if (openNewTab) {
+      this.preventOnClick(linkNode);
+      try {
+        // for the moment just do it for Google and Yahoo....
+        // and tvguide.com - added 2013-07-20
+        var blocked = /tvguide.com|google|yahoo.com\/search|my.yahoo.com/.test(currentHref);
+        // youtube.com - added 2013-11-15
+        if (!blocked && /youtube.com/.test(currentHref) &&
+           (!this.isGMEnabled() || decodeURI(href).indexOf("return false;") == -1))
+          blocked = true;
+      } catch (ex) {blocked = false;}
+      if (!blocked)
+        return;
+
       let where = whereToOpenLink(aEvent);
       aEvent.__where = where == "tabshifted" ? "tabshifted" : "tab";
       handleLinkClick(aEvent, href, linkNode);
@@ -335,6 +327,34 @@ Tabmix.contentAreaClick = {
   },
 
   /**
+   * @brief prevent onclick function with the form javascript:top.location.href = url
+   *        or the form window.location = url when we force new tab from link
+   */
+  preventOnClick: function(linkNode) {
+    let {href, onclick} = this._data;
+
+    let removeOnclick = function (node, click) {
+      if (this.checkAttr(click, "window.location=")) {
+        let clickTarget = click.replace("window.location=", "").trim().replace(/^["|']+|["|']+$/g, "");
+        if (href.indexOf(clickTarget) != -1)
+          node.removeAttribute("onclick");
+      }
+    }.bind(this);
+
+    if (onclick) {
+      let code = "javascript:top.location.href="
+      if (this.checkAttr(href, "javascript:void(0)") && this.checkAttr(onclick, code))
+        linkNode.setAttribute("onclick", onclick.replace(code, "var __tabmix.href="));
+      else
+        removeOnclick(linkNode, onclick);
+    }
+
+    let parent = linkNode.parentNode;
+    if (parent.hasAttribute("onclick"))
+      removeOnclick(parent, parent.getAttribute("onclick"));
+  },
+
+  /**
    * @brief hock the proper Greasemonkey function into Tabmix.isGMEnabled
    */
   isGreasemonkeyInstalled: function TMP_isGreasemonkeyInstalled() {

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