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

Commit

Permalink
Merge pull request #8336 from NejcZdovc/hotfix/#8322-refs
Browse files Browse the repository at this point in the history
Remove ref dependency from Frame
  • Loading branch information
NejcZdovc authored Apr 19, 2017
2 parents c719806 + 81aa4d2 commit 22dc2b2
Show file tree
Hide file tree
Showing 16 changed files with 505 additions and 185 deletions.
47 changes: 47 additions & 0 deletions app/browser/reducers/tabsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ 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')
const windows = require('../windows')

const tabsReducer = (state, action) => {
action = makeImmutable(action)
Expand Down Expand Up @@ -71,6 +73,51 @@ const tabsReducer = (state, action) => {
case appConstants.APP_LOAD_URL_IN_ACTIVE_TAB_REQUESTED:
state = tabs.loadURLInActiveTab(state, action)
break
case appConstants.APP_ON_GO_BACK:
state = tabs.goBack(state, action)
break
case appConstants.APP_ON_GO_FORWARD:
state = tabs.goForward(state, action)
break
case appConstants.APP_ON_GO_TO_INDEX:
state = tabs.goToIndex(state, action)
break
case appConstants.APP_ON_GO_BACK_LONG:
{
const history = tabs.getHistoryEntries(state, action)
const tabValue = tabState.getByTabId(state, action.get('tabId'))
const windowId = windows.getActiveWindowId()

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_GO_FORWARD_LONG:
{
const history = tabs.getHistoryEntries(state, action)
const tabValue = tabState.getByTabId(state, action.get('tabId'))
const windowId = windows.getActiveWindowId()

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
Expand Down
83 changes: 80 additions & 3 deletions app/browser/tabs.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
/* 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')
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 {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')
const {getSetting} = require('../../js/settings')
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -619,6 +623,79 @@ 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
},

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 (isTargetAboutUrl(url)) {
// 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
}
}

Expand Down
8 changes: 8 additions & 0 deletions app/browser/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,14 @@ const api = {

getWindow: (windowId) => {
return currentWindows[windowId]
},

getActiveWindowId: () => {
if (BrowserWindow.getFocusedWindow()) {
return BrowserWindow.getFocusedWindow().id
}

return windowState.WINDOW_ID_NONE
}
}

Expand Down
37 changes: 37 additions & 0 deletions app/common/state/contextMenuState.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* 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 { makeImmutable, isMap } = require('./immutableUtil')

const validateState = function (state) {
state = makeImmutable(state)
assert.ok(isMap(state), 'state must be an Immutable.Map')
return state
}

const contextMenuState = {
setContextMenu: (state, detail) => {
detail = makeImmutable(detail)
state = validateState(state)

if (!detail) {
if (state.getIn(['contextMenuDetail', 'type']) === 'hamburgerMenu') {
state = state.set('hamburgerMenuWasOpen', true)
} else {
state = state.set('hamburgerMenuWasOpen', false)
}
state = state.delete('contextMenuDetail')
} else {
if (!(detail.get('type') === 'hamburgerMenu' && state.get('hamburgerMenuWasOpen'))) {
state = state.set('contextMenuDetail', detail)
}
state = state.set('hamburgerMenuWasOpen', false)
}

return state
}
}

module.exports = contextMenuState
21 changes: 15 additions & 6 deletions app/renderer/components/navigation/navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -69,7 +68,7 @@ class Navigator extends ImmutableComponent {
})
}
} else {
navAction.call(this.activeFrame)
navAction.call(this, this.props.activeTab.get('tabId'))
}
}

Expand Down Expand Up @@ -122,19 +121,29 @@ class Navigator extends ImmutableComponent {
}

onBack (e) {
this.onNav(e, 'canGoBack', 'back', this.activeFrame.goBack)
this.onNav(e, 'canGoBack', 'back', appActions.onGoBack)
}

onForward (e) {
this.onNav(e, 'canGoForward', 'forward', this.activeFrame.goForward)
this.onNav(e, 'canGoForward', 'forward', appActions.onGoForward)
}

onBackLongPress (target) {
contextMenus.onBackButtonHistoryMenu(this.activeFrame, this.activeFrame.getHistory(this.props.appState), target)
const activeTab = this.props.activeTab
const rect = target.parentNode.getBoundingClientRect()
appActions.onGoBackLong(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.onGoForwardLong(activeTab.get('tabId'), {
left: rect.left,
bottom: rect.bottom
})
}

onDragOver (e) {
Expand Down
Loading

0 comments on commit 22dc2b2

Please sign in to comment.