OLD | NEW |
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" |
11 #include "base/process_util.h" | 11 #include "base/process_util.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
14 #include "chrome/common/print_messages.h" | 14 #include "chrome/common/print_messages.h" |
15 #include "chrome/common/render_messages.h" | 15 #include "chrome/common/render_messages.h" |
16 #include "chrome/renderer/prerender/prerender_helper.h" | 16 #include "chrome/renderer/prerender/prerender_helper.h" |
17 #include "content/renderer/render_view.h" | 17 #include "content/renderer/render_view.h" |
18 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
19 #include "printing/metafile.h" | 19 #include "printing/metafile.h" |
| 20 #include "printing/print_job_constants.h" |
20 #include "printing/units.h" | 21 #include "printing/units.h" |
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h" |
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" |
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" |
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" |
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" |
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" |
(...skipping 13 matching lines...) Expand all Loading... |
43 using WebKit::WebElement; | 44 using WebKit::WebElement; |
44 using WebKit::WebFrame; | 45 using WebKit::WebFrame; |
45 using WebKit::WebNode; | 46 using WebKit::WebNode; |
46 using WebKit::WebSize; | 47 using WebKit::WebSize; |
47 using WebKit::WebString; | 48 using WebKit::WebString; |
48 using WebKit::WebURLRequest; | 49 using WebKit::WebURLRequest; |
49 using WebKit::WebView; | 50 using WebKit::WebView; |
50 | 51 |
51 namespace { | 52 namespace { |
52 | 53 |
| 54 const double kMinDpi = 1.0; |
| 55 |
53 int GetDPI(const PrintMsg_Print_Params* print_params) { | 56 int GetDPI(const PrintMsg_Print_Params* print_params) { |
54 #if defined(OS_MACOSX) | 57 #if defined(OS_MACOSX) |
55 // On the Mac, the printable area is in points, don't do any scaling based | 58 // On the Mac, the printable area is in points, don't do any scaling based |
56 // on dpi. | 59 // on dpi. |
57 return printing::kPointsPerInch; | 60 return printing::kPointsPerInch; |
58 #else | 61 #else |
59 return static_cast<int>(print_params->dpi); | 62 return static_cast<int>(print_params->dpi); |
60 #endif // defined(OS_MACOSX) | 63 #endif // defined(OS_MACOSX) |
61 } | 64 } |
62 | 65 |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 &settings.params)); | 576 &settings.params)); |
574 // Check if the printer returned any settings, if the settings is empty, we | 577 // Check if the printer returned any settings, if the settings is empty, we |
575 // can safely assume there are no printer drivers configured. So we safely | 578 // can safely assume there are no printer drivers configured. So we safely |
576 // terminate. | 579 // terminate. |
577 if (PrintMsg_Print_Params_IsEmpty(settings.params)) { | 580 if (PrintMsg_Print_Params_IsEmpty(settings.params)) { |
578 render_view()->runModalAlertDialog( | 581 render_view()->runModalAlertDialog( |
579 frame, | 582 frame, |
580 l10n_util::GetStringUTF16(IDS_DEFAULT_PRINTER_NOT_FOUND_WARNING)); | 583 l10n_util::GetStringUTF16(IDS_DEFAULT_PRINTER_NOT_FOUND_WARNING)); |
581 return false; | 584 return false; |
582 } | 585 } |
583 if (!settings.params.dpi || !settings.params.document_cookie) { | 586 if (settings.params.dpi < kMinDpi || settings.params.document_cookie == 0) { |
584 // Invalid print page settings. | 587 // Invalid print page settings. |
585 NOTREACHED(); | 588 NOTREACHED(); |
586 return false; | 589 return false; |
587 } | 590 } |
588 UpdatePrintableSizeInPrintParameters(frame, node, &settings.params); | 591 UpdatePrintableSizeInPrintParameters(frame, node, &settings.params); |
589 settings.pages.clear(); | 592 settings.pages.clear(); |
590 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); | 593 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); |
591 return true; | 594 return true; |
592 } | 595 } |
593 | 596 |
594 bool PrintWebViewHelper::UpdatePrintSettings( | 597 bool PrintWebViewHelper::UpdatePrintSettings( |
595 const DictionaryValue& job_settings) { | 598 const DictionaryValue& job_settings) { |
596 PrintMsg_PrintPages_Params settings; | 599 bool print_to_cloud = job_settings.HasKey(printing::kSettingCloudPrintId); |
597 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), | 600 if (print_to_cloud) { |
598 print_pages_params_->params.document_cookie, job_settings, &settings)); | 601 // TODO(abodenha@chromium.org) Really update the settings for a cloud |
| 602 // printer. |
| 603 return true; |
| 604 } else { |
| 605 PrintMsg_PrintPages_Params settings; |
| 606 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), |
| 607 print_pages_params_->params.document_cookie, job_settings, &settings)); |
599 | 608 |
600 if (!settings.params.dpi) | 609 if (settings.params.dpi < kMinDpi) |
601 return false; | 610 return false; |
602 | 611 |
603 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); | 612 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); |
604 return true; | 613 return true; |
| 614 } |
605 } | 615 } |
606 | 616 |
607 bool PrintWebViewHelper::GetPrintSettingsFromUser(WebKit::WebFrame* frame, | 617 bool PrintWebViewHelper::GetPrintSettingsFromUser(WebKit::WebFrame* frame, |
608 int expected_pages_count, | 618 int expected_pages_count, |
609 bool use_browser_overlays) { | 619 bool use_browser_overlays) { |
610 PrintHostMsg_ScriptedPrint_Params params; | 620 PrintHostMsg_ScriptedPrint_Params params; |
611 PrintMsg_PrintPages_Params print_settings; | 621 PrintMsg_PrintPages_Params print_settings; |
612 | 622 |
613 // The routing id is sent across as it is needed to look up the | 623 // The routing id is sent across as it is needed to look up the |
614 // corresponding RenderViewHost instance to signal and reset the | 624 // corresponding RenderViewHost instance to signal and reset the |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 | 717 |
708 void PrintWebViewHelper::ResetScriptedPrintCount() { | 718 void PrintWebViewHelper::ResetScriptedPrintCount() { |
709 // Reset cancel counter on successful print. | 719 // Reset cancel counter on successful print. |
710 user_cancelled_scripted_print_count_ = 0; | 720 user_cancelled_scripted_print_count_ = 0; |
711 } | 721 } |
712 | 722 |
713 void PrintWebViewHelper::IncrementScriptedPrintCount() { | 723 void PrintWebViewHelper::IncrementScriptedPrintCount() { |
714 ++user_cancelled_scripted_print_count_; | 724 ++user_cancelled_scripted_print_count_; |
715 last_cancelled_script_print_ = base::Time::Now(); | 725 last_cancelled_script_print_ = base::Time::Now(); |
716 } | 726 } |
OLD | NEW |