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

Update Linter & Remove Unsafe React Lifecycle Events #552

Closed
wants to merge 13 commits into from
Closed
Changes from 1 commit
Commits
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

finish linting for class-methods-use-this

  • Loading branch information
IAmThePan committed May 6, 2020
commit 5f3471ef6303743b58dcb8059065a89d9b4abc3a
@@ -72,7 +72,7 @@ const IS_FIREFOX = (BROWSER_INFO.name === 'firefox');
const VERSION_CHECK_URL = `${CDN_BASE_URL}/update/version`;
const REAL_ESTATE_ID = 'ghostery';
const onBeforeRequest = events.onBeforeRequest.bind(events);
const onHeadersReceived = events.onHeadersReceived.bind(events);
const { onHeadersReceived } = Events;

// Cliqz Modules
const moduleMock = {
@@ -1188,7 +1188,7 @@ function initialiseWebRequestPipeline() {
spec: 'collect',
before: existingSteps.onHeadersReceived,
fn: (state) => {
events.onHeadersReceived(state);
Events.onHeadersReceived(state);
return true;
}
})
@@ -1344,10 +1344,10 @@ function initializeEventListeners() {
chrome.webNavigation.onCommitted.addListener(events.onCommitted.bind(events));

// Fired when the page's DOM is fully constructed, but the referenced resources may not finish loading
chrome.webNavigation.onDOMContentLoaded.addListener(events.onDOMContentLoaded.bind(events));
chrome.webNavigation.onDOMContentLoaded.addListener(Events.onDOMContentLoaded.bind(events));

// Fired when a document, including the resources it refers to, is completely loaded and initialized
chrome.webNavigation.onCompleted.addListener(events.onNavigationCompleted.bind(events));
chrome.webNavigation.onCompleted.addListener(Events.onNavigationCompleted.bind(events));

// Fired when a new window, or a new tab in an existing window, is created to host a navigation.
// chrome.webNavigation.onCreatedNavigationTarget
@@ -1372,7 +1372,7 @@ function initializeEventListeners() {
// chrome.webRequest.onBeforeRequest

// Fires when a request is about to send headers
chrome.webRequest.onBeforeSendHeaders.addListener(events.onBeforeSendHeaders.bind(events), {
chrome.webRequest.onBeforeSendHeaders.addListener(Events.onBeforeSendHeaders.bind(events), {
urls: [
'https://l.ghostery.com/*',
'https://d.ghostery.com/*',
@@ -1400,17 +1400,17 @@ function initializeEventListeners() {
});

// Fires when a request could not be processed successfully
chrome.webRequest.onErrorOccurred.addListener(events.onRequestErrorOccurred.bind(events), {
chrome.webRequest.onErrorOccurred.addListener(Events.onRequestErrorOccurred.bind(events), {
urls: ['http://*/*', 'https://*/*']
});

/** * TABS ** */

// Fired when a new tab is created by user or internally
chrome.tabs.onCreated.addListener(events.onTabCreated.bind(events));
chrome.tabs.onCreated.addListener(Events.onTabCreated.bind(events));

// Fires when the active tab in a window changes
chrome.tabs.onActivated.addListener(events.onTabActivated.bind(events));
chrome.tabs.onActivated.addListener(Events.onTabActivated.bind(events));

// Fired when a tab is replaced with another tab due to prerendering
chrome.tabs.onReplaced.addListener(events.onTabReplaced.bind(events));
@@ -37,7 +37,7 @@ class BugDb extends Updatable {
* @param {Object} old_apps trackers in the original database
* @return {Object} list of all new trackers
*/
updateNewAppIds(new_apps, old_apps) {
static updateNewAppIds(new_apps, old_apps) {
log('updating newAppIds...');

const new_app_ids = difference(
@@ -54,7 +54,7 @@ class BugDb extends Updatable {
* Apply block to all new trackers
* @param {Object} new_app_ids list of new trackers
*/
applyBlockByDefault(new_app_ids) {
static applyBlockByDefault(new_app_ids) {
if (conf.block_by_default) {
log('applying block-by-default...');
const { selected_app_ids } = conf;
@@ -74,7 +74,7 @@ class BugDb extends Updatable {
* @param {Object} db bugs database object
* @return {array} array of categories
*/
_buildCategories(db) {
static _buildCategories(db) {
const selectedApps = conf.selected_app_ids || {};
let appId;
let category;
@@ -207,10 +207,10 @@ class BugDb extends Updatable {
// update newAppIds and apply block-by-default
if (old_bugs) {
if (Object.prototype.hasOwnProperty.call(old_bugs, 'version') && bugs.version > old_bugs.version) {
new_app_ids = this.updateNewAppIds(bugs.apps, old_bugs.apps);
new_app_ids = BugDb.updateNewAppIds(bugs.apps, old_bugs.apps);

if (new_app_ids.length) {
this.applyBlockByDefault(new_app_ids);
BugDb.applyBlockByDefault(new_app_ids);
db.JUST_UPDATED_WITH_NEW_TRACKERS = true;
}

@@ -221,10 +221,10 @@ class BugDb extends Updatable {
return memo;
}, {});

new_app_ids = this.updateNewAppIds(bugs.apps, old_apps);
new_app_ids = BugDb.updateNewAppIds(bugs.apps, old_apps);

if (new_app_ids.length) {
this.applyBlockByDefault(new_app_ids);
BugDb.applyBlockByDefault(new_app_ids);

// don't claim new trackers when db got downgraded by version
if (bugs.version > old_bugs.bugsVersion) {
@@ -237,7 +237,7 @@ class BugDb extends Updatable {
conf.bugs = bugs;
}

db.categories = this._buildCategories(db);
db.categories = BugDb._buildCategories(db);

this.db = db;

@@ -72,15 +72,15 @@ class EventHandlers {
log(`❤ ❤ ❤ Tab ${tabId} navigating to ${url} ❤ ❤ ❤`);

this._clearTabData(tabId);
this._resetNotifications();
EventHandlers._resetNotifications();
// TODO understand why this does not work when placed in the 'reload' branch in onCommitted
panelData.clearPageLoadTime(tabId);

// initialize tabInfo, foundBugs objects for this tab
tabInfo.create(tabId, url);
foundBugs.update(tabId);
button.update(tabId);
this._eventReset(details.tabId);
EventHandlers._eventReset(details.tabId);

// Workaround for foundBugs/tabInfo memory leak when the user triggers
// prefetching/prerendering but never loads the page. Wait two minutes
@@ -89,7 +89,7 @@ class EventHandlers {
utils.getTab(tabId, null, () => {
log('Clearing orphan tab data for tab', tabId);
this._clearTabData(tabId);
this._resetNotifications();
EventHandlers._resetNotifications();
});
}, 120000);
}
@@ -143,7 +143,7 @@ class EventHandlers {
*
* @param {Object} details event data
*/
onDOMContentLoaded(details) {
static onDOMContentLoaded(details) {
const tab_id = details.tabId;

// ignore if this is a sub-frame
@@ -280,7 +280,7 @@ class EventHandlers {
*
* @param {Object} details event data
*/
onNavigationCompleted(details) {
static onNavigationCompleted(details) {
if (!utils.isValidTopLevelNavigation(details)) {
return;
}
@@ -289,7 +289,7 @@ class EventHandlers {
log(`foundBugs: ${foundBugs.getAppsCount(details.tabId)}, tab_id: ${details.tabId}`);

// inject page_performance script to display page latency on Summary view
if (this._isValidUrl(utils.processUrl(details.url))) {
if (EventHandlers._isValidUrl(utils.processUrl(details.url))) {
utils.injectScript(details.tabId, 'dist/page_performance.js', '', 'document_idle').catch((err) => {
log('onNavigationCompleted injectScript error', err);
});
@@ -310,13 +310,13 @@ class EventHandlers {
// TODO what other webRequest-restricted pages are out there?
if (details.url.startsWith('https://chrome.google.com/webstore/')) {
this._clearTabData(tab_id);
this._resetNotifications();
EventHandlers._resetNotifications();
}

return;
}

this._eventReset(tab_id);
EventHandlers._eventReset(tab_id);
}

/**
@@ -362,7 +362,7 @@ class EventHandlers {
});
}

if (!this._checkRedirect(details.type, request_id)) {
if (!EventHandlers._checkRedirect(details.type, request_id)) {
return { cancel: false };
}

@@ -373,7 +373,7 @@ class EventHandlers {
/* ** SMART BLOCKING - Privacy ** */
// block HTTP request on HTTPS page
if (PolicySmartBlock.isInsecureRequest(tab_id, page_protocol, processed.scheme, processed.hostname)) {
return this._blockHelper(details, tab_id, null, null, request_id, from_redirect, true);
return EventHandlers._blockHelper(details, tab_id, null, null, request_id, from_redirect, true);
}

// TODO fuse this into a single call to improve performance
@@ -402,7 +402,7 @@ class EventHandlers {
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);
const { block, reason } = EventHandlers._checkBlocking(app_id, cat_id, tab_id, tab_host, page_url, request_id);
if (!block && reason === BLOCK_REASON_SS_UNBLOCKED) {
// The way to pass this flag to Cliqz handlers
details.ghosteryWhitelisted = true;
@@ -441,7 +441,7 @@ class EventHandlers {
}, 1);

if ((block && !smartUnblocked) || smartBlocked) {
return this._blockHelper(details, tab_id, app_id, bug_id, request_id, fromRedirect);
return EventHandlers._blockHelper(details, tab_id, app_id, bug_id, request_id, fromRedirect);
}

return { cancel: false };
@@ -454,7 +454,7 @@ class EventHandlers {
* @param {Object} d event data
* @return {Object} optionally return headers to send
*/
onBeforeSendHeaders(d) {
static onBeforeSendHeaders(d) {
const details = d;
for (let i = 0; i < details.requestHeaders.length; ++i) {
// Fetch requests in Firefox web-extension has a flaw. They attach
@@ -477,7 +477,7 @@ class EventHandlers {
*
* @param {Object} details event data
*/
onHeadersReceived(details) {
static onHeadersReceived(details) {
// Skip content-length collection if it's a 3XX (redirect)
if (details.statusCode >> 8 === 1) { } // eslint-disable-line
}
@@ -511,7 +511,7 @@ class EventHandlers {
if (!details || details.tabId <= 0) {
return;
}
this._clearRedirects(details.requestId);
EventHandlers._clearRedirects(details.requestId);

if (details.type !== 'main_frame') {
const appWithLatencyId = latency.logLatency(details);
@@ -529,9 +529,9 @@ class EventHandlers {
*
* @param {Object} details event data
*/
onRequestErrorOccurred(details) {
static onRequestErrorOccurred(details) {
latency.logLatency(details);
this._clearRedirects(details.requestId);
EventHandlers._clearRedirects(details.requestId);
}

/**
@@ -540,7 +540,7 @@ class EventHandlers {
*
* @param {Object} tab Details of the tab that was created
*/
onTabCreated(tab) {
static onTabCreated(tab) {
const { url } = tab;

metrics.handleBrokenPageTrigger(globals.BROKEN_PAGE_NEW_TAB, url);
@@ -552,9 +552,9 @@ class EventHandlers {
*
* @param {Object} activeInfo tab data
*/
onTabActivated(activeInfo) {
static onTabActivated(activeInfo) {
button.update(activeInfo.tabId);
this._resetNotifications();
EventHandlers._resetNotifications();
}

/**
@@ -586,7 +586,7 @@ class EventHandlers {
*/
onTabRemoved(tab_id) {
this._clearTabData(tab_id);
this._resetNotifications();
EventHandlers._resetNotifications();
}

/**
@@ -646,7 +646,7 @@ class EventHandlers {
* @param {boolean} fromRedirect
* @return {string|boolean}
*/
_blockHelper(details, tabId, appId, bugId, requestId, fromRedirect, upgradeInsecure) {
static _blockHelper(details, tabId, appId, bugId, requestId, fromRedirect, upgradeInsecure) {
if (upgradeInsecure) {
// attempt to redirect request to HTTPS. NOTE: Redirects from URLs
// with ws:// and wss:// schemes are ignored.
@@ -675,7 +675,7 @@ class EventHandlers {
if (details.type === 'script' && bugId) {
let code = '';
if (appId === 2575) { // Hubspot
code = this._getHubspotFormSurrogate(details.url);
code = EventHandlers._getHubspotFormSurrogate(details.url);
} else {
const ti = tabInfo.getTabInfo(tabId);
const surrogates = surrogatedb.getForTracker(details.url, appId, bugId, ti.host);
@@ -717,7 +717,7 @@ class EventHandlers {
* @param {URL} parsedURL
* @return {Boolean}
*/
_isValidUrl(parsedURL) {
static _isValidUrl(parsedURL) {
if (parsedURL && parsedURL.protocol.startsWith('http') && parsedURL.isValidHost() && !parsedURL.pathname.includes('_/chrome/newtab')) {
return true;
}
@@ -733,7 +733,7 @@ class EventHandlers {
* @param {string} form request url
* @return {string} surrogate code
*/
_getHubspotFormSurrogate(url) {
static _getHubspotFormSurrogate(url) {
// Hubspot url has a fixed format
// https://forms.hubspot.com/embed/v3/form/532040/95b5de3a-6d4a-4729-bebf-07c41268d773?callback=hs_reqwest_0&hutk=941df50e9277ee76755310cd78647a08
// The following three parameters are privacy-safe:
@@ -786,7 +786,7 @@ class EventHandlers {
*
* @param {number} requestId
*/
_clearRedirects(requestId) {
static _clearRedirects(requestId) {
globals.REDIRECT_MAP.delete(requestId);
globals.LET_REDIRECTS_THROUGH = false;
}
@@ -800,7 +800,7 @@ class EventHandlers {
* @param {number} request_id request id
* @return {boolean}
*/
_checkRedirect(type, request_id) {
static _checkRedirect(type, request_id) {
const fromRedirect = globals.REDIRECT_MAP.has(request_id);
// if the request is part of the main_frame and not a redirect, we don't proceed
if (type === 'main_frame' && !fromRedirect) {
@@ -829,7 +829,7 @@ class EventHandlers {
* @param {number} request_id request id
* @return {BlockWithReason} block result with reason
*/
_checkBlocking(app_id, cat_id, tab_id, tab_host, page_url, request_id) {
static _checkBlocking(app_id, cat_id, tab_id, tab_host, page_url, request_id) {
const fromRedirect = globals.REDIRECT_MAP.has(request_id);
let block;

@@ -851,7 +851,7 @@ class EventHandlers {
*
* @param {number} tab_id tab id
*/
_eventReset(tab_id) {
static _eventReset(tab_id) {
c2pDb.reset(tab_id);
globals.REDIRECT_MAP.clear();
globals.LET_REDIRECTS_THROUGH = false;
@@ -879,7 +879,7 @@ class EventHandlers {
* @private
*
*/
_resetNotifications() {
static _resetNotifications() {
globals.C2P_LOADED = globals.NOTIFICATIONS_LOADED = false; // eslint-disable-line no-multi-assign
}
}
@@ -30,7 +30,7 @@ const background = baseBackground({
});

class GhosteryModule extends Module {
get _module() {
static get _module() {
return background;
}
}
ProTip! Use n and p to navigate between commits in a pull request.