fix: crash on custom printing margins (#22164) (#22187)

This commit is contained in:
Shelley Vohr
2020-02-17 00:44:53 +00:00
committed by GitHub
parent 14d9b8a8b4
commit c30ecc38d0
2 changed files with 18 additions and 6 deletions

View File

@@ -1728,18 +1728,21 @@ void WebContents::Print(mate::Arguments* args) {
settings.SetInteger(printing::kSettingMarginsType, margin_type);
if (margin_type == printing::CUSTOM_MARGINS) {
auto custom_margins = std::make_unique<base::DictionaryValue>();
int top = 0;
margins.Get("top", &top);
settings.SetInteger(printing::kSettingMarginTop, top);
custom_margins->SetInteger(printing::kSettingMarginTop, top);
int bottom = 0;
margins.Get("bottom", &bottom);
settings.SetInteger(printing::kSettingMarginBottom, bottom);
custom_margins->SetInteger(printing::kSettingMarginBottom, bottom);
int left = 0;
margins.Get("left", &left);
settings.SetInteger(printing::kSettingMarginLeft, left);
custom_margins->SetInteger(printing::kSettingMarginLeft, left);
int right = 0;
margins.Get("right", &right);
settings.SetInteger(printing::kSettingMarginRight, right);
custom_margins->SetInteger(printing::kSettingMarginRight, right);
settings.SetDictionary(printing::kSettingMarginsCustom,
std::move(custom_margins));
}
} else {
settings.SetInteger(printing::kSettingMarginsType,

View File

@@ -130,9 +130,18 @@ describe('webContents module', () => {
}).to.throw('webContents.print(): Invalid deviceName provided.')
})
it('does not crash', () => {
it('does not crash with custom margins', () => {
expect(() => {
w.webContents.print({ silent: true })
w.webContents.print({
silent: true,
margins: {
marginType: 'custom',
top: 1,
bottom: 1,
left: 1,
right: 1
}
})
}).to.not.throw()
})
})