Chromium Code Reviews| 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 #if defined(OS_ANDROID) |
| 859 Print(frame, blink::WebNode(), true); | |
| 860 #else | |
|
Vitaly Buka (NO REVIEWS)
2014/12/12 08:37:17
set true for all platforms, and use if def on brow
dgn
2014/12/12 16:49:44
I will still have to use if def to send false when
| |
| 861 Print(frame, blink::WebNode(), false); | |
| 862 #endif | |
| 862 } else { | 863 } else { |
| 863 print_preview_context_.InitWithFrame(frame); | 864 print_preview_context_.InitWithFrame(frame); |
| 864 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); | 865 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); |
| 865 } | 866 } |
| 866 } | 867 } |
| 867 | 868 |
| 868 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { | 869 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { |
| 869 bool handled = true; | 870 bool handled = true; |
| 870 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) | 871 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) |
| 871 #if defined(ENABLE_BASIC_PRINTING) | 872 #if defined(ENABLE_BASIC_PRINTING) |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1268 Print(duplicate_node.document().frame(), duplicate_node); | 1269 Print(duplicate_node.document().frame(), duplicate_node); |
| 1269 } else { | 1270 } else { |
| 1270 print_preview_context_.InitWithNode(node); | 1271 print_preview_context_.InitWithNode(node); |
| 1271 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE); | 1272 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE); |
| 1272 } | 1273 } |
| 1273 | 1274 |
| 1274 print_node_in_progress_ = false; | 1275 print_node_in_progress_ = false; |
| 1275 } | 1276 } |
| 1276 | 1277 |
| 1277 void PrintWebViewHelper::Print(blink::WebLocalFrame* frame, | 1278 void PrintWebViewHelper::Print(blink::WebLocalFrame* frame, |
| 1278 const blink::WebNode& node) { | 1279 const blink::WebNode& node, |
| 1280 const bool use_system_specific_flow) { | |
|
Vitaly Buka (NO REVIEWS)
2014/12/12 08:37:17
let's call this argn and IPC is_scripted or someth
dgn
2014/12/12 16:49:44
Done.
| |
| 1279 // If still not finished with earlier print request simply ignore. | 1281 // If still not finished with earlier print request simply ignore. |
| 1280 if (prep_frame_view_) | 1282 if (prep_frame_view_) |
| 1281 return; | 1283 return; |
| 1282 | 1284 |
| 1283 FrameReference frame_ref(frame); | 1285 FrameReference frame_ref(frame); |
| 1284 | 1286 |
| 1285 int expected_page_count = 0; | 1287 int expected_page_count = 0; |
| 1286 if (!CalculateNumberOfPages(frame, node, &expected_page_count)) { | 1288 if (!CalculateNumberOfPages(frame, node, &expected_page_count)) { |
| 1287 DidFinishPrinting(FAIL_PRINT_INIT); | 1289 DidFinishPrinting(FAIL_PRINT_INIT); |
| 1288 return; // Failed to init print page settings. | 1290 return; // Failed to init print page settings. |
| 1289 } | 1291 } |
| 1290 | 1292 |
| 1291 // Some full screen plugins can say they don't want to print. | 1293 // Some full screen plugins can say they don't want to print. |
| 1292 if (!expected_page_count) { | 1294 if (!expected_page_count) { |
| 1293 DidFinishPrinting(FAIL_PRINT); | 1295 DidFinishPrinting(FAIL_PRINT); |
| 1294 return; | 1296 return; |
| 1295 } | 1297 } |
| 1296 | 1298 |
| 1297 // Ask the browser to show UI to retrieve the final print settings. | 1299 // Ask the browser to show UI to retrieve the final print settings. |
| 1298 if (!GetPrintSettingsFromUser(frame_ref.GetFrame(), node, | 1300 if (!GetPrintSettingsFromUser(frame_ref.GetFrame(), node, |
| 1299 expected_page_count)) { | 1301 expected_page_count, |
| 1302 use_system_specific_flow)) { | |
| 1300 DidFinishPrinting(OK); // Release resources and fail silently. | 1303 DidFinishPrinting(OK); // Release resources and fail silently. |
| 1301 return; | 1304 return; |
| 1302 } | 1305 } |
| 1303 | 1306 |
| 1304 // Render Pages for printing. | 1307 // Render Pages for printing. |
| 1305 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { | 1308 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { |
| 1306 LOG(ERROR) << "RenderPagesForPrint failed"; | 1309 LOG(ERROR) << "RenderPagesForPrint failed"; |
| 1307 DidFinishPrinting(FAIL_PRINT); | 1310 DidFinishPrinting(FAIL_PRINT); |
| 1308 } | 1311 } |
| 1309 scripting_throttler_.Reset(); | 1312 scripting_throttler_.Reset(); |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1566 Send(new PrintHostMsg_ShowInvalidPrinterSettingsError(routing_id())); | 1569 Send(new PrintHostMsg_ShowInvalidPrinterSettingsError(routing_id())); |
| 1567 | 1570 |
| 1568 return false; | 1571 return false; |
| 1569 } | 1572 } |
| 1570 | 1573 |
| 1571 return true; | 1574 return true; |
| 1572 } | 1575 } |
| 1573 | 1576 |
| 1574 bool PrintWebViewHelper::GetPrintSettingsFromUser(blink::WebFrame* frame, | 1577 bool PrintWebViewHelper::GetPrintSettingsFromUser(blink::WebFrame* frame, |
| 1575 const blink::WebNode& node, | 1578 const blink::WebNode& node, |
| 1576 int expected_pages_count) { | 1579 int expected_pages_count, |
| 1580 const bool system_specific) { | |
| 1577 PrintHostMsg_ScriptedPrint_Params params; | 1581 PrintHostMsg_ScriptedPrint_Params params; |
| 1578 PrintMsg_PrintPages_Params print_settings; | 1582 PrintMsg_PrintPages_Params print_settings; |
| 1579 | 1583 |
| 1580 params.cookie = print_pages_params_->params.document_cookie; | 1584 params.cookie = print_pages_params_->params.document_cookie; |
| 1581 params.has_selection = frame->hasSelection(); | 1585 params.has_selection = frame->hasSelection(); |
| 1582 params.expected_pages_count = expected_pages_count; | 1586 params.expected_pages_count = expected_pages_count; |
| 1583 MarginType margin_type = DEFAULT_MARGINS; | 1587 MarginType margin_type = DEFAULT_MARGINS; |
| 1584 if (PrintingNodeOrPdfFrame(frame, node)) | 1588 if (PrintingNodeOrPdfFrame(frame, node)) |
| 1585 margin_type = GetMarginsForPdf(frame, node); | 1589 margin_type = GetMarginsForPdf(frame, node); |
| 1586 params.margin_type = margin_type; | 1590 params.margin_type = margin_type; |
| 1591 params.use_system_specific_flow = system_specific; | |
| 1587 | 1592 |
| 1588 Send(new PrintHostMsg_DidShowPrintDialog(routing_id())); | 1593 Send(new PrintHostMsg_DidShowPrintDialog(routing_id())); |
| 1589 | 1594 |
| 1590 // PrintHostMsg_ScriptedPrint will reset print_scaling_option, so we save the | 1595 // PrintHostMsg_ScriptedPrint will reset print_scaling_option, so we save the |
| 1591 // value before and restore it afterwards. | 1596 // value before and restore it afterwards. |
| 1592 blink::WebPrintScalingOption scaling_option = | 1597 blink::WebPrintScalingOption scaling_option = |
| 1593 print_pages_params_->params.print_scaling_option; | 1598 print_pages_params_->params.print_scaling_option; |
| 1594 | 1599 |
| 1595 print_pages_params_.reset(); | 1600 print_pages_params_.reset(); |
| 1596 IPC::SyncMessage* msg = | 1601 IPC::SyncMessage* msg = |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2055 blink::WebConsoleMessage::LevelWarning, message)); | 2060 blink::WebConsoleMessage::LevelWarning, message)); |
| 2056 return false; | 2061 return false; |
| 2057 } | 2062 } |
| 2058 | 2063 |
| 2059 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2064 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
| 2060 // Reset counter on successful print. | 2065 // Reset counter on successful print. |
| 2061 count_ = 0; | 2066 count_ = 0; |
| 2062 } | 2067 } |
| 2063 | 2068 |
| 2064 } // namespace printing | 2069 } // namespace printing |
| OLD | NEW |