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

Commit

Permalink
Converts Main into redux component
Browse files Browse the repository at this point in the history
Resolves #9452

Auditors: @bbondy @bridiver @bsclifton

Test Plan:
  • Loading branch information
NejcZdovc committed Jun 30, 2017
1 parent 4cc1273 commit a59c4ba
Show file tree
Hide file tree
Showing 14 changed files with 342 additions and 298 deletions.
105 changes: 53 additions & 52 deletions app/browser/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const electron = require('electron')
const appConfig = require('../../js/constants/appConfig')
const appActions = require('../../js/actions/appActions')
const appConstants = require('../../js/constants/appConstants')
const appDispatcher = require('../../js/dispatcher/appDispatcher')
const appStore = require('../../js/stores/appStore')
const windowConstants = require('../../js/constants/windowConstants')
const Menu = electron.Menu
Expand All @@ -22,7 +21,7 @@ const dialog = electron.dialog
const app = electron.app
const BrowserWindow = electron.BrowserWindow
const {fileUrl} = require('../../js/lib/appUrlUtil')
const {isValidClosedFrame} = require('../../js/state/frameStateUtil')
const frameStateUtil = require('../../js/state/frameStateUtil')
const menuUtil = require('../common/lib/menuUtil')
const {getByTabId} = require('../common/state/tabState')
const getSetting = require('../../js/settings').getSetting
Expand Down Expand Up @@ -615,113 +614,115 @@ const setMenuItemChecked = (label, checked) => {
}
}

const doAction = (action) => {
const doAction = (state, action) => {
switch (action.actionType) {
case windowConstants.WINDOW_SET_FOCUSED_FRAME:
// Update the checkbox next to "Bookmark Page" (Bookmarks menu)
currentLocation = action.frameProps.get('location')
setMenuItemChecked(locale.translation('bookmarkPage'), isCurrentLocationBookmarked())
case appConstants.APP_SET_STATE:
createMenu()
break
case windowConstants.WINDOW_SET_FOCUSED_FRAME:
{
// Update the checkbox next to "Bookmark Page" (Bookmarks menu)
const frame = frameStateUtil.getFrameByTabId(state, action.tabId)
if (frame) {
currentLocation = frame.location
setMenuItemChecked(locale.translation('bookmarkPage'), isCurrentLocationBookmarked())
}
break
}
case appConstants.APP_CHANGE_SETTING:
if (action.key === settings.SHOW_BOOKMARKS_TOOLBAR) {
// Update the checkbox next to "Bookmarks Toolbar" (Bookmarks menu)
setMenuItemChecked(locale.translation('bookmarksToolbar'), action.value)
}
break
case windowConstants.WINDOW_UNDO_CLOSED_FRAME:
appDispatcher.waitFor([appStore.dispatchToken], () => {
{
if (!lastClosedUrl) {
return
}
closedFrames = closedFrames.delete(lastClosedUrl)
const nextLastFrame = closedFrames.last()
lastClosedUrl = nextLastFrame ? nextLastFrame.get('location') : null
updateRecentlyClosedMenuItems()
})
break
break
}
case windowConstants.WINDOW_CLEAR_CLOSED_FRAMES:
appDispatcher.waitFor([appStore.dispatchToken], () => {
{
closedFrames = new Immutable.OrderedMap()
lastClosedUrl = null
updateRecentlyClosedMenuItems()
})
break
break
}
case appConstants.APP_TAB_CLOSE_REQUESTED:
appDispatcher.waitFor([appStore.dispatchToken], () => {
{
action = makeImmutable(action)
const tab = getByTabId(appStore.getState(), action.get('tabId'))
const tab = getByTabId(state, action.get('tabId'))
const frame = tab && tab.get('frame')
if (tab && !tab.get('incognito') && frame && isValidClosedFrame(frame)) {
if (tab && !tab.get('incognito') && frame && frameStateUtil.isValidClosedFrame(frame)) {
lastClosedUrl = tab.get('url')
closedFrames = closedFrames.set(tab.get('url'), tab.get('frame'))
updateRecentlyClosedMenuItems()
}
})
break
break
}
case appConstants.APP_APPLY_SITE_RECORDS:
if (action.records.find((record) => record.objectData === 'bookmark')) {
appDispatcher.waitFor([appStore.dispatchToken], () => {
createMenu()
})
createMenu()
}
break
case appConstants.APP_ADD_SITE:
if (action.tag === siteTags.BOOKMARK || action.tag === siteTags.BOOKMARK_FOLDER) {
appDispatcher.waitFor([appStore.dispatchToken], () => {
{
if (action.tag === siteTags.BOOKMARK || action.tag === siteTags.BOOKMARK_FOLDER) {
createMenu()
})
} else if (action.siteDetail.constructor === Immutable.List && action.tag === undefined) {
let shouldRebuild = false
action.siteDetail.forEach((site) => {
const tag = site.getIn(['tags', 0])
if (tag === siteTags.BOOKMARK || tag === siteTags.BOOKMARK_FOLDER) {
shouldRebuild = true
}
})
if (shouldRebuild) {
appDispatcher.waitFor([appStore.dispatchToken], () => {
createMenu()
} else if (action.siteDetail.constructor === Immutable.List && action.tag === undefined) {
let shouldRebuild = false
action.siteDetail.forEach((site) => {
const tag = site.getIn(['tags', 0])
if (tag === siteTags.BOOKMARK || tag === siteTags.BOOKMARK_FOLDER) {
shouldRebuild = true
}
})
if (shouldRebuild) {
createMenu()
}
}
break
}
break
case appConstants.APP_REMOVE_SITE:
if (action.tag === siteTags.BOOKMARK || action.tag === siteTags.BOOKMARK_FOLDER) {
appDispatcher.waitFor([appStore.dispatchToken], () => {
{
if (action.tag === siteTags.BOOKMARK || action.tag === siteTags.BOOKMARK_FOLDER) {
createMenu()
})
}
break
}
break
case appConstants.APP_ON_CLEAR_BROWSING_DATA:
appDispatcher.waitFor([appStore.dispatchToken], () => {
const state = appStore.getState()
{
const defaults = state.get('clearBrowsingDataDefaults')
const temp = state.get('tempClearBrowsingData', Immutable.Map())
const clearData = defaults ? defaults.merge(temp) : temp
if (clearData.get('browserHistory')) {
createMenu()
}
})
break
break
}
case windowConstants.WINDOW_CLICK_MENUBAR_SUBMENU:
appDispatcher.waitFor([appStore.dispatchToken], () => {
{
const clickedMenuItem = menuUtil.getMenuItem(appMenu, action.label)
if (clickedMenuItem) {
const focusedWindow = BrowserWindow.getFocusedWindow()
clickedMenuItem.click(clickedMenuItem, focusedWindow, focusedWindow.webContents)
}
})
break
break
}
default:
}

return state
}

/**
* Sets up the menu.
* @param {Object} appState - Application state. Used to fetch bookmarks and settings (like homepage)
*/
module.exports.init = (appState) => {
createMenu()
appDispatcher.register(doAction)
return appState
}

module.exports = doAction
4 changes: 2 additions & 2 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,10 @@ app.on('ready', () => {
}
})

ipcMain.on(messages.CHECK_CERT_ERROR_ACCEPTED, (event, host, frameKey) => {
ipcMain.on(messages.CHECK_CERT_ERROR_ACCEPTED, (event, host, tabId) => {
// If the host is associated with a URL with a cert error, update the
// security state to insecure
event.sender.send(messages.SET_SECURITY_STATE, frameKey, {
event.sender.send(messages.SET_SECURITY_STATE, tabId, {
secure: 2
})
})
Expand Down
22 changes: 11 additions & 11 deletions app/renderer/components/frame/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ class Frame extends React.Component {
}
}

onPropsChanged (prevProps = {}) {
onPropsChanged () {
if (this.props.isActive && isFocused()) {
windowActions.setFocusedFrame(this.frame)
windowActions.setFocusedFrame(this.props.location, this.props.tabId)
}
}

Expand Down Expand Up @@ -270,7 +270,7 @@ class Frame extends React.Component {
this.lastFrame = this.frame.delete('lastAccessedTime')

const cb = (prevProps = {}) => {
this.onPropsChanged(prevProps)
this.onPropsChanged()
if (this.props.isActive && !prevProps.isActive && !this.props.urlBarFocused) {
this.webview.focus()
}
Expand Down Expand Up @@ -469,7 +469,7 @@ class Frame extends React.Component {
return
}
if (e.details[0] === 'javascript' && e.details[1]) {
windowActions.setBlockedBy(this.frame, 'noScript', e.details[1])
windowActions.setBlockedBy(this.props.tabId, 'noScript', e.details[1])
}
if (e.details[0] === 'autoplay') {
appActions.autoplayBlocked(this.props.tabId)
Expand Down Expand Up @@ -550,7 +550,7 @@ class Frame extends React.Component {
}
method = (detail) => {
const description = [detail.type, detail.scriptUrl || this.props.provisionalLocation].join(': ')
windowActions.setBlockedBy(this.frame, 'fingerprintingProtection', description)
windowActions.setBlockedBy(this.props.tabId, 'fingerprintingProtection', description)
}
break
case messages.THEME_COLOR_COMPUTED:
Expand Down Expand Up @@ -648,7 +648,7 @@ class Frame extends React.Component {

if (url.startsWith(pdfjsOrigin)) {
let displayLocation = UrlUtil.getLocationIfPDF(url)
windowActions.setSecurityState(this.frame, {
windowActions.setSecurityState(this.props.tabId, {
secure: urlParse(displayLocation).protocol === 'https:',
runInsecureContent: false
})
Expand Down Expand Up @@ -706,14 +706,14 @@ class Frame extends React.Component {
} else if (e.securityState === 'broken') {
isSecure = false
const parsedUrl = urlParse(this.props.location)
ipc.send(messages.CHECK_CERT_ERROR_ACCEPTED, parsedUrl.host, this.props.frameKey)
ipc.send(messages.CHECK_CERT_ERROR_ACCEPTED, parsedUrl.host, this.props.tabId)
} else if (['warning', 'passive-mixed-content'].includes(e.securityState)) {
// Passive mixed content should not upgrade an insecure connection to a
// partially-secure connection. It can only downgrade a secure
// connection.
isSecure = this.props.isSecure !== false ? 1 : false
}
windowActions.setSecurityState(this.frame, {
windowActions.setSecurityState(this.props.tabId, {
secure: runInsecureContent ? false : isSecure,
runInsecureContent
})
Expand Down Expand Up @@ -783,15 +783,15 @@ class Frame extends React.Component {
if (this.frame.isEmpty()) {
return
}
windowActions.setFullScreen(this.frame, true, true)
windowActions.setFullScreen(this.props.tabId, true, true)
// disable the fullscreen warning after 5 seconds
setTimeout(windowActions.setFullScreen.bind(this, this.frame, undefined, false), 5000)
setTimeout(windowActions.setFullScreen.bind(this, this.props.tabId, undefined, false), 5000)
})
this.webview.addEventListener('leave-html-full-screen', () => {
if (this.frame.isEmpty()) {
return
}
windowActions.setFullScreen(this.frame, false)
windowActions.setFullScreen(this.props.tabId, false)
})
this.webview.addEventListener('media-started-playing', ({title}) => {
if (this.frame.isEmpty()) {
Expand Down
Loading

0 comments on commit a59c4ba

Please sign in to comment.