| 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 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 | 827 |
| 828 if (!IsScriptInitiatedPrintAllowed(frame, user_initiated)) | 828 if (!IsScriptInitiatedPrintAllowed(frame, user_initiated)) |
| 829 return; | 829 return; |
| 830 print_preview_context_.InitWithFrame(frame); | 830 print_preview_context_.InitWithFrame(frame); |
| 831 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); | 831 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); |
| 832 } | 832 } |
| 833 | 833 |
| 834 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { | 834 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { |
| 835 bool handled = true; | 835 bool handled = true; |
| 836 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) | 836 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) |
| 837 #if !defined(DISABLE_BASIC_PRINTING) |
| 837 IPC_MESSAGE_HANDLER(PrintMsg_PrintPages, OnPrintPages) | 838 IPC_MESSAGE_HANDLER(PrintMsg_PrintPages, OnPrintPages) |
| 838 IPC_MESSAGE_HANDLER(PrintMsg_PrintForSystemDialog, OnPrintForSystemDialog) | 839 IPC_MESSAGE_HANDLER(PrintMsg_PrintForSystemDialog, OnPrintForSystemDialog) |
| 840 #endif // !DISABLE_BASIC_PRINTING |
| 839 IPC_MESSAGE_HANDLER(PrintMsg_InitiatePrintPreview, OnInitiatePrintPreview) | 841 IPC_MESSAGE_HANDLER(PrintMsg_InitiatePrintPreview, OnInitiatePrintPreview) |
| 840 IPC_MESSAGE_HANDLER(PrintMsg_PrintPreview, OnPrintPreview) | 842 IPC_MESSAGE_HANDLER(PrintMsg_PrintPreview, OnPrintPreview) |
| 841 IPC_MESSAGE_HANDLER(PrintMsg_PrintForPrintPreview, OnPrintForPrintPreview) | 843 IPC_MESSAGE_HANDLER(PrintMsg_PrintForPrintPreview, OnPrintForPrintPreview) |
| 842 IPC_MESSAGE_HANDLER(PrintMsg_PrintingDone, OnPrintingDone) | 844 IPC_MESSAGE_HANDLER(PrintMsg_PrintingDone, OnPrintingDone) |
| 843 IPC_MESSAGE_HANDLER(PrintMsg_SetScriptedPrintingBlocked, | 845 IPC_MESSAGE_HANDLER(PrintMsg_SetScriptedPrintingBlocked, |
| 844 SetScriptedPrintBlocked) | 846 SetScriptedPrintBlocked) |
| 845 IPC_MESSAGE_UNHANDLED(handled = false) | 847 IPC_MESSAGE_UNHANDLED(handled = false) |
| 846 IPC_END_MESSAGE_MAP() | 848 IPC_END_MESSAGE_MAP() |
| 847 return handled; | 849 return handled; |
| 848 } | 850 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 925 // If the user has selected text in the currently focused frame we print | 927 // If the user has selected text in the currently focused frame we print |
| 926 // only that frame (this makes print selection work for multiple frames). | 928 // only that frame (this makes print selection work for multiple frames). |
| 927 blink::WebLocalFrame* focusedFrame = | 929 blink::WebLocalFrame* focusedFrame = |
| 928 webView->focusedFrame()->toWebLocalFrame(); | 930 webView->focusedFrame()->toWebLocalFrame(); |
| 929 *frame = focusedFrame->hasSelection() | 931 *frame = focusedFrame->hasSelection() |
| 930 ? focusedFrame | 932 ? focusedFrame |
| 931 : webView->mainFrame()->toWebLocalFrame(); | 933 : webView->mainFrame()->toWebLocalFrame(); |
| 932 return true; | 934 return true; |
| 933 } | 935 } |
| 934 | 936 |
| 937 #if !defined(DISABLE_BASIC_PRINTING) |
| 935 void PrintWebViewHelper::OnPrintPages() { | 938 void PrintWebViewHelper::OnPrintPages() { |
| 936 blink::WebLocalFrame* frame; | 939 blink::WebLocalFrame* frame; |
| 937 if (GetPrintFrame(&frame)) | 940 if (GetPrintFrame(&frame)) |
| 938 Print(frame, blink::WebNode()); | 941 Print(frame, blink::WebNode()); |
| 939 } | 942 } |
| 940 | 943 |
| 941 void PrintWebViewHelper::OnPrintForSystemDialog() { | 944 void PrintWebViewHelper::OnPrintForSystemDialog() { |
| 942 blink::WebLocalFrame* frame = print_preview_context_.source_frame(); | 945 blink::WebLocalFrame* frame = print_preview_context_.source_frame(); |
| 943 if (!frame) { | 946 if (!frame) { |
| 944 NOTREACHED(); | 947 NOTREACHED(); |
| 945 return; | 948 return; |
| 946 } | 949 } |
| 947 | |
| 948 Print(frame, print_preview_context_.source_node()); | 950 Print(frame, print_preview_context_.source_node()); |
| 949 } | 951 } |
| 952 #endif // !DISABLE_BASIC_PRINTING |
| 950 | 953 |
| 951 void PrintWebViewHelper::GetPageSizeAndContentAreaFromPageLayout( | 954 void PrintWebViewHelper::GetPageSizeAndContentAreaFromPageLayout( |
| 952 const PageSizeMargins& page_layout_in_points, | 955 const PageSizeMargins& page_layout_in_points, |
| 953 gfx::Size* page_size, | 956 gfx::Size* page_size, |
| 954 gfx::Rect* content_area) { | 957 gfx::Rect* content_area) { |
| 955 *page_size = gfx::Size( | 958 *page_size = gfx::Size( |
| 956 page_layout_in_points.content_width + | 959 page_layout_in_points.content_width + |
| 957 page_layout_in_points.margin_right + | 960 page_layout_in_points.margin_right + |
| 958 page_layout_in_points.margin_left, | 961 page_layout_in_points.margin_left, |
| 959 page_layout_in_points.content_height + | 962 page_layout_in_points.content_height + |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1216 print_node_in_progress_ = true; | 1219 print_node_in_progress_ = true; |
| 1217 | 1220 |
| 1218 // Make a copy of the node, in case RenderView::OnContextMenuClosed resets | 1221 // Make a copy of the node, in case RenderView::OnContextMenuClosed resets |
| 1219 // its |context_menu_node_|. | 1222 // its |context_menu_node_|. |
| 1220 print_preview_context_.InitWithNode(node); | 1223 print_preview_context_.InitWithNode(node); |
| 1221 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE); | 1224 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE); |
| 1222 | 1225 |
| 1223 print_node_in_progress_ = false; | 1226 print_node_in_progress_ = false; |
| 1224 } | 1227 } |
| 1225 | 1228 |
| 1229 #if !defined(DISABLE_BASIC_PRINTING) |
| 1226 void PrintWebViewHelper::Print(blink::WebLocalFrame* frame, | 1230 void PrintWebViewHelper::Print(blink::WebLocalFrame* frame, |
| 1227 const blink::WebNode& node) { | 1231 const blink::WebNode& node) { |
| 1228 // If still not finished with earlier print request simply ignore. | 1232 // If still not finished with earlier print request simply ignore. |
| 1229 if (prep_frame_view_) | 1233 if (prep_frame_view_) |
| 1230 return; | 1234 return; |
| 1231 | 1235 |
| 1232 FrameReference frame_ref(frame); | 1236 FrameReference frame_ref(frame); |
| 1233 | 1237 |
| 1234 int expected_page_count = 0; | 1238 int expected_page_count = 0; |
| 1235 if (!CalculateNumberOfPages(frame, node, &expected_page_count)) { | 1239 if (!CalculateNumberOfPages(frame, node, &expected_page_count)) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1249 DidFinishPrinting(OK); // Release resources and fail silently. | 1253 DidFinishPrinting(OK); // Release resources and fail silently. |
| 1250 return; | 1254 return; |
| 1251 } | 1255 } |
| 1252 | 1256 |
| 1253 // Render Pages for printing. | 1257 // Render Pages for printing. |
| 1254 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { | 1258 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { |
| 1255 LOG(ERROR) << "RenderPagesForPrint failed"; | 1259 LOG(ERROR) << "RenderPagesForPrint failed"; |
| 1256 DidFinishPrinting(FAIL_PRINT); | 1260 DidFinishPrinting(FAIL_PRINT); |
| 1257 } | 1261 } |
| 1258 } | 1262 } |
| 1263 #endif // !DISABLE_BASIC_PRINTING |
| 1259 | 1264 |
| 1260 void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) { | 1265 void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) { |
| 1261 switch (result) { | 1266 switch (result) { |
| 1262 case OK: | 1267 case OK: |
| 1263 break; | 1268 break; |
| 1264 | 1269 |
| 1265 case FAIL_PRINT_INIT: | 1270 case FAIL_PRINT_INIT: |
| 1266 DCHECK(!notify_browser_of_print_failure_); | 1271 DCHECK(!notify_browser_of_print_failure_); |
| 1267 break; | 1272 break; |
| 1268 | 1273 |
| (...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1959 } | 1964 } |
| 1960 | 1965 |
| 1961 void PrintWebViewHelper::SetPrintPagesParams( | 1966 void PrintWebViewHelper::SetPrintPagesParams( |
| 1962 const PrintMsg_PrintPages_Params& settings) { | 1967 const PrintMsg_PrintPages_Params& settings) { |
| 1963 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); | 1968 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); |
| 1964 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), | 1969 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), |
| 1965 settings.params.document_cookie)); | 1970 settings.params.document_cookie)); |
| 1966 } | 1971 } |
| 1967 | 1972 |
| 1968 } // namespace printing | 1973 } // namespace printing |
| OLD | NEW |