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

Side by Side Diff: lib/filterComposer.js

Issue 4734012065054720: Issue 2634 - Consider alternative URLs for element collapsing (Closed)
Patch Set: Consider all URLs for element collapsing Created June 7, 2015, 3:14 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 | « include.preload.js ('k') | 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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 let frame = details.frame; 88 let frame = details.frame;
89 89
90 if (!isFrameWhitelisted(page, frame, "DOCUMENT")) 90 if (!isFrameWhitelisted(page, frame, "DOCUMENT"))
91 { 91 {
92 let docDomain = extractHostFromFrame(frame); 92 let docDomain = extractHostFromFrame(frame);
93 93
94 // Add a blocking filter for each URL of the element that can be blocked 94 // Add a blocking filter for each URL of the element that can be blocked
95 for (let url of details.urls) 95 for (let url of details.urls)
96 { 96 {
97 let urlObj = new URL(url, details.baseURL); 97 let urlObj = new URL(url, details.baseURL);
98 url = stringifyURL(urlObj);
98 99
99 if (urlObj.protocol == "http:" || urlObj.protocol == "https:") 100 let filter = defaultMatcher.whitelist.matchesAny(
101 url, details.type, docDomain,
102 isThirdParty(urlObj, docDomain),
103 getKey(page, frame)
104 );
105
106 if (!filter)
100 { 107 {
101 url = stringifyURL(urlObj); 108 let filterText = url.replace(/^[\w\-]+:\/+(?:www\.)?/, "||");
102 109
103 let filter = defaultMatcher.whitelist.matchesAny( 110 if (filters.indexOf(filterText) == -1)
104 url, details.type, docDomain, 111 filters.push(filterText);
105 isThirdParty(urlObj, docDomain),
106 getKey(page, frame)
107 );
108
109 if (!filter)
110 {
111 let filterText = url.replace(/^[\w\-]+:\/+(?:www\.)?/, "||");
112
113 if (filters.indexOf(filterText) == -1)
114 filters.push(filterText);
115 }
116 } 112 }
117 } 113 }
118 114
119 // If we couldn't generate any blocking filters, fallback to element hiding 115 // If we couldn't generate any blocking filters, fallback to element hiding
120 let selectors = []; 116 let selectors = [];
121 if (filters.length == 0 && !isFrameWhitelisted(page, frame, "ELEMHIDE")) 117 if (filters.length == 0 && !isFrameWhitelisted(page, frame, "ELEMHIDE"))
122 { 118 {
123 // Generate CSS selectors based on the element's "id" and "class" attribut e 119 // Generate CSS selectors based on the element's "id" and "class" attribut e
124 if (details.id) 120 if (details.id)
125 selectors.push("#" + escapeCSS(details.id)); 121 selectors.push("#" + escapeCSS(details.id));
(...skipping 11 matching lines...) Expand all
137 selectors.push(escapeCSS(details.tagName) + "[style=" + quoteCSS(details .style) + "]"); 133 selectors.push(escapeCSS(details.tagName) + "[style=" + quoteCSS(details .style) + "]");
138 134
139 // Add an element hiding filter for each generated CSS selector 135 // Add an element hiding filter for each generated CSS selector
140 for (let selector of selectors) 136 for (let selector of selectors)
141 filters.push(docDomain.replace(/^www\./, "") + "##" + selector); 137 filters.push(docDomain.replace(/^www\./, "") + "##" + selector);
142 } 138 }
143 } 139 }
144 140
145 return {filters: filters, selectors: selectors}; 141 return {filters: filters, selectors: selectors};
146 }; 142 };
OLDNEW
« no previous file with comments | « include.preload.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld