| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/printing/renderer/print_web_view_helper.h" | 5 #include "components/printing/renderer/print_web_view_helper.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 "document.open(); document.write(%s); document.close();"; | 94 "document.open(); document.write(%s); document.close();"; |
| 95 | 95 |
| 96 const char kPageSetupScriptFormat[] = "setup(%s);"; | 96 const char kPageSetupScriptFormat[] = "setup(%s);"; |
| 97 | 97 |
| 98 void ExecuteScript(blink::WebFrame* frame, | 98 void ExecuteScript(blink::WebFrame* frame, |
| 99 const char* script_format, | 99 const char* script_format, |
| 100 const base::Value& parameters) { | 100 const base::Value& parameters) { |
| 101 std::string json; | 101 std::string json; |
| 102 base::JSONWriter::Write(parameters, &json); | 102 base::JSONWriter::Write(parameters, &json); |
| 103 std::string script = base::StringPrintf(script_format, json.c_str()); | 103 std::string script = base::StringPrintf(script_format, json.c_str()); |
| 104 frame->executeScript(blink::WebString(base::UTF8ToUTF16(script))); | 104 frame->executeScript(blink::WebString::fromUTF8(script)); |
| 105 } | 105 } |
| 106 #else | 106 #else |
| 107 bool g_is_preview_enabled = false; | 107 bool g_is_preview_enabled = false; |
| 108 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) | 108 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 109 | 109 |
| 110 int GetDPI(const PrintMsg_Print_Params* print_params) { | 110 int GetDPI(const PrintMsg_Print_Params* print_params) { |
| 111 #if defined(OS_MACOSX) | 111 #if defined(OS_MACOSX) |
| 112 // On the Mac, the printable area is in points, don't do any scaling based | 112 // On the Mac, the printable area is in points, don't do any scaling based |
| 113 // on dpi. | 113 // on dpi. |
| 114 return kPointsPerInch; | 114 return kPointsPerInch; |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 options.reset(new base::DictionaryValue()); | 600 options.reset(new base::DictionaryValue()); |
| 601 options->SetDouble(kSettingHeaderFooterDate, base::Time::Now().ToJsTime()); | 601 options->SetDouble(kSettingHeaderFooterDate, base::Time::Now().ToJsTime()); |
| 602 options->SetDouble("width", page_size.width); | 602 options->SetDouble("width", page_size.width); |
| 603 options->SetDouble("height", page_size.height); | 603 options->SetDouble("height", page_size.height); |
| 604 options->SetDouble("topMargin", page_layout.margin_top); | 604 options->SetDouble("topMargin", page_layout.margin_top); |
| 605 options->SetDouble("bottomMargin", page_layout.margin_bottom); | 605 options->SetDouble("bottomMargin", page_layout.margin_bottom); |
| 606 options->SetString("pageNumber", | 606 options->SetString("pageNumber", |
| 607 base::StringPrintf("%d/%d", page_number, total_pages)); | 607 base::StringPrintf("%d/%d", page_number, total_pages)); |
| 608 | 608 |
| 609 options->SetString("url", params.url); | 609 options->SetString("url", params.url); |
| 610 base::string16 title = source_frame.document().title(); | 610 base::string16 title = source_frame.document().title().utf16(); |
| 611 options->SetString("title", title.empty() ? params.title : title); | 611 options->SetString("title", title.empty() ? params.title : title); |
| 612 | 612 |
| 613 ExecuteScript(frame, kPageSetupScriptFormat, *options); | 613 ExecuteScript(frame, kPageSetupScriptFormat, *options); |
| 614 | 614 |
| 615 blink::WebPrintParams webkit_params(page_size); | 615 blink::WebPrintParams webkit_params(page_size); |
| 616 webkit_params.printerDPI = GetDPI(¶ms); | 616 webkit_params.printerDPI = GetDPI(¶ms); |
| 617 | 617 |
| 618 frame->printBegin(webkit_params); | 618 frame->printBegin(webkit_params); |
| 619 frame->printPage(0, canvas); | 619 frame->printPage(0, canvas); |
| 620 frame->printEnd(); | 620 frame->printEnd(); |
| (...skipping 1728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2349 blink::WebConsoleMessage::LevelWarning, message)); | 2349 blink::WebConsoleMessage::LevelWarning, message)); |
| 2350 return false; | 2350 return false; |
| 2351 } | 2351 } |
| 2352 | 2352 |
| 2353 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2353 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
| 2354 // Reset counter on successful print. | 2354 // Reset counter on successful print. |
| 2355 count_ = 0; | 2355 count_ = 0; |
| 2356 } | 2356 } |
| 2357 | 2357 |
| 2358 } // namespace printing | 2358 } // namespace printing |
| OLD | NEW |