Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: chrome/renderer/print_web_view_helper.cc

Issue 7740005: Print preview not showing if default print is invalid. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Update per code review Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/print_web_view_helper.h" 5 #include "chrome/renderer/print_web_view_helper.h"
6 6
7 #if defined(OS_MACOSX) && !defined(USE_SKIA) 7 #if defined(OS_MACOSX) && !defined(USE_SKIA)
8 #include <CoreGraphics/CGContext.h> 8 #include <CoreGraphics/CGContext.h>
9 #endif 9 #endif
10 10
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 // chrome/browser/resources/print_preview/print_preview.js 565 // chrome/browser/resources/print_preview/print_preview.js
566 WebElement pdf_element = document.getElementById("pdf-viewer"); 566 WebElement pdf_element = document.getElementById("pdf-viewer");
567 if (pdf_element.isNull()) { 567 if (pdf_element.isNull()) {
568 NOTREACHED(); 568 NOTREACHED();
569 return; 569 return;
570 } 570 }
571 571
572 WebFrame* pdf_frame = pdf_element.document().frame(); 572 WebFrame* pdf_frame = pdf_element.document().frame();
573 scoped_ptr<PrepareFrameAndViewForPrint> prepare; 573 scoped_ptr<PrepareFrameAndViewForPrint> prepare;
574 if (!InitPrintSettingsAndPrepareFrame(pdf_frame, &pdf_element, &prepare)) { 574 if (!InitPrintSettingsAndPrepareFrame(pdf_frame, &pdf_element, &prepare)) {
575 NOTREACHED() << "Failed to initialize print page settings"; 575 LOG(ERROR) << "Failed to initialize print page settings";
576 return; 576 return;
577 } 577 }
578 578
579 if (!UpdatePrintSettings(job_settings, false)) { 579 if (!UpdatePrintSettings(job_settings, false)) {
580 LOG(ERROR) << "UpdatePrintSettings failed"; 580 LOG(ERROR) << "UpdatePrintSettings failed";
581 DidFinishPrinting(FAIL_PRINT); 581 DidFinishPrinting(FAIL_PRINT);
582 return; 582 return;
583 } 583 }
584 584
585 // Render Pages for printing. 585 // Render Pages for printing.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 WebNode duplicate_node(*node); 625 WebNode duplicate_node(*node);
626 Print(frame, &duplicate_node); 626 Print(frame, &duplicate_node);
627 } 627 }
628 } 628 }
629 629
630 void PrintWebViewHelper::OnPrintPreview(const DictionaryValue& settings) { 630 void PrintWebViewHelper::OnPrintPreview(const DictionaryValue& settings) {
631 DCHECK(is_preview_); 631 DCHECK(is_preview_);
632 print_preview_context_.OnPrintPreview(); 632 print_preview_context_.OnPrintPreview();
633 633
634 if (!InitPrintSettings(print_preview_context_.frame(), 634 if (!InitPrintSettings(print_preview_context_.frame(),
635 print_preview_context_.node())) { 635 print_preview_context_.node(),
636 NOTREACHED(); 636 true)) {
637 Send(new PrintHostMsg_PrintPreviewInvalidPrinterSettings(
638 routing_id(),
639 print_pages_params_->params.document_cookie));
637 return; 640 return;
638 } 641 }
639 642
640 if (!UpdatePrintSettings(settings, true)) { 643 if (!UpdatePrintSettings(settings, true)) {
641 LOG(ERROR) << "UpdatePrintSettings failed"; 644 LOG(ERROR) << "UpdatePrintSettings failed";
642 DidFinishPrinting(FAIL_PREVIEW); 645 DidFinishPrinting(FAIL_PREVIEW);
643 return; 646 return;
644 } 647 }
645 648
646 if (!print_pages_params_->params.is_first_request && 649 if (!print_pages_params_->params.is_first_request &&
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 static_cast<int>(ConvertUnitDouble( 1017 static_cast<int>(ConvertUnitDouble(
1015 page_height_in_points, printing::kPointsPerInch, dpi))); 1018 page_height_in_points, printing::kPointsPerInch, dpi)));
1016 1019
1017 params->margin_top = static_cast<int>(ConvertUnitDouble( 1020 params->margin_top = static_cast<int>(ConvertUnitDouble(
1018 page_layout_in_points.margin_top, printing::kPointsPerInch, dpi)); 1021 page_layout_in_points.margin_top, printing::kPointsPerInch, dpi));
1019 params->margin_left = static_cast<int>(ConvertUnitDouble( 1022 params->margin_left = static_cast<int>(ConvertUnitDouble(
1020 page_layout_in_points.margin_left, printing::kPointsPerInch, dpi)); 1023 page_layout_in_points.margin_left, printing::kPointsPerInch, dpi));
1021 } 1024 }
1022 1025
1023 bool PrintWebViewHelper::InitPrintSettings(WebKit::WebFrame* frame, 1026 bool PrintWebViewHelper::InitPrintSettings(WebKit::WebFrame* frame,
1024 WebKit::WebNode* node) { 1027 WebKit::WebNode* node,
1028 bool is_preview) {
1025 DCHECK(frame); 1029 DCHECK(frame);
1026 PrintMsg_PrintPages_Params settings; 1030 PrintMsg_PrintPages_Params settings;
1027 1031
1028 Send(new PrintHostMsg_GetDefaultPrintSettings(routing_id(), 1032 Send(new PrintHostMsg_GetDefaultPrintSettings(routing_id(),
1029 &settings.params)); 1033 &settings.params));
1030 // Check if the printer returned any settings, if the settings is empty, we 1034 // Check if the printer returned any settings, if the settings is empty, we
1031 // can safely assume there are no printer drivers configured. So we safely 1035 // can safely assume there are no printer drivers configured. So we safely
1032 // terminate. 1036 // terminate.
1037 bool result = true;
1033 if (PrintMsg_Print_Params_IsEmpty(settings.params)) { 1038 if (PrintMsg_Print_Params_IsEmpty(settings.params)) {
1034 render_view()->runModalAlertDialog( 1039 if (!is_preview) {
1035 frame, 1040 render_view()->runModalAlertDialog(
1036 l10n_util::GetStringUTF16(IDS_DEFAULT_PRINTER_NOT_FOUND_WARNING)); 1041 frame,
1037 return false; 1042 l10n_util::GetStringUTF16(
1043 IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS));
1044 }
1045 result = false;
1038 } 1046 }
1039 if (settings.params.dpi < kMinDpi || settings.params.document_cookie == 0) { 1047
1048 if (result &&
1049 (settings.params.dpi < kMinDpi || settings.params.document_cookie == 0)) {
1040 // Invalid print page settings. 1050 // Invalid print page settings.
1041 NOTREACHED(); 1051 NOTREACHED();
1042 return false; 1052 result = false;
1043 } 1053 }
1044 1054
1045 settings.pages.clear(); 1055 settings.pages.clear();
1046 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); 1056 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings));
1047 return true; 1057 return result;
1048 } 1058 }
1049 1059
1050 bool PrintWebViewHelper::InitPrintSettingsAndPrepareFrame( 1060 bool PrintWebViewHelper::InitPrintSettingsAndPrepareFrame(
1051 WebKit::WebFrame* frame, WebKit::WebNode* node, 1061 WebKit::WebFrame* frame, WebKit::WebNode* node,
1052 scoped_ptr<PrepareFrameAndViewForPrint>* prepare) { 1062 scoped_ptr<PrepareFrameAndViewForPrint>* prepare) {
1053 if (!InitPrintSettings(frame, node)) 1063 if (!InitPrintSettings(frame, node, false))
1054 return false; 1064 return false;
1055 1065
1056 DCHECK(!prepare->get()); 1066 DCHECK(!prepare->get());
1057 prepare->reset(new PrepareFrameAndViewForPrint(print_pages_params_->params, 1067 prepare->reset(new PrepareFrameAndViewForPrint(print_pages_params_->params,
1058 frame, node)); 1068 frame, node));
1059 UpdatePrintableSizeInPrintParameters(frame, node, prepare->get(), 1069 UpdatePrintableSizeInPrintParameters(frame, node, prepare->get(),
1060 &print_pages_params_->params); 1070 &print_pages_params_->params);
1061 Send(new PrintHostMsg_DidGetDocumentCookie( 1071 Send(new PrintHostMsg_DidGetDocumentCookie(
1062 routing_id(), print_pages_params_->params.document_cookie)); 1072 routing_id(), print_pages_params_->params.document_cookie));
1063 return true; 1073 return true;
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 const gfx::Size& 1466 const gfx::Size&
1457 PrintWebViewHelper::PrintPreviewContext::GetPrintCanvasSize() const { 1467 PrintWebViewHelper::PrintPreviewContext::GetPrintCanvasSize() const {
1458 return prep_frame_view_->GetPrintCanvasSize(); 1468 return prep_frame_view_->GetPrintCanvasSize();
1459 } 1469 }
1460 1470
1461 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { 1471 void PrintWebViewHelper::PrintPreviewContext::ClearContext() {
1462 prep_frame_view_.reset(); 1472 prep_frame_view_.reset();
1463 metafile_.reset(); 1473 metafile_.reset();
1464 pages_to_render_.clear(); 1474 pages_to_render_.clear();
1465 } 1475 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698