Skip to content

Commit

Permalink
address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Jan 29, 2020
1 parent f513be4 commit 858dbc6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 28 deletions.
23 changes: 2 additions & 21 deletions docs/api/webview-tag.md
Expand Up @@ -545,28 +545,9 @@ Stops any `findInPage` request for the `webview` with the provided `action`.

* `options` Object (optional)
* `silent` Boolean (optional) - Don't ask user for print settings. Default is `false`.
* `printBackground` Boolean (optional) - Prints the background color and image of
* `printBackground` Boolean (optional) - Also prints the background color and image of
the web page. Default is `false`.
* `deviceName` String (optional) - Set the printer device name to use. Must be the system-defined name and not the 'friendly' name, e.g 'Brother_QL_820NWB' and not 'Brother QL-820NWB'.
* `color` Boolean (optional) - Set whether the printed web page will be in color or grayscale. Default is `true`.
* `margins` Object (optional)
* `marginType` String (optional) - Can be `default`, `none`, `printableArea`, or `custom`. If `custom` is chosen, you will also need to specify `top`, `bottom`, `left`, and `right`.
* `top` Number (optional) - The top margin of the printed web page, in pixels.
* `bottom` Number (optional) - The bottom margin of the printed web page, in pixels.
* `left` Number (optional) - The left margin of the printed web page, in pixels.
* `right` Number (optional) - The right margin of the printed web page, in pixels.
* `landscape` Boolean (optional) - Whether the web page should be printed in landscape mode. Default is `false`.
* `scaleFactor` Number (optional) - The scale factor of the web page.
* `pagesPerSheet` Number (optional) - The number of pages to print per page sheet.
* `collate` Boolean (optional) - Whether the web page should be collated.
* `copies` Number (optional) - The number of copies of the web page to print.
* `pageRanges` Record<string, number> (optional) - The page range to print. Should have two keys: `from` and `to`.
* `duplexMode` String (optional) - Set the duplex mode of the printed web page. Can be `simplex`, `shortEdge`, or `longEdge`.
* `dpi` Object (optional)
* `horizontal` Number (optional) - The horizontal dpi.
* `vertical` Number (optional) - The vertical dpi.
* `header` String (optional) - String to be printed as page header.
* `footer` String (optional) - String to be printed as page footer.
* `deviceName` String (optional) - Set the printer device name to use. Default is `''`.

Returns `Promise<void>`

Expand Down
14 changes: 8 additions & 6 deletions shell/browser/api/atom_api_web_contents.cc
Expand Up @@ -354,14 +354,17 @@ base::Optional<base::TimeDelta> GetCursorBlinkInterval() {
// This will return false if no printer with the provided device_name can be
// found on the network. We need to check this because Chromium does not do
// sanity checking of device_name validity and so will crash on invalid names.
bool DeviceNameValid(const std::string& device_name) {
bool IsDeviceNameValid(const base::string16& device_name) {
#if defined(OS_MACOSX)
base::ScopedCFTypeRef<CFStringRef> new_printer_id(
base::SysUTF8ToCFStringRef(device_name));
return PMPrinterCreateFromPrinterID(new_printer_id.get());
base::SysUTF16ToCFStringRef(device_name));
PMPrinter new_printer = PMPrinterCreateFromPrinterID(new_printer_id.get());
bool printer_exists = new_printer != nullptr;
PMRelease(new_printer);
return printer_exists;
#elif defined(OS_WIN)
printing::ScopedPrinterHandle printer;
return printer.OpenPrinterWithName(base::UTF8ToUTF16(device_name).c_str());
return printer.OpenPrinterWithName(device_name.c_str());
#endif
return true;
}
Expand Down Expand Up @@ -1804,8 +1807,7 @@ void WebContents::Print(gin_helper::Arguments* args) {
// Printer device name as opened by the OS.
base::string16 device_name;
options.Get("deviceName", &device_name);
if (!device_name.empty() &&
!DeviceNameValid(base::UTF16ToUTF8(device_name))) {
if (!device_name.empty() && !IsDeviceNameValid(device_name)) {
args->ThrowError("webContents.print(): Invalid deviceName provided.");
return;
}
Expand Down
1 change: 0 additions & 1 deletion spec-main/api-web-contents-spec.ts
Expand Up @@ -128,7 +128,6 @@ describe('webContents module', () => {
})

it('does not crash', () => {
const w = new BrowserWindow({ show: false })
expect(() => {
w.webContents.print({ silent: true })
}).to.not.throw()
Expand Down

0 comments on commit 858dbc6

Please sign in to comment.