
Loading…
code review re. https://github.com/gorhill/uBlock/issues/134: no need to... #1339
+560
−258
gorhill
commented
1 check passed
Details
continuous-integration/travis-ci/pr
The Travis CI build passed
Owner
chrisaljoudi
commented
Thank you, @gorhill.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This page is out of date. Refresh to see the latest.
Showing
with
560 additions
and 258 deletions.
- +41 −41 assets/checksums.txt
- +4 −0 assets/ublock/filters.txt
- +1 −0 src/background.html
- +17 −3 src/css/devtool-log.css
- +7 −4 src/js/contentscript-end.js
- +12 −3 src/js/contentscript-start.js
- +96 −0 src/js/cosmetic-logger.js
- +52 −4 src/js/devtool-log.js
- +214 −0 src/js/logger.js
- +86 −13 src/js/messaging.js
- +0 −181 src/js/pagestore.js
- +1 −8 src/js/storage.js
- +1 −0 src/js/tab.js
- +5 −1 src/js/traffic.js
- +23 −0 src/js/ublock.js
82
assets/checksums.txt
| @@ -1,60 +1,60 @@ | ||
| -e42e13e07117589d46671e876c787cc2 assets/ublock/filter-lists.json | ||
| -7ef50e668ccfdd4de56af0003f575e93 assets/ublock/filters.txt | ||
| -c9c5cc56bec563bc1885847f925b9be2 assets/ublock/mirror-candidates.txt | ||
| ba85c7991d208fe26c8f74f57bb5cfe1 assets/ublock/privacy.txt | ||
| -0d707b2cee4a38988662107971137d13 assets/thirdparties/abp.mozilla-hispano.org/nauscopio/filtros.txt | ||
| -36a285b3ef9aadad4529d40153364013 assets/thirdparties/adblock-chinalist.googlecode.com/svn/trunk/adblock.txt | ||
| -7c0d09fbccd87b5252d3bab3e822f2e4 assets/thirdparties/adblock-czechoslovaklist.googlecode.com/svn/filters.txt | ||
| +bd73f55fa11330ec115e41d7194935f2 assets/ublock/filters.txt | ||
| +c9c5cc56bec563bc1885847f925b9be2 assets/ublock/mirror-candidates.txt | ||
| +e42e13e07117589d46671e876c787cc2 assets/ublock/filter-lists.json | ||
| 132b3ecc9da8a68c3faf740c00af734b assets/thirdparties/adblock-plus-japanese-filter.googlecode.com/hg/abp_jp.txt | ||
| +94c0a3eab74c42783855f07b22a429cf assets/thirdparties/home.fredfiber.no/langsholt/adblock.txt | ||
| +1888a9521b2a138699ec01c654e35118 assets/thirdparties/www.zoso.ro/pages/rolist.txt | ||
| 72373316d0e7ad22604d307c2d93e7cc assets/thirdparties/adblock.gardar.net/is.abp.txt | ||
| -81fb33375814d8fb1653ba721ffd6a01 assets/thirdparties/adblock.schack.dk/block.txt | ||
| +041f42feff1f0046a350506207d83a4c assets/thirdparties/raw.githubusercontent.com/k2jp/abp-japanese-filters/master/abp_jp.txt | ||
| +eef36569f78b6a2401c1e228f7761bc7 assets/thirdparties/raw.githubusercontent.com/AdBlockPlusIsrael/EasyListHebrew/master/EasyListHebrew.txt | ||
| +0b1e52e8e0bb5f0458e2d315f0fd96de assets/thirdparties/raw.githubusercontent.com/cjx82630/cjxlist/master/cjxlist.txt | ||
| +aaaefbe31ac8c7d2c32e684ffdca2bff assets/thirdparties/raw.githubusercontent.com/reek/anti-adblock-killer/master/anti-adblock-killer-filters.txt | ||
| +24231e63eeab50ad6116218aa1dc3b5b assets/thirdparties/raw.githubusercontent.com/wiltteri/wiltteri.txt/master/wiltteri.txt | ||
| +5471b40cfefa128a133b993e5ef2f555 assets/thirdparties/raw.githubusercontent.com/tomasko126/easylistczechandslovak/master/filters.txt | ||
| +068ceb3b1d8ce5ef155d6bdd30ec9d53 assets/thirdparties/raw.githubusercontent.com/szpeter80/hufilter/master/hufilter.txt | ||
| +cbde6559e6100aca9690fd01f2a93ad3 assets/thirdparties/raw.githubusercontent.com/adblockpolska/Adblock_PL_List/master/adblock_polska.txt | ||
| d8c58f5bb8072907ae361bc14dbbd28f assets/thirdparties/cjxlist1.googlecode.com/svn/cjxlist.txt | ||
| -b2823c07be0286782cc72c2355425a67 assets/thirdparties/dl.dropboxusercontent.com/u/1289327/abpxfiles/filtri.txt | ||
| -8d87a4fd68102ba59da4989cfd65ed05 assets/thirdparties/easylist-downloads.adblockplus.org/advblock.txt | ||
| -e0fcb343a05b399f0b0824f573c5015c assets/thirdparties/easylist-downloads.adblockplus.org/bitblock.txt | ||
| -674e58227219e0e477dc5b6f664388ed assets/thirdparties/easylist-downloads.adblockplus.org/easylist.txt | ||
| -f58ca4633056194a1350ebfa90a7f9d3 assets/thirdparties/easylist-downloads.adblockplus.org/easylist_noelemhide.txt | ||
| +7720856eb1b1d15d0ab415b1f19d2345 assets/thirdparties/www.hufilter.hu/hufilter.txt | ||
| +295bde39b70e1b3df7fc281d2d369ac7 assets/thirdparties/gnuzilla.gnu.org/filters/blacklist.txt | ||
| +7755619a576f2479dcf26ef1c2753182 assets/thirdparties/spam404bl.com/spam404scamlist.txt | ||
| 2ed9fcfc35ac135db1e2fda3cda8fcbc assets/thirdparties/easylist-downloads.adblockplus.org/easylistchina.txt | ||
| +44497cd06bf45dc738b7716ca1fa66b6 assets/thirdparties/easylist-downloads.adblockplus.org/fanboy-annoyance.txt | ||
| +e0fcb343a05b399f0b0824f573c5015c assets/thirdparties/easylist-downloads.adblockplus.org/bitblock.txt | ||
| 06ed68d31cf9460e58c0fa8ff8a61326 assets/thirdparties/easylist-downloads.adblockplus.org/easylistdutch.txt | ||
| -4f2cb90acac064a6dec053a5c809c0a0 assets/thirdparties/easylist-downloads.adblockplus.org/easylistgermany.txt | ||
| -3c4d23e31a12b822fd86975ab6f67e16 assets/thirdparties/easylist-downloads.adblockplus.org/easylistitaly.txt | ||
| 3e07d4c7ee50251b950c392c8060b12d assets/thirdparties/easylist-downloads.adblockplus.org/easyprivacy.txt | ||
| -44497cd06bf45dc738b7716ca1fa66b6 assets/thirdparties/easylist-downloads.adblockplus.org/fanboy-annoyance.txt | ||
| +f58ca4633056194a1350ebfa90a7f9d3 assets/thirdparties/easylist-downloads.adblockplus.org/easylist_noelemhide.txt | ||
| +8d87a4fd68102ba59da4989cfd65ed05 assets/thirdparties/easylist-downloads.adblockplus.org/advblock.txt | ||
| def19717429aaeee2331cb797d5e240e assets/thirdparties/easylist-downloads.adblockplus.org/fanboy-social.txt | ||
| d7a5ce9f655e43cd6026fa31356b8161 assets/thirdparties/easylist-downloads.adblockplus.org/liste_fr.txt | ||
| -c95fd7804f199ddc7aa5cd56a61a32ec assets/thirdparties/gitorious.org/adblock-latvian/adblock-latvian/raw/master_lists/latvian-list.txt | ||
| -295bde39b70e1b3df7fc281d2d369ac7 assets/thirdparties/gnuzilla.gnu.org/filters/blacklist.txt | ||
| -94c0a3eab74c42783855f07b22a429cf assets/thirdparties/home.fredfiber.no/langsholt/adblock.txt | ||
| -c0b6983add2393e18defcbda28fecec1 assets/thirdparties/hosts-file.net/ad-servers | ||
| -d12fbce40c55bdea5d8c7ef6b0d0202d assets/thirdparties/indonesianadblockrules.googlecode.com/hg/subscriptions/abpindo.txt | ||
| -cb26265deac870beef7133660bff9704 assets/thirdparties/liste-ar-adblock.googlecode.com/hg/Liste_AR.txt | ||
| -dea183551bca4d87e6c5ecee3bbe0c82 assets/thirdparties/margevicius.lt/easylistlithuania.txt | ||
| +3c4d23e31a12b822fd86975ab6f67e16 assets/thirdparties/easylist-downloads.adblockplus.org/easylistitaly.txt | ||
| +4f2cb90acac064a6dec053a5c809c0a0 assets/thirdparties/easylist-downloads.adblockplus.org/easylistgermany.txt | ||
| +674e58227219e0e477dc5b6f664388ed assets/thirdparties/easylist-downloads.adblockplus.org/easylist.txt | ||
| +36a285b3ef9aadad4529d40153364013 assets/thirdparties/adblock-chinalist.googlecode.com/svn/trunk/adblock.txt | ||
| +b2823c07be0286782cc72c2355425a67 assets/thirdparties/dl.dropboxusercontent.com/u/1289327/abpxfiles/filtri.txt | ||
| adc945b82aec20f53ea31c36468b3759 assets/thirdparties/mirror1.malwaredomains.com/files/immortal_domains.txt | ||
| -8732c6da425f67017af76a40f33ef0b4 assets/thirdparties/mirror1.malwaredomains.com/files/justdomains | ||
| 7f0443f3dcc9abfd47cfbc95ce824ddb assets/thirdparties/mirror1.malwaredomains.com/files/README.md | ||
| -5b8e13b618c68293430913029118781a assets/thirdparties/pgl.yoyo.org/as/README.md | ||
| -b68842b8073833ff04414d8141986ac7 assets/thirdparties/pgl.yoyo.org/as/serverlist | ||
| +8732c6da425f67017af76a40f33ef0b4 assets/thirdparties/mirror1.malwaredomains.com/files/justdomains | ||
| e63f51b30304ddca0337c8eba3bff101 assets/thirdparties/publicsuffix.org/list/effective_tld_names.dat | ||
| -eef36569f78b6a2401c1e228f7761bc7 assets/thirdparties/raw.githubusercontent.com/AdBlockPlusIsrael/EasyListHebrew/master/EasyListHebrew.txt | ||
| -cbde6559e6100aca9690fd01f2a93ad3 assets/thirdparties/raw.githubusercontent.com/adblockpolska/Adblock_PL_List/master/adblock_polska.txt | ||
| -0b1e52e8e0bb5f0458e2d315f0fd96de assets/thirdparties/raw.githubusercontent.com/cjx82630/cjxlist/master/cjxlist.txt | ||
| -041f42feff1f0046a350506207d83a4c assets/thirdparties/raw.githubusercontent.com/k2jp/abp-japanese-filters/master/abp_jp.txt | ||
| -aaaefbe31ac8c7d2c32e684ffdca2bff assets/thirdparties/raw.githubusercontent.com/reek/anti-adblock-killer/master/anti-adblock-killer-filters.txt | ||
| -068ceb3b1d8ce5ef155d6bdd30ec9d53 assets/thirdparties/raw.githubusercontent.com/szpeter80/hufilter/master/hufilter.txt | ||
| -5471b40cfefa128a133b993e5ef2f555 assets/thirdparties/raw.githubusercontent.com/tomasko126/easylistczechandslovak/master/filters.txt | ||
| -24231e63eeab50ad6116218aa1dc3b5b assets/thirdparties/raw.githubusercontent.com/wiltteri/wiltteri.txt/master/wiltteri.txt | ||
| +0d707b2cee4a38988662107971137d13 assets/thirdparties/abp.mozilla-hispano.org/nauscopio/filtros.txt | ||
| +dea183551bca4d87e6c5ecee3bbe0c82 assets/thirdparties/margevicius.lt/easylistlithuania.txt | ||
| 5933a3c9059d10ef13544013e0d6e658 assets/thirdparties/someonewhocares.org/hosts/hosts | ||
| -7755619a576f2479dcf26ef1c2753182 assets/thirdparties/spam404bl.com/spam404scamlist.txt | ||
| -72ae2048c0201c940978d27cda361891 assets/thirdparties/stanev.org/abp/adblock_bg.txt | ||
| d960765d2489db4f6038d3032cbd988c assets/thirdparties/winhelp2002.mvps.org/hosts.txt | ||
| +81fb33375814d8fb1653ba721ffd6a01 assets/thirdparties/adblock.schack.dk/block.txt | ||
| +7c0d09fbccd87b5252d3bab3e822f2e4 assets/thirdparties/adblock-czechoslovaklist.googlecode.com/svn/filters.txt | ||
| +cb26265deac870beef7133660bff9704 assets/thirdparties/liste-ar-adblock.googlecode.com/hg/Liste_AR.txt | ||
| +e68acbf09f22a8ac0650907fdd45a669 assets/thirdparties/www.fanboy.co.nz/fanboy-korean.txt | ||
| 38517bc04606b74d18cd2b48cfb74c62 assets/thirdparties/www.fanboy.co.nz/enhancedstats.txt | ||
| 2a9d105b544c47c55a3a22bb536db2bc assets/thirdparties/www.fanboy.co.nz/fanboy-antifacebook.txt | ||
| -e68acbf09f22a8ac0650907fdd45a669 assets/thirdparties/www.fanboy.co.nz/fanboy-korean.txt | ||
| -5de29853cdd54c919c283c9fdb0f3998 assets/thirdparties/www.fanboy.co.nz/fanboy-swedish.txt | ||
| -dbdc8f71338ca741a6d1e23440960965 assets/thirdparties/www.fanboy.co.nz/fanboy-ultimate.txt | ||
| faf479000090920441f1f01a664e0aca assets/thirdparties/www.fanboy.co.nz/fanboy-vietnam.txt | ||
| -7720856eb1b1d15d0ab415b1f19d2345 assets/thirdparties/www.hufilter.hu/hufilter.txt | ||
| -01ef1940551cff40fd1011f08f990d04 assets/thirdparties/www.malwaredomainlist.com/hostslist/hosts.txt | ||
| +dbdc8f71338ca741a6d1e23440960965 assets/thirdparties/www.fanboy.co.nz/fanboy-ultimate.txt | ||
| +5de29853cdd54c919c283c9fdb0f3998 assets/thirdparties/www.fanboy.co.nz/fanboy-swedish.txt | ||
| 042419405031f0fcfac3735bf4f05e21 assets/thirdparties/www.malwaredomainlist.com/hostslist/README.md | ||
| +01ef1940551cff40fd1011f08f990d04 assets/thirdparties/www.malwaredomainlist.com/hostslist/hosts.txt | ||
| +c95fd7804f199ddc7aa5cd56a61a32ec assets/thirdparties/gitorious.org/adblock-latvian/adblock-latvian/raw/master_lists/latvian-list.txt | ||
| +d12fbce40c55bdea5d8c7ef6b0d0202d assets/thirdparties/indonesianadblockrules.googlecode.com/hg/subscriptions/abpindo.txt | ||
| +72ae2048c0201c940978d27cda361891 assets/thirdparties/stanev.org/abp/adblock_bg.txt | ||
| +c0b6983add2393e18defcbda28fecec1 assets/thirdparties/hosts-file.net/ad-servers | ||
| +b68842b8073833ff04414d8141986ac7 assets/thirdparties/pgl.yoyo.org/as/serverlist | ||
| +5b8e13b618c68293430913029118781a assets/thirdparties/pgl.yoyo.org/as/README.md | ||
| 342eccafdb7e6ef7b9aacd33d1442ed1 assets/thirdparties/www.void.gr/kargig/void-gr-filters.txt | ||
| -1888a9521b2a138699ec01c654e35118 assets/thirdparties/www.zoso.ro/pages/rolist.txt |
4
assets/ublock/filters.txt
1
src/background.html
20
src/css/devtool-log.css
11
src/js/contentscript-end.js
15
src/js/contentscript-start.js
96
src/js/cosmetic-logger.js
| @@ -0,0 +1,96 @@ | ||
| +/******************************************************************************* | ||
| + | ||
| + uBlock - a browser extension to block requests. | ||
| + Copyright (C) 2015 Raymond Hill | ||
| + | ||
| + This program is free software: you can redistribute it and/or modify | ||
| + it under the terms of the GNU General Public License as published by | ||
| + the Free Software Foundation, either version 3 of the License, or | ||
| + (at your option) any later version. | ||
| + | ||
| + This program is distributed in the hope that it will be useful, | ||
| + but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| + GNU General Public License for more details. | ||
| + | ||
| + You should have received a copy of the GNU General Public License | ||
| + along with this program. If not, see {http://www.gnu.org/licenses/}. | ||
| + | ||
| + Home: https://github.com/gorhill/uBlock | ||
| +*/ | ||
| + | ||
| +/* global vAPI, HTMLDocument */ | ||
| + | ||
| +/******************************************************************************/ | ||
| + | ||
| +(function() { | ||
| + | ||
| +'use strict'; | ||
| + | ||
| +/******************************************************************************/ | ||
| + | ||
| +// https://github.com/gorhill/uBlock/issues/464 | ||
| +if ( document instanceof HTMLDocument === false ) { | ||
| + //console.debug('cosmetic-logger.js > not a HTLMDocument'); | ||
| + return; | ||
| +} | ||
| + | ||
| +// This can happen | ||
| +if ( !vAPI ) { | ||
| + //console.debug('cosmetic-logger.js > vAPI not found'); | ||
| + return; | ||
| +} | ||
| + | ||
| +/******************************************************************************/ | ||
| + | ||
| +var loggedSelectors = vAPI.loggedSelectors || {}; | ||
| + | ||
| +var injectedSelectors = []; | ||
| +var reProperties = /\s*\{[^}]+\}\s*/; | ||
| +var i; | ||
| +var styles = vAPI.styles || []; | ||
| + | ||
| +i = styles.length; | ||
| +while ( i-- ) { | ||
| + injectedSelectors = injectedSelectors.concat(styles[i].textContent.replace(reProperties, '').split(/\s*,\n\s*/)); | ||
| +} | ||
| + | ||
| +if ( injectedSelectors.length === 0 ) { | ||
| + return; | ||
| +} | ||
| + | ||
| +var matchedSelectors = []; | ||
| +var selector; | ||
| + | ||
| +i = injectedSelectors.length; | ||
| +while ( i-- ) { | ||
| + selector = injectedSelectors[i]; | ||
| + if ( loggedSelectors.hasOwnProperty(selector) ) { | ||
| + continue; | ||
| + } | ||
| + if ( document.querySelector(selector) === null ) { | ||
| + continue; | ||
| + } | ||
| + loggedSelectors[selector] = true; | ||
| + matchedSelectors.push(selector); | ||
| +} | ||
| + | ||
| +vAPI.loggedSelectors = loggedSelectors; | ||
| + | ||
| +/******************************************************************************/ | ||
| + | ||
| +var localMessager = vAPI.messaging.channel('cosmetic-*.js'); | ||
| + | ||
| +localMessager.send({ | ||
| + what: 'logCosmeticFilteringData', | ||
| + pageURL: window.location.href, | ||
| + matchedSelectors: matchedSelectors | ||
| +}, function() { | ||
| + localMessager.close(); | ||
| +}); | ||
| + | ||
| +/******************************************************************************/ | ||
| + | ||
| +})(); | ||
| + | ||
| +/******************************************************************************/ |
56
src/js/devtool-log.js
214
src/js/logger.js
| @@ -0,0 +1,214 @@ | ||
| +/******************************************************************************* | ||
| + | ||
| + uBlock Origin - a browser extension to block requests. | ||
| + Copyright (C) 2015 Raymond Hill | ||
| + | ||
| + This program is free software: you can redistribute it and/or modify | ||
| + it under the terms of the GNU General Public License as published by | ||
| + the Free Software Foundation, either version 3 of the License, or | ||
| + (at your option) any later version. | ||
| + | ||
| + This program is distributed in the hope that it will be useful, | ||
| + but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| + GNU General Public License for more details. | ||
| + | ||
| + You should have received a copy of the GNU General Public License | ||
| + along with this program. If not, see {http://www.gnu.org/licenses/}. | ||
| + | ||
| + Home: https://github.com/gorhill/uBlock | ||
| +*/ | ||
| + | ||
| +/* global µBlock */ | ||
| + | ||
| +/******************************************************************************/ | ||
| +/******************************************************************************/ | ||
| + | ||
| +µBlock.logger = (function() { | ||
| + | ||
| +'use strict'; | ||
| + | ||
| +/******************************************************************************/ | ||
| +/******************************************************************************/ | ||
| + | ||
| +var LogEntry = function(details, result) { | ||
| + this.init(details, result); | ||
| +}; | ||
| + | ||
| +/******************************************************************************/ | ||
| + | ||
| +var logEntryFactory = function(details, result) { | ||
| + var entry = logEntryJunkyard.pop(); | ||
| + if ( entry ) { | ||
| + return entry.init(details, result); | ||
| + } | ||
| + return new LogEntry(details, result); | ||
| +}; | ||
| + | ||
| +var logEntryJunkyard = []; | ||
| +var logEntryJunkyardMax = 100; | ||
| + | ||
| +/******************************************************************************/ | ||
| + | ||
| +LogEntry.prototype.init = function(details, result) { | ||
| + this.tstamp = Date.now(); | ||
| + this.url = details.requestURL; | ||
| + this.hostname = details.requestHostname; | ||
| + this.type = details.requestType; | ||
| + this.result = result; | ||
| + return this; | ||
| +}; | ||
| + | ||
| +/******************************************************************************/ | ||
| + | ||
| +LogEntry.prototype.dispose = function() { | ||
| + this.url = this.hostname = this.type = this.result = ''; | ||
| + if ( logEntryJunkyard.length < logEntryJunkyardMax ) { | ||
| + logEntryJunkyard.push(this); | ||
| + } | ||
| +}; | ||
| + | ||
| +/******************************************************************************/ | ||
| +/******************************************************************************/ | ||
| + | ||
| +var LogBuffer = function() { | ||
| + this.lastReadTime = 0; | ||
| + this.size = 50; | ||
| + this.buffer = new Array(this.size); | ||
| + this.readPtr = 0; | ||
| + this.writePtr = 0; | ||
| +}; | ||
| + | ||
| +/******************************************************************************/ | ||
| + | ||
| +LogBuffer.prototype.dispose = function() { | ||
| + var entry; | ||
| + var i = this.buffer.length; | ||
| + while ( i-- ) { | ||
| + entry = this.buffer[i]; | ||
| + if ( entry instanceof LogEntry ) { | ||
| + entry.dispose(); | ||
| + } | ||
| + } | ||
| + this.buffer = null; | ||
| + return null; | ||
| +}; | ||
| + | ||
| +/******************************************************************************/ | ||
| + | ||
| +LogBuffer.prototype.writeOne = function(details, result) { | ||
| + // Reusing log entry = less memory churning | ||
| + var entry = this.buffer[this.writePtr]; | ||
| + if ( entry instanceof LogEntry === false ) { | ||
| + this.buffer[this.writePtr] = logEntryFactory(details, result); | ||
| + } else { | ||
| + entry.init(details, result); | ||
| + } | ||
| + this.writePtr += 1; | ||
| + if ( this.writePtr === this.size ) { | ||
| + this.writePtr = 0; | ||
| + } | ||
| + // Grow the buffer between 1.5x-2x the current size | ||
| + if ( this.writePtr === this.readPtr ) { | ||
| + var toMove = this.buffer.slice(0, this.writePtr); | ||
| + var minSize = Math.ceil(this.size * 1.5); | ||
| + this.size += toMove.length; | ||
| + if ( this.size < minSize ) { | ||
| + this.buffer = this.buffer.concat(toMove, new Array(minSize - this.size)); | ||
| + this.writePtr = this.size; | ||
| + } else { | ||
| + this.buffer = this.buffer.concat(toMove); | ||
| + this.writePtr = 0; | ||
| + } | ||
| + this.size = this.buffer.length; | ||
| + } | ||
| +}; | ||
| + | ||
| +/******************************************************************************/ | ||
| + | ||
| +LogBuffer.prototype.readAll = function() { | ||
| + var out; | ||
| + if ( this.readPtr < this.writePtr ) { | ||
| + out = this.buffer.slice(this.readPtr, this.writePtr); | ||
| + } else if ( this.writePtr < this.readPtr ) { | ||
| + out = this.buffer.slice(this.readPtr).concat(this.buffer.slice(0, this.writePtr)); | ||
| + } else { | ||
| + out = []; | ||
| + } | ||
| + this.readPtr = this.writePtr; | ||
| + this.lastReadTime = Date.now(); | ||
| + return out; | ||
| +}; | ||
| + | ||
| +/******************************************************************************/ | ||
| +/******************************************************************************/ | ||
| + | ||
| +// Tab id to log buffer instances | ||
| +var logBuffers = {}; | ||
| + | ||
| +// After 30 seconds without being read, a buffer will be considered unused, and | ||
| +// thus removed from memory. | ||
| +var logBufferObsoleteAfter = 30 * 1000; | ||
| + | ||
| +/******************************************************************************/ | ||
| + | ||
| +var writeOne = function(tabId, details, result) { | ||
| + if ( logBuffers.hasOwnProperty(tabId) === false ) { | ||
| + return; | ||
| + } | ||
| + var logBuffer = logBuffers[tabId]; | ||
| + logBuffer.writeOne(details, result); | ||
| +}; | ||
| + | ||
| +/******************************************************************************/ | ||
| + | ||
| +var readAll = function(tabId) { | ||
| + if ( logBuffers.hasOwnProperty(tabId) === false ) { | ||
| + logBuffers[tabId] = new LogBuffer(); | ||
| + } | ||
| + return logBuffers[tabId].readAll(); | ||
| +}; | ||
| + | ||
| +/******************************************************************************/ | ||
| + | ||
| +var isObserved = function(tabId) { | ||
| + return logBuffers.hasOwnProperty(tabId); | ||
| +}; | ||
| + | ||
| +/******************************************************************************/ | ||
| + | ||
| +var loggerJanitor = function() { | ||
| + var logBuffer; | ||
| + var obsolete = Date.now() - logBufferObsoleteAfter; | ||
| + for ( var tabId in logBuffers ) { | ||
| + if ( logBuffers.hasOwnProperty(tabId) === false ) { | ||
| + continue; | ||
| + } | ||
| + logBuffer = logBuffers[tabId]; | ||
| + if ( logBuffer.lastReadTime < obsolete ) { | ||
| + logBuffer.dispose(); | ||
| + delete logBuffers[tabId]; | ||
| + } | ||
| + } | ||
| + setTimeout(loggerJanitor, loggerJanitorPeriod); | ||
| +}; | ||
| + | ||
| +// The janitor will look for stale log buffer every 2 minutes. | ||
| +var loggerJanitorPeriod = 2 * 60 * 1000; | ||
| + | ||
| +setTimeout(loggerJanitor, loggerJanitorPeriod); | ||
| + | ||
| +/******************************************************************************/ | ||
| + | ||
| +return { | ||
| + writeOne: writeOne, | ||
| + readAll: readAll, | ||
| + isObserved: isObserved | ||
| +}; | ||
| + | ||
| +/******************************************************************************/ | ||
| +/******************************************************************************/ | ||
| + | ||
| +})(); | ||
| + | ||
| +/******************************************************************************/ |
99
src/js/messaging.js
181
src/js/pagestore.js
9
src/js/storage.js
1
src/js/tab.js
6
src/js/traffic.js
23
src/js/ublock.js
... force a recompile of whole user filter list