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

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

Issue 1228693002: Crash on nested IPC handlers in PrintWebViewHelper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months 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 <string> 7 #include <string>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 reset_prep_frame_view_(false), 808 reset_prep_frame_view_(false),
809 is_print_ready_metafile_sent_(false), 809 is_print_ready_metafile_sent_(false),
810 ignore_css_margins_(false), 810 ignore_css_margins_(false),
811 is_scripted_printing_blocked_(false), 811 is_scripted_printing_blocked_(false),
812 notify_browser_of_print_failure_(true), 812 notify_browser_of_print_failure_(true),
813 print_for_preview_(false), 813 print_for_preview_(false),
814 delegate_(delegate.Pass()), 814 delegate_(delegate.Pass()),
815 print_node_in_progress_(false), 815 print_node_in_progress_(false),
816 is_loading_(false), 816 is_loading_(false),
817 is_scripted_preview_delayed_(false), 817 is_scripted_preview_delayed_(false),
818 ipc_nesting_level_(0),
818 weak_ptr_factory_(this) { 819 weak_ptr_factory_(this) {
819 if (!delegate_->IsPrintPreviewEnabled()) 820 if (!delegate_->IsPrintPreviewEnabled())
820 DisablePreview(); 821 DisablePreview();
821 } 822 }
822 823
823 PrintWebViewHelper::~PrintWebViewHelper() { 824 PrintWebViewHelper::~PrintWebViewHelper() {
824 } 825 }
825 826
826 // static 827 // static
827 void PrintWebViewHelper::DisablePreview() { 828 void PrintWebViewHelper::DisablePreview() {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 872
872 if (!g_is_preview_enabled_) { 873 if (!g_is_preview_enabled_) {
873 Print(frame, blink::WebNode(), true); 874 Print(frame, blink::WebNode(), true);
874 } else { 875 } else {
875 print_preview_context_.InitWithFrame(frame); 876 print_preview_context_.InitWithFrame(frame);
876 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); 877 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED);
877 } 878 }
878 } 879 }
879 880
880 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { 881 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) {
882 // The class is not designed to handle recursive messages. This is not
883 // expected during regular flow. However, during rendering of content for
884 // printing, lower level code may run nested message loop. E.g. PDF may has
885 // script to show message box http://crbug.com/502562. In that moment browser
Vitaly Buka (NO REVIEWS) 2015/07/09 05:54:33 Added explanation.
886 // may receive updated printer capabilities and decide to restart print
887 // preview generation.
888 // When this happened message handling function may choose to ignore message
889 // or safely crash process.
890 ++ipc_nesting_level_;
891
881 bool handled = true; 892 bool handled = true;
882 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) 893 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message)
883 #if defined(ENABLE_BASIC_PRINTING) 894 #if defined(ENABLE_BASIC_PRINTING)
884 IPC_MESSAGE_HANDLER(PrintMsg_PrintPages, OnPrintPages) 895 IPC_MESSAGE_HANDLER(PrintMsg_PrintPages, OnPrintPages)
885 IPC_MESSAGE_HANDLER(PrintMsg_PrintForSystemDialog, OnPrintForSystemDialog) 896 IPC_MESSAGE_HANDLER(PrintMsg_PrintForSystemDialog, OnPrintForSystemDialog)
886 #endif // ENABLE_BASIC_PRINTING 897 #endif // ENABLE_BASIC_PRINTING
887 IPC_MESSAGE_HANDLER(PrintMsg_InitiatePrintPreview, OnInitiatePrintPreview) 898 IPC_MESSAGE_HANDLER(PrintMsg_InitiatePrintPreview, OnInitiatePrintPreview)
888 IPC_MESSAGE_HANDLER(PrintMsg_PrintPreview, OnPrintPreview) 899 IPC_MESSAGE_HANDLER(PrintMsg_PrintPreview, OnPrintPreview)
889 IPC_MESSAGE_HANDLER(PrintMsg_PrintForPrintPreview, OnPrintForPrintPreview) 900 IPC_MESSAGE_HANDLER(PrintMsg_PrintForPrintPreview, OnPrintForPrintPreview)
890 IPC_MESSAGE_HANDLER(PrintMsg_PrintingDone, OnPrintingDone) 901 IPC_MESSAGE_HANDLER(PrintMsg_PrintingDone, OnPrintingDone)
891 IPC_MESSAGE_HANDLER(PrintMsg_SetScriptedPrintingBlocked, 902 IPC_MESSAGE_HANDLER(PrintMsg_SetScriptedPrintingBlocked,
892 SetScriptedPrintBlocked) 903 SetScriptedPrintBlocked)
893 IPC_MESSAGE_UNHANDLED(handled = false) 904 IPC_MESSAGE_UNHANDLED(handled = false)
894 IPC_END_MESSAGE_MAP() 905 IPC_END_MESSAGE_MAP()
906
907 --ipc_nesting_level_;
895 return handled; 908 return handled;
896 } 909 }
897 910
898 void PrintWebViewHelper::OnPrintForPrintPreview( 911 void PrintWebViewHelper::OnPrintForPrintPreview(
899 const base::DictionaryValue& job_settings) { 912 const base::DictionaryValue& job_settings) {
913 CHECK_LE(ipc_nesting_level_, 1);
900 // If still not finished with earlier print request simply ignore. 914 // If still not finished with earlier print request simply ignore.
901 if (prep_frame_view_) 915 if (prep_frame_view_)
902 return; 916 return;
903 917
904 if (!render_view()->GetWebView()) 918 if (!render_view()->GetWebView())
905 return; 919 return;
906 blink::WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); 920 blink::WebFrame* main_frame = render_view()->GetWebView()->mainFrame();
907 if (!main_frame) 921 if (!main_frame)
908 return; 922 return;
909 923
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 blink::WebLocalFrame* focusedFrame = 985 blink::WebLocalFrame* focusedFrame =
972 webView->focusedFrame()->toWebLocalFrame(); 986 webView->focusedFrame()->toWebLocalFrame();
973 *frame = focusedFrame->hasSelection() 987 *frame = focusedFrame->hasSelection()
974 ? focusedFrame 988 ? focusedFrame
975 : webView->mainFrame()->toWebLocalFrame(); 989 : webView->mainFrame()->toWebLocalFrame();
976 return true; 990 return true;
977 } 991 }
978 992
979 #if defined(ENABLE_BASIC_PRINTING) 993 #if defined(ENABLE_BASIC_PRINTING)
980 void PrintWebViewHelper::OnPrintPages() { 994 void PrintWebViewHelper::OnPrintPages() {
995 CHECK_LE(ipc_nesting_level_, 1);
981 blink::WebLocalFrame* frame; 996 blink::WebLocalFrame* frame;
982 if (!GetPrintFrame(&frame)) 997 if (!GetPrintFrame(&frame))
983 return; 998 return;
984 // If we are printing a PDF extension frame, find the plugin node and print 999 // If we are printing a PDF extension frame, find the plugin node and print
985 // that instead. 1000 // that instead.
986 auto plugin = delegate_->GetPdfElement(frame); 1001 auto plugin = delegate_->GetPdfElement(frame);
987 Print(frame, plugin, false); 1002 Print(frame, plugin, false);
988 } 1003 }
989 1004
990 void PrintWebViewHelper::OnPrintForSystemDialog() { 1005 void PrintWebViewHelper::OnPrintForSystemDialog() {
1006 CHECK_LE(ipc_nesting_level_, 1);
991 blink::WebLocalFrame* frame = print_preview_context_.source_frame(); 1007 blink::WebLocalFrame* frame = print_preview_context_.source_frame();
992 if (!frame) { 1008 if (!frame) {
993 NOTREACHED(); 1009 NOTREACHED();
994 return; 1010 return;
995 } 1011 }
996 Print(frame, print_preview_context_.source_node(), false); 1012 Print(frame, print_preview_context_.source_node(), false);
997 } 1013 }
998 #endif // ENABLE_BASIC_PRINTING 1014 #endif // ENABLE_BASIC_PRINTING
999 1015
1000 void PrintWebViewHelper::GetPageSizeAndContentAreaFromPageLayout( 1016 void PrintWebViewHelper::GetPageSizeAndContentAreaFromPageLayout(
(...skipping 21 matching lines...) Expand all
1022 1038
1023 bool PrintWebViewHelper::IsPrintToPdfRequested( 1039 bool PrintWebViewHelper::IsPrintToPdfRequested(
1024 const base::DictionaryValue& job_settings) { 1040 const base::DictionaryValue& job_settings) {
1025 bool print_to_pdf = false; 1041 bool print_to_pdf = false;
1026 if (!job_settings.GetBoolean(kSettingPrintToPDF, &print_to_pdf)) 1042 if (!job_settings.GetBoolean(kSettingPrintToPDF, &print_to_pdf))
1027 NOTREACHED(); 1043 NOTREACHED();
1028 return print_to_pdf; 1044 return print_to_pdf;
1029 } 1045 }
1030 1046
1031 void PrintWebViewHelper::OnPrintPreview(const base::DictionaryValue& settings) { 1047 void PrintWebViewHelper::OnPrintPreview(const base::DictionaryValue& settings) {
1048 CHECK_LE(ipc_nesting_level_, 1);
1049
1032 print_preview_context_.OnPrintPreview(); 1050 print_preview_context_.OnPrintPreview();
1033 1051
1034 UMA_HISTOGRAM_ENUMERATION("PrintPreview.PreviewEvent", 1052 UMA_HISTOGRAM_ENUMERATION("PrintPreview.PreviewEvent",
1035 PREVIEW_EVENT_REQUESTED, PREVIEW_EVENT_MAX); 1053 PREVIEW_EVENT_REQUESTED, PREVIEW_EVENT_MAX);
1036 1054
1037 if (!print_preview_context_.source_frame()) { 1055 if (!print_preview_context_.source_frame()) {
1038 DidFinishPrinting(FAIL_PREVIEW); 1056 DidFinishPrinting(FAIL_PREVIEW);
1039 return; 1057 return;
1040 } 1058 }
1041 1059
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 print_preview_context_.set_error(PREVIEW_ERROR_METAFILE_COPY_FAILED); 1228 print_preview_context_.set_error(PREVIEW_ERROR_METAFILE_COPY_FAILED);
1211 return false; 1229 return false;
1212 } 1230 }
1213 is_print_ready_metafile_sent_ = true; 1231 is_print_ready_metafile_sent_ = true;
1214 1232
1215 Send(new PrintHostMsg_MetafileReadyForPrinting(routing_id(), preview_params)); 1233 Send(new PrintHostMsg_MetafileReadyForPrinting(routing_id(), preview_params));
1216 return true; 1234 return true;
1217 } 1235 }
1218 1236
1219 void PrintWebViewHelper::OnPrintingDone(bool success) { 1237 void PrintWebViewHelper::OnPrintingDone(bool success) {
1238 CHECK_LE(ipc_nesting_level_, 1);
1220 notify_browser_of_print_failure_ = false; 1239 notify_browser_of_print_failure_ = false;
1221 if (!success) 1240 if (!success)
1222 LOG(ERROR) << "Failure in OnPrintingDone"; 1241 LOG(ERROR) << "Failure in OnPrintingDone";
1223 DidFinishPrinting(success ? OK : FAIL_PRINT); 1242 DidFinishPrinting(success ? OK : FAIL_PRINT);
1224 } 1243 }
1225 1244
1226 void PrintWebViewHelper::SetScriptedPrintBlocked(bool blocked) { 1245 void PrintWebViewHelper::SetScriptedPrintBlocked(bool blocked) {
1227 is_scripted_printing_blocked_ = blocked; 1246 is_scripted_printing_blocked_ = blocked;
1228 } 1247 }
1229 1248
1230 void PrintWebViewHelper::OnInitiatePrintPreview(bool selection_only) { 1249 void PrintWebViewHelper::OnInitiatePrintPreview(bool selection_only) {
1250 CHECK_LE(ipc_nesting_level_, 1);
1231 blink::WebLocalFrame* frame = NULL; 1251 blink::WebLocalFrame* frame = NULL;
1232 GetPrintFrame(&frame); 1252 GetPrintFrame(&frame);
1233 DCHECK(frame); 1253 DCHECK(frame);
1234 // If we are printing a PDF extension frame, find the plugin node and print 1254 // If we are printing a PDF extension frame, find the plugin node and print
1235 // that instead. 1255 // that instead.
1236 auto plugin = delegate_->GetPdfElement(frame); 1256 auto plugin = delegate_->GetPdfElement(frame);
1237 if (!plugin.isNull()) { 1257 if (!plugin.isNull()) {
1238 PrintNode(plugin); 1258 PrintNode(plugin);
1239 return; 1259 return;
1240 } 1260 }
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after
2078 blink::WebConsoleMessage::LevelWarning, message)); 2098 blink::WebConsoleMessage::LevelWarning, message));
2079 return false; 2099 return false;
2080 } 2100 }
2081 2101
2082 void PrintWebViewHelper::ScriptingThrottler::Reset() { 2102 void PrintWebViewHelper::ScriptingThrottler::Reset() {
2083 // Reset counter on successful print. 2103 // Reset counter on successful print.
2084 count_ = 0; 2104 count_ = 0;
2085 } 2105 }
2086 2106
2087 } // namespace printing 2107 } // 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