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

Unified Diff: include.preload.js

Issue 29338713: Issue 3840 - Prevent websites from making collapsed elements visible again (Closed)
Patch Set: Created March 19, 2016, 2:50 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.preload.js
===================================================================
--- a/include.preload.js
+++ b/include.preload.js
@@ -15,6 +15,7 @@
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
+var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
kzar 2016/03/19 15:05:20 Nit: There's an extra space after the pipes.
Sebastian Noack 2016/03/19 15:12:20 Done.
var SELECTOR_GROUP_SIZE = 20;
var typeMap = {
@@ -127,48 +128,49 @@
function checkCollapse(element)
{
- var tag = element.localName;
- if (tag in typeMap)
- {
- // This element failed loading, did we block it?
- var urls = getURLsFromElement(element);
- if (urls.length == 0)
- return;
+ window.collapsing = true;
- ext.backgroundPage.sendMessage(
+ var mediatype = typeMap[element.localName];
+ if (!mediatype)
+ return;
+
+ var urls = getURLsFromElement(element);
+ if (urls.length == 0)
+ return;
+
+ ext.backgroundPage.sendMessage(
+ {
+ type: "should-collapse",
+ urls: urls,
+ mediatype: mediatype,
+ baseURL: document.location.href
+ },
+
+ function(collapse)
+ {
+ function collapseElement()
{
- type: "should-collapse",
- urls: urls,
- mediatype: typeMap[tag],
- baseURL: document.location.href
- },
+ if (element.localName == "frame")
+ element.style.setProperty("visibility", "hidden", "important");
+ else
+ element.style.setProperty("display", "none", "important");
+ }
- function(response)
+ if (collapse && !element._collapsed)
{
- if (response && element.parentNode)
- {
- var property = "display";
- var value = "none";
+ collapseElement();
+ element._collapsed = true;
- // <frame> cannot be removed, doing that will mess up the frameset
- if (tag == "frame")
- {
- property = "visibility";
- value = "hidden";
- }
-
- // <input type="image"> elements try to load their image again
- // when the "display" CSS property is set. So we have to check
- // that it isn't already collapsed to avoid an infinite recursion.
- if (element.style.getPropertyValue(property) != value ||
- element.style.getPropertyPriority(property) != "important")
- element.style.setProperty(property, value, "important");
- }
+ if (MutationObserver)
+ new MutationObserver(collapseElement).observe(
+ element, {
+ attributes: true,
+ attributeFilter: ["style"]
+ }
+ );
}
- );
- }
-
- window.collapsing = true;
+ }
+ );
}
function checkSitekey()
@@ -333,8 +335,6 @@
function reinjectStyleSheetWhenRemoved(document, style)
{
- var MutationObserver = window.MutationObserver ||
- window.WebKitMutationObserver;
if (!MutationObserver)
return null;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld