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

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
886 // may receive updated printer capabilities and decide to restart print
887 // preview generation. When this happened message handling function may
888 // choose to ignore message or safely crash process.
889 ++ipc_nesting_level_;
890
881 bool handled = true; 891 bool handled = true;
882 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) 892 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message)
883 #if defined(ENABLE_BASIC_PRINTING) 893 #if defined(ENABLE_BASIC_PRINTING)
884 IPC_MESSAGE_HANDLER(PrintMsg_PrintPages, OnPrintPages) 894 IPC_MESSAGE_HANDLER(PrintMsg_PrintPages, OnPrintPages)
885 IPC_MESSAGE_HANDLER(PrintMsg_PrintForSystemDialog, OnPrintForSystemDialog) 895 IPC_MESSAGE_HANDLER(PrintMsg_PrintForSystemDialog, OnPrintForSystemDialog)
886 #endif // ENABLE_BASIC_PRINTING 896 #endif // ENABLE_BASIC_PRINTING
887 IPC_MESSAGE_HANDLER(PrintMsg_InitiatePrintPreview, OnInitiatePrintPreview) 897 IPC_MESSAGE_HANDLER(PrintMsg_InitiatePrintPreview, OnInitiatePrintPreview)
888 IPC_MESSAGE_HANDLER(PrintMsg_PrintPreview, OnPrintPreview) 898 IPC_MESSAGE_HANDLER(PrintMsg_PrintPreview, OnPrintPreview)
889 IPC_MESSAGE_HANDLER(PrintMsg_PrintForPrintPreview, OnPrintForPrintPreview) 899 IPC_MESSAGE_HANDLER(PrintMsg_PrintForPrintPreview, OnPrintForPrintPreview)
890 IPC_MESSAGE_HANDLER(PrintMsg_PrintingDone, OnPrintingDone) 900 IPC_MESSAGE_HANDLER(PrintMsg_PrintingDone, OnPrintingDone)
891 IPC_MESSAGE_HANDLER(PrintMsg_SetScriptedPrintingBlocked, 901 IPC_MESSAGE_HANDLER(PrintMsg_SetScriptedPrintingBlocked,
892 SetScriptedPrintBlocked) 902 SetScriptedPrintBlocked)
893 IPC_MESSAGE_UNHANDLED(handled = false) 903 IPC_MESSAGE_UNHANDLED(handled = false)
894 IPC_END_MESSAGE_MAP() 904 IPC_END_MESSAGE_MAP()
905
906 --ipc_nesting_level_;
895 return handled; 907 return handled;
896 } 908 }
897 909
898 void PrintWebViewHelper::OnPrintForPrintPreview( 910 void PrintWebViewHelper::OnPrintForPrintPreview(
899 const base::DictionaryValue& job_settings) { 911 const base::DictionaryValue& job_settings) {
912 CHECK_LE(ipc_nesting_level_, 1);
900 // If still not finished with earlier print request simply ignore. 913 // If still not finished with earlier print request simply ignore.
901 if (prep_frame_view_) 914 if (prep_frame_view_)
902 return; 915 return;
903 916
904 if (!render_view()->GetWebView()) 917 if (!render_view()->GetWebView())
905 return; 918 return;
906 blink::WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); 919 blink::WebFrame* main_frame = render_view()->GetWebView()->mainFrame();
907 if (!main_frame) 920 if (!main_frame)
908 return; 921 return;
909 922
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 blink::WebLocalFrame* focusedFrame = 984 blink::WebLocalFrame* focusedFrame =
972 webView->focusedFrame()->toWebLocalFrame(); 985 webView->focusedFrame()->toWebLocalFrame();
973 *frame = focusedFrame->hasSelection() 986 *frame = focusedFrame->hasSelection()
974 ? focusedFrame 987 ? focusedFrame
975 : webView->mainFrame()->toWebLocalFrame(); 988 : webView->mainFrame()->toWebLocalFrame();
976 return true; 989 return true;
977 } 990 }
978 991
979 #if defined(ENABLE_BASIC_PRINTING) 992 #if defined(ENABLE_BASIC_PRINTING)
980 void PrintWebViewHelper::OnPrintPages() { 993 void PrintWebViewHelper::OnPrintPages() {
994 CHECK_LE(ipc_nesting_level_, 1);
981 blink::WebLocalFrame* frame; 995 blink::WebLocalFrame* frame;
982 if (!GetPrintFrame(&frame)) 996 if (!GetPrintFrame(&frame))
983 return; 997 return;
984 // If we are printing a PDF extension frame, find the plugin node and print 998 // If we are printing a PDF extension frame, find the plugin node and print
985 // that instead. 999 // that instead.
986 auto plugin = delegate_->GetPdfElement(frame); 1000 auto plugin = delegate_->GetPdfElement(frame);
987 Print(frame, plugin, false); 1001 Print(frame, plugin, false);
988 } 1002 }
989 1003
990 void PrintWebViewHelper::OnPrintForSystemDialog() { 1004 void PrintWebViewHelper::OnPrintForSystemDialog() {
1005 CHECK_LE(ipc_nesting_level_, 1);
991 blink::WebLocalFrame* frame = print_preview_context_.source_frame(); 1006 blink::WebLocalFrame* frame = print_preview_context_.source_frame();
992 if (!frame) { 1007 if (!frame) {
993 NOTREACHED(); 1008 NOTREACHED();
994 return; 1009 return;
995 } 1010 }
996 Print(frame, print_preview_context_.source_node(), false); 1011 Print(frame, print_preview_context_.source_node(), false);
997 } 1012 }
998 #endif // ENABLE_BASIC_PRINTING 1013 #endif // ENABLE_BASIC_PRINTING
999 1014
1000 void PrintWebViewHelper::GetPageSizeAndContentAreaFromPageLayout( 1015 void PrintWebViewHelper::GetPageSizeAndContentAreaFromPageLayout(
(...skipping 21 matching lines...) Expand all
1022 1037
1023 bool PrintWebViewHelper::IsPrintToPdfRequested( 1038 bool PrintWebViewHelper::IsPrintToPdfRequested(
1024 const base::DictionaryValue& job_settings) { 1039 const base::DictionaryValue& job_settings) {
1025 bool print_to_pdf = false; 1040 bool print_to_pdf = false;
1026 if (!job_settings.GetBoolean(kSettingPrintToPDF, &print_to_pdf)) 1041 if (!job_settings.GetBoolean(kSettingPrintToPDF, &print_to_pdf))
1027 NOTREACHED(); 1042 NOTREACHED();
1028 return print_to_pdf; 1043 return print_to_pdf;
1029 } 1044 }
1030 1045
1031 void PrintWebViewHelper::OnPrintPreview(const base::DictionaryValue& settings) { 1046 void PrintWebViewHelper::OnPrintPreview(const base::DictionaryValue& settings) {
1047 CHECK_LE(ipc_nesting_level_, 1);
1048
1032 print_preview_context_.OnPrintPreview(); 1049 print_preview_context_.OnPrintPreview();
1033 1050
1034 UMA_HISTOGRAM_ENUMERATION("PrintPreview.PreviewEvent", 1051 UMA_HISTOGRAM_ENUMERATION("PrintPreview.PreviewEvent",
1035 PREVIEW_EVENT_REQUESTED, PREVIEW_EVENT_MAX); 1052 PREVIEW_EVENT_REQUESTED, PREVIEW_EVENT_MAX);
1036 1053
1037 if (!print_preview_context_.source_frame()) { 1054 if (!print_preview_context_.source_frame()) {
1038 DidFinishPrinting(FAIL_PREVIEW); 1055 DidFinishPrinting(FAIL_PREVIEW);
1039 return; 1056 return;
1040 } 1057 }
1041 1058
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 print_preview_context_.set_error(PREVIEW_ERROR_METAFILE_COPY_FAILED); 1227 print_preview_context_.set_error(PREVIEW_ERROR_METAFILE_COPY_FAILED);
1211 return false; 1228 return false;
1212 } 1229 }
1213 is_print_ready_metafile_sent_ = true; 1230 is_print_ready_metafile_sent_ = true;
1214 1231
1215 Send(new PrintHostMsg_MetafileReadyForPrinting(routing_id(), preview_params)); 1232 Send(new PrintHostMsg_MetafileReadyForPrinting(routing_id(), preview_params));
1216 return true; 1233 return true;
1217 } 1234 }
1218 1235
1219 void PrintWebViewHelper::OnPrintingDone(bool success) { 1236 void PrintWebViewHelper::OnPrintingDone(bool success) {
1237 CHECK_LE(ipc_nesting_level_, 1);
1220 notify_browser_of_print_failure_ = false; 1238 notify_browser_of_print_failure_ = false;
1221 if (!success) 1239 if (!success)
1222 LOG(ERROR) << "Failure in OnPrintingDone"; 1240 LOG(ERROR) << "Failure in OnPrintingDone";
1223 DidFinishPrinting(success ? OK : FAIL_PRINT); 1241 DidFinishPrinting(success ? OK : FAIL_PRINT);
1224 } 1242 }
1225 1243
1226 void PrintWebViewHelper::SetScriptedPrintBlocked(bool blocked) { 1244 void PrintWebViewHelper::SetScriptedPrintBlocked(bool blocked) {
1227 is_scripted_printing_blocked_ = blocked; 1245 is_scripted_printing_blocked_ = blocked;
1228 } 1246 }
1229 1247
1230 void PrintWebViewHelper::OnInitiatePrintPreview(bool selection_only) { 1248 void PrintWebViewHelper::OnInitiatePrintPreview(bool selection_only) {
1249 CHECK_LE(ipc_nesting_level_, 1);
1231 blink::WebLocalFrame* frame = NULL; 1250 blink::WebLocalFrame* frame = NULL;
1232 GetPrintFrame(&frame); 1251 GetPrintFrame(&frame);
1233 DCHECK(frame); 1252 DCHECK(frame);
1234 // If we are printing a PDF extension frame, find the plugin node and print 1253 // If we are printing a PDF extension frame, find the plugin node and print
1235 // that instead. 1254 // that instead.
1236 auto plugin = delegate_->GetPdfElement(frame); 1255 auto plugin = delegate_->GetPdfElement(frame);
1237 if (!plugin.isNull()) { 1256 if (!plugin.isNull()) {
1238 PrintNode(plugin); 1257 PrintNode(plugin);
1239 return; 1258 return;
1240 } 1259 }
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after
2078 blink::WebConsoleMessage::LevelWarning, message)); 2097 blink::WebConsoleMessage::LevelWarning, message));
2079 return false; 2098 return false;
2080 } 2099 }
2081 2100
2082 void PrintWebViewHelper::ScriptingThrottler::Reset() { 2101 void PrintWebViewHelper::ScriptingThrottler::Reset() {
2083 // Reset counter on successful print. 2102 // Reset counter on successful print.
2084 count_ = 0; 2103 count_ = 0;
2085 } 2104 }
2086 2105
2087 } // namespace printing 2106 } // 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