Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Use ad-block data file version from ad-block lib
Browse files Browse the repository at this point in the history
This adds a new argument version, which if undefined it uses the old way
to get it.  We only currently specify a version explicitly from the
ad-block lib, otherwise we use the front-end config.

The lib knows best which version it is on. In this repo we had problems
because people switch between branches but don't npm install again.
With a fully C++ implementation this wouldn't have been seen.

Related: brave-experiments/ad-block@85e6b35

Fix #8489

Auditors: @SergeyZhukovsky
  • Loading branch information
bbondy committed Apr 26, 2017
1 parent eb24c95 commit be2f2d3
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
8 changes: 4 additions & 4 deletions app/adBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
'use strict'

const urlParse = require('./common/urlParse')
const {AdBlockClient} = require('ad-block')
const DataFile = require('./dataFile')
const {adBlockDataFileVersion, AdBlockClient} = require('ad-block')
const dataFile = require('./dataFile')
const Filtering = require('./filtering')
const appConfig = require('../js/constants/appConfig')
const debounce = require('../js/lib/debounce')
Expand Down Expand Up @@ -53,7 +53,7 @@ const startAdBlocking = (adblock, resourceName, shouldCheckMainFrame) => {
}

module.exports.initInstance = (adBlockClient, resourceName, shouldCheckMainFrame) => {
DataFile.init(resourceName, startAdBlocking.bind(null, adBlockClient, resourceName, shouldCheckMainFrame),
dataFile.init(resourceName, adBlockDataFileVersion, startAdBlocking.bind(null, adBlockClient, resourceName, shouldCheckMainFrame),
(data) => adBlockClient.deserialize(data))
return module.exports
}
Expand Down Expand Up @@ -87,7 +87,7 @@ const registerAppConfigForResource = (uuid, enabled, version) => {
* @param uuid - The uuid of the adblock datafile resource
* @param forAdblock - true if main frame URLs should be blocked
*/
module.exports.updateAdblockDataFiles = (uuid, enabled, version = Number(appConfig.adblock.version), shouldCheckMainFrame = false) => {
module.exports.updateAdblockDataFiles = (uuid, enabled, version = adBlockDataFileVersion, shouldCheckMainFrame = false) => {
registerAppConfigForResource(uuid, enabled, version)
if (!adblockInstances.has(uuid)) {
const adBlockClient = new AdBlockClient()
Expand Down
4 changes: 2 additions & 2 deletions app/dataFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ module.exports.shouldRedownloadFirst = (resourceName, version) => {
* Takes either the data itself as an argument or the pathname on disk of the
* directory where the data was downloaded.
*/
module.exports.init = (resourceName, startExtension, onInitDone, forceDownload) => {
const version = appConfig[resourceName].version
module.exports.init = (resourceName, version, startExtension, onInitDone, forceDownload) => {
version = version || appConfig[resourceName].version

let versionFolder = version
const hasStagedDatFile = [appConfig.resourceNames.ADBLOCK, appConfig.resourceNames.SAFE_BROWSING].includes(resourceName)
Expand Down
4 changes: 2 additions & 2 deletions app/httpsEverywhere.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
'use strict'

const urlParse = require('./common/urlParse')
const DataFile = require('./dataFile')
const dataFile = require('./dataFile')
const Filtering = require('./filtering')
const LRUCache = require('lru-cache')
const getHostnamePatterns = require('../js/lib/urlutil').getHostnamePatterns
Expand Down Expand Up @@ -203,5 +203,5 @@ function canonicalizeUrl (url) {
* Loads HTTPS Everywhere
*/
module.exports.init = () => {
DataFile.init(module.exports.resourceName, startHttpsEverywhere, loadRulesets)
dataFile.init(module.exports.resourceName, undefined, startHttpsEverywhere, loadRulesets)
}
6 changes: 3 additions & 3 deletions app/trackingProtection.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

const urlParse = require('./common/urlParse')
const TrackingProtection = require('tracking-protection').CTPParser
const DataFile = require('./dataFile')
const dataFile = require('./dataFile')
const Filtering = require('./filtering')
const isThirdPartyHost = require('./browser/isThirdPartyHost')
const LRUCache = require('lru-cache')
Expand Down Expand Up @@ -51,7 +51,7 @@ const startTrackingProtection = (wnd) => {
!cachedFirstParty.get(firstPartyUrlHost).find((baseHost) =>
!isThirdPartyHost(baseHost, urlHost))

DataFile.debug(module.exports.resourceName, details, cancel)
dataFile.debug(module.exports.resourceName, details, cancel)
return {
cancel,
resourceName: module.exports.resourceName
Expand All @@ -61,6 +61,6 @@ const startTrackingProtection = (wnd) => {

module.exports.init = () => {
trackingProtection = new TrackingProtection()
DataFile.init(module.exports.resourceName, startTrackingProtection,
dataFile.init(module.exports.resourceName, undefined, startTrackingProtection,
(data) => trackingProtection.deserialize(data))
}
5 changes: 2 additions & 3 deletions js/constants/appConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const adHost = process.env.AD_HOST || 'https://oip.brave.com'
const buildConfig = require('./buildConfig')
const isProduction = buildConfig.nodeEnv === 'production'
const {fullscreenOption} = require('../../app/common/constants/settingsEnums')
const ABPDatVersion = '3'

module.exports = {
name: 'Brave',
Expand Down Expand Up @@ -58,13 +57,13 @@ module.exports = {
adblock: {
alternateDataFiles: 'https://s3.amazonaws.com/adblock-data/{version}/{uuid}.dat',
url: 'https://s3.amazonaws.com/adblock-data/{version}/ABPFilterParserData.dat',
version: ABPDatVersion,
// version is specified in the ad-block library
msBetweenRechecks: 1000 * 60 * 60 * 2, // 2 hours
enabled: true
},
safeBrowsing: {
url: 'https://s3.amazonaws.com/adblock-data/{version}/SafeBrowsingData.dat',
version: ABPDatVersion,
// version is specified in the ad-block library
msBetweenRechecks: 1000 * 60 * 60 * 2, // 2 hours
enabled: true
},
Expand Down

0 comments on commit be2f2d3

Please sign in to comment.