ELECTRON-648 (Prevent drag and drop of files) (#464)

- Prevent drag and drop of files
- Prevent drag and drop of files for about app window
This commit is contained in:
Kiran Niranjan 2018-08-16 11:35:40 +05:30 committed by Vishwas Shashidhar
parent a2510677ed
commit 7fb6c4c407
5 changed files with 80 additions and 0 deletions

View File

@ -30,4 +30,21 @@ ipcRenderer.on('register-crash-reporter', (event, arg) => {
if (arg && typeof arg === 'object') {
crashReporter.start(arg);
}
});
// note: this is a workaround until
// https://github.com/electron/electron/issues/8841
// is fixed on the electron. where 'will-navigate'
// is never fired in sandbox mode
//
// This is required in order to prevent from loading
// dropped content
window.addEventListener('drop', function(e) {
e.preventDefault();
e.stopPropagation();
});
window.addEventListener('dragover', function(e) {
e.preventDefault();
e.stopPropagation();
});

View File

@ -289,4 +289,22 @@ ipcRenderer.on('i18n-screen-picker', (event, content) => {
}
}
}
});
// note: this is a workaround until
// https://github.com/electron/electron/issues/8841
// is fixed on the electron. where 'will-navigate'
// is never fired in sandbox mode
//
// This is required in order to prevent from loading
// dropped content
window.addEventListener('drop', function(e) {
e.preventDefault();
e.stopPropagation();
});
window.addEventListener('dragover', function(e) {
e.preventDefault();
e.stopPropagation();
});

View File

@ -231,3 +231,20 @@ function reset() {
ipc.on('electron-notify-set-contents', setContents);
ipc.on('electron-notify-load-config', loadConfig);
ipc.on('electron-notify-reset', reset);
// note: this is a workaround until
// https://github.com/electron/electron/issues/8841
// is fixed on the electron. where 'will-navigate'
// is never fired in sandbox mode
//
// This is required in order to prevent from loading
// dropped content
window.addEventListener('drop', function(e) {
e.preventDefault();
e.stopPropagation();
});
window.addEventListener('dragover', function(e) {
e.preventDefault();
e.stopPropagation();
});

View File

@ -97,4 +97,21 @@ ipc.on('i18n-notification-settings', (event, content) => {
}
}
}
});
// note: this is a workaround until
// https://github.com/electron/electron/issues/8841
// is fixed on the electron. where 'will-navigate'
// is never fired in sandbox mode
//
// This is required in order to prevent from loading
// dropped content
window.addEventListener('drop', function(e) {
e.preventDefault();
e.stopPropagation();
});
window.addEventListener('dragover', function(e) {
e.preventDefault();
e.stopPropagation();
});

View File

@ -496,6 +496,11 @@ function doCreateMainWindow(initialUrl, initialBounds, isCustomTitleBar) {
};
browserWin.webContents.on('crashed', handleChildWindowCrashEvent);
browserWin.webContents.on('will-navigate', (e, navigatedURL) => {
if (!navigatedURL.startsWith('http' || 'https')) {
e.preventDefault();
}
});
// In case we navigate to an external link from inside a pop-out,
// we open that link in an external browser rather than creating
@ -575,6 +580,12 @@ function doCreateMainWindow(initialUrl, initialBounds, isCustomTitleBar) {
// whenever the main window is navigated for ex: window.location.href or url redirect
mainWindow.webContents.on('will-navigate', function (event, navigatedURL) {
if (!navigatedURL.startsWith('http' || 'https')) {
event.preventDefault();
return;
}
isWhitelisted(navigatedURL)
.catch(() => {
event.preventDefault();