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

Update JSDocs and update block reason c2p names.

  • Loading branch information
jsignanini committed Mar 23, 2018
commit b523b46a5e188ff5ca12c933dde65ea0641416c3
@@ -31,7 +31,9 @@ export const BLOCK_REASON_WHITELISTED = 'BLOCK_REASON_WHITELISTED';
export const BLOCK_REASON_BLACKLISTED = 'BLOCK_REASON_BLACKLISTED';
export const BLOCK_REASON_SS_UNBLOCKED = 'BLOCK_REASON_SS_UNBLOCKED';
export const BLOCK_REASON_SS_BLOCKED = 'BLOCK_REASON_SS_BLOCKED';
export const BLOCK_REASON_ALLOWED_ONCE = 'BLOCK_REASON_ALLOWED_ONCE';
export const BLOCK_REASON_C2P_ALLOWED_ONCE = 'BLOCK_REASON_C2P_ALLOWED_ONCE';
export const BLOCK_REASON_C2P_ALLOWED_THROUGH = 'BLOCK_REASON_C2P_ALLOWed_THROUGH';

/**
* Class for handling site policy.
* @memberOf BackgroundClasses
@@ -101,6 +103,12 @@ class Policy {
return false;
}

/**
* @typedef {Object} BlockWithReason
* @property {boolean} block indicates if the tracker should be blocked.
* @property {string} reason indicates the reason for the block result.
*/

/**
* Check the users blocking settings (selected_app_ids and site_specific_blocks/unblocks)
* to determine whether a tracker should be blocked
@@ -109,7 +117,7 @@ class Policy {
* @param {number} tab_id tab id
* @param {string} tab_host tab url host
* @param {string} tab_url tab url
* @return {Object} {block, ss_unblock}
* @return {BlockWithReason} block result with reason
*/
shouldBlock(app_id, cat_id, tab_id, tab_host, tab_url) {
if (globals.SESSION.paused_blocking) {
@@ -120,27 +128,27 @@ class Policy {
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)) {
const allowedOnce = c2pDb.allowedOnce(tab_id, app_id);
return { block: !allowedOnce, reason: allowedOnce ? BLOCK_REASON_ALLOWED_ONCE : BLOCK_REASON_BLACKLISTED };
return { block: !allowedOnce, reason: allowedOnce ? BLOCK_REASON_C2P_ALLOWED_ONCE : BLOCK_REASON_BLACKLISTED };
}
return { block: false, reason: BLOCK_REASON_SS_UNBLOCKED };
}
if (this.whitelisted(tab_url)) {
return { block: false, reason: BLOCK_REASON_WHITELISTED };
}
const allowedOnce = c2pDb.allowedOnce(tab_id, app_id);
return { block: !allowedOnce, reason: allowedOnce ? BLOCK_REASON_ALLOWED_ONCE : BLOCK_REASON_GLOBAL_BLOCKED };
return { block: !allowedOnce, reason: allowedOnce ? BLOCK_REASON_C2P_ALLOWED_ONCE : BLOCK_REASON_GLOBAL_BLOCKED };
}
// 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, reason: BLOCK_REASON_WHITELISTED };
}
const allowedOnce = c2pDb.allowedOnce(tab_id, app_id);
return { block: !allowedOnce, reason: allowedOnce ? BLOCK_REASON_ALLOWED_ONCE : BLOCK_REASON_SS_BLOCKED };
return { block: !allowedOnce, reason: allowedOnce ? BLOCK_REASON_C2P_ALLOWED_ONCE : BLOCK_REASON_SS_BLOCKED };
}
if (this.blacklisted(tab_url)) {
const allowedOnce = c2pDb.allowedOnce(tab_id, app_id);
return { block: !allowedOnce, reason: allowedOnce ? BLOCK_REASON_ALLOWED_ONCE : BLOCK_REASON_BLACKLISTED };
return { block: !allowedOnce, reason: allowedOnce ? BLOCK_REASON_C2P_ALLOWED_ONCE : BLOCK_REASON_BLACKLISTED };
}
return { block: false, reason: BLOCK_REASON_GLOBAL_BLOCKED };
}
ProTip! Use n and p to navigate between commits in a pull request.