[Pkg-mozext-commits] [firegestures] 03/13: fix "unsafe CPOW usage" (part 2)

David Prévot taffit at moszumanska.debian.org
Thu Feb 4 02:06:13 UTC 2016


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

taffit pushed a commit to branch master
in repository firegestures.

commit 72cc6d5e794ec17f480b468575a33c77b85c3baa
Author: Gomita <gomita at xuldev.org>
Date:   Sun Jan 31 18:34:43 2016 +0900

    fix "unsafe CPOW usage" (part 2)
---
 chrome/content/firegestures/browser.js | 31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/chrome/content/firegestures/browser.js b/chrome/content/firegestures/browser.js
index a358f52..bb4416b 100644
--- a/chrome/content/firegestures/browser.js
+++ b/chrome/content/firegestures/browser.js
@@ -436,8 +436,7 @@ var FireGestures = {
 				var doc = this.sourceNode.ownerDocument;
 				this.checkURL(linkURL, doc);
 				// XXX using saveHelper is a bit hackish but good to handle appropriate MIME-type
-				var linkText = gatherTextUnder(this.sourceNode);
-				nsContextMenu.prototype.saveHelper(linkURL, linkText, null, true, doc);
+				nsContextMenu.prototype.saveHelper(linkURL, this.getLinkText(), null, true, doc);
 				break;
 			case "FireGestures:ViewImage": 
 				var imageURL = this.getImageURL();
@@ -633,11 +632,35 @@ var FireGestures = {
 		return null;
 	},
 
-	// NOTE: this method uses |gatherTextUnder| defined in utilityOverlay.js
+	// @see nsContextMenu::getLinkText()
+	// @see gatherTextUnder in utilityOverlay.js
 	getLinkText: function(aNode) {
 		if (!aNode)
 			aNode = this.sourceNode;
-		var text = gatherTextUnder(aNode);
+		var text = "", node = aNode.firstChild, depth = 1;
+		while (node && depth > 0) {
+			if (node.nodeType == Node.TEXT_NODE) {
+				text += " " + node.data;
+			}
+			else if (node instanceof HTMLImageElement) {
+				var altText = node.getAttribute("alt");
+				if (altText && altText != "")
+					text += " " + altText;
+			}
+			if (node.hasChildNodes()) {
+				node = node.firstChild;
+				depth++;
+			}
+			else {
+				while (depth > 0 && !node.nextSibling) {
+					node = node.parentNode;
+					depth--;
+				}
+				if (node.nextSibling)
+					node = node.nextSibling;
+			}
+		}
+		text = text.trim().replace(/\s+/g, " ");
 		if (!text || !text.match(/\S/)) {
 			text = aNode.getAttribute("title");
 			if (!text || !text.match(/\S/)) {

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



More information about the Pkg-mozext-commits mailing list