| LEFT | RIGHT | 
|---|
| 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  Loading... | 
| 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  Loading... | 
| 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))); | 
| 96 |  | 
| 97 // We sometimes set the badge text before Chrome considers the tab to have been |  | 
| 98 // updated. In those cases Chrome automatically clears the text again, so the |  | 
| 99 // blocked count will only flash for a second. To work around that we wait for |  | 
| 100 // the navigation to be committed and then update the text again. |  | 
| 101 browser.webNavigation.onCommitted.addListener(details => |  | 
| 102 { |  | 
| 103   let page = new ext.Page({id: details.tabId}); |  | 
| 104   let blocked = blockedPerPage.get(page); |  | 
| 105 |  | 
| 106   if (blocked) |  | 
| 107   { |  | 
| 108     page.browserAction.setBadge({ |  | 
| 109       color: badgeColor, |  | 
| 110       number: blocked |  | 
| 111     }); |  | 
| 112   } |  | 
| 113 }); |  | 
| LEFT | RIGHT | 
|---|