2017-04-27 03:59:52 +02:00
|
|
|
diff --git base/message_loop/message_loop.h base/message_loop/message_loop.h
|
2018-02-15 01:12:09 +01:00
|
|
|
index 27ee7fe8155b..353a61c3badd 100644
|
2017-04-27 03:59:52 +02:00
|
|
|
--- base/message_loop/message_loop.h
|
|
|
|
+++ base/message_loop/message_loop.h
|
2017-12-07 22:44:24 +01:00
|
|
|
@@ -266,6 +266,16 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate,
|
2016-06-21 00:59:23 +02:00
|
|
|
void AddTaskObserver(TaskObserver* task_observer);
|
|
|
|
void RemoveTaskObserver(TaskObserver* task_observer);
|
|
|
|
|
|
|
|
+#if defined(OS_WIN)
|
|
|
|
+ void set_os_modal_loop(bool os_modal_loop) {
|
|
|
|
+ os_modal_loop_ = os_modal_loop;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ bool os_modal_loop() const {
|
|
|
|
+ return os_modal_loop_;
|
|
|
|
+ }
|
|
|
|
+#endif // OS_WIN
|
|
|
|
+
|
2018-02-15 01:12:09 +01:00
|
|
|
// Returns true if the message loop is idle (ignoring delayed tasks). This is
|
|
|
|
// the same condition which triggers DoWork() to return false: i.e.
|
|
|
|
// out of tasks which can be processed at the current run-level -- there might
|
|
|
|
@@ -373,6 +383,12 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate,
|
2017-12-07 22:44:24 +01:00
|
|
|
// is known to generate a system-driven nested loop.
|
|
|
|
bool task_execution_allowed_ = true;
|
2016-06-21 00:59:23 +02:00
|
|
|
|
|
|
|
+#if defined(OS_WIN)
|
|
|
|
+ // Should be set to true before calling Windows APIs like TrackPopupMenu, etc.
|
|
|
|
+ // which enter a modal message loop.
|
2017-05-31 17:33:30 +02:00
|
|
|
+ bool os_modal_loop_ = false;
|
2016-06-21 00:59:23 +02:00
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
// pump_factory_.Run() is called to create a message pump for this loop
|
|
|
|
// if type_ is TYPE_CUSTOM and pump_ is null.
|
|
|
|
MessagePumpFactoryCallback pump_factory_;
|
2017-04-27 03:59:52 +02:00
|
|
|
diff --git base/message_loop/message_pump_win.cc base/message_loop/message_pump_win.cc
|
2018-03-20 21:15:08 +01:00
|
|
|
index 5069b8524924..e88a3c7974f2 100644
|
2017-04-27 03:59:52 +02:00
|
|
|
--- base/message_loop/message_pump_win.cc
|
|
|
|
+++ base/message_loop/message_pump_win.cc
|
2016-11-23 21:54:29 +01:00
|
|
|
@@ -366,20 +366,28 @@ bool MessagePumpForUI::ProcessMessageHelper(const MSG& msg) {
|
2016-06-21 00:59:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MessagePumpForUI::ProcessPumpReplacementMessage() {
|
|
|
|
- // When we encounter a kMsgHaveWork message, this method is called to peek and
|
|
|
|
- // process a replacement message. The goal is to make the kMsgHaveWork as non-
|
|
|
|
- // intrusive as possible, even though a continuous stream of such messages are
|
|
|
|
- // posted. This method carefully peeks a message while there is no chance for
|
|
|
|
- // a kMsgHaveWork to be pending, then resets the |have_work_| flag (allowing a
|
|
|
|
- // replacement kMsgHaveWork to possibly be posted), and finally dispatches
|
|
|
|
- // that peeked replacement. Note that the re-post of kMsgHaveWork may be
|
|
|
|
- // asynchronous to this thread!!
|
|
|
|
-
|
|
|
|
+ // When we encounter a kMsgHaveWork message, this method is called to peek
|
|
|
|
+ // and process a replacement message, such as a WM_PAINT or WM_TIMER. The
|
|
|
|
+ // goal is to make the kMsgHaveWork as non-intrusive as possible, even though
|
|
|
|
+ // a continuous stream of such messages are posted. This method carefully
|
|
|
|
+ // peeks a message while there is no chance for a kMsgHaveWork to be pending,
|
|
|
|
+ // then resets the have_work_ flag (allowing a replacement kMsgHaveWork to
|
|
|
|
+ // possibly be posted), and finally dispatches that peeked replacement. Note
|
|
|
|
+ // that the re-post of kMsgHaveWork may be asynchronous to this thread!!
|
|
|
|
+
|
|
|
|
+ bool have_message = false;
|
|
|
|
MSG msg;
|
|
|
|
- const bool have_message =
|
2016-11-23 21:54:29 +01:00
|
|
|
- PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE) != FALSE;
|
2016-06-21 00:59:23 +02:00
|
|
|
+ // We should not process all window messages if we are in the context of an
|
|
|
|
+ // OS modal loop, i.e. in the context of a windows API call like MessageBox.
|
|
|
|
+ // This is to ensure that these messages are peeked out by the OS modal loop.
|
|
|
|
+ if (MessageLoop::current()->os_modal_loop()) {
|
|
|
|
+ // We only peek out WM_PAINT and WM_TIMER here for reasons mentioned above.
|
|
|
|
+ have_message = PeekMessage(&msg, NULL, WM_PAINT, WM_PAINT, PM_REMOVE) ||
|
|
|
|
+ PeekMessage(&msg, NULL, WM_TIMER, WM_TIMER, PM_REMOVE);
|
|
|
|
+ } else {
|
|
|
|
+ have_message = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) != FALSE;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // Expect no message or a message different than kMsgHaveWork.
|
|
|
|
DCHECK(!have_message || kMsgHaveWork != msg.message ||
|
2016-11-23 21:54:29 +01:00
|
|
|
msg.hwnd != message_window_.hwnd());
|
2016-06-21 00:59:23 +02:00
|
|
|
|