diff --git a/browser/app/firefox.exe.manifest b/browser/app/firefox.exe.manifest index 995b2fc869c1..1e1d6f651d27 100644 --- a/browser/app/firefox.exe.manifest +++ b/browser/app/firefox.exe.manifest @@ -36,6 +36,12 @@ + + + True/PM + PerMonitorV2,PerMonitor + + diff --git a/browser/app/nsBrowserApp.cpp b/browser/app/nsBrowserApp.cpp index 3e95186df58a..12ed20d3b00d 100644 --- a/browser/app/nsBrowserApp.cpp +++ b/browser/app/nsBrowserApp.cpp @@ -28,7 +28,6 @@ # include "freestanding/SharedSection.h" # include "LauncherProcessWin.h" # include "mozilla/WindowsDllBlocklist.h" -# include "mozilla/WindowsDpiInitialization.h" # define XRE_WANT_ENVIRON # define strcasecmp _stricmp @@ -297,22 +296,6 @@ int main(int argc, char* argv[], char* envp[]) { DllBlocklist_Initialize(gBlocklistInitFlags | eDllBlocklistInitFlagIsChildProcess); # endif -# if defined(XP_WIN) - // Ideally, we would be able to set our DPI awareness in - // firefox.exe.manifest Unfortunately, that would cause Win32k calls when - // user32.dll gets loaded, which would be incompatible with Win32k Lockdown - // - // MSDN says that it's allowed-but-not-recommended to initialize DPI - // programatically, as long as it's done before any HWNDs are created. - // Thus, we do it almost as soon as we possibly can - { - auto result = mozilla::WindowsDpiInitialization(); - if (result != WindowsDpiInitializationResult::Success) { - Output(WindowsDpiInitializationResultString(result)); - return 255; - } - } -# endif # if defined(XP_WIN) && defined(MOZ_SANDBOX) // We need to initialize the sandbox TargetServices before InitXPCOMGlue // because we might need the sandbox broker to give access to some files. @@ -345,22 +328,6 @@ int main(int argc, char* argv[], char* envp[]) { #endif #if defined(XP_WIN) - - // Ideally, we would be able to set our DPI awareness in firefox.exe.manifest - // Unfortunately, that would cause Win32k calls when user32.dll gets loaded, - // which would be incompatible with Win32k Lockdown - // - // MSDN says that it's allowed-but-not-recommended to initialize DPI - // programatically, as long as it's done before any HWNDs are created. - // Thus, we do it almost as soon as we possibly can - { - auto result = mozilla::WindowsDpiInitialization(); - if (result != WindowsDpiInitializationResult::Success) { - Output(WindowsDpiInitializationResultString(result)); - return 255; - } - } - // Once the browser process hits the main function, we no longer need // a writable section handle because all dependent modules have been // loaded. diff --git a/mozglue/misc/WindowsDpiInitialization.cpp b/mozglue/misc/WindowsDpiInitialization.cpp deleted file mode 100644 index 2e957b583012..000000000000 --- a/mozglue/misc/WindowsDpiInitialization.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "mozilla/WindowsDpiInitialization.h" - -#include "mozilla/DynamicallyLinkedFunctionPtr.h" -#include "mozilla/WindowsProcessMitigations.h" -#include "mozilla/WindowsVersion.h" - -#include -#include - -namespace mozilla { - -typedef HRESULT(WINAPI* SetProcessDpiAwarenessType)(PROCESS_DPI_AWARENESS); -typedef BOOL(WINAPI* SetProcessDpiAwarenessContextType)(DPI_AWARENESS_CONTEXT); - -WindowsDpiInitializationResult WindowsDpiInitialization() { - // DPI Awareness can't be used in a Win32k Lockdown process, so there's - // nothing to do - if (IsWin32kLockedDown()) { - return WindowsDpiInitializationResult::Success; - } - - // From MSDN: - // SetProcessDpiAwarenessContext() was added in the Win10 Anniversary Update - // SetProcessDpiAwareness() was added in Windows 8.1 - // SetProcessDpiAware() was added in Windows Vista - // - // DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 wasn't added later until - // the Creators Update, so if it fails we just fall back to - // DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE - if (IsWin10AnniversaryUpdateOrLater()) { - DynamicallyLinkedFunctionPtr - setProcessDpiAwarenessContext(L"user32.dll", - "SetProcessDpiAwarenessContext"); - if (!setProcessDpiAwarenessContext) { - return WindowsDpiInitializationResult:: - FindSetProcessDpiAwarenessContextFailed; - } - - if (!setProcessDpiAwarenessContext( - DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2) && - !setProcessDpiAwarenessContext( - DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE)) { - return WindowsDpiInitializationResult:: - SetProcessDpiAwarenessContextFailed; - } - - return WindowsDpiInitializationResult::Success; - } else if (IsWin8Point1OrLater()) { - DynamicallyLinkedFunctionPtr - setProcessDpiAwareness(L"Shcore.dll", "SetProcessDpiAwareness"); - if (!setProcessDpiAwareness) { - return WindowsDpiInitializationResult::FindSetProcessDpiAwarenessFailed; - } - - if (FAILED(setProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE))) { - return WindowsDpiInitializationResult::SetProcessDpiAwarenessFailed; - } - - return WindowsDpiInitializationResult::Success; - } else { - if (!SetProcessDPIAware()) { - return WindowsDpiInitializationResult::SetProcessDPIAwareFailed; - } - - return WindowsDpiInitializationResult::Success; - } -} - -} // namespace mozilla diff --git a/mozglue/misc/WindowsDpiInitialization.h b/mozglue/misc/WindowsDpiInitialization.h deleted file mode 100644 index 5943d50526e3..000000000000 --- a/mozglue/misc/WindowsDpiInitialization.h +++ /dev/null @@ -1,54 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef MOZILLA_MOZGLUE_MISC_WINDOWSDPIINITIALIZATION_H_ -#define MOZILLA_MOZGLUE_MISC_WINDOWSDPIINITIALIZATION_H_ -#include "mozilla/Types.h" - -namespace mozilla { - -// The result codes that may be returned from WindowsDpiInitialization() -enum class WindowsDpiInitializationResult : uint32_t { - Success, - FindSetProcessDpiAwarenessContextFailed, - SetProcessDpiAwarenessContextFailed, - FindSetProcessDpiAwarenessFailed, - SetProcessDpiAwarenessFailed, - SetProcessDPIAwareFailed, -}; - -// Get a string representation of any WindowsDpiInitializationResult value -inline const char* WindowsDpiInitializationResultString( - WindowsDpiInitializationResult result) { - switch (result) { - case WindowsDpiInitializationResult::Success: - return "Success"; - case WindowsDpiInitializationResult:: - FindSetProcessDpiAwarenessContextFailed: - return "Failed to find SetProcessDpiAwarenessContext"; - case WindowsDpiInitializationResult::SetProcessDpiAwarenessContextFailed: - return "SetProcessDpiAwarenessContext failed"; - case WindowsDpiInitializationResult::FindSetProcessDpiAwarenessFailed: - return "Failed to find SetProcessDpiAwareness"; - case WindowsDpiInitializationResult::SetProcessDpiAwarenessFailed: - return "SetProcessDpiAwareness failed"; - case WindowsDpiInitializationResult::SetProcessDPIAwareFailed: - return "SetProcessDPIAware failed"; - default: - return "Unknown result"; - } -} - -// Initialize DPI awareness to the best available for the current OS -// According to MSDN, this will be: -// Per-Monitor V2 for Windows 10 Creators Update (1703) and later -// Per-Monitor V1 for Windows 8.1 and later -// System DPI for Vista and later (we don't support anything older) -// https://docs.microsoft.com/en-us/windows/win32/hidpi/high-dpi-desktop-application-development-on-windows -MFBT_API WindowsDpiInitializationResult WindowsDpiInitialization(); - -} // namespace mozilla - -#endif // MOZILLA_MOZGLUE_MISC_WINDOWSDPIINITIALIZATION_H_ diff --git a/mozglue/misc/moz.build b/mozglue/misc/moz.build index 36e472d6918a..45c2a7773ecf 100644 --- a/mozglue/misc/moz.build +++ b/mozglue/misc/moz.build @@ -59,7 +59,6 @@ if CONFIG["OS_ARCH"] == "WINNT": "DynamicallyLinkedFunctionPtr.h", "ImportDir.h", "NativeNt.h", - "WindowsDpiInitialization.h", "WindowsEnumProcessModules.h", "WindowsMapRemoteView.h", "WindowsProcessMitigations.h", @@ -70,7 +69,6 @@ if CONFIG["OS_ARCH"] == "WINNT": SOURCES += [ "PreXULSkeletonUI.cpp", "TimeStamp_windows.cpp", - "WindowsDpiInitialization.cpp", "WindowsMapRemoteView.cpp", "WindowsProcessMitigations.cpp", "WindowsUnicode.cpp", diff --git a/widget/windows/WinUtils.cpp b/widget/windows/WinUtils.cpp index 20a0e343528d..af4ae6840f3c 100644 --- a/widget/windows/WinUtils.cpp +++ b/widget/windows/WinUtils.cpp @@ -432,10 +432,7 @@ GetSystemMetricsForDpiProc WinUtils::sGetSystemMetricsForDpi = NULL; /* static */ void WinUtils::Initialize() { - // Dpi-Awareness is not supported with Win32k Lockdown enabled, so we don't - // initialize DPI-related members and assert later that nothing accidently - // uses these static members - if (IsWin10OrLater() && !IsWin32kLockedDown()) { + if (IsWin10OrLater()) { HMODULE user32Dll = ::GetModuleHandleW(L"user32"); if (user32Dll) { auto getThreadDpiAwarenessContext = @@ -467,8 +464,6 @@ void WinUtils::Initialize() { LRESULT WINAPI WinUtils::NonClientDpiScalingDefWindowProcW(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { - MOZ_DIAGNOSTIC_ASSERT(!IsWin32kLockedDown()); - // NOTE: this function was copied out into the body of the pre-XUL skeleton // UI window proc (PreXULSkeletonUI.cpp). If this function changes at any // point, we should probably factor this out and use it from both locations. @@ -667,13 +662,11 @@ WinUtils::MonitorFromRect(const gfx::Rect& rect) { /* static */ bool WinUtils::HasSystemMetricsForDpi() { - MOZ_DIAGNOSTIC_ASSERT(!IsWin32kLockedDown()); return (sGetSystemMetricsForDpi != NULL); } /* static */ int WinUtils::GetSystemMetricsForDpi(int nIndex, UINT dpi) { - MOZ_DIAGNOSTIC_ASSERT(!IsWin32kLockedDown()); if (HasSystemMetricsForDpi()) { return sGetSystemMetricsForDpi(nIndex, dpi); } else { diff --git a/widget/windows/WinUtils.h b/widget/windows/WinUtils.h index 515887931d22..18b5766a5689 100644 --- a/widget/windows/WinUtils.h +++ b/widget/windows/WinUtils.h @@ -38,7 +38,6 @@ #include "mozilla/UniquePtr.h" #include "mozilla/Vector.h" #include "mozilla/WindowsDpiAwareness.h" -#include "mozilla/WindowsProcessMitigations.h" #include "mozilla/gfx/2D.h" /** @@ -149,8 +148,6 @@ class WinUtils { class AutoSystemDpiAware { public: AutoSystemDpiAware() { - MOZ_DIAGNOSTIC_ASSERT(!IsWin32kLockedDown()); - if (sSetThreadDpiAwarenessContext) { mPrevContext = sSetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_SYSTEM_AWARE);