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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #include "third_party/WebKit/public/web/WebView.h" | 42 #include "third_party/WebKit/public/web/WebView.h" |
43 #include "third_party/WebKit/public/web/WebViewClient.h" | 43 #include "third_party/WebKit/public/web/WebViewClient.h" |
44 #include "ui/base/resource/resource_bundle.h" | 44 #include "ui/base/resource/resource_bundle.h" |
45 | 45 |
46 using content::WebPreferences; | 46 using content::WebPreferences; |
47 | 47 |
48 namespace printing { | 48 namespace printing { |
49 | 49 |
50 namespace { | 50 namespace { |
51 | 51 |
| 52 #define STATIC_ASSERT_PP_MATCHING_ENUM(a, b) \ |
| 53 static_assert(static_cast<int>(a) == static_cast<int>(b), \ |
| 54 "mismatching enums: " #a) |
| 55 |
| 56 // Check blink::WebDuplexMode and printing::DuplexMode are kept in sync. |
| 57 STATIC_ASSERT_PP_MATCHING_ENUM(blink::WebUnknownDuplexMode, |
| 58 UNKNOWN_DUPLEX_MODE); |
| 59 STATIC_ASSERT_PP_MATCHING_ENUM(blink::WebSimplex, SIMPLEX); |
| 60 STATIC_ASSERT_PP_MATCHING_ENUM(blink::WebLongEdge, LONG_EDGE); |
| 61 STATIC_ASSERT_PP_MATCHING_ENUM(blink::WebShortEdge, SHORT_EDGE); |
| 62 |
52 enum PrintPreviewHelperEvents { | 63 enum PrintPreviewHelperEvents { |
53 PREVIEW_EVENT_REQUESTED, | 64 PREVIEW_EVENT_REQUESTED, |
54 PREVIEW_EVENT_CACHE_HIT, // Unused | 65 PREVIEW_EVENT_CACHE_HIT, // Unused |
55 PREVIEW_EVENT_CREATE_DOCUMENT, | 66 PREVIEW_EVENT_CREATE_DOCUMENT, |
56 PREVIEW_EVENT_NEW_SETTINGS, // Unused | 67 PREVIEW_EVENT_NEW_SETTINGS, // Unused |
57 PREVIEW_EVENT_MAX, | 68 PREVIEW_EVENT_MAX, |
58 }; | 69 }; |
59 | 70 |
60 const double kMinDpi = 1.0; | 71 const double kMinDpi = 1.0; |
61 | 72 |
(...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
998 notify_browser_of_print_failure_ = false; // Already sent. | 1009 notify_browser_of_print_failure_ = false; // Already sent. |
999 } | 1010 } |
1000 DidFinishPrinting(FAIL_PREVIEW); | 1011 DidFinishPrinting(FAIL_PREVIEW); |
1001 return; | 1012 return; |
1002 } | 1013 } |
1003 | 1014 |
1004 // Set the options from document if we are previewing a pdf and send a | 1015 // Set the options from document if we are previewing a pdf and send a |
1005 // message to browser. | 1016 // message to browser. |
1006 if (print_pages_params_->params.is_first_request && | 1017 if (print_pages_params_->params.is_first_request && |
1007 !print_preview_context_.IsModifiable()) { | 1018 !print_preview_context_.IsModifiable()) { |
1008 PrintHostMsg_SetOptionsFromDocument_Params params; | 1019 PrintHostMsg_SetOptionsFromDocument_Params options; |
1009 SetOptionsFromDocument(params); | 1020 SetOptionsFromPdfDocument(&options); |
1010 Send(new PrintHostMsg_SetOptionsFromDocument(routing_id(), params)); | 1021 Send(new PrintHostMsg_SetOptionsFromDocument(routing_id(), options)); |
1011 } | 1022 } |
1012 | 1023 |
1013 is_print_ready_metafile_sent_ = false; | 1024 is_print_ready_metafile_sent_ = false; |
1014 | 1025 |
1015 // PDF printer device supports alpha blending. | 1026 // PDF printer device supports alpha blending. |
1016 print_pages_params_->params.supports_alpha_blend = true; | 1027 print_pages_params_->params.supports_alpha_blend = true; |
1017 | 1028 |
1018 bool generate_draft_pages = false; | 1029 bool generate_draft_pages = false; |
1019 if (!settings.GetBoolean(kSettingGenerateDraftData, &generate_draft_pages)) { | 1030 if (!settings.GetBoolean(kSettingGenerateDraftData, &generate_draft_pages)) { |
1020 NOTREACHED(); | 1031 NOTREACHED(); |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1425 } | 1436 } |
1426 | 1437 |
1427 const PrintMsg_Print_Params& params = print_pages_params_->params; | 1438 const PrintMsg_Print_Params& params = print_pages_params_->params; |
1428 PrepareFrameAndViewForPrint prepare(params, frame, node, ignore_css_margins_); | 1439 PrepareFrameAndViewForPrint prepare(params, frame, node, ignore_css_margins_); |
1429 prepare.StartPrinting(); | 1440 prepare.StartPrinting(); |
1430 | 1441 |
1431 *number_of_pages = prepare.GetExpectedPageCount(); | 1442 *number_of_pages = prepare.GetExpectedPageCount(); |
1432 return true; | 1443 return true; |
1433 } | 1444 } |
1434 | 1445 |
1435 void PrintWebViewHelper::SetOptionsFromDocument( | 1446 void PrintWebViewHelper::SetOptionsFromPdfDocument( |
1436 PrintHostMsg_SetOptionsFromDocument_Params& params) { | 1447 PrintHostMsg_SetOptionsFromDocument_Params* options) { |
1437 blink::WebLocalFrame* source_frame = print_preview_context_.source_frame(); | 1448 blink::WebLocalFrame* source_frame = print_preview_context_.source_frame(); |
1438 const blink::WebNode& source_node = print_preview_context_.source_node(); | 1449 const blink::WebNode& source_node = print_preview_context_.source_node(); |
1439 | 1450 |
1440 blink::WebPrintPresetOptions preset_options; | 1451 blink::WebPrintPresetOptions preset_options; |
1441 if (!source_frame->getPrintPresetOptionsForPlugin(source_node, | 1452 if (!source_frame->getPrintPresetOptionsForPlugin(source_node, |
1442 &preset_options)) { | 1453 &preset_options)) { |
1443 return; | 1454 return; |
1444 } | 1455 } |
1445 | 1456 |
1446 params.is_scaling_disabled = preset_options.isScalingDisabled; | 1457 options->is_scaling_disabled = preset_options.isScalingDisabled; |
1447 params.copies = preset_options.copies; | 1458 options->copies = preset_options.copies; |
| 1459 |
| 1460 // TODO(thestig) This should be a straight pass-through, but print preview |
| 1461 // does not currently support short-edge printing. |
| 1462 switch (preset_options.duplexMode) { |
| 1463 case blink::WebSimplex: |
| 1464 options->duplex = SIMPLEX; |
| 1465 break; |
| 1466 case blink::WebLongEdge: |
| 1467 options->duplex = LONG_EDGE; |
| 1468 break; |
| 1469 default: |
| 1470 options->duplex = UNKNOWN_DUPLEX_MODE; |
| 1471 break; |
| 1472 } |
1448 } | 1473 } |
1449 | 1474 |
1450 bool PrintWebViewHelper::UpdatePrintSettings( | 1475 bool PrintWebViewHelper::UpdatePrintSettings( |
1451 blink::WebLocalFrame* frame, | 1476 blink::WebLocalFrame* frame, |
1452 const blink::WebNode& node, | 1477 const blink::WebNode& node, |
1453 const base::DictionaryValue& passed_job_settings) { | 1478 const base::DictionaryValue& passed_job_settings) { |
1454 const base::DictionaryValue* job_settings = &passed_job_settings; | 1479 const base::DictionaryValue* job_settings = &passed_job_settings; |
1455 base::DictionaryValue modified_job_settings; | 1480 base::DictionaryValue modified_job_settings; |
1456 if (job_settings->empty()) { | 1481 if (job_settings->empty()) { |
1457 if (!print_for_preview_) | 1482 if (!print_for_preview_) |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2009 blink::WebConsoleMessage::LevelWarning, message)); | 2034 blink::WebConsoleMessage::LevelWarning, message)); |
2010 return false; | 2035 return false; |
2011 } | 2036 } |
2012 | 2037 |
2013 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2038 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
2014 // Reset counter on successful print. | 2039 // Reset counter on successful print. |
2015 count_ = 0; | 2040 count_ = 0; |
2016 } | 2041 } |
2017 | 2042 |
2018 } // namespace printing | 2043 } // namespace printing |
OLD | NEW |