This repository has been archived by the owner on Dec 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #168 from mozilla/privacy-controls
#72: Disable extraction in private browsing sessions.
- Loading branch information
Showing
5 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* 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/. */ | ||
|
||
/** | ||
* Handles checking privacy settings to gate functionality across the add-on. | ||
* @module | ||
*/ | ||
|
||
/** | ||
* Determine if a content script should extract a product. | ||
* @return {boolean} | ||
*/ | ||
export async function shouldExtract() { | ||
return !browser.extension.inIncognitoContext; | ||
} | ||
|
||
/** | ||
* Determine if a telemetry event should be recorded | ||
* @return {boolean} | ||
*/ | ||
export async function shouldCollectTelemetry() { | ||
if (await trackingProtectionEnabled()) { | ||
return false; | ||
} | ||
|
||
if (doNotTrackEnabled()) { | ||
return false; | ||
} | ||
|
||
if (await cookiesBlocked()) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Determine if a background price update should start | ||
* @return {boolean} | ||
*/ | ||
export async function shouldUpdatePrices() { | ||
if (await trackingProtectionEnabled()) { | ||
return false; | ||
} | ||
|
||
if (doNotTrackEnabled()) { | ||
return false; | ||
} | ||
|
||
if (await cookiesBlocked()) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
async function trackingProtectionEnabled() { | ||
const result = await browser.privacy.websites.trackingProtectionMode.get({}); | ||
return result.value === 'always'; | ||
} | ||
|
||
function doNotTrackEnabled() { | ||
return navigator.doNotTrack === '1'; | ||
} | ||
|
||
async function cookiesBlocked() { | ||
if (browser.privacy.websites.cookieConfig) { | ||
const {behavior} = (await browser.privacy.websites.cookieConfig.get({})).value; | ||
if (!['allow_all', 'allow_visited'].includes(behavior)) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
return true; | ||
} |