From 24b50361c60f42490235febb7312c731445aad4e Mon Sep 17 00:00:00 2001 From: NejcZdovc Date: Fri, 14 Apr 2017 20:51:48 +0200 Subject: [PATCH 1/2] Remove ref dependency from Frame Resolves #8322 Auditors: @bsclifton @bridiver Test Plan: - tests are green --- app/browser/reducers/tabsReducer.js | 46 +++++ app/browser/tabs.js | 89 +++++++++- app/common/state/contextMenuState.js | 159 ++++++++++++++++++ .../components/navigation/navigator.js | 21 ++- docs/appActions.md | 56 ++++++ js/actions/appActions.js | 61 +++++++ js/actions/windowActions.js | 28 +++ js/components/frame.js | 61 +------ js/components/main.js | 3 - js/constants/appConstants.js | 7 +- js/constants/windowConstants.js | 4 +- js/contextMenus.js | 98 ----------- js/lib/urlutil.js | 2 +- js/stores/windowStore.js | 21 +-- 14 files changed, 473 insertions(+), 183 deletions(-) create mode 100644 app/common/state/contextMenuState.js diff --git a/app/browser/reducers/tabsReducer.js b/app/browser/reducers/tabsReducer.js index d4116bb9a07..21b8f4d43c4 100644 --- a/app/browser/reducers/tabsReducer.js +++ b/app/browser/reducers/tabsReducer.js @@ -8,6 +8,7 @@ const appConstants = require('../../../js/constants/appConstants') const tabs = require('../tabs') const tabState = require('../../common/state/tabState') const windowConstants = require('../../../js/constants/windowConstants') +const windowAction = require('../../../js/actions/windowActions.js') const {makeImmutable} = require('../../common/state/immutableUtil') const {getFlashResourceId} = require('../../../js/flash') const {l10nErrorText} = require('../../common/lib/httpUtil') @@ -71,6 +72,51 @@ const tabsReducer = (state, action) => { case appConstants.APP_LOAD_URL_IN_ACTIVE_TAB_REQUESTED: state = tabs.loadURLInActiveTab(state, action) break + case appConstants.APP_ON_NAVIGATE_BACK: + state = tabs.goBack(state, action) + break + case appConstants.APP_ON_NAVIGATE_FORWARD: + state = tabs.goForward(state, action) + break + case appConstants.APP_ON_NAVIGATE_INDEX: + state = tabs.goToIndex(state, action) + break + case appConstants.APP_ON_NAVIGATE_BACK_LONG: + { + const history = tabs.getHistoryEntries(state, action) + const tabValue = tabState.getByTabId(state, action.get('tabId')) + const windowId = tabs.getWindowId() + + if (history !== null) { + windowAction.onLongBackHistory( + history, + action.getIn(['rect', 'left']), + action.getIn(['rect', 'bottom']), + tabValue.get('partitionNumber'), + action.get('tabId'), + windowId + ) + } + break + } + case appConstants.APP_ON_NAVIGATE_FORWARD_LONG: + { + const history = tabs.getHistoryEntries(state, action) + const tabValue = tabState.getByTabId(state, action.get('tabId')) + const windowId = tabs.getWindowId() + + if (history !== null) { + windowAction.onLongForwardHistory( + history, + action.getIn(['rect', 'left']), + action.getIn(['rect', 'bottom']), + tabValue.get('partitionNumber'), + action.get('tabId'), + windowId + ) + } + break + } case appConstants.APP_FRAME_CHANGED: state = tabState.updateFrame(state, action) break diff --git a/app/browser/tabs.js b/app/browser/tabs.js index 7241e9b43a1..5b531a808af 100644 --- a/app/browser/tabs.js +++ b/app/browser/tabs.js @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + const appActions = require('../../js/actions/appActions') const config = require('../../js/constants/config') const Immutable = require('immutable') @@ -5,7 +9,7 @@ const tabState = require('../common/state/tabState') const {app, BrowserWindow, extensions, session, ipcMain} = require('electron') const {makeImmutable} = require('../common/state/immutableUtil') const {getTargetAboutUrl, getSourceAboutUrl, isSourceAboutUrl, newFrameUrl} = require('../../js/lib/appUrlUtil') -const {isURL, getUrlFromInput, toPDFJSLocation} = require('../../js/lib/urlutil') +const {isURL, getUrlFromInput, toPDFJSLocation, getDefaultFaviconUrl} = require('../../js/lib/urlutil') const {isSessionPartition} = require('../../js/state/frameStateUtil') const {getOrigin} = require('../../js/state/siteUtil') const {getSetting} = require('../../js/settings') @@ -69,7 +73,7 @@ const getPartitionNumber = (partition) => { } /** - * Obtains the curent partition. + * Obtains the current partition. * Warning: This function has global side effects in that it increments the * global next partition number if isPartitioned is passed into the create options. */ @@ -619,6 +623,87 @@ const api = { api.createTab(state, action) } return state + }, + + goBack: (state, action) => { + action = makeImmutable(action) + const tab = api.getWebContents(action.get('tabId')) + if (tab && !tab.isDestroyed()) { + tab.goBack() + } + return state + }, + + goForward: (state, action) => { + action = makeImmutable(action) + const tab = api.getWebContents(action.get('tabId')) + if (tab && !tab.isDestroyed()) { + tab.goForward() + } + return state + }, + + goToIndex: (state, action) => { + action = makeImmutable(action) + const tab = api.getWebContents(action.get('tabId')) + if (tab && !tab.isDestroyed()) { + tab.goToIndex(action.get('index')) + } + return state + }, + + getWindowId: () => { + if (BrowserWindow.getFocusedWindow()) { + return BrowserWindow.getFocusedWindow().id + } + + return -1 + }, + + getHistoryEntries: (state, action) => { + const tab = api.getWebContents(action.get('tabId')) + const sites = state ? state.get('sites') : null + + if (tab && !tab.isDestroyed()) { + let history = { + count: tab.getEntryCount(), + currentIndex: tab.getCurrentEntryIndex(), + entries: [] + } + + for (let index = 0; index < history.count; index++) { + const url = tab.getURLAtIndex(index) + const title = tab.getTitleAtIndex(index) + + let entry = { + index: index, + url: url, + display: title || url, + icon: null + } + + if (url.startsWith('chrome-extension://')) { + // TODO: return brave lion (or better: get icon from extension if possible as data URI) + } else { + if (sites) { + const site = sites.find(function (element) { return element.get('location') === url }) + if (site) { + entry.icon = site.get('favicon') + } + } + + if (!entry.icon) { + entry.icon = getDefaultFaviconUrl(url) + } + } + + history.entries.push(entry) + } + + return history + } + + return null } } diff --git a/app/common/state/contextMenuState.js b/app/common/state/contextMenuState.js new file mode 100644 index 00000000000..5d7bedf6f87 --- /dev/null +++ b/app/common/state/contextMenuState.js @@ -0,0 +1,159 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +const assert = require('assert') +const eventUtil = require('../../../js/lib/eventUtil.js') +const appActions = require('../../../js/actions/appActions.js') +const windowAction = require('../../../js/actions/windowActions.js') +const config = require('../../../js/constants/config.js') +const CommonMenu = require('../commonMenu.js') +const locale = require('../../../js/l10n.js') +const { makeImmutable, isMap } = require('./immutableUtil') + +const validateAction = function (action) { + action = makeImmutable(action) + assert.ok(isMap(action), 'action must be an Immutable.Map') + return action +} + +const validateState = function (state) { + state = makeImmutable(state) + assert.ok(isMap(state), 'state must be an Immutable.Map') + return state +} + +const contextMenuState = { + setContextMenu: (state, action) => { + action = validateAction(action) + state = validateState(state) + + if (!action.get('detail')) { + if (state.getIn(['contextMenuDetail', 'type']) === 'hamburgerMenu') { + state = state.set('hamburgerMenuWasOpen', true) + } else { + state = state.set('hamburgerMenuWasOpen', false) + } + state = state.delete('contextMenuDetail') + } else { + if (!(action.getIn(['detail', 'type']) === 'hamburgerMenu' && state.get('hamburgerMenuWasOpen'))) { + state = state.set('contextMenuDetail', action.get('detail')) + } + state = state.set('hamburgerMenuWasOpen', false) + } + + return state + }, + + onLongBacHistory: (state, action) => { + action = validateAction(action) + state = validateState(state) + const history = action.get('history') + + const menuTemplate = [] + + if (action.get('tabId') > -1 && history && history.get('entries').size > 0) { + const stopIndex = Math.max(((history.get('currentIndex') - config.navigationBar.maxHistorySites) - 1), -1) + for (let index = (history.get('currentIndex') - 1); index > stopIndex; index--) { + const entry = history.getIn(['entries', index]) + const url = entry.get('url') + + menuTemplate.push({ + label: entry.get('display'), + icon: entry.get('icon'), + click: function (e) { + if (eventUtil.isForSecondaryAction(e)) { + appActions.createTabRequested({ + url, + partitionNumber: action.get('partitionNumber'), + active: !!e.shiftKey + }) + } else { + appActions.onNavigateIndex(action.get('tabId'), index) + } + } + }) + } + + // Always display "Show History" link + menuTemplate.push( + CommonMenu.separatorMenuItem, + { + label: locale.translation('showAllHistory'), + click: function () { + appActions.createTabRequested({ + url: 'about:history' + }) + windowAction.setContextMenuDetail() + } + }) + + state = contextMenuState.setContextMenu(state, makeImmutable({ + detail: { + left: action.get('left'), + top: action.get('top'), + template: menuTemplate + } + })) + } + + return state + }, + + onLongForwardHistory: (state, action) => { + action = validateAction(action) + state = validateState(state) + const history = action.get('history') + + const menuTemplate = [] + + if (action.get('tabId') > -1 && history && history.get('entries').size > 0) { + const stopIndex = Math.min(((history.get('currentIndex') + config.navigationBar.maxHistorySites) + 1), history.get('entries').size) + for (let index = (history.get('currentIndex') + 1); index < stopIndex; index++) { + const entry = history.getIn(['entries', index]) + const url = entry.get('url') + + menuTemplate.push({ + label: entry.get('display'), + icon: entry.get('icon'), + click: function (e) { + if (eventUtil.isForSecondaryAction(e)) { + appActions.createTabRequested({ + url, + partitionNumber: action.get('partitionNumber'), + active: !!e.shiftKey + }) + } else { + appActions.onNavigateIndex(action.get('tabId'), index) + } + } + }) + } + + // Always display "Show History" link + menuTemplate.push( + CommonMenu.separatorMenuItem, + { + label: locale.translation('showAllHistory'), + click: function () { + appActions.createTabRequested({ + url: 'about:history' + }) + windowAction.setContextMenuDetail() + } + }) + + state = contextMenuState.setContextMenu(state, makeImmutable({ + detail: { + left: action.get('left'), + top: action.get('top'), + template: menuTemplate + } + })) + } + + return state + } +} + +module.exports = contextMenuState diff --git a/app/renderer/components/navigation/navigator.js b/app/renderer/components/navigation/navigator.js index 546069d97ed..a15cb3ac98e 100644 --- a/app/renderer/components/navigation/navigator.js +++ b/app/renderer/components/navigation/navigator.js @@ -10,7 +10,6 @@ const ipc = electron.ipcRenderer // Actions const appActions = require('../../../../js/actions/appActions') const windowActions = require('../../../../js/actions/windowActions') -const contextMenus = require('../../../../js/contextMenus') const getSetting = require('../../../../js/settings').getSetting // Components @@ -69,7 +68,7 @@ class Navigator extends ImmutableComponent { }) } } else { - navAction.call(this.activeFrame) + navAction.call(this, this.props.activeTab.get('tabId')) } } @@ -122,19 +121,29 @@ class Navigator extends ImmutableComponent { } onBack (e) { - this.onNav(e, 'canGoBack', 'back', this.activeFrame.goBack) + this.onNav(e, 'canGoBack', 'back', appActions.onNavigateBack) } onForward (e) { - this.onNav(e, 'canGoForward', 'forward', this.activeFrame.goForward) + this.onNav(e, 'canGoForward', 'forward', appActions.onNavigateForward) } onBackLongPress (target) { - contextMenus.onBackButtonHistoryMenu(this.activeFrame, this.activeFrame.getHistory(this.props.appState), target) + const activeTab = this.props.activeTab + const rect = target.parentNode.getBoundingClientRect() + appActions.onNavigateBackLong(activeTab.get('tabId'), { + left: rect.left, + bottom: rect.bottom + }) } onForwardLongPress (target) { - contextMenus.onForwardButtonHistoryMenu(this.activeFrame, this.activeFrame.getHistory(this.props.appState), target) + const activeTab = this.props.activeTab + const rect = target.parentNode.getBoundingClientRect() + appActions.onNavigateForwardLong(activeTab.get('tabId'), { + left: rect.left, + bottom: rect.bottom + }) } onDragOver (e) { diff --git a/docs/appActions.md b/docs/appActions.md index 5bf3478d23a..d022aadc7d3 100644 --- a/docs/appActions.md +++ b/docs/appActions.md @@ -955,6 +955,62 @@ Notifies the app that a drop operation occurred +### onNavigateBack(tabId) + +Go back in a history for a given tab + +**Parameters** + +**tabId**: `number`, Tab id used for an action + + + +### onNavigateForward(tabId) + +Go forward in a history for a given tab + +**Parameters** + +**tabId**: `number`, Tab id used for an action + + + +### onNavigateIndex(tabId, index) + +Go to specific item in a history for a given tab + +**Parameters** + +**tabId**: `number`, Tab id used for an action + +**index**: `number`, Index in the history + + + +### onNavigateBackLong(tabId, rect) + +Go back in a history for a given tab + +**Parameters** + +**tabId**: `number`, Tab id used for an action + +**rect**: `ClientRect`, Parent element position for this action + + + +### onNavigateForwardLong(tabId, rect) + +Go forward in a history for a given tab + +**Parameters** + +**tabId**: `number`, Tab id used for an action + +**rect**: `ClientRect`, Parent element position for this action + + + * * * diff --git a/js/actions/appActions.js b/js/actions/appActions.js index e64e53043a1..4fe05a28e6a 100644 --- a/js/actions/appActions.js +++ b/js/actions/appActions.js @@ -1198,6 +1198,67 @@ const appActions = { actionType: appConstants.APP_DRAGGED_OVER, draggedOverData }) + }, + + /** + * Go back in a history for a given tab + * @param {number} tabId - Tab id used for an action + */ + onNavigateBack: function (tabId) { + AppDispatcher.dispatch({ + actionType: appConstants.APP_ON_NAVIGATE_BACK, + tabId + }) + }, + + /** + * Go forward in a history for a given tab + * @param {number} tabId - Tab id used for an action + */ + onNavigateForward: function (tabId) { + AppDispatcher.dispatch({ + actionType: appConstants.APP_ON_NAVIGATE_FORWARD, + tabId + }) + }, + + /** + * Go to specific item in a history for a given tab + * @param {number} tabId - Tab id used for an action + * @param {number} index - Index in the history + */ + onNavigateIndex: function (tabId, index) { + AppDispatcher.dispatch({ + actionType: appConstants.APP_ON_NAVIGATE_INDEX, + tabId, + index + }) + }, + + /** + * Go back in a history for a given tab + * @param {number} tabId - Tab id used for an action + * @param {ClientRect} rect - Parent element position for this action + */ + onNavigateBackLong: function (tabId, rect) { + AppDispatcher.dispatch({ + actionType: appConstants.APP_ON_NAVIGATE_BACK_LONG, + tabId, + rect + }) + }, + + /** + * Go forward in a history for a given tab + * @param {number} tabId - Tab id used for an action + * @param {ClientRect} rect - Parent element position for this action + */ + onNavigateForwardLong: function (tabId, rect) { + AppDispatcher.dispatch({ + actionType: appConstants.APP_ON_NAVIGATE_FORWARD_LONG, + tabId, + rect + }) } } diff --git a/js/actions/windowActions.js b/js/actions/windowActions.js index 0f21d744d8b..070adccd2b2 100644 --- a/js/actions/windowActions.js +++ b/js/actions/windowActions.js @@ -1179,6 +1179,34 @@ const windowActions = { actionType: windowConstants.WINDOW_ON_EXIT_FULL_SCREEN, windowId }) + }, + + onLongBackHistory: function (history, left, top, partition, tabId, windowId) { + dispatch({ + actionType: windowConstants.WINDOW_ON_NAVIGATE_BACK_LONG, + queryInfo: { + windowId + }, + history, + left, + top, + partition, + tabId + }) + }, + + onLongForwardHistory: function (history, left, top, partition, tabId, windowId) { + dispatch({ + actionType: windowConstants.WINDOW_ON_NAVIGATE_FORWARD_LONG, + queryInfo: { + windowId + }, + history, + left, + top, + partition, + tabId + }) } } diff --git a/js/components/frame.js b/js/components/frame.js index 49672f46e67..fafc6756e32 100644 --- a/js/components/frame.js +++ b/js/components/frame.js @@ -629,10 +629,10 @@ class Frame extends ImmutableComponent { method = () => this.webview.stop() break case messages.GO_BACK: - method = () => this.webview.goBack() + method = () => appActions.onNavigateBack(this.props.tabId) break case messages.GO_FORWARD: - method = () => this.webview.goForward() + method = () => appActions.onNavigateForward(this.props.tabId) break case messages.RELOAD: method = () => { @@ -728,7 +728,7 @@ class Frame extends ImmutableComponent { } else if (isTargetAboutUrl(e.validatedURL)) { // open a new tab for other about urls // and send this tab back to wherever it came from - this.goBack() + appActions.tabNavigateBack(this.props.tabId) appActions.createTabRequested({ url: e.validatedURL, active: true @@ -904,61 +904,6 @@ class Frame extends ImmutableComponent { this.webview.addEventListener('mousewheel', this.onMouseWheel.bind(this)) } - goBack () { - this.webview.goBack() - } - - getHistoryEntry (sites, index) { - const url = this.webview.getURLAtIndex(index) - const title = this.webview.getTitleAtIndex(index) - - let entry = { - index: index, - url: url, - display: title || url, - icon: null - } - - if (url.startsWith('chrome-extension://')) { - // TODO: return brave lion (or better: get icon from extension if possible as data URI) - } else { - if (sites) { - const site = sites.find(function (element) { return element.get('location') === url }) - if (site) { entry.icon = site.get('favicon') } - } - - if (!entry.icon) { entry.icon = UrlUtil.getDefaultFaviconUrl(url) } - } - - return entry - } - - getHistory (appState) { - const historyCount = this.webview.getEntryCount() - const currentIndex = this.webview.getCurrentEntryIndex() - const sites = appState ? appState.get('sites') : null - - let history = { - count: historyCount, - currentIndex, - entries: [] - } - - for (let index = 0; index < historyCount; index++) { - history.entries.push(this.getHistoryEntry(sites, index)) - } - - return history - } - - goToIndex (index) { - this.webview.goToIndex(index) - } - - goForward () { - this.webview.goForward() - } - get origin () { return siteUtil.getOrigin(this.props.location) } diff --git a/js/components/main.js b/js/components/main.js index 5bb6d619354..ec6997793f8 100644 --- a/js/components/main.js +++ b/js/components/main.js @@ -688,7 +688,6 @@ class Main extends ImmutableComponent { // can be passed everywhere other than the Frame elements. const sortedFrames = frameStateUtil.getSortedFrames(this.props.windowState) const activeFrame = frameStateUtil.getActiveFrame(this.props.windowState) - this.frames = {} const allSiteSettings = this.allSiteSettings const lastCommittedURL = frameStateUtil.getLastCommittedURL(activeFrame) const activeSiteSettings = this.frameSiteSettings(lastCommittedURL) @@ -760,7 +759,6 @@ class Main extends ImmutableComponent { { this.frames[frame.get('key')] = node }} urlBarFocused={activeFrame && activeFrame.getIn(['navbar', 'urlbar', 'focused'])} tabIndex={frameStateUtil.getFrameIndex(this.props.windowState, frame.get('key'))} prefOpenInForeground={getSetting(settings.SWITCH_TO_NEW_TABS)} diff --git a/js/constants/appConstants.js b/js/constants/appConstants.js index 17ff7a89f7e..46460e6e860 100644 --- a/js/constants/appConstants.js +++ b/js/constants/appConstants.js @@ -115,7 +115,12 @@ const appConstants = { APP_DRAG_STARTED: _, APP_DRAG_STOPPED: _, APP_DATA_DROPPED: _, - APP_DRAGGED_OVER: _ + APP_DRAGGED_OVER: _, + APP_ON_NAVIGATE_BACK: _, + APP_ON_NAVIGATE_FORWARD: _, + APP_ON_NAVIGATE_INDEX: _, + APP_ON_NAVIGATE_BACK_LONG: _, + APP_ON_NAVIGATE_FORWARD_LONG: _ } module.exports = mapValuesByKeys(appConstants) diff --git a/js/constants/windowConstants.js b/js/constants/windowConstants.js index 9094daa01fa..1a5f6e5228e 100644 --- a/js/constants/windowConstants.js +++ b/js/constants/windowConstants.js @@ -101,7 +101,9 @@ const windowConstants = { WINDOW_SHOULD_UNMAXIMIZE: _, WINDOW_SHOULD_EXIT_FULL_SCREEN: _, WINDOW_SHOULD_OPEN_DEV_TOOLS: _, - WINDOW_SET_ALL_AUDIO_MUTED: _ + WINDOW_SET_ALL_AUDIO_MUTED: _, + WINDOW_ON_NAVIGATE_BACK_LONG: _, + WINDOW_ON_NAVIGATE_FORWARD_LONG: _ } module.exports = mapValuesByKeys(windowConstants) diff --git a/js/contextMenus.js b/js/contextMenus.js index 6d24a52c064..5978cc77f2b 100644 --- a/js/contextMenus.js +++ b/js/contextMenus.js @@ -33,9 +33,7 @@ const {getPartitionFromNumber, frameOptsFromFrame, getActiveFrame} = require('./ const {isIntermediateAboutPage, isUrl, aboutUrls} = require('./lib/appUrlUtil') const {getBase64FromImageUrl} = require('./lib/imageUtil') const urlParse = require('../app/common/urlParse') -const eventUtil = require('./lib/eventUtil') const {getCurrentWindow} = require('../app/renderer/currentWindow') -const config = require('./constants/config') const {bookmarksToolbarMode} = require('../app/common/constants/settingsEnums') const extensionState = require('../app/common/state/extensionState') const extensionActions = require('../app/common/actions/extensionActions') @@ -1513,100 +1511,6 @@ function onMoreBookmarksMenu (activeFrame, allBookmarkItems, overflowItems, e) { })) } -function onBackButtonHistoryMenu (activeFrame, history, target) { - const rect = target.parentNode.getBoundingClientRect() - const menuTemplate = [] - - if (activeFrame && history && history.entries.length > 0) { - const stopIndex = Math.max(((history.currentIndex - config.navigationBar.maxHistorySites) - 1), -1) - for (let index = (history.currentIndex - 1); index > stopIndex; index--) { - const url = history.entries[index].url - - menuTemplate.push({ - label: history.entries[index].display, - icon: history.entries[index].icon, - click: (e) => { - if (eventUtil.isForSecondaryAction(e)) { - appActions.createTabRequested({ - url, - partitionNumber: activeFrame.props.partitionNumber, - active: !!e.shiftKey - }) - } else { - activeFrame.goToIndex(index) - } - } - }) - } - - // Always display "Show History" link - menuTemplate.push( - CommonMenu.separatorMenuItem, - { - label: locale.translation('showAllHistory'), - click: (e) => { - appActions.createTabRequested({ - url: 'about:history' - }) - windowActions.setContextMenuDetail() - } - }) - } - - windowActions.setContextMenuDetail(Immutable.fromJS({ - left: rect.left, - top: rect.bottom, - template: menuTemplate - })) -} - -function onForwardButtonHistoryMenu (activeFrame, history, target) { - const rect = target.parentNode.getBoundingClientRect() - const menuTemplate = [] - - if (activeFrame && history && history.entries.length > 0) { - const stopIndex = Math.min(((history.currentIndex + config.navigationBar.maxHistorySites) + 1), history.entries.length) - for (let index = (history.currentIndex + 1); index < stopIndex; index++) { - const url = history.entries[index].url - - menuTemplate.push({ - label: history.entries[index].display, - icon: history.entries[index].icon, - click: (e) => { - if (eventUtil.isForSecondaryAction(e)) { - appActions.createTabRequested({ - url, - partitionNumber: activeFrame.props.partitionNumber, - active: !!e.shiftKey - }) - } else { - activeFrame.goToIndex(index) - } - } - }) - } - - // Always display "Show History" link - menuTemplate.push( - CommonMenu.separatorMenuItem, - { - label: locale.translation('showAllHistory'), - click: (e) => { - appActions.createTabRequested({ - url: 'about:history' - }) - windowActions.setContextMenuDetail() - } - }) - } - - windowActions.setContextMenuDetail(Immutable.fromJS({ - left: rect.left, - top: rect.bottom, - template: menuTemplate - })) -} - function onReloadContextMenu (target) { const rect = target.getBoundingClientRect() const menuTemplate = [ @@ -1637,7 +1541,5 @@ module.exports = { onShowUsernameMenu, onShowAutofillMenu, onMoreBookmarksMenu, - onBackButtonHistoryMenu, - onForwardButtonHistoryMenu, onReloadContextMenu } diff --git a/js/lib/urlutil.js b/js/lib/urlutil.js index d4d231f3ceb..cb164886637 100644 --- a/js/lib/urlutil.js +++ b/js/lib/urlutil.js @@ -353,7 +353,7 @@ const UrlUtil = { * @return {string} url The base favicon URL */ getDefaultFaviconUrl: function (url) { - if (UrlUtil.isURL(url)) { + if (typeof window !== 'undefined' && UrlUtil.isURL(url)) { const loc = new window.URL(url) return loc.protocol + '//' + loc.host + '/favicon.ico' } diff --git a/js/stores/windowStore.js b/js/stores/windowStore.js index d70bb850e53..e35f38fd67c 100644 --- a/js/stores/windowStore.js +++ b/js/stores/windowStore.js @@ -25,6 +25,7 @@ const {aboutUrls, getTargetAboutUrl, newFrameUrl} = require('../lib/appUrlUtil') const Serializer = require('../dispatcher/serializer') const {updateTabPageIndex} = require('../../app/renderer/lib/tabUtil') const assert = require('assert') +const contextMenuState = require('../../app/common/state/contextMenuState.js') let windowState = Immutable.fromJS({ activeFrameKey: null, @@ -472,19 +473,13 @@ const doAction = (action) => { } break case windowConstants.WINDOW_SET_CONTEXT_MENU_DETAIL: - if (!action.detail) { - if (windowState.getIn(['contextMenuDetail', 'type']) === 'hamburgerMenu') { - windowState = windowState.set('hamburgerMenuWasOpen', true) - } else { - windowState = windowState.set('hamburgerMenuWasOpen', false) - } - windowState = windowState.delete('contextMenuDetail') - } else { - if (!(action.detail.get('type') === 'hamburgerMenu' && windowState.get('hamburgerMenuWasOpen'))) { - windowState = windowState.set('contextMenuDetail', action.detail) - } - windowState = windowState.set('hamburgerMenuWasOpen', false) - } + windowState = contextMenuState.setContextMenu(windowState, action) + break + case windowConstants.WINDOW_ON_NAVIGATE_BACK_LONG: + windowState = contextMenuState.onLongBacHistory(windowState, action) + break + case windowConstants.WINDOW_ON_NAVIGATE_FORWARD_LONG: + windowState = contextMenuState.onLongForwardHistory(windowState, action) break case windowConstants.WINDOW_SET_POPUP_WINDOW_DETAIL: if (!action.detail) { From 81aa4d278f219f5d85baadceb0a44384f91c1726 Mon Sep 17 00:00:00 2001 From: NejcZdovc Date: Wed, 19 Apr 2017 18:53:07 +0200 Subject: [PATCH 2/2] Review fixes --- app/browser/reducers/tabsReducer.js | 15 +- app/browser/tabs.js | 12 +- app/browser/windows.js | 8 + app/common/state/contextMenuState.js | 132 +-------------- .../components/navigation/navigator.js | 8 +- app/renderer/reducers/contextMenuReducer.js | 155 ++++++++++++++++++ docs/appActions.md | 10 +- js/actions/appActions.js | 21 +-- js/actions/windowActions.js | 4 +- js/components/frame.js | 6 +- js/constants/appConstants.js | 10 +- js/constants/windowConstants.js | 4 +- js/lib/urlutil.js | 4 +- js/stores/windowStore.js | 11 +- 14 files changed, 215 insertions(+), 185 deletions(-) create mode 100644 app/renderer/reducers/contextMenuReducer.js diff --git a/app/browser/reducers/tabsReducer.js b/app/browser/reducers/tabsReducer.js index 21b8f4d43c4..7232f3ee64c 100644 --- a/app/browser/reducers/tabsReducer.js +++ b/app/browser/reducers/tabsReducer.js @@ -12,6 +12,7 @@ const windowAction = require('../../../js/actions/windowActions.js') const {makeImmutable} = require('../../common/state/immutableUtil') const {getFlashResourceId} = require('../../../js/flash') const {l10nErrorText} = require('../../common/lib/httpUtil') +const windows = require('../windows') const tabsReducer = (state, action) => { action = makeImmutable(action) @@ -72,20 +73,20 @@ const tabsReducer = (state, action) => { case appConstants.APP_LOAD_URL_IN_ACTIVE_TAB_REQUESTED: state = tabs.loadURLInActiveTab(state, action) break - case appConstants.APP_ON_NAVIGATE_BACK: + case appConstants.APP_ON_GO_BACK: state = tabs.goBack(state, action) break - case appConstants.APP_ON_NAVIGATE_FORWARD: + case appConstants.APP_ON_GO_FORWARD: state = tabs.goForward(state, action) break - case appConstants.APP_ON_NAVIGATE_INDEX: + case appConstants.APP_ON_GO_TO_INDEX: state = tabs.goToIndex(state, action) break - case appConstants.APP_ON_NAVIGATE_BACK_LONG: + case appConstants.APP_ON_GO_BACK_LONG: { const history = tabs.getHistoryEntries(state, action) const tabValue = tabState.getByTabId(state, action.get('tabId')) - const windowId = tabs.getWindowId() + const windowId = windows.getActiveWindowId() if (history !== null) { windowAction.onLongBackHistory( @@ -99,11 +100,11 @@ const tabsReducer = (state, action) => { } break } - case appConstants.APP_ON_NAVIGATE_FORWARD_LONG: + case appConstants.APP_ON_GO_FORWARD_LONG: { const history = tabs.getHistoryEntries(state, action) const tabValue = tabState.getByTabId(state, action.get('tabId')) - const windowId = tabs.getWindowId() + const windowId = windows.getActiveWindowId() if (history !== null) { windowAction.onLongForwardHistory( diff --git a/app/browser/tabs.js b/app/browser/tabs.js index 5b531a808af..a0392d2ddff 100644 --- a/app/browser/tabs.js +++ b/app/browser/tabs.js @@ -8,7 +8,7 @@ const Immutable = require('immutable') const tabState = require('../common/state/tabState') const {app, BrowserWindow, extensions, session, ipcMain} = require('electron') const {makeImmutable} = require('../common/state/immutableUtil') -const {getTargetAboutUrl, getSourceAboutUrl, isSourceAboutUrl, newFrameUrl} = require('../../js/lib/appUrlUtil') +const {getTargetAboutUrl, getSourceAboutUrl, isSourceAboutUrl, newFrameUrl, isTargetAboutUrl} = require('../../js/lib/appUrlUtil') const {isURL, getUrlFromInput, toPDFJSLocation, getDefaultFaviconUrl} = require('../../js/lib/urlutil') const {isSessionPartition} = require('../../js/state/frameStateUtil') const {getOrigin} = require('../../js/state/siteUtil') @@ -652,14 +652,6 @@ const api = { return state }, - getWindowId: () => { - if (BrowserWindow.getFocusedWindow()) { - return BrowserWindow.getFocusedWindow().id - } - - return -1 - }, - getHistoryEntries: (state, action) => { const tab = api.getWebContents(action.get('tabId')) const sites = state ? state.get('sites') : null @@ -682,7 +674,7 @@ const api = { icon: null } - if (url.startsWith('chrome-extension://')) { + if (isTargetAboutUrl(url)) { // TODO: return brave lion (or better: get icon from extension if possible as data URI) } else { if (sites) { diff --git a/app/browser/windows.js b/app/browser/windows.js index ee336614ba6..c609b6e9a53 100644 --- a/app/browser/windows.js +++ b/app/browser/windows.js @@ -328,6 +328,14 @@ const api = { getWindow: (windowId) => { return currentWindows[windowId] + }, + + getActiveWindowId: () => { + if (BrowserWindow.getFocusedWindow()) { + return BrowserWindow.getFocusedWindow().id + } + + return windowState.WINDOW_ID_NONE } } diff --git a/app/common/state/contextMenuState.js b/app/common/state/contextMenuState.js index 5d7bedf6f87..0f88ce240c1 100644 --- a/app/common/state/contextMenuState.js +++ b/app/common/state/contextMenuState.js @@ -3,20 +3,8 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ const assert = require('assert') -const eventUtil = require('../../../js/lib/eventUtil.js') -const appActions = require('../../../js/actions/appActions.js') -const windowAction = require('../../../js/actions/windowActions.js') -const config = require('../../../js/constants/config.js') -const CommonMenu = require('../commonMenu.js') -const locale = require('../../../js/l10n.js') const { makeImmutable, isMap } = require('./immutableUtil') -const validateAction = function (action) { - action = makeImmutable(action) - assert.ok(isMap(action), 'action must be an Immutable.Map') - return action -} - const validateState = function (state) { state = makeImmutable(state) assert.ok(isMap(state), 'state must be an Immutable.Map') @@ -24,11 +12,11 @@ const validateState = function (state) { } const contextMenuState = { - setContextMenu: (state, action) => { - action = validateAction(action) + setContextMenu: (state, detail) => { + detail = makeImmutable(detail) state = validateState(state) - if (!action.get('detail')) { + if (!detail) { if (state.getIn(['contextMenuDetail', 'type']) === 'hamburgerMenu') { state = state.set('hamburgerMenuWasOpen', true) } else { @@ -36,122 +24,12 @@ const contextMenuState = { } state = state.delete('contextMenuDetail') } else { - if (!(action.getIn(['detail', 'type']) === 'hamburgerMenu' && state.get('hamburgerMenuWasOpen'))) { - state = state.set('contextMenuDetail', action.get('detail')) + if (!(detail.get('type') === 'hamburgerMenu' && state.get('hamburgerMenuWasOpen'))) { + state = state.set('contextMenuDetail', detail) } state = state.set('hamburgerMenuWasOpen', false) } - return state - }, - - onLongBacHistory: (state, action) => { - action = validateAction(action) - state = validateState(state) - const history = action.get('history') - - const menuTemplate = [] - - if (action.get('tabId') > -1 && history && history.get('entries').size > 0) { - const stopIndex = Math.max(((history.get('currentIndex') - config.navigationBar.maxHistorySites) - 1), -1) - for (let index = (history.get('currentIndex') - 1); index > stopIndex; index--) { - const entry = history.getIn(['entries', index]) - const url = entry.get('url') - - menuTemplate.push({ - label: entry.get('display'), - icon: entry.get('icon'), - click: function (e) { - if (eventUtil.isForSecondaryAction(e)) { - appActions.createTabRequested({ - url, - partitionNumber: action.get('partitionNumber'), - active: !!e.shiftKey - }) - } else { - appActions.onNavigateIndex(action.get('tabId'), index) - } - } - }) - } - - // Always display "Show History" link - menuTemplate.push( - CommonMenu.separatorMenuItem, - { - label: locale.translation('showAllHistory'), - click: function () { - appActions.createTabRequested({ - url: 'about:history' - }) - windowAction.setContextMenuDetail() - } - }) - - state = contextMenuState.setContextMenu(state, makeImmutable({ - detail: { - left: action.get('left'), - top: action.get('top'), - template: menuTemplate - } - })) - } - - return state - }, - - onLongForwardHistory: (state, action) => { - action = validateAction(action) - state = validateState(state) - const history = action.get('history') - - const menuTemplate = [] - - if (action.get('tabId') > -1 && history && history.get('entries').size > 0) { - const stopIndex = Math.min(((history.get('currentIndex') + config.navigationBar.maxHistorySites) + 1), history.get('entries').size) - for (let index = (history.get('currentIndex') + 1); index < stopIndex; index++) { - const entry = history.getIn(['entries', index]) - const url = entry.get('url') - - menuTemplate.push({ - label: entry.get('display'), - icon: entry.get('icon'), - click: function (e) { - if (eventUtil.isForSecondaryAction(e)) { - appActions.createTabRequested({ - url, - partitionNumber: action.get('partitionNumber'), - active: !!e.shiftKey - }) - } else { - appActions.onNavigateIndex(action.get('tabId'), index) - } - } - }) - } - - // Always display "Show History" link - menuTemplate.push( - CommonMenu.separatorMenuItem, - { - label: locale.translation('showAllHistory'), - click: function () { - appActions.createTabRequested({ - url: 'about:history' - }) - windowAction.setContextMenuDetail() - } - }) - - state = contextMenuState.setContextMenu(state, makeImmutable({ - detail: { - left: action.get('left'), - top: action.get('top'), - template: menuTemplate - } - })) - } - return state } } diff --git a/app/renderer/components/navigation/navigator.js b/app/renderer/components/navigation/navigator.js index a15cb3ac98e..4847fac4dc4 100644 --- a/app/renderer/components/navigation/navigator.js +++ b/app/renderer/components/navigation/navigator.js @@ -121,17 +121,17 @@ class Navigator extends ImmutableComponent { } onBack (e) { - this.onNav(e, 'canGoBack', 'back', appActions.onNavigateBack) + this.onNav(e, 'canGoBack', 'back', appActions.onGoBack) } onForward (e) { - this.onNav(e, 'canGoForward', 'forward', appActions.onNavigateForward) + this.onNav(e, 'canGoForward', 'forward', appActions.onGoForward) } onBackLongPress (target) { const activeTab = this.props.activeTab const rect = target.parentNode.getBoundingClientRect() - appActions.onNavigateBackLong(activeTab.get('tabId'), { + appActions.onGoBackLong(activeTab.get('tabId'), { left: rect.left, bottom: rect.bottom }) @@ -140,7 +140,7 @@ class Navigator extends ImmutableComponent { onForwardLongPress (target) { const activeTab = this.props.activeTab const rect = target.parentNode.getBoundingClientRect() - appActions.onNavigateForwardLong(activeTab.get('tabId'), { + appActions.onGoForwardLong(activeTab.get('tabId'), { left: rect.left, bottom: rect.bottom }) diff --git a/app/renderer/reducers/contextMenuReducer.js b/app/renderer/reducers/contextMenuReducer.js new file mode 100644 index 00000000000..5e878a032fe --- /dev/null +++ b/app/renderer/reducers/contextMenuReducer.js @@ -0,0 +1,155 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +const assert = require('assert') + +// Constants +const config = require('../../../js/constants/config.js') +const windowConstants = require('../../../js/constants/windowConstants') + +// State +const contextMenuState = require('../../common/state/contextMenuState.js') + +// Actions +const appActions = require('../../../js/actions/appActions.js') +const windowAction = require('../../../js/actions/windowActions.js') + +// Utils +const eventUtil = require('../../../js/lib/eventUtil.js') +const CommonMenu = require('../../common/commonMenu.js') +const locale = require('../../../js/l10n.js') +const { makeImmutable, isMap } = require('../../common/state/immutableUtil') + +const validateAction = function (action) { + action = makeImmutable(action) + assert.ok(isMap(action), 'action must be an Immutable.Map') + return action +} + +const validateState = function (state) { + state = makeImmutable(state) + assert.ok(isMap(state), 'state must be an Immutable.Map') + return state +} + +const onLongBackHistory = (state, action) => { + action = validateAction(action) + state = validateState(state) + const history = action.get('history') + + const menuTemplate = [] + + if (action.get('tabId') > -1 && history && history.get('entries').size > 0) { + const stopIndex = Math.max(((history.get('currentIndex') - config.navigationBar.maxHistorySites) - 1), -1) + for (let index = (history.get('currentIndex') - 1); index > stopIndex; index--) { + const entry = history.getIn(['entries', index]) + const url = entry.get('url') + + menuTemplate.push({ + label: entry.get('display'), + icon: entry.get('icon'), + click: function (e) { + if (eventUtil.isForSecondaryAction(e)) { + appActions.createTabRequested({ + url, + partitionNumber: action.get('partitionNumber'), + active: !!e.shiftKey + }) + } else { + appActions.onGoToIndex(action.get('tabId'), index) + } + } + }) + } + + // Always display "Show History" link + menuTemplate.push( + CommonMenu.separatorMenuItem, + { + label: locale.translation('showAllHistory'), + click: function () { + appActions.createTabRequested({ + url: 'about:history' + }) + windowAction.setContextMenuDetail() + } + }) + + state = contextMenuState.setContextMenu(state, makeImmutable({ + left: action.get('left'), + top: action.get('top'), + template: menuTemplate + })) + } + + return state +} + +const onLongForwardHistory = (state, action) => { + action = validateAction(action) + state = validateState(state) + const history = action.get('history') + + const menuTemplate = [] + + if (action.get('tabId') > -1 && history && history.get('entries').size > 0) { + const stopIndex = Math.min(((history.get('currentIndex') + config.navigationBar.maxHistorySites) + 1), history.get('entries').size) + for (let index = (history.get('currentIndex') + 1); index < stopIndex; index++) { + const entry = history.getIn(['entries', index]) + const url = entry.get('url') + + menuTemplate.push({ + label: entry.get('display'), + icon: entry.get('icon'), + click: function (e) { + if (eventUtil.isForSecondaryAction(e)) { + appActions.createTabRequested({ + url, + partitionNumber: action.get('partitionNumber'), + active: !!e.shiftKey + }) + } else { + appActions.onGoToIndex(action.get('tabId'), index) + } + } + }) + } + + // Always display "Show History" link + menuTemplate.push( + CommonMenu.separatorMenuItem, + { + label: locale.translation('showAllHistory'), + click: function () { + appActions.createTabRequested({ + url: 'about:history' + }) + windowAction.setContextMenuDetail() + } + }) + + state = contextMenuState.setContextMenu(state, makeImmutable({ + left: action.get('left'), + top: action.get('top'), + template: menuTemplate + })) + } + + return state +} + +const contextMenuReducer = (windowState, action) => { + switch (action.actionType) { + case windowConstants.WINDOW_ON_GO_BACK_LONG: + windowState = onLongBackHistory(windowState, action) + break + case windowConstants.WINDOW_ON_GO_FORWARD_LONG: + windowState = onLongForwardHistory(windowState, action) + break + } + + return windowState +} + +module.exports = contextMenuReducer diff --git a/docs/appActions.md b/docs/appActions.md index d022aadc7d3..d1099a82cbd 100644 --- a/docs/appActions.md +++ b/docs/appActions.md @@ -955,7 +955,7 @@ Notifies the app that a drop operation occurred -### onNavigateBack(tabId) +### onGoBack(tabId) Go back in a history for a given tab @@ -965,7 +965,7 @@ Go back in a history for a given tab -### onNavigateForward(tabId) +### onGoForward(tabId) Go forward in a history for a given tab @@ -975,7 +975,7 @@ Go forward in a history for a given tab -### onNavigateIndex(tabId, index) +### onGoToIndex(tabId, index) Go to specific item in a history for a given tab @@ -987,7 +987,7 @@ Go to specific item in a history for a given tab -### onNavigateBackLong(tabId, rect) +### onGoBackLong(tabId, rect) Go back in a history for a given tab @@ -999,7 +999,7 @@ Go back in a history for a given tab -### onNavigateForwardLong(tabId, rect) +### onGoForwardLong(tabId, rect) Go forward in a history for a given tab diff --git a/js/actions/appActions.js b/js/actions/appActions.js index 4fe05a28e6a..2cfbece5e28 100644 --- a/js/actions/appActions.js +++ b/js/actions/appActions.js @@ -1204,9 +1204,9 @@ const appActions = { * Go back in a history for a given tab * @param {number} tabId - Tab id used for an action */ - onNavigateBack: function (tabId) { + onGoBack: function (tabId) { AppDispatcher.dispatch({ - actionType: appConstants.APP_ON_NAVIGATE_BACK, + actionType: appConstants.APP_ON_GO_BACK, tabId }) }, @@ -1215,9 +1215,9 @@ const appActions = { * Go forward in a history for a given tab * @param {number} tabId - Tab id used for an action */ - onNavigateForward: function (tabId) { + onGoForward: function (tabId) { AppDispatcher.dispatch({ - actionType: appConstants.APP_ON_NAVIGATE_FORWARD, + actionType: appConstants.APP_ON_GO_FORWARD, tabId }) }, @@ -1227,10 +1227,11 @@ const appActions = { * @param {number} tabId - Tab id used for an action * @param {number} index - Index in the history */ - onNavigateIndex: function (tabId, index) { + onGoToIndex: function (tabId, index) { AppDispatcher.dispatch({ - actionType: appConstants.APP_ON_NAVIGATE_INDEX, + actionType: appConstants.APP_ON_GO_TO_INDEX, tabId, + index }) }, @@ -1240,9 +1241,9 @@ const appActions = { * @param {number} tabId - Tab id used for an action * @param {ClientRect} rect - Parent element position for this action */ - onNavigateBackLong: function (tabId, rect) { + onGoBackLong: function (tabId, rect) { AppDispatcher.dispatch({ - actionType: appConstants.APP_ON_NAVIGATE_BACK_LONG, + actionType: appConstants.APP_ON_GO_BACK_LONG, tabId, rect }) @@ -1253,9 +1254,9 @@ const appActions = { * @param {number} tabId - Tab id used for an action * @param {ClientRect} rect - Parent element position for this action */ - onNavigateForwardLong: function (tabId, rect) { + onGoForwardLong: function (tabId, rect) { AppDispatcher.dispatch({ - actionType: appConstants.APP_ON_NAVIGATE_FORWARD_LONG, + actionType: appConstants.APP_ON_GO_FORWARD_LONG, tabId, rect }) diff --git a/js/actions/windowActions.js b/js/actions/windowActions.js index 070adccd2b2..ef4dfa1e8e1 100644 --- a/js/actions/windowActions.js +++ b/js/actions/windowActions.js @@ -1183,7 +1183,7 @@ const windowActions = { onLongBackHistory: function (history, left, top, partition, tabId, windowId) { dispatch({ - actionType: windowConstants.WINDOW_ON_NAVIGATE_BACK_LONG, + actionType: windowConstants.WINDOW_ON_GO_BACK_LONG, queryInfo: { windowId }, @@ -1197,7 +1197,7 @@ const windowActions = { onLongForwardHistory: function (history, left, top, partition, tabId, windowId) { dispatch({ - actionType: windowConstants.WINDOW_ON_NAVIGATE_FORWARD_LONG, + actionType: windowConstants.WINDOW_ON_GO_FORWARD_LONG, queryInfo: { windowId }, diff --git a/js/components/frame.js b/js/components/frame.js index fafc6756e32..ea2ea4cc1bf 100644 --- a/js/components/frame.js +++ b/js/components/frame.js @@ -629,10 +629,10 @@ class Frame extends ImmutableComponent { method = () => this.webview.stop() break case messages.GO_BACK: - method = () => appActions.onNavigateBack(this.props.tabId) + method = () => appActions.onGoBack(this.props.tabId) break case messages.GO_FORWARD: - method = () => appActions.onNavigateForward(this.props.tabId) + method = () => appActions.onGoForward(this.props.tabId) break case messages.RELOAD: method = () => { @@ -728,7 +728,7 @@ class Frame extends ImmutableComponent { } else if (isTargetAboutUrl(e.validatedURL)) { // open a new tab for other about urls // and send this tab back to wherever it came from - appActions.tabNavigateBack(this.props.tabId) + appActions.onGoBack(this.props.tabId) appActions.createTabRequested({ url: e.validatedURL, active: true diff --git a/js/constants/appConstants.js b/js/constants/appConstants.js index 46460e6e860..5ef90c36054 100644 --- a/js/constants/appConstants.js +++ b/js/constants/appConstants.js @@ -116,11 +116,11 @@ const appConstants = { APP_DRAG_STOPPED: _, APP_DATA_DROPPED: _, APP_DRAGGED_OVER: _, - APP_ON_NAVIGATE_BACK: _, - APP_ON_NAVIGATE_FORWARD: _, - APP_ON_NAVIGATE_INDEX: _, - APP_ON_NAVIGATE_BACK_LONG: _, - APP_ON_NAVIGATE_FORWARD_LONG: _ + APP_ON_GO_BACK: _, + APP_ON_GO_FORWARD: _, + APP_ON_GO_TO_INDEX: _, + APP_ON_GO_BACK_LONG: _, + APP_ON_GO_FORWARD_LONG: _ } module.exports = mapValuesByKeys(appConstants) diff --git a/js/constants/windowConstants.js b/js/constants/windowConstants.js index 1a5f6e5228e..b67fdcf97a2 100644 --- a/js/constants/windowConstants.js +++ b/js/constants/windowConstants.js @@ -102,8 +102,8 @@ const windowConstants = { WINDOW_SHOULD_EXIT_FULL_SCREEN: _, WINDOW_SHOULD_OPEN_DEV_TOOLS: _, WINDOW_SET_ALL_AUDIO_MUTED: _, - WINDOW_ON_NAVIGATE_BACK_LONG: _, - WINDOW_ON_NAVIGATE_FORWARD_LONG: _ + WINDOW_ON_GO_BACK_LONG: _, + WINDOW_ON_GO_FORWARD_LONG: _ } module.exports = mapValuesByKeys(windowConstants) diff --git a/js/lib/urlutil.js b/js/lib/urlutil.js index cb164886637..f0e230779e4 100644 --- a/js/lib/urlutil.js +++ b/js/lib/urlutil.js @@ -353,8 +353,8 @@ const UrlUtil = { * @return {string} url The base favicon URL */ getDefaultFaviconUrl: function (url) { - if (typeof window !== 'undefined' && UrlUtil.isURL(url)) { - const loc = new window.URL(url) + if (UrlUtil.isURL(url)) { + const loc = urlParse(url) return loc.protocol + '//' + loc.host + '/favicon.ico' } return '' diff --git a/js/stores/windowStore.js b/js/stores/windowStore.js index e35f38fd67c..3f456e15193 100644 --- a/js/stores/windowStore.js +++ b/js/stores/windowStore.js @@ -238,7 +238,8 @@ const emitChanges = debounce(windowStore.emitChanges.bind(windowStore), 5) const applyReducers = (state, action) => [ require('../../app/renderer/reducers/urlBarReducer'), require('../../app/renderer/reducers/urlBarSuggestionsReducer'), - require('../../app/renderer/reducers/frameReducer') + require('../../app/renderer/reducers/frameReducer'), + require('../../app/renderer/reducers/contextMenuReducer') ].reduce( (windowState, reducer) => { const newState = reducer(windowState, action) @@ -473,13 +474,7 @@ const doAction = (action) => { } break case windowConstants.WINDOW_SET_CONTEXT_MENU_DETAIL: - windowState = contextMenuState.setContextMenu(windowState, action) - break - case windowConstants.WINDOW_ON_NAVIGATE_BACK_LONG: - windowState = contextMenuState.onLongBacHistory(windowState, action) - break - case windowConstants.WINDOW_ON_NAVIGATE_FORWARD_LONG: - windowState = contextMenuState.onLongForwardHistory(windowState, action) + windowState = contextMenuState.setContextMenu(windowState, action.detail) break case windowConstants.WINDOW_SET_POPUP_WINDOW_DETAIL: if (!action.detail) {