From c69f37a2de527f8c4c744761e37d4f85faf504fd Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Thu, 24 Aug 2017 10:54:34 +0100 Subject: [PATCH] Removal of tab page counter code. Fixes #759 --- webextension/js/.eslintrc.js | 3 +- webextension/js/background/index.html | 2 - webextension/js/background/messageHandler.js | 19 ------- webextension/js/background/tabPageCounter.js | 55 -------------------- 4 files changed, 1 insertion(+), 78 deletions(-) delete mode 100644 webextension/js/background/tabPageCounter.js diff --git a/webextension/js/.eslintrc.js b/webextension/js/.eslintrc.js index 801dad5..f78079f 100644 --- a/webextension/js/.eslintrc.js +++ b/webextension/js/.eslintrc.js @@ -7,7 +7,6 @@ module.exports = { "badge": true, "backgroundLogic": true, "identityState": true, - "messageHandler": true, - "tabPageCounter": true + "messageHandler": true } }; diff --git a/webextension/js/background/index.html b/webextension/js/background/index.html index cd0021e..06de8ff 100644 --- a/webextension/js/background/index.html +++ b/webextension/js/background/index.html @@ -11,7 +11,6 @@ "js/background/badge.js", "js/background/identityState.js", "js/background/messageHandler.js", - "js/background/tabPageCounter.js", "js/backdround/init.js" ] --> @@ -20,7 +19,6 @@ - diff --git a/webextension/js/background/messageHandler.js b/webextension/js/background/messageHandler.js index e45a0fa..f58816f 100644 --- a/webextension/js/background/messageHandler.js +++ b/webextension/js/background/messageHandler.js @@ -88,20 +88,17 @@ const messageHandler = { if (tab.id === -1) { return {}; } - tabPageCounter.initTabCounter(tab); }); browser.tabs.onRemoved.addListener((tabId) => { if (tabId === -1) { return {}; } - tabPageCounter.sendTabCountAndDelete(tabId); }); browser.tabs.onActivated.addListener((info) => { assignManager.removeContextMenu(); browser.tabs.get(info.tabId).then((tab) => { - tabPageCounter.initTabCounter(tab); assignManager.calculateContextMenu(tab); }).catch((e) => { throw e; @@ -112,20 +109,6 @@ const messageHandler = { this.onFocusChangedCallback(windowId); }); - browser.idle.onStateChanged.addListener((newState) => { - browser.tabs.query({}).then(tabs => { - for (let tab of tabs) { // eslint-disable-line prefer-const - if (newState === "idle") { - tabPageCounter.sendTabCountAndDelete(tab.id, "user-went-idle"); - } else if (newState === "active" && tab.active) { - tabPageCounter.initTabCounter(tab); - } - } - }).catch(e => { - throw e; - }); - }); - browser.webRequest.onCompleted.addListener((details) => { if (details.frameId !== 0 || details.tabId === -1) { return {}; @@ -133,7 +116,6 @@ const messageHandler = { assignManager.removeContextMenu(); browser.tabs.get(details.tabId).then((tab) => { - tabPageCounter.incrementTabCount(tab); assignManager.calculateContextMenu(tab); }).catch((e) => { throw e; @@ -160,7 +142,6 @@ const messageHandler = { badge.displayBrowserActionBadge(currentWindow.incognito); browser.tabs.query({active: true, windowId}).then((tabs) => { if (tabs && tabs[0]) { - tabPageCounter.initTabCounter(tabs[0]); assignManager.calculateContextMenu(tabs[0]); } }).catch((e) => { diff --git a/webextension/js/background/tabPageCounter.js b/webextension/js/background/tabPageCounter.js deleted file mode 100644 index 19d9591..0000000 --- a/webextension/js/background/tabPageCounter.js +++ /dev/null @@ -1,55 +0,0 @@ -// eslint-disable-next-line no-unused-vars -const tabPageCounter = { - counters: {}, - - initTabCounter(tab) { - if (tab.id in this.counters) { - if (!("activity" in this.counters[tab.id])) { - this.counters[tab.id].activity = { - "cookieStoreId": tab.cookieStoreId, - "pageRequests": 0 - }; - } - if (!("tab" in this.counters[tab.id])) { - this.counters[tab.id].tab = { - "cookieStoreId": tab.cookieStoreId, - "pageRequests": 0 - }; - } - } else { - this.counters[tab.id] = {}; - this.counters[tab.id].tab = { - "cookieStoreId": tab.cookieStoreId, - "pageRequests": 0 - }; - this.counters[tab.id].activity = { - "cookieStoreId": tab.cookieStoreId, - "pageRequests": 0 - }; - } - }, - - sendTabCountAndDelete(tabId, why = "user-closed-tab") { - if (!(this.counters[tabId])) { - return; - } - if (why === "user-closed-tab" && this.counters[tabId].tab) { - // When we send the ping because the user closed the tab, - // delete both the 'tab' and 'activity' counters - delete this.counters[tabId]; - } else if (why === "user-went-idle" && this.counters[tabId].activity) { - // When we send the ping because the user went idle, - // only reset the 'activity' counter - this.counters[tabId].activity = { - "cookieStoreId": this.counters[tabId].tab.cookieStoreId, - "pageRequests": 0 - }; - } - }, - - incrementTabCount(tab) { - this.initTabCounter(tab); - this.counters[tab.id].tab.pageRequests++; - this.counters[tab.id].activity.pageRequests++; - } -};