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

GH-1566 - Smart blocking should check for Click2Play #388

Merged
merged 9 commits into from Jun 11, 2019

Implement c2p allow once for lazy loading trackers.

  • Loading branch information
jsignanini committed Jun 11, 2019
commit 50dc5a10742985bdf51cc849f05dbe527a15b300
@@ -49,9 +49,7 @@
<p id="text"><%= data.click2play_text %></p>
<% } %>
<img id="ghostery-blocked" src="<%= data.ghostery_blocked_src %>" title="<%= data.ghostery_blocked_title %>">
<% if (data.smartBlocked === false) { %>
<a id="action-once" href="#" onclick="return false"><img src="<%= data.allow_once_src %>" title="<%= data.allow_once_title %>"></a>
<% } %>
<a id="action-once" href="#" onclick="return false"><img src="<%= data.allow_once_src %>" title="<%= data.allow_once_title %>"></a>
<% if (data.blacklisted === false) { %>
<a id="action-always" href="#" onclick="return false"><img src="<%= data.allow_always_src %>" title="<%= data.allow_always_title %>"></a>
<% } %>
@@ -66,18 +66,35 @@ class Click2PlayDb extends Updatable {

// TODO memory leak when you close tabs before reset() can run?
reset(tab_id) {
delete this.allowOnceList[tab_id];
if (!this.allowOnceList.hasOwnProperty(tab_id)) { return; }

const entries = Object.entries(this.allowOnceList[tab_id]);
let keep = false;
for (const [appID, count] of entries) {
const newCount = count - 1;
this.allowOnceList[tab_id][appID] = newCount;
if (newCount > 0) {
keep = true;
}
}
if (!keep) {
delete this.allowOnceList[tab_id];
}
}

allowedOnce(tab_id, aid) {
return this.allowOnceList.hasOwnProperty(tab_id) && this.allowOnceList[tab_id].hasOwnProperty(aid);
return (
this.allowOnceList.hasOwnProperty(tab_id) &&
this.allowOnceList[tab_id].hasOwnProperty(aid) &&
this.allowOnceList[tab_id][aid] > 0
);
}

allowOnce(app_ids, tab_id) {
this.allowOnceList[tab_id] = {};

app_ids.forEach((app_id) => {
this.allowOnceList[tab_id][app_id] = 1;
this.allowOnceList[tab_id][app_id] = 2;
});
}

@@ -78,6 +78,7 @@ class EventHandlers {
tabInfo.create(tabId, url);
foundBugs.update(tabId);
button.update(tabId);
this._eventReset(details.tabId);

// Workaround for foundBugs/tabInfo memory leak when the user triggers
// prefetching/prerendering but never loads the page. Wait two minutes
@@ -292,11 +293,6 @@ class EventHandlers {
log('onNavigationCompleted injectScript error', err);
});
}
// Requests may continue well after onNavigationCompleted, which breaks
// C2P's "allow once" feature because the allowOnceList is cleared too early
setTimeout(() => {
this._eventReset(details.tabId);
}, 5000); // match THRESHHOLD value in PolicySmartBlock._requestWasSlow()
}

/**
@@ -43,7 +43,7 @@ const policy = new Policy();
* @param {number} app_id tracker id
*/
export function buildC2P(details, app_id) {
const { tab_id, smartBlocked } = details;
const { tab_id } = details;
let c2pApp = c2pDb.db.apps && c2pDb.db.apps[app_id];

if (!c2pApp) {
@@ -67,7 +67,6 @@ export function buildC2P(details, app_id) {
c2pApp.forEach((c2pAppDef) => {
const tplData = {
blacklisted, // if the site is blacklisted, don't show allow_always button
smartBlocked, // if the app has been Smart Blocked, don't show allow_once (see comment block)
button: !!c2pAppDef.button,
ghostery_blocked_src: c2p_images.ghosty_blocked,
allow_always_src: c2p_images.allow_unblock,
ProTip! Use n and p to navigate between commits in a pull request.