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

Side by Side Diff: include.preload.js

Issue 29401596: Issue 5094 - Implement support for :has() in chrome extension (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Updated to use the latest version of the core patch Created June 1, 2017, 6:25 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 | « dependencies ('k') | lib/filterValidation.js » ('j') | 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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 120
121 for (let i = 0; i < urls.length; i++) 121 for (let i = 0; i < urls.length; i++)
122 { 122 {
123 if (/^(?!https?:)[\w-]+:/i.test(urls[i])) 123 if (/^(?!https?:)[\w-]+:/i.test(urls[i]))
124 urls.splice(i--, 1); 124 urls.splice(i--, 1);
125 } 125 }
126 126
127 return urls; 127 return urls;
128 } 128 }
129 129
130 function hideElement(element)
131 {
132 function doHide(el)
133 {
134 let propertyName = "display";
135 let propertyValue = "none";
136 if (el.localName == "frame")
137 {
138 propertyName = "visibility";
139 propertyValue = "hidden";
140 }
141
142 if (el.style.getPropertyValue(propertyName) != propertyValue ||
143 el.style.getPropertyPriority(propertyName) != "important")
144 el.style.setProperty(propertyName, propertyValue, "important");
145 }
146
147 doHide(element);
148
149 new MutationObserver(doHide).observe(
150 element, {
151 attributes: true,
152 attributeFilter: ["style"]
153 }
154 );
155 }
156
130 function checkCollapse(element) 157 function checkCollapse(element)
131 { 158 {
132 let mediatype = typeMap.get(element.localName); 159 let mediatype = typeMap.get(element.localName);
133 if (!mediatype) 160 if (!mediatype)
134 return; 161 return;
135 162
136 let urls = getURLsFromElement(element); 163 let urls = getURLsFromElement(element);
137 if (urls.length == 0) 164 if (urls.length == 0)
138 return; 165 return;
139 166
140 ext.backgroundPage.sendMessage( 167 ext.backgroundPage.sendMessage(
141 { 168 {
142 type: "filters.collapse", 169 type: "filters.collapse",
143 urls, 170 urls,
144 mediatype, 171 mediatype,
145 baseURL: document.location.href 172 baseURL: document.location.href
146 }, 173 },
147 174
148 collapse => 175 collapse =>
149 { 176 {
150 function collapseElement()
151 {
152 let propertyName = "display";
153 let propertyValue = "none";
154 if (element.localName == "frame")
155 {
156 propertyName = "visibility";
157 propertyValue = "hidden";
158 }
159
160 if (element.style.getPropertyValue(propertyName) != propertyValue ||
161 element.style.getPropertyPriority(propertyName) != "important")
162 element.style.setProperty(propertyName, propertyValue, "important");
163 }
164
165 if (collapse) 177 if (collapse)
166 { 178 {
167 collapseElement(); 179 hideElement(element);
168
169 new MutationObserver(collapseElement).observe(
170 element, {
171 attributes: true,
172 attributeFilter: ["style"]
173 }
174 );
175 } 180 }
176 } 181 }
177 ); 182 );
178 } 183 }
179 184
180 function checkSitekey() 185 function checkSitekey()
181 { 186 {
182 let attr = document.documentElement.getAttribute("data-adblockkey"); 187 let attr = document.documentElement.getAttribute("data-adblockkey");
183 if (attr) 188 if (attr)
184 ext.backgroundPage.sendMessage({type: "filters.addKey", token: attr}); 189 ext.backgroundPage.sendMessage({type: "filters.addKey", token: attr});
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 346
342 this.elemHideEmulation = new ElemHideEmulation( 347 this.elemHideEmulation = new ElemHideEmulation(
343 window, 348 window,
344 callback => 349 callback =>
345 { 350 {
346 ext.backgroundPage.sendMessage({ 351 ext.backgroundPage.sendMessage({
347 type: "filters.get", 352 type: "filters.get",
348 what: "elemhideemulation" 353 what: "elemhideemulation"
349 }, callback); 354 }, callback);
350 }, 355 },
351 this.addSelectors.bind(this) 356 this.addSelectors.bind(this),
357 this.hideElements.bind(this)
352 ); 358 );
353 } 359 }
354 ElemHide.prototype = { 360 ElemHide.prototype = {
355 selectorGroupSize: 200, 361 selectorGroupSize: 200,
356 362
357 createShadowTree() 363 createShadowTree()
358 { 364 {
359 // Use Shadow DOM if available as to not mess with with web pages that 365 // Use Shadow DOM if available as to not mess with with web pages that
360 // rely on the order of their own <style> tags (#309). However, creating 366 // rely on the order of their own <style> tags (#309). However, creating
361 // a shadow root breaks running CSS transitions. So we have to create 367 // a shadow root breaks running CSS transitions. So we have to create
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 i, i + this.selectorGroupSize 436 i, i + this.selectorGroupSize
431 ).join(", "); 437 ).join(", ");
432 this.style.sheet.insertRule(selector + "{display: none !important;}", 438 this.style.sheet.insertRule(selector + "{display: none !important;}",
433 this.style.sheet.cssRules.length); 439 this.style.sheet.cssRules.length);
434 } 440 }
435 441
436 if (this.tracer) 442 if (this.tracer)
437 this.tracer.addSelectors(selectors, filters); 443 this.tracer.addSelectors(selectors, filters);
438 }, 444 },
439 445
446 hideElements(elements, filters)
447 {
448 for (let element of elements)
449 hideElement(element);
450
451 if (this.tracer)
452 ext.backgroundPage.sendMessage({
453 type: "devtools.traceElemHide",
454 selectors: [],
455 filters
456 });
457 },
458
440 apply() 459 apply()
441 { 460 {
442 ext.backgroundPage.sendMessage({type: "get-selectors"}, response => 461 ext.backgroundPage.sendMessage({type: "get-selectors"}, response =>
443 { 462 {
444 if (this.tracer) 463 if (this.tracer)
445 this.tracer.disconnect(); 464 this.tracer.disconnect();
446 this.tracer = null; 465 this.tracer = null;
447 466
448 if (this.style && this.style.parentElement) 467 if (this.style && this.style.parentElement)
449 this.style.parentElement.removeChild(this.style); 468 this.style.parentElement.removeChild(this.style);
(...skipping 20 matching lines...) Expand all
470 checkCollapse(event.target); 489 checkCollapse(event.target);
471 }, true); 490 }, true);
472 491
473 document.addEventListener("load", event => 492 document.addEventListener("load", event =>
474 { 493 {
475 let element = event.target; 494 let element = event.target;
476 if (/^i?frame$/.test(element.localName)) 495 if (/^i?frame$/.test(element.localName))
477 checkCollapse(element); 496 checkCollapse(element);
478 }, true); 497 }, true);
479 } 498 }
OLDNEW
« no previous file with comments | « dependencies ('k') | lib/filterValidation.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld