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

Side by Side Diff: include.preload.js

Issue 29338713: Issue 3840 - Prevent websites from making collapsed elements visible again (Closed)
Patch Set: Removed redundant space Created March 19, 2016, 3:12 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
18 var SELECTOR_GROUP_SIZE = 20; 19 var SELECTOR_GROUP_SIZE = 20;
19 20
20 var typeMap = { 21 var typeMap = {
21 "img": "IMAGE", 22 "img": "IMAGE",
22 "input": "IMAGE", 23 "input": "IMAGE",
23 "picture": "IMAGE", 24 "picture": "IMAGE",
24 "audio": "MEDIA", 25 "audio": "MEDIA",
25 "video": "MEDIA", 26 "video": "MEDIA",
26 "frame": "SUBDOCUMENT", 27 "frame": "SUBDOCUMENT",
27 "iframe": "SUBDOCUMENT", 28 "iframe": "SUBDOCUMENT",
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 { 121 {
121 if (/^(?!https?:)[\w-]+:/i.test(urls[i])) 122 if (/^(?!https?:)[\w-]+:/i.test(urls[i]))
122 urls.splice(i--, 1); 123 urls.splice(i--, 1);
123 } 124 }
124 125
125 return urls; 126 return urls;
126 } 127 }
127 128
128 function checkCollapse(element) 129 function checkCollapse(element)
129 { 130 {
130 var tag = element.localName; 131 window.collapsing = true;
131 if (tag in typeMap)
132 {
133 // This element failed loading, did we block it?
134 var urls = getURLsFromElement(element);
135 if (urls.length == 0)
136 return;
137 132
138 ext.backgroundPage.sendMessage( 133 var mediatype = typeMap[element.localName];
134 if (!mediatype)
135 return;
136
137 var urls = getURLsFromElement(element);
138 if (urls.length == 0)
139 return;
140
141 ext.backgroundPage.sendMessage(
142 {
143 type: "should-collapse",
144 urls: urls,
145 mediatype: mediatype,
146 baseURL: document.location.href
147 },
148
149 function(collapse)
150 {
151 function collapseElement()
139 { 152 {
140 type: "should-collapse", 153 if (element.localName == "frame")
141 urls: urls, 154 element.style.setProperty("visibility", "hidden", "important");
142 mediatype: typeMap[tag], 155 else
143 baseURL: document.location.href 156 element.style.setProperty("display", "none", "important");
144 }, 157 }
145 158
146 function(response) 159 if (collapse && !element._collapsed)
147 { 160 {
148 if (response && element.parentNode) 161 collapseElement();
149 { 162 element._collapsed = true;
150 var property = "display";
151 var value = "none";
152 163
153 // <frame> cannot be removed, doing that will mess up the frameset 164 if (MutationObserver)
154 if (tag == "frame") 165 new MutationObserver(collapseElement).observe(
155 { 166 element, {
156 property = "visibility"; 167 attributes: true,
157 value = "hidden"; 168 attributeFilter: ["style"]
158 } 169 }
159 170 );
160 // <input type="image"> elements try to load their image again
161 // when the "display" CSS property is set. So we have to check
162 // that it isn't already collapsed to avoid an infinite recursion.
163 if (element.style.getPropertyValue(property) != value ||
164 element.style.getPropertyPriority(property) != "important")
165 element.style.setProperty(property, value, "important");
166 }
167 } 171 }
168 ); 172 }
169 } 173 );
170
171 window.collapsing = true;
172 } 174 }
173 175
174 function checkSitekey() 176 function checkSitekey()
175 { 177 {
176 var attr = document.documentElement.getAttribute("data-adblockkey"); 178 var attr = document.documentElement.getAttribute("data-adblockkey");
177 if (attr) 179 if (attr)
178 ext.backgroundPage.sendMessage({type: "add-sitekey", token: attr}); 180 ext.backgroundPage.sendMessage({type: "add-sitekey", token: attr});
179 } 181 }
180 182
181 function getContentDocument(element) 183 function getContentDocument(element)
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 disconnect: function() 328 disconnect: function()
327 { 329 {
328 this.document.removeEventListener("DOMContentLoaded", this.trace); 330 this.document.removeEventListener("DOMContentLoaded", this.trace);
329 this.observer.disconnect(); 331 this.observer.disconnect();
330 clearTimeout(this.timeout); 332 clearTimeout(this.timeout);
331 } 333 }
332 }; 334 };
333 335
334 function reinjectStyleSheetWhenRemoved(document, style) 336 function reinjectStyleSheetWhenRemoved(document, style)
335 { 337 {
336 var MutationObserver = window.MutationObserver ||
337 window.WebKitMutationObserver;
338 if (!MutationObserver) 338 if (!MutationObserver)
339 return null; 339 return null;
340 340
341 var parentNode = style.parentNode; 341 var parentNode = style.parentNode;
342 var observer = new MutationObserver(function() 342 var observer = new MutationObserver(function()
343 { 343 {
344 if (style.parentNode != parentNode) 344 if (style.parentNode != parentNode)
345 parentNode.appendChild(style); 345 parentNode.appendChild(style);
346 }); 346 });
347 347
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 }, true); 551 }, true);
552 552
553 return updateStylesheet; 553 return updateStylesheet;
554 } 554 }
555 555
556 if (document instanceof HTMLDocument) 556 if (document instanceof HTMLDocument)
557 { 557 {
558 checkSitekey(); 558 checkSitekey();
559 window.updateStylesheet = init(document); 559 window.updateStylesheet = init(document);
560 } 560 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld