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

Fix Brave bookmark drag-and-drop #10937

Merged
merged 1 commit into from
Sep 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)