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

Unified Diff: lib/devtools.js

Issue 29705719: Issue 6402 - Split filter hit / request logging out into own API (Closed)
Patch Set: Addressed Sebastian's feedback Created May 3, 2018, 3:55 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/cssInjection.js ('k') | lib/hitLogger.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/devtools.js
diff --git a/lib/devtools.js b/lib/devtools.js
index a9afca243cf3ad43d706edd4ee0b0ef2bad48036..644084c321090c793ab439f90c2863f637a6d431 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,8 @@ browser.runtime.onConnect.addListener(newPort =>
let inspectedTabId = parseInt(match[1], 10);
let localOnBeforeRequest = onBeforeRequest.bind();
+ let panel = {port: newPort, records: []};
+ let hitListener = addRecord.bind(null, panel);
browser.webRequest.onBeforeRequest.addListener(
localOnBeforeRequest,
@@ -362,6 +261,7 @@ browser.runtime.onConnect.addListener(newPort =>
newPort.onDisconnect.addListener(() =>
{
+ HitLogger.removeListener(inspectedTabId, hitListener);
panels.delete(inspectedTabId);
browser.webRequest.onBeforeRequest.removeListener(localOnBeforeRequest);
@@ -374,13 +274,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.addListener(inspectedTabId, hitListener);
+ panels.set(inspectedTabId, panel);
});
« no previous file with comments | « lib/cssInjection.js ('k') | lib/hitLogger.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld