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

Adding return after rejects in a few places. Implementing Ghostery side of GH-885. Fix for GH-871. #10

Merged
merged 10 commits into from Mar 23, 2018

Implementing suggested changes.

  • Loading branch information
Serge Zarembsky
Serge Zarembsky committed Mar 23, 2018
commit 61a1e5c88c9e6bcd48cf76eaef3023ef59541f2c
@@ -23,7 +23,7 @@ import conf from './Conf';
import foundBugs from './FoundBugs';
import globals from './Globals';
import latency from './Latency';
import Policy from './Policy';
import Policy, { BLOCK_REASON_SS_UNBLOCK } from './Policy';
import PolicySmartBlock from './PolicySmartBlock';
import PurpleBox from './PurpleBox';
import surrogatedb from './SurrogateDb';
@@ -372,24 +372,15 @@ class EventHandlers {
return { cancel: false };
}

let app_id;
let cat_id;
let incognito;
let tab_host;
let fromRedirect;
let block;
if (bug_id) {
app_id = bugDb.db.bugs[bug_id].aid;
cat_id = bugDb.db.apps[app_id].cat;
incognito = tabInfo.getTabInfo(tab_id, 'incognito');
tab_host = tabInfo.getTabInfo(tab_id, 'host');
fromRedirect = globals.REDIRECT_MAP.has(request_id);
const { block1, ss_unblock } = this._checkBlocking(app_id, cat_id, tab_id, tab_host, page_url, request_id);
block = block1;
if (ss_unblock) {
// The way to pass this flag to Cliqz handlers
details.ghosteryWhitelisted = true;
}
const app_id = bugDb.db.bugs[bug_id].aid;
const cat_id = bugDb.db.apps[app_id].cat;
const incognito = tabInfo.getTabInfo(tab_id, 'incognito');
const tab_host = tabInfo.getTabInfo(tab_id, 'host');
const fromRedirect = globals.REDIRECT_MAP.has(request_id);
const { block, reason } = this._checkBlocking(app_id, cat_id, tab_id, tab_host, page_url, request_id);
if (!block && reason === BLOCK_REASON_SS_UNBLOCK) {
// The way to pass this flag to Cliqz handlers
details.ghosteryWhitelisted = true;
}
// Latency initialization needs to be synchronous to avoid race condition with onCompleted, etc.
// TODO can URLs repeat within a redirect chain? what are the cases of repeating URLs (trackers only, ...)?
@@ -20,9 +20,18 @@ import conf from './Conf';
import { processUrl } from '../utils/utils';
import globals from './Globals';

const POLICY_BLOCK_NOTHING = 'POLICY_BLOCK_NOTHING';
const POLICY_BLOCK_EVERYTHING = 'POLICY_BLOCK_EVERYTHING';
const POLICY_BLOCK_ADS = 'POLICY_BLOCK_ADS';
/**
* Enum for reasons returned by shouldBlock
* @type {string}
* TBD: See if we can do with integer values for performance.
*/
export const BLOCK_REASON_PAUSED = 'BLOCK_REASON_PAUSED';
export const BLOCK_REASON_ALLOW_ONCE = 'BLOCK_REASON_ALLOW_ONCE';
export const BLOCK_REASON_BLACKLISTED = 'BLOCK_REASON_BLACKLISTED';
export const BLOCK_REASON_SS_UNBLOCK = 'BLOCK_REASON_SS_UNBLOCK';
export const BLOCK_REASON_WHITELISTED = 'BLOCK_REASON_WHITELISTED';
export const BLOCK_REASON_GLOBAL_BLOCKING = 'BLOCK_REASON_GLOBAL_BLOCKING';
export const BLOCK_REASON_SS_BLOCKED = 'BLOCK_REASON_SS_BLOCKED';
/**
* Class for handling site policy.
* @memberOf BackgroundClasses
@@ -104,39 +113,35 @@ class Policy {
*/
shouldBlock(app_id, cat_id, tab_id, tab_host, tab_url) {
if (globals.SESSION.paused_blocking) {
return { block: false, ss_unblock: false };
}

const ss_unblock = conf.toggle_individual_trackers && conf.site_specific_unblocks.hasOwnProperty(tab_host) && conf.site_specific_unblocks[tab_host].includes(+app_id);

if (ss_unblock && !this.blacklisted(tab_url) && !this.whitelisted(tab_url)) {
return { block: false, ss_unblock: true };
return { block: false, reason: BLOCK_REASON_PAUSED };
}

const allowedOnce = c2pDb.allowedOnce(tab_id, app_id);
if (conf.selected_app_ids.hasOwnProperty(app_id)) {
if (ss_unblock) {
if (conf.toggle_individual_trackers && conf.site_specific_unblocks.hasOwnProperty(tab_host) && conf.site_specific_unblocks[tab_host].includes(+app_id)) {
if (this.blacklisted(tab_url)) {
return { block: !c2pDb.allowedOnce(tab_id, app_id), ss_unblock: false };
return { block: !allowedOnce, reason: allowedOnce ? BLOCK_REASON_ALLOW_ONCE : BLOCK_REASON_BLACKLISTED };
}
return { block: false, ss_unblock: false };
return { block: false, reason: BLOCK_REASON_SS_UNBLOCK };
}
if (this.whitelisted(tab_url)) {
return { block: false, ss_unblock: false };
return { block: false, reason: BLOCK_REASON_WHITELISTED };
}
return { block: !c2pDb.allowedOnce(tab_id, app_id), ss_unblock: false };
return { block: !allowedOnce, reason: allowedOnce ? BLOCK_REASON_ALLOW_ONCE : BLOCK_REASON_GLOBAL_BLOCKING };
}
// We get here when app_id is not selected for blocking
if (conf.toggle_individual_trackers && conf.site_specific_blocks.hasOwnProperty(tab_host) && conf.site_specific_blocks[tab_host].includes(+app_id)) {
if (this.whitelisted(tab_url)) {
return { block: false, ss_unblock: false };
return { block: false, reason: BLOCK_REASON_WHITELISTED };
}
return { block: !c2pDb.allowedOnce(tab_id, app_id), ss_unblock: false };
return { block: !allowedOnce, reason: allowedOnce ? BLOCK_REASON_ALLOW_ONCE : BLOCK_REASON_SS_BLOCKED };
}
if (this.blacklisted(tab_url)) {
return { block: !c2pDb.allowedOnce(tab_id, app_id), ss_unblock: false };
return { block: !allowedOnce, reason: allowedOnce ? BLOCK_REASON_ALLOW_ONCE : BLOCK_REASON_BLACKLISTED };
}
return { block: false, ss_unblock: false };
return { block: false, reason: BLOCK_REASON_GLOBAL_BLOCKING };
}
}

export default Policy;

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