Skip to content

Commit

Permalink
Delay loading GetCurrentPackageFullName
Browse files Browse the repository at this point in the history
MSIX only anyways
  • Loading branch information
K4sum1 committed Jan 27, 2024
1 parent f2cb153 commit d09e8b7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
13 changes: 11 additions & 2 deletions browser/components/shell/WindowsUserChoice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include "nsDebug.h"
#include "mozilla/ArrayUtils.h"
#include "mozilla/DynamicallyLinkedFunctionPtr.h"
#include "mozilla/UniquePtr.h"
#include "nsWindowsHelpers.h"

Expand Down Expand Up @@ -429,12 +430,20 @@ nsresult GetMsixProgId(const wchar_t* assoc, UniquePtr<wchar_t[]>& 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<decltype(&GetCurrentPackageFullName)>
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<wchar_t[]>(pfnLen);
rv = GetCurrentPackageFullName(&pfnLen, pfn.get());
rv = pGetCurrentPackageFullName(&pfnLen, pfn.get());
NS_ENSURE_TRUE(rv == ERROR_SUCCESS, NS_ERROR_FAILURE);

const wchar_t* assocSuffix;
Expand Down
14 changes: 12 additions & 2 deletions toolkit/mozapps/defaultagent/SetDefaultBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -301,10 +302,19 @@ nsresult SetDefaultExtensionHandlersUserChoice(
nsresult SetDefaultExtensionHandlersUserChoiceImpl(
const wchar_t* aAumi, const wchar_t* const aSid,
const nsTArray<nsString>& aFileExtensions) {

// `GetCurrentPackageFullName` added in Windows 8.
DynamicallyLinkedFunctionPtr<decltype(&GetCurrentPackageFullName)>
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
Expand Down

0 comments on commit d09e8b7

Please sign in to comment.