From 5345b08d247b957988fc74ecc79825d629da20ae Mon Sep 17 00:00:00 2001 From: Geoff Lywood Date: Wed, 7 Dec 2016 17:33:28 -0800 Subject: [PATCH] Fix printing with the sandbox enabled Closes #7984 --- .../atom_sandboxed_renderer_client.cc | 2 ++ spec/api-browser-window-spec.js | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/atom/renderer/atom_sandboxed_renderer_client.cc b/atom/renderer/atom_sandboxed_renderer_client.cc index 47d9d0ded6c6..892930cf5004 100644 --- a/atom/renderer/atom_sandboxed_renderer_client.cc +++ b/atom/renderer/atom_sandboxed_renderer_client.cc @@ -15,6 +15,7 @@ #include "atom/renderer/api/atom_api_renderer_ipc.h" #include "atom/renderer/atom_render_view_observer.h" #include "base/command_line.h" +#include "chrome/renderer/printing/print_web_view_helper.h" #include "content/public/renderer/render_frame.h" #include "content/public/renderer/render_frame_observer.h" #include "content/public/renderer/render_view.h" @@ -126,6 +127,7 @@ void AtomSandboxedRendererClient::RenderFrameCreated( void AtomSandboxedRendererClient::RenderViewCreated( content::RenderView* render_view) { + new printing::PrintWebViewHelper(render_view); new AtomSandboxedRenderViewObserver(render_view, this); } diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index dad48d5497aa..26fb22df39b8 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -943,6 +943,26 @@ describe('browser-window module', function () { w.loadURL('file://' + path.join(fixtures, 'api', 'sandbox.html?webcontents-events')) }) }) + + it('can print to PDF', function (done) { + w.destroy() + w = new BrowserWindow({ + show: false, + webPreferences: { + sandbox: true, + preload: preload + } + }) + w.loadURL('data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E') + w.webContents.once('did-finish-load', function () { + w.webContents.printToPDF({}, function (error, data) { + assert.equal(error, null) + assert.equal(data instanceof Buffer, true) + assert.notEqual(data.length, 0) + done() + }) + }) + }) }) })