2018-11-30 23:21:07 +01:00
|
|
|
diff --git base/message_loop/message_loop.cc base/message_loop/message_loop.cc
|
2019-03-13 22:27:37 +01:00
|
|
|
index fff922d36819..28fea401be5f 100644
|
2018-11-30 23:21:07 +01:00
|
|
|
--- base/message_loop/message_loop.cc
|
|
|
|
+++ base/message_loop/message_loop.cc
|
2019-03-13 22:27:37 +01:00
|
|
|
@@ -163,6 +163,9 @@ MessageLoopBase* MessageLoop::GetMessageLoopBase() {
|
2018-12-26 16:12:11 +01:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2018-11-30 23:21:07 +01:00
|
|
|
|
|
|
|
+MessageLoopForUI::MessageLoopForUI(std::unique_ptr<MessagePump> pump)
|
2019-03-13 22:27:37 +01:00
|
|
|
+ : MessageLoop(TYPE_UI, std::move(pump)) {}
|
2018-11-30 23:21:07 +01:00
|
|
|
+
|
|
|
|
// static
|
2019-03-13 22:27:37 +01:00
|
|
|
std::unique_ptr<MessageLoop> MessageLoop::CreateUnbound(Type type) {
|
|
|
|
return WrapUnique(new MessageLoop(type, nullptr));
|
2018-11-30 23:21:07 +01:00
|
|
|
diff --git base/message_loop/message_loop.h base/message_loop/message_loop.h
|
2019-03-13 22:27:37 +01:00
|
|
|
index 46782b49a7f0..78ebaf71cbdf 100644
|
2018-11-30 23:21:07 +01:00
|
|
|
--- base/message_loop/message_loop.h
|
|
|
|
+++ base/message_loop/message_loop.h
|
2019-03-13 22:27:37 +01:00
|
|
|
@@ -377,6 +377,7 @@ class BASE_EXPORT MessageLoop {
|
2018-11-30 23:21:07 +01:00
|
|
|
class BASE_EXPORT MessageLoopForUI : public MessageLoop {
|
|
|
|
public:
|
|
|
|
explicit MessageLoopForUI(Type type = TYPE_UI);
|
|
|
|
+ explicit MessageLoopForUI(std::unique_ptr<MessagePump> pump);
|
|
|
|
|
2018-12-26 16:12:11 +01:00
|
|
|
#if defined(OS_IOS)
|
|
|
|
// On iOS, the main message loop cannot be Run(). Instead call Attach(),
|
2018-09-06 17:32:01 +02:00
|
|
|
diff --git base/message_loop/message_loop_current.cc base/message_loop/message_loop_current.cc
|
2019-03-13 22:27:37 +01:00
|
|
|
index c0b2ff7e0ad6..75802589ca01 100644
|
2018-09-06 17:32:01 +02:00
|
|
|
--- base/message_loop/message_loop_current.cc
|
|
|
|
+++ base/message_loop/message_loop_current.cc
|
2018-11-30 23:21:07 +01:00
|
|
|
@@ -49,6 +49,8 @@ void MessageLoopCurrent::AddDestructionObserver(
|
2018-09-06 17:32:01 +02:00
|
|
|
|
|
|
|
void MessageLoopCurrent::RemoveDestructionObserver(
|
|
|
|
DestructionObserver* destruction_observer) {
|
|
|
|
+ if (!current_)
|
|
|
|
+ return;
|
2018-11-30 23:21:07 +01:00
|
|
|
DCHECK(current_->IsBoundToCurrentThread());
|
|
|
|
current_->RemoveDestructionObserver(destruction_observer);
|
2018-09-06 17:32:01 +02:00
|
|
|
}
|
2018-05-14 13:24:05 +02:00
|
|
|
diff --git base/message_loop/message_loop_current.h base/message_loop/message_loop_current.h
|
2019-03-13 22:27:37 +01:00
|
|
|
index bcab89d6e2e7..3160b321990e 100644
|
2018-05-14 13:24:05 +02:00
|
|
|
--- base/message_loop/message_loop_current.h
|
|
|
|
+++ base/message_loop/message_loop_current.h
|
2019-03-13 22:27:37 +01:00
|
|
|
@@ -133,6 +133,12 @@ class BASE_EXPORT MessageLoopCurrent {
|
2018-08-09 22:18:24 +02:00
|
|
|
// posted tasks.
|
|
|
|
void SetAddQueueTimeToTasks(bool enable);
|
2016-06-21 00:59:23 +02:00
|
|
|
|
|
|
|
+#if defined(OS_WIN)
|
2019-03-13 22:27:37 +01:00
|
|
|
+ void set_os_modal_loop(bool os_modal_loop) { os_modal_loop_ = os_modal_loop; }
|
2016-06-21 00:59:23 +02:00
|
|
|
+
|
2019-03-13 22:27:37 +01:00
|
|
|
+ bool os_modal_loop() const { return os_modal_loop_; }
|
2016-06-21 00:59:23 +02:00
|
|
|
+#endif // OS_WIN
|
|
|
|
+
|
2018-05-14 13:24:05 +02:00
|
|
|
// Enables or disables the recursive task processing. This happens in the case
|
|
|
|
// of recursive message loops. Some unwanted message loops may occur when
|
|
|
|
// using common controls or printer functions. By default, recursive task
|
2019-03-13 22:27:37 +01:00
|
|
|
@@ -213,6 +219,13 @@ class BASE_EXPORT MessageLoopCurrent {
|
2018-11-30 23:21:07 +01:00
|
|
|
MessageLoopBase* ToMessageLoopBaseDeprecated() const { return current_; }
|
|
|
|
|
|
|
|
MessageLoopBase* current_;
|
2018-05-14 13:24:05 +02:00
|
|
|
+
|
2016-06-21 00:59:23 +02:00
|
|
|
+#if defined(OS_WIN)
|
2018-05-14 13:24:05 +02:00
|
|
|
+ private:
|
2016-06-21 00:59:23 +02:00
|
|
|
+ // 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
|
2018-05-14 13:24:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#if !defined(OS_NACL)
|
2017-04-27 03:59:52 +02:00
|
|
|
diff --git base/message_loop/message_pump_win.cc base/message_loop/message_pump_win.cc
|
2019-03-13 22:27:37 +01:00
|
|
|
index 3e9562cc4cc5..cf4a700364d3 100644
|
2017-04-27 03:59:52 +02:00
|
|
|
--- base/message_loop/message_pump_win.cc
|
|
|
|
+++ base/message_loop/message_pump_win.cc
|
2019-03-13 22:27:37 +01:00
|
|
|
@@ -2,6 +2,7 @@
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2018-05-20 15:51:42 +02:00
|
|
|
+#include "base/message_loop/message_loop_current.h"
|
2019-03-13 22:27:37 +01:00
|
|
|
#include "base/message_loop/message_pump_win.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
@@ -493,10 +494,18 @@ bool MessagePumpForUI::ProcessPumpReplacementMessage() {
|
|
|
|
// asynchronous to this thread!!
|
2016-06-21 00:59:23 +02:00
|
|
|
|
|
|
|
MSG msg;
|
|
|
|
- const bool have_message =
|
2018-10-02 14:14:11 +02:00
|
|
|
- ::PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE) != FALSE;
|
2019-03-13 22:27:37 +01:00
|
|
|
+ bool have_message = 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.
|
2018-05-20 15:51:42 +02:00
|
|
|
+ if (MessageLoopCurrent::Get()->os_modal_loop()) {
|
2016-06-21 00:59:23 +02:00
|
|
|
+ // 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
|
|
|
|