| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef CHROME_FRAME_TEST_WIN_EVENT_RECEIVER_H_ | 5 #ifndef CHROME_FRAME_TEST_WIN_EVENT_RECEIVER_H_ |
| 6 #define CHROME_FRAME_TEST_WIN_EVENT_RECEIVER_H_ | 6 #define CHROME_FRAME_TEST_WIN_EVENT_RECEIVER_H_ |
| 7 | 7 |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 #include <utility> | 12 #include <utility> |
| 13 | 13 |
| 14 #include "base/linked_ptr.h" | 14 #include "base/linked_ptr.h" |
| 15 #include "base/object_watcher.h" | 15 #include "base/win/object_watcher.h" |
| 16 | 16 |
| 17 struct FunctionStub; | 17 struct FunctionStub; |
| 18 | 18 |
| 19 // Listens to WinEvents from the WinEventReceiver. | 19 // Listens to WinEvents from the WinEventReceiver. |
| 20 class WinEventListener { | 20 class WinEventListener { |
| 21 public: | 21 public: |
| 22 virtual ~WinEventListener() {} | 22 virtual ~WinEventListener() {} |
| 23 // Called when an event has been received. |hwnd| is the window that generated | 23 // Called when an event has been received. |hwnd| is the window that generated |
| 24 // the event, or null if no window is associated with the event. | 24 // the event, or null if no window is associated with the event. |
| 25 virtual void OnEventReceived(DWORD event, HWND hwnd, LONG object_id, | 25 virtual void OnEventReceived(DWORD event, HWND hwnd, LONG object_id, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 // Remove all registrations of |observer|. The |observer| will not be notified | 99 // Remove all registrations of |observer|. The |observer| will not be notified |
| 100 // during or after this call. | 100 // during or after this call. |
| 101 void RemoveObserver(WindowObserver* observer); | 101 void RemoveObserver(WindowObserver* observer); |
| 102 | 102 |
| 103 private: | 103 private: |
| 104 class ProcessExitObserver; | 104 class ProcessExitObserver; |
| 105 | 105 |
| 106 // The Delegate object is actually a ProcessExitObserver, but declaring | 106 // The Delegate object is actually a ProcessExitObserver, but declaring |
| 107 // it as such would require fully declaring the ProcessExitObserver class | 107 // it as such would require fully declaring the ProcessExitObserver class |
| 108 // here in order for linked_ptr to access its destructor. | 108 // here in order for linked_ptr to access its destructor. |
| 109 typedef std::pair<HWND, linked_ptr<base::ObjectWatcher::Delegate> > | 109 typedef std::pair<HWND, linked_ptr<base::win::ObjectWatcher::Delegate> > |
| 110 OpenWindowEntry; | 110 OpenWindowEntry; |
| 111 typedef std::vector<OpenWindowEntry> OpenWindowList; | 111 typedef std::vector<OpenWindowEntry> OpenWindowList; |
| 112 | 112 |
| 113 struct ObserverEntry { | 113 struct ObserverEntry { |
| 114 WindowObserver* observer; | 114 WindowObserver* observer; |
| 115 std::string caption_pattern; | 115 std::string caption_pattern; |
| 116 std::string class_name_pattern; | 116 std::string class_name_pattern; |
| 117 OpenWindowList open_windows; | 117 OpenWindowList open_windows; |
| 118 }; | 118 }; |
| 119 | 119 |
| 120 typedef std::vector<ObserverEntry> ObserverEntryList; | 120 typedef std::vector<ObserverEntry> ObserverEntryList; |
| 121 | 121 |
| 122 // WinEventListener implementation. | 122 // WinEventListener implementation. |
| 123 virtual void OnEventReceived( | 123 virtual void OnEventReceived( |
| 124 DWORD event, HWND hwnd, LONG object_id, LONG child_id); | 124 DWORD event, HWND hwnd, LONG object_id, LONG child_id); |
| 125 | 125 |
| 126 static std::string GetWindowCaption(HWND hwnd); | 126 static std::string GetWindowCaption(HWND hwnd); |
| 127 | 127 |
| 128 void HandleOnOpen(HWND hwnd); | 128 void HandleOnOpen(HWND hwnd); |
| 129 void HandleOnClose(HWND hwnd); | 129 void HandleOnClose(HWND hwnd); |
| 130 void OnHwndProcessExited(HWND hwnd); | 130 void OnHwndProcessExited(HWND hwnd); |
| 131 | 131 |
| 132 // Returns true if the caption pattern and/or the class name pattern in the | 132 // Returns true if the caption pattern and/or the class name pattern in the |
| 133 // observer entry structure matches the caption and/or class name passed in. | 133 // observer entry structure matches the caption and/or class name passed in. |
| 134 bool MatchingWindow(const ObserverEntry& entry, | 134 bool MatchingWindow(const ObserverEntry& entry, |
| 135 const std::string& caption, | 135 const std::string& caption, |
| 136 const std::string& class_name); | 136 const std::string& class_name); |
| 137 | 137 |
| 138 ObserverEntryList observers_; | 138 ObserverEntryList observers_; |
| 139 WinEventReceiver win_event_receiver_; | 139 WinEventReceiver win_event_receiver_; |
| 140 | 140 |
| 141 DISALLOW_COPY_AND_ASSIGN(WindowWatchdog); | 141 DISALLOW_COPY_AND_ASSIGN(WindowWatchdog); |
| 142 }; | 142 }; |
| 143 | 143 |
| 144 | 144 |
| 145 | 145 |
| 146 #endif // CHROME_FRAME_TEST_WIN_EVENT_RECEIVER_H_ | 146 #endif // CHROME_FRAME_TEST_WIN_EVENT_RECEIVER_H_ |
| OLD | NEW |