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

Commit

Permalink
Frame -> redux component
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Apr 11, 2017
1 parent 6f84ad0 commit 3e38b43
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 114 deletions.
15 changes: 15 additions & 0 deletions app/common/state/aboutHistoryState.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,32 @@

const {makeImmutable} = require('./immutableUtil')
const historyUtil = require('../lib/historyUtil')
const appActions = require('../../../js/actions/appActions')

const aboutHistoryState = {
getHistory: (state) => {
state = makeImmutable(state)
return state.getIn(['about', 'history'])
},

setHistory: (state) => {
state = makeImmutable(state)
state = state.setIn(['about', 'history', 'entries'],
historyUtil.getHistory(state.get('sites')))
return state.setIn(['about', 'history', 'updatedStamp'], new Date().getTime())
},

buildHistory: (state, frame) => {
if (frame.get('location') === 'about:history') {
const history = this.getHistory(state)
if (history) {
return history
}

appActions.populateHistory()
}

return null
}
}

Expand Down
45 changes: 45 additions & 0 deletions app/common/state/siteState.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const assert = require('assert')
const Immutable = require('immutable')
const { makeImmutable, isMap, isList } = require('./immutableUtil')
const siteTags = require('../../../js/constants/siteTags')
const siteSettings = require('../../../js/state/siteSettings')
const appConfig = require('../../../js//constants/appConfig')

const validateState = function (state) {
state = makeImmutable(state)
assert.ok(isMap(state), 'state must be an Immutable.Map')
assert.ok(isList(state.get('sites')), 'state must contain an Immutable.List of sites')
return state
}

const siteState = {
getSites: (state) => {
state = validateState(state)
return state.get('sites')
},

getBookmarkFolders: (state) => {
const sites = this.getSites(state)
return sites.filter((site) => site.get('tags')
.includes(siteTags.BOOKMARK_FOLDER)) || new Immutable.Map()
},

getBookmarks: (state) => {
const sites = this.getSites(state)
return sites.filter((site) => site.get('tags')
.includes(siteTags.BOOKMARK)) || new Immutable.Map()
},

getAllSiteSettings: (state, frame) => {
if (frame && frame.get('isPrivate')) {
return state.get('siteSettings').mergeDeep(state.get('temporarySiteSettings'))
}
return state.get('siteSettings')
},

enabledNoScript (state, settings) {
return siteSettings.activeSettings(settings, state, appConfig).noScript === true
}
}

module.exports = siteState
105 changes: 97 additions & 8 deletions js/components/frame.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 ReduxComponent = require('../../app/renderer/components/reduxComponent')
const urlParse = require('../../app/common/urlParse')
const windowActions = require('../actions/windowActions')
const appActions = require('../actions/appActions')
Expand All @@ -25,14 +26,16 @@ const {aboutUrls, isSourceMagnetUrl, isSourceAboutUrl, isTargetAboutUrl, getTarg
const {isFrameError, isAborted} = require('../../app/common/lib/httpUtil')
const locale = require('../l10n')
const appConfig = require('../constants/appConfig')
const {getSiteSettingsForHostPattern} = require('../state/siteSettings')
const {currentWindowWebContents, isFocused} = require('../../app/renderer/currentWindow')
const windowStore = require('../stores/windowStore')
const appStoreRenderer = require('../stores/appStoreRenderer')
const siteSettings = require('../state/siteSettings')
const {newTabMode} = require('../../app/common/constants/settingsEnums')
const imageUtil = require('../lib/imageUtil')
const MessageBox = require('../../app/renderer/components/messageBox')
const siteState = require('../../app/common/state/siteState')
const tabState = require('../../app/common/state/tabState')
const aboutHistoryState = require('../../app/common/state/aboutHistoryState')

const WEBRTC_DEFAULT = 'default'
const WEBRTC_DISABLE_NON_PROXY = 'disable_non_proxied_udp'
Expand Down Expand Up @@ -245,7 +248,7 @@ class Frame extends ImmutableComponent {
}

runInsecureContent () {
const activeSiteSettings = getSiteSettingsForHostPattern(this.props.allSiteSettings, this.origin)
const activeSiteSettings = siteSettings.getSiteSettingsForHostPattern(this.props.allSiteSettings, this.origin)
return activeSiteSettings === undefined
? false : activeSiteSettings.get('runInsecureContent')
}
Expand All @@ -262,7 +265,7 @@ class Frame extends ImmutableComponent {
if (!this.props.allSiteSettings) {
return false
}
const activeSiteSettings = getSiteSettingsForHostPattern(this.props.allSiteSettings,
const activeSiteSettings = siteSettings.getSiteSettingsForHostPattern(this.props.allSiteSettings,
origin)
if (activeSiteSettings && typeof activeSiteSettings.get('widevine') === 'number') {
return true
Expand All @@ -273,7 +276,7 @@ class Frame extends ImmutableComponent {
expireContentSettings (origin) {
// Expired Flash settings should be deleted when the webview is
// navigated or closed. Same for NoScript's allow-once option.
const activeSiteSettings = getSiteSettingsForHostPattern(this.props.allSiteSettings,
const activeSiteSettings = siteSettings.getSiteSettingsForHostPattern(this.props.allSiteSettings,
origin)
if (!activeSiteSettings) {
return
Expand Down Expand Up @@ -1128,7 +1131,7 @@ class Frame extends ImmutableComponent {

onFindAgain (forward) {
if (!this.props.findbarShown) {
windowActions.setFindbarShown(this.frame, true)
windowActions.setFindbarShown(this.props.frame, true)
}
const searchString = this.props.findDetail && this.props.findDetail.get('searchString')
if (searchString) {
Expand Down Expand Up @@ -1164,10 +1167,96 @@ class Frame extends ImmutableComponent {
}
}

mergeProps (state, dispatchProps, ownProps) {
const currentWindow = state.get('currentWindow')
const frame = frameStateUtil.getFrameByKey(currentWindow, ownProps.frameKey)
const activeFrame = frameStateUtil.getActiveFrame(currentWindow)
const emptyMap = new Immutable.Map()
const allSiteSettings = siteState.getAllSiteSettings(state, activeFrame)
const frameSiteSettings = frame.get('location')
? siteSettings.getSiteSettingsForURL(allSiteSettings, frame.get('location'))
: undefined
const baseUrl = getBaseUrl(frame.get('location'))

const props = {
frame,
tabIndex: frameStateUtil.getFrameIndex(currentWindow, frame.get('key')),
tabData: tabState.getByTabId(state, frame.get('tabId')),
urlBarFocused: activeFrame && activeFrame.getIn(['navbar', 'urlbar', 'focused']),
contextMenuDetail: currentWindow.get('contextMenuDetail'),
partition: frameStateUtil.getPartition(frame),
settings: ['about:preferences', 'about:history', 'about:adblock'].includes(baseUrl)
? state.get('settings') || emptyMap
: null,
bookmarks: frame.get('location') === 'about:bookmarks'
? siteState.getBookmarks(state)
: null,
history: aboutHistoryState.buildHistory(state, frame),
extensions: ['about:extensions', 'about:preferences'].includes(baseUrl)
? state.get('extensions') || emptyMap
: null,
preferencesData: frame.get('location') === 'about:preferences#payments'
? state.getIn(['about', 'preferences']) || emptyMap
: null,
downloads: state.get('downloads') || emptyMap,
bookmarkFolders: frame.get('location') === 'about:bookmarks'
? siteState.getBookmarkFolders(state)
: null,
isFullScreen: frame.get('isFullScreen'),
isSecure: frame.getIn(['security', 'isSecure']),
showFullScreenWarning: frame.get('showFullScreenWarning'),
findbarShown: frame.get('findbarShown'),
findDetail: frame.get('findDetail'),
hrefPreview: frame.get('hrefPreview'),
showOnRight: frame.get('showOnRight'),
location: frame.get('location'),
isPrivate: frame.get('isPrivate'),
partitionNumber: frame.get('partitionNumber'),
activeShortcut: frame.get('activeShortcut'),
activeShortcutDetails: frame.get('activeShortcutDetails'),
provisionalLocation: frame.get('provisionalLocation'),
pinnedLocation: frame.get('pinnedLocation'),
src: frame.get('src'),
guestInstanceId: frame.get('guestInstanceId'),
tabId: frame.get('tabId'),
aboutDetails: frame.get('aboutDetails'),
unloaded: frame.get('unloaded'),
audioMuted: frame.get('audioMuted'),
passwords: state.get('passwords'),
adblock: state.get('adblock'),
safeBrowsing: state.get('safeBrowsing'),
httpsEverywhere: state.get('httpsEverywhere'),
trackingProtection: state.get('trackingProtection'),
adInsertion: state.get('adInsertion'),
noScript: state.get('noScript'),
flash: state.get('flash'),
widevine: state.get('widevine'),
cookieblock: state.get('cookieblock'),
allSiteSettings: allSiteSettings,
sync: state.get('sync') || new Immutable.Map(),
ledgerInfo: state.get('ledgerInfo') || new Immutable.Map(),
publisherInfo: state.get('publisherInfo') || new Immutable.Map(),
versionInformation: state.getIn(['about', 'brave', 'versionInformation']),
braveryDefaults: Immutable.fromJS(siteSettings.braveryDefaults(state, appConfig)),
isPreview: frame.get('key') === currentWindow.get('previewFrameKey'),
isActive: frameStateUtil.isFrameKeyActive(currentWindow, frame.get('key')),
autofillCreditCards: state.getIn(['autofill', 'creditCards']),
autofillAddresses: state.getIn(['autofill', 'addresses']),
adblockCount: state.getIn(['adblock', 'count']),
trackedBlockersCount: state.getIn(['trackingProtection', 'count']),
httpsUpgradedCount: state.getIn(['httpsEverywhere', 'count']),
newTabDetail: frame.get('location') === 'about:newtab' ? state.getIn(['about', 'newtab']) : null,
frameSiteSettings: frameSiteSettings,
enableNoScript: siteState.enabledNoScript(state, frameSiteSettings)
}

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

render () {
const messageBoxDetail = this.tab && this.tab.get('messageBoxDetail')
return <div
data-partition={frameStateUtil.getPartition(this.frame)}
data-partition={frameStateUtil.getPartition(this.props.frame)}
className={cx({
frameWrapper: true,
isPreview: this.props.isPreview,
Expand Down Expand Up @@ -1197,12 +1286,12 @@ class Frame extends ImmutableComponent {
messageBoxDetail
? <MessageBox
isActive={this.props.isActive}
tabId={this.frame.get('tabId')}
tabId={this.props.frame.get('tabId')}
detail={messageBoxDetail} />
: null
}
</div>
}
}

module.exports = Frame
module.exports = ReduxComponent.connect(Frame)
Loading

0 comments on commit 3e38b43

Please sign in to comment.