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

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: Merge with latest trunk (again) 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 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 // chrome/browser/resources/print_preview/print_preview.js 564 // chrome/browser/resources/print_preview/print_preview.js
565 WebElement pdf_element = document.getElementById("pdf-viewer"); 565 WebElement pdf_element = document.getElementById("pdf-viewer");
566 if (pdf_element.isNull()) { 566 if (pdf_element.isNull()) {
567 NOTREACHED(); 567 NOTREACHED();
568 return; 568 return;
569 } 569 }
570 570
571 WebFrame* pdf_frame = pdf_element.document().frame(); 571 WebFrame* pdf_frame = pdf_element.document().frame();
572 scoped_ptr<PrepareFrameAndViewForPrint> prepare; 572 scoped_ptr<PrepareFrameAndViewForPrint> prepare;
573 if (!InitPrintSettingsAndPrepareFrame(pdf_frame, &pdf_element, &prepare)) { 573 if (!InitPrintSettingsAndPrepareFrame(pdf_frame, &pdf_element, &prepare)) {
574 NOTREACHED() << "Failed to initialize print page settings"; 574 LOG(ERROR) << "Failed to initialize print page settings";
575 return; 575 return;
576 } 576 }
577 577
578 if (!UpdatePrintSettings(job_settings, false)) { 578 if (!UpdatePrintSettings(job_settings, false)) {
579 LOG(ERROR) << "UpdatePrintSettings failed"; 579 LOG(ERROR) << "UpdatePrintSettings failed";
580 DidFinishPrinting(FAIL_PRINT); 580 DidFinishPrinting(FAIL_PRINT);
581 return; 581 return;
582 } 582 }
583 583
584 // Render Pages for printing. 584 // Render Pages for printing.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 WebNode duplicate_node(*node); 624 WebNode duplicate_node(*node);
625 Print(frame, &duplicate_node); 625 Print(frame, &duplicate_node);
626 } 626 }
627 } 627 }
628 628
629 void PrintWebViewHelper::OnPrintPreview(const DictionaryValue& settings) { 629 void PrintWebViewHelper::OnPrintPreview(const DictionaryValue& settings) {
630 DCHECK(is_preview_); 630 DCHECK(is_preview_);
631 print_preview_context_.OnPrintPreview(); 631 print_preview_context_.OnPrintPreview();
632 632
633 if (!InitPrintSettings(print_preview_context_.frame(), 633 if (!InitPrintSettings(print_preview_context_.frame(),
634 print_preview_context_.node())) { 634 print_preview_context_.node(),
635 NOTREACHED(); 635 true)) {
636 Send(new PrintHostMsg_PrintPreviewInvalidPrinterSettings(
637 routing_id(),
638 print_pages_params_->params.document_cookie));
636 return; 639 return;
637 } 640 }
638 641
639 if (!UpdatePrintSettings(settings, true)) { 642 if (!UpdatePrintSettings(settings, true)) {
640 LOG(ERROR) << "UpdatePrintSettings failed"; 643 LOG(ERROR) << "UpdatePrintSettings failed";
641 DidFinishPrinting(FAIL_PREVIEW); 644 DidFinishPrinting(FAIL_PREVIEW);
642 return; 645 return;
643 } 646 }
644 647
645 if (!print_pages_params_->params.is_first_request && 648 if (!print_pages_params_->params.is_first_request &&
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 1033
1031 params->margin_top = static_cast<int>(ConvertUnitDouble( 1034 params->margin_top = static_cast<int>(ConvertUnitDouble(
1032 page_layout_in_points.margin_top, printing::kPointsPerInch, dpi)); 1035 page_layout_in_points.margin_top, printing::kPointsPerInch, dpi));
1033 params->margin_left = static_cast<int>(ConvertUnitDouble( 1036 params->margin_left = static_cast<int>(ConvertUnitDouble(
1034 page_layout_in_points.margin_left, printing::kPointsPerInch, dpi)); 1037 page_layout_in_points.margin_left, printing::kPointsPerInch, dpi));
1035 1038
1036 prepare->UpdatePrintParams(*params); 1039 prepare->UpdatePrintParams(*params);
1037 } 1040 }
1038 1041
1039 bool PrintWebViewHelper::InitPrintSettings(WebKit::WebFrame* frame, 1042 bool PrintWebViewHelper::InitPrintSettings(WebKit::WebFrame* frame,
1040 WebKit::WebNode* node) { 1043 WebKit::WebNode* node,
1044 bool is_preview) {
1041 DCHECK(frame); 1045 DCHECK(frame);
1042 PrintMsg_PrintPages_Params settings; 1046 PrintMsg_PrintPages_Params settings;
1043 1047
1044 Send(new PrintHostMsg_GetDefaultPrintSettings(routing_id(), 1048 Send(new PrintHostMsg_GetDefaultPrintSettings(routing_id(),
1045 &settings.params)); 1049 &settings.params));
1046 // Check if the printer returned any settings, if the settings is empty, we 1050 // Check if the printer returned any settings, if the settings is empty, we
1047 // can safely assume there are no printer drivers configured. So we safely 1051 // can safely assume there are no printer drivers configured. So we safely
1048 // terminate. 1052 // terminate.
1053 bool result = true;
1049 if (PrintMsg_Print_Params_IsEmpty(settings.params)) { 1054 if (PrintMsg_Print_Params_IsEmpty(settings.params)) {
1050 render_view()->runModalAlertDialog( 1055 if (!is_preview) {
1051 frame, 1056 render_view()->runModalAlertDialog(
1052 l10n_util::GetStringUTF16(IDS_DEFAULT_PRINTER_NOT_FOUND_WARNING)); 1057 frame,
1053 return false; 1058 l10n_util::GetStringUTF16(
1059 IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS));
1060 }
1061 result = false;
1054 } 1062 }
1055 if (settings.params.dpi < kMinDpi || settings.params.document_cookie == 0) { 1063
1064 if (result &&
1065 (settings.params.dpi < kMinDpi || settings.params.document_cookie == 0)) {
1056 // Invalid print page settings. 1066 // Invalid print page settings.
1057 NOTREACHED(); 1067 NOTREACHED();
1058 return false; 1068 result = false;
1059 } 1069 }
1060 1070
1061 settings.pages.clear(); 1071 settings.pages.clear();
1062 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); 1072 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings));
1063 return true; 1073 return result;
1064 } 1074 }
1065 1075
1066 bool PrintWebViewHelper::InitPrintSettingsAndPrepareFrame( 1076 bool PrintWebViewHelper::InitPrintSettingsAndPrepareFrame(
1067 WebKit::WebFrame* frame, WebKit::WebNode* node, 1077 WebKit::WebFrame* frame, WebKit::WebNode* node,
1068 scoped_ptr<PrepareFrameAndViewForPrint>* prepare) { 1078 scoped_ptr<PrepareFrameAndViewForPrint>* prepare) {
1069 if (!InitPrintSettings(frame, node)) 1079 if (!InitPrintSettings(frame, node, false))
1070 return false; 1080 return false;
1071 1081
1072 DCHECK(!prepare->get()); 1082 DCHECK(!prepare->get());
1073 prepare->reset(new PrepareFrameAndViewForPrint(print_pages_params_->params, 1083 prepare->reset(new PrepareFrameAndViewForPrint(print_pages_params_->params,
1074 frame, node)); 1084 frame, node));
1075 UpdatePrintableSizeInPrintParameters(frame, node, prepare->get(), 1085 UpdatePrintableSizeInPrintParameters(frame, node, prepare->get(),
1076 &print_pages_params_->params); 1086 &print_pages_params_->params);
1077 Send(new PrintHostMsg_DidGetDocumentCookie( 1087 Send(new PrintHostMsg_DidGetDocumentCookie(
1078 routing_id(), print_pages_params_->params.document_cookie)); 1088 routing_id(), print_pages_params_->params.document_cookie));
1079 return true; 1089 return true;
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
1495 const gfx::Size& 1505 const gfx::Size&
1496 PrintWebViewHelper::PrintPreviewContext::GetPrintCanvasSize() const { 1506 PrintWebViewHelper::PrintPreviewContext::GetPrintCanvasSize() const {
1497 return prep_frame_view_->GetPrintCanvasSize(); 1507 return prep_frame_view_->GetPrintCanvasSize();
1498 } 1508 }
1499 1509
1500 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { 1510 void PrintWebViewHelper::PrintPreviewContext::ClearContext() {
1501 prep_frame_view_.reset(); 1511 prep_frame_view_.reset();
1502 metafile_.reset(); 1512 metafile_.reset();
1503 pages_to_render_.clear(); 1513 pages_to_render_.clear();
1504 } 1514 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698