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

Commit

Permalink
UrlBarIcon uses now only primitives
Browse files Browse the repository at this point in the history
Resolves #9753

Auditors: @bsclifton @bridiver

Test Plan:
  • Loading branch information
NejcZdovc committed Jul 5, 2017
1 parent e782ec6 commit d82f171
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 11 deletions.
6 changes: 4 additions & 2 deletions app/renderer/components/navigation/urlBarIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ class UrlBarIcon extends React.Component {

onDragStart (e) {
dndData.setupDataTransferURL(e.dataTransfer, this.props.location, this.props.title)
dndData.setupDataTransferBraveData(e.dataTransfer, dragTypes.TAB, this.props.activeFrame)
dndData.setupDataTransferBraveData(e.dataTransfer, dragTypes.TAB, {
tabId: this.props.tabId
})
}

mergeProps (state, ownProps) {
Expand All @@ -138,7 +140,7 @@ class UrlBarIcon extends React.Component {

// used in other functions
props.title = activeFrame.get('title', '')
props.activeFrame = activeFrame // TODO (nejc) only primitives
props.tabId = activeFrame.get('tabId')

return props
}
Expand Down
13 changes: 13 additions & 0 deletions app/renderer/reducers/frameReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const Immutable = require('immutable')
const appConstants = require('../../../js/constants/appConstants')
const windowConstants = require('../../../js/constants/windowConstants')
const config = require('../../../js/constants/config')
const siteTags = require('../../../js/constants/siteTags')

// Actions
const appActions = require('../../../js/actions/appActions')
Expand All @@ -19,6 +20,7 @@ const frameStateUtil = require('../../../js/state/frameStateUtil')
const {getCurrentWindowId} = require('../currentWindow')
const {getSourceAboutUrl, getSourceMagnetUrl} = require('../../../js/lib/appUrlUtil')
const {isURL, isPotentialPhishingUrl, getUrlFromInput} = require('../../../js/lib/urlutil')
const siteUtil = require('../../../js/state/siteUtil')

const setFullScreen = (state, action) => {
const index = frameStateUtil.getIndexByTabId(state, action.tabId)
Expand Down Expand Up @@ -205,6 +207,17 @@ const frameReducer = (state, action, immutableAction) => {
case windowConstants.WINDOW_SET_FULL_SCREEN:
state = setFullScreen(state, action)
break

case windowConstants.WINDOW_ON_FRAME_BOOKMARK:
{
// TODO make this an appAction that gets the bookmark data from tabState
const frameProps = frameStateUtil.getFrameByTabId(state, action.tabId)
if (frameProps) {
const bookmark = siteUtil.getDetailFromFrame(frameProps, siteTags.BOOKMARK)
appActions.addSite(bookmark, siteTags.BOOKMARK)
}
break
}
}

return state
Expand Down
7 changes: 7 additions & 0 deletions js/actions/windowActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,13 @@ const windowActions = {
actionType: windowConstants.WINDOW_ON_TAB_PAGE_CONTEXT_MENU,
index
})
},

onFrameBookmark: function (tabId) {
dispatch({
actionType: windowConstants.WINDOW_ON_FRAME_BOOKMARK,
tabId
})
}
}

Expand Down
3 changes: 2 additions & 1 deletion js/constants/windowConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ const windowConstants = {
WINDOW_ON_GO_FORWARD_LONG: _,
WINDOW_CLOSE_OTHER_FRAMES: _,
WINDOW_ON_CERT_ERROR: _,
WINDOW_ON_TAB_PAGE_CONTEXT_MENU: _
WINDOW_ON_TAB_PAGE_CONTEXT_MENU: _,
WINDOW_ON_FRAME_BOOKMARK: _
}

module.exports = mapValuesByKeys(windowConstants)
9 changes: 2 additions & 7 deletions js/dnd.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ const appActions = require('./actions/appActions')
const ReactDOM = require('react-dom')
const dndData = require('./dndData')
const dragTypes = require('./constants/dragTypes')
const siteTags = require('./constants/siteTags')
const siteUtil = require('./state/siteUtil')
const appStoreRenderer = require('./stores/appStoreRenderer')
const {getCurrentWindowId} = require('../app/renderer/currentWindow')
const {ESC} = require('../app/common/constants/keyCodes.js')
Expand Down Expand Up @@ -137,11 +135,8 @@ module.exports.isMiddle = (domNode, clientX) => {
module.exports.prepareBookmarkDataFromCompatible = (dataTransfer) => {
let bookmark = dndData.getDragData(dataTransfer, dragTypes.BOOKMARK)
if (!bookmark) {
const frameProps = dndData.getDragData(dataTransfer, dragTypes.TAB)
if (frameProps) {
bookmark = siteUtil.getDetailFromFrame(frameProps, siteTags.BOOKMARK)
appActions.addSite(bookmark, siteTags.BOOKMARK)
}
const dragData = dndData.getDragData(dataTransfer, dragTypes.TAB)
windowActions.onFrameBookmark(dragData.get('tabId'))
}
return bookmark
}
2 changes: 1 addition & 1 deletion js/dndData.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports.setupDataTransferURL = (dataTransfer, location, title) => {
}

module.exports.setupDataTransferBraveData = (dataTransfer, dragType, data) => {
dataTransfer.setData(`application/x-brave-${dragType}`, JSON.stringify(data.toJS()))
dataTransfer.setData(`application/x-brave-${dragType}`, JSON.stringify(data))
}

module.exports.shouldPrependVerticalItem = (target, clientY) => {
Expand Down

0 comments on commit d82f171

Please sign in to comment.