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 9da6bcc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
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 9da6bcc

Please sign in to comment.