Index: chrome/renderer/printing/print_web_view_helper.cc |
diff --git a/chrome/renderer/printing/print_web_view_helper.cc b/chrome/renderer/printing/print_web_view_helper.cc |
index f1d4cfd7595d45b458661ea864b79927608b1b0f..6dd507e0823c2a1c582d6bbc1aca498490bc3540 100644 |
--- a/chrome/renderer/printing/print_web_view_helper.cc |
+++ b/chrome/renderer/printing/print_web_view_helper.cc |
@@ -443,9 +443,9 @@ void PrintWebViewHelper::PrintHeaderAndFooter( |
blink::WebCanvas* canvas, |
int page_number, |
int total_pages, |
+ const blink::WebFrame& source_frame, |
float webkit_scale_factor, |
const PageSizeMargins& page_layout, |
- const base::DictionaryValue& header_footer_info, |
const PrintMsg_Print_Params& params) { |
skia::VectorPlatformDeviceSkia* device = |
static_cast<skia::VectorPlatformDeviceSkia*>(canvas->getTopDevice()); |
@@ -455,9 +455,9 @@ void PrintWebViewHelper::PrintHeaderAndFooter( |
canvas->scale(1 / webkit_scale_factor, 1 / webkit_scale_factor); |
blink::WebSize page_size(page_layout.margin_left + page_layout.margin_right + |
- page_layout.content_width, |
- page_layout.margin_top + page_layout.margin_bottom + |
- page_layout.content_height); |
+ page_layout.content_width, |
+ page_layout.margin_top + page_layout.margin_bottom + |
+ page_layout.content_height); |
blink::WebView* web_view = blink::WebView::create(NULL); |
web_view->settings()->setJavaScriptEnabled(true); |
@@ -465,13 +465,14 @@ void PrintWebViewHelper::PrintHeaderAndFooter( |
blink::WebLocalFrame* frame = blink::WebLocalFrame::create(NULL); |
web_view->setMainFrame(frame); |
- base::StringValue html( |
- ResourceBundle::GetSharedInstance().GetLocalizedString( |
- IDR_PRINT_PREVIEW_PAGE)); |
+ base::StringValue html(ResourceBundle::GetSharedInstance().GetLocalizedString( |
+ IDR_PRINT_PREVIEW_PAGE)); |
// Load page with script to avoid async operations. |
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("height", page_size.height); |
options->SetDouble("topMargin", page_layout.margin_top); |
@@ -479,6 +480,12 @@ void PrintWebViewHelper::PrintHeaderAndFooter( |
options->SetString("pageNumber", |
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); |
blink::WebPrintParams webkit_params(page_size); |
@@ -1493,17 +1500,6 @@ bool PrintWebViewHelper::UpdatePrintSettings( |
UpdateFrameMarginsCssInfo(*job_settings); |
settings.params.print_scaling_option = GetPrintScalingOption( |
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); |