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

Commit

Permalink
Fix Brave bookmark drag-and-drop
Browse files Browse the repository at this point in the history
fix #10936

Test Plan:
1. go to about:bookmarks, try dragging and dropping some bookmarks. it should work.
2. drag a tab to change its position. it should work.
  • Loading branch information
diracdeltas authored and NejcZdovc committed Sep 14, 2017
1 parent f0f13d0 commit 899e417
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 31 deletions.
14 changes: 14 additions & 0 deletions app/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,20 @@ let generateBraveManifest = () => {
getBraveExtUrl('about-blank.html'),
getBraveExtUrl('about-blank.html') + '#*'
]
},
{
run_at: 'document_start',
all_frames: true,
js: [
'content/scripts/dndHandler.js'
],
matches: [
'<all_urls>'
],
exclude_globs: [
indexHTML,
getBraveExtUrl('*')
]
}
],
web_accessible_resources: [
Expand Down
34 changes: 34 additions & 0 deletions app/extensions/brave/content/scripts/dndHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* 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/. */

function hasBraveDragData (dataTransfer) {
if (!dataTransfer || !dataTransfer.types) {
return false
}
for (let i = 0; i < dataTransfer.types.length; i++) {
let type = dataTransfer.types[i]
if (type && type.startsWith('application/x-brave-')) {
return true
}
}
return false
}

function blockDndData (e) {
if (hasBraveDragData(e.dataTransfer)) {
// Block drag data from the Brave UI
try {
e.dataTransfer.dropEffect = 'none'
} catch (e) {}
e.preventDefault()
e.stopPropagation()
return false
}
return true
}

window.addEventListener('dragover', blockDndData, true)
window.addEventListener('dragenter', blockDndData, true)
window.addEventListener('dragleave', blockDndData, true)
window.addEventListener('drop', blockDndData, true)
31 changes: 0 additions & 31 deletions app/extensions/brave/content/scripts/inputHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,34 +151,3 @@ document.addEventListener('keydown', (e /*: Event*/) => {
break
}
})

function hasBraveDragData (dataTransfer) {
if (!dataTransfer || !dataTransfer.types) {
return false
}
for (let i = 0; i < dataTransfer.types.length; i++) {
let type = dataTransfer.types[i]
if (type && type.startsWith('application/x-brave-')) {
return true
}
}
return false
}

function blockDndData (e) {
if (hasBraveDragData(e.dataTransfer)) {
// Block drag data from the Brave UI
try {
e.dataTransfer.dropEffect = 'none'
} catch (e) {}
e.preventDefault()
e.stopPropagation()
return false
}
return true
}

window.addEventListener('dragover', blockDndData, true)
window.addEventListener('dragenter', blockDndData, true)
window.addEventListener('dragleave', blockDndData, true)
window.addEventListener('drop', blockDndData, true)

0 comments on commit 899e417

Please sign in to comment.