Skip to content

Commit d09e8b7

Browse files
committed
Delay loading GetCurrentPackageFullName
MSIX only anyways
1 parent f2cb153 commit d09e8b7

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

browser/components/shell/WindowsUserChoice.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include "nsDebug.h"
3030
#include "mozilla/ArrayUtils.h"
31+
#include "mozilla/DynamicallyLinkedFunctionPtr.h"
3132
#include "mozilla/UniquePtr.h"
3233
#include "nsWindowsHelpers.h"
3334

@@ -429,12 +430,20 @@ nsresult GetMsixProgId(const wchar_t* assoc, UniquePtr<wchar_t[]>& aProgId) {
429430
// HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\Repository\Packages\[Package Full Name]\App\Capabilities\[FileAssociations | URLAssociations]\[File | URL]
430431
// clang-format on
431432

433+
// `GetCurrentPackageFullName` added in Windows 8.
434+
DynamicallyLinkedFunctionPtr<decltype(&GetCurrentPackageFullName)>
435+
pGetCurrentPackageFullName(L"kernel32.dll",
436+
"GetCurrentPackageFullName");
437+
if (!pGetCurrentPackageFullName) {
438+
return NS_OK;
439+
}
440+
432441
UINT32 pfnLen = 0;
433-
LONG rv = GetCurrentPackageFullName(&pfnLen, nullptr);
442+
LONG rv = pGetCurrentPackageFullName(&pfnLen, nullptr);
434443
NS_ENSURE_TRUE(rv != APPMODEL_ERROR_NO_PACKAGE, NS_ERROR_FAILURE);
435444

436445
auto pfn = mozilla::MakeUnique<wchar_t[]>(pfnLen);
437-
rv = GetCurrentPackageFullName(&pfnLen, pfn.get());
446+
rv = pGetCurrentPackageFullName(&pfnLen, pfn.get());
438447
NS_ENSURE_TRUE(rv == ERROR_SUCCESS, NS_ERROR_FAILURE);
439448

440449
const wchar_t* assocSuffix;

toolkit/mozapps/defaultagent/SetDefaultBrowser.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "mozilla/ArrayUtils.h"
1313
#include "mozilla/CmdLineAndEnvUtils.h"
14+
#include "mozilla/DynamicallyLinkedFunctionPtr.h"
1415
#include "mozilla/RefPtr.h"
1516
#include "mozilla/UniquePtr.h"
1617
#include "mozilla/WindowsVersion.h"
@@ -301,10 +302,19 @@ nsresult SetDefaultExtensionHandlersUserChoice(
301302
nsresult SetDefaultExtensionHandlersUserChoiceImpl(
302303
const wchar_t* aAumi, const wchar_t* const aSid,
303304
const nsTArray<nsString>& aFileExtensions) {
305+
306+
// `GetCurrentPackageFullName` added in Windows 8.
307+
DynamicallyLinkedFunctionPtr<decltype(&GetCurrentPackageFullName)>
308+
pGetCurrentPackageFullName(L"kernel32.dll",
309+
"GetCurrentPackageFullName");
310+
if (!pGetCurrentPackageFullName) {
311+
return NS_OK;
312+
}
313+
304314
UINT32 pfnLen = 0;
305315
bool inMsix =
306-
GetCurrentPackageFullName(&pfnLen, nullptr) != APPMODEL_ERROR_NO_PACKAGE;
307-
316+
pGetCurrentPackageFullName(&pfnLen, nullptr) != APPMODEL_ERROR_NO_PACKAGE;
317+
308318
if (inMsix) {
309319
// MSIX packages can not meaningfully modify the registry keys related to
310320
// default handlers

0 commit comments

Comments
 (0)