diff --git a/app/extensions.js b/app/extensions.js index c964dc0fbfe..43251873f62 100644 --- a/app/extensions.js +++ b/app/extensions.js @@ -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: [ + '' + ], + exclude_globs: [ + indexHTML, + getBraveExtUrl('*') + ] } ], web_accessible_resources: [ diff --git a/app/extensions/brave/content/scripts/dndHandler.js b/app/extensions/brave/content/scripts/dndHandler.js new file mode 100644 index 00000000000..26e9193e000 --- /dev/null +++ b/app/extensions/brave/content/scripts/dndHandler.js @@ -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) diff --git a/app/extensions/brave/content/scripts/inputHandler.js b/app/extensions/brave/content/scripts/inputHandler.js index 82c80acf069..86a9ed03497 100644 --- a/app/extensions/brave/content/scripts/inputHandler.js +++ b/app/extensions/brave/content/scripts/inputHandler.js @@ -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)