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

Side by Side Diff: lib/filterComposer.js

Issue 29772555: Issue 6647 - Stop converting domains from punycode to unicode (Closed)
Patch Set: Created May 6, 2018, 2:42 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
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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 /** @module filterComposer */ 18 /** @module filterComposer */
19 19
20 "use strict"; 20 "use strict";
21 21
22 const {defaultMatcher} = require("../adblockpluscore/lib/matcher"); 22 const {defaultMatcher} = require("../adblockpluscore/lib/matcher");
23 const {RegExpFilter} = require("../adblockpluscore/lib/filterClasses"); 23 const {RegExpFilter} = require("../adblockpluscore/lib/filterClasses");
24 const {FilterNotifier} = require("../adblockpluscore/lib/filterNotifier"); 24 const {FilterNotifier} = require("../adblockpluscore/lib/filterNotifier");
25 const {Prefs} = require("./prefs"); 25 const {Prefs} = require("./prefs");
26 const {extractHostFromFrame, stringifyURL, isThirdParty} = require("./url"); 26 const {extractHostFromFrame, isThirdParty} = require("./url");
27 const {getKey, checkWhitelisted} = require("./whitelisting"); 27 const {getKey, checkWhitelisted} = require("./whitelisting");
28 const {port} = require("./messaging"); 28 const {port} = require("./messaging");
29 const info = require("../buildtools/info"); 29 const info = require("../buildtools/info");
30 30
31 let readyPages = new ext.PageMap(); 31 let readyPages = new ext.PageMap();
32 32
33 /** 33 /**
34 * Checks whether the given page is ready to use the filter composer 34 * Checks whether the given page is ready to use the filter composer
35 * 35 *
36 * @param {Page} page 36 * @param {Page} page
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 { 97 {
98 let typeMask = RegExpFilter.typeMap[details.type]; 98 let typeMask = RegExpFilter.typeMap[details.type];
99 let docDomain = extractHostFromFrame(frame); 99 let docDomain = extractHostFromFrame(frame);
100 let specificOnly = checkWhitelisted(page, frame, null, 100 let specificOnly = checkWhitelisted(page, frame, null,
101 RegExpFilter.typeMap.GENERICBLOCK); 101 RegExpFilter.typeMap.GENERICBLOCK);
102 102
103 // Add a blocking filter for each URL of the element that can be blocked 103 // Add a blocking filter for each URL of the element that can be blocked
104 for (let url of details.urls) 104 for (let url of details.urls)
105 { 105 {
106 let urlObj = new URL(url, details.baseURL); 106 let urlObj = new URL(url, details.baseURL);
107 url = stringifyURL(urlObj);
108
109 let filter = defaultMatcher.whitelist.matchesAny( 107 let filter = defaultMatcher.whitelist.matchesAny(
110 url, typeMask, docDomain, 108 urlObj.href, typeMask, docDomain,
111 isThirdParty(urlObj, docDomain), 109 isThirdParty(urlObj, docDomain),
112 getKey(page, frame), specificOnly 110 getKey(page, frame), specificOnly
113 ); 111 );
114 112
115 if (!filter) 113 if (!filter)
116 { 114 {
117 let filterText = url.replace(/^[\w-]+:\/+(?:www\.)?/, "||"); 115 let filterText = urlObj.href.replace(/^[\w-]+:\/+(?:www\.)?/, "||");
118 116
119 if (specificOnly) 117 if (specificOnly)
120 filterText += "$domain=" + docDomain; 118 filterText += "$domain=" + docDomain;
121 119
122 if (!filters.includes(filterText)) 120 if (!filters.includes(filterText))
123 filters.push(filterText); 121 filters.push(filterText);
124 } 122 }
125 } 123 }
126 124
127 // If we couldn't generate any blocking filters, fallback to element hiding 125 // If we couldn't generate any blocking filters, fallback to element hiding
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 // When tabs start loading we send them a message to ensure that the state 331 // When tabs start loading we send them a message to ensure that the state
334 // of the "block element" tool is reset. This is necessary since Firefox will 332 // of the "block element" tool is reset. This is necessary since Firefox will
335 // sometimes cache the state of a tab when the user navigates back / forward, 333 // sometimes cache the state of a tab when the user navigates back / forward,
336 // which includes the state of the "block element" tool. 334 // which includes the state of the "block element" tool.
337 // Since sending this message will often fail (e.g. for new tabs which have 335 // Since sending this message will often fail (e.g. for new tabs which have
338 // just been opened) we catch and ignore any exception thrown. 336 // just been opened) we catch and ignore any exception thrown.
339 browser.tabs.sendMessage( 337 browser.tabs.sendMessage(
340 page.id, {type: "composer.content.finished"} 338 page.id, {type: "composer.content.finished"}
341 ).catch(() => {}); 339 ).catch(() => {});
342 }); 340 });
OLDNEW

Powered by Google App Engine
This is Rietveld