diff --git a/README.md b/README.md index 3f5ab934f..b3b969270 100644 --- a/README.md +++ b/README.md @@ -157,7 +157,7 @@ See [CONTRIBUTING](CONTRIBUTING.md) and [CODE OF CONDUCT](CODE-OF-CONDUCT.md) ## Links + [Website](https://ghostery.com/) -+ [Support](mailto:support@ghostery.com) ++ [Support](https://ghostery.com/support) + [Twitter (@ghostery)](https://twitter.com/ghostery) + [Facebook](https://www.facebook.com/ghostery) + [Privacy Policy](https://www.ghostery.com/about-ghostery/browser-extension-privacy-policy/) diff --git a/src/background.js b/src/background.js index 213aca689..423a41ba0 100644 --- a/src/background.js +++ b/src/background.js @@ -49,7 +49,7 @@ import * as common from './utils/common'; import * as utils from './utils/utils'; import { _getJSONAPIErrorsObject } from './utils/api'; import { importCliqzSettings } from './utils/cliqzSettingImport'; -import { sendCliqzModulesData } from './utils/cliqzModulesData'; +import { sendCliqzModuleCounts } from './utils/cliqzModulesData'; // For debug purposes, provide Access to the internals of `browser-core` // module from Developer Tools Console. @@ -841,12 +841,12 @@ function onMessageHandler(request, sender, callback) { callback(); return false; } - if (name === 'getCliqzModuleData') { + if (name === 'getCliqzModuleData') { // panel-android only if (message && message.tabId) { - sendCliqzModulesData(message.tabId, callback); + sendCliqzModuleCounts(message.tabId, callback); } else { utils.getActiveTab((tab) => { - sendCliqzModulesData(tab.id, callback); + sendCliqzModuleCounts(tab.id, callback); }); } return true; @@ -953,7 +953,7 @@ function onMessageHandler(request, sender, callback) { if (name === 'account.openSupportPage') { metrics.ping('priority_support_submit'); const subscriber = account.hasScopesUnverified(['subscriptions:plus']); - const tabUrl = subscriber ? `https://account.${globals.GHOSTERY_DOMAIN}.com/support` : 'https://www.ghostery.com/faqs/'; + const tabUrl = subscriber ? `https://account.${globals.GHOSTERY_DOMAIN}.com/support` : 'https://www.ghostery.com/support/'; utils.openNewTab({ url: tabUrl, become_active: true }); return false; } diff --git a/src/classes/BrowserButton.js b/src/classes/BrowserButton.js index 028c1a4eb..ffdc820aa 100644 --- a/src/classes/BrowserButton.js +++ b/src/classes/BrowserButton.js @@ -17,7 +17,7 @@ import conf from './Conf'; import foundBugs from './FoundBugs'; import rewards from './Rewards'; import Policy from './Policy'; -import { getCliqzAntitrackingData, getCliqzAdblockingData } from '../utils/cliqzModulesData'; +import { getCliqzAntiTrackingCount, getCliqzAdBlockingCount } from '../utils/cliqzModulesData'; import { getTab } from '../utils/utils'; import { log } from '../utils/common'; import globals from './Globals'; @@ -144,20 +144,19 @@ class BrowserButton { return; } - getCliqzAntitrackingData(tabId).then((antitrackingData) => { - const { appsCount, appsAlertCount } = this._getTrackerCount(tabId); - const adBlockingCount = getCliqzAdblockingData(tabId).totalCount; + const { appsCount, appsAlertCount } = this._getTrackerCount(tabId); + const adBlockingCount = getCliqzAdBlockingCount(tabId).totalCount; + const antiTrackingCount = getCliqzAntiTrackingCount(tabId).totalUnsafeCount; - alert = (appsAlertCount > 0); - trackerCount = (appsCount + antitrackingData.totalUnsafeCount + adBlockingCount).toString(); + alert = (appsAlertCount > 0); + trackerCount = (appsCount + antiTrackingCount + adBlockingCount).toString(); - // gray-out the icon when blocking has been disabled for whatever reason - if (trackerCount === '') { - this._setIcon(false, tabId, trackerCount, alert); - } else { - this._setIcon(!globals.SESSION.paused_blocking && !this.policy.whitelisted(tab.url), tabId, trackerCount, alert); - } - }); + // gray-out the icon when blocking has been disabled for whatever reason + if (trackerCount === '') { + this._setIcon(false, tabId, trackerCount, alert); + } else { + this._setIcon(!globals.SESSION.paused_blocking && !this.policy.whitelisted(tab.url), tabId, trackerCount, alert); + } } /** diff --git a/src/classes/PanelData.js b/src/classes/PanelData.js index c0f50576e..b84c929cb 100644 --- a/src/classes/PanelData.js +++ b/src/classes/PanelData.js @@ -26,7 +26,7 @@ import tabInfo from './TabInfo'; import rewards from './Rewards'; import account from './Account'; import dispatcher from './Dispatcher'; -import { getCliqzGhosteryStats, sendCliqzModulesData } from '../utils/cliqzModulesData'; +import { getCliqzGhosteryBugs, sendCliqzModuleCounts } from '../utils/cliqzModulesData'; import { getActiveTab, flushChromeMemoryCache, processUrl } from '../utils/utils'; import { objectEntries, log } from '../utils/common'; @@ -206,7 +206,7 @@ class PanelData { } /** - * Wrapper helper passed as callback to utils/cliqzModuleData#sendCliqzModulesData + * Wrapper helper passed as callback to utils/cliqzModuleData#sendCliqzModuleCounts */ postMessageToSummary = ((message) => { this._postMessage('summary', message); @@ -545,12 +545,12 @@ class PanelData { } /** - * Retrieves antitracking and adblock Cliqz data and sends it to the panel + * Retrieves antitracking and adblock counts and sends it to the panel */ _postCliqzModulesData() { if (!this._panelPort || !this._activeTab) { return; } - sendCliqzModulesData(this._activeTab.id, this.postMessageToSummary); + sendCliqzModuleCounts(this._activeTab.id, this.postMessageToSummary); } /** @@ -830,23 +830,23 @@ class PanelData { this._trackerList = foundBugs.getApps(id, false, url) || []; - const ghosteryStats = getCliqzGhosteryStats(id); + const ghosteryBugs = getCliqzGhosteryBugs(id); - if (ghosteryStats && ghosteryStats.bugs) { - const gsBugs = ghosteryStats.bugs; - const bugsIds = Object.keys(gsBugs); + if (ghosteryBugs && ghosteryBugs.bugs) { + const { bugs } = ghosteryBugs; + const bugIds = Object.keys(bugs); const appsById = foundBugs.getAppsById(id); - bugsIds.forEach((bugsId) => { + bugIds.forEach((bugsId) => { const trackerId = conf.bugs.bugs[bugsId]; if (!trackerId) return; const trackerListIndex = appsById[trackerId.aid]; if (!trackerListIndex) return; - this._trackerList[trackerListIndex].cliqzCookieCount = gsBugs[bugsId].cookies; - this._trackerList[trackerListIndex].cliqzFingerprintCount = gsBugs[bugsId].fingerprints; - this._trackerList[trackerListIndex].cliqzAdCount = gsBugs[bugsId].ads; + this._trackerList[trackerListIndex].cliqzCookieCount = bugs[bugsId].cookies; + this._trackerList[trackerListIndex].cliqzFingerprintCount = bugs[bugsId].fingerprints; + this._trackerList[trackerListIndex].cliqzAdCount = bugs[bugsId].ads; }); } diff --git a/src/utils/cliqzModulesData.js b/src/utils/cliqzModulesData.js index 46e6485c9..b22974133 100644 --- a/src/utils/cliqzModulesData.js +++ b/src/utils/cliqzModulesData.js @@ -12,96 +12,90 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0 */ +// @namespace BackgroundUtils + +import { extend } from 'underscore'; import conf from '../classes/Conf'; import cliqz from '../classes/Cliqz'; const { adblocker, antitracking } = cliqz.modules; -export function getCliqzAntitrackingData(tabId) { - return new Promise((resolve) => { - if (!conf.enable_anti_tracking || !antitracking.background) { - resolve({ - totalUnsafeCount: 0 - }); - } +/** + * Get the totalUnsafeCount of trackers found by Anti-Tracking on this tabId + * @memberOf BackgroundUtils + * @param {int} tabId + * @return {object} totalUnsafeCount + */ +export function getCliqzAntiTrackingCount(tabId) { + let count = 0; + if (!conf.enable_anti_tracking || !antitracking.background) { + return { + totalUnsafeCount: count + }; + } + + // Count up number of fingerprints and cookies found + const { bugs, others } = antitracking.background.actions.getGhosteryStats(tabId); + const allStats = Object.assign({}, bugs, others); + const values = Object.values(allStats); + + for (const val of values) { + count += val.cookies + val.fingerprints; + } - antitracking.background.actions.aggregatedBlockingStats(tabId).then((antitrackingData) => { - let totalUnsafeCount = 0; - for (const category in antitrackingData) { - if (antitrackingData.hasOwnProperty(category)) { - for (const app in antitrackingData[category]) { - if (antitrackingData[category][app] === 'unsafe') { - totalUnsafeCount++; - } - } - } - } - antitrackingData.totalUnsafeCount = totalUnsafeCount; - resolve(antitrackingData); - }).catch(() => { - resolve({ - totalUnsafeCount: 0 - }); - }); - }); + return { + totalUnsafeCount: count + }; } -export function getCliqzAdblockingData(tabId) { +/** + * Get the totalCount of ads found by the Ad Blocker on this tabId + * @memberOf BackgroundUtils + * @param {int} tabId + * @return {object} + */ +export function getCliqzAdBlockingCount(tabId) { if (!conf.enable_ad_block || !adblocker.background) { return { totalCount: 0 }; } - const adBlocking = adblocker.background.actions.getAdBlockInfoForTab(tabId); - return adBlocking || { totalCount: 0 }; + const adBlockInfo = adblocker.background.actions.getAdBlockInfoForTab(tabId); + return { + totalCount: adBlockInfo.totalCount || 0, + }; } /** - * TODO: Add a test that verifies the following structure so that we automatically know if Cliqz changes it and we need to updated it - The returned object has the following structure: - { - bugs: { - 4147: { cookies: 3, fingerprints: 4, ads: 0 }, - another_bug_id: { cookies: 2, ..... - .... - }, - others: { - CloudFlare: { - ads: 0, - cat: "cdn", - cookies: 3, - domains: ["cdnjs.cloudlare.com", ...], - fingerprints: 4, - name: "CloudFlare", - wtm: "cloudflare", - }, - ... - } - } + * Get list of matched bug_ids from Anti-Tracking and Ad-Blocking for this + * tab, along with list of 'other' trackers found that do not match known bug_ids. + * @memberOf BackgroundUtils + * @param {int} tabId + * @return {object} */ -export function getCliqzGhosteryStats(tabId) { - if (!conf.enable_anti_tracking) { - return { - bugs: {}, - others: {}, - }; - } +export function getCliqzGhosteryBugs(tabId) { + // Merge Ad-Block stats into Anti-Track Stats + const antiTrackingStats = (conf.enable_anti_tracking) ? antitracking.background.actions.getGhosteryStats(tabId) : { bugs: {}, others: {} }; + const adBlockingStats = (conf.enable_ad_block) ? adblocker.background.actions.getGhosteryStats(tabId) : { bugs: {}, others: {} }; - const ghosteryStats = antitracking.background.actions.getGhosteryStats(tabId); - return ghosteryStats; + return { + bugs: extend({}, antiTrackingStats.bugs, adBlockingStats.bugs), + others: extend({}, antiTrackingStats.others, adBlockingStats.others), + }; } -export function sendCliqzModulesData(tabId, callback) { +/** + * Send `totalCount` of ads found by Ad Blocker and `totalUnsafeCount` + * found by Anti-Tracking + * @memberOf BackgroundUtils + * @param {int} tabId + * @param {Function} callback + */ +export function sendCliqzModuleCounts(tabId, callback) { const modules = { adblock: {}, antitracking: {} }; - modules.adblock = getCliqzAdblockingData(tabId); - - // TODO convert to use finally to avoid duplication (does our Babel transpile it?) - getCliqzAntitrackingData(tabId).then((antitrackingData) => { - modules.antitracking = antitrackingData; - callback(modules); - }).catch(() => { - callback(modules); - }); + modules.adblock = getCliqzAdBlockingCount(tabId); + modules.antitracking = getCliqzAntiTrackingCount(tabId); + callback(modules); }