Merge pull request #6278 from electron/ico-native-image-crash
Fix nativeImage.createFromPath for non-existent .ico
This commit is contained in:
commit
49bec9165c
3 changed files with 16 additions and 1 deletions
|
@ -160,10 +160,14 @@ base::win::ScopedHICON ReadICOFromPath(int size, const base::FilePath& path) {
|
||||||
LR_LOADFROMFILE)));
|
LR_LOADFROMFILE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadImageSkiaFromICO(gfx::ImageSkia* image, HICON icon) {
|
bool ReadImageSkiaFromICO(gfx::ImageSkia* image, HICON icon) {
|
||||||
// Convert the icon from the Windows specific HICON to gfx::ImageSkia.
|
// Convert the icon from the Windows specific HICON to gfx::ImageSkia.
|
||||||
std::unique_ptr<SkBitmap> bitmap(IconUtil::CreateSkBitmapFromHICON(icon));
|
std::unique_ptr<SkBitmap> bitmap(IconUtil::CreateSkBitmapFromHICON(icon));
|
||||||
|
if (!bitmap)
|
||||||
|
return false;
|
||||||
|
|
||||||
image->AddRepresentation(gfx::ImageSkiaRep(*bitmap, 1.0f));
|
image->AddRepresentation(gfx::ImageSkiaRep(*bitmap, 1.0f));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ describe('nativeImage module', () => {
|
||||||
it('returns an empty image for invalid paths', () => {
|
it('returns an empty image for invalid paths', () => {
|
||||||
assert(nativeImage.createFromPath('').isEmpty())
|
assert(nativeImage.createFromPath('').isEmpty())
|
||||||
assert(nativeImage.createFromPath('does-not-exist.png').isEmpty())
|
assert(nativeImage.createFromPath('does-not-exist.png').isEmpty())
|
||||||
|
assert(nativeImage.createFromPath('does-not-exist.ico').isEmpty())
|
||||||
})
|
})
|
||||||
|
|
||||||
it('loads images from paths relative to the current working directory', () => {
|
it('loads images from paths relative to the current working directory', () => {
|
||||||
|
@ -47,5 +48,15 @@ describe('nativeImage module', () => {
|
||||||
// If all bytes are null, that's Bad
|
// If all bytes are null, that's Bad
|
||||||
assert.equal(nsimage.reduce((acc, x) => acc || (x !== 0), false), true)
|
assert.equal(nsimage.reduce((acc, x) => acc || (x !== 0), false), true)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('loads images from .ico files on Windows', () => {
|
||||||
|
if (process.platform !== 'win32') return
|
||||||
|
|
||||||
|
const imagePath = path.join(__dirname, 'fixtures', 'assets', 'icon.ico')
|
||||||
|
const image = nativeImage.createFromPath(imagePath)
|
||||||
|
assert(!image.isEmpty())
|
||||||
|
assert.equal(image.getSize().height, 256)
|
||||||
|
assert.equal(image.getSize().width, 256)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
BIN
spec/fixtures/assets/icon.ico
vendored
Normal file
BIN
spec/fixtures/assets/icon.ico
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 76 KiB |
Loading…
Reference in a new issue