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 March 21, 2018, 3:14 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') | lib/hitLogger.js » ('J')
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 167a7650e990cb3819b50d719a3e25501caf9e5f..69b21420a4f1b0d0838b37874befed5ee36dc491 100644
--- a/lib/devtools.js
+++ b/lib/devtools.js
@@ -18,14 +18,13 @@
"use strict";
const {RegExpFilter,
- WhitelistFilter,
- ElemHideFilter} = require("filterClasses");
+ WhitelistFilter} = require("filterClasses");
const {SpecialSubscription} = require("subscriptionClasses");
-const {FilterStorage} = require("filterStorage");
const {defaultMatcher} = require("matcher");
const {FilterNotifier} = require("filterNotifier");
const {extractHostFromFrame} = require("url");
const {port} = require("messaging");
+const {HitLogger} = require("hitLogger");
const nonRequestTypes = ["DOCUMENT", "ELEMHIDE", "GENERICBLOCK", "GENERICHIDE"];
@@ -94,7 +93,7 @@ function hasRecord(panel, request, filter)
function addRecord(panel, request, filter)
{
- if (!hasRecord(panel, request, filter))
+ if (isActivePanel(panel) && !hasRecord(panel, request, filter))
kzar 2018/03/21 15:18:45 Since we can no longer do the `isActivePanel` che
{
panel.port.postMessage({
type: "add-record",
@@ -118,106 +117,6 @@ function matchRequest(request)
);
}
-/**
- * Logs a request to the devtools panel.
- *
- * @param {?Page} page The page the request occured on or null if
- * the request isn't associated with a page
- * @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(page, url, type, docDomain,
- thirdParty, sitekey,
- specificOnly, filter)
-{
- if (panels.size == 0)
- return;
-
- let request = {url, type, docDomain, thirdParty, sitekey, specificOnly};
- for (let [tabId, panel] of panels)
- if ((!page || page.id == tabId) && isActivePanel(panel))
- addRecord(panel, request, filter);
-};
-
-/**
- * Logs active element hiding filters to the devtools panel.
- *
- * @param {Page} page The page the elements were hidden on
- * @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(page, selectors, filters, docDomain)
-{
- let panel = getActivePanel(page);
- 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 {Page} page The page the whitelisting is active on
- * @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(page, url, typeMask, docDomain,
- filter)
-{
- let panel = getActivePanel(page);
- if (panel)
- {
- for (let type of nonRequestTypes)
- {
- if (typeMask & filter.contentType & RegExpFilter.typeMap[type])
- addRecord(panel, {url, type, docDomain}, filter);
- }
- }
-};
-
-/**
- * Checks whether a page is inspected by the devtools panel.
- *
- * @param {Page} page
- * @return {boolean}
- */
-exports.hasPanel = function(page)
-{
- return panels.has(page.id);
-};
-
function onBeforeRequest(details)
{
let panel = panels.get(details.tabId);
@@ -342,6 +241,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 +260,11 @@ browser.runtime.onConnect.addListener(newPort =>
FilterNotifier.on("subscription.added", onSubscriptionAdded);
}
+ let hitListener = addRecord.bind(null, panel);
+
newPort.onDisconnect.addListener(() =>
{
+ HitLogger.off(inspectedTabId, hitListener);
panels.delete(inspectedTabId);
browser.webRequest.onBeforeRequest.removeListener(localOnBeforeRequest);
@@ -374,13 +277,6 @@ browser.runtime.onConnect.addListener(newPort =>
}
});
- panels.set(inspectedTabId, {port: newPort, records: []});
-});
-
-port.on("devtools.traceElemHide", (message, sender) =>
-{
- logHiddenElements(
- sender.page, message.selectors, message.filters,
- extractHostFromFrame(sender.frame)
- );
+ HitLogger.on(inspectedTabId, hitListener);
+ panels.set(inspectedTabId, panel);
});
« no previous file with comments | « lib/cssInjection.js ('k') | lib/hitLogger.js » ('j') | lib/hitLogger.js » ('J')

Powered by Google App Engine
This is Rietveld