Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: components/printing/renderer/print_web_view_helper.cc

Issue 2522313003: Check for PrintWebViewHelper validity when running nested message loops. (Closed)
Patch Set: self review Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/printing/renderer/print_web_view_helper.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "components/printing/renderer/print_web_view_helper.h" 5 #include "components/printing/renderer/print_web_view_helper.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <string> 11 #include <string>
12 #include <utility> 12 #include <utility>
13 13
14 #include "base/auto_reset.h" 14 #include "base/auto_reset.h"
15 #include "base/callback_helpers.h"
15 #include "base/json/json_writer.h" 16 #include "base/json/json_writer.h"
16 #include "base/location.h" 17 #include "base/location.h"
17 #include "base/logging.h" 18 #include "base/logging.h"
18 #include "base/macros.h" 19 #include "base/macros.h"
19 #include "base/metrics/histogram_macros.h" 20 #include "base/metrics/histogram_macros.h"
20 #include "base/process/process_handle.h" 21 #include "base/process/process_handle.h"
21 #include "base/single_thread_task_runner.h" 22 #include "base/single_thread_task_runner.h"
22 #include "base/strings/string_number_conversions.h" 23 #include "base/strings/string_number_conversions.h"
23 #include "base/strings/stringprintf.h" 24 #include "base/strings/stringprintf.h"
24 #include "base/strings/utf_string_conversions.h" 25 #include "base/strings/utf_string_conversions.h"
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 result_params.margin_left = 515 result_params.margin_left =
515 ScaleAndRound(result_params.margin_left, page_scaling); 516 ScaleAndRound(result_params.margin_left, page_scaling);
516 result_params.margin_top = 517 result_params.margin_top =
517 ScaleAndRound(result_params.margin_top, page_scaling); 518 ScaleAndRound(result_params.margin_top, page_scaling);
518 } 519 }
519 } 520 }
520 521
521 return result_params; 522 return result_params;
522 } 523 }
523 524
525 void SendScriptedPrint(
526 PrintWebViewHelper* print_helper,
527 const PrintHostMsg_ScriptedPrint_Params& params,
528 blink::WebPrintScalingOption scaling_option,
529 const PrintWebViewHelper::GetPrintSettingsFromUserCallback& done_callback) {
530 PrintMsg_PrintPages_Params print_settings;
531 auto msg = base::MakeUnique<PrintHostMsg_ScriptedPrint>(
532 print_helper->routing_id(), params, &print_settings);
533 msg->EnableMessagePumping();
534
535 // WARNING: |print_helper| may no longer be valid when Send() returns.
536 print_helper->Send(msg.release());
537 print_settings.params.print_scaling_option = scaling_option;
538 done_callback.Run(print_settings);
539 }
540
541 void SendSetupScriptedPrintPreview(PrintWebViewHelper* print_helper,
542 const base::Closure& done_callback) {
543 auto msg = base::MakeUnique<PrintHostMsg_SetupScriptedPrintPreview>(
544 print_helper->routing_id());
545 msg->EnableMessagePumping();
546
547 // WARNING: |print_helper| may no longer be valid when Send() returns.
548 print_helper->Send(msg.release());
549 done_callback.Run();
550 }
551
524 } // namespace 552 } // namespace
525 553
526 FrameReference::FrameReference(blink::WebLocalFrame* frame) { 554 FrameReference::FrameReference(blink::WebLocalFrame* frame) {
527 Reset(frame); 555 Reset(frame);
528 } 556 }
529 557
530 FrameReference::FrameReference() { 558 FrameReference::FrameReference() {
531 Reset(NULL); 559 Reset(NULL);
532 } 560 }
533 561
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 if (!IsScriptInitiatedPrintAllowed(web_frame, user_initiated)) 985 if (!IsScriptInitiatedPrintAllowed(web_frame, user_initiated))
958 return; 986 return;
959 987
960 if (delegate_->OverridePrint(web_frame)) 988 if (delegate_->OverridePrint(web_frame))
961 return; 989 return;
962 990
963 if (g_is_preview_enabled) { 991 if (g_is_preview_enabled) {
964 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) 992 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
965 print_preview_context_.InitWithFrame(web_frame); 993 print_preview_context_.InitWithFrame(web_frame);
966 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); 994 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED);
995 // WARNING: |this| may be gone at this point. Do not do any more work here
996 // and just return.
967 #endif 997 #endif
968 } else { 998 return;
999 }
969 #if BUILDFLAG(ENABLE_BASIC_PRINTING) 1000 #if BUILDFLAG(ENABLE_BASIC_PRINTING)
970 Print(web_frame, blink::WebNode(), true /* is_scripted? */); 1001 StartPrint(web_frame, blink::WebNode(), true /* is_scripted? */,
1002 false /* reset_print_node_in_progress? */);
1003 // WARNING: |this| may be gone at this point. Do not do any more work here and
1004 // just return.
971 #endif 1005 #endif
972 }
973 } 1006 }
974 1007
975 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { 1008 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) {
976 // The class is not designed to handle recursive messages. This is not 1009 // The class is not designed to handle recursive messages. This is not
977 // expected during regular flow. However, during rendering of content for 1010 // expected during regular flow. However, during rendering of content for
978 // printing, lower level code may run nested message loop. E.g. PDF may has 1011 // printing, lower level code may run nested message loop. E.g. PDF may has
979 // script to show message box http://crbug.com/502562. In that moment browser 1012 // script to show message box http://crbug.com/502562. In that moment browser
980 // may receive updated printer capabilities and decide to restart print 1013 // may receive updated printer capabilities and decide to restart print
981 // preview generation. When this happened message handling function may 1014 // preview generation. When this happened message handling function may
982 // choose to ignore message or safely crash process. 1015 // choose to ignore message or safely crash process.
(...skipping 28 matching lines...) Expand all
1011 #if BUILDFLAG(ENABLE_BASIC_PRINTING) 1044 #if BUILDFLAG(ENABLE_BASIC_PRINTING)
1012 void PrintWebViewHelper::OnPrintPages() { 1045 void PrintWebViewHelper::OnPrintPages() {
1013 if (ipc_nesting_level_> 1) 1046 if (ipc_nesting_level_> 1)
1014 return; 1047 return;
1015 1048
1016 blink::WebLocalFrame* frame = render_frame()->GetWebFrame(); 1049 blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
1017 1050
1018 // If we are printing a PDF extension frame, find the plugin node and print 1051 // If we are printing a PDF extension frame, find the plugin node and print
1019 // that instead. 1052 // that instead.
1020 auto plugin = delegate_->GetPdfElement(frame); 1053 auto plugin = delegate_->GetPdfElement(frame);
1021 Print(frame, plugin, false /* is_scripted? */); 1054 StartPrint(frame, plugin, false /* is_scripted? */,
1055 false /* reset_print_node_in_progress? */);
1056 // WARNING: |this| may be gone at this point. Do not do any more work here and
1057 // just return.
1022 } 1058 }
1023 1059
1024 void PrintWebViewHelper::OnPrintForSystemDialog() { 1060 void PrintWebViewHelper::OnPrintForSystemDialog() {
1025 if (ipc_nesting_level_> 1) 1061 if (ipc_nesting_level_> 1)
1026 return; 1062 return;
1027 blink::WebLocalFrame* frame = print_preview_context_.source_frame(); 1063 blink::WebLocalFrame* frame = print_preview_context_.source_frame();
1028 if (!frame) { 1064 if (!frame) {
1029 NOTREACHED(); 1065 NOTREACHED();
1030 return; 1066 return;
1031 } 1067 }
1032 Print(frame, print_preview_context_.source_node(), false); 1068 StartPrint(frame, print_preview_context_.source_node(), false,
1069 false /* reset_print_node_in_progress? */);
1070 // WARNING: |this| may be gone at this point. Do not do any more work here and
1071 // just return.
1033 } 1072 }
1034 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) 1073 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING)
1035 1074
1036 #if BUILDFLAG(ENABLE_BASIC_PRINTING) && BUILDFLAG(ENABLE_PRINT_PREVIEW) 1075 #if BUILDFLAG(ENABLE_BASIC_PRINTING) && BUILDFLAG(ENABLE_PRINT_PREVIEW)
1037 void PrintWebViewHelper::OnPrintForPrintPreview( 1076 void PrintWebViewHelper::OnPrintForPrintPreview(
1038 const base::DictionaryValue& job_settings) { 1077 const base::DictionaryValue& job_settings) {
1039 CHECK_LE(ipc_nesting_level_, 1); 1078 CHECK_LE(ipc_nesting_level_, 1);
1040 // If still not finished with earlier print request simply ignore. 1079 // If still not finished with earlier print request simply ignore.
1041 if (prep_frame_view_) 1080 if (prep_frame_view_)
1042 return; 1081 return;
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
1411 1450
1412 if (print_node_in_progress_) { 1451 if (print_node_in_progress_) {
1413 // This can happen as a result of processing sync messages when printing 1452 // This can happen as a result of processing sync messages when printing
1414 // from ppapi plugins. It's a rare case, so its OK to just fail here. 1453 // from ppapi plugins. It's a rare case, so its OK to just fail here.
1415 // See http://crbug.com/159165. 1454 // See http://crbug.com/159165.
1416 return; 1455 return;
1417 } 1456 }
1418 1457
1419 print_node_in_progress_ = true; 1458 print_node_in_progress_ = true;
1420 1459
1421 // Make a copy of the node, in case RenderView::OnContextMenuClosed resets
1422 // its |context_menu_node_|.
1423 if (g_is_preview_enabled) { 1460 if (g_is_preview_enabled) {
1424 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) 1461 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
1425 print_preview_context_.InitWithNode(node); 1462 print_preview_context_.InitWithNode(node);
1426 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE); 1463 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE);
1427 #endif 1464 #endif
1428 } else { 1465 print_node_in_progress_ = false;
1429 #if BUILDFLAG(ENABLE_BASIC_PRINTING) 1466 return;
1430 blink::WebNode duplicate_node(node);
1431 Print(duplicate_node.document().frame(), duplicate_node, false);
1432 #endif
1433 } 1467 }
1434 1468
1435 print_node_in_progress_ = false; 1469 #if BUILDFLAG(ENABLE_BASIC_PRINTING)
1470 // Make a copy of the node, in case RenderView::OnContextMenuClosed() resets
1471 // its |context_menu_node_|.
1472 blink::WebNode duplicate_node(node);
1473 StartPrint(duplicate_node.document().frame(), duplicate_node,
1474 false /* is_scripted? */,
1475 true /* reset_print_node_in_progress? */);
1476 // WARNING: |this| may be gone at this point. Do not do any more work here and
1477 // just return.
1478 #endif
1436 } 1479 }
1437 1480
1438 #if BUILDFLAG(ENABLE_BASIC_PRINTING) 1481 #if BUILDFLAG(ENABLE_BASIC_PRINTING)
1439 void PrintWebViewHelper::Print(blink::WebLocalFrame* frame, 1482 void PrintWebViewHelper::StartPrint(blink::WebLocalFrame* frame,
1440 const blink::WebNode& node, 1483 const blink::WebNode& node,
1441 bool is_scripted) { 1484 bool is_scripted,
1485 bool reset_print_node_in_progress) {
1486 std::unique_ptr<base::ScopedClosureRunner> on_finish_callback;
1487 if (reset_print_node_in_progress) {
1488 on_finish_callback = base::MakeUnique<base::ScopedClosureRunner>(
1489 base::Bind(&PrintWebViewHelper::print_node_in_progress_finished,
1490 weak_ptr_factory_.GetWeakPtr()));
1491 }
1492
1442 // If still not finished with earlier print request simply ignore. 1493 // If still not finished with earlier print request simply ignore.
1443 if (prep_frame_view_) 1494 if (prep_frame_view_)
1444 return; 1495 return;
1445 1496
1446 FrameReference frame_ref(frame); 1497 auto frame_ref = base::MakeUnique<FrameReference>(frame);
1447 1498
1448 int expected_page_count = 0; 1499 int expected_page_count = 0;
1449 if (!CalculateNumberOfPages(frame, node, &expected_page_count)) { 1500 if (!CalculateNumberOfPages(frame, node, &expected_page_count)) {
1450 DidFinishPrinting(FAIL_PRINT_INIT); 1501 DidFinishPrinting(FAIL_PRINT_INIT);
1451 return; // Failed to init print page settings. 1502 return; // Failed to init print page settings.
1452 } 1503 }
1453 1504
1454 // Some full screen plugins can say they don't want to print. 1505 // Some full screen plugins can say they don't want to print.
1455 if (!expected_page_count) { 1506 if (!expected_page_count) {
1456 DidFinishPrinting(FAIL_PRINT); 1507 DidFinishPrinting(FAIL_PRINT);
1457 return; 1508 return;
1458 } 1509 }
1459 1510
1511 // If the browser does not want to show the UI, then just go ahead and print.
1512 if (!delegate_->IsAskPrintSettingsEnabled()) {
1513 FinishPrint(std::move(frame_ref), node);
1514 return;
1515 }
1516
1460 // Ask the browser to show UI to retrieve the final print settings. 1517 // Ask the browser to show UI to retrieve the final print settings.
1461 if (delegate_->IsAskPrintSettingsEnabled() && 1518 GetPrintSettingsFromUser(std::move(frame_ref), node, expected_page_count,
1462 !GetPrintSettingsFromUser(frame_ref.GetFrame(), node, expected_page_count, 1519 is_scripted, std::move(on_finish_callback));
1463 is_scripted)) { 1520 // WARNING: |this| may be gone at this point. Do not do any more work here and
1464 DidFinishPrinting(OK); // Release resources and fail silently. 1521 // just return.
1465 return; 1522 }
1466 }
1467 1523
1524 void PrintWebViewHelper::FinishPrint(std::unique_ptr<FrameReference> frame_ref,
1525 const blink::WebNode& node) {
1468 // Render Pages for printing. 1526 // Render Pages for printing.
1469 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { 1527 if (!RenderPagesForPrint(frame_ref->GetFrame(), node)) {
1470 LOG(ERROR) << "RenderPagesForPrint failed"; 1528 LOG(ERROR) << "RenderPagesForPrint failed";
1471 DidFinishPrinting(FAIL_PRINT); 1529 DidFinishPrinting(FAIL_PRINT);
1472 } 1530 }
1473 scripting_throttler_.Reset(); 1531 scripting_throttler_.Reset();
1474 } 1532 }
1475 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) 1533 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING)
1476 1534
1477 void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) { 1535 void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) {
1478 switch (result) { 1536 switch (result) {
1479 case OK: 1537 case OK:
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1725 } 1783 }
1726 1784
1727 settings.params.print_to_pdf = IsPrintToPdfRequested(*job_settings); 1785 settings.params.print_to_pdf = IsPrintToPdfRequested(*job_settings);
1728 UpdateFrameMarginsCssInfo(*job_settings); 1786 UpdateFrameMarginsCssInfo(*job_settings);
1729 settings.params.print_scaling_option = GetPrintScalingOption( 1787 settings.params.print_scaling_option = GetPrintScalingOption(
1730 frame, node, source_is_html, *job_settings, settings.params); 1788 frame, node, source_is_html, *job_settings, settings.params);
1731 } 1789 }
1732 1790
1733 SetPrintPagesParams(settings); 1791 SetPrintPagesParams(settings);
1734 1792
1735 if (!PrintMsg_Print_Params_IsValid(settings.params)) { 1793 if (PrintMsg_Print_Params_IsValid(settings.params))
1736 if (!print_for_preview_) 1794 return true;
1737 print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS);
1738 else
1739 Send(new PrintHostMsg_ShowInvalidPrinterSettingsError(routing_id()));
1740 1795
1741 return false; 1796 if (print_for_preview_)
1742 } 1797 Send(new PrintHostMsg_ShowInvalidPrinterSettingsError(routing_id()));
1743 1798 else
1744 return true; 1799 print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS);
1800 return false;
1745 } 1801 }
1746 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) 1802 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
1747 1803
1748 #if BUILDFLAG(ENABLE_BASIC_PRINTING) 1804 #if BUILDFLAG(ENABLE_BASIC_PRINTING)
1749 bool PrintWebViewHelper::GetPrintSettingsFromUser(blink::WebLocalFrame* frame, 1805 void PrintWebViewHelper::GetPrintSettingsFromUser(
1750 const blink::WebNode& node, 1806 std::unique_ptr<FrameReference> frame_ref,
1751 int expected_pages_count, 1807 const blink::WebNode& node,
1752 bool is_scripted) { 1808 int expected_pages_count,
1809 bool is_scripted,
1810 std::unique_ptr<base::ScopedClosureRunner> on_finish_callback) {
1811 blink::WebLocalFrame* frame = frame_ref->GetFrame();
1753 PrintHostMsg_ScriptedPrint_Params params; 1812 PrintHostMsg_ScriptedPrint_Params params;
1754 PrintMsg_PrintPages_Params print_settings;
1755
1756 params.cookie = print_pages_params_->params.document_cookie; 1813 params.cookie = print_pages_params_->params.document_cookie;
1757 params.has_selection = frame->hasSelection(); 1814 params.has_selection = frame->hasSelection();
1758 params.expected_pages_count = expected_pages_count; 1815 params.expected_pages_count = expected_pages_count;
1759 MarginType margin_type = DEFAULT_MARGINS; 1816 MarginType margin_type = DEFAULT_MARGINS;
1760 if (PrintingNodeOrPdfFrame(frame, node)) { 1817 if (PrintingNodeOrPdfFrame(frame, node))
1761 margin_type = 1818 margin_type = GetMarginsForPdf(frame, node, print_pages_params_->params);
1762 GetMarginsForPdf(frame, node, print_pages_params_->params);
1763 }
1764 params.margin_type = margin_type; 1819 params.margin_type = margin_type;
1765 params.is_scripted = is_scripted; 1820 params.is_scripted = is_scripted;
1766 params.is_modifiable = !PrintingNodeOrPdfFrame(frame, node); 1821 params.is_modifiable = !PrintingNodeOrPdfFrame(frame, node);
1767 1822
1768 Send(new PrintHostMsg_DidShowPrintDialog(routing_id())); 1823 Send(new PrintHostMsg_DidShowPrintDialog(routing_id()));
1769 1824
1770 // PrintHostMsg_ScriptedPrint will reset print_scaling_option, so we save the 1825 // PrintHostMsg_ScriptedPrint in SendScriptedPrint() will reset
1771 // value before and restore it afterwards. 1826 // |print_scaling_option|, so save the value before and restore it afterwards.
1772 blink::WebPrintScalingOption scaling_option = 1827 blink::WebPrintScalingOption scaling_option =
1773 print_pages_params_->params.print_scaling_option; 1828 print_pages_params_->params.print_scaling_option;
1774 1829
1775 print_pages_params_.reset(); 1830 print_pages_params_.reset();
1776 IPC::SyncMessage* msg = 1831
1777 new PrintHostMsg_ScriptedPrint(routing_id(), params, &print_settings); 1832 GetPrintSettingsFromUserCallback ask_user_done_callback =
1778 msg->EnableMessagePumping(); 1833 base::Bind(&PrintWebViewHelper::OnGetPrintSettingsFromUser,
1779 Send(msg); 1834 weak_ptr_factory_.GetWeakPtr(), base::Passed(&frame_ref), node,
1780 print_settings.params.print_scaling_option = scaling_option; 1835 base::Passed(&on_finish_callback));
1836 SendScriptedPrint(this, params, scaling_option, ask_user_done_callback);
1837 // WARNING: |this| may be gone at this point. Do not do any more work here and
1838 // just return. Put any work that needs to be done in |done_callback| above.
1839 }
1840
1841 void PrintWebViewHelper::OnGetPrintSettingsFromUser(
1842 std::unique_ptr<FrameReference> frame_ref,
1843 const blink::WebNode& node,
1844 std::unique_ptr<base::ScopedClosureRunner> on_finish_callback,
1845 const PrintMsg_PrintPages_Params& print_settings) {
1781 SetPrintPagesParams(print_settings); 1846 SetPrintPagesParams(print_settings);
1782 return (print_settings.params.dpi && print_settings.params.document_cookie); 1847 if (print_settings.params.dpi && print_settings.params.document_cookie) {
1848 FinishPrint(std::move(frame_ref), node);
1849 return;
1850 }
1851 DidFinishPrinting(OK); // Release resources and fail silently on failure.
1783 } 1852 }
1784 1853
1785 bool PrintWebViewHelper::RenderPagesForPrint(blink::WebLocalFrame* frame, 1854 bool PrintWebViewHelper::RenderPagesForPrint(blink::WebLocalFrame* frame,
1786 const blink::WebNode& node) { 1855 const blink::WebNode& node) {
1787 if (!frame || prep_frame_view_) 1856 if (!frame || prep_frame_view_)
1788 return false; 1857 return false;
1789 1858
1790 const PrintMsg_PrintPages_Params& params = *print_pages_params_; 1859 const PrintMsg_PrintPages_Params& params = *print_pages_params_;
1791 const PrintMsg_Print_Params& print_params = params.params; 1860 const PrintMsg_Print_Params& print_params = params.params;
1792 prep_frame_view_.reset(new PrepareFrameAndViewForPrint( 1861 prep_frame_view_.reset(new PrepareFrameAndViewForPrint(
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1936 // |is_modifiable| value until they are fully loaded, which occurs when 2005 // |is_modifiable| value until they are fully loaded, which occurs when
1937 // DidStopLoading() is called. Defer showing the preview until then. 2006 // DidStopLoading() is called. Defer showing the preview until then.
1938 on_stop_loading_closure_ = 2007 on_stop_loading_closure_ =
1939 base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview, 2008 base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview,
1940 base::Unretained(this)); 2009 base::Unretained(this));
1941 } else { 2010 } else {
1942 base::ThreadTaskRunnerHandle::Get()->PostTask( 2011 base::ThreadTaskRunnerHandle::Get()->PostTask(
1943 FROM_HERE, base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview, 2012 FROM_HERE, base::Bind(&PrintWebViewHelper::ShowScriptedPrintPreview,
1944 weak_ptr_factory_.GetWeakPtr())); 2013 weak_ptr_factory_.GetWeakPtr()));
1945 } 2014 }
1946 IPC::SyncMessage* msg = 2015 base::Closure done_callback =
1947 new PrintHostMsg_SetupScriptedPrintPreview(routing_id()); 2016 base::Bind(&PrintWebViewHelper::reset_scripted_preview_delayed,
1948 msg->EnableMessagePumping(); 2017 weak_ptr_factory_.GetWeakPtr());
1949 Send(msg); 2018 SendSetupScriptedPrintPreview(this, done_callback);
lfg 2016/11/24 05:25:47 Wouldn't it be simpler to do: auto ptr = weak_ptr
Lei Zhang 2016/11/24 07:46:34 Yes, thank you.
1950 is_scripted_preview_delayed_ = false; 2019 // WARNING: |this| may be gone at this point. Do not do any more work
2020 // here and just return. Put any work that needs to be done in
2021 // |done_callback| above.
1951 return; 2022 return;
1952 } 2023 }
1953 case PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME: { 2024 case PRINT_PREVIEW_USER_INITIATED_ENTIRE_FRAME: {
1954 // Wait for DidStopLoading. Continuing with this function while 2025 // Wait for DidStopLoading. Continuing with this function while
1955 // |is_loading_| is true will cause print preview to hang when try to 2026 // |is_loading_| is true will cause print preview to hang when try to
1956 // print a PDF document. 2027 // print a PDF document.
1957 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) { 2028 if (is_loading_ && GetPlugin(print_preview_context_.source_frame())) {
1958 on_stop_loading_closure_ = 2029 on_stop_loading_closure_ =
1959 base::Bind(&PrintWebViewHelper::RequestPrintPreview, 2030 base::Bind(&PrintWebViewHelper::RequestPrintPreview,
1960 base::Unretained(this), type); 2031 base::Unretained(this), type);
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
2317 blink::WebConsoleMessage::LevelWarning, message)); 2388 blink::WebConsoleMessage::LevelWarning, message));
2318 return false; 2389 return false;
2319 } 2390 }
2320 2391
2321 void PrintWebViewHelper::ScriptingThrottler::Reset() { 2392 void PrintWebViewHelper::ScriptingThrottler::Reset() {
2322 // Reset counter on successful print. 2393 // Reset counter on successful print.
2323 count_ = 0; 2394 count_ = 0;
2324 } 2395 }
2325 2396
2326 } // namespace printing 2397 } // namespace printing
OLDNEW
« no previous file with comments | « components/printing/renderer/print_web_view_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698