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

Refactors Navigator and BrowserAction into redux components #8658

Merged
merged 1 commit into from
May 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions app/common/state/siteSettingsState.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
const appConfig = require('../../../js/constants/appConfig')
const siteSettings = require('../../../js/state/siteSettings')

const siteSettingsState = {
const api = {
getAllSiteSettings: (state, isPrivate) => {
if (isPrivate) {
return state.get('siteSettings').mergeDeep(state.get('temporarySiteSettings'))
}
return state.get('siteSettings')
},

isNoScriptEnabled (state, settings) {
isNoScriptEnabled (state, isPrivate) {
const settings = api.getAllSiteSettings(state, isPrivate)
return siteSettings.activeSettings(settings, state, appConfig).noScript === true
}
}

module.exports = siteSettingsState
module.exports = api
26 changes: 26 additions & 0 deletions app/common/state/windowState.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

const { makeImmutable, isMap, isList } = require('./immutableUtil')
const assert = require('assert')
const defaultBrowserState = require('./defaultBrowserState')
const shieldState = require('./shieldState')

// TODO(bridiver) - make these generic validation functions
const validateId = function (propName, id) {
Expand Down Expand Up @@ -155,6 +157,30 @@ const api = {
// TODO(bridiver) handle restoring state
state = makeImmutable(state)
return state.delete('windows')
},

// TODO (nejc) we should only pass in one state
// refactor when window state is merged into app state
shouldAllowWindowDrag: (state, windowState, frame, isFocused) => {
const braveryPanelIsVisible = shieldState.braveShieldsEnabled(frame) &&
windowState.get('braveryPanelDetail')
const checkDefaultBrowserDialogIsVisible = isFocused &&
defaultBrowserState.shouldDisplayDialog(state)

return !state.get('contextMenuDetail') &&
!windowState.get('bookmarkDetail') &&
!windowState.getIn(['ui', 'siteInfo', 'isVisible']) &&
!braveryPanelIsVisible &&
!windowState.getIn(['ui', 'isClearBrowsingDataPanelVisible']) &&
!windowState.get('importBrowserDataDetail') &&
!windowState.getIn(['widevinePanelDetail', 'shown']) &&
!windowState.get('autofillAddressDetail') &&
!windowState.get('autofillCreditCardDetail') &&
!windowState.getIn(['ui', 'releaseNotes', 'isVisible']) &&
!checkDefaultBrowserDialogIsVisible &&
!windowState.getIn(['ui', 'noScriptInfo', 'isVisible']) &&
frame && !frame.getIn(['security', 'loginRequiredDetail']) &&
!windowState.getIn(['ui', 'menubar', 'selectedIndex'])
}
}

Expand Down
60 changes: 45 additions & 15 deletions app/renderer/components/browserAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,26 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const React = require('react')
const ImmutableComponent = require('./immutableComponent')
const electron = require('electron')
const ipc = electron.ipcRenderer
const {StyleSheet, css} = require('aphrodite')

// Components
const ReduxComponent = require('./reduxComponent')
const BrowserButton = require('./common/browserButton')
const BrowserActionBadge = require('../../renderer/components/browserActionBadge')

// State
const extensionState = require('../../common/state/extensionState')
const tabState = require('../../common/state/tabState')

// Actions
const windowActions = require('../../../js/actions/windowActions')
const {StyleSheet, css} = require('aphrodite')

class BrowserAction extends ImmutableComponent {
// Utils
const {getCurrentWindowId} = require('../currentWindow')

class BrowserAction extends React.Component {
constructor () {
super()
this.onClick = this.onClick.bind(this)
Expand All @@ -39,39 +49,59 @@ class BrowserAction extends ImmutableComponent {
offsetX: e.nativeEvent.offsetX,
offsetY: e.nativeEvent.offsetY
}
ipc.send('chrome-browser-action-clicked', this.props.extensionId, this.props.tabId, this.props.browserAction.get('title'), props)
ipc.send('chrome-browser-action-clicked', this.props.extensionId, this.props.activeTabId, this.props.title, props)
}

mergeProps (state, dispatchProps, ownProps) {
const currentWindow = state.get('currentWindow')
const activeTab = tabState.getActiveTabValue(state, getCurrentWindowId())
const activeTabId = activeTab && activeTab.get('tabId')
const browserActions = extensionState.getBrowserActionByTabId(state, ownProps.extensionId, activeTabId)

const props = {}
// used in renderer
props.title = browserActions.get('title')
props.text = browserActions.get('text')
props.color = browserActions.get('color')
props.image = extensionState.browserActionBackgroundImage(browserActions, activeTabId)

// used in other functions
props.popupWindowSrc = currentWindow.getIn(['popupWindowDetail', 'src'])
props.activeTabId = activeTabId

return Object.assign({}, ownProps, props)
}

render () {
const browserBadgeText = this.props.browserAction.get('text')
const browserBadgeColor = this.props.browserAction.get('color')
// TODO(bridiver) should have some visual notification of hover/press
return <div className={css(styles.browserActionButton)}>
<BrowserButton extensionItem
<BrowserButton
extensionItem
l10nId='browserActionButton'
testId='extensionBrowserAction'
l10nArgs={{ name: this.props.browserAction.get('title') }}
l10nArgs={{ name: this.props.title }}
inlineStyles={{
backgroundImage: extensionState
.browserActionBackgroundImage(this.props.browserAction, this.props.tabId),
backgroundImage: this.props.image,
backgroundPosition: 'center',
backgroundSize: 'contain',
backgroundRepeat: 'no-repeat'
}}
dataButtonValue={this.props.extensionId}
onClick={this.onClick} />
{ browserBadgeText
? <BrowserActionBadge text={browserBadgeText} color={browserBadgeColor} />
onClick={this.onClick}
/>
{
this.props.text
? <BrowserActionBadge text={this.props.text} color={this.props.color} />
: null
}
</div>
}
}

module.exports = ReduxComponent.connect(BrowserAction)

const styles = StyleSheet.create({
browserActionButton: {
position: 'relative'
}
})

module.exports = BrowserAction
7 changes: 5 additions & 2 deletions app/renderer/components/navigation/navigationBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const {getCurrentWindowId} = require('../../currentWindow')
// State
const tabState = require('../../../common/state/tabState')
const frameStateUtil = require('../../../../js/state/frameStateUtil')
const menuBarState = require('../../../common/state/menuBarState')
const siteSettingsState = require('../../../common/state/siteSettingsState')

class NavigationBar extends React.Component {
constructor (props) {
Expand Down Expand Up @@ -125,6 +127,7 @@ class NavigationBar extends React.Component {
const loading = activeFrame.get('loading')
const location = activeFrame.get('location') || ''
const navbar = activeFrame.get('navbar') || Immutable.Map()
const isPrivate = activeFrame.get('isPrivate') || false

const hasTitle = title && location && title !== location.replace(/^https?:\/\//, '')
const titleMode = activeTabShowingMessageBox ||
Expand All @@ -151,9 +154,9 @@ class NavigationBar extends React.Component {
props.loading = loading
props.bookmarkDetail = bookmarkDetail
props.mouseInTitlebar = mouseInTitlebar
props.enableNoScript = ownProps.enableNoScript
props.enableNoScript = siteSettingsState.isNoScriptEnabled(state, isPrivate)
props.settings = state.get('settings')
props.menubarVisible = ownProps.menubarVisible
props.menubarVisible = menuBarState.isMenuBarVisible(windowState)
props.siteSettings = state.get('siteSettings')
props.synopsis = state.getIn(['publisherInfo', 'synopsis']) || new Immutable.Map()
props.activeTabShowingMessageBox = activeTabShowingMessageBox
Expand Down
Loading