diff --git printing/renderer/print_web_view_helper.cc printing/renderer/print_web_view_helper.cc index 27419d6..0a6757b 100644 --- printing/renderer/print_web_view_helper.cc +++ printing/renderer/print_web_view_helper.cc @@ -73,6 +73,9 @@ const double kMinDpi = 1.0; #if defined(ENABLE_PRINT_PREVIEW) bool g_is_preview_enabled = true; +#else +bool g_is_preview_enabled = false; +#endif // defined(ENABLE_PRINT_PREVIEW) const char kPageLoadScriptFormat[] = "document.open(); document.write(%s); document.close();"; @@ -87,9 +90,6 @@ void ExecuteScript(blink::WebFrame* frame, std::string script = base::StringPrintf(script_format, json.c_str()); frame->executeScript(blink::WebString(base::UTF8ToUTF16(script))); } -#else -bool g_is_preview_enabled = false; -#endif // defined(ENABLE_PRINT_PREVIEW) int GetDPI(const PrintMsg_Print_Params* print_params) { #if defined(OS_MACOSX) @@ -480,7 +480,6 @@ blink::WebView* FrameReference::view() { return view_; } -#if defined(ENABLE_PRINT_PREVIEW) // static - Not anonymous so that platform implementations can use it. void PrintWebViewHelper::PrintHeaderAndFooter( blink::WebCanvas* canvas, @@ -536,7 +535,6 @@ void PrintWebViewHelper::PrintHeaderAndFooter( web_view->close(); frame->close(); } -#endif // defined(ENABLE_PRINT_PREVIEW) // static - Not anonymous so that platform implementations can use it. float PrintWebViewHelper::RenderPageContent(blink::WebFrame* frame, @@ -807,6 +805,7 @@ PrintWebViewHelper::PrintWebViewHelper(content::RenderView* render_view, print_for_preview_(false), delegate_(delegate.Pass()), print_node_in_progress_(false), + force_print_preview_(false), is_loading_(false), is_scripted_preview_delayed_(false), ipc_nesting_level_(0), @@ -1246,7 +1245,9 @@ void PrintWebViewHelper::OnInitiatePrintPreview(bool selection_only) { // that instead. auto plugin = delegate_->GetPdfElement(frame); if (!plugin.isNull()) { + force_print_preview_ = true; PrintNode(plugin); + force_print_preview_ = false; return; } print_preview_context_.InitWithFrame(frame); @@ -1279,7 +1280,7 @@ void PrintWebViewHelper::PrintNode(const blink::WebNode& node) { // Make a copy of the node, in case RenderView::OnContextMenuClosed resets // its |context_menu_node_|. - if (!g_is_preview_enabled) { + if (!g_is_preview_enabled && !force_print_preview_) { blink::WebNode duplicate_node(node); Print(duplicate_node.document().frame(), duplicate_node, false); } else { diff --git printing/renderer/print_web_view_helper.h printing/renderer/print_web_view_helper.h index d9ea441..dce6b9e 100644 --- printing/renderer/print_web_view_helper.h +++ printing/renderer/print_web_view_helper.h @@ -309,7 +309,6 @@ class PrintWebViewHelper double* scale_factor, PageSizeMargins* page_layout_in_points); -#if defined(ENABLE_PRINT_PREVIEW) // Given the |device| and |canvas| to draw on, prints the appropriate headers // and footers using strings from |header_footer_info| on to the canvas. static void PrintHeaderAndFooter(blink::WebCanvas* canvas, @@ -319,7 +318,6 @@ class PrintWebViewHelper float webkit_scale_factor, const PageSizeMargins& page_layout_in_points, const PrintMsg_Print_Params& params); -#endif // defined(ENABLE_PRINT_PREVIEW) bool GetPrintFrame(blink::WebLocalFrame** frame); @@ -498,6 +496,7 @@ class PrintWebViewHelper ScriptingThrottler scripting_throttler_; bool print_node_in_progress_; + bool force_print_preview_; PrintPreviewContext print_preview_context_; bool is_loading_; bool is_scripted_preview_delayed_; diff --git printing/renderer/print_web_view_helper_linux.cc printing/renderer/print_web_view_helper_linux.cc index 52f92ec..85f7adb 100644 --- printing/renderer/print_web_view_helper_linux.cc +++ printing/renderer/print_web_view_helper_linux.cc @@ -154,7 +154,6 @@ void PrintWebViewHelper::PrintPageInternal( MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); -#if defined(ENABLE_PRINT_PREVIEW) if (params.params.display_header_footer) { // |page_number| is 0-based, so 1 is added. // TODO(vitalybuka) : why does it work only with 1.25? @@ -163,7 +162,6 @@ void PrintWebViewHelper::PrintPageInternal( scale_factor / 1.25, page_layout_in_points, params.params); } -#endif // defined(ENABLE_PRINT_PREVIEW) RenderPageContent(frame, params.page_number, canvas_area, content_area, scale_factor, canvas); diff --git printing/renderer/print_web_view_helper_mac.mm printing/renderer/print_web_view_helper_mac.mm index f2b94e7..8c5df5e 100644 --- printing/renderer/print_web_view_helper_mac.mm +++ printing/renderer/print_web_view_helper_mac.mm @@ -126,14 +126,12 @@ void PrintWebViewHelper::RenderPage(const PrintMsg_Print_Params& params, MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); skia::SetIsPreviewMetafile(*canvas, is_preview); -#if defined(ENABLE_PRINT_PREVIEW) if (params.display_header_footer) { PrintHeaderAndFooter(static_cast(canvas), page_number + 1, print_preview_context_.total_page_count(), *frame, scale_factor, page_layout_in_points, params); } -#endif // defined(ENABLE_PRINT_PREVIEW) RenderPageContent(frame, page_number, canvas_area, content_area, scale_factor, static_cast(canvas)); } diff --git printing/renderer/print_web_view_helper_pdf_win.cc printing/renderer/print_web_view_helper_pdf_win.cc index 56acc74..ac85bf6 100644 --- printing/renderer/print_web_view_helper_pdf_win.cc +++ printing/renderer/print_web_view_helper_pdf_win.cc @@ -162,14 +162,12 @@ void PrintWebViewHelper::PrintPageInternal( MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); -#if defined(ENABLE_PRINT_PREVIEW) if (params.params.display_header_footer) { // |page_number| is 0-based, so 1 is added. PrintHeaderAndFooter(canvas, params.page_number + 1, print_preview_context_.total_page_count(), *frame, scale_factor, page_layout_in_points, params.params); } -#endif // defined(ENABLE_PRINT_PREVIEW) float webkit_scale_factor = RenderPageContent(frame, params.page_number, canvas_area, content_area, diff --git resources/printing_resources.grdp resources/printing_resources.grdp index 7213746..32b8b1e 100644 --- resources/printing_resources.grdp +++ resources/printing_resources.grdp @@ -1,6 +1,4 @@ - -