Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 0e4dea8

Browse files
committed
Bug 1709131 - Report whether the current process has a package identity. r=mhowell
Differential Revision: https://phabricator.services.mozilla.com/D114427
1 parent 71c872b commit 0e4dea8

3 files changed

Lines changed: 31 additions & 0 deletions

File tree

widget/windows/WinUtils.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ struct CoTaskMemFreePolicy {
429429
SetThreadDpiAwarenessContextProc WinUtils::sSetThreadDpiAwarenessContext = NULL;
430430
EnableNonClientDpiScalingProc WinUtils::sEnableNonClientDpiScaling = NULL;
431431
GetSystemMetricsForDpiProc WinUtils::sGetSystemMetricsForDpi = NULL;
432+
bool WinUtils::sHasPackageIdentity = false;
432433

433434
/* static */
434435
void WinUtils::Initialize() {
@@ -461,6 +462,24 @@ void WinUtils::Initialize() {
461462
user32Dll, "GetSystemMetricsForDpi");
462463
}
463464
}
465+
466+
if (IsWin8OrLater()) {
467+
HMODULE kernel32Dll = ::GetModuleHandleW(L"kernel32");
468+
if (kernel32Dll) {
469+
typedef LONG(WINAPI * GetCurrentPackageIdProc)(UINT32*, BYTE*);
470+
GetCurrentPackageIdProc pGetCurrentPackageId =
471+
(GetCurrentPackageIdProc)::GetProcAddress(kernel32Dll,
472+
"GetCurrentPackageId");
473+
474+
// If there was any package identity to retrieve, we get
475+
// ERROR_INSUFFICIENT_BUFFER. If there had been no package identity it
476+
// would instead return APPMODEL_ERROR_NO_PACKAGE.
477+
UINT32 packageNameSize = 0;
478+
sHasPackageIdentity = pGetCurrentPackageId &&
479+
(pGetCurrentPackageId(&packageNameSize, nullptr) ==
480+
ERROR_INSUFFICIENT_BUFFER);
481+
}
482+
}
464483
}
465484

466485
// static

widget/windows/WinUtils.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ class WinUtils {
145145
static EnableNonClientDpiScalingProc sEnableNonClientDpiScaling;
146146
static GetSystemMetricsForDpiProc sGetSystemMetricsForDpi;
147147

148+
// Set on Initialize().
149+
static bool sHasPackageIdentity;
150+
148151
public:
149152
class AutoSystemDpiAware {
150153
public:
@@ -218,6 +221,8 @@ class WinUtils {
218221
*/
219222
static gfx::MarginDouble GetUnwriteableMarginsForDeviceInInches(HDC aHdc);
220223

224+
static bool HasPackageIdentity() { return sHasPackageIdentity; }
225+
221226
/**
222227
* Logging helpers that dump output to prlog module 'Widget', console, and
223228
* OutputDebugString. Note these output in both debug and release builds.

xpcom/base/nsSystemInfo.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
# include "nsDirectoryServiceDefs.h"
3535
# include "nsDirectoryServiceUtils.h"
3636
# include "nsWindowsHelpers.h"
37+
# include "WinUtils.h"
3738

3839
#endif
3940

@@ -932,6 +933,12 @@ nsresult nsSystemInfo::Init() {
932933
return rv;
933934
}
934935

936+
rv = SetPropertyAsBool(u"hasWinPackageId"_ns,
937+
widget::WinUtils::HasPackageIdentity());
938+
if (NS_WARN_IF(NS_FAILED(rv))) {
939+
return rv;
940+
}
941+
935942
# ifndef __MINGW32__
936943
nsAutoString avInfo, antiSpyInfo, firewallInfo;
937944
if (NS_SUCCEEDED(

0 commit comments

Comments
 (0)