LEFT | RIGHT |
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 Loading... |
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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 { | 280 { |
281 sender.page.sendMessage({ | 281 sender.page.sendMessage({ |
282 type: "composer.content.dialogClosed", | 282 type: "composer.content.dialogClosed", |
283 popupId: popupPageId | 283 popupId: popupPageId |
284 }); | 284 }); |
285 browser.tabs.onRemoved.removeListener(onRemoved); | 285 browser.tabs.onRemoved.removeListener(onRemoved); |
286 } | 286 } |
287 }; | 287 }; |
288 browser.tabs.onRemoved.addListener(onRemoved); | 288 browser.tabs.onRemoved.addListener(onRemoved); |
289 | 289 |
290 if (require("../buildtools/info").application == "firefox" && | 290 if (info.application == "firefox" && navigator.oscpu.startsWith("Linux")) |
291 navigator.oscpu.startsWith("Linux")) | |
292 { | 291 { |
293 // Work around https://bugzil.la/1408446 | 292 // Work around https://bugzil.la/1408446 |
294 browser.windows.update(window.id, {width: window.width + 1}); | 293 browser.windows.update(window.id, {width: window.width + 1}); |
295 } | 294 } |
296 return popupPageId; | 295 return popupPageId; |
297 }); | 296 }); |
298 }); | 297 }); |
299 | 298 |
300 port.on("composer.getFilters", (message, sender) => | 299 port.on("composer.getFilters", (message, sender) => |
301 { | 300 { |
302 return composeFilters({ | 301 return composeFilters({ |
303 tagName: message.tagName, | 302 tagName: message.tagName, |
304 id: message.id, | 303 id: message.id, |
305 src: message.src, | 304 src: message.src, |
306 style: message.style, | 305 style: message.style, |
307 classes: message.classes, | 306 classes: message.classes, |
308 urls: message.urls, | 307 urls: message.urls, |
309 type: message.mediatype, | 308 type: message.mediatype, |
310 baseURL: message.baseURL, | 309 baseURL: message.baseURL, |
311 page: sender.page, | 310 page: sender.page, |
312 frame: sender.frame | 311 frame: sender.frame |
313 }); | 312 }); |
314 }); | 313 }); |
315 | 314 |
316 port.on("composer.quoteCSS", (message, sender) => | |
317 { | |
318 return quoteCSS(message.CSS); | |
319 }); | |
320 | |
321 ext.pages.onLoading.addListener(page => | 315 ext.pages.onLoading.addListener(page => |
322 { | 316 { |
323 // When tabs start loading we send them a message to ensure that the state | 317 // When tabs start loading we send them a message to ensure that the state |
324 // of the "block element" tool is reset. This is necessary since Firefox will | 318 // of the "block element" tool is reset. This is necessary since Firefox will |
325 // sometimes cache the state of a tab when the user navigates back / forward, | 319 // sometimes cache the state of a tab when the user navigates back / forward, |
326 // which includes the state of the "block element" tool. | 320 // which includes the state of the "block element" tool. |
327 // Since sending this message will often fail (e.g. for new tabs which have | 321 // Since sending this message will often fail (e.g. for new tabs which have |
328 // just been opened) we catch and ignore any exception thrown. | 322 // just been opened) we catch and ignore any exception thrown. |
329 browser.tabs.sendMessage( | 323 browser.tabs.sendMessage( |
330 page.id, {type: "composer.content.finished"} | 324 page.id, {type: "composer.content.finished"} |
331 ).catch(() => {}); | 325 ).catch(() => {}); |
332 }); | 326 }); |
LEFT | RIGHT |