]> khamidou — GitHub mirrors - electron.git/commitdiff
Move printToPDF API to WebContents.
authorHaojian Wu <hokein.wu@gmail.com>
Tue, 9 Jun 2015 05:07:40 +0000 (13:07 +0800)
committerHaojian Wu <hokein.wu@gmail.com>
Tue, 16 Jun 2015 12:06:52 +0000 (20:06 +0800)
Also expose in webview.

atom/browser/api/atom_api_web_contents.cc
atom/browser/api/atom_api_web_contents.h
atom/browser/api/atom_api_window.cc
atom/browser/native_window.cc
atom/browser/native_window.h
atom/renderer/lib/web-view/web-view.coffee

index ec24ab45fa241b35e2f40ba51e99c787f9dbc992..e325ed902aed9cd1535b10787b7e54813cba8db6 100644 (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(
index 7c20144517f38b4245005d4d6d809e4ce02aa69b..0f8f08889feff67cec2bb5331c18a0a814d3bc2c 100644 (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();
index 4b6ab9c95422d45765adea1a10f63f6f89894c03..69271c0db328eab84676d017db9dcda95e7515b3 100644 (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)
index e1cdab59471b32dca2aeeb3020e1e12db535453c..581565ad188cca6b4d336a285487794297b33828 100644 (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();
 }
index 78187bc8d45851e5485be5fe2286d860b62e15cd..a5b8b677b2d54a05bbf7a6dab14637e0fb379a64 100644 (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();
 
index 443b2bca1f2dd5658956c68be4e6354510429d2d..3778d7f48d3f76c8714c592664145948d6d424be 100644 (file)
@@ -291,6 +291,7 @@ registerWebViewElement = ->
     "send"
     "getId"
     "inspectServiceWorker"
+    "printToPDF"
   ]
 
   # Forward proto.foo* method calls to WebViewImpl.foo*.