aboutsummaryrefslogtreecommitdiffstats
path: root/js/pagestore.js
diff options
context:
space:
mode:
authorgorhill <rhill@raymondhill.net>2014-08-04 08:42:57 -0400
committergorhill <rhill@raymondhill.net>2014-08-04 08:42:57 -0400
commite2c79b3919aa33bd30c49fcd05d02f607e6b9eeb (patch)
treed364acbe343e69f80c92a8574f4f37a0832d565b /js/pagestore.js
parent08c01e11fd84e5b9f42b369016711cbb19e1b75e (diff)
downloaduBlock-e2c79b3919aa33bd30c49fcd05d02f607e6b9eeb.zip
uBlock-e2c79b3919aa33bd30c49fcd05d02f607e6b9eeb.tar.gz
uBlock-e2c79b3919aa33bd30c49fcd05d02f607e6b9eeb.tar.bz2
this fixes #19
Diffstat (limited to 'js/pagestore.js')
-rw-r--r--js/pagestore.js33
1 files changed, 14 insertions, 19 deletions
diff --git a/js/pagestore.js b/js/pagestore.js
index 79f96f2..d541305 100644
--- a/js/pagestore.js
+++ b/js/pagestore.js
@@ -207,38 +207,33 @@ PageStore.prototype.recordRequest = function(type, url, reason) {
/******************************************************************************/
-// Update badge, incrementally
-
-// rhill 2013-11-09: well this sucks, I can't update icon/badge
-// incrementally, as chromium overwrites the icon at some point without
-// notifying me, and this causes internal cached state to be out of sync.
-
-PageStore.prototype.updateBadge = function() {
- // https://github.com/gorhill/uBlock/issues/19
- // TODO: need to check with µb object to see whether tab still exists.
-
+PageStore.prototype.updateBadgeFromTab = function(tab) {
+ if ( !tab ) {
+ return;
+ }
var netFiltering = this.getNetFilteringSwitch();
var iconPath = netFiltering ? 'img/browsericons/icon19.png' : 'img/browsericons/icon19-off.png';
- chrome.browserAction.setIcon({ tabId: this.tabId, path: iconPath });
+ chrome.browserAction.setIcon({ tabId: tab.id, path: iconPath });
var iconStr = '';
if ( µb.userSettings.showIconBadge && netFiltering && this.perLoadBlockedRequestCount ) {
iconStr = this.perLoadBlockedRequestCount.toLocaleString();
}
- chrome.browserAction.setBadgeText({
- tabId: this.tabId,
- text: iconStr
- });
+ chrome.browserAction.setBadgeText({ tabId: tab.id, text: iconStr });
if ( iconStr !== '' ) {
- chrome.browserAction.setBadgeBackgroundColor({
- tabId: this.tabId,
- color: '#666'
- });
+ chrome.browserAction.setBadgeBackgroundColor({ tabId: tab.id, color: '#666' });
}
};
+PageStore.prototype.updateBadge = function() {
+ // https://github.com/gorhill/uBlock/issues/19
+ // Since we may be called asynchronously, the tab id may not exist
+ // anymore, so this ensures it does still exist.
+ chrome.tabs.get(this.tabId, this.updateBadgeFromTab.bind(this));
+};
+
/******************************************************************************/
return {