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

Commit

Permalink
1. Add option to allow mixed content
Browse files Browse the repository at this point in the history
2. Change icon of http and mixed content to fa-unlock

fix #3443
  • Loading branch information
darkdh committed Aug 26, 2016
1 parent 12391d9 commit 33b40ff
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/extensions/brave/locales/en-US/app.properties
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,4 @@ phone=Phone
email=Email
editAddress=Edit Address
editCreditCard=Edit Credit Card
allowMixedContent=Allow Mixed Content
5 changes: 3 additions & 2 deletions docs/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,9 @@ WindowStore
realm: string
},
isExtendedValidation: boolean, // is using https ev
activeMixedContent: boolean, // has active mixed content
passiveMixedContent: boolean, // has passive mixed content
isMixedContent: boolean, // has active mixed content
blockedMixedContent: string, // source of blocked mixed content
allowMixedContent: string // allow mixed content of the source
},
parentFrameKey: number, // the key of the frame this frame was opened from
modalPromptDetail: {...},
Expand Down
26 changes: 26 additions & 0 deletions js/actions/windowActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,32 @@ const windowActions = {
currentDetail,
originalDetail
})
},

/**
* Sets which mixed content were blocked on a page.
* @param {Object} frameProps - The frame to set blocked mixed content on
* @param {string} source - Source of blocked mixed content
*/
setBlockedMixedContent: function (frameProps, source) {
dispatch({
actionType: WindowConstants.WINDOW_SET_BLOCKED_MIXED_CONTENT,
frameProps,
source
})
},

/**
* Sets allow mixed content on a page.
* @param {Object} frameProps - The frame to set blocked info on
* @param {string} source - Source of mixed content
*/
setAllowdMixedContent: function (frameProps, source) {
dispatch({
actionType: WindowConstants.WINDOW_SET_ALLOW_MIXED_CONTENT,
frameProps,
source
})
}
}

Expand Down
12 changes: 10 additions & 2 deletions js/components/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ class Frame extends ImmutableComponent {

allowRunningInsecureContent () {
let hack = siteHacks[urlParse(this.props.location).hostname]
return !!(hack && hack.allowRunningInsecureContent)
const userAllow = this.props.allowMixedContent
return !!(userAllow || (hack && hack.allowRunningInsecureContent))
}

allowRunningPlugins (url) {
Expand Down Expand Up @@ -557,6 +558,8 @@ class Frame extends ImmutableComponent {
this.webview.addEventListener('content-blocked', (e) => {
if (e.details[0] === 'javascript') {
windowActions.setBlockedBy(this.frame, 'noScript', e.details[1])
} else if (!this.allowRunningInsecureContent()) {
windowActions.setBlockedMixedContent(this.frame, e.details[1])
}
})
this.webview.addEventListener('context-menu', (e) => {
Expand Down Expand Up @@ -621,9 +624,11 @@ class Frame extends ImmutableComponent {
}
})
this.webview.addEventListener('destroyed', (e) => {
windowActions.setAllowdMixedContent(this.frame)
this.props.onCloseFrame(this.frame)
})
this.webview.addEventListener('close', () => {
windowActions.setAllowdMixedContent(this.props.frame)
this.props.onCloseFrame(this.frame)
})
this.webview.addEventListener('page-favicon-updated', (e) => {
Expand Down Expand Up @@ -733,9 +738,12 @@ class Frame extends ImmutableComponent {
interceptFlash(true, e.url)
}
windowActions.onWebviewLoadStart(this.frame, e.url)
windowActions.setBlockedMixedContent(this.frame)
const isSecure = parsedUrl.protocol === 'https:' && !this.allowRunningInsecureContent()
const isMixedContent = parsedUrl.protocol === 'https:' && this.allowRunningInsecureContent()
windowActions.setSecurityState(this.frame, {
secure: isSecure
secure: isSecure,
mixedContent: isMixedContent
})
if (isSecure) {
// Check that there isn't a cert error.
Expand Down
1 change: 1 addition & 0 deletions js/components/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,7 @@ class Main extends ImmutableComponent {
aboutDetails={frame.get('aboutDetails')}
unloaded={frame.get('unloaded')}
audioMuted={frame.get('audioMuted')}
allowMixedContent={frame.getIn(['security', 'allowMixedContent'])}
passwords={this.props.appState.get('passwords')}
adblock={this.props.appState.get('adblock')}
safeBrowsing={this.props.appState.get('safeBrowsing')}
Expand Down
24 changes: 23 additions & 1 deletion js/components/siteInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,18 @@ const React = require('react')
const ImmutableComponent = require('./immutableComponent')
const cx = require('../lib/classSet.js')
const Dialog = require('./dialog')
const Button = require('./button')
const windowActions = require('../actions/windowActions')

class SiteInfo extends ImmutableComponent {
constructor () {
super()
this.onAllowMixedContent = this.onAllowMixedContent.bind(this)
}
onAllowMixedContent () {
windowActions.setAllowdMixedContent(this.props.frameProps, this.isMixedContentBlocked)
this.props.onHide()
}
get isExtendedValidation () {
return this.props.frameProps.getIn(['security', 'isExtendedValidation'])
}
Expand All @@ -17,6 +27,9 @@ class SiteInfo extends ImmutableComponent {
get isMixedContent () {
return this.props.frameProps.getIn(['security', 'isMixedContent'])
}
get isMixedContentBlocked () {
return this.props.frameProps.getIn(['security', 'blockedMixedContent'])
}
get partitionNumber () {
return this.props.frameProps.getIn(['partitionNumber'])
}
Expand All @@ -30,7 +43,7 @@ class SiteInfo extends ImmutableComponent {
extendedValidation: this.isExtendedValidation
})} /><span data-l10n-id='secureConnection' /></li>
} else if (this.isMixedContent) {
secureIcon = <li><span className='fa fa-unlock-alt' /><span data-l10n-id='mixedConnection' /></li>
secureIcon = <li><span className='fa fa-unlock' /><span data-l10n-id='mixedConnection' /></li>
} else {
secureIcon = <li><span className='fa fa-unlock' /><span data-l10n-id='insecureConnection' data-l10n-args={JSON.stringify(l10nArgs)} /></li>
}
Expand All @@ -46,6 +59,12 @@ class SiteInfo extends ImmutableComponent {
<span data-l10n-args={JSON.stringify(l10nArgs)} data-l10n-id='sessionInfo' /></li>
}

let allowMixedContentButton
if (this.isMixedContentBlocked) {
allowMixedContentButton =
<Button l10nId='allowMixedContent' className='primaryButton' onClick={this.onAllowMixedContent} />
}

return <Dialog onHide={this.props.onHide} className='siteInfo' isClickDismiss>
<ul onClick={(e) => e.stopPropagation()}>
{
Expand All @@ -54,6 +73,9 @@ class SiteInfo extends ImmutableComponent {
{
partitionInfo
}
{
allowMixedContentButton
}
</ul>
</Dialog>
}
Expand Down
2 changes: 1 addition & 1 deletion js/components/urlBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ class UrlBar extends ImmutableComponent {
urlbarIcon: true,
'fa': !this.activateSearchEngine,
'fa-lock': !this.activateSearchEngine && this.isHTTPPage && this.props.isSecure && !this.props.urlbar.get('active'),
'fa-unlock-alt': !this.activateSearchEngine && this.isHTTPPage && !this.props.isSecure && !this.props.urlbar.get('active') && !this.props.titleMode,
'fa-unlock': !this.activateSearchEngine && this.isHTTPPage && !this.props.isSecure && !this.props.urlbar.get('active') && !this.props.titleMode,
'fa fa-file': !this.activateSearchEngine && this.props.urlbar.get('active') && this.props.loading === false,
extendedValidation: this.extendedValidationSSL
})}
Expand Down
4 changes: 3 additions & 1 deletion js/constants/windowConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ const windowConstants = {
WINDOW_SET_LAST_ZOOM_PERCENTAGE: _,
WINDOW_SET_CLEAR_BROWSING_DATA_DETAIL: _,
WINDOW_SET_AUTOFILL_ADDRESS_DETAIL: _,
WINDOW_SET_AUTOFILL_CREDIT_CARD_DETAIL: _
WINDOW_SET_AUTOFILL_CREDIT_CARD_DETAIL: _,
WINDOW_SET_BLOCKED_MIXED_CONTENT: _,
WINDOW_SET_ALLOW_MIXED_CONTENT: _
}

module.exports = mapValuesByKeys(windowConstants)
3 changes: 3 additions & 0 deletions js/data/siteHacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ module.exports = {
'www.twitch.tv': {
allowRunningInsecureContent: true
},
'forgetfulbc.blogspot.com': {
allowRunningInsecureContent: false
},
'imasdk.googleapis.com': {
enableForAdblock: true,
onBeforeRequest: function (details) {
Expand Down
26 changes: 26 additions & 0 deletions js/stores/windowStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,10 @@ const doAction = (action) => {
windowState = windowState.setIn(path.concat(['security', 'isSecure']),
action.securityState.secure)
}
if (action.securityState.mixedContent !== undefined) {
windowState = windowState.setIn(path.concat(['security', 'isMixedContent']),
action.securityState.mixedContent)
}
if (action.securityState.certDetails) {
windowState = windowState.setIn(path.concat(['security', 'certDetails']),
action.securityState.certDetails)
Expand Down Expand Up @@ -770,6 +774,28 @@ const doAction = (action) => {
history: addToHistory(action.frameProps)
})
break
case WindowConstants.WINDOW_SET_BLOCKED_MIXED_CONTENT:
const blockedMixedContentPath =
['frames', FrameStateUtil.getFramePropsIndex(windowState.get('frames'), action.frameProps)]
if (action.source) {
windowState =
windowState.setIn(blockedMixedContentPath.concat(['security', 'blockedMixedContent']), action.source)
} else {
windowState =
windowState.deleteIn(blockedMixedContentPath.concat(['security', 'blockedMixedContent']))
}
break
case WindowConstants.WINDOW_SET_ALLOW_MIXED_CONTENT:
const allowMixedContentPath =
['frames', FrameStateUtil.getFramePropsIndex(windowState.get('frames'), action.frameProps)]
if (action.source) {
windowState =
windowState.setIn(allowMixedContentPath.concat(['security', 'allowMixedContent']), action.source)
} else {
windowState =
windowState.deleteIn(allowMixedContentPath.concat(['security', 'allowMixedContent']))
}
break
default:
}

Expand Down

0 comments on commit 33b40ff

Please sign in to comment.