Index: lib/contentFiltering.js |
=================================================================== |
--- a/lib/contentFiltering.js |
+++ b/lib/contentFiltering.js |
@@ -17,21 +17,22 @@ |
/** @module contentFiltering */ |
"use strict"; |
const {RegExpFilter} = require("../adblockpluscore/lib/filterClasses"); |
const {ElemHide} = require("../adblockpluscore/lib/elemHide"); |
const {ElemHideEmulation} = require("../adblockpluscore/lib/elemHideEmulation"); |
+const {FilterNotifier} = require("../adblockpluscore/lib/filterNotifier"); |
const {Snippets, compileScript} = require("../adblockpluscore/lib/snippets"); |
const {checkWhitelisted} = require("./whitelisting"); |
const {extractHostFromFrame} = require("./url"); |
const {port} = require("./messaging"); |
-const {HitLogger} = require("./hitLogger"); |
+const {HitLogger, logRequest} = require("./hitLogger"); |
const info = require("info"); |
// Chromium's support for tabs.removeCSS is still a work in progress and the |
// API is likely to be different from Firefox's; for now we just don't use it |
// at all, even if it's available. |
// See https://crbug.com/608854 |
const styleSheetRemovalSupported = info.platform == "gecko"; |
@@ -186,17 +187,17 @@ |
runAt: "document_start" |
}; |
// Chrome <50 throws an exception if chrome.tabs.executeScript is called |
// with a frameId of 0. |
if (frameId != 0) |
details.frameId = frameId; |
- browser.tabs.executeScript(tabId, details) |
+ return browser.tabs.executeScript(tabId, details) |
.catch(error => |
{ |
// Sometimes a frame is added and removed very quickly, in such cases we |
// simply ignore the error. |
if (error.message == "The frame was removed.") |
return; |
// Sometimes the frame in question is just not found. We don't know why |
@@ -205,49 +206,61 @@ |
return; |
throw error; |
}); |
} |
catch (error) |
{ |
// See the comment in the catch block associated with the call to |
- // tabs.insertCSS for why we catch and ignore any errors here. |
+ // tabs.insertCSS for why we catch and simply reject the promise. |
Manish Jethani
2018/08/27 15:40:49
I think this would read better as "... why we catc
hub
2018/08/27 16:42:04
Done.
|
+ return Promise.reject(error); |
} |
} |
port.on("content.applyFilters", (message, sender) => |
{ |
let selectors = []; |
let emulatedPatterns = []; |
let trace = HitLogger.hasListener(sender.page.id); |
let inline = !userStyleSheetsSupported; |
let {elemhide, snippets} = message.filterTypes || |
{elemhide: true, snippets: true}; |
if (!checkWhitelisted(sender.page, sender.frame, null, |
RegExpFilter.typeMap.DOCUMENT)) |
{ |
- let hostname = extractHostFromFrame(sender.frame); |
+ let docDomain = extractHostFromFrame(sender.frame); |
if (snippets) |
{ |
- for (let script of Snippets.getScriptsForDomain(hostname)) |
- executeScript(script, sender.page.id, sender.frame.id); |
+ for (let filter of Snippets.getFiltersForDomain(docDomain)) |
Manish Jethani
2018/08/27 15:40:49
Nit: As a convention we have been adding braces ar
hub
2018/08/27 16:42:04
Done.
|
+ executeScript(filter.script, sender.page.id, sender.frame.id) |
+ .then(() => |
+ { |
+ let tabIds = [sender.page.id]; |
+ if (filter) |
+ FilterNotifier.emit("filter.hitCount", filter, 0, 0, tabIds); |
+ |
+ logRequest(tabIds, { |
+ url: sender.frame.url.href, type: "SNIPPET", |
Manish Jethani
2018/08/27 15:40:49
Nit: When an object literal spans multiple lines,
hub
2018/08/27 16:42:04
Done.
|
+ docDomain |
+ }, filter); |
+ }); |
} |
if (elemhide && !checkWhitelisted(sender.page, sender.frame, null, |
RegExpFilter.typeMap.ELEMHIDE)) |
{ |
let specificOnly = checkWhitelisted(sender.page, sender.frame, null, |
RegExpFilter.typeMap.GENERICHIDE); |
- selectors = ElemHide.getSelectorsForDomain(hostname, specificOnly); |
+ selectors = ElemHide.getSelectorsForDomain(docDomain, specificOnly); |
- for (let filter of ElemHideEmulation.getRulesForDomain(hostname)) |
+ for (let filter of ElemHideEmulation.getRulesForDomain(docDomain)) |
emulatedPatterns.push({selector: filter.selector, text: filter.text}); |
} |
} |
if (!inline && !updateFrameStyles(sender.page.id, sender.frame.id, |
selectors, "standard")) |
{ |
inline = true; |