Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
this fixes 202
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Sep 14, 2014
1 parent 1b033d3 commit ee81436
Show file tree
Hide file tree
Showing 19 changed files with 601 additions and 313 deletions.
14 changes: 3 additions & 11 deletions _locales/de/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,22 +207,14 @@
"message":"Änderungen anwenden",
"description":"English: Apply changes"
},
"logBlockedRequestsPrompt":{
"logNetRequestsPrompt":{
"message":"Protokollieren von blockierten Elementen aktivieren",
"description":"English: Enable the logging of blocked requests"
"description":"English: Enable the logging of network requests"
},
"logBlockedRequestsHelp":{
"logNetRequestsHelp":{
"message":"Du kannst dir die Details von blockierten Anfragen anschauen, wenn du diese Option aktivierst. Das Protokollieren von blockierten Anfragen erhöht den Speicherbedarf von <i>µBlock<\/i>. Da dieses Feature von vielen Benutzern wohl nicht genutzt werden wird, ist es standardmäßig deaktiviert.",
"description":"English: see _locales\/en\/messages.log"
},
"logAllowedRequestsPrompt":{
"message":"Protokollieren von nicht-blockierten Elementen aktivieren",
"description":"English: Enable the logging of non-blocked requests"
},
"logAllowedRequestsHelp":{
"message":"Du kannst dir die Details von nicht-blockierten Anfragen anschauen, wenn du diese Option aktivierst. Das Protokollieren von nicht-blockierten Anfragen erhöht den Speicherbedarf von µBlock. Da dieses Feature von vielen Benutzern wohl nicht genutzt werden wird, ist es standardmäßig deaktiviert.",
"description":"English: see _locales\/en\/messages.log"
},
"logBlockedRequestsHeader":{
"message":"Blockierte Anfragen",
"description":"English: Blocked requests"
Expand Down
18 changes: 5 additions & 13 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,20 +207,12 @@
"message":"Apply changes",
"description":"English: Apply changes"
},
"logBlockedRequestsPrompt":{
"message":"Enable the logging of blocked requests",
"description":"English: Enable the logging of blocked requests"
"logNetRequestsPrompt":{
"message":"Enable the logging of network requests",
"description":"English: Enable the logging of network requests"
},
"logBlockedRequestsHelp":{
"message":"You can inspect the details of blocked requests if you wish by enabling this option. The logging of blocked requests increases the memory footprint of µBlock. Since many users will never use this feature, it is disabled by default.",
"description":"English: see _locales\/en\/messages.log"
},
"logAllowedRequestsPrompt":{
"message":"Enable the logging of non-blocked requests",
"description":"English: Enable the logging of non-blocked requests"
},
"logAllowedRequestsHelp":{
"message":"You can inspect the details of non-blocked requests if you wish by enabling this option. The logging of non-blocked requests increases the memory footprint of µBlock. Since many users will never use this feature, it is disabled by default.",
"logNetRequestsHelp":{
"message":"You can inspect the details of network requests if you wish by enabling this option. The logging of network requests increases the memory footprint of µBlock. Since many users will never use this feature, it is disabled by default.",
"description":"English: see _locales\/en\/messages.log"
},
"logBlockedRequestsHeader":{
Expand Down
18 changes: 5 additions & 13 deletions _locales/fr/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,20 +207,12 @@
"message":"Appliquer",
"description":"English: Apply changes"
},
"logBlockedRequestsPrompt":{
"message":"Activer la journalisation des requêtes bloquées",
"description":"English: Enable the logging of blocked requests"
"logNetRequestsPrompt":{
"message":"Activer la journalisation des requêtes",
"description":"English: Enable the logging of network requests"
},
"logBlockedRequestsHelp":{
"message":"Vous pouvez inspecter les détails des requêtes bloquées en activant cette option. La journalisation des requêtes bloquées augmente l'empreinte mémoire utilisée par µBlock. Puisque que bon nombre d'utilisateurs n'utiliseront jamais cette fonctionnalité, elle est désactivée par défaut.",
"description":"English: see _locales\/en\/messages.log"
},
"logAllowedRequestsPrompt":{
"message":"Activer la journalisation des requêtes autorisées",
"description":"English: Enable the logging of non-blocked requests"
},
"logAllowedRequestsHelp":{
"message":"Vous pouvez inspecter les détails des requêtes autorisées en activant cette option. La journalisation des requêtes autorisées augmente l'empreinte mémoire utilisée par µBlock. Puisque que bon nombre d'utilisateurs n'utiliseront jamais cette fonctionnalité, elle est désactivée par défaut.",
"logNetRequestsHelp":{
"message":"Vous pouvez inspecter les détails des requêtes en activant cette option. La journalisation des requêtes augmente l'empreinte mémoire utilisée par µBlock. Puisque que bon nombre d'utilisateurs n'utiliseront jamais cette fonctionnalité, elle est désactivée par défaut.",
"description":"English: see _locales\/en\/messages.log"
},
"logBlockedRequestsHeader":{
Expand Down
4 changes: 2 additions & 2 deletions background.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<script src="js/liquid-dict.js"></script>
<script src="js/utils.js"></script>
<script src="js/assets.js"></script>
<script src="js/net-filters.js"></script>
<script src="js/cosmetic-filters.js"></script>
<script src="js/net-filtering.js"></script>
<script src="js/cosmetic-filtering.js"></script>
<script src="js/ublock.js"></script>
<script src="js/messaging.js"></script>
<script src="js/profiler.js"></script>
Expand Down
62 changes: 54 additions & 8 deletions js/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

µBlock.asyncJobs = (function() {

/******************************************************************************/

var processJobs = function() {
asyncJobManager.process();
};
Expand All @@ -45,6 +47,8 @@ AsyncJobEntry.prototype.destroy = function() {
this.callback = null;
};

/******************************************************************************/

var AsyncJobManager = function() {
this.timeResolution = 200;
this.jobs = {};
Expand All @@ -54,7 +58,15 @@ var AsyncJobManager = function() {
this.timerWhen = Number.MAX_VALUE;
};

/******************************************************************************/

AsyncJobManager.prototype.restartTimer = function() {
// TODO: Another way to do this is to extract the keys, sort the keys
// in chronological order, than pick the first entry to get the next
// time at which we want a time event to fire. Completely unsure the
// overhead of extracting keys/sorting is less than what is below.
// I could also keep the keys ordered, and use binary search when adding
// a new job.
var when = Number.MAX_VALUE;
var jobs = this.jobs, job;
for ( var jobName in jobs ) {
Expand All @@ -68,13 +80,19 @@ AsyncJobManager.prototype.restartTimer = function() {
// Quantize time value
when = Math.floor((when + this.timeResolution - 1) / this.timeResolution) * this.timeResolution;

// TODO: Maybe use chrome.alarms() API when the next job is at more than
// one minute in the future... From reading about it, chrome.alarms() is
// smarter in that it will fire the event only when the browser is not
// too busy. (through XAL to abstract API specificities)
if ( when < this.timerWhen ) {
clearTimeout(this.timerId);
this.timerWhen = when;
this.timerId = setTimeout(processJobs, Math.max(when - Date.now(), 10));
}
};

/******************************************************************************/

AsyncJobManager.prototype.add = function(name, data, callback, delay, recurrent) {
var job = this.jobs[name];
if ( !job ) {
Expand All @@ -94,6 +112,22 @@ AsyncJobManager.prototype.add = function(name, data, callback, delay, recurrent)
this.restartTimer();
};

/******************************************************************************/

AsyncJobManager.prototype.remove = function(jobName) {
if ( this.jobs.hasOwnProperty(jobName) === false ) {
return;
}
var job = this.jobs[jobName];
delete this.jobs[jobName];
job.destroy();
this.jobCount--;
this.jobJunkyard.push(job);
this.restartTimer();
};

/******************************************************************************/

AsyncJobManager.prototype.process = function() {
this.timerId = null;
this.timerWhen = Number.MAX_VALUE;
Expand All @@ -120,9 +154,13 @@ AsyncJobManager.prototype.process = function() {
this.restartTimer();
};

/******************************************************************************/

// Only one instance
var asyncJobManager = new AsyncJobManager();

/******************************************************************************/

// Publish
return asyncJobManager;

Expand All @@ -133,12 +171,12 @@ return asyncJobManager;
// Update visual of extension icon.
// A time out is used to coalesce adjacent requests to update badge.

µBlock.updateBadgeAsync = function(tabId) {
if ( tabId < 0 ) {
return;
}
var µb = this;
var updateBadge = function() {
µBlock.updateBadgeAsync = (function(){
var µb = µBlock;

// Cache callback definition, it was a bad idea to define this one inside
// updateBadgeAsync
var updateBadge = function(tabId) {
var pageStore = µb.pageStoreFromTabId(tabId);
if ( pageStore ) {
pageStore.updateBadge();
Expand All @@ -150,5 +188,13 @@ return asyncJobManager;
''
);
};
this.asyncJobs.add('updateBadge-' + tabId, tabId, updateBadge, 250);
};

var updateBadgeAsync = function(tabId) {
if ( tabId < 0 ) {
return;
}
µb.asyncJobs.add('updateBadge-' + tabId, tabId, updateBadge, 250);
};

return updateBadgeAsync;
})();
3 changes: 1 addition & 2 deletions js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ return {
autoUpdate: true,
collapseBlocked: true,
externalLists: '',
logBlockedRequests: false,
logAllowedRequests: false,
logRequests: false,
parseAllABPHideFilters: true,
showIconBadge: true
},
Expand Down
Loading

0 comments on commit ee81436

Please sign in to comment.