Move printToPDF API to WebContents.

Also expose in webview.
This commit is contained in:
Haojian Wu 2015-06-09 13:07:40 +08:00
parent 2597ded985
commit c0a6cb69bf
6 changed files with 22 additions and 23 deletions

View file

@ -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<void(int)> 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(

View file

@ -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();

View file

@ -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<void(int)> 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)

View file

@ -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();
}

View file

@ -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();

View file

@ -291,6 +291,7 @@ registerWebViewElement = ->
"send"
"getId"
"inspectServiceWorker"
"printToPDF"
]
# Forward proto.foo* method calls to WebViewImpl.foo*.