OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Provides a way to handle exceptions that happen while a WindowProc is | 5 // Provides a way to handle exceptions that happen while a WindowProc is |
6 // running. The behavior of exceptions generated inside a WindowProc is OS | 6 // running. The behavior of exceptions generated inside a WindowProc is OS |
7 // dependent, but it is possible that the OS just ignores the exception and | 7 // dependent, but it is possible that the OS just ignores the exception and |
8 // continues execution, which leads to unpredictable behavior for Chrome. | 8 // continues execution, which leads to unpredictable behavior for Chrome. |
9 | 9 |
10 #ifndef BASE_WIN_WRAPPED_WINDOW_PROC_H_ | 10 #ifndef BASE_WIN_WRAPPED_WINDOW_PROC_H_ |
11 #define BASE_WIN_WRAPPED_WINDOW_PROC_H_ | 11 #define BASE_WIN_WRAPPED_WINDOW_PROC_H_ |
12 #pragma once | 12 #pragma once |
13 | 13 |
14 #include <windows.h> | 14 #include <windows.h> |
15 | 15 |
| 16 #include "base/base_api.h" |
| 17 |
16 namespace base { | 18 namespace base { |
17 namespace win { | 19 namespace win { |
18 | 20 |
19 // An exception filter for a WindowProc. The return value determines how the | 21 // An exception filter for a WindowProc. The return value determines how the |
20 // exception should be handled, following standard SEH rules. However, the | 22 // exception should be handled, following standard SEH rules. However, the |
21 // expected behavior for this function is to not return, instead of returning | 23 // expected behavior for this function is to not return, instead of returning |
22 // EXCEPTION_EXECUTE_HANDLER or similar, given that in general we are not | 24 // EXCEPTION_EXECUTE_HANDLER or similar, given that in general we are not |
23 // prepared to handle exceptions. | 25 // prepared to handle exceptions. |
24 typedef int (__cdecl *WinProcExceptionFilter)(EXCEPTION_POINTERS* info); | 26 typedef int (__cdecl *WinProcExceptionFilter)(EXCEPTION_POINTERS* info); |
25 | 27 |
26 // Sets the filter to deal with exceptions inside a WindowProc. Returns the old | 28 // Sets the filter to deal with exceptions inside a WindowProc. Returns the old |
27 // exception filter, if any. | 29 // exception filter, if any. |
28 // This function should be called before any window is created. | 30 // This function should be called before any window is created. |
29 WinProcExceptionFilter SetWinProcExceptionFilter(WinProcExceptionFilter filter); | 31 BASE_API WinProcExceptionFilter SetWinProcExceptionFilter( |
| 32 WinProcExceptionFilter filter); |
30 | 33 |
31 // Calls the registered exception filter. | 34 // Calls the registered exception filter. |
32 int CallExceptionFilter(EXCEPTION_POINTERS* info); | 35 BASE_API int CallExceptionFilter(EXCEPTION_POINTERS* info); |
33 | 36 |
34 // Wrapper that supplies a standard exception frame for the provided WindowProc. | 37 // Wrapper that supplies a standard exception frame for the provided WindowProc. |
35 // The normal usage is something like this: | 38 // The normal usage is something like this: |
36 // | 39 // |
37 // LRESULT CALLBACK MyWinProc(HWND hwnd, UINT message, | 40 // LRESULT CALLBACK MyWinProc(HWND hwnd, UINT message, |
38 // WPARAM wparam, LPARAM lparam) { | 41 // WPARAM wparam, LPARAM lparam) { |
39 // // Do Something. | 42 // // Do Something. |
40 // } | 43 // } |
41 // | 44 // |
42 // ... | 45 // ... |
(...skipping 14 matching lines...) Expand all Loading... |
57 rv = proc(hwnd, message, wparam, lparam); | 60 rv = proc(hwnd, message, wparam, lparam); |
58 } __except(CallExceptionFilter(GetExceptionInformation())) { | 61 } __except(CallExceptionFilter(GetExceptionInformation())) { |
59 } | 62 } |
60 return rv; | 63 return rv; |
61 } | 64 } |
62 | 65 |
63 } // namespace win | 66 } // namespace win |
64 } // namespace base | 67 } // namespace base |
65 | 68 |
66 #endif // BASE_WIN_WRAPPED_WINDOW_PROC_H_ | 69 #endif // BASE_WIN_WRAPPED_WINDOW_PROC_H_ |
OLD | NEW |