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

Unified Diff: lib/stats.js

Issue 5088751004942336: Issue 370 - Right-clicked element is removed independent of created filter (Closed)
Patch Set: Rebase to rev 3c9cea80c481 Created July 18, 2014, 8:54 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/rsa.js ('k') | lib/storage/io.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
@@ -1,6 +1,6 @@
/*
* This file is part of Adblock Plus <http://adblockplus.org/>,
- * Copyright (C) 2006-2013 Eyeo GmbH
+ * Copyright (C) 2006-2014 Eyeo GmbH
*
* Adblock Plus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
@@ -24,25 +24,26 @@
let {FilterNotifier} = require("filterNotifier");
let badgeColor = "#646464";
+let statsPerPage = new ext.PageMap();
/**
- * Get statistics for specified tab
+ * Get statistics for specified page
* @param {String} key field key
- * @param {Number} tabId tab ID (leave undefined for total stats)
+ * @param {Page} page field page
* @return {Number} field value
*/
-let getStats = exports.getStats = function getStats(key, tab)
+let getStats = exports.getStats = function getStats(key, page)
{
- if (!tab)
+ if (!page)
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 pageStats = statsPerPage.get(page);
+ return pageStats ? pageStats.blocked : 0;
};
-FilterNotifier.addListener(function(action, item, newValue, oldValue, tab)
+FilterNotifier.addListener(function(action, item, newValue, oldValue, page)
{
- if (action != "filter.hitCount" || !tab)
+ if (action != "filter.hitCount" || !page)
return;
let blocked = item instanceof BlockingFilter;
@@ -56,64 +57,53 @@
Prefs.stats_total.blocked = 1;
Prefs.stats_total = Prefs.stats_total;
- let frameData = getFrameData(tab, 0);
- if (frameData)
+ let pageStats = statsPerPage.get(page);
+ if (!pageStats)
{
- if ("blocked" in frameData)
- frameData.blocked++;
- else
- frameData.blocked = 1;
+ pageStats = {};
+ statsPerPage.set(page, pageStats);
}
+ if ("blocked" in pageStats)
+ pageStats.blocked++;
+ else
+ pageStats.blocked = 1;
// Update number in icon
if (Prefs.show_statsinicon)
{
- tab.browserAction.setBadge({
+ page.browserAction.setBadge({
color: badgeColor,
- number: frameData.blocked
+ number: pageStats.blocked
});
}
}
});
-/**
- * Execute function for each tab in any window
- * @param {Function} func function to be executed
- */
-function forEachTab(func)
-{
- ext.windows.getAll(function(windows)
- {
- for each (let window in windows)
- {
- window.getAllTabs(function(tabs)
- {
- for (let i = 0; i < tabs.length; i++)
- func(tabs[i]);
- });
- }
- });
-}
-
Prefs.addListener(function(name)
{
if (name != "show_statsinicon")
return;
- forEachTab(function(tab)
+ ext.pages.query({}, function(pages)
{
- let badge = null;
- if (Prefs.show_statsinicon)
+ for (var i = 0; i < pages.length; i++)
{
- let frameData = getFrameData(tab, 0);
- if (frameData && "blocked" in frameData)
+ let page = pages[i];
+ let badge = null;
+
+ if (Prefs.show_statsinicon)
{
- badge = {
- color: badgeColor,
- number: frameData.blocked
- };
+ let pageStats = statsPerPage.get(page);
+ if (pageStats && "blocked" in pageStats)
+ {
+ badge = {
+ color: badgeColor,
+ number: pageStats.blocked
+ };
+ }
}
+
+ page.browserAction.setBadge(badge);
}
- tab.browserAction.setBadge(badge);
});
});
« no previous file with comments | « lib/rsa.js ('k') | lib/storage/io.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld