From d09e8b7fbbf3817373ad1c6c7e6150b0b24b06b2 Mon Sep 17 00:00:00 2001 From: K4sum1 Date: Mon, 22 Jan 2024 03:30:24 -0800 Subject: [PATCH] Delay loading GetCurrentPackageFullName MSIX only anyways --- browser/components/shell/WindowsUserChoice.cpp | 13 +++++++++++-- toolkit/mozapps/defaultagent/SetDefaultBrowser.cpp | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/browser/components/shell/WindowsUserChoice.cpp b/browser/components/shell/WindowsUserChoice.cpp index baa3e7286e111..7df8fc0938425 100644 --- a/browser/components/shell/WindowsUserChoice.cpp +++ b/browser/components/shell/WindowsUserChoice.cpp @@ -28,6 +28,7 @@ #include "nsDebug.h" #include "mozilla/ArrayUtils.h" +#include "mozilla/DynamicallyLinkedFunctionPtr.h" #include "mozilla/UniquePtr.h" #include "nsWindowsHelpers.h" @@ -429,12 +430,20 @@ nsresult GetMsixProgId(const wchar_t* assoc, UniquePtr& aProgId) { // HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\Repository\Packages\[Package Full Name]\App\Capabilities\[FileAssociations | URLAssociations]\[File | URL] // clang-format on + // `GetCurrentPackageFullName` added in Windows 8. + DynamicallyLinkedFunctionPtr + pGetCurrentPackageFullName(L"kernel32.dll", + "GetCurrentPackageFullName"); + if (!pGetCurrentPackageFullName) { + return NS_OK; + } + UINT32 pfnLen = 0; - LONG rv = GetCurrentPackageFullName(&pfnLen, nullptr); + LONG rv = pGetCurrentPackageFullName(&pfnLen, nullptr); NS_ENSURE_TRUE(rv != APPMODEL_ERROR_NO_PACKAGE, NS_ERROR_FAILURE); auto pfn = mozilla::MakeUnique(pfnLen); - rv = GetCurrentPackageFullName(&pfnLen, pfn.get()); + rv = pGetCurrentPackageFullName(&pfnLen, pfn.get()); NS_ENSURE_TRUE(rv == ERROR_SUCCESS, NS_ERROR_FAILURE); const wchar_t* assocSuffix; diff --git a/toolkit/mozapps/defaultagent/SetDefaultBrowser.cpp b/toolkit/mozapps/defaultagent/SetDefaultBrowser.cpp index 8bc0889e67655..2a1481b7b90b2 100644 --- a/toolkit/mozapps/defaultagent/SetDefaultBrowser.cpp +++ b/toolkit/mozapps/defaultagent/SetDefaultBrowser.cpp @@ -11,6 +11,7 @@ #include "mozilla/ArrayUtils.h" #include "mozilla/CmdLineAndEnvUtils.h" +#include "mozilla/DynamicallyLinkedFunctionPtr.h" #include "mozilla/RefPtr.h" #include "mozilla/UniquePtr.h" #include "mozilla/WindowsVersion.h" @@ -301,10 +302,19 @@ nsresult SetDefaultExtensionHandlersUserChoice( nsresult SetDefaultExtensionHandlersUserChoiceImpl( const wchar_t* aAumi, const wchar_t* const aSid, const nsTArray& aFileExtensions) { + + // `GetCurrentPackageFullName` added in Windows 8. + DynamicallyLinkedFunctionPtr + pGetCurrentPackageFullName(L"kernel32.dll", + "GetCurrentPackageFullName"); + if (!pGetCurrentPackageFullName) { + return NS_OK; + } + UINT32 pfnLen = 0; bool inMsix = - GetCurrentPackageFullName(&pfnLen, nullptr) != APPMODEL_ERROR_NO_PACKAGE; - + pGetCurrentPackageFullName(&pfnLen, nullptr) != APPMODEL_ERROR_NO_PACKAGE; + if (inMsix) { // MSIX packages can not meaningfully modify the registry keys related to // default handlers