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

Commit

Permalink
Add scope to methods which modify content settings
Browse files Browse the repository at this point in the history
  • Loading branch information
bsclifton committed Oct 1, 2018
1 parent c654fdc commit 26b44c3
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions app/background/api/shieldsAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export const getShieldSettingsForTabData = (tabData?: chrome.tabs.Tab) => {
})
}

const getScope = () =>
chrome.extension.inIncognitoContext ? 'incognito_session_only' : 'regular'

/**
* Obtains specified tab data
* @return a promise with the active tab data
Expand Down Expand Up @@ -93,7 +96,8 @@ export const setAllowBraveShields = (origin: string, setting: string) =>
chrome.braveShields.plugins.setAsync({
primaryPattern: origin.replace(/^(http|https):\/\//, '*://') + '/*',
resourceIdentifier: { id: resourceIdentifiers.RESOURCE_IDENTIFIER_BRAVE_SHIELDS },
setting
setting,
scope: getScope()
})

/**
Expand All @@ -107,7 +111,8 @@ export const setAllowAds = (origin: string, setting: string) =>
chrome.braveShields.plugins.setAsync({
primaryPattern: origin + '/*',
resourceIdentifier: { id: resourceIdentifiers.RESOURCE_IDENTIFIER_ADS },
setting
setting,
scope: getScope()
})

/**
Expand All @@ -121,7 +126,8 @@ export const setAllowTrackers = (origin: string, setting: string) =>
chrome.braveShields.plugins.setAsync({
primaryPattern: origin + '/*',
resourceIdentifier: { id: resourceIdentifiers.RESOURCE_IDENTIFIER_TRACKERS },
setting
setting,
scope: getScope()
})

/**
Expand All @@ -135,7 +141,8 @@ export const setAllowHTTPUpgradableResources = (origin: string, setting: BlockOp
return chrome.braveShields.plugins.setAsync({
primaryPattern,
resourceIdentifier: { id: resourceIdentifiers.RESOURCE_IDENTIFIER_HTTP_UPGRADABLE_RESOURCES },
setting
setting,
scope: getScope()
})
}

Expand All @@ -148,7 +155,8 @@ export const setAllowHTTPUpgradableResources = (origin: string, setting: BlockOp
export const setAllowJavaScript = (origin: string, setting: string) =>
chrome.braveShields.javascript.setAsync({
primaryPattern: origin + '/*',
setting
setting,
scope: getScope()
})

/**
Expand All @@ -164,14 +172,16 @@ export const setAllowFingerprinting = (origin: string, setting: string) => {
const p1 = chrome.braveShields.plugins.setAsync({
primaryPattern: origin + '/*',
resourceIdentifier: { id: resourceIdentifiers.RESOURCE_IDENTIFIER_FINGERPRINTING },
setting: originSetting
setting: originSetting,
scope: getScope()
})

const p2 = chrome.braveShields.plugins.setAsync({
primaryPattern: origin + '/*',
secondaryPattern: 'https://firstParty/*',
resourceIdentifier: { id: resourceIdentifiers.RESOURCE_IDENTIFIER_FINGERPRINTING },
setting: firstPartySetting
setting: firstPartySetting,
scope: getScope()
})

return Promise.all([p1, p2])
Expand All @@ -189,20 +199,23 @@ export const setAllowCookies = (origin: string, setting: string) => {
const p1 = chrome.braveShields.plugins.setAsync({
primaryPattern: origin + '/*',
resourceIdentifier: { id: resourceIdentifiers.RESOURCE_IDENTIFIER_REFERRERS },
setting: originSetting
setting: originSetting,
scope: getScope()
})

const p2 = chrome.braveShields.plugins.setAsync({
primaryPattern: origin + '/*',
resourceIdentifier: { id: resourceIdentifiers.RESOURCE_IDENTIFIER_COOKIES },
setting: originSetting
setting: originSetting,
scope: getScope()
})

const p3 = chrome.braveShields.plugins.setAsync({
primaryPattern: origin + '/*',
secondaryPattern: 'https://firstParty/*',
resourceIdentifier: { id: resourceIdentifiers.RESOURCE_IDENTIFIER_COOKIES },
setting: firstPartySetting
setting: firstPartySetting,
scope: getScope()
})

return Promise.all([p1, p2, p3])
Expand Down

0 comments on commit 26b44c3

Please sign in to comment.