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

Delta Between Two Patch Sets: lib/stats.js

Issue 29785558: Issue 6679 - Don't show block stats in icon if disabled (Closed)
Left Patch Set: Created May 18, 2018, 10:39 a.m.
Right Patch Set: Split logic out into separate function Created May 18, 2018, 12:24 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 18 matching lines...) Expand all
29 29
30 let getBlockedPerPage = 30 let getBlockedPerPage =
31 /** 31 /**
32 * Gets the number of requests blocked on the given page. 32 * Gets the number of requests blocked on the given page.
33 * 33 *
34 * @param {Page} page 34 * @param {Page} page
35 * @return {Number} 35 * @return {Number}
36 */ 36 */
37 exports.getBlockedPerPage = page => blockedPerPage.get(page) || 0; 37 exports.getBlockedPerPage = page => blockedPerPage.get(page) || 0;
38 38
39 function updateBadge(page, blockedCount)
40 {
41 if (Prefs.show_statsinicon)
42 {
43 page.browserAction.setBadge(blockedCount && {
44 color: badgeColor,
45 number: blockedCount
46 });
47 }
48 }
49
39 // Once nagivation for the tab has been committed to (e.g. it's no longer 50 // Once nagivation for the tab has been committed to (e.g. it's no longer
40 // being prerendered) we clear its badge, or if some requests were already 51 // being prerendered) we clear its badge, or if some requests were already
41 // blocked beforehand we display those on the badge now. 52 // blocked beforehand we display those on the badge now.
42 browser.webNavigation.onCommitted.addListener(details => 53 browser.webNavigation.onCommitted.addListener(details =>
43 { 54 {
44 if (details.frameId == 0) 55 if (details.frameId == 0)
45 { 56 {
46 let page = new ext.Page({id: details.tabId}); 57 let page = new ext.Page({id: details.tabId});
47 let blocked = blockedPerPage.get(page); 58 let blocked = blockedPerPage.get(page);
48 59
49 if (Prefs.show_statsinicon) 60 updateBadge(page, blocked);
Thomas Greiner 2018/05/18 10:50:18 What about moving this entire if-statement into a
kzar 2018/05/18 12:25:30 Sure, I can do it that way if you like. Done.
50 {
51 page.browserAction.setBadge(blocked && {
52 color: badgeColor,
53 number: blocked
54 });
55 }
56 } 61 }
57 }); 62 });
58 63
59 FilterNotifier.on("filter.hitCount", (filter, newValue, oldValue, tabIds) => 64 FilterNotifier.on("filter.hitCount", (filter, newValue, oldValue, tabIds) =>
60 { 65 {
61 if (!(filter instanceof BlockingFilter)) 66 if (!(filter instanceof BlockingFilter))
62 return; 67 return;
63 68
64 for (let tabId of tabIds) 69 for (let tabId of tabIds)
65 { 70 {
66 let page = new ext.Page({id: tabId}); 71 let page = new ext.Page({id: tabId});
67 let blocked = blockedPerPage.get(page) || 0; 72 let blocked = blockedPerPage.get(page) || 0;
73
68 blockedPerPage.set(page, ++blocked); 74 blockedPerPage.set(page, ++blocked);
69 75 updateBadge(page, blocked);
70 // Update number in icon
71 if (Prefs.show_statsinicon)
72 {
73 page.browserAction.setBadge({
74 color: badgeColor,
75 number: blocked
76 });
77 }
78 } 76 }
79 77
80 Prefs.blocked_total++; 78 Prefs.blocked_total++;
81 }); 79 });
82 80
83 Prefs.on("show_statsinicon", () => 81 Prefs.on("show_statsinicon", () =>
84 { 82 {
85 browser.tabs.query({}, tabs => 83 browser.tabs.query({}, tabs =>
86 { 84 {
87 for (let tab of tabs) 85 for (let tab of tabs)
88 { 86 {
89 let page = new ext.Page(tab); 87 let page = new ext.Page(tab);
90 let badge = null;
91 88
92 if (Prefs.show_statsinicon) 89 if (Prefs.show_statsinicon)
93 { 90 updateBadge(page, blockedPerPage.get(page));
94 let blocked = blockedPerPage.get(page); 91 else
95 if (blocked) 92 page.browserAction.setBadge(null);
96 {
97 badge = {
98 color: badgeColor,
99 number: blocked
100 };
101 }
102 }
103
104 page.browserAction.setBadge(badge);
105 } 93 }
106 }); 94 });
107 }); 95 });
108 96
109 port.on("stats.getBlockedPerPage", 97 port.on("stats.getBlockedPerPage",
110 message => getBlockedPerPage(new ext.Page(message.tab))); 98 message => getBlockedPerPage(new ext.Page(message.tab)));
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld