cef/patch/patches/print_header_footer_1478_15...

165 lines
6.9 KiB
Diff
Raw Normal View History

diff --git printing/renderer/print_web_view_helper.cc printing/renderer/print_web_view_helper.cc
index f2dc502..c0049d0 100644
--- printing/renderer/print_web_view_helper.cc
+++ printing/renderer/print_web_view_helper.cc
@@ -74,6 +74,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();";
@@ -88,9 +91,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)
@@ -481,7 +481,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,
@@ -537,7 +536,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,
@@ -810,6 +808,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),
@@ -1249,7 +1248,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);
@@ -1282,7 +1283,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 3e4033d..7a8b61f 100644
--- printing/renderer/print_web_view_helper_linux.cc
+++ printing/renderer/print_web_view_helper_linux.cc
@@ -152,7 +152,6 @@ void PrintWebViewHelper::PrintPageInternal(
MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile);
-#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?
@@ -161,7 +160,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 293f567..601fee6 100644
--- printing/renderer/print_web_view_helper_mac.mm
+++ printing/renderer/print_web_view_helper_mac.mm
@@ -125,14 +125,12 @@ void PrintWebViewHelper::RenderPage(const PrintMsg_Print_Params& params,
MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile);
skia::SetIsPreviewMetafile(*canvas, is_preview);
-#if defined(ENABLE_PRINT_PREVIEW)
if (params.display_header_footer) {
PrintHeaderAndFooter(static_cast<blink::WebCanvas*>(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<blink::WebCanvas*>(canvas));
}
diff --git printing/renderer/print_web_view_helper_pdf_win.cc printing/renderer/print_web_view_helper_pdf_win.cc
index 13ad735..fffce71 100644
--- printing/renderer/print_web_view_helper_pdf_win.cc
+++ printing/renderer/print_web_view_helper_pdf_win.cc
@@ -160,14 +160,12 @@ void PrintWebViewHelper::PrintPageInternal(
MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile);
-#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 @@
<?xml version="1.0" encoding="utf-8"?>
<grit-part>
- <if expr="enable_print_preview">
<include name="IDR_PRINT_PREVIEW_PAGE" file="../printing/resources/print_preview_page.html" flattenhtml="true" allowexternalscript="false" type="BINDATA" />
- </if>
</grit-part>