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 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
787 | 787 |
788 PrintWebViewHelper::~PrintWebViewHelper() {} | 788 PrintWebViewHelper::~PrintWebViewHelper() {} |
789 | 789 |
790 // static | 790 // static |
791 void PrintWebViewHelper::DisablePreview() { | 791 void PrintWebViewHelper::DisablePreview() { |
792 g_is_preview_enabled_ = false; | 792 g_is_preview_enabled_ = false; |
793 } | 793 } |
794 | 794 |
795 bool PrintWebViewHelper::IsScriptInitiatedPrintAllowed( | 795 bool PrintWebViewHelper::IsScriptInitiatedPrintAllowed( |
796 blink::WebFrame* frame, bool user_initiated) { | 796 blink::WebFrame* frame, bool user_initiated) { |
797 #if defined(OS_ANDROID) | |
798 return false; | |
dgn
2014/11/20 12:26:16
That's how window.print() was disabled
| |
799 #endif // defined(OS_ANDROID) | |
800 // If preview is enabled, then the print dialog is tab modal, and the user | 797 // If preview is enabled, then the print dialog is tab modal, and the user |
801 // can always close the tab on a mis-behaving page (the system print dialog | 798 // can always close the tab on a mis-behaving page (the system print dialog |
802 // is app modal). If the print was initiated through user action, don't | 799 // is app modal). If the print was initiated through user action, don't |
803 // throttle. Or, if the command line flag to skip throttling has been set. | 800 // throttle. Or, if the command line flag to skip throttling has been set. |
804 return !is_scripted_printing_blocked_ && | 801 return !is_scripted_printing_blocked_ && |
805 (user_initiated || g_is_preview_enabled_ || | 802 (user_initiated || g_is_preview_enabled_ || |
806 scripting_throttler_.IsAllowed(frame)); | 803 scripting_throttler_.IsAllowed(frame)); |
807 } | 804 } |
808 | 805 |
809 void PrintWebViewHelper::DidStartLoading() { | 806 void PrintWebViewHelper::DidStartLoading() { |
810 is_loading_ = true; | 807 is_loading_ = true; |
811 } | 808 } |
812 | 809 |
813 void PrintWebViewHelper::DidStopLoading() { | 810 void PrintWebViewHelper::DidStopLoading() { |
814 is_loading_ = false; | 811 is_loading_ = false; |
815 if (!on_stop_loading_closure_.is_null()) { | 812 if (!on_stop_loading_closure_.is_null()) { |
816 on_stop_loading_closure_.Run(); | 813 on_stop_loading_closure_.Run(); |
817 on_stop_loading_closure_.Reset(); | 814 on_stop_loading_closure_.Reset(); |
818 } | 815 } |
819 } | 816 } |
820 | 817 |
821 // Prints |frame| which called window.print(). | 818 // Prints |frame| which called window.print(). |
822 void PrintWebViewHelper::PrintPage(blink::WebLocalFrame* frame, | 819 void PrintWebViewHelper::PrintPage(blink::WebLocalFrame* frame, |
823 bool user_initiated) { | 820 bool user_initiated) { |
821 | |
822 DLOG(INFO) << "DGN PrintPage - From Script - routing_id: " << routing_id(); | |
823 | |
824 DCHECK(frame); | 824 DCHECK(frame); |
825 | 825 |
826 // Allow Prerendering to cancel this print request if necessary. | 826 // Allow Prerendering to cancel this print request if necessary. |
827 if (prerender::PrerenderHelper::IsPrerendering( | 827 if (prerender::PrerenderHelper::IsPrerendering( |
828 render_view()->GetMainRenderFrame())) { | 828 render_view()->GetMainRenderFrame())) { |
829 Send(new ChromeViewHostMsg_CancelPrerenderForPrinting(routing_id())); | 829 Send(new ChromeViewHostMsg_CancelPrerenderForPrinting(routing_id())); |
830 return; | 830 return; |
831 } | 831 } |
832 | 832 |
833 if (!IsScriptInitiatedPrintAllowed(frame, user_initiated)) | 833 if (!IsScriptInitiatedPrintAllowed(frame, user_initiated)) { |
834 DLOG(INFO) << "DGN PrintPage - Script printing not allowed"; | |
834 return; | 835 return; |
836 } | |
835 | 837 |
838 #if defined(OS_ANDROID) | |
839 int cookie = 0; | |
840 if (!print_pages_params_) { | |
841 DLOG(INFO) << "DGN PrintPage - no print_pages_params_"; | |
842 } else { | |
843 cookie = print_pages_params_->params.document_cookie; | |
dgn
2014/11/20 12:26:16
how to properly initialize params? I currently alw
| |
844 DLOG(INFO) << "DGN PrintPage - print_pages_params_->params.document_cookie i s " << cookie; | |
845 } | |
846 | |
847 DLOG(INFO) << "DGN PrintPage - Sending InitiateAndroidPrint"; | |
848 IPC::SyncMessage* msg = new PrintHostMsg_InitiateAndroidPrint(routing_id(), co okie); | |
849 msg->EnableMessagePumping(); | |
850 Send(msg); | |
dgn
2014/11/20 12:26:16
This is the where the renderer should wait until p
| |
851 DLOG(INFO) << "DGN PrintPage - InitiateAndroidPrint returned"; | |
852 #else | |
836 if (!g_is_preview_enabled_) { | 853 if (!g_is_preview_enabled_) { |
837 Print(frame, blink::WebNode()); | 854 Print(frame, blink::WebNode()); |
Vitaly Buka (NO REVIEWS)
2014/11/21 17:05:13
it should go into Print(frame, blink::WebNode());
| |
838 } else { | 855 } else { |
839 print_preview_context_.InitWithFrame(frame); | 856 print_preview_context_.InitWithFrame(frame); |
840 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); | 857 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); |
841 } | 858 } |
859 #endif | |
842 } | 860 } |
843 | 861 |
844 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { | 862 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { |
845 bool handled = true; | 863 bool handled = true; |
846 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) | 864 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) |
847 #if defined(ENABLE_BASIC_PRINTING) | 865 #if defined(ENABLE_BASIC_PRINTING) |
848 IPC_MESSAGE_HANDLER(PrintMsg_PrintPages, OnPrintPages) | 866 IPC_MESSAGE_HANDLER(PrintMsg_PrintPages, OnPrintPages) |
849 IPC_MESSAGE_HANDLER(PrintMsg_PrintForSystemDialog, OnPrintForSystemDialog) | 867 IPC_MESSAGE_HANDLER(PrintMsg_PrintForSystemDialog, OnPrintForSystemDialog) |
850 #endif // ENABLE_BASIC_PRINTING | 868 #endif // ENABLE_BASIC_PRINTING |
851 IPC_MESSAGE_HANDLER(PrintMsg_InitiatePrintPreview, OnInitiatePrintPreview) | 869 IPC_MESSAGE_HANDLER(PrintMsg_InitiatePrintPreview, OnInitiatePrintPreview) |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
939 blink::WebLocalFrame* focusedFrame = | 957 blink::WebLocalFrame* focusedFrame = |
940 webView->focusedFrame()->toWebLocalFrame(); | 958 webView->focusedFrame()->toWebLocalFrame(); |
941 *frame = focusedFrame->hasSelection() | 959 *frame = focusedFrame->hasSelection() |
942 ? focusedFrame | 960 ? focusedFrame |
943 : webView->mainFrame()->toWebLocalFrame(); | 961 : webView->mainFrame()->toWebLocalFrame(); |
944 return true; | 962 return true; |
945 } | 963 } |
946 | 964 |
947 #if defined(ENABLE_BASIC_PRINTING) | 965 #if defined(ENABLE_BASIC_PRINTING) |
948 void PrintWebViewHelper::OnPrintPages() { | 966 void PrintWebViewHelper::OnPrintPages() { |
967 DLOG(INFO) << "DGN - OnPrintPages - Call from PrintManager"; | |
949 blink::WebLocalFrame* frame; | 968 blink::WebLocalFrame* frame; |
950 if (GetPrintFrame(&frame)) | 969 if (GetPrintFrame(&frame)) |
951 Print(frame, blink::WebNode()); | 970 Print(frame, blink::WebNode()); |
952 } | 971 } |
953 | 972 |
954 void PrintWebViewHelper::OnPrintForSystemDialog() { | 973 void PrintWebViewHelper::OnPrintForSystemDialog() { |
955 blink::WebLocalFrame* frame = print_preview_context_.source_frame(); | 974 blink::WebLocalFrame* frame = print_preview_context_.source_frame(); |
956 if (!frame) { | 975 if (!frame) { |
957 NOTREACHED(); | 976 NOTREACHED(); |
958 return; | 977 return; |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1237 print_preview_context_.InitWithNode(node); | 1256 print_preview_context_.InitWithNode(node); |
1238 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE); | 1257 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE); |
1239 } | 1258 } |
1240 | 1259 |
1241 print_node_in_progress_ = false; | 1260 print_node_in_progress_ = false; |
1242 } | 1261 } |
1243 | 1262 |
1244 void PrintWebViewHelper::Print(blink::WebLocalFrame* frame, | 1263 void PrintWebViewHelper::Print(blink::WebLocalFrame* frame, |
1245 const blink::WebNode& node) { | 1264 const blink::WebNode& node) { |
1246 // If still not finished with earlier print request simply ignore. | 1265 // If still not finished with earlier print request simply ignore. |
1247 if (prep_frame_view_) | 1266 DLOG(INFO) << "DGN Print"; |
1267 | |
1268 if (prep_frame_view_) { | |
1269 DLOG(INFO) << "DGN Print request ignored"; | |
1248 return; | 1270 return; |
1271 } | |
1249 | 1272 |
1250 FrameReference frame_ref(frame); | 1273 FrameReference frame_ref(frame); |
1251 | 1274 |
1252 int expected_page_count = 0; | 1275 int expected_page_count = 0; |
1253 if (!CalculateNumberOfPages(frame, node, &expected_page_count)) { | 1276 if (!CalculateNumberOfPages(frame, node, &expected_page_count)) { |
1254 DidFinishPrinting(FAIL_PRINT_INIT); | 1277 DidFinishPrinting(FAIL_PRINT_INIT); |
1255 return; // Failed to init print page settings. | 1278 return; // Failed to init print page settings. |
1256 } | 1279 } |
1257 | 1280 |
1281 DLOG(INFO) << "DGN CalculateNumberOfPages OK"; | |
1282 | |
1258 // Some full screen plugins can say they don't want to print. | 1283 // Some full screen plugins can say they don't want to print. |
1259 if (!expected_page_count) { | 1284 if (!expected_page_count) { |
1260 DidFinishPrinting(FAIL_PRINT); | 1285 DidFinishPrinting(FAIL_PRINT); |
1261 return; | 1286 return; |
1262 } | 1287 } |
1263 | 1288 |
1264 // Ask the browser to show UI to retrieve the final print settings. | 1289 // Ask the browser to show UI to retrieve the final print settings. |
1265 if (!GetPrintSettingsFromUser(frame_ref.GetFrame(), node, | 1290 if (!GetPrintSettingsFromUser(frame_ref.GetFrame(), node, |
Vitaly Buka (NO REVIEWS)
2014/11/21 17:05:13
this will set print_pages_params_
| |
1266 expected_page_count)) { | 1291 expected_page_count)) { |
1267 DidFinishPrinting(OK); // Release resources and fail silently. | 1292 DidFinishPrinting(OK); // Release resources and fail silently. |
1268 return; | 1293 return; |
1269 } | 1294 } |
1270 | 1295 |
1296 DLOG(INFO) << "DGN GetPrintSettingsFromUser OK"; | |
1297 | |
1271 // Render Pages for printing. | 1298 // Render Pages for printing. |
1272 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { | 1299 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { |
1273 LOG(ERROR) << "RenderPagesForPrint failed"; | 1300 LOG(ERROR) << "RenderPagesForPrint failed"; |
1274 DidFinishPrinting(FAIL_PRINT); | 1301 DidFinishPrinting(FAIL_PRINT); |
1275 } | 1302 } |
1276 scripting_throttler_.Reset(); | 1303 scripting_throttler_.Reset(); |
1277 } | 1304 } |
1278 | 1305 |
1279 void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) { | 1306 void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) { |
1307 if (result == OK) DLOG(INFO) << "DGN DidFinishPrinting"; | |
1308 else DLOG(INFO) << "DGN DidFinishPrinting - Failure: " << result; | |
1309 | |
1280 switch (result) { | 1310 switch (result) { |
1281 case OK: | 1311 case OK: |
1282 break; | 1312 break; |
1283 | 1313 |
1284 case FAIL_PRINT_INIT: | 1314 case FAIL_PRINT_INIT: |
1285 DCHECK(!notify_browser_of_print_failure_); | 1315 DCHECK(!notify_browser_of_print_failure_); |
1286 break; | 1316 break; |
1287 | 1317 |
1288 case FAIL_PRINT: | 1318 case FAIL_PRINT: |
1289 if (notify_browser_of_print_failure_ && print_pages_params_) { | 1319 if (notify_browser_of_print_failure_ && print_pages_params_) { |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1560 Send(msg); | 1590 Send(msg); |
1561 print_settings.params.print_scaling_option = scaling_option; | 1591 print_settings.params.print_scaling_option = scaling_option; |
1562 SetPrintPagesParams(print_settings); | 1592 SetPrintPagesParams(print_settings); |
1563 return (print_settings.params.dpi && print_settings.params.document_cookie); | 1593 return (print_settings.params.dpi && print_settings.params.document_cookie); |
1564 } | 1594 } |
1565 | 1595 |
1566 bool PrintWebViewHelper::RenderPagesForPrint(blink::WebLocalFrame* frame, | 1596 bool PrintWebViewHelper::RenderPagesForPrint(blink::WebLocalFrame* frame, |
1567 const blink::WebNode& node) { | 1597 const blink::WebNode& node) { |
1568 if (!frame || prep_frame_view_) | 1598 if (!frame || prep_frame_view_) |
1569 return false; | 1599 return false; |
1600 | |
1570 const PrintMsg_PrintPages_Params& params = *print_pages_params_; | 1601 const PrintMsg_PrintPages_Params& params = *print_pages_params_; |
1571 const PrintMsg_Print_Params& print_params = params.params; | 1602 const PrintMsg_Print_Params& print_params = params.params; |
1572 prep_frame_view_.reset(new PrepareFrameAndViewForPrint( | 1603 prep_frame_view_.reset(new PrepareFrameAndViewForPrint( |
1573 print_params, frame, node, ignore_css_margins_)); | 1604 print_params, frame, node, ignore_css_margins_)); |
1574 DCHECK(!print_pages_params_->params.selection_only || | 1605 DCHECK(!print_pages_params_->params.selection_only || |
1575 print_pages_params_->pages.empty()); | 1606 print_pages_params_->pages.empty()); |
1576 prep_frame_view_->CopySelectionIfNeeded( | 1607 prep_frame_view_->CopySelectionIfNeeded( |
1577 render_view()->GetWebkitPreferences(), | 1608 render_view()->GetWebkitPreferences(), |
1578 base::Bind(&PrintWebViewHelper::OnFramePreparedForPrintPages, | 1609 base::Bind(&PrintWebViewHelper::OnFramePreparedForPrintPages, |
1579 base::Unretained(this))); | 1610 base::Unretained(this))); |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2016 blink::WebConsoleMessage::LevelWarning, message)); | 2047 blink::WebConsoleMessage::LevelWarning, message)); |
2017 return false; | 2048 return false; |
2018 } | 2049 } |
2019 | 2050 |
2020 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2051 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
2021 // Reset counter on successful print. | 2052 // Reset counter on successful print. |
2022 count_ = 0; | 2053 count_ = 0; |
2023 } | 2054 } |
2024 | 2055 |
2025 } // namespace printing | 2056 } // namespace printing |
OLD | NEW |