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

Commit

Permalink
Merge pull request #9899 from NejcZdovc/redux/check
Browse files Browse the repository at this point in the history
Fixes some possible null scenarios; Some linting and code clean up
  • Loading branch information
NejcZdovc authored Jul 12, 2017
2 parents be93d99 + 067ce6a commit bebfb2e
Show file tree
Hide file tree
Showing 23 changed files with 72 additions and 66 deletions.
5 changes: 3 additions & 2 deletions app/renderer/components/common/messageBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const React = require('react')
const Immutable = require('immutable')
const {StyleSheet, css} = require('aphrodite')

// Components
Expand Down Expand Up @@ -101,8 +102,8 @@ class MessageBox extends React.Component {
mergeProps (state, ownProps) {
const currentWindow = state.get('currentWindow')
const tabId = ownProps.tabId
const tab = tabState.getByTabId(state, tabId)
const messageBoxDetail = tab.get('messageBoxDetail')
const tab = tabState.getByTabId(state, tabId) || Immutable.Map()
const messageBoxDetail = tab.get('messageBoxDetail', Immutable.Map())

const props = {}
// used in renderer
Expand Down
6 changes: 3 additions & 3 deletions app/renderer/components/download/downloadsBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const React = require('react')
const {StyleSheet, css} = require('aphrodite/no-important')
const Immutable = require('immutable')

// Components
const ReduxComponent = require('../reduxComponent')
const Button = require('../common/button')
const BrowserButton = require('../common/browserButton')
const DownloadItem = require('./downloadItem')

const {StyleSheet, css} = require('aphrodite/no-important')

// Actions
const windowActions = require('../../../../js/actions/windowActions')
const webviewActions = require('../../../../js/actions/webviewActions')
Expand Down Expand Up @@ -45,7 +45,7 @@ class DownloadsBar extends React.Component {
mergeProps (state, ownProps) {
const props = {}
// used in renderer
props.downloads = downloadUtil.getDownloadItems(state)
props.downloads = downloadUtil.getDownloadItems(state) || Immutable.List()

return props
}
Expand Down
10 changes: 5 additions & 5 deletions app/renderer/components/frame/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ class Frame extends React.Component {
return !this.webview
}

allowRunningWidevinePlugin (url) {
allowRunningWidevinePlugin () {
if (!this.props.isWidevineEnabled) {
return false
}
if (!this.props.origin) {
return false
}
// Check for at least one CtP allowed on this origin
if (!this.props.allSiteSettings) {
if (!this.props.hasAllSiteSettings) {
return false
}
if (typeof this.props.widevine === 'number') {
Expand Down Expand Up @@ -859,7 +859,7 @@ class Frame extends React.Component {
mergeProps (state, ownProps) {
const currentWindow = state.get('currentWindow')
const frame = frameStateUtil.getFrameByKey(currentWindow, ownProps.frameKey) || Immutable.Map()
const tabId = frame.get('tabId')
const tabId = frame.get('tabId', tabState.TAB_ID_NONE)

const location = frame.get('location')
const origin = tabState.getVisibleOrigin(state, tabId)
Expand Down Expand Up @@ -896,7 +896,7 @@ class Frame extends React.Component {
props.isAutFillContextMenu = contextMenu && contextMenu.get('type') === 'autofill'
props.isSecure = frame.getIn(['security', 'isSecure'])
props.findbarShown = frame.get('findbarShown')
props.findDetailCaseSensitivity = frame.getIn(['findDetail', 'caseSensitivity']) || undefined
props.findDetailCaseSensitivity = frame.getIn(['findDetail', 'caseSensitivity'], undefined)
props.findDetailSearchString = frame.getIn(['findDetail', 'searchString'])
props.findDetailInternalFindStatePresent = frame.getIn(['findDetail', 'internalFindStatePresent'])
props.isPrivate = frame.get('isPrivate')
Expand All @@ -914,7 +914,7 @@ class Frame extends React.Component {
props.unloaded = frame.get('unloaded')
props.isWidevineEnabled = state.get('widevine') && state.getIn(['widevine', 'enabled'])
props.siteZoomLevel = frameSiteSettings.get('zoomLevel')
props.allSiteSettings = allSiteSettings // TODO (nejc) can be improved even more
props.hasAllSiteSettings = !!allSiteSettings
props.tabUrl = tab && tab.get('url')
props.partitionNumber = frame.get('partitionNumber')

Expand Down
6 changes: 4 additions & 2 deletions app/renderer/components/main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const shieldState = require('../../../common/state/shieldState')
const menuBarState = require('../../../common/state/menuBarState')
const windowState = require('../../../common/state/windowState')
const updateState = require('../../../common/state/updateState')
const tabState = require('../../../common/state/tabState')

// Util
const _ = require('underscore')
Expand Down Expand Up @@ -518,11 +519,12 @@ class Main extends React.Component {
mergeProps (state, ownProps) {
const currentWindow = state.get('currentWindow')
const activeFrame = frameStateUtil.getActiveFrame(currentWindow) || Immutable.Map()
const activeTabId = activeFrame.get('tabId', tabState.TAB_ID_NONE)
const nonPinnedFrames = frameStateUtil.getNonPinnedFrames(currentWindow)
const tabsPerPage = Number(getSetting(settings.TABS_PER_PAGE))
const activeOrigin = !activeFrame.isEmpty() ? siteUtil.getOrigin(activeFrame.get('location')) : null
const widevinePanelDetail = currentWindow.get('widevinePanelDetail', Immutable.Map())
const loginRequiredDetails = basicAuthState.getLoginRequiredDetail(state, activeFrame.get('tabId'))
const loginRequiredDetails = basicAuthState.getLoginRequiredDetail(state, activeTabId)

const props = {}
// used in renderer
Expand Down Expand Up @@ -570,7 +572,7 @@ class Main extends React.Component {
props.menubarVisible = menuBarState.isMenuBarVisible(currentWindow)
props.mouseInFrame = currentWindow.getIn(['ui', 'mouseInFrame'])
props.braveShieldEnabled = shieldState.braveShieldsEnabled(activeFrame)
props.tabId = activeFrame.get('tabId')
props.tabId = activeTabId
props.location = activeFrame.get('location')
props.isWidevineReady = state.getIn([appConfig.resourceNames.WIDEVINE, 'ready'])
props.widevineLocation = siteUtil.getOrigin(widevinePanelDetail.get('location'))
Expand Down
2 changes: 1 addition & 1 deletion app/renderer/components/main/notificationBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class NotificationBar extends React.Component {
const currentWindow = state.get('currentWindow')
const activeFrame = frameStateUtil.getActiveFrame(currentWindow) || Immutable.Map()
const activeOrigin = getOrigin(activeFrame.get('location'))
const notifications = state.get('notifications')
const notifications = state.get('notifications', Immutable.List())

const props = {}
props.activeNotifications = notifications
Expand Down
3 changes: 2 additions & 1 deletion app/renderer/components/main/widevinePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const React = require('react')
const Immutable = require('immutable')
const {StyleSheet, css} = require('aphrodite/no-important')

// Components
Expand Down Expand Up @@ -60,7 +61,7 @@ class WidevinePanel extends React.Component {

mergeProps (state, ownProps) {
const currentWindow = state.get('currentWindow')
const widevinePanelDetail = currentWindow.get('widevinePanelDetail')
const widevinePanelDetail = currentWindow.get('widevinePanelDetail', Immutable.Map())

const props = {}
props.origin = siteUtil.getOrigin(widevinePanelDetail.get('location'))
Expand Down
4 changes: 2 additions & 2 deletions app/renderer/components/navigation/browserAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class BrowserAction extends React.Component {
mergeProps (state, ownProps) {
const currentWindow = state.get('currentWindow')
const activeFrame = frameStateUtil.getActiveFrame(currentWindow) || Immutable.Map()
const activeTabId = activeFrame.get('tabId') || tabState.TAB_ID_NONE
let browserActions = extensionState.getBrowserActionByTabId(state, ownProps.extensionId, activeTabId)
const activeTabId = activeFrame.get('tabId', tabState.TAB_ID_NONE)
let browserActions = extensionState.getBrowserActionByTabId(state, ownProps.extensionId, activeTabId) || Immutable.Map()
let tabAction = browserActions.getIn(['tabs', activeTabId.toString()])

if (tabAction) {
Expand Down
3 changes: 1 addition & 2 deletions app/renderer/components/navigation/menuBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ class MenuBar extends React.Component {

mergeProps (state, ownProps) {
const currentWindow = state.get('currentWindow')
const contextMenuDetail = currentWindow.get('contextMenuDetail')

const props = {}
// used in renderer
Expand All @@ -130,7 +129,7 @@ class MenuBar extends React.Component {
// used in other functions
props.selectedIndex = currentWindow.getIn(['ui', 'menubar', 'selectedIndex'])
props.contextMenuSelectedIndex = contextMenuState.selectedIndex(currentWindow)
props.contextMenuDetail = !!contextMenuDetail
props.contextMenuDetail = currentWindow.has('contextMenuDetail')
props.lastFocusedSelector = currentWindow.getIn(['ui', 'menubar', 'lastFocusedSelector'])

return props
Expand Down
3 changes: 2 additions & 1 deletion app/renderer/components/navigation/menuBarItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const React = require('react')
const Immutable = require('immutable')

// Components
const ReduxComponent = require('../reduxComponent')
Expand Down Expand Up @@ -48,7 +49,7 @@ class MenuBarItem extends React.Component {
mergeProps (state, ownProps) {
const currentWindow = state.get('currentWindow')
const selectedIndex = currentWindow.getIn(['ui', 'menubar', 'selectedIndex'])
const template = state.getIn(['menu', 'template', ownProps.index])
const template = state.getIn(['menu', 'template', ownProps.index], Immutable.Map())

const props = {}
// used in renderer
Expand Down
6 changes: 3 additions & 3 deletions app/renderer/components/navigation/navigationBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class NavigationBar extends React.Component {
const activeTab = tabState.getByTabId(state, activeTabId)

const activeTabShowingMessageBox = tabState.isShowingMessageBox(state, activeTabId)
const bookmarkDetail = currentWindow.get('bookmarkDetail')
const bookmarkDetail = currentWindow.get('bookmarkDetail', Immutable.Map())
const mouseInTitlebar = currentWindow.getIn(['ui', 'mouseInTitlebar'])
const title = activeFrame.get('title', '')
const loading = activeFrame.get('loading')
Expand All @@ -113,10 +113,10 @@ class NavigationBar extends React.Component {
// used in renderer
props.activeFrameKey = activeFrameKey
props.titleMode = titleMode
props.isBookmarked = props.activeFrameKey !== undefined &&
props.isBookmarked = activeFrameKey !== undefined &&
activeTab && activeTab.get('bookmarked')
props.isWideUrlBarEnabled = getSetting(settings.WIDE_URL_BAR)
props.showBookmarkHanger = bookmarkDetail && bookmarkDetail.get('isBookmarkHanger')
props.showBookmarkHanger = bookmarkDetail.get('isBookmarkHanger')
props.isLoading = loading
props.showPublisherToggle = publisherState.shouldShowAddPublisherButton(state, location, publisherId)
props.showHomeButton = !props.titleMode && getSetting(settings.SHOW_HOME_BUTTON)
Expand Down
8 changes: 4 additions & 4 deletions app/renderer/components/navigation/navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ class Navigator extends React.Component {
const swipeRightPercent = state.get('swipeRightPercent')
const activeFrame = frameStateUtil.getActiveFrame(currentWindow) || Immutable.Map()
const activeFrameKey = activeFrame.get('key')
const activeTabId = activeFrame.get('tabId') || tabState.TAB_ID_NONE
const activeTab = tabState.getByTabId(state, activeTabId)
const activeTabId = activeFrame.get('tabId', tabState.TAB_ID_NONE)
const activeTab = tabState.getByTabId(state, activeTabId) || Immutable.Map()
const activeTabShowingMessageBox = !!(activeTab && tabState.isShowingMessageBox(state, activeTabId))
const allSiteSettings = siteSettingsState.getAllSiteSettings(state, activeFrame)
const activeSiteSettings = siteSettings.getSiteSettingsForURL(allSiteSettings, activeFrame.get('location'))
Expand All @@ -173,8 +173,8 @@ class Navigator extends React.Component {

const props = {}
// used in renderer
props.canGoBack = activeTab && activeTab.get('canGoBack') && !activeTabShowingMessageBox
props.canGoForward = activeTab && activeTab.get('canGoForward') && !activeTabShowingMessageBox
props.canGoBack = activeTab.get('canGoBack') && !activeTabShowingMessageBox
props.canGoForward = activeTab.get('canGoForward') && !activeTabShowingMessageBox
props.totalBlocks = activeFrame ? frameStateUtil.getTotalBlocks(activeFrame) : false
props.shieldsDown = !braverySettings.shieldsUp
props.shieldEnabled = braveShieldsEnabled(activeFrame)
Expand Down
2 changes: 1 addition & 1 deletion app/renderer/components/navigation/urlBarIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class UrlBarIcon extends React.Component {

// used in other functions
props.title = activeFrame.get('title', '')
props.tabId = activeFrame.get('tabId')
props.tabId = activeFrame.get('tabId', tabState.TAB_ID_NONE)

return props
}
Expand Down
2 changes: 1 addition & 1 deletion app/renderer/components/tabs/content/audioTabIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class AudioTabIcon extends React.Component {
// used in other functions
props.frameKey = ownProps.frameKey
props.pageCanPlayAudio = !!frame.get('audioPlaybackActive')
props.tabId = frame ? frame.get('tabId') : tabState.TAB_ID_NONE
props.tabId = frame.get('tabId', tabState.TAB_ID_NONE)
props.audioMuted = frame.get('audioMuted')

return props
Expand Down
25 changes: 10 additions & 15 deletions app/renderer/components/tabs/content/closeTabIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ const TabIcon = require('./tabIcon')

// State
const tabContentState = require('../../../../common/state/tabContentState')

// Store
const windowStore = require('../../../../../js/stores/windowStore')
const tabState = require('../../../../common/state/tabState')

// Actions
const windowActions = require('../../../../../js/actions/windowActions')
Expand All @@ -35,14 +33,9 @@ class CloseTabIcon extends React.Component {
this.onDragStart = this.onDragStart.bind(this)
}

get frame () {
return windowStore.getFrame(this.props.frameKey)
}

onClick (event) {
event.stopPropagation()
const frame = this.frame
if (frame && !frame.isEmpty()) {
if (this.props.hasFrame) {
windowActions.onTabClosedWithMouse({
fixTabWidth: this.props.fixTabWidth
})
Expand All @@ -56,21 +49,23 @@ class CloseTabIcon extends React.Component {

mergeProps (state, ownProps) {
const currentWindow = state.get('currentWindow')
const isPinnedTab = frameStateUtil.isPinned(currentWindow, ownProps.frameKey)
const frame = frameStateUtil.getFrameByKey(currentWindow, ownProps.frameKey) || Immutable.Map()
const frameKey = ownProps.frameKey
const isPinnedTab = frameStateUtil.isPinned(currentWindow, frameKey)
const frame = frameStateUtil.getFrameByKey(currentWindow, frameKey) || Immutable.Map()

const props = {}
// used in renderer
props.showCloseIcon = !isPinnedTab &&
(
tabContentState.hasRelativeCloseIcon(currentWindow, ownProps.frameKey) ||
tabContentState.hasFixedCloseIcon(currentWindow, ownProps.frameKey)
tabContentState.hasRelativeCloseIcon(currentWindow, frameKey) ||
tabContentState.hasFixedCloseIcon(currentWindow, frameKey)
)

// used in functions
props.frameKey = ownProps.frameKey
props.frameKey = frameKey
props.fixTabWidth = ownProps.fixTabWidth
props.tabId = frame.get('tabId')
props.tabId = frame.get('tabId', tabState.TAB_ID_NONE)
props.hasFrame = !frame.isEmpty()

return props
}
Expand Down
13 changes: 7 additions & 6 deletions app/renderer/components/tabs/content/favIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,20 @@ class Favicon extends React.Component {

mergeProps (state, ownProps) {
const currentWindow = state.get('currentWindow')
const frame = frameStateUtil.getFrameByKey(currentWindow, ownProps.frameKey) || Immutable.Map()
const isTabLoading = tabContentState.isTabLoading(currentWindow, ownProps.frameKey)
const frameKey = ownProps.frameKey
const frame = frameStateUtil.getFrameByKey(currentWindow, frameKey) || Immutable.Map()
const isTabLoading = tabContentState.isTabLoading(currentWindow, frameKey)

const props = {}
// used in renderer
props.isTabLoading = isTabLoading
props.favicon = !isTabLoading && frame.get('icon')
props.isPinnedTab = frameStateUtil.isPinned(currentWindow, ownProps.frameKey)
props.tabIconColor = tabContentState.getTabIconColor(currentWindow, ownProps.frameKey)
props.isNarrowestView = tabContentState.isNarrowestView(currentWindow, ownProps.frameKey)
props.isPinnedTab = frameStateUtil.isPinned(currentWindow, frameKey)
props.tabIconColor = tabContentState.getTabIconColor(currentWindow, frameKey)
props.isNarrowestView = tabContentState.isNarrowestView(currentWindow, frameKey)

// used in functions
props.frameKey = ownProps.frameKey
props.frameKey = frameKey

return props
}
Expand Down
11 changes: 6 additions & 5 deletions app/renderer/components/tabs/content/newSessionIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,23 @@ const newSessionSvg = require('../../../../extensions/brave/img/tabs/new_session
class NewSessionIcon extends React.Component {
mergeProps (state, ownProps) {
const currentWindow = state.get('currentWindow')
const frame = frameStateUtil.getFrameByKey(currentWindow, ownProps.frameKey) || Immutable.Map()
const frameKey = ownProps.frameKey
const frame = frameStateUtil.getFrameByKey(currentWindow, frameKey) || Immutable.Map()
const partition = frame.get('partitionNumber')

const props = {}
// used in renderer
props.isActive = frameStateUtil.isFrameKeyActive(currentWindow, ownProps.frameKey)
props.iconColor = tabContentState.getTabIconColor(currentWindow, ownProps.frameKey)
props.isActive = frameStateUtil.isFrameKeyActive(currentWindow, frameKey)
props.iconColor = tabContentState.getTabIconColor(currentWindow, frameKey)
props.partitionNumber = typeof partition === 'string'
? partition.replace(/^partition-/i, '')
: partition
props.partitionIndicator = props.partitionNumber > tabs.maxAllowedNewSessions
? tabs.maxAllowedNewSessions
: props.partitionNumber

// used in funtions
props.frameKey = ownProps.frameKey
// used in functions
props.frameKey = frameKey

return props
}
Expand Down
5 changes: 3 additions & 2 deletions app/renderer/components/tabs/content/privateIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ const privateSvg = require('../../../../extensions/brave/img/tabs/private.svg')
class PrivateIcon extends React.Component {
mergeProps (state, ownProps) {
const currentWindow = state.get('currentWindow')
const frameKey = ownProps.frameKey

const props = {}
// used in renderer
props.isActive = frameStateUtil.isFrameKeyActive(currentWindow, ownProps.frameKey)
props.isActive = frameStateUtil.isFrameKeyActive(currentWindow, frameKey)

// used in functions
props.frameKey = ownProps.frameKey
props.frameKey = frameKey

return props
}
Expand Down
Loading

0 comments on commit bebfb2e

Please sign in to comment.