Commit 01f88e86 authored by vitalybuka's avatar vitalybuka Committed by Commit bot

Try to use URL and title of the printed frame for header and footer.

Removed header_footer_info_ member.

BUG=263710

Review URL: https://codereview.chromium.org/510253002

Cr-Commit-Position: refs/heads/master@{#292488}
parent dae35047
...@@ -443,9 +443,9 @@ void PrintWebViewHelper::PrintHeaderAndFooter( ...@@ -443,9 +443,9 @@ void PrintWebViewHelper::PrintHeaderAndFooter(
blink::WebCanvas* canvas, blink::WebCanvas* canvas,
int page_number, int page_number,
int total_pages, int total_pages,
const blink::WebFrame& source_frame,
float webkit_scale_factor, float webkit_scale_factor,
const PageSizeMargins& page_layout, const PageSizeMargins& page_layout,
const base::DictionaryValue& header_footer_info,
const PrintMsg_Print_Params& params) { const PrintMsg_Print_Params& params) {
skia::VectorPlatformDeviceSkia* device = skia::VectorPlatformDeviceSkia* device =
static_cast<skia::VectorPlatformDeviceSkia*>(canvas->getTopDevice()); static_cast<skia::VectorPlatformDeviceSkia*>(canvas->getTopDevice());
...@@ -455,9 +455,9 @@ void PrintWebViewHelper::PrintHeaderAndFooter( ...@@ -455,9 +455,9 @@ void PrintWebViewHelper::PrintHeaderAndFooter(
canvas->scale(1 / webkit_scale_factor, 1 / webkit_scale_factor); canvas->scale(1 / webkit_scale_factor, 1 / webkit_scale_factor);
blink::WebSize page_size(page_layout.margin_left + page_layout.margin_right + blink::WebSize page_size(page_layout.margin_left + page_layout.margin_right +
page_layout.content_width, page_layout.content_width,
page_layout.margin_top + page_layout.margin_bottom + page_layout.margin_top + page_layout.margin_bottom +
page_layout.content_height); page_layout.content_height);
blink::WebView* web_view = blink::WebView::create(NULL); blink::WebView* web_view = blink::WebView::create(NULL);
web_view->settings()->setJavaScriptEnabled(true); web_view->settings()->setJavaScriptEnabled(true);
...@@ -465,13 +465,14 @@ void PrintWebViewHelper::PrintHeaderAndFooter( ...@@ -465,13 +465,14 @@ void PrintWebViewHelper::PrintHeaderAndFooter(
blink::WebLocalFrame* frame = blink::WebLocalFrame::create(NULL); blink::WebLocalFrame* frame = blink::WebLocalFrame::create(NULL);
web_view->setMainFrame(frame); web_view->setMainFrame(frame);
base::StringValue html( base::StringValue html(ResourceBundle::GetSharedInstance().GetLocalizedString(
ResourceBundle::GetSharedInstance().GetLocalizedString( IDR_PRINT_PREVIEW_PAGE));
IDR_PRINT_PREVIEW_PAGE));
// Load page with script to avoid async operations. // Load page with script to avoid async operations.
ExecuteScript(frame, kPageLoadScriptFormat, html); ExecuteScript(frame, kPageLoadScriptFormat, html);
scoped_ptr<base::DictionaryValue> options(header_footer_info.DeepCopy()); scoped_ptr<base::DictionaryValue> options(new base::DictionaryValue());
options.reset(new base::DictionaryValue());
options->SetDouble(kSettingHeaderFooterDate, base::Time::Now().ToJsTime());
options->SetDouble("width", page_size.width); options->SetDouble("width", page_size.width);
options->SetDouble("height", page_size.height); options->SetDouble("height", page_size.height);
options->SetDouble("topMargin", page_layout.margin_top); options->SetDouble("topMargin", page_layout.margin_top);
...@@ -479,6 +480,12 @@ void PrintWebViewHelper::PrintHeaderAndFooter( ...@@ -479,6 +480,12 @@ void PrintWebViewHelper::PrintHeaderAndFooter(
options->SetString("pageNumber", options->SetString("pageNumber",
base::StringPrintf("%d/%d", page_number, total_pages)); base::StringPrintf("%d/%d", page_number, total_pages));
// Fallback to initiator URL and title if it's empty for printed frame.
base::string16 url = source_frame.document().url().string();
options->SetString("url", url.empty() ? params.url : url);
base::string16 title = source_frame.document().title();
options->SetString("title", title.empty() ? params.title : title);
ExecuteScript(frame, kPageSetupScriptFormat, *options); ExecuteScript(frame, kPageSetupScriptFormat, *options);
blink::WebPrintParams webkit_params(page_size); blink::WebPrintParams webkit_params(page_size);
...@@ -1493,17 +1500,6 @@ bool PrintWebViewHelper::UpdatePrintSettings( ...@@ -1493,17 +1500,6 @@ bool PrintWebViewHelper::UpdatePrintSettings(
UpdateFrameMarginsCssInfo(*job_settings); UpdateFrameMarginsCssInfo(*job_settings);
settings.params.print_scaling_option = GetPrintScalingOption( settings.params.print_scaling_option = GetPrintScalingOption(
frame, node, source_is_html, *job_settings, settings.params); frame, node, source_is_html, *job_settings, settings.params);
// Header/Footer: Set |header_footer_info_|.
if (settings.params.display_header_footer) {
header_footer_info_.reset(new base::DictionaryValue());
header_footer_info_->SetDouble(kSettingHeaderFooterDate,
base::Time::Now().ToJsTime());
header_footer_info_->SetString(kSettingHeaderFooterURL,
settings.params.url);
header_footer_info_->SetString(kSettingHeaderFooterTitle,
settings.params.title);
}
} }
SetPrintPagesParams(settings); SetPrintPagesParams(settings);
......
...@@ -273,14 +273,13 @@ class PrintWebViewHelper ...@@ -273,14 +273,13 @@ class PrintWebViewHelper
// Given the |device| and |canvas| to draw on, prints the appropriate headers // Given the |device| and |canvas| to draw on, prints the appropriate headers
// and footers using strings from |header_footer_info| on to the canvas. // and footers using strings from |header_footer_info| on to the canvas.
static void PrintHeaderAndFooter( static void PrintHeaderAndFooter(blink::WebCanvas* canvas,
blink::WebCanvas* canvas, int page_number,
int page_number, int total_pages,
int total_pages, const blink::WebFrame& source_frame,
float webkit_scale_factor, float webkit_scale_factor,
const PageSizeMargins& page_layout_in_points, const PageSizeMargins& page_layout_in_points,
const base::DictionaryValue& header_footer_info, const PrintMsg_Print_Params& params);
const PrintMsg_Print_Params& params);
bool GetPrintFrame(blink::WebLocalFrame** frame); bool GetPrintFrame(blink::WebLocalFrame** frame);
...@@ -327,10 +326,6 @@ class PrintWebViewHelper ...@@ -327,10 +326,6 @@ class PrintWebViewHelper
// True, when printing from print preview. // True, when printing from print preview.
bool print_for_preview_; bool print_for_preview_;
// Strings generated by the browser process to be printed as headers and
// footers if requested by the user.
scoped_ptr<base::DictionaryValue> header_footer_info_;
// Keeps track of the state of print preview between messages. // Keeps track of the state of print preview between messages.
// TODO(vitalybuka): Create PrintPreviewContext when needed and delete after // TODO(vitalybuka): Create PrintPreviewContext when needed and delete after
// use. Now it's interaction with various messages is confusing. // use. Now it's interaction with various messages is confusing.
......
...@@ -181,10 +181,12 @@ void PrintWebViewHelper::PrintPageInternal( ...@@ -181,10 +181,12 @@ void PrintWebViewHelper::PrintPageInternal(
if (params.params.display_header_footer) { if (params.params.display_header_footer) {
// |page_number| is 0-based, so 1 is added. // |page_number| is 0-based, so 1 is added.
// TODO(vitalybuka) : why does it work only with 1.25? // TODO(vitalybuka) : why does it work only with 1.25?
PrintHeaderAndFooter(canvas.get(), params.page_number + 1, PrintHeaderAndFooter(canvas.get(),
params.page_number + 1,
print_preview_context_.total_page_count(), print_preview_context_.total_page_count(),
*frame,
scale_factor / 1.25, scale_factor / 1.25,
page_layout_in_points, *header_footer_info_, page_layout_in_points,
params.params); params.params);
} }
RenderPageContent(frame, params.page_number, canvas_area, content_area, RenderPageContent(frame, params.page_number, canvas_area, content_area,
......
...@@ -130,11 +130,14 @@ void PrintWebViewHelper::RenderPage( ...@@ -130,11 +130,14 @@ void PrintWebViewHelper::RenderPage(
skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_);
skia::SetIsPreviewMetafile(*canvas, is_preview); skia::SetIsPreviewMetafile(*canvas, is_preview);
if (print_pages_params_->params.display_header_footer) { if (params.display_header_footer) {
PrintHeaderAndFooter(canvas_ptr, page_number + 1, PrintHeaderAndFooter(canvas_ptr,
page_number + 1,
print_preview_context_.total_page_count(), print_preview_context_.total_page_count(),
scale_factor, page_layout_in_points, *frame,
*header_footer_info_, params); scale_factor,
page_layout_in_points,
params);
} }
RenderPageContent(frame, page_number, canvas_area, content_area, RenderPageContent(frame, page_number, canvas_area, content_area,
scale_factor, canvas_ptr); scale_factor, canvas_ptr);
......
...@@ -202,9 +202,9 @@ void PrintWebViewHelper::PrintPageInternal( ...@@ -202,9 +202,9 @@ void PrintWebViewHelper::PrintPageInternal(
PrintHeaderAndFooter(canvas.get(), PrintHeaderAndFooter(canvas.get(),
params.page_number + 1, params.page_number + 1,
print_preview_context_.total_page_count(), print_preview_context_.total_page_count(),
*frame,
scale_factor, scale_factor,
page_layout_in_points, page_layout_in_points,
*header_footer_info_,
params.params); params.params);
} }
......
...@@ -187,9 +187,13 @@ void PrintWebViewHelper::RenderPage( ...@@ -187,9 +187,13 @@ void PrintWebViewHelper::RenderPage(
if (params.display_header_footer) { if (params.display_header_footer) {
// |page_number| is 0-based, so 1 is added. // |page_number| is 0-based, so 1 is added.
PrintHeaderAndFooter(canvas.get(), page_number + 1, PrintHeaderAndFooter(canvas.get(),
print_preview_context_.total_page_count(), scale_factor, page_number + 1,
page_layout_in_points, *header_footer_info_, params); print_preview_context_.total_page_count(),
*frame,
scale_factor,
page_layout_in_points,
params);
} }
float webkit_scale_factor = RenderPageContent(frame, page_number, canvas_area, float webkit_scale_factor = RenderPageContent(frame, page_number, canvas_area,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment