| 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 "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> |
| (...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 977 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { | 977 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { |
| 978 // The class is not designed to handle recursive messages. This is not | 978 // The class is not designed to handle recursive messages. This is not |
| 979 // expected during regular flow. However, during rendering of content for | 979 // expected during regular flow. However, during rendering of content for |
| 980 // printing, lower level code may run nested message loop. E.g. PDF may has | 980 // printing, lower level code may run nested message loop. E.g. PDF may has |
| 981 // script to show message box http://crbug.com/502562. In that moment browser | 981 // script to show message box http://crbug.com/502562. In that moment browser |
| 982 // may receive updated printer capabilities and decide to restart print | 982 // may receive updated printer capabilities and decide to restart print |
| 983 // preview generation. When this happened message handling function may | 983 // preview generation. When this happened message handling function may |
| 984 // choose to ignore message or safely crash process. | 984 // choose to ignore message or safely crash process. |
| 985 ++ipc_nesting_level_; | 985 ++ipc_nesting_level_; |
| 986 | 986 |
| 987 auto self = weak_ptr_factory_.GetWeakPtr(); |
| 988 |
| 987 bool handled = true; | 989 bool handled = true; |
| 988 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) | 990 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) |
| 989 #if BUILDFLAG(ENABLE_BASIC_PRINTING) | 991 #if BUILDFLAG(ENABLE_BASIC_PRINTING) |
| 990 IPC_MESSAGE_HANDLER(PrintMsg_PrintPages, OnPrintPages) | 992 IPC_MESSAGE_HANDLER(PrintMsg_PrintPages, OnPrintPages) |
| 991 IPC_MESSAGE_HANDLER(PrintMsg_PrintForSystemDialog, OnPrintForSystemDialog) | 993 IPC_MESSAGE_HANDLER(PrintMsg_PrintForSystemDialog, OnPrintForSystemDialog) |
| 992 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) | 994 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) |
| 993 #if BUILDFLAG(ENABLE_BASIC_PRINTING) && BUILDFLAG(ENABLE_PRINT_PREVIEW) | 995 #if BUILDFLAG(ENABLE_BASIC_PRINTING) && BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 994 IPC_MESSAGE_HANDLER(PrintMsg_PrintForPrintPreview, OnPrintForPrintPreview) | 996 IPC_MESSAGE_HANDLER(PrintMsg_PrintForPrintPreview, OnPrintForPrintPreview) |
| 995 #endif | 997 #endif |
| 996 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) | 998 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 997 IPC_MESSAGE_HANDLER(PrintMsg_InitiatePrintPreview, OnInitiatePrintPreview) | 999 IPC_MESSAGE_HANDLER(PrintMsg_InitiatePrintPreview, OnInitiatePrintPreview) |
| 998 IPC_MESSAGE_HANDLER(PrintMsg_PrintPreview, OnPrintPreview) | 1000 IPC_MESSAGE_HANDLER(PrintMsg_PrintPreview, OnPrintPreview) |
| 999 IPC_MESSAGE_HANDLER(PrintMsg_PrintingDone, OnPrintingDone) | 1001 IPC_MESSAGE_HANDLER(PrintMsg_PrintingDone, OnPrintingDone) |
| 1000 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) | 1002 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 1001 IPC_MESSAGE_HANDLER(PrintMsg_SetPrintingEnabled, OnSetPrintingEnabled) | 1003 IPC_MESSAGE_HANDLER(PrintMsg_SetPrintingEnabled, OnSetPrintingEnabled) |
| 1002 IPC_MESSAGE_UNHANDLED(handled = false) | 1004 IPC_MESSAGE_UNHANDLED(handled = false) |
| 1003 IPC_END_MESSAGE_MAP() | 1005 IPC_END_MESSAGE_MAP() |
| 1004 | 1006 |
| 1005 --ipc_nesting_level_; | 1007 // Check if |this| is still valid. e.g. when OnPrintPages() returns. |
| 1008 if (self) |
| 1009 --ipc_nesting_level_; |
| 1006 return handled; | 1010 return handled; |
| 1007 } | 1011 } |
| 1008 | 1012 |
| 1009 void PrintWebViewHelper::OnDestruct() { | 1013 void PrintWebViewHelper::OnDestruct() { |
| 1010 delete this; | 1014 delete this; |
| 1011 } | 1015 } |
| 1012 | 1016 |
| 1013 #if BUILDFLAG(ENABLE_BASIC_PRINTING) | 1017 #if BUILDFLAG(ENABLE_BASIC_PRINTING) |
| 1014 void PrintWebViewHelper::OnPrintPages() { | 1018 void PrintWebViewHelper::OnPrintPages() { |
| 1015 if (ipc_nesting_level_> 1) | 1019 if (ipc_nesting_level_> 1) |
| (...skipping 1322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2338 blink::WebConsoleMessage::LevelWarning, message)); | 2342 blink::WebConsoleMessage::LevelWarning, message)); |
| 2339 return false; | 2343 return false; |
| 2340 } | 2344 } |
| 2341 | 2345 |
| 2342 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2346 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
| 2343 // Reset counter on successful print. | 2347 // Reset counter on successful print. |
| 2344 count_ = 0; | 2348 count_ = 0; |
| 2345 } | 2349 } |
| 2346 | 2350 |
| 2347 } // namespace printing | 2351 } // namespace printing |
| OLD | NEW |