Also move the print implementation from window to webContents.
#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_view_manager_basic.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 "atom/common/node_includes.h"
+namespace {
+
+struct PrintSettings {
+ bool silent;
+ bool print_background;
+};
+
+} // namespace
+
namespace mate {
template<>
}
};
+template<>
+struct Converter<PrintSettings> {
+ static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
+ PrintSettings* out) {
+ mate::Dictionary dict;
+ if (!ConvertFromV8(isolate, val, &dict))
+ return false;
+ dict.Get("silent", &(out->silent));
+ dict.Get("printBackground", &(out->print_background));
+ return true;
+ }
+};
+
} // namespace mate
callback);
}
-<<<<<<< HEAD
-<<<<<<< HEAD
void WebContents::SetAudioMuted(bool muted) {
web_contents()->SetAudioMuted(muted);
}
return web_contents()->IsAudioMuted();
}
+void WebContents::Print(mate::Arguments* args) {
+ PrintSettings settings = { false, false };
+ if (args->Length() == 1 && !args->GetNext(&settings)) {
+ args->ThrowError();
+ return;
+ }
+
+ printing::PrintViewManagerBasic::FromWebContents(web_contents())->
+ PrintNow(settings.silent, settings.print_background);
+}
+
void WebContents::PrintToPDF(const base::DictionaryValue& setting,
const PrintToPDFCallback& callback) {
printing::PrintPreviewMessageHandler::FromWebContents(web_contents())->
.SetMethod("unregisterServiceWorker",
&WebContents::UnregisterServiceWorker)
.SetMethod("inspectServiceWorker", &WebContents::InspectServiceWorker)
+ .SetMethod("print", &WebContents::Print)
.SetMethod("_printToPDF", &WebContents::PrintToPDF)
.Build());
void UnregisterServiceWorker(const base::Callback<void(bool)>&);
void SetAudioMuted(bool muted);
bool IsAudioMuted();
+ void Print(mate::Arguments* args);
// Print current page as PDF.
void PrintToPDF(const base::DictionaryValue& setting,
#include "atom/common/node_includes.h"
-namespace {
-
-struct PrintSettings {
- bool silent;
- bool print_background;
-};
-
-} // namespace
-
-namespace mate {
-
-template<>
-struct Converter<PrintSettings> {
- static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
- PrintSettings* out) {
- mate::Dictionary dict;
- if (!ConvertFromV8(isolate, val, &dict))
- return false;
- dict.Get("silent", &(out->silent));
- dict.Get("printBackground", &(out->print_background));
- return true;
- }
-};
-
-} // namespace mate
-
namespace atom {
namespace api {
rect, base::Bind(&OnCapturePageDone, args->isolate(), callback));
}
-void Window::Print(mate::Arguments* args) {
- PrintSettings settings = { false, false };
- if (args->Length() == 1 && !args->GetNext(&settings)) {
- args->ThrowError();
- return;
- }
-
- window_->Print(settings.silent, settings.print_background);
-}
-
void Window::SetProgressBar(double progress) {
window_->SetProgressBar(progress);
}
.SetMethod("blurWebView", &Window::BlurWebView)
.SetMethod("isWebViewFocused", &Window::IsWebViewFocused)
.SetMethod("capturePage", &Window::CapturePage)
- .SetMethod("print", &Window::Print)
.SetMethod("setProgressBar", &Window::SetProgressBar)
.SetMethod("setOverlayIcon", &Window::SetOverlayIcon)
.SetMethod("_setMenu", &Window::SetMenu)
void SetDocumentEdited(bool edited);
bool IsDocumentEdited();
void CapturePage(mate::Arguments* args);
- void Print(mate::Arguments* args);
void SetProgressBar(double progress);
void SetOverlayIcon(const gfx::Image& overlay,
const std::string& description);
BrowserWindow::toggleDevTools = -> @webContents.toggleDevTools()
BrowserWindow::inspectElement = -> @webContents.inspectElement.apply @webContents, arguments
BrowserWindow::inspectServiceWorker = -> @webContents.inspectServiceWorker()
+BrowserWindow::print = -> @webContents.print.apply @webContents, arguments
module.exports = BrowserWindow
#include "atom/browser/web_dialog_helper.h"
#include "base/files/file_util.h"
#include "chrome/browser/printing/print_preview_message_handler.h"
+#include "chrome/browser/printing/print_view_manager_basic.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "content/public/browser/child_process_security_policy.h"
#include "content/public/browser/render_process_host.h"
owner_window_ = owner_window;
web_contents->SetDelegate(this);
+ printing::PrintViewManagerBasic::CreateForWebContents(web_contents);
printing::PrintPreviewMessageHandler::CreateForWebContents(web_contents);
// Create InspectableWebContents.
#include "base/strings/utf_string_conversions.h"
#include "brightray/browser/inspectable_web_contents.h"
#include "brightray/browser/inspectable_web_contents_view.h"
-#include "chrome/browser/printing/print_view_manager_basic.h"
#include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/notification_details.h"
has_dialog_attached_(false),
zoom_factor_(1.0),
weak_factory_(this) {
- printing::PrintViewManagerBasic::CreateForWebContents(web_contents);
-
InitWithWebContents(web_contents, this);
options.Get(switches::kFrame, &has_frame_);
void NativeWindow::SetMenu(ui::MenuModel* menu) {
}
-void NativeWindow::Print(bool silent, bool print_background) {
- printing::PrintViewManagerBasic::FromWebContents(GetWebContents())->
- PrintNow(silent, print_background);
-}
-
void NativeWindow::ShowDefinitionForSelection() {
NOTIMPLEMENTED();
}
virtual void CapturePage(const gfx::Rect& rect,
const CapturePageCallback& callback);
- // Print current page.
- virtual void Print(bool silent, bool print_background);
-
// Show popup dictionary.
virtual void ShowDefinitionForSelection();
"send"
"getId"
"inspectServiceWorker"
+ "print"
"printToPDF"
]
### BrowserWindow.print([options])
-* `options` Object
- * `silent` Boolean - Don't ask user for print settings, defaults to `false`
- * `printBackground` Boolean - Also prints the background color and image of
- the web page, defaults to `false`.
-
-Prints window's web page. When `silent` is set to `false`, Electron will pick
-up system's default printer and default settings for printing.
-
-Calling `window.print()` in web page is equivalent to call
-`BrowserWindow.print({silent: false, printBackground: false})`.
-
-**Note:** On Windows, the print API relies on `pdf.dll`. If your application
-doesn't need print feature, you can safely remove `pdf.dll` in saving binary
-size.
+Same with `webContents.print([options])`
### BrowserWindow.loadUrl(url, [options])
response to `callback` when the JS promise is fullfilled or false
when the JS promise is rejected.
+### WebContents.print([options])
+
+* `options` Object
+ * `silent` Boolean - Don't ask user for print settings, defaults to `false`
+ * `printBackground` Boolean - Also prints the background color and image of
+ the web page, defaults to `false`.
+
+Prints window's web page. When `silent` is set to `false`, Electron will pick
+up system's default printer and default settings for printing.
+
+Calling `window.print()` in web page is equivalent to call
+`WebContents.print({silent: false, printBackground: false})`.
+
+**Note:** On Windows, the print API relies on `pdf.dll`. If your application
+doesn't need print feature, you can safely remove `pdf.dll` in saving binary
+size.
+
### WebContents.printToPDF(options, callback)
* `options` Object
Executes editing command `replaceMisspelling` in page.
+### `<webview>.print([options])`
+
+Prints webview's web page. Same with `webContents.print([options])`.
+
### `<webview>`.send(channel[, args...])
* `channel` String