From 501e7a5f1b8af9fd224a788d06664928ebb1342e Mon Sep 17 00:00:00 2001 From: Aaron Klotz Date: Mon, 12 May 2014 13:30:31 -0600 Subject: [PATCH] Bug 1006765: Ensure that Win32 widget handles terminal services messages; r=jimm --HG-- extra : rebase_source : a25ad41fb20aa3b52207a78f42d51fb870246bf4 --- toolkit/library/libxul.mk | 2 +- widget/windows/nsWindow.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/toolkit/library/libxul.mk b/toolkit/library/libxul.mk index 3ebb8fccba92..11a0c6948a3d 100644 --- a/toolkit/library/libxul.mk +++ b/toolkit/library/libxul.mk @@ -207,7 +207,7 @@ OS_LIBS += $(call EXPAND_LIBNAME,util) endif ifeq ($(OS_ARCH),WINNT) -OS_LIBS += $(call EXPAND_LIBNAME,shell32 ole32 version winspool comdlg32 imm32 msimg32 shlwapi psapi ws2_32 dbghelp rasapi32 rasdlg iphlpapi uxtheme setupapi secur32 sensorsapi portabledeviceguids windowscodecs wininet wbemuuid wintrust) +OS_LIBS += $(call EXPAND_LIBNAME,shell32 ole32 version winspool comdlg32 imm32 msimg32 shlwapi psapi ws2_32 dbghelp rasapi32 rasdlg iphlpapi uxtheme setupapi secur32 sensorsapi portabledeviceguids windowscodecs wininet wbemuuid wintrust wtsapi32) ifdef ACCESSIBILITY OS_LIBS += $(call EXPAND_LIBNAME,oleacc) endif diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp index af1fbd18409f..54ca46b77b6c 100644 --- a/widget/windows/nsWindow.cpp +++ b/widget/windows/nsWindow.cpp @@ -66,6 +66,7 @@ #include #include +#include #include #include #include @@ -606,6 +607,14 @@ nsWindow::Create(nsIWidget *aParent, SubclassWindow(TRUE); + // Starting with Windows XP, a process always runs within a terminal services + // session. In order to play nicely with RDP, fast user switching, and the + // lock screen, we should be handling WM_WTSSESSION_CHANGE. We must register + // our HWND in order to receive this message. + DebugOnly wtsRegistered = ::WTSRegisterSessionNotification(mWnd, + NOTIFY_FOR_THIS_SESSION); + NS_ASSERTION(wtsRegistered, "WTSRegisterSessionNotification failed!\n"); + IMEHandler::InitInputContext(this, mInputContext); // If the internal variable set by the config.trim_on_minimize pref has not @@ -4569,6 +4578,21 @@ nsWindow::ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam, } break; + case WM_WTSSESSION_CHANGE: + { + switch (wParam) { + case WTS_CONSOLE_CONNECT: + case WTS_REMOTE_CONNECT: + case WTS_SESSION_UNLOCK: + // When a session becomes visible, we should invalidate. + Invalidate(true, true, true); + break; + default: + break; + } + } + break; + case WM_FONTCHANGE: { // We only handle this message for the hidden window, @@ -6401,6 +6425,9 @@ void nsWindow::OnDestroy() mWidgetListener = nullptr; mAttachedWidgetListener = nullptr; + // Unregister notifications from terminal services + ::WTSUnRegisterSessionNotification(mWnd); + // Free our subclass and clear |this| stored in the window props. We will no longer // receive events from Windows after this point. SubclassWindow(FALSE);