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

Commit

Permalink
[WIP] disable plugins in Tor private tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
diracdeltas committed Mar 22, 2018
1 parent 8b47785 commit 8d8f83d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
10 changes: 9 additions & 1 deletion app/browser/contentSettings/hostContentSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,27 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const { makeImmutable } = require('../../common/state/immutableUtil')
const appConfig = require('../../../js/constants/appConfig')

let registeredCallbacks = []
let registeredSessions = {}
let registeredPrivateSessions = {}
const blockContentSetting = { setting: 'block', primaryPattern: '*' }

module.exports.setContentSettings = (contentSettings, incognito) => {
contentSettings = makeImmutable(contentSettings)

const partitions = incognito ? registeredPrivateSessions : registeredSessions
for (let partition in partitions) {
let newContentSettings = contentSettings
if (partition === appConfig.tor.partition) {
// Do not allow plugins to be enabled in Tor contexts
newContentSettings = contentSettings.set('plugins', makeImmutable([blockContentSetting]))
}

const ses = partitions[partition]

contentSettings.forEach((settings, contentType) => {
newContentSettings.forEach((settings, contentType) => {
ses.contentSettings.clearForOneType(contentType)
settings.forEach((setting) => {
module.exports.setContentSetting(ses, setting.get('primaryPattern'), setting.get('secondaryPattern'),
Expand Down
13 changes: 12 additions & 1 deletion js/state/userPrefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
* 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/. */

const appConfig = require('../constants/appConfig')

let registeredCallbacks = []
let registeredSessions = {}
let registeredPrivateSessions = {}
const blockContentSetting = { setting: 'block', primaryPattern: '*' }

// TODO(bridiver) move this to electron so we can call a simpler api
const setUserPrefType = (ses, path, value) => {
Expand Down Expand Up @@ -54,8 +57,16 @@ module.exports.setUserPref = (path, value, incognito = false) => {

const partitions = incognito ? registeredPrivateSessions : registeredSessions
for (let partition in partitions) {
let newValue = value
if (partition === appConfig.tor.partition && path === 'content_settings' && value) {
newValue = Object.assign({}, value, {
flashEnabled: [blockContentSetting],
flashAllowed: [blockContentSetting],
plugins: [blockContentSetting]
})
}
const ses = partitions[partition]
setUserPrefType(ses, path, value)
setUserPrefType(ses, path, newValue)
ses.webRequest.handleBehaviorChanged()
}
}
Expand Down

0 comments on commit 8d8f83d

Please sign in to comment.