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 #ifndef BASE_MESSAGE_PUMP_WIN_H_ | 5 #ifndef BASE_MESSAGE_PUMP_WIN_H_ |
6 #define BASE_MESSAGE_PUMP_WIN_H_ | 6 #define BASE_MESSAGE_PUMP_WIN_H_ |
7 | 7 |
8 #include <windows.h> | 8 #include <windows.h> |
9 | 9 |
10 #include <list> | 10 #include <list> |
11 | 11 |
12 #include "base/base_export.h" | 12 #include "base/base_export.h" |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/memory/scoped_ptr.h" |
14 #include "base/message_pump.h" | 15 #include "base/message_pump.h" |
15 #include "base/message_pump_dispatcher.h" | 16 #include "base/message_pump_dispatcher.h" |
16 #include "base/message_pump_observer.h" | 17 #include "base/message_pump_observer.h" |
17 #include "base/observer_list.h" | 18 #include "base/observer_list.h" |
18 #include "base/time.h" | 19 #include "base/time.h" |
19 #include "base/win/scoped_handle.h" | 20 #include "base/win/scoped_handle.h" |
20 | 21 |
21 namespace base { | 22 namespace base { |
22 | 23 |
23 // MessagePumpWin serves as the base for specialized versions of the MessagePump | 24 // MessagePumpWin serves as the base for specialized versions of the MessagePump |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 // is peeked, and before a replacement kMsgHaveWork is posted). | 120 // is peeked, and before a replacement kMsgHaveWork is posted). |
120 // | 121 // |
121 // NOTE: Although it may seem odd that messages are used to start and stop this | 122 // NOTE: Although it may seem odd that messages are used to start and stop this |
122 // flow (as opposed to signaling objects, etc.), it should be understood that | 123 // flow (as opposed to signaling objects, etc.), it should be understood that |
123 // the native message pump will *only* respond to messages. As a result, it is | 124 // the native message pump will *only* respond to messages. As a result, it is |
124 // an excellent choice. It is also helpful that the starter messages that are | 125 // an excellent choice. It is also helpful that the starter messages that are |
125 // placed in the queue when new task arrive also awakens DoRunLoop. | 126 // placed in the queue when new task arrive also awakens DoRunLoop. |
126 // | 127 // |
127 class BASE_EXPORT MessagePumpForUI : public MessagePumpWin { | 128 class BASE_EXPORT MessagePumpForUI : public MessagePumpWin { |
128 public: | 129 public: |
| 130 // A MessageFilter implements the common Peek/Translate/Dispatch code to deal |
| 131 // with windows messages. |
| 132 // This abstraction is used to inject TSF message peeking. See |
| 133 // TextServicesMessageFilter. |
| 134 class BASE_EXPORT MessageFilter { |
| 135 public: |
| 136 virtual ~MessageFilter() {} |
| 137 // Implements the functionality exposed by the OS through PeekMessage. |
| 138 virtual BOOL DoPeekMessage(MSG* msg, |
| 139 HWND window_handle, |
| 140 UINT msg_filter_min, |
| 141 UINT msg_filter_max, |
| 142 UINT remove_msg) { |
| 143 return PeekMessage(msg, window_handle, msg_filter_min, msg_filter_max, |
| 144 remove_msg); |
| 145 } |
| 146 // Returns true if |message| was consumed by the filter and no extra |
| 147 // processing is required. If this method returns false, it is the |
| 148 // responsibility of the caller to ensure that normal processing takes |
| 149 // place. |
| 150 // The priority to consume messages is the following: |
| 151 // - Native Windows' message filter (CallMsgFilter). |
| 152 // - MessageFilter::ProcessMessage. |
| 153 // - MessagePumpDispatcher. |
| 154 // - TranslateMessage / DispatchMessage. |
| 155 virtual bool ProcessMessage(const MSG& msg) { return false;} |
| 156 }; |
129 // The application-defined code passed to the hook procedure. | 157 // The application-defined code passed to the hook procedure. |
130 static const int kMessageFilterCode = 0x5001; | 158 static const int kMessageFilterCode = 0x5001; |
131 | 159 |
132 MessagePumpForUI(); | 160 MessagePumpForUI(); |
133 virtual ~MessagePumpForUI(); | 161 virtual ~MessagePumpForUI(); |
134 | 162 |
| 163 // Sets a new MessageFilter. MessagePumpForUI takes ownership of |
| 164 // |message_filter|. When SetMessageFilter is called, old MessageFilter is |
| 165 // deleted. |
| 166 void SetMessageFilter(scoped_ptr<MessageFilter> message_filter); |
| 167 |
135 // MessagePump methods: | 168 // MessagePump methods: |
136 virtual void ScheduleWork(); | 169 virtual void ScheduleWork(); |
137 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time); | 170 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time); |
138 | 171 |
139 // Applications can call this to encourage us to process all pending WM_PAINT | 172 // Applications can call this to encourage us to process all pending WM_PAINT |
140 // messages. This method will process all paint messages the Windows Message | 173 // messages. This method will process all paint messages the Windows Message |
141 // queue can provide, up to some fixed number (to avoid any infinite loops). | 174 // queue can provide, up to some fixed number (to avoid any infinite loops). |
142 void PumpOutPendingPaintMessages(); | 175 void PumpOutPendingPaintMessages(); |
143 | 176 |
144 private: | 177 private: |
145 static LRESULT CALLBACK WndProcThunk( | 178 static LRESULT CALLBACK WndProcThunk(HWND window_handle, |
146 HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); | 179 UINT message, |
| 180 WPARAM wparam, |
| 181 LPARAM lparam); |
147 virtual void DoRunLoop(); | 182 virtual void DoRunLoop(); |
148 void InitMessageWnd(); | 183 void InitMessageWnd(); |
149 void WaitForWork(); | 184 void WaitForWork(); |
150 void HandleWorkMessage(); | 185 void HandleWorkMessage(); |
151 void HandleTimerMessage(); | 186 void HandleTimerMessage(); |
152 bool ProcessNextWindowsMessage(); | 187 bool ProcessNextWindowsMessage(); |
153 bool ProcessMessageHelper(const MSG& msg); | 188 bool ProcessMessageHelper(const MSG& msg); |
154 bool ProcessPumpReplacementMessage(); | 189 bool ProcessPumpReplacementMessage(); |
155 | 190 |
156 // Instance of the module containing the window procedure. | 191 // Instance of the module containing the window procedure. |
157 HMODULE instance_; | 192 HMODULE instance_; |
158 | 193 |
159 // A hidden message-only window. | 194 // A hidden message-only window. |
160 HWND message_hwnd_; | 195 HWND message_hwnd_; |
| 196 |
| 197 scoped_ptr<MessageFilter> message_filter_; |
161 }; | 198 }; |
162 | 199 |
163 //----------------------------------------------------------------------------- | 200 //----------------------------------------------------------------------------- |
164 // MessagePumpForIO extends MessagePumpWin with methods that are particular to a | 201 // MessagePumpForIO extends MessagePumpWin with methods that are particular to a |
165 // MessageLoop instantiated with TYPE_IO. This version of MessagePump does not | 202 // MessageLoop instantiated with TYPE_IO. This version of MessagePump does not |
166 // deal with Windows mesagges, and instead has a Run loop based on Completion | 203 // deal with Windows mesagges, and instead has a Run loop based on Completion |
167 // Ports so it is better suited for IO operations. | 204 // Ports so it is better suited for IO operations. |
168 // | 205 // |
169 class BASE_EXPORT MessagePumpForIO : public MessagePumpWin { | 206 class BASE_EXPORT MessagePumpForIO : public MessagePumpWin { |
170 public: | 207 public: |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 // This list will be empty almost always. It stores IO completions that have | 387 // This list will be empty almost always. It stores IO completions that have |
351 // not been delivered yet because somebody was doing cleanup. | 388 // not been delivered yet because somebody was doing cleanup. |
352 std::list<IOItem> completed_io_; | 389 std::list<IOItem> completed_io_; |
353 | 390 |
354 ObserverList<IOObserver> io_observers_; | 391 ObserverList<IOObserver> io_observers_; |
355 }; | 392 }; |
356 | 393 |
357 } // namespace base | 394 } // namespace base |
358 | 395 |
359 #endif // BASE_MESSAGE_PUMP_WIN_H_ | 396 #endif // BASE_MESSAGE_PUMP_WIN_H_ |
OLD | NEW |