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; |
| 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: { | |
1582 Send(new PrintHostMsg_RequestPrintPreview(routing_id(), is_modifiable, | |
1583 false, has_selection)); | |
1584 break; | |
1585 } | |
1586 case PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE: { | |
1587 Send(new PrintHostMsg_RequestPrintPreview(routing_id(), is_modifiable, | |
1588 true, has_selection)); | |
1589 break; | |
1590 } | |
1591 case PRINT_PREVIEW_SCRIPTED: { | 1586 case PRINT_PREVIEW_SCRIPTED: { |
1592 IPC::SyncMessage* msg = | 1587 IPC::SyncMessage* msg = |
1593 new PrintHostMsg_ScriptedPrintPreview(routing_id(), is_modifiable); | 1588 new PrintHostMsg_ScriptedPrintPreview(routing_id(), is_modifiable); |
1594 msg->EnableMessagePumping(); | 1589 msg->EnableMessagePumping(); |
1595 Send(msg); | 1590 Send(msg); |
| 1591 return; |
| 1592 } |
| 1593 case PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME: { |
| 1594 break; |
| 1595 } |
| 1596 case PRINT_PREVIEW_USER_INITIATED_SELECTION: { |
| 1597 DCHECK(has_selection); |
| 1598 params.selection_only = has_selection; |
| 1599 break; |
| 1600 } |
| 1601 case PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE: { |
| 1602 params.webnode_only = true; |
1596 break; | 1603 break; |
1597 } | 1604 } |
1598 default: { | 1605 default: { |
1599 NOTREACHED(); | 1606 NOTREACHED(); |
1600 return; | 1607 return; |
1601 } | 1608 } |
1602 } | 1609 } |
| 1610 Send(new PrintHostMsg_RequestPrintPreview(routing_id(), params)); |
1603 } | 1611 } |
1604 | 1612 |
1605 bool PrintWebViewHelper::CheckForCancel() { | 1613 bool PrintWebViewHelper::CheckForCancel() { |
1606 const PrintMsg_Print_Params& print_params = print_pages_params_->params; | 1614 const PrintMsg_Print_Params& print_params = print_pages_params_->params; |
1607 bool cancel = false; | 1615 bool cancel = false; |
1608 Send(new PrintHostMsg_CheckForCancel(routing_id(), | 1616 Send(new PrintHostMsg_CheckForCancel(routing_id(), |
1609 print_params.preview_ui_id, | 1617 print_params.preview_ui_id, |
1610 print_params.preview_request_id, | 1618 print_params.preview_request_id, |
1611 &cancel)); | 1619 &cancel)); |
1612 if (cancel) | 1620 if (cancel) |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1884 } | 1892 } |
1885 | 1893 |
1886 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { | 1894 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { |
1887 prep_frame_view_.reset(); | 1895 prep_frame_view_.reset(); |
1888 metafile_.reset(); | 1896 metafile_.reset(); |
1889 pages_to_render_.clear(); | 1897 pages_to_render_.clear(); |
1890 error_ = PREVIEW_ERROR_NONE; | 1898 error_ = PREVIEW_ERROR_NONE; |
1891 } | 1899 } |
1892 | 1900 |
1893 } // namespace printing | 1901 } // namespace printing |
OLD | NEW |