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-2188 - Adjustments for Ghostery Browser #622

Merged
merged 5 commits into from Oct 26, 2020
Merged
Changes from 1 commit
Commits
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

use deferred promises to wait for getBrowserInfo()

  • Loading branch information
christophertino committed Oct 26, 2020
commit 25f945d607d87bb9001b455f9b89c43aa248a01a
@@ -21,6 +21,8 @@ import ghosteryDebugger from './classes/Debugger';
// object classes
import Events from './classes/EventHandlers';
import Policy from './classes/Policy';
import Rewards from './classes/Rewards';
import GhosteryModule from './classes/Module';
// static classes
import panelData from './classes/PanelData';
import bugDb from './classes/BugDb';
@@ -37,11 +39,8 @@ import globals from './classes/Globals';
import surrogatedb from './classes/SurrogateDb';
import tabInfo from './classes/TabInfo';
import metrics from './classes/Metrics';
import Rewards from './classes/Rewards';
import account from './classes/Account';
import GhosteryModule from './classes/Module';
import promoModals from './classes/PromoModals';

// utilities
import { allowAllwaysC2P } from './utils/click2play';
import * as common from './utils/common';
@@ -1648,18 +1647,22 @@ function initializeGhosteryModules() {
conf.enable_ad_block = !adblocker.isDisabled;
conf.enable_anti_tracking = !antitracking.isDisabled;
conf.enable_human_web = !humanweb.isDisabled;
conf.enable_offers = !offers.isDisabled && !IS_ANDROID && BROWSER_INFO.name !== 'ghostery_desktop';

if (IS_FIREFOX && BROWSER_INFO.name !== 'ghostery_desktop' && BROWSER_INFO.name !== 'ghostery_android') {
if (globals.JUST_INSTALLED) {
conf.enable_human_web = false;
conf.enable_offers = false;
} else if (globals.REQUIRE_LEGACY_OPT_IN && !conf.cliqz_legacy_opt_in) {
conf.enable_human_web = false;
conf.enable_offers = cliqz.prefs.get('myoffrz.opted_in') || false;
conf.cliqz_legacy_opt_in = true;
// Make sure that getBrowserInfo() has resolved before we set these properties
(async() => {
await globals.BROWSER_INFO_READY;
conf.enable_offers = !offers.isDisabled && !IS_ANDROID && BROWSER_INFO.name !== 'ghostery_desktop';
if (IS_FIREFOX && BROWSER_INFO.name !== 'ghostery_desktop' && BROWSER_INFO.name !== 'ghostery_android') {
if (globals.JUST_INSTALLED) {
conf.enable_human_web = false;
conf.enable_offers = false;
} else if (globals.REQUIRE_LEGACY_OPT_IN && !conf.cliqz_legacy_opt_in) {
conf.enable_human_web = false;
conf.enable_offers = cliqz.prefs.get('myoffrz.opted_in') || false;
conf.cliqz_legacy_opt_in = true;
}
}
}
})();

const myoffrzShouldMigrate = conf.rewards_opted_in !== undefined && cliqz.prefs.get('myoffrz.opted_in', undefined) === undefined;
if (myoffrzShouldMigrate) {
@@ -93,6 +93,13 @@ class ConfData {
_initProperty('trackers_banner_status', true);
}

// Make sure that getBrowserInfo() has resolved before we set these properties
(async() => {
await globals.BROWSER_INFO_READY;
_initProperty('enable_metrics', BROWSER_INFO.name === 'ghostery_desktop');
_initProperty('enable_offers', !IS_CLIQZ && !IS_FIREFOX && !IS_ANDROID && BROWSER_INFO.name !== 'ghostery_desktop');
})();

// simple props
_initProperty('alert_bubble_pos', 'br');
_initProperty('alert_bubble_timeout', 15);
@@ -111,8 +118,6 @@ class ConfData {
_initProperty('enable_click2play', true);
_initProperty('enable_click2play_social', true);
_initProperty('enable_human_web', !IS_CLIQZ && !IS_FIREFOX);
_initProperty('enable_metrics', BROWSER_INFO.name === 'ghostery_desktop');
_initProperty('enable_offers', !IS_CLIQZ && !IS_FIREFOX && !IS_ANDROID && BROWSER_INFO.name !== 'ghostery_desktop');
_initProperty('enable_abtests', true);
_initProperty('enable_smart_block', true);
_initProperty('expand_all_trackers', true);
@@ -0,0 +1,27 @@
/**
* Deferred Promise
*
* Used to resolve a Promise outside of its function scope
*
* Ghostery Browser Extension
* https://www.ghostery.com/
*
* Copyright 2020 Ghostery, Inc. All rights reserved.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0
*/

class Deferred {
constructor() {
this.promise = new Promise((resolve, reject) => {
this.resolve = resolve;
this.reject = reject;
});
this.then = this.promise.then.bind(this.promise);
this.catch = this.promise.catch.bind(this.promise);
}
}

export default Deferred;
@@ -14,13 +14,14 @@
*/

import parser from 'ua-parser-js';
import Deferred from './Deferred';

const manifest = chrome.runtime.getManifest();
const isCliqzBrowser = !!(chrome.runtime.isCliqz);

/**
* Structure which holds parameters to be used throughout the code, a.k.a. global values.
* Most of them (but not all) are const.
* Most of them (but not all) are constants.
* @memberOf BackgroundClasses
*/
class Globals {
@@ -32,6 +33,7 @@ class Globals {
this.BROWSER_INFO = {
displayName: '', name: '', token: '', version: '', os: 'other'
};
this.BROWSER_INFO_READY = new Deferred();
this.IS_CLIQZ = !!((manifest.applications && manifest.applications.gecko && manifest.applications.gecko.update_url) || isCliqzBrowser);

// flags
@@ -189,35 +191,36 @@ class Globals {
this.BROWSER_INFO.version = version;

// Check for Ghostery browsers
if (browser.includes('firefox') || browser.includes('mozilla')) {
Globals._checkBrowserInfo().then((info) => {
if (info.name === 'Ghostery') {
if (platform.includes('android')) {
this.BROWSER_INFO.displayName = 'Ghostery Android Browser';
this.BROWSER_INFO.name = 'ghostery_android';
this.BROWSER_INFO.token = 'ga';
this.BROWSER_INFO.os = 'android';
} else {
this.BROWSER_INFO.displayName = 'Ghostery Desktop Browser';
this.BROWSER_INFO.name = 'ghostery_desktop';
this.BROWSER_INFO.token = 'gd';
}
this.BROWSER_INFO.version = info.version;
this._checkBrowserInfo().then((info) => {
if (info && info.name === 'Ghostery') {
if (platform.includes('android')) {
this.BROWSER_INFO.displayName = 'Ghostery Android Browser';
this.BROWSER_INFO.name = 'ghostery_android';
this.BROWSER_INFO.token = 'ga';
this.BROWSER_INFO.os = 'android';
} else {
this.BROWSER_INFO.displayName = 'Ghostery Desktop Browser';
this.BROWSER_INFO.name = 'ghostery_desktop';
this.BROWSER_INFO.token = 'gd';
}
});
}
this.BROWSER_INFO.version = info.version;
}
});
}

/**
* Check for information about this browser
* Note: This is asynchronous and not available at runtime.
* Check for information about this browser (FF only)
* @private
* @return boolean
* @return Promise
*/
static _checkBrowserInfo() {
_checkBrowserInfo() {
if (typeof chrome.runtime.getBrowserInfo === 'function') {
return chrome.runtime.getBrowserInfo();
return chrome.runtime.getBrowserInfo().then((data) => {
this.BROWSER_INFO_READY.resolve(true);
return data;
});
}
this.BROWSER_INFO_READY.resolve(false);
return Promise.resolve(false);
}
}
ProTip! Use n and p to navigate between commits in a pull request.