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

Side by Side Diff: lib/stats.js

Issue 29680693: [$csp3 adblockpluschrome] Issue 5241 - Avoid setting badge text before navigation is committed (Closed)
Patch Set: Remove onLoading listener Created March 7, 2018, 11:32 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Chrome automatically clears the browser action badge text when the URL of 39 // Once nagivation for the tab has been committed to (e.g. it's no longer
40 // the tab is updated, but Firefox doesn't. 40 // being prerendered) we clear its badge, or if some requests were already
41 // https://bugzilla.mozilla.org/show_bug.cgi?id=1395074 41 // blocked beforehand we display those on the badge now.
42 ext.pages.onLoading.addListener(page => 42 browser.webNavigation.onCommitted.addListener(details =>
43 { 43 {
44 if (!blockedPerPage.get(page)) 44 let page = new ext.Page({id: details.tabId});
45 page.browserAction.setBadge(); 45 let blocked = blockedPerPage.get(page);
46
47 page.browserAction.setBadge(blocked && {
48 color: badgeColor,
49 number: blocked
50 });
46 }); 51 });
47 52
48 FilterNotifier.on("filter.hitCount", (filter, newValue, oldValue, page) => 53 FilterNotifier.on("filter.hitCount", (filter, newValue, oldValue, page) =>
49 { 54 {
50 if (!(filter instanceof BlockingFilter) || !page) 55 if (!(filter instanceof BlockingFilter) || !page)
51 return; 56 return;
52 57
53 Prefs.blocked_total++; 58 Prefs.blocked_total++;
54 59
55 let blocked = blockedPerPage.get(page) || 0; 60 let blocked = blockedPerPage.get(page) || 0;
(...skipping 30 matching lines...) Expand all
86 } 91 }
87 } 92 }
88 93
89 page.browserAction.setBadge(badge); 94 page.browserAction.setBadge(badge);
90 } 95 }
91 }); 96 });
92 }); 97 });
93 98
94 port.on("stats.getBlockedPerPage", 99 port.on("stats.getBlockedPerPage",
95 message => getBlockedPerPage(new ext.Page(message.tab))); 100 message => getBlockedPerPage(new ext.Page(message.tab)));
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld