[Pkg-mozext-commits] [tabmixplus] 22/22: Click events on links that have defaultPrevented set to true should not open the link in a new tab. using addSystemEventListener instead of addEventListener allow us to test defaultPrevented properly
David Prévot
taffit at moszumanska.debian.org
Sat Aug 5 15:28:35 UTC 2017
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to tag 0.5.0.4pre.170625a1
in repository tabmixplus.
commit 2a9c3932983a54a0551aa85e9b7bf4a0a3099b75
Author: onemen <tabmix.onemen at gmail.com>
Date: Sun Jun 25 12:18:32 2017 +0300
Click events on links that have defaultPrevented set to true should not open the link in a new tab. using addSystemEventListener instead of addEventListener allow us to test defaultPrevented properly
---
chrome/content/scripts/content.js | 34 +++++++++++++++++++++++------
modules/ContentClick.jsm | 37 +++++--------------------------
modules/LinkNodeUtils.jsm | 46 ++++++++++++++++++++++++++++++++++++++-
3 files changed, 77 insertions(+), 40 deletions(-)
diff --git a/chrome/content/scripts/content.js b/chrome/content/scripts/content.js
index f3999ab..0e8ba4e 100644
--- a/chrome/content/scripts/content.js
+++ b/chrome/content/scripts/content.js
@@ -192,35 +192,55 @@ var TabmixContentHandler = {
TabmixClickEventHandler = {
init: function init(global) {
if (TabmixSvc.version(380)) {
- global.addEventListener("click", this, true);
+ global.addEventListener("click", event => {
+ let linkData = this.getLinkData(event);
+ if (linkData) {
+ let [href, node] = linkData;
+ let currentHref = event.originalTarget.ownerDocument.documentURI;
+ if (LinkNodeUtils.isSpecialPage(href, node, currentHref)) {
+ this.contentAreaClick(event, linkData);
+ }
+ }
+ }, true);
+ Cc["@mozilla.org/eventlistenerservice;1"]
+ .getService(Ci.nsIEventListenerService)
+ .addSystemEventListener(global, "click", this, true);
}
},
handleEvent(event) {
switch (event.type) {
case "click":
- this.contentAreaClick(event);
+ this.contentAreaClick(event, this.getLinkData(event));
break;
}
},
- contentAreaClick(event) {
+ getLinkData(event) {
// tabmix_isMultiProcessBrowser is undefined for remote browser when
// window.gMultiProcessBrowser is true
if (!event.isTrusted || event.defaultPrevented || event.button == 2 ||
event.tabmix_isMultiProcessBrowser === false) {
- return;
+ return null;
}
- let originalTarget = event.originalTarget;
- let ownerDoc = originalTarget.ownerDocument;
+ let ownerDoc = event.originalTarget.ownerDocument;
// let Firefox code handle click events from about pages
if (!ownerDoc || /^about:(certerror|blocked|neterror)$/.test(ownerDoc.documentURI)) {
+ return null;
+ }
+
+ return this._hrefAndLinkNodeForClickEvent(event);
+ },
+
+ contentAreaClick(event, linkData) {
+ if (!linkData) {
return;
}
- let [href, node, principal] = this._hrefAndLinkNodeForClickEvent(event);
+ let [href, node, principal] = linkData;
+ let ownerDoc = event.originalTarget.ownerDocument;
// first get document wide referrer policy, then
// get referrer attribute from clicked link and parse it and
diff --git a/modules/ContentClick.jsm b/modules/ContentClick.jsm
index 41771d5..e167928 100644
--- a/modules/ContentClick.jsm
+++ b/modules/ContentClick.jsm
@@ -592,29 +592,10 @@ ContentClickInternal = {
openNewTab = true;
if (openNewTab) {
- let blocked;
- try {
- // for the moment just do it for Google and Yahoo....
- // tvguide.com - added 2013-07-20
- // duckduckgo.com - added 2014-12-24
- // jetbrains.com - added 2016-05-01
- let re = /duckduckgo.com|tvguide.com|google|yahoo.com|jetbrains.com/;
- blocked = re.test(currentHref);
- // youtube.com - added 2013-11-15
- if (!blocked && /youtube.com/.test(currentHref) &&
- (!this.isGMEnabled() || decodeURI(href).indexOf("return false;") == -1))
- blocked = true;
- else if (!blocked) {
- // make sure external links in developer.mozilla.org open new tab
- let host = this._browser.currentURI.host;
- blocked = host == "developer.mozilla.org" && linkNode.host != host &&
- linkNode.classList.contains("external");
- }
- } catch (ex) {
- blocked = false;
- }
- if (!blocked)
+ let blocked = LinkNodeUtils.isSpecialPage(href, linkNode, currentHref, this._window);
+ if (!blocked) {
return "16";
+ }
let where = this._window.whereToOpenLink(aEvent);
aEvent.__where = where == "tabshifted" ? "tabshifted" : "tab";
@@ -646,7 +627,7 @@ ContentClickInternal = {
if (typeof GM_function != "function")
return;
- this._GM_function.set(window, GM_function);
+ LinkNodeUtils._GM_function.set(window, GM_function);
},
miscellaneous(node) {
@@ -684,21 +665,13 @@ ContentClickInternal = {
*
*/
isGreasemonkeyScript: function TMP_isGreasemonkeyScript(href) {
- if (this.isGMEnabled()) {
+ if (LinkNodeUtils.isGMEnabled(this._window)) {
if (href && href.match(/\.user\.js(\?|$)/i))
return true;
}
return false;
},
- _GM_function: new WeakMap(),
-
- isGMEnabled() {
- if (this._GM_function.has(this._window))
- return this._GM_function.get(this._window)();
- return false;
- },
-
/**
* @brief Suppress tabs that may be created by downloading a file.
*
diff --git a/modules/LinkNodeUtils.jsm b/modules/LinkNodeUtils.jsm
index 34352dc..b88daf7 100644
--- a/modules/LinkNodeUtils.jsm
+++ b/modules/LinkNodeUtils.jsm
@@ -2,6 +2,13 @@
this.EXPORTED_SYMBOLS = ["LinkNodeUtils"];
+const Cu = Components.utils;
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
+
+XPCOMUtils.defineLazyModuleGetter(this, "Services",
+ "resource://gre/modules/Services.jsm");
+
const ATTRIBS = ["href", "onclick", "onmousedown", "rel", "role"];
this.LinkNodeUtils = {
@@ -58,7 +65,44 @@ this.LinkNodeUtils = {
if (node && node.hasAttribute && node.hasAttribute("onclick"))
return node;
return null;
- }
+ },
+
+ // catch link in special pages
+ isSpecialPage(href, linkNode, currentHref, window) {
+ let blocked;
+ try {
+ // for the moment just do it for Google and Yahoo....
+ // tvguide.com - added 2013-07-20
+ // duckduckgo.com - added 2014-12-24
+ // jetbrains.com - added 2016-05-01
+ let re = /duckduckgo.com|tvguide.com|google|yahoo.com|jetbrains.com/;
+ blocked = re.test(currentHref);
+ // youtube.com - added 2013-11-15
+ if (!blocked && /youtube.com/.test(currentHref) &&
+ (!this.isGMEnabled(window) || decodeURI(href).indexOf("return false;") == -1)) {
+ blocked = true;
+ } else if (!blocked) {
+ // make sure external links in developer.mozilla.org open new tab
+ let uri = Services.io.newURI(currentHref);
+ let host = uri && uri.host;
+ blocked = host == "developer.mozilla.org" && linkNode.host != host &&
+ linkNode.classList.contains("external");
+ }
+ } catch (ex) {
+ blocked = false;
+ }
+ return blocked;
+ },
+
+ _GM_function: new WeakMap(),
+
+ isGMEnabled(window) {
+ window = window || Services.wm.getMostRecentWindow("navigator:browser");
+ if (this._GM_function.has(window)) {
+ return this._GM_function.get(window)();
+ }
+ return false;
+ },
};
function getAttributes(node, attribs) {
--
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