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

Commit

Permalink
Use https://firstParty/* instead of new content setting type
Browse files Browse the repository at this point in the history
  • Loading branch information
yrliou committed Apr 5, 2018
1 parent fab3d78 commit c9c33b7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
26 changes: 20 additions & 6 deletions app/background/api/shieldsAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ export const getShieldSettingsForTabData = (tabData?: chrome.tabs.Tab) => {
chrome.contentSettings.plugins.getAsync({ primaryUrl: origin, resourceIdentifier: { id: resourceIdentifiers.RESOURCE_IDENTIFIER_TRACKERS } }),
chrome.contentSettings.plugins.getAsync({ primaryUrl: origin, resourceIdentifier: { id: resourceIdentifiers.RESOURCE_IDENTIFIER_HTTP_UPGRADABLE_RESOURCES } }),
chrome.contentSettings.javascript.getAsync({ primaryUrl: origin }),
chrome.contentSettings.plugins.getAsync({ primaryUrl: origin, resourceIdentifier: { id: resourceIdentifiers.RESOURCE_IDENTIFIER_FINGERPRINTING } })
chrome.contentSettings.plugins.getAsync({ primaryUrl: origin, resourceIdentifier: { id: resourceIdentifiers.RESOURCE_IDENTIFIER_FINGERPRINTING } }),
chrome.contentSettings.plugins.getAsync({ primaryUrl: origin, secondaryUrl: 'https://firstParty/*', resourceIdentifier: { id: resourceIdentifiers.RESOURCE_IDENTIFIER_FINGERPRINTING } })
]).then((details) => {
const fingerprinting = details[5].setting !== details[6].setting ? 'block_third_party' : details[5].setting
return {
url: url.href,
origin,
Expand All @@ -38,7 +40,7 @@ export const getShieldSettingsForTabData = (tabData?: chrome.tabs.Tab) => {
trackers: details[2].setting,
httpUpgradableResources: details[3].setting,
javascript: details[4].setting,
fingerprinting: details[5].setting
fingerprinting
}
}).catch(() => {
return {
Expand Down Expand Up @@ -147,16 +149,28 @@ export const setAllowJavaScript = (origin: string, setting: string) =>
* Changes the fingerprinting at origin to be allowed or blocked.
* The fingerprinting-protection service will come into effect if the fingerprinting is marked as blocked.
* @param {string} origin the origin of the site to change the setting for
* @param {string} setting 'allow' or 'block' or 'block_third_party'
* @return a promise which resolves with the setting is set
*/
export const setAllowFingerprinting = (origin: string, setting: string) =>
chrome.contentSettings.plugins.setAsync({
export const setAllowFingerprinting = (origin: string, setting: string) => {
const originSetting = setting === 'allow' ? 'allow' : 'block'
const firstPartySetting = setting === 'block' ? 'block' : 'allow'

const p1 = chrome.contentSettings.plugins.setAsync({
primaryPattern: origin + '/*',
resourceIdentifier: { id: resourceIdentifiers.RESOURCE_IDENTIFIER_FINGERPRINTING },
setting
setting: originSetting
})

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

return Promise.all([p1, p2])
}

/**
* Toggles the input value between allow and block
* @return the toggled value
Expand Down
12 changes: 11 additions & 1 deletion test/app/background/api/shieldsAPITest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,23 @@ describe('Shields API', () => {
resourceIdentifier: { id: resourceIdentifiers.RESOURCE_IDENTIFIER_FINGERPRINTING },
setting: 'block'
})
const arg1 = this.spy.getCall(1).args[0]
assert.deepEqual(arg1, {
primaryPattern: 'https://www.brave.com/*',
secondaryPattern: 'https://firstParty/*',
resourceIdentifier: { id: resourceIdentifiers.RESOURCE_IDENTIFIER_FINGERPRINTING },
setting: 'block'
})
})
it('passes only 1 arg to chrome.contentSettings.plugins', function () {
assert.equal(this.spy.getCall(0).args.length, 1)
assert.equal(this.spy.getCall(1).args.length, 1)
})
it('resolves the returned promise', function (cb) {
this.p
.then(cb)
.then(function() {
cb()
})
.catch((e: Error) => {
console.error(e.toString())
})
Expand Down
2 changes: 1 addition & 1 deletion test/app/background/reducers/shieldsPanelReducerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ describe('braveShieldsPanelReducer', () => {
assert.deepEqual(
shieldsPanelReducer(state, {
type: types.BLOCK_FINGERPRINTING,
setting: 'allow',
setting: 'allow'
}), state)
assert.equal(this.setAllowFingerprintingSpy.withArgs(origin, 'allow').calledOnce, true)
})
Expand Down

0 comments on commit c9c33b7

Please sign in to comment.