Require a non-empty drag image to prevent crash

This commit is contained in:
Kevin Sawicki 2017-01-26 10:38:13 -08:00
parent 8ce1930f0d
commit e683f28e32
2 changed files with 15 additions and 5 deletions

View file

@ -1327,9 +1327,17 @@ void WebContents::StartDrag(const mate::Dictionary& item,
// Error checking. // Error checking.
if (icon.IsEmpty()) { if (icon.IsEmpty()) {
args->ThrowError("Must specify 'icon' option");
return;
}
#if defined(OS_MACOSX)
// NSWindow.dragImage requires a non-empty NSImage
if (icon->image().IsEmpty()) {
args->ThrowError("Must specify non-empty 'icon' option"); args->ThrowError("Must specify non-empty 'icon' option");
return; return;
} }
#endif
// Start dragging. // Start dragging.
if (!files.empty()) { if (!files.empty()) {

View file

@ -292,13 +292,15 @@ describe('webContents module', function () {
w.webContents.startDrag({icon: path.join(__dirname, 'fixtures', 'assets', 'logo.png')}) w.webContents.startDrag({icon: path.join(__dirname, 'fixtures', 'assets', 'logo.png')})
}, /Must specify either 'file' or 'files' option/) }, /Must specify either 'file' or 'files' option/)
assert.throws(() => {
w.webContents.startDrag({file: __filename, icon: __filename})
}, /Must specify non-empty 'icon' option/)
assert.throws(() => { assert.throws(() => {
w.webContents.startDrag({file: __filename}) w.webContents.startDrag({file: __filename})
}, /Must specify non-empty 'icon' option/) }, /Must specify 'icon' option/)
if (process.platform === 'darwin') {
assert.throws(() => {
w.webContents.startDrag({file: __filename, icon: __filename})
}, /Must specify non-empty 'icon' option/)
}
}) })
}) })
}) })