| 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 1088 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1099 } | 1099 } |
| 1100 | 1100 |
| 1101 void PrintWebViewHelper::SetScriptedPrintBlocked(bool blocked) { | 1101 void PrintWebViewHelper::SetScriptedPrintBlocked(bool blocked) { |
| 1102 is_scripted_printing_blocked_ = blocked; | 1102 is_scripted_printing_blocked_ = blocked; |
| 1103 } | 1103 } |
| 1104 | 1104 |
| 1105 void PrintWebViewHelper::OnPrintNodeUnderContextMenu() { | 1105 void PrintWebViewHelper::OnPrintNodeUnderContextMenu() { |
| 1106 PrintNode(render_view()->GetContextMenuNode()); | 1106 PrintNode(render_view()->GetContextMenuNode()); |
| 1107 } | 1107 } |
| 1108 | 1108 |
| 1109 void PrintWebViewHelper::OnInitiatePrintPreview() { | 1109 void PrintWebViewHelper::OnInitiatePrintPreview(bool selection_only) { |
| 1110 DCHECK(is_preview_enabled_); | 1110 DCHECK(is_preview_enabled_); |
| 1111 WebKit::WebFrame* frame; | 1111 WebKit::WebFrame* frame; |
| 1112 if (GetPrintFrame(&frame)) { | 1112 if (GetPrintFrame(&frame)) { |
| 1113 print_preview_context_.InitWithFrame(frame); | 1113 print_preview_context_.InitWithFrame(frame); |
| 1114 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME); | 1114 RequestPrintPreview(selection_only ? |
| 1115 PRINT_PREVIEW_USER_INITIATED_SELECTION : |
| 1116 PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME); |
| 1115 } else { | 1117 } else { |
| 1116 // This should not happen. Let's add a CHECK here to see how often this | 1118 // This should not happen. Let's add a CHECK here to see how often this |
| 1117 // gets hit. | 1119 // gets hit. |
| 1118 // TODO(thestig) Remove this later when we have sufficient usage of this | 1120 // TODO(thestig) Remove this later when we have sufficient usage of this |
| 1119 // code on the M19 stable channel. | 1121 // code on the M19 stable channel. |
| 1120 CHECK(false); | 1122 CHECK(false); |
| 1121 } | 1123 } |
| 1122 } | 1124 } |
| 1123 | 1125 |
| 1124 void PrintWebViewHelper::PrintNode(const WebKit::WebNode& node) { | 1126 void PrintWebViewHelper::PrintNode(const WebKit::WebNode& node) { |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1570 | 1572 |
| 1571 void PrintWebViewHelper::IncrementScriptedPrintCount() { | 1573 void PrintWebViewHelper::IncrementScriptedPrintCount() { |
| 1572 ++user_cancelled_scripted_print_count_; | 1574 ++user_cancelled_scripted_print_count_; |
| 1573 last_cancelled_script_print_ = base::Time::Now(); | 1575 last_cancelled_script_print_ = base::Time::Now(); |
| 1574 } | 1576 } |
| 1575 | 1577 |
| 1576 void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) { | 1578 void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) { |
| 1577 const bool is_modifiable = print_preview_context_.IsModifiable(); | 1579 const bool is_modifiable = print_preview_context_.IsModifiable(); |
| 1578 const bool has_selection = print_preview_context_.HasSelection(); | 1580 const bool has_selection = print_preview_context_.HasSelection(); |
| 1579 old_print_pages_params_.reset(); | 1581 old_print_pages_params_.reset(); |
| 1582 PrintHostMsg_RequestPrintPreview_Params params = {0}; |
| 1583 params.is_modifiable = is_modifiable; |
| 1584 params.has_selection = has_selection; |
| 1580 switch (type) { | 1585 switch (type) { |
| 1581 case PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME: { | 1586 case PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME: { |
| 1582 Send(new PrintHostMsg_RequestPrintPreview(routing_id(), is_modifiable, | 1587 Send(new PrintHostMsg_RequestPrintPreview(routing_id(), params)); |
| 1583 false, has_selection)); | |
| 1584 break; | 1588 break; |
| 1585 } | 1589 } |
| 1586 case PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE: { | 1590 case PRINT_PREVIEW_USER_INITIATED_SELECTION: { |
| 1587 Send(new PrintHostMsg_RequestPrintPreview(routing_id(), is_modifiable, | 1591 DCHECK(has_selection); |
| 1588 true, has_selection)); | 1592 params.selection_only = has_selection; |
| 1593 Send(new PrintHostMsg_RequestPrintPreview(routing_id(), params)); |
| 1589 break; | 1594 break; |
| 1590 } | 1595 } |
| 1591 case PRINT_PREVIEW_SCRIPTED: { | 1596 case PRINT_PREVIEW_SCRIPTED: { |
| 1592 IPC::SyncMessage* msg = | 1597 IPC::SyncMessage* msg = |
| 1593 new PrintHostMsg_ScriptedPrintPreview(routing_id(), is_modifiable); | 1598 new PrintHostMsg_ScriptedPrintPreview(routing_id(), is_modifiable); |
| 1594 msg->EnableMessagePumping(); | 1599 msg->EnableMessagePumping(); |
| 1595 Send(msg); | 1600 Send(msg); |
| 1596 break; | 1601 break; |
| 1597 } | 1602 } |
| 1598 default: { | 1603 default: { |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1884 } | 1889 } |
| 1885 | 1890 |
| 1886 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { | 1891 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { |
| 1887 prep_frame_view_.reset(); | 1892 prep_frame_view_.reset(); |
| 1888 metafile_.reset(); | 1893 metafile_.reset(); |
| 1889 pages_to_render_.clear(); | 1894 pages_to_render_.clear(); |
| 1890 error_ = PREVIEW_ERROR_NONE; | 1895 error_ = PREVIEW_ERROR_NONE; |
| 1891 } | 1896 } |
| 1892 | 1897 |
| 1893 } // namespace printing | 1898 } // namespace printing |
| OLD | NEW |