#include "atom/common/node_includes.h"
+namespace {
+
+struct PrintSettings {
+ bool silent;
+ bool print_backgournd;
+};
+
+} // namespace
+
namespace mate {
+template<>
+struct Converter<PrintSettings> {
+ static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
+ PrintSettings* out) {
+ mate::Dictionary dict;
+ if (!ConvertFromV8(isolate, val, &dict))
+ return false;
+ if (!dict.Get("silent", &(out->silent)) ||
+ !dict.Get("printBackground", &(out->print_backgournd)))
+ return false;
+ return true;
+ }
+};
+
template<>
struct Converter<gfx::Rect> {
static bool FromV8(v8::Isolate* isolate,
rect, base::Bind(&OnCapturePageDone, args->isolate(), callback));
}
-void Window::Print() {
- window_->Print();
+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_backgournd);
}
mate::Handle<WebContents> Window::GetWebContents(v8::Isolate* isolate) const {
void SetDocumentEdited(bool edited);
bool IsDocumentEdited();
void CapturePage(mate::Arguments* args);
- void Print();
+ void Print(mate::Arguments* args);
// APIs for WebContents.
mate::Handle<WebContents> GetWebContents(v8::Isolate* isolate) const;
void NativeWindow::SetMenu(ui::MenuModel* menu) {
}
-void NativeWindow::Print() {
+void NativeWindow::Print(bool silent, bool print_background) {
printing::PrintViewManagerBasic::FromWebContents(GetWebContents())->
- PrintNow();
+ PrintNow(silent, print_background);
}
bool NativeWindow::HasModalDialog() {
const CapturePageCallback& callback);
// Print current page.
- virtual void Print();
+ virtual void Print(bool silent, bool print_background);
// The same with closing a tab in a real browser.
//
DisconnectFromCurrentPrintJob();
}
-bool PrintViewManagerBase::PrintNow() {
- return PrintNowInternal(new PrintMsg_PrintPages(routing_id()));
+bool PrintViewManagerBase::PrintNow(bool silent, bool print_background) {
+ return PrintNowInternal(new PrintMsg_PrintPages(
+ routing_id(), silent, print_background));
}
void PrintViewManagerBase::NavigationStopped() {
// Prints the current document immediately. Since the rendering is
// asynchronous, the actual printing will not be completed on the return of
// this function. Returns false if printing is impossible at the moment.
- virtual bool PrintNow();
+ virtual bool PrintNow(bool silent, bool print_background);
// PrintedPagesSource implementation.
virtual base::string16 RenderSourceName() OVERRIDE;
selection_only(false),
supports_alpha_blend(false),
print_scaling_option(blink::WebPrintScalingOptionSourceSize),
- print_to_pdf(false),
title(),
url(),
should_print_backgrounds(false) {
selection_only = false;
supports_alpha_blend = false;
print_scaling_option = blink::WebPrintScalingOptionSourceSize;
- print_to_pdf = false;
title.clear();
url.clear();
should_print_backgrounds = false;
bool selection_only;
bool supports_alpha_blend;
blink::WebPrintScalingOption print_scaling_option;
- bool print_to_pdf;
base::string16 title;
base::string16 url;
bool should_print_backgrounds;
// Specifies the page scaling option for preview printing.
IPC_STRUCT_TRAITS_MEMBER(print_scaling_option)
- // True if print to pdf is requested.
- IPC_STRUCT_TRAITS_MEMBER(print_to_pdf)
-
// Title string to be printed as header if requested by the user.
IPC_STRUCT_TRAITS_MEMBER(title)
// Tells the render view to switch the CSS to print media type, renders every
// requested pages and switch back the CSS to display media type.
-IPC_MESSAGE_ROUTED0(PrintMsg_PrintPages)
+IPC_MESSAGE_ROUTED2(PrintMsg_PrintPages,
+ bool /* silent print */,
+ bool /* print page's background */)
// Tells the render view that printing is done so it can clean up.
IPC_MESSAGE_ROUTED1(PrintMsg_PrintingDone,
return true;
}
-void PrintWebViewHelper::OnPrintPages() {
+void PrintWebViewHelper::OnPrintPages(bool silent, bool print_background) {
blink::WebLocalFrame* frame;
if (GetPrintFrame(&frame))
- Print(frame, blink::WebNode());
+ Print(frame, blink::WebNode(), silent, print_background);
}
void PrintWebViewHelper::GetPageSizeAndContentAreaFromPageLayout(
ignore_css_margins_ = (margins_type != DEFAULT_MARGINS);
}
-bool PrintWebViewHelper::IsPrintToPdfRequested(
- const base::DictionaryValue& job_settings) {
- bool print_to_pdf = false;
- if (!job_settings.GetBoolean(kSettingPrintToPDF, &print_to_pdf))
- NOTREACHED();
- return print_to_pdf;
-}
-
void PrintWebViewHelper::OnPrintingDone(bool success) {
notify_browser_of_print_failure_ = false;
if (!success)
}
void PrintWebViewHelper::Print(blink::WebLocalFrame* frame,
- const blink::WebNode& node) {
+ const blink::WebNode& node,
+ bool silent,
+ bool print_background) {
// If still not finished with earlier print request simply ignore.
if (prep_frame_view_)
return;
}
// Ask the browser to show UI to retrieve the final print settings.
- if (!GetPrintSettingsFromUser(frame_ref.GetFrame(), node,
- expected_page_count)) {
+ if (!silent && !GetPrintSettingsFromUser(frame_ref.GetFrame(), node,
+ expected_page_count)) {
DidFinishPrinting(OK); // Release resources and fail silently.
return;
}
+ print_pages_params_->params.should_print_backgrounds = print_background;
+
// Render Pages for printing.
if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) {
LOG(ERROR) << "RenderPagesForPrint failed";
bool user_initiated) OVERRIDE;
// Message handlers ---------------------------------------------------------
- void OnPrintPages();
+ void OnPrintPages(bool silent, bool print_background);
void OnPrintingDone(bool success);
// Get |page_size| and |content_area| information from
// Update |ignore_css_margins_| based on settings.
void UpdateFrameMarginsCssInfo(const base::DictionaryValue& settings);
- // Returns true if the current destination printer is PRINT_TO_PDF.
- bool IsPrintToPdfRequested(const base::DictionaryValue& settings);
-
// Main printing code -------------------------------------------------------
- void Print(blink::WebLocalFrame* frame, const blink::WebNode& node);
+ void Print(blink::WebLocalFrame* frame,
+ const blink::WebNode& node,
+ bool silent = false,
+ bool print_background = false);
// Notification when printing is done - signal tear-down/free resources.
void DidFinishPrinting(PrintingResult result);