1 /* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 
6 #include "mozilla/ipc/MessageChannel.h"
7 #include "mozilla/ipc/WindowsMessageLoop.h"
8 #include "nsAppShell.h"
9 #include "nsToolkit.h"
10 #include "nsThreadUtils.h"
11 #include "WinUtils.h"
12 #include "WinTaskbar.h"
13 #include "WinMouseScrollHandler.h"
14 #include "nsWindowDefs.h"
15 #include "nsString.h"
16 #include "WinIMEHandler.h"
17 #include "mozilla/widget/AudioSession.h"
18 #include "mozilla/HangMonitor.h"
19 #include "nsIDOMWakeLockListener.h"
20 #include "nsIPowerManagerService.h"
21 #include "mozilla/StaticPtr.h"
22 #include "nsTHashtable.h"
23 #include "nsHashKeys.h"
24 #include "GeckoProfiler.h"
25 #include "nsComponentManagerUtils.h"
26 #include "ScreenHelperWin.h"
27 #include "HeadlessScreenHelper.h"
28 #include "mozilla/widget/ScreenManager.h"
29 #include "mozilla/Atomics.h"
30 
31 #if defined(ACCESSIBILITY)
32 #include "mozilla/a11y/Compatibility.h"
33 #include "mozilla/a11y/Platform.h"
34 #endif  // defined(ACCESSIBILITY)
35 
36 // These are two messages that the code in winspool.drv on Windows 7 explicitly
37 // waits for while it is pumping other Windows messages, during display of the
38 // Printer Properties dialog.
39 #define MOZ_WM_PRINTER_PROPERTIES_COMPLETION 0x5b7a
40 #define MOZ_WM_PRINTER_PROPERTIES_FAILURE 0x5b7f
41 
42 using namespace mozilla;
43 using namespace mozilla::widget;
44 
45 #define WAKE_LOCK_LOG(...) \
46   MOZ_LOG(gWinWakeLockLog, mozilla::LogLevel::Debug, (__VA_ARGS__))
47 static mozilla::LazyLogModule gWinWakeLockLog("WinWakeLock");
48 
49 // A wake lock listener that disables screen saver when requested by
50 // Gecko. For example when we're playing video in a foreground tab we
51 // don't want the screen saver to turn on.
52 class WinWakeLockListener final : public nsIDOMMozWakeLockListener {
53  public:
54   NS_DECL_ISUPPORTS
55 
56  private:
~WinWakeLockListener()57   ~WinWakeLockListener() {}
58 
Callback(const nsAString & aTopic,const nsAString & aState)59   NS_IMETHOD Callback(const nsAString& aTopic,
60                       const nsAString& aState) override {
61     if (!aTopic.EqualsASCII("screen") && !aTopic.EqualsASCII("audio-playing") &&
62         !aTopic.EqualsASCII("video-playing")) {
63       return NS_OK;
64     }
65 
66     // we should still hold the lock for background audio.
67     if (aTopic.EqualsASCII("audio-playing") &&
68         aState.EqualsASCII("locked-background")) {
69       return NS_OK;
70     }
71 
72     if (aTopic.EqualsASCII("screen") || aTopic.EqualsASCII("video-playing")) {
73       mRequireForDisplay = aState.EqualsASCII("locked-foreground");
74     }
75 
76     // Note the wake lock code ensures that we're not sent duplicate
77     // "locked-foreground" notifications when multiple wake locks are held.
78     if (aState.EqualsASCII("locked-foreground")) {
79       WAKE_LOCK_LOG("WinWakeLock: Blocking screen saver");
80       if (mRequireForDisplay) {
81         // Prevent the display turning off and block the screen saver.
82         SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_CONTINUOUS);
83       } else {
84         SetThreadExecutionState(ES_SYSTEM_REQUIRED | ES_CONTINUOUS);
85       }
86     } else {
87       WAKE_LOCK_LOG("WinWakeLock: Unblocking screen saver");
88       // Unblock display/screen saver turning off.
89       SetThreadExecutionState(ES_CONTINUOUS);
90     }
91     return NS_OK;
92   }
93 
94   bool mRequireForDisplay = false;
95 };
96 
97 NS_IMPL_ISUPPORTS(WinWakeLockListener, nsIDOMMozWakeLockListener)
98 StaticRefPtr<WinWakeLockListener> sWakeLockListener;
99 
AddScreenWakeLockListener()100 static void AddScreenWakeLockListener() {
101   nsCOMPtr<nsIPowerManagerService> sPowerManagerService =
102       do_GetService(POWERMANAGERSERVICE_CONTRACTID);
103   if (sPowerManagerService) {
104     sWakeLockListener = new WinWakeLockListener();
105     sPowerManagerService->AddWakeLockListener(sWakeLockListener);
106   } else {
107     NS_WARNING(
108         "Failed to retrieve PowerManagerService, wakelocks will be broken!");
109   }
110 }
111 
RemoveScreenWakeLockListener()112 static void RemoveScreenWakeLockListener() {
113   nsCOMPtr<nsIPowerManagerService> sPowerManagerService =
114       do_GetService(POWERMANAGERSERVICE_CONTRACTID);
115   if (sPowerManagerService) {
116     sPowerManagerService->RemoveWakeLockListener(sWakeLockListener);
117     sPowerManagerService = nullptr;
118     sWakeLockListener = nullptr;
119   }
120 }
121 
122 class SingleNativeEventPump final : public nsIThreadObserver {
123  public:
124   NS_DECL_THREADSAFE_ISUPPORTS
125   NS_DECL_NSITHREADOBSERVER
126 
SingleNativeEventPump()127   SingleNativeEventPump() {
128     MOZ_ASSERT(!XRE_UseNativeEventProcessing(),
129                "Should only be used when not properly processing events.");
130   }
131 
132  private:
~SingleNativeEventPump()133   ~SingleNativeEventPump() {}
134 };
135 
NS_IMPL_ISUPPORTS(SingleNativeEventPump,nsIThreadObserver)136 NS_IMPL_ISUPPORTS(SingleNativeEventPump, nsIThreadObserver)
137 
138 NS_IMETHODIMP
139 SingleNativeEventPump::OnDispatchedEvent() { return NS_OK; }
140 
141 NS_IMETHODIMP
OnProcessNextEvent(nsIThreadInternal * aThread,bool aMayWait)142 SingleNativeEventPump::OnProcessNextEvent(nsIThreadInternal* aThread,
143                                           bool aMayWait) {
144   MSG msg;
145   bool gotMessage = WinUtils::PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE);
146   if (gotMessage) {
147     ::TranslateMessage(&msg);
148     ::DispatchMessageW(&msg);
149   }
150   return NS_OK;
151 }
152 
153 NS_IMETHODIMP
AfterProcessNextEvent(nsIThreadInternal * aThread,bool aMayWait)154 SingleNativeEventPump::AfterProcessNextEvent(nsIThreadInternal* aThread,
155                                              bool aMayWait) {
156   return NS_OK;
157 }
158 
159 namespace mozilla {
160 namespace widget {
161 // Native event callback message.
162 UINT sAppShellGeckoMsgId = RegisterWindowMessageW(L"nsAppShell:EventID");
163 }  // namespace widget
164 }  // namespace mozilla
165 
166 const wchar_t* kTaskbarButtonEventId = L"TaskbarButtonCreated";
167 UINT sTaskbarButtonCreatedMsg;
168 
169 /* static */
GetTaskbarButtonCreatedMessage()170 UINT nsAppShell::GetTaskbarButtonCreatedMessage() {
171   return sTaskbarButtonCreatedMsg;
172 }
173 
174 namespace mozilla {
175 namespace crashreporter {
176 void LSPAnnotate();
177 }  // namespace crashreporter
178 }  // namespace mozilla
179 
180 using mozilla::crashreporter::LSPAnnotate;
181 
182 //-------------------------------------------------------------------------
183 
184 // Note that since we're on x86-ish processors here, ReleaseAcquire is the
185 // semantics that normal loads and stores would use anyway.
186 static Atomic<size_t, ReleaseAcquire> sOutstandingNativeEventCallbacks;
187 
EventWindowProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)188 /*static*/ LRESULT CALLBACK nsAppShell::EventWindowProc(HWND hwnd, UINT uMsg,
189                                                         WPARAM wParam,
190                                                         LPARAM lParam) {
191   if (uMsg == sAppShellGeckoMsgId) {
192     // The app shell might have been destroyed between this message being
193     // posted and being executed, so be extra careful.
194     if (!sOutstandingNativeEventCallbacks) {
195       return TRUE;
196     }
197 
198     nsAppShell* as = reinterpret_cast<nsAppShell*>(lParam);
199     as->NativeEventCallback();
200     --sOutstandingNativeEventCallbacks;
201     return TRUE;
202   }
203   return DefWindowProc(hwnd, uMsg, wParam, lParam);
204 }
205 
~nsAppShell()206 nsAppShell::~nsAppShell() {
207   if (mEventWnd) {
208     // DestroyWindow doesn't do anything when called from a non UI thread.
209     // Since mEventWnd was created on the UI thread, it must be destroyed on
210     // the UI thread.
211     SendMessage(mEventWnd, WM_CLOSE, 0, 0);
212   }
213 
214   // Cancel any outstanding native event callbacks.
215   sOutstandingNativeEventCallbacks = 0;
216 }
217 
218 #if defined(ACCESSIBILITY)
219 
220 static ULONG gUiaMsg;
221 static HHOOK gUiaHook;
222 static uint32_t gUiaAttempts;
223 static const uint32_t kMaxUiaAttempts = 5;
224 
225 static void InitUIADetection();
226 
UiaHookProc(int aCode,WPARAM aWParam,LPARAM aLParam)227 static LRESULT CALLBACK UiaHookProc(int aCode, WPARAM aWParam, LPARAM aLParam) {
228   if (aCode < 0) {
229     return ::CallNextHookEx(nullptr, aCode, aWParam, aLParam);
230   }
231 
232   auto cwp = reinterpret_cast<CWPSTRUCT*>(aLParam);
233   if (gUiaMsg && cwp->message == gUiaMsg) {
234     if (gUiaAttempts < kMaxUiaAttempts) {
235       ++gUiaAttempts;
236 
237       Maybe<bool> shouldCallNextHook =
238           a11y::Compatibility::OnUIAMessage(cwp->wParam, cwp->lParam);
239       if (shouldCallNextHook.isSome()) {
240         // We've got an instantiator.
241         if (!shouldCallNextHook.value()) {
242           // We're blocking this instantiation. We need to keep this hook set
243           // so that we can catch any future instantiation attempts.
244           return 0;
245         }
246 
247         // We're allowing the instantiator to proceed, so this hook is no longer
248         // needed.
249         if (::UnhookWindowsHookEx(gUiaHook)) {
250           gUiaHook = nullptr;
251         }
252       } else {
253         // Our hook might be firing after UIA; let's try reinstalling ourselves.
254         InitUIADetection();
255       }
256     } else {
257       // We've maxed out our attempts. Let's unhook.
258       if (::UnhookWindowsHookEx(gUiaHook)) {
259         gUiaHook = nullptr;
260       }
261     }
262   }
263 
264   return ::CallNextHookEx(nullptr, aCode, aWParam, aLParam);
265 }
266 
InitUIADetection()267 static void InitUIADetection() {
268   if (gUiaHook) {
269     // In this case we want to re-hook so that the hook is always called ahead
270     // of UIA's hook.
271     if (::UnhookWindowsHookEx(gUiaHook)) {
272       gUiaHook = nullptr;
273     }
274   }
275 
276   if (!gUiaMsg) {
277     // This is the message that UIA sends to trigger a command. UIA's
278     // CallWndProc looks for this message and then handles the request.
279     // Our hook gets in front of UIA's hook and examines the message first.
280     gUiaMsg = ::RegisterWindowMessageW(L"HOOKUTIL_MSG");
281   }
282 
283   if (!gUiaHook) {
284     gUiaHook = ::SetWindowsHookEx(WH_CALLWNDPROC, &UiaHookProc, nullptr,
285                                   ::GetCurrentThreadId());
286   }
287 }
288 
289 NS_IMETHODIMP
Observe(nsISupports * aSubject,const char * aTopic,const char16_t * aData)290 nsAppShell::Observe(nsISupports* aSubject, const char* aTopic,
291                     const char16_t* aData) {
292   if (XRE_IsParentProcess() && !strcmp(aTopic, "dll-loaded-main-thread")) {
293     if (a11y::PlatformDisabledState() != a11y::ePlatformIsDisabled &&
294         !gUiaHook) {
295       nsDependentString dllName(aData);
296 
297       if (StringEndsWith(dllName, NS_LITERAL_STRING("uiautomationcore.dll"),
298                          nsCaseInsensitiveStringComparator())) {
299         InitUIADetection();
300 
301         // Now that we've handled the observer notification, we can remove it
302         nsCOMPtr<nsIObserverService> obsServ(
303             mozilla::services::GetObserverService());
304         obsServ->RemoveObserver(this, "dll-loaded-main-thread");
305       }
306     }
307 
308     return NS_OK;
309   }
310 
311   return nsBaseAppShell::Observe(aSubject, aTopic, aData);
312 }
313 
314 #endif  // defined(ACCESSIBILITY)
315 
Init()316 nsresult nsAppShell::Init() {
317   LSPAnnotate();
318 
319   mozilla::ipc::windows::InitUIThread();
320 
321   sTaskbarButtonCreatedMsg = ::RegisterWindowMessageW(kTaskbarButtonEventId);
322   NS_ASSERTION(sTaskbarButtonCreatedMsg,
323                "Could not register taskbar button creation message");
324 
325   // The hidden message window is used for interrupting the processing of native
326   // events, so that we can process gecko events. Therefore, we only need it if
327   // we are processing native events.
328   if (XRE_UseNativeEventProcessing()) {
329     mLastNativeEventScheduled = TimeStamp::NowLoRes();
330 
331     WNDCLASSW wc;
332     HINSTANCE module = GetModuleHandle(nullptr);
333 
334     const wchar_t* const kWindowClass = L"nsAppShell:EventWindowClass";
335     if (!GetClassInfoW(module, kWindowClass, &wc)) {
336       wc.style = 0;
337       wc.lpfnWndProc = EventWindowProc;
338       wc.cbClsExtra = 0;
339       wc.cbWndExtra = 0;
340       wc.hInstance = module;
341       wc.hIcon = nullptr;
342       wc.hCursor = nullptr;
343       wc.hbrBackground = (HBRUSH) nullptr;
344       wc.lpszMenuName = (LPCWSTR) nullptr;
345       wc.lpszClassName = kWindowClass;
346       RegisterClassW(&wc);
347     }
348 
349     mEventWnd = CreateWindowW(kWindowClass, L"nsAppShell:EventWindow", 0, 0, 0,
350                               10, 10, HWND_MESSAGE, nullptr, module, nullptr);
351     NS_ENSURE_STATE(mEventWnd);
352   } else {
353     // We're not generally processing native events, but still using GDI and we
354     // still have some internal windows, e.g. from calling CoInitializeEx.
355     // So we use a class that will do a single event pump where previously we
356     // might have processed multiple events to make sure any occasional messages
357     // to these windows are processed. This also allows any internal Windows
358     // messages to be processed to ensure the GDI data remains fresh.
359     nsCOMPtr<nsIThreadInternal> threadInt =
360         do_QueryInterface(NS_GetCurrentThread());
361     if (threadInt) {
362       threadInt->SetObserver(new SingleNativeEventPump());
363     }
364   }
365 
366   if (XRE_IsParentProcess()) {
367     ScreenManager& screenManager = ScreenManager::GetSingleton();
368     if (gfxPlatform::IsHeadless()) {
369       screenManager.SetHelper(mozilla::MakeUnique<HeadlessScreenHelper>());
370     } else {
371       screenManager.SetHelper(mozilla::MakeUnique<ScreenHelperWin>());
372       ScreenHelperWin::RefreshScreens();
373     }
374 
375 #if defined(ACCESSIBILITY)
376     if (::GetModuleHandleW(L"uiautomationcore.dll")) {
377       InitUIADetection();
378     } else {
379       nsCOMPtr<nsIObserverService> obsServ(
380           mozilla::services::GetObserverService());
381       obsServ->AddObserver(this, "dll-loaded-main-thread", false);
382     }
383 #endif  // defined(ACCESSIBILITY)
384   }
385 
386   return nsBaseAppShell::Init();
387 }
388 
389 NS_IMETHODIMP
Run(void)390 nsAppShell::Run(void) {
391   // Content processes initialize audio later through PContent using audio
392   // tray id information pulled from the browser process AudioSession. This
393   // way the two share a single volume control.
394   // Note StopAudioSession() is called from nsAppRunner.cpp after xpcom is torn
395   // down to insure the browser shuts down after child processes.
396   if (XRE_IsParentProcess()) {
397     mozilla::widget::StartAudioSession();
398   }
399 
400   // Add an observer that disables the screen saver when requested by Gecko.
401   // For example when we're playing video in the foreground tab.
402   AddScreenWakeLockListener();
403 
404   nsresult rv = nsBaseAppShell::Run();
405 
406   RemoveScreenWakeLockListener();
407 
408   return rv;
409 }
410 
411 NS_IMETHODIMP
Exit(void)412 nsAppShell::Exit(void) {
413 #if defined(ACCESSIBILITY)
414   if (XRE_IsParentProcess()) {
415     nsCOMPtr<nsIObserverService> obsServ(
416         mozilla::services::GetObserverService());
417     obsServ->RemoveObserver(this, "dll-loaded-main-thread");
418 
419     if (gUiaHook && ::UnhookWindowsHookEx(gUiaHook)) {
420       gUiaHook = nullptr;
421     }
422   }
423 #endif  // defined(ACCESSIBILITY)
424 
425   return nsBaseAppShell::Exit();
426 }
427 
DoProcessMoreGeckoEvents()428 void nsAppShell::DoProcessMoreGeckoEvents() {
429   // Called by nsBaseAppShell's NativeEventCallback() after it has finished
430   // processing pending gecko events and there are still gecko events pending
431   // for the thread. (This can happen if NS_ProcessPendingEvents reached it's
432   // starvation timeout limit.) The default behavior in nsBaseAppShell is to
433   // call ScheduleNativeEventCallback to post a follow up native event callback
434   // message. This triggers an additional call to NativeEventCallback for more
435   // gecko event processing.
436 
437   // There's a deadlock risk here with certain internal Windows modal loops. In
438   // our dispatch code, we prioritize messages so that input is handled first.
439   // However Windows modal dispatch loops often prioritize posted messages. If
440   // we find ourselves in a tight gecko timer loop where NS_ProcessPendingEvents
441   // takes longer than the timer duration, NS_HasPendingEvents(thread) will
442   // always be true. ScheduleNativeEventCallback will be called on every
443   // NativeEventCallback callback, and in a Windows modal dispatch loop, the
444   // callback message will be processed first -> input gets starved, dead lock.
445 
446   // To avoid, don't post native callback messages from NativeEventCallback
447   // when we're in a modal loop. This gets us back into the Windows modal
448   // dispatch loop dispatching input messages. Once we drop out of the modal
449   // loop, we use mNativeCallbackPending to fire off a final NativeEventCallback
450   // if we need it, which insures NS_ProcessPendingEvents gets called and all
451   // gecko events get processed.
452   if (mEventloopNestingLevel < 2) {
453     OnDispatchedEvent();
454     mNativeCallbackPending = false;
455   } else {
456     mNativeCallbackPending = true;
457   }
458 }
459 
ScheduleNativeEventCallback()460 void nsAppShell::ScheduleNativeEventCallback() {
461   MOZ_ASSERT(mEventWnd,
462              "We should have created mEventWnd in Init, if this is called.");
463 
464   // Post a message to the hidden message window
465   ++sOutstandingNativeEventCallbacks;
466   {
467     MutexAutoLock lock(mLastNativeEventScheduledMutex);
468     // Time stamp this event so we can detect cases where the event gets
469     // dropping in sub classes / modal loops we do not control.
470     mLastNativeEventScheduled = TimeStamp::NowLoRes();
471   }
472   ::PostMessage(mEventWnd, sAppShellGeckoMsgId, 0,
473                 reinterpret_cast<LPARAM>(this));
474 }
475 
ProcessNextNativeEvent(bool mayWait)476 bool nsAppShell::ProcessNextNativeEvent(bool mayWait) {
477   // Notify ipc we are spinning a (possibly nested) gecko event loop.
478   mozilla::ipc::MessageChannel::NotifyGeckoEventDispatch();
479 
480   bool gotMessage = false;
481 
482   do {
483     MSG msg;
484     bool uiMessage = false;
485 
486     // For avoiding deadlock between our process and plugin process by
487     // mouse wheel messages, we're handling actually when we receive one of
488     // following internal messages which is posted by native mouse wheel
489     // message handler. Any other events, especially native modifier key
490     // events, should not be handled between native message and posted
491     // internal message because it may make different modifier key state or
492     // mouse cursor position between them.
493     if (mozilla::widget::MouseScrollHandler::IsWaitingInternalMessage()) {
494       gotMessage = WinUtils::PeekMessage(&msg, nullptr, MOZ_WM_MOUSEWHEEL_FIRST,
495                                          MOZ_WM_MOUSEWHEEL_LAST, PM_REMOVE);
496       NS_ASSERTION(gotMessage,
497                    "waiting internal wheel message, but it has not come");
498       uiMessage = gotMessage;
499     }
500 
501     if (!gotMessage) {
502       gotMessage = WinUtils::PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE);
503       uiMessage =
504           (msg.message >= WM_KEYFIRST && msg.message <= WM_IME_KEYLAST) ||
505           (msg.message >= NS_WM_IMEFIRST && msg.message <= NS_WM_IMELAST) ||
506           (msg.message >= WM_MOUSEFIRST && msg.message <= WM_MOUSELAST);
507     }
508 
509     if (gotMessage) {
510       if (msg.message == WM_QUIT) {
511         ::PostQuitMessage(msg.wParam);
512         Exit();
513       } else {
514         // If we had UI activity we would be processing it now so we know we
515         // have either kUIActivity or kActivityNoUIAVail.
516         mozilla::HangMonitor::NotifyActivity(
517             uiMessage ? mozilla::HangMonitor::kUIActivity
518                       : mozilla::HangMonitor::kActivityNoUIAVail);
519 
520         if (msg.message >= WM_KEYFIRST && msg.message <= WM_KEYLAST &&
521             IMEHandler::ProcessRawKeyMessage(msg)) {
522           continue;  // the message is consumed.
523         }
524 
525         // Store Printer Properties messages for reposting, because they are not
526         // processed by a window procedure, but are explicitly waited for in the
527         // winspool.drv code that will be further up the stack.
528         if (msg.message == MOZ_WM_PRINTER_PROPERTIES_COMPLETION ||
529             msg.message == MOZ_WM_PRINTER_PROPERTIES_FAILURE) {
530           mMsgsToRepost.push_back(msg);
531           continue;
532         }
533 
534         ::TranslateMessage(&msg);
535         ::DispatchMessageW(&msg);
536       }
537     } else if (mayWait) {
538       // Block and wait for any posted application message
539       mozilla::HangMonitor::Suspend();
540       {
541         AUTO_PROFILER_THREAD_SLEEP;
542         WinUtils::WaitForMessage();
543       }
544     }
545   } while (!gotMessage && mayWait);
546 
547   // See DoProcessNextNativeEvent, mEventloopNestingLevel will be
548   // one when a modal loop unwinds.
549   if (mNativeCallbackPending && mEventloopNestingLevel == 1)
550     DoProcessMoreGeckoEvents();
551 
552   // Check for starved native callbacks. If we haven't processed one
553   // of these events in NATIVE_EVENT_STARVATION_LIMIT, fire one off.
554   static const mozilla::TimeDuration nativeEventStarvationLimit =
555       mozilla::TimeDuration::FromSeconds(NATIVE_EVENT_STARVATION_LIMIT);
556 
557   TimeDuration timeSinceLastNativeEventScheduled;
558   {
559     MutexAutoLock lock(mLastNativeEventScheduledMutex);
560     timeSinceLastNativeEventScheduled =
561         TimeStamp::NowLoRes() - mLastNativeEventScheduled;
562   }
563   if (timeSinceLastNativeEventScheduled > nativeEventStarvationLimit) {
564     ScheduleNativeEventCallback();
565   }
566 
567   return gotMessage;
568 }
569 
AfterProcessNextEvent(nsIThreadInternal *,bool)570 nsresult nsAppShell::AfterProcessNextEvent(nsIThreadInternal* /* unused */,
571                                            bool /* unused */) {
572   if (!mMsgsToRepost.empty()) {
573     for (MSG msg : mMsgsToRepost) {
574       ::PostMessageW(msg.hwnd, msg.message, msg.wParam, msg.lParam);
575     }
576     mMsgsToRepost.clear();
577   }
578   return NS_OK;
579 }
580