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 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
811 | 811 |
812 PrintWebViewHelper::~PrintWebViewHelper() {} | 812 PrintWebViewHelper::~PrintWebViewHelper() {} |
813 | 813 |
814 // static | 814 // static |
815 void PrintWebViewHelper::DisablePreview() { | 815 void PrintWebViewHelper::DisablePreview() { |
816 g_is_preview_enabled_ = false; | 816 g_is_preview_enabled_ = false; |
817 } | 817 } |
818 | 818 |
819 bool PrintWebViewHelper::IsScriptInitiatedPrintAllowed( | 819 bool PrintWebViewHelper::IsScriptInitiatedPrintAllowed( |
820 blink::WebFrame* frame, bool user_initiated) { | 820 blink::WebFrame* frame, bool user_initiated) { |
821 #if defined(OS_ANDROID) | |
822 return false; | |
823 #endif // defined(OS_ANDROID) | |
824 // If preview is enabled, then the print dialog is tab modal, and the user | 821 // If preview is enabled, then the print dialog is tab modal, and the user |
825 // can always close the tab on a mis-behaving page (the system print dialog | 822 // can always close the tab on a mis-behaving page (the system print dialog |
826 // is app modal). If the print was initiated through user action, don't | 823 // is app modal). If the print was initiated through user action, don't |
827 // throttle. Or, if the command line flag to skip throttling has been set. | 824 // throttle. Or, if the command line flag to skip throttling has been set. |
828 return !is_scripted_printing_blocked_ && | 825 return !is_scripted_printing_blocked_ && |
829 (user_initiated || g_is_preview_enabled_ || | 826 (user_initiated || g_is_preview_enabled_ || |
830 scripting_throttler_.IsAllowed(frame)); | 827 scripting_throttler_.IsAllowed(frame)); |
831 } | 828 } |
832 | 829 |
833 void PrintWebViewHelper::DidStartLoading() { | 830 void PrintWebViewHelper::DidStartLoading() { |
(...skipping 17 matching lines...) Expand all Loading... | |
851 if (prerender::PrerenderHelper::IsPrerendering( | 848 if (prerender::PrerenderHelper::IsPrerendering( |
852 render_view()->GetMainRenderFrame())) { | 849 render_view()->GetMainRenderFrame())) { |
853 Send(new ChromeViewHostMsg_CancelPrerenderForPrinting(routing_id())); | 850 Send(new ChromeViewHostMsg_CancelPrerenderForPrinting(routing_id())); |
854 return; | 851 return; |
855 } | 852 } |
856 | 853 |
857 if (!IsScriptInitiatedPrintAllowed(frame, user_initiated)) | 854 if (!IsScriptInitiatedPrintAllowed(frame, user_initiated)) |
858 return; | 855 return; |
859 | 856 |
860 if (!g_is_preview_enabled_) { | 857 if (!g_is_preview_enabled_) { |
861 Print(frame, blink::WebNode()); | 858 Print(frame, blink::WebNode(), true); |
862 } else { | 859 } else { |
863 print_preview_context_.InitWithFrame(frame); | 860 print_preview_context_.InitWithFrame(frame); |
864 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); | 861 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); |
865 } | 862 } |
866 } | 863 } |
867 | 864 |
868 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { | 865 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { |
869 bool handled = true; | 866 bool handled = true; |
870 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) | 867 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) |
871 #if defined(ENABLE_BASIC_PRINTING) | 868 #if defined(ENABLE_BASIC_PRINTING) |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
967 } | 964 } |
968 | 965 |
969 #if defined(ENABLE_BASIC_PRINTING) | 966 #if defined(ENABLE_BASIC_PRINTING) |
970 void PrintWebViewHelper::OnPrintPages() { | 967 void PrintWebViewHelper::OnPrintPages() { |
971 blink::WebLocalFrame* frame; | 968 blink::WebLocalFrame* frame; |
972 if (!GetPrintFrame(&frame)) | 969 if (!GetPrintFrame(&frame)) |
973 return; | 970 return; |
974 // If we are printing a PDF extension frame, find the plugin node and print | 971 // If we are printing a PDF extension frame, find the plugin node and print |
975 // that instead. | 972 // that instead. |
976 auto plugin = GetPdfElement(frame); | 973 auto plugin = GetPdfElement(frame); |
977 Print(frame, plugin); | 974 |
975 Print(frame, plugin, false); | |
978 } | 976 } |
979 | 977 |
980 void PrintWebViewHelper::OnPrintForSystemDialog() { | 978 void PrintWebViewHelper::OnPrintForSystemDialog() { |
dgn
2014/12/12 18:42:49
This is called from the print preview, which may o
Vitaly Buka (NO REVIEWS)
2014/12/12 18:52:09
should be false
we care about direct call from win
| |
981 blink::WebLocalFrame* frame = print_preview_context_.source_frame(); | 979 blink::WebLocalFrame* frame = print_preview_context_.source_frame(); |
982 if (!frame) { | 980 if (!frame) { |
983 NOTREACHED(); | 981 NOTREACHED(); |
984 return; | 982 return; |
985 } | 983 } |
986 Print(frame, print_preview_context_.source_node()); | 984 Print(frame, print_preview_context_.source_node(), true); |
987 } | 985 } |
988 #endif // ENABLE_BASIC_PRINTING | 986 #endif // ENABLE_BASIC_PRINTING |
989 | 987 |
990 void PrintWebViewHelper::GetPageSizeAndContentAreaFromPageLayout( | 988 void PrintWebViewHelper::GetPageSizeAndContentAreaFromPageLayout( |
991 const PageSizeMargins& page_layout_in_points, | 989 const PageSizeMargins& page_layout_in_points, |
992 gfx::Size* page_size, | 990 gfx::Size* page_size, |
993 gfx::Rect* content_area) { | 991 gfx::Rect* content_area) { |
994 *page_size = gfx::Size( | 992 *page_size = gfx::Size( |
995 page_layout_in_points.content_width + | 993 page_layout_in_points.content_width + |
996 page_layout_in_points.margin_right + | 994 page_layout_in_points.margin_right + |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1258 // See http://crbug.com/159165. | 1256 // See http://crbug.com/159165. |
1259 return; | 1257 return; |
1260 } | 1258 } |
1261 | 1259 |
1262 print_node_in_progress_ = true; | 1260 print_node_in_progress_ = true; |
1263 | 1261 |
1264 // Make a copy of the node, in case RenderView::OnContextMenuClosed resets | 1262 // Make a copy of the node, in case RenderView::OnContextMenuClosed resets |
1265 // its |context_menu_node_|. | 1263 // its |context_menu_node_|. |
1266 if (!g_is_preview_enabled_) { | 1264 if (!g_is_preview_enabled_) { |
1267 blink::WebNode duplicate_node(node); | 1265 blink::WebNode duplicate_node(node); |
1268 Print(duplicate_node.document().frame(), duplicate_node); | 1266 Print(duplicate_node.document().frame(), duplicate_node, true); |
dgn
2014/12/12 18:42:48
Can definitely come from the UI here, but I'm not
| |
1269 } else { | 1267 } else { |
1270 print_preview_context_.InitWithNode(node); | 1268 print_preview_context_.InitWithNode(node); |
1271 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE); | 1269 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE); |
1272 } | 1270 } |
1273 | 1271 |
1274 print_node_in_progress_ = false; | 1272 print_node_in_progress_ = false; |
1275 } | 1273 } |
1276 | 1274 |
1277 void PrintWebViewHelper::Print(blink::WebLocalFrame* frame, | 1275 void PrintWebViewHelper::Print(blink::WebLocalFrame* frame, |
1278 const blink::WebNode& node) { | 1276 const blink::WebNode& node, |
1277 bool is_scripted) { | |
1279 // If still not finished with earlier print request simply ignore. | 1278 // If still not finished with earlier print request simply ignore. |
1280 if (prep_frame_view_) | 1279 if (prep_frame_view_) |
1281 return; | 1280 return; |
1282 | 1281 |
1283 FrameReference frame_ref(frame); | 1282 FrameReference frame_ref(frame); |
1284 | 1283 |
1285 int expected_page_count = 0; | 1284 int expected_page_count = 0; |
1286 if (!CalculateNumberOfPages(frame, node, &expected_page_count)) { | 1285 if (!CalculateNumberOfPages(frame, node, &expected_page_count)) { |
1287 DidFinishPrinting(FAIL_PRINT_INIT); | 1286 DidFinishPrinting(FAIL_PRINT_INIT); |
1288 return; // Failed to init print page settings. | 1287 return; // Failed to init print page settings. |
1289 } | 1288 } |
1290 | 1289 |
1291 // Some full screen plugins can say they don't want to print. | 1290 // Some full screen plugins can say they don't want to print. |
1292 if (!expected_page_count) { | 1291 if (!expected_page_count) { |
1293 DidFinishPrinting(FAIL_PRINT); | 1292 DidFinishPrinting(FAIL_PRINT); |
1294 return; | 1293 return; |
1295 } | 1294 } |
1296 | 1295 |
1297 // Ask the browser to show UI to retrieve the final print settings. | 1296 // Ask the browser to show UI to retrieve the final print settings. |
1298 if (!GetPrintSettingsFromUser(frame_ref.GetFrame(), node, | 1297 if (!GetPrintSettingsFromUser(frame_ref.GetFrame(), node, |
1299 expected_page_count)) { | 1298 expected_page_count, |
1299 is_scripted)) { | |
1300 DidFinishPrinting(OK); // Release resources and fail silently. | 1300 DidFinishPrinting(OK); // Release resources and fail silently. |
1301 return; | 1301 return; |
1302 } | 1302 } |
1303 | 1303 |
1304 // Render Pages for printing. | 1304 // Render Pages for printing. |
1305 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { | 1305 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { |
1306 LOG(ERROR) << "RenderPagesForPrint failed"; | 1306 LOG(ERROR) << "RenderPagesForPrint failed"; |
1307 DidFinishPrinting(FAIL_PRINT); | 1307 DidFinishPrinting(FAIL_PRINT); |
1308 } | 1308 } |
1309 scripting_throttler_.Reset(); | 1309 scripting_throttler_.Reset(); |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1566 Send(new PrintHostMsg_ShowInvalidPrinterSettingsError(routing_id())); | 1566 Send(new PrintHostMsg_ShowInvalidPrinterSettingsError(routing_id())); |
1567 | 1567 |
1568 return false; | 1568 return false; |
1569 } | 1569 } |
1570 | 1570 |
1571 return true; | 1571 return true; |
1572 } | 1572 } |
1573 | 1573 |
1574 bool PrintWebViewHelper::GetPrintSettingsFromUser(blink::WebFrame* frame, | 1574 bool PrintWebViewHelper::GetPrintSettingsFromUser(blink::WebFrame* frame, |
1575 const blink::WebNode& node, | 1575 const blink::WebNode& node, |
1576 int expected_pages_count) { | 1576 int expected_pages_count, |
1577 bool is_scripted) { | |
1577 PrintHostMsg_ScriptedPrint_Params params; | 1578 PrintHostMsg_ScriptedPrint_Params params; |
1578 PrintMsg_PrintPages_Params print_settings; | 1579 PrintMsg_PrintPages_Params print_settings; |
1579 | 1580 |
1580 params.cookie = print_pages_params_->params.document_cookie; | 1581 params.cookie = print_pages_params_->params.document_cookie; |
1581 params.has_selection = frame->hasSelection(); | 1582 params.has_selection = frame->hasSelection(); |
1582 params.expected_pages_count = expected_pages_count; | 1583 params.expected_pages_count = expected_pages_count; |
1583 MarginType margin_type = DEFAULT_MARGINS; | 1584 MarginType margin_type = DEFAULT_MARGINS; |
1584 if (PrintingNodeOrPdfFrame(frame, node)) | 1585 if (PrintingNodeOrPdfFrame(frame, node)) |
1585 margin_type = GetMarginsForPdf(frame, node); | 1586 margin_type = GetMarginsForPdf(frame, node); |
1586 params.margin_type = margin_type; | 1587 params.margin_type = margin_type; |
1588 params.is_scripted = is_scripted; | |
1587 | 1589 |
1588 Send(new PrintHostMsg_DidShowPrintDialog(routing_id())); | 1590 Send(new PrintHostMsg_DidShowPrintDialog(routing_id())); |
1589 | 1591 |
1590 // PrintHostMsg_ScriptedPrint will reset print_scaling_option, so we save the | 1592 // PrintHostMsg_ScriptedPrint will reset print_scaling_option, so we save the |
1591 // value before and restore it afterwards. | 1593 // value before and restore it afterwards. |
1592 blink::WebPrintScalingOption scaling_option = | 1594 blink::WebPrintScalingOption scaling_option = |
1593 print_pages_params_->params.print_scaling_option; | 1595 print_pages_params_->params.print_scaling_option; |
1594 | 1596 |
1595 print_pages_params_.reset(); | 1597 print_pages_params_.reset(); |
1596 IPC::SyncMessage* msg = | 1598 IPC::SyncMessage* msg = |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2055 blink::WebConsoleMessage::LevelWarning, message)); | 2057 blink::WebConsoleMessage::LevelWarning, message)); |
2056 return false; | 2058 return false; |
2057 } | 2059 } |
2058 | 2060 |
2059 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2061 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
2060 // Reset counter on successful print. | 2062 // Reset counter on successful print. |
2061 count_ = 0; | 2063 count_ = 0; |
2062 } | 2064 } |
2063 | 2065 |
2064 } // namespace printing | 2066 } // namespace printing |
OLD | NEW |