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

Commit

Permalink
fix flash checks for chromium 54
Browse files Browse the repository at this point in the history
auditors: @bbondy @diractdeltas
  • Loading branch information
bridiver committed Dec 14, 2016
1 parent 89609a9 commit bda60d6
Show file tree
Hide file tree
Showing 15 changed files with 340 additions and 319 deletions.
6 changes: 4 additions & 2 deletions app/browser/basicAuth.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {app} = require('electron')
const { app } = require('electron')

This comment has been minimized.

Copy link
@bbondy

bbondy Dec 15, 2016

Member

nit: we prefer the tightly wrapped brace in browser-laptop code for destructuring.

This comment has been minimized.

Copy link
@bridiver

bridiver Dec 15, 2016

Author Collaborator

I never liked the tightly wrapped brace, but I'll follow the conventions we're using and update this. standardjs seems to be mostly silent on whitespace as long as you don't do something like { app}. I know we can't modify standardjs, but it would be nice if lint enforced things like this

const appActions = require('../../js/actions/appActions')
const basicAuthState = require('../common/state/basicAuthState')
const { makeImmutable } = require('../common/state/immutableUtil')
Expand All @@ -11,7 +11,7 @@ const cleanupAuthCallback = (tabId) => {
}

const basicAuth = {
init: () => {
init: (state, action) => {
app.on('login', (e, webContents, request, authInfo, cb) => {
e.preventDefault()
let tabId = webContents.getId()
Expand All @@ -29,6 +29,8 @@ const basicAuth = {
})
})
})

return state
},

setLoginResponseDetail: (state, action) => {
Expand Down
28 changes: 26 additions & 2 deletions app/browser/webtorrent.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const electron = require('electron')
const ipc = electron.ipcMain
const messages = require('../../js/constants/messages')

module.exports = {init}
const Filtering = require('../filtering')
const { getTargetMagnetUrl } = require('../../js/lib/appUrlUtil')

// Set to see communication between WebTorrent and torrent viewer tabs
const DEBUG_IPC = false
Expand All @@ -13,6 +13,25 @@ if (DEBUG_IPC) console.log('WebTorrent IPC debugging enabled')
let server = null
let channels = {}

function handleMangetUrl (details, isPrivate) {
const result = {
resourceName: module.exports.resourceName,
redirectURL: null,
cancel: false
}

if (details.resourceType !== 'mainFrame') {
return result
}

const magnetUrl = getTargetMagnetUrl(details.url)
if (magnetUrl) {
result.redirectUrl = magnetUrl
}

return result
}

// Receive messages via the window process, ultimately from the UI in a <webview> process
function init () {
if (DEBUG_IPC) console.log('WebTorrent IPC init')
Expand Down Expand Up @@ -42,3 +61,8 @@ function send (msg) {
}
channel.send(messages.TORRENT_MESSAGE, msg)
}

module.exports = {
init,
resourceName: 'webtorrent'
}
1 change: 0 additions & 1 deletion app/browser/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ const api = {
cleanupWindow(windowId)
})
win.webContents.on('new-window', (e, url, frameName, disposition, options = {}) => {
console.log(options)
let userGesture = options.userGesture
if (userGesture === false) {
e.preventDefault()
Expand Down
24 changes: 0 additions & 24 deletions app/extensions/brave/content/scripts/flashListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ function isAdobeLink (href) {
return adobeRegex.test(href)
}

function showFlashNotification (origin, e) {
chrome.ipcRenderer.sendToHost('show-flash-notification', origin)
e.preventDefault()
e.stopPropagation()
}

/**
* Whether a src is a .swf file.
* If so, returns the origin of the file. Otherwise returns false.
Expand Down Expand Up @@ -137,24 +131,6 @@ function insertFlashPlaceholders (elem = document.documentElement) {
if (chrome.contentSettings.flashActive != 'allow' ||
chrome.contentSettings.flashEnabled != 'allow') {
// Open flash links in the same tab so we can intercept them correctly
(function () {
function replaceAdobeLinks () {
Array.from(document.querySelectorAll('a')).forEach((elem) => {
const href = elem.getAttribute('href')
if (isAdobeLink(href)) {
elem.onclick = showFlashNotification.bind(null, window.location.origin)
}
})
}
replaceAdobeLinks()
let interval = setInterval(replaceAdobeLinks, 3000)
document.addEventListener('visibilitychange', () => {
clearInterval(interval)
if (document.visibilityState !== 'hidden') {
interval = setInterval(replaceAdobeLinks, 3000)
}
})
})()
insertFlashPlaceholders()
let interval = setInterval(insertFlashPlaceholders, 3000)
document.addEventListener('visibilitychange', () => {
Expand Down
111 changes: 65 additions & 46 deletions app/filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const electron = require('electron')
const session = electron.session
const BrowserWindow = electron.BrowserWindow
const webContents = electron.webContents
const appStore = require('../js/stores/appStore')
const appActions = require('../js/actions/appActions')
const appConfig = require('../js/constants/appConfig')
const downloadStates = require('../js/constants/downloadStates')
Expand All @@ -33,6 +32,8 @@ const path = require('path')
const getOrigin = require('../js/state/siteUtil').getOrigin
const {adBlockResourceName} = require('./adBlock')

let appStore = null

const beforeSendHeadersFilteringFns = []
const beforeRequestFilteringFns = []
const beforeRedirectFilteringFns = []
Expand Down Expand Up @@ -571,54 +572,76 @@ function shouldIgnoreUrl (url) {
return true
}

module.exports.init = () => {
['default'].forEach((partition) => {
initForPartition(partition)
})
ipcMain.on(messages.INITIALIZE_PARTITION, (e, partition) => {
if (initializedPartitions[partition]) {
module.exports.init = (state, action, store) => {
appStore = store

setImmediate(() => {
['default'].forEach((partition) => {
initForPartition(partition)
})
ipcMain.on(messages.INITIALIZE_PARTITION, (e, partition) => {
if (initializedPartitions[partition]) {
e.returnValue = true
return e.returnValue
}
initForPartition(partition)
e.returnValue = true
return e.returnValue
}
initForPartition(partition)
e.returnValue = true
return e.returnValue
})
ipcMain.on(messages.DOWNLOAD_ACTION, (e, downloadId, action) => {
const item = downloadMap[downloadId]
switch (action) {
case downloadActions.CANCEL:
updateDownloadState(downloadId, item, downloadStates.CANCELLED)
if (item) {
item.cancel()
}
break
case downloadActions.PAUSE:
if (item) {
item.pause()
}
updateDownloadState(downloadId, item, downloadStates.PAUSED)
break
case downloadActions.RESUME:
if (item) {
item.resume()
}
updateDownloadState(downloadId, item, downloadStates.IN_PROGRESS)
break
}
})
ipcMain.on(messages.NOTIFICATION_RESPONSE, (e, message, buttonIndex, persist) => {
if (permissionCallbacks[message]) {
permissionCallbacks[message](buttonIndex, persist)
}
})
ipcMain.on(messages.DOWNLOAD_ACTION, (e, downloadId, action) => {
const item = downloadMap[downloadId]
switch (action) {
case downloadActions.CANCEL:
updateDownloadState(downloadId, item, downloadStates.CANCELLED)
if (item) {
item.cancel()
}
break
case downloadActions.PAUSE:
if (item) {
item.pause()
}
updateDownloadState(downloadId, item, downloadStates.PAUSED)
break
case downloadActions.RESUME:
if (item) {
item.resume()
}
updateDownloadState(downloadId, item, downloadStates.IN_PROGRESS)
break
}
})
ipcMain.on(messages.NOTIFICATION_RESPONSE, (e, message, buttonIndex, persist) => {
if (permissionCallbacks[message]) {
permissionCallbacks[message](buttonIndex, persist)
}
})
})

return state
}

module.exports.getSiteSettings = (url, isPrivate) => {
const appState = appStore.getState()
let settings = appState.get('siteSettings')
if (isPrivate) {
settings = settings.mergeDeep(appState.get('temporarySiteSettings'))
}
return siteSettings.getSiteSettingsForURL(settings, url)
}

module.exports.isResourceEnabled = (resourceName, url, isPrivate) => {
if (resourceName === 'siteHacks') {
return true
}

// TODO(bridiver) - need to clean up the rest of this so web can
// remove this because it duplicates checks made in siteSettings
// and not all resources are controlled by shields up/down
if (resourceName === 'flash' || resourceName === 'webtorrent') {
return true
}

const appState = appStore.getState()
const settings = siteSettings.getSiteSettingsForURL(appState.get('siteSettings'), url)
const tempSettings = siteSettings.getSiteSettingsForURL(appState.get('temporarySiteSettings'), url)
Expand Down Expand Up @@ -702,13 +725,9 @@ module.exports.getMainFrameUrl = (details) => {
if (details.resourceType === 'mainFrame') {
return details.url
}
const tabId = details.tabId
const wc = webContents.getAllWebContents()
if (wc && tabId) {
const content = wc.find((item) => item.getId() === tabId)
if (content) {
return content.getURL()
}
const tab = webContents.fromTabID(details.tabId)
if (tab) {
return tab.getURL()
}
return null
}
21 changes: 0 additions & 21 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ const AppStore = require('../js/stores/appStore')
const PackageLoader = require('./package-loader')
const Autofill = require('./autofill')
const Extensions = require('./extensions')
const Filtering = require('./filtering')
const TrackingProtection = require('./trackingProtection')
const AdBlock = require('./adBlock')
const AdInsertion = require('./browser/ads/adInsertion')
Expand All @@ -73,12 +72,10 @@ const siteSettings = require('../js/state/siteSettings')
const spellCheck = require('./spellCheck')
const locale = require('./locale')
const ledger = require('./ledger')
const flash = require('../js/flash')
const contentSettings = require('../js/state/contentSettings')
const privacy = require('../js/state/privacy')
const async = require('async')
const settings = require('../js/constants/settings')
const webtorrent = require('./browser/webtorrent')

// temporary fix for #4517, #4518 and #4472
app.commandLine.appendSwitch('enable-use-zoom-for-dsf', 'false')
Expand Down Expand Up @@ -240,8 +237,6 @@ const initiateSessionStateSave = (beforeQuit) => {

let loadAppStatePromise = SessionStore.loadAppState()

let flashInitialized = false

// Some settings must be set right away on startup, those settings should be handled here.
loadAppStatePromise.then((initialState) => {
const {HARDWARE_ACCELERATION_ENABLED, SMOOTH_SCROLL_ENABLED, SEND_CRASH_REPORTS} = require('../js/constants/settings')
Expand All @@ -257,13 +252,6 @@ loadAppStatePromise.then((initialState) => {
if (initialState.settings[SMOOTH_SCROLL_ENABLED] === false) {
app.commandLine.appendSwitch('disable-smooth-scrolling')
}
if (initialState.flash && initialState.flash.enabled === true) {
if (flash.init()) {
// Flash was initialized successfully
flashInitialized = true
return
}
}
})

const notifyCertError = (webContents, url, error, cert) => {
Expand Down Expand Up @@ -410,7 +398,6 @@ app.on('ready', () => {
// For tests we always want to load default app state
const loadedPerWindowState = initialState.perWindowState
delete initialState.perWindowState
initialState.flashInitialized = flashInitialized
appActions.setState(Immutable.fromJS(initialState))
Menu.init(initialState, null)
return loadedPerWindowState
Expand All @@ -419,14 +406,12 @@ app.on('ready', () => {
privacy.init()
Autofill.init()
Extensions.init()
Filtering.init()
SiteHacks.init()
spellCheck.init()
HttpsEverywhere.init()
TrackingProtection.init()
AdBlock.init()
AdInsertion.init()
webtorrent.init()

if (!loadedPerWindowState || loadedPerWindowState.length === 0) {
if (!CmdLine.newWindowURL()) {
Expand Down Expand Up @@ -498,12 +483,6 @@ app.on('ready', () => {
electron.clipboard.writeText(text)
})

ipcMain.on(messages.CHECK_FLASH_INSTALLED, (e) => {
flash.checkFlashInstalled((installed) => {
e.sender.send(messages.FLASH_UPDATED, installed)
})
})

ipcMain.on(messages.OPEN_DOWNLOAD_PATH, (e, download) => {
downloadActions.openDownloadPath(Immutable.fromJS(download))
})
Expand Down
9 changes: 4 additions & 5 deletions js/about/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -1552,6 +1552,7 @@ class SecurityTab extends ImmutableComponent {

const isLinux = navigator.appVersion.indexOf('Linux') !== -1

const flashInstalled = getSetting(settings.FLASH_INSTALLED, this.props.settings)
return <div>
<div className='sectionTitle' data-l10n-id='privateData' />
<SettingsList dataL10nId='privateDataMessage'>
Expand Down Expand Up @@ -1608,8 +1609,9 @@ class SecurityTab extends ImmutableComponent {
</SettingsList>
<div className='sectionTitle' data-l10n-id='pluginSettings' />
<SettingsList>
<SettingCheckbox checked={this.props.flashInstalled ? this.props.braveryDefaults.get('flash') : false} dataL10nId='enableFlash' onChange={this.onToggleFlash} disabled={!this.props.flashInstalled} />
<div className='subtext flashText'>
<SettingCheckbox checked={flashInstalled ? this.props.braveryDefaults.get('flash') : false} dataL10nId='enableFlash' onChange={this.onToggleFlash} disabled={!flashInstalled} />
<span className='subtext flashText'>
<span className='fa fa-info-circle' id='flashInfoIcon' />
{
isDarwin || isWindows
? <div>
Expand Down Expand Up @@ -1803,9 +1805,6 @@ class AboutPreferences extends React.Component {
ipc.on(messages.BRAVERY_DEFAULTS_UPDATED, (e, braveryDefaults) => {
this.setState({ braveryDefaults: Immutable.fromJS(braveryDefaults || {}) })
})
ipc.on(messages.FLASH_UPDATED, (e, flashInstalled) => {
this.setState({ flashInstalled })
})
ipc.on(messages.LANGUAGE, (e, {langCode, languageCodes}) => {
this.setState({ languageCodes })
})
Expand Down
Loading

0 comments on commit bda60d6

Please sign in to comment.