Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 23 matching lines...) Expand all Loading... | |
34 { | 34 { |
35 return Object.keys(panels).length > 0; | 35 return Object.keys(panels).length > 0; |
36 } | 36 } |
37 | 37 |
38 function getActivePanel(page) | 38 function getActivePanel(page) |
39 { | 39 { |
40 let panel = panels[page._id]; | 40 let panel = panels[page._id]; |
41 if(panel && !panel.reload && !panel.reloading) | 41 if(panel && !panel.reload && !panel.reloading) |
42 return panel; | 42 return panel; |
43 return null; | 43 return null; |
44 } | |
45 | |
46 function getRequestInfo(request) | |
47 { | |
48 return { | |
49 url: request.url, | |
50 type: request.type, | |
51 docDomain: request.docDomain | |
52 }; | |
53 } | 44 } |
54 | 45 |
55 function getFilterInfo(filter) | 46 function getFilterInfo(filter) |
56 { | 47 { |
57 if (!filter) | 48 if (!filter) |
58 return null; | 49 return null; |
59 | 50 |
60 let userDefined = false; | 51 let userDefined = false; |
61 let subscriptionTitle = null; | 52 let subscriptionTitle = null; |
62 | 53 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 (record.filter && record.filter.selector) == (filter && filter.selector) | 86 (record.filter && record.filter.selector) == (filter && filter.selector) |
96 ); | 87 ); |
97 } | 88 } |
98 | 89 |
99 function addRecord(panel, request, filter) | 90 function addRecord(panel, request, filter) |
100 { | 91 { |
101 if (!hasRecord(panel, request, filter)) | 92 if (!hasRecord(panel, request, filter)) |
102 { | 93 { |
103 panel.port.postMessage({ | 94 panel.port.postMessage({ |
104 type: "add-record", | 95 type: "add-record", |
105 request: getRequestInfo(request), | 96 request: request, |
106 filter: getFilterInfo(filter) | 97 filter: getFilterInfo(filter) |
107 }); | 98 }); |
108 | 99 |
109 panel.records.push({ | 100 panel.records.push({ |
110 request: request, | 101 request: request, |
111 filter: filter | 102 filter: filter |
112 }); | 103 }); |
113 } | 104 } |
114 } | 105 } |
115 | 106 |
116 function matchRequest(request) | 107 function matchRequest(request) |
117 { | 108 { |
118 return defaultMatcher.matchesAny( | 109 return defaultMatcher.matchesAny( |
119 request.url, | 110 request.url, |
120 RegExpFilter.typeMap[request.type], | 111 RegExpFilter.typeMap[request.type], |
121 request.docDomain, | 112 request.docDomain, |
122 request.thirdParty, | 113 request.thirdParty, |
123 request.sitekey, | 114 request.sitekey, |
124 request.specificOnly | 115 request.specificOnly |
125 ); | 116 ); |
126 } | 117 } |
127 | 118 |
128 /** | 119 /** |
129 * Logs a request to the devtools panel. | 120 * Logs a request to the devtools panel. |
130 * | 121 * |
131 * @param {Page} page The page the request occured on | 122 * @param {Page} page The page the request occured on |
132 * @param {string] url The URL of the request | 123 * @param {string} url The URL of the request |
kzar
2016/02/02 15:42:11
Nit: Typo here `{string]`
Sebastian Noack
2016/02/02 16:33:46
Done.
| |
133 * @param {string} type The request type | 124 * @param {string} type The request type |
134 * @param {string} docDomain The IDN-decoded hostname of the document | 125 * @param {string} docDomain The IDN-decoded hostname of the document |
135 * @param {boolean} thirdParty Whether the origin of the request and documen t differs | 126 * @param {boolean} thirdParty Whether the origin of the request and documen t differs |
136 * @param {?string} sitekey The active sitekey if there is any | 127 * @param {?string} sitekey The active sitekey if there is any |
kzar
2016/02/02 15:42:11
Nit: Isn't the syntax for optional parameters `@pa
Sebastian Noack
2016/02/02 16:33:46
{?string} means "string or null", which seems to b
kzar
2016/02/02 16:40:31
Acknowledged.
| |
137 * @param {?boolean} specificOnly Whether generic filters should be ignored | 128 * @param {?boolean} specificOnly Whether generic filters should be ignored |
138 * @param {?BlockingFilter} filter The matched filter or null if there is no mat ch | 129 * @param {?BlockingFilter} filter The matched filter or null if there is no mat ch |
139 */ | 130 */ |
140 exports.logRequest = function(page, url, type, docDomain, | 131 exports.logRequest = function(page, url, type, docDomain, |
141 thirdParty, sitekey, | 132 thirdParty, sitekey, |
142 specificOnly, filter) | 133 specificOnly, filter) |
143 { | 134 { |
144 let panel = getActivePanel(page); | 135 let panel = getActivePanel(page); |
145 if (panel) | 136 if (panel) |
146 { | 137 { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 * @param {Page} page The page the whitelisting is active on | 186 * @param {Page} page The page the whitelisting is active on |
196 * @param {string} url The url of the whitelisted document | 187 * @param {string} url The url of the whitelisted document |
197 * @param {number} typeMask The bit mask of whitelisting types checked fo r | 188 * @param {number} typeMask The bit mask of whitelisting types checked fo r |
198 * @param {string} docDomain The IDN-decoded hostname of the parent docume nt | 189 * @param {string} docDomain The IDN-decoded hostname of the parent docume nt |
199 * @param {WhitelistFilter} filter The matched whitelisting filter | 190 * @param {WhitelistFilter} filter The matched whitelisting filter |
200 */ | 191 */ |
201 exports.logWhitelistedDocument = function(page, url, typeMask, docDomain, filter ) | 192 exports.logWhitelistedDocument = function(page, url, typeMask, docDomain, filter ) |
202 { | 193 { |
203 let panel = getActivePanel(page); | 194 let panel = getActivePanel(page); |
204 if (panel) | 195 if (panel) |
205 { | 196 { |
kzar
2016/02/02 15:42:10
Nit: We don't need the braces here and for the for
Sebastian Noack
2016/02/02 16:33:47
Well, according to the Wladimir-ish notation for u
kzar
2016/02/02 16:40:31
Acknowledged.
| |
206 for (let type of nonRequestTypes) | 197 for (let type of nonRequestTypes) |
207 { | 198 { |
208 if (typeMask & filter.contentType & RegExpFilter.typeMap[type]) | 199 if (typeMask & filter.contentType & RegExpFilter.typeMap[type]) |
209 addRecord(panel, {url: url, type: type, docDomain: docDomain}, filter); | 200 addRecord(panel, {url: url, type: type, docDomain: docDomain}, filter); |
210 } | 201 } |
211 } | 202 } |
212 }; | 203 }; |
213 | 204 |
214 /** | 205 /** |
215 * Checks whether a page is inspected by the devtools panel. | 206 * Checks whether a page is inspected by the devtools panel. |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
337 panel.records.splice(i--, 1); | 328 panel.records.splice(i--, 1); |
338 continue; | 329 continue; |
339 } | 330 } |
340 | 331 |
341 record.filter = matchRequest(record.request); | 332 record.filter = matchRequest(record.request); |
342 } | 333 } |
343 | 334 |
344 panel.port.postMessage({ | 335 panel.port.postMessage({ |
345 type: "update-record", | 336 type: "update-record", |
346 index: i, | 337 index: i, |
347 request: getRequestInfo(record.request), | 338 request: record.request, |
348 filter: getFilterInfo(record.filter) | 339 filter: getFilterInfo(record.filter) |
349 }); | 340 }); |
350 } | 341 } |
351 } | 342 } |
352 } | 343 } |
353 | 344 |
354 chrome.runtime.onConnect.addListener(port => | 345 chrome.runtime.onConnect.addListener(port => |
355 { | 346 { |
356 let match = port.name.match(/^devtools-(\d+)$/); | 347 let match = port.name.match(/^devtools-(\d+)$/); |
357 if (!match) | 348 if (!match) |
(...skipping 24 matching lines...) Expand all Loading... | |
382 | 373 |
383 if (!hasPanels()) | 374 if (!hasPanels()) |
384 { | 375 { |
385 FilterNotifier.removeListener(onFilterChange); | 376 FilterNotifier.removeListener(onFilterChange); |
386 ext.pages.onLoading.removeListener(onLoading); | 377 ext.pages.onLoading.removeListener(onLoading); |
387 } | 378 } |
388 }); | 379 }); |
389 | 380 |
390 panels[inspectedTabId] = {port: port, records: []}; | 381 panels[inspectedTabId] = {port: port, records: []}; |
391 }); | 382 }); |
LEFT | RIGHT |