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.
Fix #72: Disable telemetry/price updates based on privacy settings.
- Loading branch information
Michael Kelly
committed
Oct 15, 2018
1 parent
b6473f7
commit 565941f
Showing
7 changed files
with
92 additions
and
28 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* 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 | ||
*/ | ||
|
||
/** | ||
* Listener for content scripts that want to gate functionality on privacy | ||
* settings that only the background script can read. | ||
* @param {object} message | ||
* @param {MessageSender} sender | ||
* @return {object} Object containing flags for what features should be enabled | ||
*/ | ||
export async function handlePrivacyMessage(message, sender) { | ||
return { | ||
shouldExtract: await shouldExtract(message, sender), | ||
}; | ||
} | ||
|
||
/** | ||
* Determine if a content script should extract a product from a specific tab. | ||
* @param {object} message | ||
* @param {MessageSender} sender | ||
* @return {boolean} | ||
*/ | ||
async function shouldExtract(message, sender) { | ||
if (sender.tab) { | ||
// Private mode windows should not perform extraction. | ||
const senderWindow = await browser.windows.get(sender.tab.windowId); | ||
if (!senderWindow.incognito) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
export async function shouldCollectTelemetry() { | ||
return !(await arePrivacyControlsActive()); | ||
} | ||
|
||
export async function shouldUpdatePrices() { | ||
return !(await arePrivacyControlsActive()); | ||
} | ||
|
||
/** | ||
* Helper for checking privacy flags that are used in multiple feature flags. | ||
*/ | ||
async function arePrivacyControlsActive() { | ||
// Tracking Protection | ||
if ((await browser.privacy.websites.trackingProtectionMode.get({})).value === 'always') { | ||
return true; | ||
} | ||
|
||
// Do Not Track | ||
if (navigator.doNotTrack === '1') { | ||
return true; | ||
} | ||
|
||
// Cookie blocking | ||
if (browser.privacy.websites.cookieConfig) { | ||
const {behavior} = (await browser.privacy.websites.cookieConfig.get({})).value; | ||
if (['reject_all', 'reject_third_party', 'reject_trackers'].includes(behavior)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} |
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