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

Commit

Permalink
Open Flash preferences from a link in the placeholder
Browse files Browse the repository at this point in the history
Not sure if this is the safest way to get brave-about.js to run on
an iframed about: page.

Auditors: @bridiver
  • Loading branch information
diracdeltas committed Jul 9, 2016
1 parent 6b2f453 commit 6bc2793
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 6 deletions.
10 changes: 10 additions & 0 deletions app/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ let generateBraveManifest = () => {
exclude_globs: [
getAppUrl('about-blank.html')
]
},
{
run_at: 'document_start',
all_frames: true,
js: [
'content/scripts/brave-about-flash.js'
],
matches: [
'<all_urls>'
]
}
],
permissions: [
Expand Down
12 changes: 12 additions & 0 deletions app/extensions/brave/content/scripts/brave-about-flash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* 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/. */

(function () {
if (window.location && window.location.origin === 'chrome-extension://mnojpmjdmbbfmejpflffifhffcmidifd') {
var ipcRenderer = chrome.ipc
window.addEventListener('new-frame', (e) => {
ipcRenderer.sendToHost('new-frame', e.detail.frameOpts, e.detail.openInForeground)
})
}
}).apply(this)
31 changes: 25 additions & 6 deletions js/about/flashPlaceholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
const React = require('react')
const ImmutableComponent = require('../components/immutableComponent')
const messages = require('../constants/messages')
const aboutActions = require('./aboutActions')

require('../../less/about/flash.less')

Expand All @@ -16,6 +17,7 @@ class FlashPlaceholder extends ImmutableComponent {
super()
const braveryDefaults = window.initBraveryDefaults
this.onContextMenu = this.onContextMenu.bind(this)
this.onPrefsClick = this.onPrefsClick.bind(this)
this.state = {
flashEnabled: braveryDefaults && braveryDefaults.flash ? braveryDefaults.flash.enabled : this.flashEnabled
}
Expand Down Expand Up @@ -56,22 +58,39 @@ class FlashPlaceholder extends ImmutableComponent {
}
}

onPrefsClick (e) {
aboutActions.newFrame({
location: 'about:preferences#security'
}, true)
}

render () {
const flashEnabled = this.state.flashEnabled
// TODO: Localization doesn't work due to CORS error from inside iframe
const cmd = isDarwin ? 'Control-Click' : 'Right-Click'
const flashRightClick = flashEnabled ? `${cmd} to run Adobe Flash Player` : 'Adobe Flash has been blocked.'
const flashExpirationText = flashEnabled ? 'For your security, approvals are limited to 1 week.' : null
const flashSubtext = flashEnabled ? `on ${this.origin || 'this site'}.` : 'To run Flash, enable it in Preferences > Security.'
const flashSubtext = `on ${this.origin || 'this site'}.`
return <div onContextMenu={this.onContextMenu}>
<div className='flashMainContent'>
<img src='img/bravePluginAlert.png' />
<div id='flashRightClick'>{flashRightClick}</div>
<div className='flashSubtext'>{flashSubtext}</div>
</div>
<div className='flashFooter'>
{flashExpirationText}
<div className='flashSubtext'>
{
flashEnabled
? flashSubtext
: <span>
To run Flash, enable it in <span className='linkText' onClick={this.onPrefsClick}>Preferences</span>.
</span>
}
</div>
</div>
{
flashEnabled
? <div className='flashFooter'>
For security, <span className='linkText' onClick={this.onPrefsClick}>approvals</span> expire in 1 week.
</div>
: null
}
</div>
}
}
Expand Down
9 changes: 9 additions & 0 deletions less/about/flash.less
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
font-size: 3vw;
}

.linkText {
text-decoration: underline;
color: #5B5B5B;
cursor: default;
&:hover {
color: #000;
}
}

#appContainer {
background: linear-gradient(to bottom, #fff 0%, #aaa 100%);
}

0 comments on commit 6bc2793

Please sign in to comment.