Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: include.postload.js

Issue 5945877571043328: Issue 705 - Generate element hiding instead request blocking filters for non-HTTP URLs (Closed)
Patch Set: Created June 24, 2014, 2:54 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include.postload.js
===================================================================
--- a/include.postload.js
+++ b/include.postload.js
@@ -279,11 +279,6 @@
else if (elt.src)
url = elt.src;
- // Only normalize when the element contains a URL (issue 328.)
- // The URL is not always normalized, so do it here
- if (url)
- url = normalizeURL(relativeToAbsoluteUrl(url));
-
// Construct filters. The popup will retrieve these.
// Only one ID
var elementId = elt.id ? elt.id.split(' ').join('') : null;
@@ -301,6 +296,13 @@
selectorList.push(selector);
};
+ var addSelectorFromAttribute = function(element, attribute)
+ {
+ var value = element.getAttribute(attribute);
+ if (value)
+ addSelector(element.localName + "[" + attribute + '="' + value.replace(/"/g, '\\"') + '"]');
+ };
+
if (elementId)
addSelector("#" + elementId);
@@ -316,8 +318,14 @@
if (url)
{
- clickHideFilters.push(url);
- selectorList.push(elt.localName + '[src="' + url + '"]');
+ url = relativeToAbsoluteUrl(url);
+ if (/^https?:/.test(url))
+ {
+ clickHideFilters.push(normalizeURL(url));
+ selectorList.push(elt.localName + '[src="' + url + '"]');
+ }
+ else
+ addSelectorFromAttribute(elt, "src");
}
// restore the original style, before generating the fallback filter that
@@ -326,8 +334,8 @@
currentElement.style.backgroundColor = currentElement_backgroundColor;
// as last resort, create a filter based on inline styles
- if (clickHideFilters.length == 0 && elt.hasAttribute("style"))
- addSelector(elt.localName + '[style="' + elt.getAttribute("style") + '"]');
+ if (clickHideFilters.length == 0)
+ addSelectorFromAttribute(elt, "style");
// Show popup
clickHide_showDialog(e.clientX, e.clientY, clickHideFilters);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld