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

Delta Between Two Patch Sets: lib/hitLogger.js

Issue 29705719: Issue 6402 - Split filter hit / request logging out into own API (Closed)
Left Patch Set: Addressed Manish's feedback Created May 1, 2018, 10:49 a.m.
Right Patch Set: Addressed Manish's feedback Created May 9, 2018, 5:53 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/devtools.js ('k') | lib/popupBlocker.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 20 matching lines...) Expand all
31 ]; 31 ];
32 32
33 let eventEmitter = new EventEmitter(); 33 let eventEmitter = new EventEmitter();
34 34
35 /** 35 /**
36 * @namespace 36 * @namespace
37 * @static 37 * @static
38 */ 38 */
39 let HitLogger = exports.HitLogger = { 39 let HitLogger = exports.HitLogger = {
40 /** 40 /**
41 * Adds a listener for requests, filter hits etc related to the tab. 41 * Adds a listener for requests, filter hits etc related to the tab.
Sebastian Noack 2018/05/02 16:11:33 Can we please document/specify that the calling co
kzar 2018/05/03 15:56:52 Done.
42 * 42 *
43 * Note: Calling code is responsible for removing the listener again,
44 * it will not be automatically removed when the tab is closed.
45 *
43 * @param {number} tabId 46 * @param {number} tabId
44 * @param {function} listener 47 * @param {function} listener
45 */ 48 */
46 addListener: eventEmitter.on.bind(eventEmitter), 49 addListener: eventEmitter.on.bind(eventEmitter),
47 50
48 /** 51 /**
49 * Removes a listener for the tab. 52 * Removes a listener for the tab.
50 * 53 *
51 * @param {number} tabId 54 * @param {number} tabId
52 * @param {function} listener 55 * @param {function} listener
53 */ 56 */
54 removeListener: eventEmitter.off.bind(eventEmitter), 57 removeListener: eventEmitter.off.bind(eventEmitter),
55 58
56 /** 59 /**
57 * Checks whether a tab is being inspected by anything. 60 * Checks whether a tab is being inspected by anything.
58 * 61 *
59 * @param {number} tabId 62 * @param {number} tabId
60 * @return {boolean} 63 * @return {boolean}
61 */ 64 */
62 hasListener(tabId) 65 hasListener(tabId)
Sebastian Noack 2018/05/02 16:11:33 Does this method needs to be public (i.e. in the H
kzar 2018/05/03 15:56:52 Yea, since it's also used in lib/cssInjection.js.
63 { 66 {
64 let listeners = eventEmitter._listeners.get(tabId); 67 let listeners = eventEmitter._listeners.get(tabId);
65 return listeners && listeners.length > 0; 68 return listeners && listeners.length > 0;
66 } 69 }
67 }; 70 };
68 71
69 /** 72 /**
70 * Logs a request associated with a tab or multiple tabs. 73 * Logs a request associated with a tab or multiple tabs.
71 * 74 *
72 * @param {number[]} tabIds 75 * @param {number[]} tabIds
73 * The tabIds associated with the request 76 * The tabIds associated with the request
74 * @param {Object} request 77 * @param {Object} request
75 * The request to log 78 * The request to log
76 * @param {string} request.url 79 * @param {string} request.url
77 * The URL of the request 80 * The URL of the request
78 * @param {string} request.type 81 * @param {string} request.type
79 * The request type 82 * The request type
80 * @param {string} request.docDomain 83 * @param {string} request.docDomain
81 * The IDN-decoded hostname of the document 84 * The hostname of the document
82 * @param {boolean} request.thirdParty 85 * @param {boolean} request.thirdParty
83 * Whether the origin of the request and document differs 86 * Whether the origin of the request and document differs
84 * @param {?string} request.sitekey 87 * @param {?string} request.sitekey
85 * The active sitekey if there is any 88 * The active sitekey if there is any
86 * @param {?boolean} request.specificOnly 89 * @param {?boolean} request.specificOnly
87 * Whether generic filters should be ignored 90 * Whether generic filters should be ignored
88 * @param {?BlockingFilter} filter 91 * @param {?BlockingFilter} filter
89 * The matched filter or null if there is no match 92 * The matched filter or null if there is no match
90 */ 93 */
91 exports.logRequest = function(tabIds, request, filter) 94 exports.logRequest = (tabIds, request, filter) =>
Sebastian Noack 2018/05/02 16:11:33 Any particular reason why you pass in the request
kzar 2018/05/03 15:56:52 Well I did it this way since Manish suggested it[1
Sebastian Noack 2018/05/03 16:40:58 Well, the main argument for creating the request o
Manish Jethani 2018/05/05 01:26:09 No reasoning other than it makes the code easy to
Sebastian Noack 2018/05/05 12:56:23 Fair enough. I'm still not entirely convinced that
92 { 95 {
93 for (let tabId of tabIds) 96 for (let tabId of tabIds)
94 eventEmitter.emit(tabId, request, filter); 97 eventEmitter.emit(tabId, request, filter);
95 }; 98 };
96 99
97 /** 100 /**
98 * Logs active element hiding filters for a tab. 101 * Logs active element hiding filters for a tab.
99 * 102 *
100 * @param {number} tabId The ID of the tab, the elements were hidden in 103 * @param {number} tabId The ID of the tab, the elements were hidden in
101 * @param {string[]} selectors The selectors of applied ElemHideFilters 104 * @param {string[]} selectors The selectors of applied ElemHideFilters
102 * @param {string[]} filters The text of applied ElemHideEmulationFilters 105 * @param {string[]} filters The text of applied ElemHideEmulationFilters
103 * @param {string} docDomain The IDN-decoded hostname of the document 106 * @param {string} docDomain The hostname of the document
104 */ 107 */
105 function logHiddenElements(tabId, selectors, filters, docDomain) 108 function logHiddenElements(tabId, selectors, filters, docDomain)
106 { 109 {
107 if (HitLogger.hasListener(tabId)) 110 if (HitLogger.hasListener(tabId))
108 { 111 {
109 for (let subscription of FilterStorage.subscriptions) 112 for (let subscription of FilterStorage.subscriptions)
110 { 113 {
111 if (subscription.disabled) 114 if (subscription.disabled)
112 continue; 115 continue;
113 116
(...skipping 15 matching lines...) Expand all
129 } 132 }
130 133
131 /** 134 /**
132 * Logs a whitelisting filter that disables (some kind of) 135 * Logs a whitelisting filter that disables (some kind of)
133 * blocking for a particular document. 136 * blocking for a particular document.
134 * 137 *
135 * @param {number} tabId The tabId the whitelisting is active for 138 * @param {number} tabId The tabId the whitelisting is active for
136 * @param {string} url The url of the whitelisted document 139 * @param {string} url The url of the whitelisted document
137 * @param {number} typeMask The bit mask of whitelisting types checked 140 * @param {number} typeMask The bit mask of whitelisting types checked
138 * for 141 * for
139 * @param {string} docDomain The IDN-decoded hostname of the parent 142 * @param {string} docDomain The hostname of the parent document
140 * document
141 * @param {WhitelistFilter} filter The matched whitelisting filter 143 * @param {WhitelistFilter} filter The matched whitelisting filter
142 */ 144 */
143 exports.logWhitelistedDocument = function(tabId, url, typeMask, docDomain, 145 exports.logWhitelistedDocument = (tabId, url, typeMask, docDomain, filter) =>
Sebastian Noack 2018/05/02 16:11:33 Nit: It seems in other modules we use arrow functi
kzar 2018/05/03 15:56:51 Done.
144 filter)
145 { 146 {
146 if (HitLogger.hasListener(tabId)) 147 if (HitLogger.hasListener(tabId))
147 { 148 {
148 for (let type of nonRequestTypes) 149 for (let type of nonRequestTypes)
149 { 150 {
150 if (typeMask & filter.contentType & RegExpFilter.typeMap[type]) 151 if (typeMask & filter.contentType & RegExpFilter.typeMap[type])
151 eventEmitter.emit(tabId, {url, type, docDomain}, filter); 152 eventEmitter.emit(tabId, {url, type, docDomain}, filter);
152 } 153 }
153 } 154 }
154 }; 155 };
155 156
156 port.on("hitLogger.traceElemHide", (message, sender) => 157 port.on("hitLogger.traceElemHide", (message, sender) =>
157 { 158 {
158 logHiddenElements( 159 logHiddenElements(
Sebastian Noack 2018/05/02 16:11:33 I wonder it would make more sense to just inline t
kzar 2018/05/03 15:56:52 I prefer it how it is, I think it's easier to reas
159 sender.page.id, message.selectors, message.filters, 160 sender.page.id, message.selectors, message.filters,
160 extractHostFromFrame(sender.frame) 161 extractHostFromFrame(sender.frame)
161 ); 162 );
162 }); 163 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld