Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Tracker DB v4 endpoints #616

Merged
merged 10 commits into from Jan 5, 2021

leverage new trackerID property in bugs.json for WTM links

  • Loading branch information
christophertino committed Jan 5, 2021
commit 75487fcedc99dc95873689618c83f1378139fdea
@@ -33,7 +33,6 @@ class GlobalTracker extends React.Component {
description: '',
showMoreInfo: false,
showTrackerLearnMore: false,
wtmID: null,
};

// click bindings
@@ -64,7 +63,6 @@ class GlobalTracker extends React.Component {
const truncate = (data.description.length > 200) ? `${data.description.substr(0, 199)}...` : data.description;
this.setState({ description: truncate });
this.setState({ showTrackerLearnMore: true });
this.setState({ wtmID: data.id });
} else {
this.setState({ description: t('tracker_description_none_found') });
}
@@ -105,7 +103,6 @@ class GlobalTracker extends React.Component {
showMoreInfo,
description,
showTrackerLearnMore,
wtmID
} = this.state;
return (
<div className="global-blocking-trk">
@@ -125,7 +122,7 @@ class GlobalTracker extends React.Component {
{
showTrackerLearnMore && (
<div className={(!showTrackerLearnMore ? 'hide' : '')}>
<a target="_blank" rel="noopener noreferrer" title={tracker.name} href={`${globals.WTM_BASE_URL}/trackers/${encodeURIComponent(wtmID).toLowerCase()}.html`}>
<a target="_blank" rel="noopener noreferrer" title={tracker.name} href={`${globals.WTM_BASE_URL}/trackers/${encodeURIComponent(tracker.trackerID).toLowerCase()}.html`}>
{ t('tracker_description_learn_more') }
</a>
</div>
@@ -35,7 +35,6 @@ class Tracker extends React.Component {
showTrackerLearnMore: false,
trackerClasses: '',
warningImageTitle: '',
wtmID: null,
};

// click bindings
@@ -160,7 +159,6 @@ class Tracker extends React.Component {
const truncate = (data.description.length > 200) ? `${data.description.substr(0, 199)}...` : data.description;
this.setState({ description: truncate });
this.setState({ showTrackerLearnMore: true });
this.setState({ wtmID: data.id });
} else {
this.setState({ description: t('tracker_description_none_found') });
}
@@ -336,7 +334,6 @@ class Tracker extends React.Component {
warningImageTitle,
showMoreInfo,
showTrackerLearnMore,
wtmID,
} = this.state;

let sources;
@@ -402,7 +399,7 @@ class Tracker extends React.Component {
<div className="trk-description">
{description}
<div className={(!showTrackerLearnMore ? 'hide' : '')}>
<a target="_blank" rel="noopener noreferrer" title={tracker.name} href={`${globals.WTM_BASE_URL}/trackers/${encodeURIComponent(wtmID).toLowerCase()}.html`}>
<a target="_blank" rel="noopener noreferrer" title={tracker.name} href={`${globals.WTM_BASE_URL}/trackers/${encodeURIComponent(tracker.trackerID).toLowerCase()}.html`}>
{t('tracker_description_learn_more')}
</a>
</div>
@@ -2,23 +2,28 @@
"apps": {
"1": {
"name": "DoubleClick",
"cat": "advertising"
"cat": "advertising",
"trackerID": "doubleclick"
},
"2": {
"name": "Google Analytics",
"cat": "site_analytics"
"cat": "site_analytics",
"trackerID": "google_analytics"
},
"3": {
"name": "Google Safeframe",
"cat": "advertising"
"cat": "advertising",
"trackerID": "google_safeframe"
},
"4": {
"name": "Google IMA",
"cat": "advertising"
"cat": "advertising",
"trackerID": "google_ima"
},
"5": {
"name": "Google Publisher Tags",
"cat": "advertising"
"cat": "advertising",
"trackerID": "google_publisher_tags"
}
},
"bugs": {
@@ -118,6 +118,7 @@ class BugDb extends Updatable {
blocked,
shouldShow: true,
catId: category,
trackerID: db.apps[appId].trackerID,
});
}

@@ -638,11 +638,10 @@ class EventHandlers {
};
}
} else if (fromRedirect) {
buildRedirectC2P(globals.REDIRECT_MAP.get(requestId), appId).then((url) => {
setTimeout(() => {
chrome.tabs.update(details.tabId, { url });
}, 0);
});
const url = buildRedirectC2P(globals.REDIRECT_MAP.get(requestId), appId);
setTimeout(() => {
chrome.tabs.update(details.tabId, { url });
}, 0);
}
return {
// If true, the request is canceled. This prevents the request from being sent.
@@ -53,7 +53,8 @@ class FoundBugs {
* blocked: boolean,
* type: string,
* request_id: string
* }]
* }],
* trackerID: string
* }],
* appsMetadata: {
* appId: {
@@ -210,6 +211,7 @@ class FoundBugs {
cats_obj[cid].trackers.push({
id: appid,
name: db.apps[appid].name,
trackerID: db.apps[appid].trackerID,
blocked: bugs[id].blocked
});
if (bugs[id].blocked) {
@@ -227,6 +229,7 @@ class FoundBugs {
trackers: [{
id: appid,
name: db.apps[appid].name,
trackerID: db.apps[appid].trackerID,
blocked: bugs[id].blocked
}],
blocked: (bugs[id].blocked ? 1 : 0),
@@ -496,12 +499,13 @@ class FoundBugs {
appsMetadata[aid].needsCompatibilityCheck =
appsMetadata[aid].needsCompatibilityCheck && app.blocked;
} else {
const { name, cat } = db.apps[aid];
const { name, cat, trackerID } = db.apps[aid];

const apps_len = apps.push({
id: aid,
name,
cat,
trackerID,
blocked,
sources,
hasCompatibilityIssue: false,
@@ -704,6 +704,7 @@ class PanelData {
id,
name,
sources,
trackerID,
} = tracker;
const { blocked, ss_allowed, ss_blocked } = trackerState;

@@ -717,6 +718,7 @@ class PanelData {
shouldShow: true, // used for filtering tracker list
catId: cat,
sources,
trackerID,
warningCompatibility: hasCompatibilityIssue,
warningInsecure: hasInsecureIssue,
warningSlow: hasLatencyIssue,
@@ -19,12 +19,7 @@ import globals from '../classes/Globals';
import Policy from '../classes/Policy';
import tabInfo from '../classes/TabInfo';
import { log } from './common';
import {
sendMessage,
processUrl,
injectScript,
getJson
} from './utils';
import { sendMessage, processUrl, injectScript } from './utils';
import c2p_tpl from '../../app/templates/click2play.html';
import c2p_images from '../../app/data-images/click2play';

@@ -181,37 +176,30 @@ export function buildC2P(details, app_id) {
* @param {Object} redirectUrls original url and redirect url as properties
* @param {number} app_id tracker id
*
* @return {Promise} url of the internal template of the blocked redirect page
* @return {string} url of the internal template of the blocked redirect page
*/
export function buildRedirectC2P(redirectUrls, app_id) {
const host_url = processUrl(redirectUrls.url).hostname;
const redirect_url = processUrl(redirectUrls.redirectUrl).hostname;
const app_name = bugDb.db.apps[app_id].name;
const { name, trackerID } = bugDb.db.apps[app_id].trackerID;
const wtmURL = `${globals.WTM_BASE_URL}/trackers/${encodeURIComponent(trackerID).toLowerCase()}`;

globals.BLOCKED_REDIRECT_DATA = {};
globals.BLOCKED_REDIRECT_DATA.app_id = app_id;
globals.BLOCKED_REDIRECT_DATA.url = redirectUrls.redirectUrl;
globals.BLOCKED_REDIRECT_DATA.blacklisted = !!Policy.blacklisted(host_url);

return getJson(`${globals.WTM_BASE_URL}/data/trackers/ghostery/${app_id}.json`).catch(() => {
log('Tracker not found on whotracks.me');
}).then((data) => {
let wtmURL = globals.WTM_BASE_URL;
if (data && data.id) {
wtmURL += `/trackers/${encodeURIComponent(data.id).toLowerCase()}`;
}
globals.BLOCKED_REDIRECT_DATA.translations = {
blocked_redirect_page_title: t('blocked_redirect_page_title'),
blocked_redirect_prevent: t(
'blocked_redirect_prevent',
[host_url, redirect_url, app_name, wtmURL]
),
blocked_redirect_action_always_title: t('blocked_redirect_action_always_title'),
blocked_redirect_action_through_once_title: t('blocked_redirect_action_through_once_title'),
blocked_redirect_url_content: t('blocked_redirect_url_content', [redirectUrls.redirectUrl, app_name])
};
return chrome.extension.getURL('app/templates/blocked_redirect.html');
});
globals.BLOCKED_REDIRECT_DATA.translations = {
blocked_redirect_page_title: t('blocked_redirect_page_title'),
blocked_redirect_prevent: t(
'blocked_redirect_prevent',
[host_url, redirect_url, name, wtmURL]
),
blocked_redirect_action_always_title: t('blocked_redirect_action_always_title'),
blocked_redirect_action_through_once_title: t('blocked_redirect_action_through_once_title'),
blocked_redirect_url_content: t('blocked_redirect_url_content', [redirectUrls.redirectUrl, name])
};
return chrome.extension.getURL('app/templates/blocked_redirect.html');
}

/**
ProTip! Use n and p to navigate between commits in a pull request.