 Issue 29705719:
  Issue 6402 - Split filter hit / request logging out into own API  (Closed)
    
  
    Issue 29705719:
  Issue 6402 - Split filter hit / request logging out into own API  (Closed) 
  | Index: lib/devtools.js | 
| diff --git a/lib/devtools.js b/lib/devtools.js | 
| index a9afca243cf3ad43d706edd4ee0b0ef2bad48036..cb7aef272c74acc02feeb0438d4231f9d63469db 100644 | 
| --- a/lib/devtools.js | 
| +++ b/lib/devtools.js | 
| @@ -27,9 +27,7 @@ const {defaultMatcher} = require("../adblockpluscore/lib/matcher"); | 
| const {FilterNotifier} = require("../adblockpluscore/lib/filterNotifier"); | 
| const {extractHostFromFrame} = require("./url"); | 
| const {port} = require("./messaging"); | 
| - | 
| -const nonRequestTypes = ["DOCUMENT", "ELEMHIDE", | 
| - "GENERICBLOCK", "GENERICHIDE", "CSP"]; | 
| +const {HitLogger, nonRequestTypes} = require("./hitLogger"); | 
| let panels = new Map(); | 
| @@ -117,107 +115,6 @@ function matchRequest(request) | 
| ); | 
| } | 
| -/** | 
| - * Logs a request to the devtools panel. | 
| - * | 
| - * @param {number[]} tabIds The tabIds associated with the request | 
| - * @param {string} url The URL of the request | 
| - * @param {string} type The request type | 
| - * @param {string} docDomain The IDN-decoded hostname of the document | 
| - * @param {boolean} thirdParty Whether the origin of the request and | 
| - * document differs | 
| - * @param {?string} sitekey The active sitekey if there is any | 
| - * @param {?boolean} specificOnly Whether generic filters should be ignored | 
| - * @param {?BlockingFilter} filter The matched filter or null if there is no | 
| - * match | 
| - */ | 
| -exports.logRequest = function(tabIds, url, type, docDomain, | 
| - thirdParty, sitekey, | 
| - specificOnly, filter) | 
| -{ | 
| - for (let tabId of tabIds) | 
| - { | 
| - let panel = getActivePanel(tabId); | 
| - if (panel) | 
| - { | 
| - let request = {url, type, docDomain, thirdParty, sitekey, specificOnly}; | 
| - addRecord(panel, request, filter); | 
| - } | 
| - } | 
| -}; | 
| - | 
| -/** | 
| - * Logs active element hiding filters to the devtools panel. | 
| - * | 
| - * @param {number} tabId The ID of the tab, the elements were hidden in | 
| - * @param {string[]} selectors The selectors of applied ElemHideFilters | 
| - * @param {string[]} filters The text of applied ElemHideEmulationFilters | 
| - * @param {string} docDomain The IDN-decoded hostname of the document | 
| - */ | 
| -function logHiddenElements(tabId, selectors, filters, docDomain) | 
| -{ | 
| - let panel = getActivePanel(tabId); | 
| - if (panel) | 
| - { | 
| - for (let subscription of FilterStorage.subscriptions) | 
| - { | 
| - if (subscription.disabled) | 
| - continue; | 
| - | 
| - for (let filter of subscription.filters) | 
| - { | 
| - // We only know the exact filter in case of element hiding emulation. | 
| - // For regular element hiding filters, the content script only knows | 
| - // the selector, so we have to find a filter that has an identical | 
| - // selector and is active on the domain the match was reported from. | 
| - let isActiveElemHideFilter = filter instanceof ElemHideFilter && | 
| - selectors.includes(filter.selector) && | 
| - filter.isActiveOnDomain(docDomain); | 
| - | 
| - if (isActiveElemHideFilter || filters.includes(filter.text)) | 
| - addRecord(panel, {type: "ELEMHIDE", docDomain}, filter); | 
| - } | 
| - } | 
| - } | 
| -} | 
| - | 
| -/** | 
| - * Logs a whitelisting filter, that disables (some kind of) | 
| - * blocking for a particular document, to the devtools panel. | 
| - * | 
| - * @param {number} tabId The tabId the whitelisting is active for | 
| - * @param {string} url The url of the whitelisted document | 
| - * @param {number} typeMask The bit mask of whitelisting types checked | 
| - * for | 
| - * @param {string} docDomain The IDN-decoded hostname of the parent | 
| - * document | 
| - * @param {WhitelistFilter} filter The matched whitelisting filter | 
| - */ | 
| -exports.logWhitelistedDocument = function(tabId, url, typeMask, docDomain, | 
| - filter) | 
| -{ | 
| - let panel = getActivePanel(tabId); | 
| - if (panel) | 
| - { | 
| - for (let type of nonRequestTypes) | 
| - { | 
| - if (typeMask & filter.contentType & RegExpFilter.typeMap[type]) | 
| - addRecord(panel, {url, type, docDomain}, filter); | 
| - } | 
| - } | 
| -}; | 
| - | 
| -/** | 
| - * Checks whether a tab is inspected by the devtools panel. | 
| - * | 
| - * @param {number} tabId | 
| - * @return {boolean} | 
| - */ | 
| -exports.hasPanel = function(tabId) | 
| -{ | 
| - return panels.has(tabId); | 
| -}; | 
| - | 
| function onBeforeRequest(details) | 
| { | 
| let panel = panels.get(details.tabId); | 
| @@ -342,6 +239,7 @@ browser.runtime.onConnect.addListener(newPort => | 
| let inspectedTabId = parseInt(match[1], 10); | 
| let localOnBeforeRequest = onBeforeRequest.bind(); | 
| + let panel = {port: newPort, records: []}; | 
| browser.webRequest.onBeforeRequest.addListener( | 
| localOnBeforeRequest, | 
| @@ -360,8 +258,11 @@ browser.runtime.onConnect.addListener(newPort => | 
| FilterNotifier.on("subscription.added", onSubscriptionAdded); | 
| } | 
| + let hitListener = addRecord.bind(null, panel); | 
| 
Manish Jethani
2018/04/23 15:30:58
I'm wondering if panel should be an object of a Pa
 
kzar
2018/05/01 10:53:07
Seems like kind of an unrelated change to me, I'll
 
Manish Jethani
2018/05/02 13:25:13
Acknowledged.
 | 
| + | 
| newPort.onDisconnect.addListener(() => | 
| { | 
| + HitLogger.off(inspectedTabId, hitListener); | 
| panels.delete(inspectedTabId); | 
| browser.webRequest.onBeforeRequest.removeListener(localOnBeforeRequest); | 
| @@ -374,13 +275,6 @@ browser.runtime.onConnect.addListener(newPort => | 
| } | 
| }); | 
| - panels.set(inspectedTabId, {port: newPort, records: []}); | 
| -}); | 
| - | 
| -port.on("devtools.traceElemHide", (message, sender) => | 
| -{ | 
| - logHiddenElements( | 
| - sender.page.id, message.selectors, message.filters, | 
| - extractHostFromFrame(sender.frame) | 
| - ); | 
| + HitLogger.on(inspectedTabId, hitListener); | 
| + panels.set(inspectedTabId, panel); | 
| }); |