Skip to content

Commit

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

Auditors: @bsclifton @bridiver

Test Plan:
  • Loading branch information
NejcZdovc committed Jun 29, 2017
1 parent a93609f commit e0827f5
Show file tree
Hide file tree
Showing 6 changed files with 28 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, {
activeFrameKey: this.props.activeFrameKey
})
}

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.activeFrameKey = activeFrame.get('key')

return props
}
Expand Down
12 changes: 12 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.getFrameIndex(state, action.frameProps.get('key'))
Expand Down Expand Up @@ -189,6 +191,16 @@ const frameReducer = (state, action, immutableAction) => {
case windowConstants.WINDOW_SET_FULL_SCREEN:
state = setFullScreen(state, action)
break

case windowConstants.WINDOW_ON_FRAME_BOOKMARK:
{
const frameProps = frameStateUtil.getFrameByKey(state, action.frameKey)
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 @@ -1118,6 +1118,13 @@ const windowActions = {
partition,
tabId
})
},

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

Expand Down
3 changes: 2 additions & 1 deletion js/constants/windowConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ const windowConstants = {
WINDOW_SHOULD_OPEN_DEV_TOOLS: _,
WINDOW_SET_ALL_AUDIO_MUTED: _,
WINDOW_ON_GO_BACK_LONG: _,
WINDOW_ON_GO_FORWARD_LONG: _
WINDOW_ON_GO_FORWARD_LONG: _,
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 frame = dndData.getDragData(dataTransfer, dragTypes.TAB)
windowActions.onFrameBookmark(frame.get('activeFrameKey'))
}
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 e0827f5

Please sign in to comment.