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 "chrome/renderer/printing/print_web_view_helper.h" | 5 #include "chrome/renderer/printing/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/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1018 Send(new PrintHostMsg_PrintPreviewInvalidPrinterSettings( | 1018 Send(new PrintHostMsg_PrintPreviewInvalidPrinterSettings( |
1019 routing_id(), | 1019 routing_id(), |
1020 print_pages_params_ ? | 1020 print_pages_params_ ? |
1021 print_pages_params_->params.document_cookie : 0)); | 1021 print_pages_params_->params.document_cookie : 0)); |
1022 notify_browser_of_print_failure_ = false; // Already sent. | 1022 notify_browser_of_print_failure_ = false; // Already sent. |
1023 } | 1023 } |
1024 DidFinishPrinting(FAIL_PREVIEW); | 1024 DidFinishPrinting(FAIL_PREVIEW); |
1025 return; | 1025 return; |
1026 } | 1026 } |
1027 | 1027 |
1028 // If we are previewing a pdf and the print scaling is disabled, send a | 1028 // Set the options from document if we are previewing a pdf and send a |
1029 // message to browser. | 1029 // message to browser. |
1030 if (print_pages_params_->params.is_first_request && | 1030 if (print_pages_params_->params.is_first_request && |
1031 !print_preview_context_.IsModifiable() && | 1031 !print_preview_context_.IsModifiable()) { |
1032 print_preview_context_.source_frame()->isPrintScalingDisabledForPlugin( | 1032 PrintHostMsg_SetOptionsFromDocument_Params params; |
1033 print_preview_context_.source_node())) { | 1033 SetOptionsFromDocument(params); |
1034 Send(new PrintHostMsg_PrintPreviewScalingDisabled(routing_id())); | 1034 Send(new PrintHostMsg_SetOptionsFromDocument(routing_id(), params)); |
1035 } | 1035 } |
1036 | 1036 |
1037 is_print_ready_metafile_sent_ = false; | 1037 is_print_ready_metafile_sent_ = false; |
1038 | 1038 |
1039 // PDF printer device supports alpha blending. | 1039 // PDF printer device supports alpha blending. |
1040 print_pages_params_->params.supports_alpha_blend = true; | 1040 print_pages_params_->params.supports_alpha_blend = true; |
1041 | 1041 |
1042 bool generate_draft_pages = false; | 1042 bool generate_draft_pages = false; |
1043 if (!settings.GetBoolean(kSettingGenerateDraftData, | 1043 if (!settings.GetBoolean(kSettingGenerateDraftData, |
1044 &generate_draft_pages)) { | 1044 &generate_draft_pages)) { |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1459 const PrintMsg_Print_Params& params = print_pages_params_->params; | 1459 const PrintMsg_Print_Params& params = print_pages_params_->params; |
1460 PrepareFrameAndViewForPrint prepare(params, frame, node, ignore_css_margins_); | 1460 PrepareFrameAndViewForPrint prepare(params, frame, node, ignore_css_margins_); |
1461 prepare.StartPrinting(); | 1461 prepare.StartPrinting(); |
1462 | 1462 |
1463 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), | 1463 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), |
1464 params.document_cookie)); | 1464 params.document_cookie)); |
1465 *number_of_pages = prepare.GetExpectedPageCount(); | 1465 *number_of_pages = prepare.GetExpectedPageCount(); |
1466 return true; | 1466 return true; |
1467 } | 1467 } |
1468 | 1468 |
| 1469 void PrintWebViewHelper::SetOptionsFromDocument( |
| 1470 PrintHostMsg_SetOptionsFromDocument_Params& params) { |
| 1471 blink::WebLocalFrame* source_frame = print_preview_context_.source_frame(); |
| 1472 const blink::WebNode& source_node = print_preview_context_.source_node(); |
| 1473 |
| 1474 params.is_scaling_disabled = |
| 1475 source_frame->isPrintScalingDisabledForPlugin(source_node); |
| 1476 params.copies = source_frame->getPrintCopiesForPlugin(source_node); |
| 1477 } |
| 1478 |
1469 bool PrintWebViewHelper::UpdatePrintSettings( | 1479 bool PrintWebViewHelper::UpdatePrintSettings( |
1470 blink::WebLocalFrame* frame, | 1480 blink::WebLocalFrame* frame, |
1471 const blink::WebNode& node, | 1481 const blink::WebNode& node, |
1472 const base::DictionaryValue& passed_job_settings) { | 1482 const base::DictionaryValue& passed_job_settings) { |
1473 DCHECK(is_preview_enabled_); | 1483 DCHECK(is_preview_enabled_); |
1474 const base::DictionaryValue* job_settings = &passed_job_settings; | 1484 const base::DictionaryValue* job_settings = &passed_job_settings; |
1475 base::DictionaryValue modified_job_settings; | 1485 base::DictionaryValue modified_job_settings; |
1476 if (job_settings->empty()) { | 1486 if (job_settings->empty()) { |
1477 if (!print_for_preview_) | 1487 if (!print_for_preview_) |
1478 print_preview_context_.set_error(PREVIEW_ERROR_BAD_SETTING); | 1488 print_preview_context_.set_error(PREVIEW_ERROR_BAD_SETTING); |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2025 } | 2035 } |
2026 | 2036 |
2027 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { | 2037 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { |
2028 prep_frame_view_.reset(); | 2038 prep_frame_view_.reset(); |
2029 metafile_.reset(); | 2039 metafile_.reset(); |
2030 pages_to_render_.clear(); | 2040 pages_to_render_.clear(); |
2031 error_ = PREVIEW_ERROR_NONE; | 2041 error_ = PREVIEW_ERROR_NONE; |
2032 } | 2042 } |
2033 | 2043 |
2034 } // namespace printing | 2044 } // namespace printing |
OLD | NEW |