| 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" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 // On the Mac, the printable area is in points, don't do any scaling based | 52 // On the Mac, the printable area is in points, don't do any scaling based |
| 53 // on dpi. | 53 // on dpi. |
| 54 return printing::kPointsPerInch; | 54 return printing::kPointsPerInch; |
| 55 #else | 55 #else |
| 56 return static_cast<int>(print_params->dpi); | 56 return static_cast<int>(print_params->dpi); |
| 57 #endif // defined(OS_MACOSX) | 57 #endif // defined(OS_MACOSX) |
| 58 } | 58 } |
| 59 | 59 |
| 60 bool PrintMsg_Print_Params_IsEmpty(const PrintMsg_Print_Params& params) { | 60 bool PrintMsg_Print_Params_IsEmpty(const PrintMsg_Print_Params& params) { |
| 61 return !params.document_cookie && !params.desired_dpi && !params.max_shrink && | 61 return !params.document_cookie && !params.desired_dpi && !params.max_shrink && |
| 62 !params.min_shrink && !params.dpi && params.printable_size.IsEmpty() &&
| 62 !params.min_shrink && !params.dpi && params.printable_size.IsEmpty() && |
| 63 !params.selection_only && params.page_size.IsEmpty() && | 63 !params.selection_only && params.page_size.IsEmpty() && |
| 64 !params.margin_top && !params.margin_left && | 64 !params.margin_top && !params.margin_left && |
| 65 !params.supports_alpha_blend; | 65 !params.supports_alpha_blend; |
| 66 } | 66 } |
| 67 | 67 |
| 68 } // namespace | 68 } // namespace |
| 69 | 69 |
| 70 PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint( | 70 PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint( |
| 71 const PrintMsg_Print_Params& print_params, | 71 const PrintMsg_Print_Params& print_params, |
| 72 WebFrame* frame, | 72 WebFrame* frame, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 print_web_view_(NULL), | 119 print_web_view_(NULL), |
| 120 script_initiated_preview_frame_(NULL), | 120 script_initiated_preview_frame_(NULL), |
| 121 context_menu_preview_node_(NULL), | 121 context_menu_preview_node_(NULL), |
| 122 user_cancelled_scripted_print_count_(0) { | 122 user_cancelled_scripted_print_count_(0) { |
| 123 is_preview_ = CommandLine::ForCurrentProcess()->HasSwitch( | 123 is_preview_ = CommandLine::ForCurrentProcess()->HasSwitch( |
| 124 switches::kEnablePrintPreview); | 124 switches::kEnablePrintPreview); |
| 125 } | 125 } |
| 126 | 126 |
| 127 PrintWebViewHelper::~PrintWebViewHelper() {} | 127 PrintWebViewHelper::~PrintWebViewHelper() {} |
| 128 | 128 |
| 129 void PrintWebViewHelper::ScriptInitiatedPrint(WebKit::WebFrame* frame) { | 129 void PrintWebViewHelper::printPage(WebKit::WebFrame* frame) { |
| 130 // Prints |frame| which called window.print(). |
| 130 DCHECK(frame); | 131 DCHECK(frame); |
| 131 | 132 |
| 132 if (IsScriptInitiatedPrintTooFrequent(frame)) | 133 if (IsScriptInitiatedPrintTooFrequent(frame)) |
| 133 return; | 134 return; |
| 134 IncrementScriptedPrintCount(); | 135 IncrementScriptedPrintCount(); |
| 135 | 136 |
| 136 if (is_preview_) { | 137 if (is_preview_) { |
| 137 script_initiated_preview_frame_ = frame; | 138 script_initiated_preview_frame_ = frame; |
| 138 if (!render_view()->Send(new PrintHostMsg_ScriptInitiatedPrintPreview( | 139 if (!render_view()->Send(new PrintHostMsg_ScriptInitiatedPrintPreview( |
| 139 render_view()->routing_id()))) { | 140 render_view()->routing_id()))) { |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 | 684 |
| 684 void PrintWebViewHelper::ResetScriptedPrintCount() { | 685 void PrintWebViewHelper::ResetScriptedPrintCount() { |
| 685 // Reset cancel counter on successful print. | 686 // Reset cancel counter on successful print. |
| 686 user_cancelled_scripted_print_count_ = 0; | 687 user_cancelled_scripted_print_count_ = 0; |
| 687 } | 688 } |
| 688 | 689 |
| 689 void PrintWebViewHelper::IncrementScriptedPrintCount() { | 690 void PrintWebViewHelper::IncrementScriptedPrintCount() { |
| 690 ++user_cancelled_scripted_print_count_; | 691 ++user_cancelled_scripted_print_count_; |
| 691 last_cancelled_script_print_ = base::Time::Now(); | 692 last_cancelled_script_print_ = base::Time::Now(); |
| 692 } | 693 } |
| OLD | NEW |