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

Side by Side Diff: lib/filterComposer.js

Issue 29739594: Issue 6543 - Match requests without tabId/frameId in their originating context (Closed)
Patch Set: Use URL patterns to find tabs for initiator Created April 4, 2018, 1:01 a.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
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 function composeFilters(details) 90 function composeFilters(details)
91 { 91 {
92 let {page, frame} = details; 92 let {page, frame} = details;
93 let filters = []; 93 let filters = [];
94 let selectors = []; 94 let selectors = [];
95 95
96 if (!checkWhitelisted(page, frame)) 96 if (!checkWhitelisted(page, frame))
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, 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); 107 url = stringifyURL(urlObj);
108 108
109 let filter = defaultMatcher.whitelist.matchesAny( 109 let filter = defaultMatcher.whitelist.matchesAny(
110 url, typeMask, docDomain, 110 url, typeMask, docDomain,
111 isThirdParty(urlObj, docDomain), 111 isThirdParty(urlObj, docDomain),
112 getKey(page, frame), specificOnly 112 getKey(page, frame), specificOnly
113 ); 113 );
114 114
115 if (!filter) 115 if (!filter)
116 { 116 {
117 let filterText = url.replace(/^[\w-]+:\/+(?:www\.)?/, "||"); 117 let filterText = url.replace(/^[\w-]+:\/+(?:www\.)?/, "||");
118 118
119 if (specificOnly) 119 if (specificOnly)
120 filterText += "$domain=" + docDomain; 120 filterText += "$domain=" + docDomain;
121 121
122 if (!filters.includes(filterText)) 122 if (!filters.includes(filterText))
123 filters.push(filterText); 123 filters.push(filterText);
124 } 124 }
125 } 125 }
126 126
127 // If we couldn't generate any blocking filters, fallback to element hiding 127 // If we couldn't generate any blocking filters, fallback to element hiding
128 if (filters.length == 0 && !checkWhitelisted(page, frame, 128 if (filters.length == 0 && !checkWhitelisted(page, frame, null,
129 RegExpFilter.typeMap.ELEMHIDE)) 129 RegExpFilter.typeMap.ELEMHIDE))
130 { 130 {
131 // Generate CSS selectors based on the element's "id" and 131 // Generate CSS selectors based on the element's "id" and
132 // "class" attribute. 132 // "class" attribute.
133 if (isValidString(details.id)) 133 if (isValidString(details.id))
134 selectors.push("#" + escapeCSS(details.id)); 134 selectors.push("#" + escapeCSS(details.id));
135 135
136 let classes = details.classes.filter(isValidString); 136 let classes = details.classes.filter(isValidString);
137 if (classes.length > 0) 137 if (classes.length > 0)
138 selectors.push(classes.map(c => "." + escapeCSS(c)).join("")); 138 selectors.push(classes.map(c => "." + escapeCSS(c)).join(""));
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 // When tabs start loading we send them a message to ensure that the state 318 // When tabs start loading we send them a message to ensure that the state
319 // of the "block element" tool is reset. This is necessary since Firefox will 319 // of the "block element" tool is reset. This is necessary since Firefox will
320 // sometimes cache the state of a tab when the user navigates back / forward, 320 // sometimes cache the state of a tab when the user navigates back / forward,
321 // which includes the state of the "block element" tool. 321 // which includes the state of the "block element" tool.
322 // Since sending this message will often fail (e.g. for new tabs which have 322 // Since sending this message will often fail (e.g. for new tabs which have
323 // just been opened) we catch and ignore any exception thrown. 323 // just been opened) we catch and ignore any exception thrown.
324 browser.tabs.sendMessage( 324 browser.tabs.sendMessage(
325 page.id, {type: "composer.content.finished"} 325 page.id, {type: "composer.content.finished"}
326 ).catch(() => {}); 326 ).catch(() => {});
327 }); 327 });
OLDNEW
« no previous file with comments | « lib/cssInjection.js ('k') | lib/popupBlocker.js » ('j') | lib/requestBlocker.js » ('J')

Powered by Google App Engine
This is Rietveld