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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 enum PrintPreviewHelperEvents { | 60 enum PrintPreviewHelperEvents { |
61 PREVIEW_EVENT_REQUESTED, | 61 PREVIEW_EVENT_REQUESTED, |
62 PREVIEW_EVENT_CACHE_HIT, // Unused | 62 PREVIEW_EVENT_CACHE_HIT, // Unused |
63 PREVIEW_EVENT_CREATE_DOCUMENT, | 63 PREVIEW_EVENT_CREATE_DOCUMENT, |
64 PREVIEW_EVENT_NEW_SETTINGS, // Unused | 64 PREVIEW_EVENT_NEW_SETTINGS, // Unused |
65 PREVIEW_EVENT_MAX, | 65 PREVIEW_EVENT_MAX, |
66 }; | 66 }; |
67 | 67 |
68 const double kMinDpi = 1.0; | 68 const double kMinDpi = 1.0; |
69 | 69 |
70 #if defined(OS_ANDROID) | |
71 // Used to trigger the android system dialog from window.print() | |
72 const bool g_is_system_specific_flow_enabled = true; | |
Vitaly Buka (NO REVIEWS)
2014/12/09 23:46:48
If I read the code correctly you just send value o
dgn
2014/12/10 18:12:52
The parameter I added to the |Print()| function ha
| |
73 #else | |
74 const bool g_is_system_specific_flow_enabled = false; | |
75 #endif | |
76 | |
70 #if !defined(ENABLE_PRINT_PREVIEW) | 77 #if !defined(ENABLE_PRINT_PREVIEW) |
71 bool g_is_preview_enabled_ = false; | 78 bool g_is_preview_enabled_ = false; |
72 #else | 79 #else |
73 bool g_is_preview_enabled_ = true; | 80 bool g_is_preview_enabled_ = true; |
74 | 81 |
75 const char kPageLoadScriptFormat[] = | 82 const char kPageLoadScriptFormat[] = |
76 "document.open(); document.write(%s); document.close();"; | 83 "document.open(); document.write(%s); document.close();"; |
77 | 84 |
78 const char kPageSetupScriptFormat[] = "setup(%s);"; | 85 const char kPageSetupScriptFormat[] = "setup(%s);"; |
79 | 86 |
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
811 | 818 |
812 PrintWebViewHelper::~PrintWebViewHelper() {} | 819 PrintWebViewHelper::~PrintWebViewHelper() {} |
813 | 820 |
814 // static | 821 // static |
815 void PrintWebViewHelper::DisablePreview() { | 822 void PrintWebViewHelper::DisablePreview() { |
816 g_is_preview_enabled_ = false; | 823 g_is_preview_enabled_ = false; |
817 } | 824 } |
818 | 825 |
819 bool PrintWebViewHelper::IsScriptInitiatedPrintAllowed( | 826 bool PrintWebViewHelper::IsScriptInitiatedPrintAllowed( |
820 blink::WebFrame* frame, bool user_initiated) { | 827 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 | 828 // 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 | 829 // 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 | 830 // 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. | 831 // throttle. Or, if the command line flag to skip throttling has been set. |
828 return !is_scripted_printing_blocked_ && | 832 return !is_scripted_printing_blocked_ && |
829 (user_initiated || g_is_preview_enabled_ || | 833 (user_initiated || g_is_preview_enabled_ || |
830 scripting_throttler_.IsAllowed(frame)); | 834 scripting_throttler_.IsAllowed(frame)); |
831 } | 835 } |
832 | 836 |
833 void PrintWebViewHelper::DidStartLoading() { | 837 void PrintWebViewHelper::DidStartLoading() { |
(...skipping 17 matching lines...) Expand all Loading... | |
851 if (prerender::PrerenderHelper::IsPrerendering( | 855 if (prerender::PrerenderHelper::IsPrerendering( |
852 render_view()->GetMainRenderFrame())) { | 856 render_view()->GetMainRenderFrame())) { |
853 Send(new ChromeViewHostMsg_CancelPrerenderForPrinting(routing_id())); | 857 Send(new ChromeViewHostMsg_CancelPrerenderForPrinting(routing_id())); |
854 return; | 858 return; |
855 } | 859 } |
856 | 860 |
857 if (!IsScriptInitiatedPrintAllowed(frame, user_initiated)) | 861 if (!IsScriptInitiatedPrintAllowed(frame, user_initiated)) |
858 return; | 862 return; |
859 | 863 |
860 if (!g_is_preview_enabled_) { | 864 if (!g_is_preview_enabled_) { |
861 Print(frame, blink::WebNode()); | 865 Print(frame, blink::WebNode(), g_is_system_specific_flow_enabled); |
862 } else { | 866 } else { |
863 print_preview_context_.InitWithFrame(frame); | 867 print_preview_context_.InitWithFrame(frame); |
864 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); | 868 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); |
865 } | 869 } |
866 } | 870 } |
867 | 871 |
868 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { | 872 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { |
869 bool handled = true; | 873 bool handled = true; |
870 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) | 874 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) |
871 #if defined(ENABLE_BASIC_PRINTING) | 875 #if defined(ENABLE_BASIC_PRINTING) |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
961 blink::WebLocalFrame* focusedFrame = | 965 blink::WebLocalFrame* focusedFrame = |
962 webView->focusedFrame()->toWebLocalFrame(); | 966 webView->focusedFrame()->toWebLocalFrame(); |
963 *frame = focusedFrame->hasSelection() | 967 *frame = focusedFrame->hasSelection() |
964 ? focusedFrame | 968 ? focusedFrame |
965 : webView->mainFrame()->toWebLocalFrame(); | 969 : webView->mainFrame()->toWebLocalFrame(); |
966 return true; | 970 return true; |
967 } | 971 } |
968 | 972 |
969 #if defined(ENABLE_BASIC_PRINTING) | 973 #if defined(ENABLE_BASIC_PRINTING) |
970 void PrintWebViewHelper::OnPrintPages() { | 974 void PrintWebViewHelper::OnPrintPages() { |
975 DLOG(INFO) << "DGN - OnPrintPages - Call from PrintManager"; | |
971 blink::WebLocalFrame* frame; | 976 blink::WebLocalFrame* frame; |
972 if (!GetPrintFrame(&frame)) | 977 if (!GetPrintFrame(&frame)) |
973 return; | 978 return; |
974 // If we are printing a PDF extension frame, find the plugin node and print | 979 // If we are printing a PDF extension frame, find the plugin node and print |
975 // that instead. | 980 // that instead. |
976 auto plugin = GetPdfElement(frame); | 981 auto plugin = GetPdfElement(frame); |
977 Print(frame, plugin); | 982 Print(frame, plugin); |
978 } | 983 } |
979 | 984 |
980 void PrintWebViewHelper::OnPrintForSystemDialog() { | 985 void PrintWebViewHelper::OnPrintForSystemDialog() { |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1268 Print(duplicate_node.document().frame(), duplicate_node); | 1273 Print(duplicate_node.document().frame(), duplicate_node); |
1269 } else { | 1274 } else { |
1270 print_preview_context_.InitWithNode(node); | 1275 print_preview_context_.InitWithNode(node); |
1271 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE); | 1276 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE); |
1272 } | 1277 } |
1273 | 1278 |
1274 print_node_in_progress_ = false; | 1279 print_node_in_progress_ = false; |
1275 } | 1280 } |
1276 | 1281 |
1277 void PrintWebViewHelper::Print(blink::WebLocalFrame* frame, | 1282 void PrintWebViewHelper::Print(blink::WebLocalFrame* frame, |
1278 const blink::WebNode& node) { | 1283 const blink::WebNode& node, |
1284 const bool use_system_specific_flow) { | |
1279 // If still not finished with earlier print request simply ignore. | 1285 // If still not finished with earlier print request simply ignore. |
1280 if (prep_frame_view_) | 1286 DLOG(INFO) << "DGN Print"; |
1287 | |
1288 if (prep_frame_view_) { | |
1289 DLOG(INFO) << "DGN Print request ignored"; | |
1281 return; | 1290 return; |
1291 } | |
1282 | 1292 |
1283 FrameReference frame_ref(frame); | 1293 FrameReference frame_ref(frame); |
1284 | 1294 |
1285 int expected_page_count = 0; | 1295 int expected_page_count = 0; |
1286 if (!CalculateNumberOfPages(frame, node, &expected_page_count)) { | 1296 if (!CalculateNumberOfPages(frame, node, &expected_page_count)) { |
1287 DidFinishPrinting(FAIL_PRINT_INIT); | 1297 DidFinishPrinting(FAIL_PRINT_INIT); |
1288 return; // Failed to init print page settings. | 1298 return; // Failed to init print page settings. |
1289 } | 1299 } |
1290 | 1300 |
1301 DLOG(INFO) << "DGN CalculateNumberOfPages OK"; | |
1302 | |
1291 // Some full screen plugins can say they don't want to print. | 1303 // Some full screen plugins can say they don't want to print. |
1292 if (!expected_page_count) { | 1304 if (!expected_page_count) { |
1293 DidFinishPrinting(FAIL_PRINT); | 1305 DidFinishPrinting(FAIL_PRINT); |
1294 return; | 1306 return; |
1295 } | 1307 } |
1296 | 1308 |
1297 // Ask the browser to show UI to retrieve the final print settings. | 1309 // Ask the browser to show UI to retrieve the final print settings. |
1298 if (!GetPrintSettingsFromUser(frame_ref.GetFrame(), node, | 1310 if (!GetPrintSettingsFromUser(frame_ref.GetFrame(), node, |
1299 expected_page_count)) { | 1311 expected_page_count, |
1312 use_system_specific_flow)) { | |
1300 DidFinishPrinting(OK); // Release resources and fail silently. | 1313 DidFinishPrinting(OK); // Release resources and fail silently. |
1301 return; | 1314 return; |
1302 } | 1315 } |
1303 | 1316 |
1317 DLOG(INFO) << "DGN GetPrintSettingsFromUser OK"; | |
1318 | |
1304 // Render Pages for printing. | 1319 // Render Pages for printing. |
1305 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { | 1320 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { |
1306 LOG(ERROR) << "RenderPagesForPrint failed"; | 1321 LOG(ERROR) << "RenderPagesForPrint failed"; |
1307 DidFinishPrinting(FAIL_PRINT); | 1322 DidFinishPrinting(FAIL_PRINT); |
1308 } | 1323 } |
1309 scripting_throttler_.Reset(); | 1324 scripting_throttler_.Reset(); |
1310 } | 1325 } |
1311 | 1326 |
1312 void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) { | 1327 void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) { |
1313 switch (result) { | 1328 switch (result) { |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1566 Send(new PrintHostMsg_ShowInvalidPrinterSettingsError(routing_id())); | 1581 Send(new PrintHostMsg_ShowInvalidPrinterSettingsError(routing_id())); |
1567 | 1582 |
1568 return false; | 1583 return false; |
1569 } | 1584 } |
1570 | 1585 |
1571 return true; | 1586 return true; |
1572 } | 1587 } |
1573 | 1588 |
1574 bool PrintWebViewHelper::GetPrintSettingsFromUser(blink::WebFrame* frame, | 1589 bool PrintWebViewHelper::GetPrintSettingsFromUser(blink::WebFrame* frame, |
1575 const blink::WebNode& node, | 1590 const blink::WebNode& node, |
1576 int expected_pages_count) { | 1591 int expected_pages_count, |
1592 const bool system_specific) { | |
1577 PrintHostMsg_ScriptedPrint_Params params; | 1593 PrintHostMsg_ScriptedPrint_Params params; |
1578 PrintMsg_PrintPages_Params print_settings; | 1594 PrintMsg_PrintPages_Params print_settings; |
1579 | 1595 |
1580 params.cookie = print_pages_params_->params.document_cookie; | 1596 params.cookie = print_pages_params_->params.document_cookie; |
1581 params.has_selection = frame->hasSelection(); | 1597 params.has_selection = frame->hasSelection(); |
1582 params.expected_pages_count = expected_pages_count; | 1598 params.expected_pages_count = expected_pages_count; |
1583 MarginType margin_type = DEFAULT_MARGINS; | 1599 MarginType margin_type = DEFAULT_MARGINS; |
1584 if (PrintingNodeOrPdfFrame(frame, node)) | 1600 if (PrintingNodeOrPdfFrame(frame, node)) |
1585 margin_type = GetMarginsForPdf(frame, node); | 1601 margin_type = GetMarginsForPdf(frame, node); |
1586 params.margin_type = margin_type; | 1602 params.margin_type = margin_type; |
1603 params.use_system_specific_flow = system_specific; | |
1587 | 1604 |
1588 Send(new PrintHostMsg_DidShowPrintDialog(routing_id())); | 1605 Send(new PrintHostMsg_DidShowPrintDialog(routing_id())); |
1589 | 1606 |
1590 // PrintHostMsg_ScriptedPrint will reset print_scaling_option, so we save the | 1607 // PrintHostMsg_ScriptedPrint will reset print_scaling_option, so we save the |
1591 // value before and restore it afterwards. | 1608 // value before and restore it afterwards. |
1592 blink::WebPrintScalingOption scaling_option = | 1609 blink::WebPrintScalingOption scaling_option = |
1593 print_pages_params_->params.print_scaling_option; | 1610 print_pages_params_->params.print_scaling_option; |
1594 | 1611 |
1595 print_pages_params_.reset(); | 1612 print_pages_params_.reset(); |
1596 IPC::SyncMessage* msg = | 1613 IPC::SyncMessage* msg = |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2055 blink::WebConsoleMessage::LevelWarning, message)); | 2072 blink::WebConsoleMessage::LevelWarning, message)); |
2056 return false; | 2073 return false; |
2057 } | 2074 } |
2058 | 2075 |
2059 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2076 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
2060 // Reset counter on successful print. | 2077 // Reset counter on successful print. |
2061 count_ = 0; | 2078 count_ = 0; |
2062 } | 2079 } |
2063 | 2080 |
2064 } // namespace printing | 2081 } // namespace printing |
OLD | NEW |