diff --git a/app/browser/menu.js b/app/browser/menu.js index 86db4f6e1e6..c2882e3c83e 100644 --- a/app/browser/menu.js +++ b/app/browser/menu.js @@ -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 @@ -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 @@ -615,13 +614,21 @@ 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) @@ -629,7 +636,7 @@ const doAction = (action) => { } break case windowConstants.WINDOW_UNDO_CLOSED_FRAME: - appDispatcher.waitFor([appStore.dispatchToken], () => { + { if (!lastClosedUrl) { return } @@ -637,91 +644,85 @@ const doAction = (action) => { 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 diff --git a/app/index.js b/app/index.js index d739e366fa4..3f0a6b35fe0 100644 --- a/app/index.js +++ b/app/index.js @@ -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 }) }) diff --git a/app/renderer/components/frame/frame.js b/app/renderer/components/frame/frame.js index 4c2c4cbb480..e77dbb1da91 100644 --- a/app/renderer/components/frame/frame.js +++ b/app/renderer/components/frame/frame.js @@ -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) } } @@ -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() } @@ -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) @@ -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: @@ -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 }) @@ -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 }) @@ -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()) { diff --git a/app/renderer/components/main/main.js b/app/renderer/components/main/main.js index 5760814cc99..e221e34b853 100644 --- a/app/renderer/components/main/main.js +++ b/app/renderer/components/main/main.js @@ -3,7 +3,7 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ const React = require('react') -const ImmutableComponent = require('../immutableComponent') +const ReduxComponent = require('../reduxComponent') const Immutable = require('immutable') const electron = require('electron') const urlResolve = require('url').resolve @@ -55,7 +55,6 @@ const siteUtil = require('../../../../js/state/siteUtil') const searchProviders = require('../../../../js/data/searchProviders') const defaultBrowserState = require('../../../common/state/defaultBrowserState') const shieldState = require('../../../common/state/shieldState') -const siteSettingsState = require('../../../common/state/siteSettingsState') const menuBarState = require('../../../common/state/menuBarState') const windowState = require('../../../common/state/windowState') const updateState = require('../../../common/state/updateState') @@ -64,14 +63,13 @@ const updateState = require('../../../common/state/updateState') const _ = require('underscore') const cx = require('../../../../js/lib/classSet') const eventUtil = require('../../../../js/lib/eventUtil') -const siteSettings = require('../../../../js/state/siteSettings') const {isSourceAboutUrl} = require('../../../../js/lib/appUrlUtil') const {getCurrentWindowId, isMaximized, isFocused, isFullScreen} = require('../../currentWindow') const {isDarwin, isWindows, isLinux} = require('../../../common/lib/platformUtil') -class Main extends ImmutableComponent { - constructor () { - super() +class Main extends React.Component { + constructor (props) { + super(props) this.onMouseDown = this.onMouseDown.bind(this) this.onClickWindow = this.onClickWindow.bind(this) this.onHideSiteInfo = this.onHideSiteInfo.bind(this) @@ -112,10 +110,9 @@ class Main extends ImmutableComponent { this.keydownHistory = [] } - registerCustomTitlebarHandlers () { - if (this.customTitlebar.enabled) { + registerCustomTitleBarHandlers () { + if (this.props.showCustomTitleBar) { document.addEventListener('keyup', (e) => { - const customTitlebar = this.customTitlebar switch (e.which) { case keyCodes.LEFT: case keyCodes.RIGHT: @@ -143,7 +140,7 @@ class Main extends ImmutableComponent { if (getSetting(settings.AUTO_HIDE_MENU)) { windowActions.toggleMenubarVisible(null) } else { - if (customTitlebar.menubarSelectedIndex) { + if (this.props.menubarSelectedIndex) { windowActions.setMenuBarSelectedIndex() windowActions.setContextMenuDetail() } else { @@ -152,12 +149,12 @@ class Main extends ImmutableComponent { } break case keyCodes.ESC: - if (getSetting(settings.AUTO_HIDE_MENU) && customTitlebar.menubarVisible && !customTitlebar.menubarSelectedIndex) { + if (getSetting(settings.AUTO_HIDE_MENU) && this.props.menubarVisible && !this.props.menubarSelectedIndex) { e.preventDefault() windowActions.toggleMenubarVisible(false) break } - if (customTitlebar.menubarSelectedIndex) { + if (this.props.menubarSelectedIndex) { e.preventDefault() windowActions.setMenuBarSelectedIndex() windowActions.setContextMenuDetail() @@ -174,7 +171,7 @@ class Main extends ImmutableComponent { delete this.keydown[e.which] }) - document.addEventListener('focus', (e) => { + document.addEventListener('focus', () => { let selector = document.activeElement.id ? '#' + document.activeElement.id : null @@ -192,15 +189,13 @@ class Main extends ImmutableComponent { } exitFullScreen () { - const activeFrame = frameStateUtil.getActiveFrame(this.props.windowState) - if (activeFrame && activeFrame.get('isFullScreen')) { - windowActions.setFullScreen(activeFrame, false) + if (this.props.isFullScreen) { + windowActions.setFullScreen(this.props.tabId, false) } } registerSwipeListener () { // Navigates back/forward on macOS two- and or three-finger swipe - let mouseInFrame = false let trackingFingers = false let startTime = 0 let isSwipeOnLeftEdge = false @@ -211,8 +206,7 @@ class Main extends ImmutableComponent { // isSwipeTrackingFromScrollEventsEnabled is only true if "two finger scroll to swipe" is enabled ipc.on('scroll-touch-begin', () => { - mouseInFrame = this.props.windowState.getIn(['ui', 'mouseInFrame']) - if (mouseInFrame) { + if (this.props.mouseInTitlebar) { trackingFingers = true startTime = (new Date()).getTime() } @@ -257,7 +251,7 @@ class Main extends ImmutableComponent { }) const throttledSwipe = _.throttle(direction => { - if (mouseInFrame) { + if (this.props.mouseInTitlebar) { if (direction === 'left') { ipc.emit(messages.SHORTCUT_ACTIVE_FRAME_BACK) } else if (direction === 'right') { @@ -288,41 +282,38 @@ class Main extends ImmutableComponent { } componentWillUpdate (nextProps) { - if (!this.props.appState.getIn([appConfig.resourceNames.WIDEVINE, 'ready']) && - nextProps.appState.getIn([appConfig.resourceNames.WIDEVINE, 'ready'])) { - const widevinePanelDetail = this.props.windowState.get('widevinePanelDetail') + if (!this.props.isWidevineReady && nextProps.isWidevineReady) { // User may have enabled from preferences and no details are present - if (!widevinePanelDetail) { + if (this.props.widevineLocation) { return } - const origin = siteUtil.getOrigin(widevinePanelDetail.get('location')) + // This automatically handles reloading the frame as well - appActions.changeSiteSetting(origin, appConfig.resourceNames.WIDEVINE, widevinePanelDetail.get('alsoAddRememberSiteSetting') ? 1 : 0) + appActions.changeSiteSetting( + this.props.widevineLocation, + appConfig.resourceNames.WIDEVINE, + this.props.widevineRememberSettings + ) } } componentDidUpdate (prevProps) { this.loadSearchProviders() - const activeFrame = frameStateUtil.getActiveFrame(this.props.windowState) - const activeFramePrev = frameStateUtil.getActiveFrame(prevProps.windowState) - const activeFrameTitle = (activeFrame && (activeFrame.get('title') || activeFrame.get('location'))) || '' - const activeFramePrevTitle = (activeFramePrev && (activeFramePrev.get('title') || activeFramePrev.get('location'))) || '' - if (activeFrameTitle !== activeFramePrevTitle) { - windowActions.shouldSetTitle(getCurrentWindowId(), activeFrameTitle) + if (prevProps.title !== this.props.title) { + windowActions.shouldSetTitle(getCurrentWindowId(), this.props.title) } // If the tab changes or was closed, exit out of full screen to give a better // picture of what's happening. - if (activeFramePrev && activeFrame && - activeFrame.get('key') !== activeFramePrev.get('key') && activeFramePrev.get('isFullScreen')) { - windowActions.setFullScreen(activeFramePrev, false) + if (prevProps.tabId !== this.props.tabId && this.props.isFullScreen) { + windowActions.setFullScreen(this.props.tabId, false) } } componentDidMount () { this.registerSwipeListener() this.registerWindowLevelShortcuts() - this.registerCustomTitlebarHandlers() + this.registerCustomTitleBarHandlers() // DO NOT ADD TO THIS LIST // ipc.on is deprecated and should be replaced by actions/reducers @@ -346,9 +337,8 @@ class Main extends ImmutableComponent { }) ipc.on(messages.OPEN_BRAVERY_PANEL, () => { - const activeFrame = frameStateUtil.getActiveFrame(self.props.windowState) - if (shieldState.braveShieldsEnabled(activeFrame)) { - this.onBraveMenu() + if (this.props.braveShieldEnabled) { + windowActions.setBraveryPanelDetail({}) } else { appActions.maybeCreateTabRequested({ url: 'about:preferences#shields' @@ -366,30 +356,20 @@ class Main extends ImmutableComponent { })) }) - ipc.on(messages.SHORTCUT_CLOSE_FRAME, (e, i) => { - const frame = i == null - ? frameStateUtil.getActiveFrame(this.props.windowState) - : frameStateUtil.getFrameByKey(self.props.windowState, i) - if (frame) { - appActions.tabCloseRequested(frame.get('tabId')) + ipc.on(messages.SHORTCUT_CLOSE_FRAME, (e, tabId) => { + if (tabId == null) { + tabId = this.props.tabId } - }) - ipc.on(messages.SHORTCUT_UNDO_CLOSED_FRAME, () => windowActions.undoClosedFrame()) - ipc.on(messages.SHORTCUT_CLOSE_OTHER_FRAMES, (e, key, isCloseRight, isCloseLeft) => { - const currentIndex = frameStateUtil.getFrameIndex(self.props.windowState, key) - if (currentIndex === -1) { - return + if (tabId) { + appActions.tabCloseRequested(tabId) } + }) - frameStateUtil.getFrames(self.props.windowState).forEach((frame, i) => { - if (!frame.get('pinnedLocation') && - ((i < currentIndex && isCloseLeft) || (i > currentIndex && isCloseRight))) { - if (frame) { - appActions.tabCloseRequested(frame.get('tabId')) - } - } - }) + ipc.on(messages.SHORTCUT_UNDO_CLOSED_FRAME, () => windowActions.undoClosedFrame()) + + ipc.on(messages.SHORTCUT_CLOSE_OTHER_FRAMES, (e, tabId, isCloseRight, isCloseLeft) => { + windowActions.closeOtherFrames(tabId, isCloseRight, isCloseLeft) }) ipc.on(messages.SHOW_DOWNLOADS_TOOLBAR, () => { @@ -400,39 +380,20 @@ class Main extends ImmutableComponent { windowActions.setDownloadsToolbarVisible(false) }) - const self = this ipc.on(messages.BLOCKED_RESOURCE, (e, blockType, details) => { - const frameProps = frameStateUtil.getFrameByTabId(self.props.windowState, details.tabId) - frameProps && windowActions.setBlockedBy(frameProps, blockType, details.url) - }) - - ipc.on(messages.BLOCKED_PAGE, (e, blockType, details) => { - // const frameProps = frameStateUtil.getFrameByTabId(self.props.windowState, details.tabId) - // if (!frameProps) { - // return - // } + windowActions.setBlockedBy(this.props.tabId, blockType, details.url) }) ipc.on(messages.HTTPSE_RULE_APPLIED, (e, ruleset, details) => { - const frameProps = frameStateUtil.getFrameByTabId(self.props.windowState, details.tabId) - frameProps && windowActions.setRedirectedBy(frameProps, ruleset, details.url) + windowActions.setRedirectedBy(details.tabId, ruleset, details.url) }) ipc.on(messages.CERT_ERROR, (e, details) => { - const frame = frameStateUtil.getFrameByTabId(self.props.windowState, details.tabId) - if (frame && (frame.get('location') === details.url || - frame.get('provisionalLocation') === details.url)) { - windowActions.setFrameError(frame, { - url: details.url, - error: details.error - }) - appActions.loadURLRequested(frame.get('tabId'), 'about:certerror') - } + windowActions.onCertError(details.tabId, details.url, details.error) }) - ipc.on(messages.SET_SECURITY_STATE, (e, frameKey, securityState) => { - windowActions.setSecurityState(frameStateUtil.getFrameByKey(self.props.windowState, frameKey), - securityState) + ipc.on(messages.SET_SECURITY_STATE, (e, tabId, securityState) => { + windowActions.setSecurityState(tabId, securityState) }) ipc.on(messages.HIDE_CONTEXT_MENU, () => { @@ -448,14 +409,14 @@ class Main extends ImmutableComponent { this.loadSearchProviders() window.addEventListener('focus', () => { - const activeFrame = frameStateUtil.getActiveFrame(self.props.windowState) - windowActions.setFocusedFrame(activeFrame) + windowActions.setFocusedFrame(this.props.location, this.props.tabId) windowActions.onFocus(getCurrentWindowId()) // For whatever reason other elements are preserved but webviews are not. if (document.activeElement && document.activeElement.tagName === 'BODY') { webviewActions.setWebviewFocused() } }, { passive: true }) + windowActions.onFocus(getCurrentWindowId()) // disable dnd by default @@ -478,24 +439,17 @@ class Main extends ImmutableComponent { return false }, true) - const activeFrame = frameStateUtil.getActiveFrame(self.props.windowState) - if (activeFrame && activeFrame.get('title')) { - windowActions.shouldSetTitle(getCurrentWindowId(), activeFrame.get('title')) + if (this.props.title) { + windowActions.shouldSetTitle(getCurrentWindowId(), this.props.title) } + const self = this window.onblur = () => { self.resetAltMenuProcessing() windowActions.onBlur(getCurrentWindowId()) } } - onBraveMenu () { - const activeFrame = frameStateUtil.getActiveFrame(this.props.windowState) - if (shieldState.braveShieldsEnabled(activeFrame)) { - windowActions.setBraveryPanelDetail({}) - } - } - onHideSiteInfo () { windowActions.setSiteInfoVisible(false) } @@ -520,6 +474,7 @@ class Main extends ImmutableComponent { } node = node.parentNode } + // Hide context menus, popup menus, and menu selections windowActions.resetMenuState() } @@ -538,90 +493,91 @@ class Main extends ImmutableComponent { } onTabContextMenu (e) { - const activeFrame = frameStateUtil.getActiveFrame(this.props.windowState) - contextMenus.onTabsToolbarContextMenu(activeFrame.get('title'), activeFrame.get('location'), undefined, undefined, e) - } - - get allSiteSettings () { - const activeFrame = frameStateUtil.getActiveFrame(this.props.windowState) || Immutable.Map() - return siteSettingsState.getAllSiteSettings(this.props.appState, activeFrame.get('isPrivate')) - } - - frameSiteSettings (location) { - if (!location) { - return undefined - } - return siteSettings.getSiteSettingsForURL(this.allSiteSettings, location) + contextMenus.onTabsToolbarContextMenu(this.props.title, this.props.location, undefined, undefined, e) } - get customTitlebar () { - const menubarVisible = menuBarState.isMenuBarVisible(this.props.windowState) - const selectedIndex = this.props.windowState.getIn(['ui', 'contextMenu', 'selectedIndex']) - return { - enabled: isWindows(), - captionButtonsVisible: isWindows(), - menubarVisible: menubarVisible, - menubarSelectedIndex: this.props.windowState.getIn(['ui', 'menubar', 'selectedIndex']), - contextMenuSelectedIndex: typeof selectedIndex === 'object' && Array.isArray(selectedIndex) && selectedIndex.length > 0 - ? selectedIndex - : null, - isMaximized: isMaximized() || isFullScreen() - } - } - - render () { - // Sort frames by key so that the order of the frames do not change which could - // cause unexpected reloading when a user moves tabs. - // All frame operations work off of frame keys and not index though so unsorted frames - // can be passed everywhere other than the Frame elements. - const sortedFrames = frameStateUtil.getSortedFrames(this.props.windowState) - const activeFrame = frameStateUtil.getActiveFrame(this.props.windowState) - const nonPinnedFrames = frameStateUtil.getNonPinnedFrames(this.props.windowState) + mergeProps (state, ownProps) { + const currentWindow = state.get('currentWindow') + const activeFrame = frameStateUtil.getActiveFrame(currentWindow) || Immutable.Map() + const nonPinnedFrames = frameStateUtil.getNonPinnedFrames(currentWindow) const tabsPerPage = Number(getSetting(settings.TABS_PER_PAGE)) - const showBookmarksToolbar = getSetting(settings.SHOW_BOOKMARKS_TOOLBAR) - const siteInfoIsVisible = this.props.windowState.getIn(['ui', 'siteInfo', 'isVisible']) && !isSourceAboutUrl(activeFrame.get('location')) - const braveryPanelIsVisible = shieldState.braveShieldsEnabled(activeFrame) && - this.props.windowState.get('braveryPanelDetail') - const clearBrowsingDataPanelIsVisible = this.props.windowState.getIn(['ui', 'isClearBrowsingDataPanelVisible']) - const importBrowserDataPanelIsVisible = this.props.windowState.get('importBrowserDataDetail') - const widevinePanelIsVisible = this.props.windowState.getIn(['widevinePanelDetail', 'shown']) && !isLinux() - const autofillAddressPanelIsVisible = this.props.windowState.get('autofillAddressDetail') - const autofillCreditCardPanelIsVisible = this.props.windowState.get('autofillCreditCardDetail') - const noScriptIsVisible = this.props.windowState.getIn(['ui', 'noScriptInfo', 'isVisible']) && + 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 props = {} + // used in renderer + props.isFullScreen = activeFrame.get('isFullScreen', false) + props.isMaximized = isMaximized() || isFullScreen() + props.captionButtonsVisible = isWindows() + props.showContextMenu = !!currentWindow.get('contextMenuDetail') + props.showPopupWindow = !!currentWindow.get('popupWindowDetail') + props.showSiteInfo = currentWindow.getIn(['ui', 'siteInfo', 'isVisible']) && + !isSourceAboutUrl(activeFrame.get('location')) + props.showBravery = shieldState.braveShieldsEnabled(activeFrame) && + !!currentWindow.get('braveryPanelDetail') + props.showClearData = !!currentWindow.getIn(['ui', 'isClearBrowsingDataPanelVisible']) + props.showImportData = !!currentWindow.get('importBrowserDataDetail') + props.showWidevine = currentWindow.getIn(['widevinePanelDetail', 'shown']) && !isLinux() + props.showAutoFillAddress = !!currentWindow.get('autofillAddressDetail') + props.showAutoFillCC = !!currentWindow.get('autofillCreditCardDetail') + props.showLogin = !!loginRequiredDetails + props.showBookmarkHanger = currentWindow.get('bookmarkDetail') && + !currentWindow.getIn(['bookmarkDetail', 'isBookmarkHanger']) + props.showNoScript = currentWindow.getIn(['ui', 'noScriptInfo', 'isVisible']) && siteUtil.getOrigin(activeFrame.get('location')) - const releaseNotesIsVisible = this.props.windowState.getIn(['ui', 'releaseNotes', 'isVisible']) - const checkDefaultBrowserDialogIsVisible = - isFocused() && defaultBrowserState.shouldDisplayDialog(this.props.appState) - const loginRequiredDetails = activeFrame - ? basicAuthState.getLoginRequiredDetail(this.props.appState, activeFrame.get('tabId')) - : null - const loginRequiredUrl = loginRequiredDetails + props.showReleaseNotes = currentWindow.getIn(['ui', 'releaseNotes', 'isVisible']) + props.showCheckDefault = isFocused() && defaultBrowserState.shouldDisplayDialog(state) + props.showUpdate = updateState.isUpdateVisible(state) + props.showBookmarksToolbar = getSetting(settings.SHOW_BOOKMARKS_TOOLBAR) + props.shouldAllowWindowDrag = windowState.shouldAllowWindowDrag(state, currentWindow, activeFrame, isFocused()) + props.isSinglePage = nonPinnedFrames.size <= tabsPerPage + props.showTabPages = nonPinnedFrames.size > tabsPerPage + props.showNotificationBar = activeOrigin && state.get('notifications').filter((item) => + item.get('frameOrigin') ? activeOrigin === item.get('frameOrigin') : true).size > 0 + props.showFindBar = activeFrame.get('findbarShown') && !activeFrame.get('isFullScreen') + props.sortedFrames = frameStateUtil.getSortedFrameKeys(currentWindow) + props.showDownloadBar = currentWindow.getIn(['ui', 'downloadsToolbar', 'isVisible']) && + state.get('downloads') && state.get('downloads').size > 0 + props.title = activeFrame.get('title') + props.location = activeFrame.get('location') + props.loginRequiredUrl = loginRequiredDetails ? urlResolve(loginRequiredDetails.getIn(['request', 'url']), '/') : null - const customTitlebar = this.customTitlebar - const contextMenuDetail = this.props.windowState.get('contextMenuDetail') - const shouldAllowWindowDrag = windowState.shouldAllowWindowDrag(this.props.appState, this.props.windowState, activeFrame, isFocused()) - const activeOrigin = activeFrame ? siteUtil.getOrigin(activeFrame.get('location')) : null - const notificationBarIsVisible = activeOrigin && this.props.appState.get('notifications').filter((item) => - item.get('frameOrigin') ? activeOrigin === item.get('frameOrigin') : true).size > 0 - const updateIsVisible = updateState.isUpdateVisible(this.props.appState) + // used in other functions + props.menubarSelectedIndex = currentWindow.getIn(['ui', 'menubar', 'selectedIndex']) + props.showCustomTitleBar = isWindows() + props.menubarVisible = menuBarState.isMenuBarVisible(currentWindow) + props.mouseInTitlebar = currentWindow.getIn(['ui', 'mouseInTitlebar']) + props.braveShieldEnabled = shieldState.braveShieldsEnabled(activeFrame) + props.tabId = activeFrame.get('tabId') + props.location = activeFrame.get('location') + props.activeFrameKey = activeFrame.get('key') + props.isWidevineReady = state.getIn([appConfig.resourceNames.WIDEVINE, 'ready']) + props.widevineLocation = siteUtil.getOrigin(widevinePanelDetail.get('location')) + props.widevineRememberSettings = widevinePanelDetail.get('alsoAddRememberSiteSetting') ? 1 : 0 + + return props + } + + render () { return