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 bool use_system_specific_flow = false; |
| 859 |
| 860 #if defined(OS_ANDROID) |
| 861 use_system_specific_flow = true; |
| 862 #endif |
| 863 |
| 864 Print(frame, blink::WebNode(), use_system_specific_flow); |
862 } else { | 865 } else { |
863 print_preview_context_.InitWithFrame(frame); | 866 print_preview_context_.InitWithFrame(frame); |
864 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); | 867 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); |
865 } | 868 } |
866 } | 869 } |
867 | 870 |
868 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { | 871 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { |
869 bool handled = true; | 872 bool handled = true; |
870 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) | 873 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) |
871 #if defined(ENABLE_BASIC_PRINTING) | 874 #if defined(ENABLE_BASIC_PRINTING) |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 blink::WebLocalFrame* focusedFrame = | 964 blink::WebLocalFrame* focusedFrame = |
962 webView->focusedFrame()->toWebLocalFrame(); | 965 webView->focusedFrame()->toWebLocalFrame(); |
963 *frame = focusedFrame->hasSelection() | 966 *frame = focusedFrame->hasSelection() |
964 ? focusedFrame | 967 ? focusedFrame |
965 : webView->mainFrame()->toWebLocalFrame(); | 968 : webView->mainFrame()->toWebLocalFrame(); |
966 return true; | 969 return true; |
967 } | 970 } |
968 | 971 |
969 #if defined(ENABLE_BASIC_PRINTING) | 972 #if defined(ENABLE_BASIC_PRINTING) |
970 void PrintWebViewHelper::OnPrintPages() { | 973 void PrintWebViewHelper::OnPrintPages() { |
| 974 DLOG(INFO) << "DGN - OnPrintPages - Call from PrintManager"; |
971 blink::WebLocalFrame* frame; | 975 blink::WebLocalFrame* frame; |
972 if (!GetPrintFrame(&frame)) | 976 if (!GetPrintFrame(&frame)) |
973 return; | 977 return; |
974 // If we are printing a PDF extension frame, find the plugin node and print | 978 // If we are printing a PDF extension frame, find the plugin node and print |
975 // that instead. | 979 // that instead. |
976 auto plugin = GetPdfElement(frame); | 980 auto plugin = GetPdfElement(frame); |
977 Print(frame, plugin); | 981 Print(frame, plugin); |
978 } | 982 } |
979 | 983 |
980 void PrintWebViewHelper::OnPrintForSystemDialog() { | 984 void PrintWebViewHelper::OnPrintForSystemDialog() { |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1268 Print(duplicate_node.document().frame(), duplicate_node); | 1272 Print(duplicate_node.document().frame(), duplicate_node); |
1269 } else { | 1273 } else { |
1270 print_preview_context_.InitWithNode(node); | 1274 print_preview_context_.InitWithNode(node); |
1271 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE); | 1275 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE); |
1272 } | 1276 } |
1273 | 1277 |
1274 print_node_in_progress_ = false; | 1278 print_node_in_progress_ = false; |
1275 } | 1279 } |
1276 | 1280 |
1277 void PrintWebViewHelper::Print(blink::WebLocalFrame* frame, | 1281 void PrintWebViewHelper::Print(blink::WebLocalFrame* frame, |
1278 const blink::WebNode& node) { | 1282 const blink::WebNode& node, |
| 1283 const bool use_system_specific_flow) { |
1279 // If still not finished with earlier print request simply ignore. | 1284 // If still not finished with earlier print request simply ignore. |
1280 if (prep_frame_view_) | 1285 DLOG(INFO) << "DGN Print"; |
| 1286 |
| 1287 if (prep_frame_view_) { |
| 1288 DLOG(INFO) << "DGN Print request ignored"; |
1281 return; | 1289 return; |
| 1290 } |
1282 | 1291 |
1283 FrameReference frame_ref(frame); | 1292 FrameReference frame_ref(frame); |
1284 | 1293 |
1285 int expected_page_count = 0; | 1294 int expected_page_count = 0; |
1286 if (!CalculateNumberOfPages(frame, node, &expected_page_count)) { | 1295 if (!CalculateNumberOfPages(frame, node, &expected_page_count)) { |
1287 DidFinishPrinting(FAIL_PRINT_INIT); | 1296 DidFinishPrinting(FAIL_PRINT_INIT); |
1288 return; // Failed to init print page settings. | 1297 return; // Failed to init print page settings. |
1289 } | 1298 } |
1290 | 1299 |
| 1300 DLOG(INFO) << "DGN CalculateNumberOfPages OK"; |
| 1301 |
1291 // Some full screen plugins can say they don't want to print. | 1302 // Some full screen plugins can say they don't want to print. |
1292 if (!expected_page_count) { | 1303 if (!expected_page_count) { |
1293 DidFinishPrinting(FAIL_PRINT); | 1304 DidFinishPrinting(FAIL_PRINT); |
1294 return; | 1305 return; |
1295 } | 1306 } |
1296 | 1307 |
1297 // Ask the browser to show UI to retrieve the final print settings. | 1308 // Ask the browser to show UI to retrieve the final print settings. |
1298 if (!GetPrintSettingsFromUser(frame_ref.GetFrame(), node, | 1309 if (!GetPrintSettingsFromUser(frame_ref.GetFrame(), node, |
1299 expected_page_count)) { | 1310 expected_page_count, |
| 1311 use_system_specific_flow)) { |
1300 DidFinishPrinting(OK); // Release resources and fail silently. | 1312 DidFinishPrinting(OK); // Release resources and fail silently. |
1301 return; | 1313 return; |
1302 } | 1314 } |
1303 | 1315 |
| 1316 DLOG(INFO) << "DGN GetPrintSettingsFromUser OK"; |
| 1317 |
1304 // Render Pages for printing. | 1318 // Render Pages for printing. |
1305 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { | 1319 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { |
1306 LOG(ERROR) << "RenderPagesForPrint failed"; | 1320 LOG(ERROR) << "RenderPagesForPrint failed"; |
1307 DidFinishPrinting(FAIL_PRINT); | 1321 DidFinishPrinting(FAIL_PRINT); |
1308 } | 1322 } |
1309 scripting_throttler_.Reset(); | 1323 scripting_throttler_.Reset(); |
1310 } | 1324 } |
1311 | 1325 |
1312 void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) { | 1326 void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) { |
1313 switch (result) { | 1327 switch (result) { |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1566 Send(new PrintHostMsg_ShowInvalidPrinterSettingsError(routing_id())); | 1580 Send(new PrintHostMsg_ShowInvalidPrinterSettingsError(routing_id())); |
1567 | 1581 |
1568 return false; | 1582 return false; |
1569 } | 1583 } |
1570 | 1584 |
1571 return true; | 1585 return true; |
1572 } | 1586 } |
1573 | 1587 |
1574 bool PrintWebViewHelper::GetPrintSettingsFromUser(blink::WebFrame* frame, | 1588 bool PrintWebViewHelper::GetPrintSettingsFromUser(blink::WebFrame* frame, |
1575 const blink::WebNode& node, | 1589 const blink::WebNode& node, |
1576 int expected_pages_count) { | 1590 int expected_pages_count, |
| 1591 const bool system_specific) { |
1577 PrintHostMsg_ScriptedPrint_Params params; | 1592 PrintHostMsg_ScriptedPrint_Params params; |
1578 PrintMsg_PrintPages_Params print_settings; | 1593 PrintMsg_PrintPages_Params print_settings; |
1579 | 1594 |
1580 params.cookie = print_pages_params_->params.document_cookie; | 1595 params.cookie = print_pages_params_->params.document_cookie; |
1581 params.has_selection = frame->hasSelection(); | 1596 params.has_selection = frame->hasSelection(); |
1582 params.expected_pages_count = expected_pages_count; | 1597 params.expected_pages_count = expected_pages_count; |
1583 MarginType margin_type = DEFAULT_MARGINS; | 1598 MarginType margin_type = DEFAULT_MARGINS; |
1584 if (PrintingNodeOrPdfFrame(frame, node)) | 1599 if (PrintingNodeOrPdfFrame(frame, node)) |
1585 margin_type = GetMarginsForPdf(frame, node); | 1600 margin_type = GetMarginsForPdf(frame, node); |
1586 params.margin_type = margin_type; | 1601 params.margin_type = margin_type; |
| 1602 params.use_system_specific_flow = system_specific; |
1587 | 1603 |
1588 Send(new PrintHostMsg_DidShowPrintDialog(routing_id())); | 1604 Send(new PrintHostMsg_DidShowPrintDialog(routing_id())); |
1589 | 1605 |
1590 // PrintHostMsg_ScriptedPrint will reset print_scaling_option, so we save the | 1606 // PrintHostMsg_ScriptedPrint will reset print_scaling_option, so we save the |
1591 // value before and restore it afterwards. | 1607 // value before and restore it afterwards. |
1592 blink::WebPrintScalingOption scaling_option = | 1608 blink::WebPrintScalingOption scaling_option = |
1593 print_pages_params_->params.print_scaling_option; | 1609 print_pages_params_->params.print_scaling_option; |
1594 | 1610 |
1595 print_pages_params_.reset(); | 1611 print_pages_params_.reset(); |
1596 IPC::SyncMessage* msg = | 1612 IPC::SyncMessage* msg = |
1597 new PrintHostMsg_ScriptedPrint(routing_id(), params, &print_settings); | 1613 new PrintHostMsg_ScriptedPrint(routing_id(), params, &print_settings); |
1598 msg->EnableMessagePumping(); | 1614 msg->EnableMessagePumping(); |
1599 Send(msg); | 1615 Send(msg); |
1600 print_settings.params.print_scaling_option = scaling_option; | 1616 print_settings.params.print_scaling_option = scaling_option; |
1601 SetPrintPagesParams(print_settings); | 1617 SetPrintPagesParams(print_settings); |
1602 return (print_settings.params.dpi && print_settings.params.document_cookie); | 1618 return (print_settings.params.dpi && print_settings.params.document_cookie); |
1603 } | 1619 } |
1604 | 1620 |
1605 bool PrintWebViewHelper::RenderPagesForPrint(blink::WebLocalFrame* frame, | 1621 bool PrintWebViewHelper::RenderPagesForPrint(blink::WebLocalFrame* frame, |
1606 const blink::WebNode& node) { | 1622 const blink::WebNode& node) { |
1607 if (!frame || prep_frame_view_) | 1623 if (!frame || prep_frame_view_) |
1608 return false; | 1624 return false; |
| 1625 |
1609 const PrintMsg_PrintPages_Params& params = *print_pages_params_; | 1626 const PrintMsg_PrintPages_Params& params = *print_pages_params_; |
1610 const PrintMsg_Print_Params& print_params = params.params; | 1627 const PrintMsg_Print_Params& print_params = params.params; |
1611 prep_frame_view_.reset(new PrepareFrameAndViewForPrint( | 1628 prep_frame_view_.reset(new PrepareFrameAndViewForPrint( |
1612 print_params, frame, node, ignore_css_margins_)); | 1629 print_params, frame, node, ignore_css_margins_)); |
1613 DCHECK(!print_pages_params_->params.selection_only || | 1630 DCHECK(!print_pages_params_->params.selection_only || |
1614 print_pages_params_->pages.empty()); | 1631 print_pages_params_->pages.empty()); |
1615 prep_frame_view_->CopySelectionIfNeeded( | 1632 prep_frame_view_->CopySelectionIfNeeded( |
1616 render_view()->GetWebkitPreferences(), | 1633 render_view()->GetWebkitPreferences(), |
1617 base::Bind(&PrintWebViewHelper::OnFramePreparedForPrintPages, | 1634 base::Bind(&PrintWebViewHelper::OnFramePreparedForPrintPages, |
1618 base::Unretained(this))); | 1635 base::Unretained(this))); |
(...skipping 436 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 |