fix: crash on custom printing margins (#22164)
This commit is contained in:
parent
f97ce86d08
commit
6ed396df17
2 changed files with 18 additions and 6 deletions
|
@ -1807,18 +1807,21 @@ void WebContents::Print(gin_helper::Arguments* args) {
|
||||||
settings.SetIntKey(printing::kSettingMarginsType, margin_type);
|
settings.SetIntKey(printing::kSettingMarginsType, margin_type);
|
||||||
|
|
||||||
if (margin_type == printing::CUSTOM_MARGINS) {
|
if (margin_type == printing::CUSTOM_MARGINS) {
|
||||||
|
base::Value custom_margins(base::Value::Type::DICTIONARY);
|
||||||
int top = 0;
|
int top = 0;
|
||||||
margins.Get("top", &top);
|
margins.Get("top", &top);
|
||||||
settings.SetIntKey(printing::kSettingMarginTop, top);
|
custom_margins.SetIntKey(printing::kSettingMarginTop, top);
|
||||||
int bottom = 0;
|
int bottom = 0;
|
||||||
margins.Get("bottom", &bottom);
|
margins.Get("bottom", &bottom);
|
||||||
settings.SetIntKey(printing::kSettingMarginBottom, bottom);
|
custom_margins.SetIntKey(printing::kSettingMarginBottom, bottom);
|
||||||
int left = 0;
|
int left = 0;
|
||||||
margins.Get("left", &left);
|
margins.Get("left", &left);
|
||||||
settings.SetIntKey(printing::kSettingMarginLeft, left);
|
custom_margins.SetIntKey(printing::kSettingMarginLeft, left);
|
||||||
int right = 0;
|
int right = 0;
|
||||||
margins.Get("right", &right);
|
margins.Get("right", &right);
|
||||||
settings.SetIntKey(printing::kSettingMarginRight, right);
|
custom_margins.SetIntKey(printing::kSettingMarginRight, right);
|
||||||
|
settings.SetPath(printing::kSettingMarginsCustom,
|
||||||
|
std::move(custom_margins));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
settings.SetIntKey(printing::kSettingMarginsType,
|
settings.SetIntKey(printing::kSettingMarginsType,
|
||||||
|
|
|
@ -135,9 +135,18 @@ describe('webContents module', () => {
|
||||||
}).to.throw('Unsupported pageSize: i-am-a-bad-pagesize')
|
}).to.throw('Unsupported pageSize: i-am-a-bad-pagesize')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does not crash', () => {
|
it('does not crash with custom margins', () => {
|
||||||
expect(() => {
|
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()
|
}).to.not.throw()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue