From c0a6cb69bf21847c84b850fc8a537d0d878bfb65 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Tue, 9 Jun 2015 13:07:40 +0800 Subject: [PATCH] Move printToPDF API to WebContents. Also expose in webview. --- atom/browser/api/atom_api_web_contents.cc | 18 ++++++++++++++++++ atom/browser/api/atom_api_web_contents.h | 3 +++ atom/browser/api/atom_api_window.cc | 13 ------------- atom/browser/native_window.cc | 6 ------ atom/browser/native_window.h | 4 ---- atom/renderer/lib/web-view/web-view.coffee | 1 + 6 files changed, 22 insertions(+), 23 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index ec24ab45fa..e325ed902a 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -18,6 +18,7 @@ #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "brightray/browser/inspectable_web_contents.h" +#include "chrome/browser/printing/print_preview_message_handler.h" #include "content/public/browser/favicon_status.h" #include "content/public/browser/guest_host.h" #include "content/public/browser/navigation_details.h" @@ -137,6 +138,7 @@ WebContents::WebContents(const mate::Dictionary& options) inspectable_web_contents_ = managed_web_contents(); Observe(GetWebContents()); + printing::PrintPreviewMessageHandler::CreateForWebContents(web_contents); } WebContents::~WebContents() { @@ -580,6 +582,7 @@ void WebContents::UnregisterServiceWorker( callback); } +<<<<<<< HEAD void WebContents::SetAudioMuted(bool muted) { web_contents()->SetAudioMuted(muted); } @@ -588,6 +591,20 @@ bool WebContents::IsAudioMuted() { return web_contents()->IsAudioMuted(); } +void WebContents::PrintToPDF(mate::Arguments* args) { + mate::Dictionary options; + base::Callback callback; + if (!(args->Length() == 1 && args->GetNext(&callback)) && + !(args->Length() == 2 && args->GetNext(&options) + && args->GetNext(&callback))) { + args->ThrowError(); + return; + } + + printing::PrintPreviewMessageHandler::FromWebContents(web_contents())-> + PrintToPDF(options, callback); +} + void WebContents::Undo() { web_contents()->Undo(); } @@ -760,6 +777,7 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder( .SetMethod("unregisterServiceWorker", &WebContents::UnregisterServiceWorker) .SetMethod("inspectServiceWorker", &WebContents::InspectServiceWorker) + .SetMethod("printToPDF", &WebContents::PrintToPDF) .Build()); return mate::ObjectTemplateBuilder( diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 7c20144517..0f8f08889f 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -90,6 +90,9 @@ class WebContents : public mate::EventEmitter, void SetAudioMuted(bool muted); bool IsAudioMuted(); + // Print current page as PDF. + void PrintToPDF(mate::Arguments* args); + // Editing commands. void Undo(); void Redo(); diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 4b6ab9c954..69271c0db3 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -430,18 +430,6 @@ void Window::Print(mate::Arguments* args) { window_->Print(settings.silent, settings.print_background); } -void Window::PrintToPDF(mate::Arguments* args) { - mate::Dictionary options; - base::Callback callback; - if (!(args->Length() == 1 && args->GetNext(&callback)) && - !(args->Length() == 2 && args->GetNext(&options) - && args->GetNext(&callback))) { - args->ThrowError(); - return; - } - window_->PrintToPDF(options, callback); -} - void Window::SetProgressBar(double progress) { window_->SetProgressBar(progress); } @@ -554,7 +542,6 @@ void Window::BuildPrototype(v8::Isolate* isolate, .SetMethod("isWebViewFocused", &Window::IsWebViewFocused) .SetMethod("capturePage", &Window::CapturePage) .SetMethod("print", &Window::Print) - .SetMethod("printToPDF", &Window::PrintToPDF) .SetMethod("setProgressBar", &Window::SetProgressBar) .SetMethod("setOverlayIcon", &Window::SetOverlayIcon) .SetMethod("_setMenu", &Window::SetMenu) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index e1cdab5947..581565ad18 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -265,12 +265,6 @@ void NativeWindow::Print(bool silent, bool print_background) { PrintNow(silent, print_background); } -void NativeWindow::PrintToPDF(const mate::Dictionary& options, - const PrintToPDFCallback& callback) { - printing::PrintPreviewMessageHandler::FromWebContents(GetWebContents())-> - PrintToPDF(options, callback); -} - void NativeWindow::ShowDefinitionForSelection() { NOTIMPLEMENTED(); } diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 78187bc8d4..a5b8b677b2 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -158,10 +158,6 @@ class NativeWindow : public CommonWebContentsDelegate, // Print current page. virtual void Print(bool silent, bool print_background); - // Print current page as PDF. - virtual void PrintToPDF(const mate::Dictionary& options, - const PrintToPDFCallback& callback); - // Show popup dictionary. virtual void ShowDefinitionForSelection(); diff --git a/atom/renderer/lib/web-view/web-view.coffee b/atom/renderer/lib/web-view/web-view.coffee index 443b2bca1f..3778d7f48d 100644 --- a/atom/renderer/lib/web-view/web-view.coffee +++ b/atom/renderer/lib/web-view/web-view.coffee @@ -291,6 +291,7 @@ registerWebViewElement = -> "send" "getId" "inspectServiceWorker" + "printToPDF" ] # Forward proto.foo* method calls to WebViewImpl.foo*.