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

Unified Diff: lib/stats.js

Issue 6346177440120832: Added abstraction for frames, to fix domain-based rules, whitelisting and ad counter on Safari (Closed)
Patch Set: Addressed another comment Created Jan. 20, 2014, 8:50 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/basedomain.js ('k') | lib/whitelisting.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/stats.js
===================================================================
--- a/lib/stats.js
+++ b/lib/stats.js
@@ -24,6 +24,7 @@
let {FilterNotifier} = require("filterNotifier");
let badgeColor = "#646464";
+let statsPerTab = new TabMap(true);
/**
* Get statistics for specified tab
@@ -36,8 +37,8 @@
if (!tab)
return (key in Prefs.stats_total ? Prefs.stats_total[key] : 0);
- let frameData = getFrameData(tab, 0);
- return (frameData && key in frameData ? frameData[key] : 0);
+ let tabStats = statsPerTab.get(tab);
+ return tabStats ? tabStats.blocked : 0;
};
FilterNotifier.addListener(function(action, item, newValue, oldValue, tab)
@@ -56,21 +57,23 @@
Prefs.stats_total.blocked = 1;
Prefs.stats_total = Prefs.stats_total;
- let frameData = getFrameData(tab, 0);
- if (frameData)
+ let tabStats = statsPerTab.get(tab);
+ if (!tabStats)
{
- if ("blocked" in frameData)
- frameData.blocked++;
- else
- frameData.blocked = 1;
+ tabStats = {};
+ statsPerTab.set(tab, tabStats);
}
+ if ("blocked" in tabStats)
+ tabStats.blocked++;
+ else
+ tabStats.blocked = 1;
// Update number in icon
if (Prefs.show_statsinicon)
{
tab.browserAction.setBadge({
color: badgeColor,
- number: frameData.blocked
+ number: tabStats.blocked
});
}
}
@@ -105,12 +108,12 @@
let badge = null;
if (Prefs.show_statsinicon)
{
- let frameData = getFrameData(tab, 0);
- if (frameData && "blocked" in frameData)
+ let tabStats = statsPerTab.get(tab);
+ if (tabStats && "blocked" in tabStats)
{
badge = {
color: badgeColor,
- number: frameData.blocked
+ number: tabStats.blocked
};
}
}
« no previous file with comments | « lib/basedomain.js ('k') | lib/whitelisting.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld