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

Commit

Permalink
move expireContentSettings to browser
Browse files Browse the repository at this point in the history
  • Loading branch information
petemill committed Apr 3, 2018
1 parent 07cec7c commit 17c1814
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 30 deletions.
40 changes: 40 additions & 0 deletions app/browser/reducers/tabsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

const appConfig = require('../../../js/constants/appConfig')
const appConstants = require('../../../js/constants/appConstants')
const appActions = require('../../../js/actions/appActions')
const tabs = require('../tabs')
const windows = require('../windows')
const {getWebContents} = require('../webContentsCache')
Expand Down Expand Up @@ -46,14 +47,51 @@ const getWebRTCPolicy = (state, tabId) => {
}
}

function expireContentSettings (state, tabId, origin) {
// Expired Flash settings should be deleted when the webview is
// navigated or closed. Same for NoScript's allow-once option.
const tabValue = tabState.getByTabId(state, tabId)
const isPrivate = tabValue.get('incognito') === true
const allSiteSettings = siteSettingsState.getAllSiteSettings(state, isPrivate)
const tabSiteSettings =
siteSettings.getSiteSettingsForURL(allSiteSettings, tabValue.get('url'))
if (!tabSiteSettings) {
return
}
const originFlashEnabled = tabSiteSettings.get('flash')
const originWidevineEnabled = tabSiteSettings.get('widevine')
const originNoScriptEnabled = tabSiteSettings.get('noScript')
const originNoScriptExceptions = tabSiteSettings.get('noScriptExceptions')
if (typeof originFlashEnabled === 'number') {
if (originFlashEnabled < Date.now()) {
appActions.removeSiteSetting(origin, 'flash', isPrivate)
}
}
if (originWidevineEnabled === 0) {
appActions.removeSiteSetting(origin, 'widevine', isPrivate)
}
if (originNoScriptEnabled === 0) {
appActions.removeSiteSetting(origin, 'noScript', isPrivate)
}
if (originNoScriptExceptions) {
appActions.noScriptExceptionsAdded(origin, originNoScriptExceptions.map(value => value === 0 ? false : value))
}
}

const tabsReducer = (state, action, immutableAction) => {
action = immutableAction || makeImmutable(action)
switch (action.get('actionType')) {
case tabActionConsts.FINISH_NAVIGATION:
case tabActionConsts.START_NAVIGATION:
{
const tabId = action.get('tabId')
const originalOrigin = tabState.getVisibleOrigin(state, tabId)
state = tabState.setNavigationState(state, tabId, action.get('navigationState'))
const newOrigin = tabState.getVisibleOrigin(state, tabId)
// For cross-origin navigation, clear temp approvals
if (originalOrigin !== newOrigin) {
expireContentSettings(state, tabId, originalOrigin)
}
setImmediate(() => {
tabs.setWebRTCIPHandlingPolicy(tabId, getWebRTCPolicy(state, tabId))
})
Expand Down Expand Up @@ -226,6 +264,8 @@ const tabsReducer = (state, action, immutableAction) => {
// But still check for no tabId because on tab detach there's a dummy tabId
const tabValue = tabState.getByTabId(state, tabId)
if (tabValue) {
const lastOrigin = tabState.getVisibleOrigin(state, tabId)
expireContentSettings(state, tabId, lastOrigin)
const windowIdOfTabBeingRemoved = tabState.getWindowId(state, tabId)
state = tabs.updateTabsStateForWindow(state, windowIdOfTabBeingRemoved)
}
Expand Down
3 changes: 2 additions & 1 deletion app/common/state/tabState.js
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,8 @@ const tabState = {

getVisibleOrigin: (state, tabId) => {
const entry = tabState.getVisibleEntry(state, tabId)
const origin = entry ? entry.get('origin') : ''
// plain js in browser, immutable in renderer
const origin = entry ? entry.get ? entry.get('origin') : entry.origin : ''
// TODO(bridiver) - all origins in browser-laptop should be changed to have a trailing slash to match chromium
return (origin || '').replace(/\/$/, '')
},
Expand Down
29 changes: 0 additions & 29 deletions app/renderer/components/frame/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,30 +90,6 @@ class Frame extends React.Component {
}


expireContentSettings (props) {
// Expired Flash settings should be deleted when the webview is
// navigated or closed. Same for NoScript's allow-once option.
if (typeof props.flash === 'number') {
if (props.flash < Date.now()) {
appActions.removeSiteSetting(props.origin, 'flash', props.isPrivate)
}
}
if (props.widevine === 0) {
appActions.removeSiteSetting(props.origin, 'widevine', props.isPrivate)
}
if (props.noScript === 0) {
appActions.removeSiteSetting(props.origin, 'noScript', props.isPrivate)
}
if (props.noScriptExceptions) {
appActions.noScriptExceptionsAdded(props.origin, props.noScriptExceptions.map(value => value === 0 ? false : value))
}
}

componentWillUnmount () {
this.expireContentSettings(this.props)
}


componentDidMount () {
this.addEventListeners()
}
Expand Down Expand Up @@ -154,11 +130,6 @@ class Frame extends React.Component {

this.lastFrame = this.frame.delete('lastAccessedTime')

// For cross-origin navigation, clear temp approvals
if (this.props.origin !== prevProps.origin) {
this.expireContentSettings(prevProps)
}

// make sure the webview content updates to
// match the fullscreen state of the frame
if (prevProps.isFullScreen !== this.props.isFullScreen ||
Expand Down

0 comments on commit 17c1814

Please sign in to comment.