Skip to content

Commit

Permalink
Backed out changeset c6d6218c85ae (bug 1818418) for causing bug 1863980.
Browse files Browse the repository at this point in the history
  • Loading branch information
rvandermeulen committed Jan 8, 2024
1 parent b04d697 commit 2684c49
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 300 deletions.
52 changes: 0 additions & 52 deletions browser/components/shell/WindowsUserChoice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
*/

#include <windows.h>
#include <appmodel.h> // for GetPackageFamilyName
#include <sddl.h> // for ConvertSidToStringSidW
#include <wincrypt.h> // for CryptoAPI base64
#include <bcrypt.h> // for CNG MD5
#include <winternl.h> // for NT_SUCCESS()

#include "nsDebug.h"
#include "mozilla/ArrayUtils.h"
#include "mozilla/UniquePtr.h"
#include "nsWindowsHelpers.h"
Expand Down Expand Up @@ -422,53 +420,3 @@ bool CheckProgIDExists(const wchar_t* aProgID) {
::RegCloseKey(key);
return true;
}

nsresult GetMsixProgId(const wchar_t* assoc, UniquePtr<wchar_t[]>& aProgId) {
// Retrieve the registry path to the package from registry path:
// clang-format off
// HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\Repository\Packages\[Package Full Name]\App\Capabilities\[FileAssociations | URLAssociations]\[File | URL]
// clang-format on

UINT32 pfnLen = 0;
LONG rv = GetCurrentPackageFullName(&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());
NS_ENSURE_TRUE(rv == ERROR_SUCCESS, NS_ERROR_FAILURE);

const wchar_t* assocSuffix;
if (assoc[0] == L'.') {
// File association.
assocSuffix = LR"(App\Capabilities\FileAssociations)";
} else {
// URL association.
assocSuffix = LR"(App\Capabilities\URLAssociations)";
}

const wchar_t* assocPathFmt =
LR"(Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\Repository\Packages\%s\%s)";
int assocPathLen = _scwprintf(assocPathFmt, pfn.get(), assocSuffix);
assocPathLen += 1; // _scwprintf does not include the terminator

auto assocPath = MakeUnique<wchar_t[]>(assocPathLen);
_snwprintf_s(assocPath.get(), assocPathLen, _TRUNCATE, assocPathFmt,
pfn.get(), assocSuffix);

LSTATUS ls;

// Retrieve the package association's ProgID, always in the form `AppX[32 hash
// characters]`.
const size_t appxProgIdLen = 37;
auto progId = MakeUnique<wchar_t[]>(appxProgIdLen);
DWORD progIdLen = appxProgIdLen * sizeof(wchar_t);
ls = ::RegGetValueW(HKEY_CLASSES_ROOT, assocPath.get(), assoc, RRF_RT_REG_SZ,
nullptr, (LPBYTE)progId.get(), &progIdLen);
if (ls != ERROR_SUCCESS) {
return NS_ERROR_WDBA_NO_PROGID;
}

aProgId.swap(progId);

return NS_OK;
}
14 changes: 0 additions & 14 deletions browser/components/shell/WindowsUserChoice.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include <windows.h>

#include "ErrorList.h" // for nsresult
#include "mozilla/UniquePtr.h"

/*
Expand Down Expand Up @@ -101,17 +100,4 @@ mozilla::UniquePtr<wchar_t[]> FormatProgID(const wchar_t* aProgIDBase,
*/
bool CheckProgIDExists(const wchar_t* aProgID);

/*
* Get the ProgID registered by Windows for the given association.
*
* The MSIX `AppManifest.xml` declares supported protocols and file
* type associations. Upon installation, Windows generates
* corresponding ProgIDs for them, of the form `AppX*`. This function
* retrieves those generated ProgIDs (from the Windows registry).
*
* @return ProgID.
*/
nsresult GetMsixProgId(const wchar_t* assoc,
mozilla::UniquePtr<wchar_t[]>& aProgId);

#endif // SHELL_WINDOWSUSERCHOICE_H__
39 changes: 4 additions & 35 deletions browser/components/shell/nsWindowsShellService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,41 +300,10 @@ nsWindowsShellService::CheckAllProgIDsExist(bool* aResult) {
if (!mozilla::widget::WinTaskbar::GetAppUserModelID(aumid)) {
return NS_OK;
}

if (widget::WinUtils::HasPackageIdentity()) {
UniquePtr<wchar_t[]> extraProgID;
nsresult rv;
bool result = true;

// "FirefoxURL".
rv = GetMsixProgId(L"https", extraProgID);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
result = result && CheckProgIDExists(extraProgID.get());

// "FirefoxHTML".
rv = GetMsixProgId(L".htm", extraProgID);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
result = result && CheckProgIDExists(extraProgID.get());

// "FirefoxPDF".
rv = GetMsixProgId(L".pdf", extraProgID);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
result = result && CheckProgIDExists(extraProgID.get());

*aResult = result;
} else {
*aResult =
CheckProgIDExists(FormatProgID(L"FirefoxURL", aumid.get()).get()) &&
CheckProgIDExists(FormatProgID(L"FirefoxHTML", aumid.get()).get()) &&
CheckProgIDExists(FormatProgID(L"FirefoxPDF", aumid.get()).get());
}

*aResult =
CheckProgIDExists(FormatProgID(L"FirefoxURL", aumid.get()).get()) &&
CheckProgIDExists(FormatProgID(L"FirefoxHTML", aumid.get()).get()) &&
CheckProgIDExists(FormatProgID(L"FirefoxPDF", aumid.get()).get());
return NS_OK;
}

Expand Down
5 changes: 3 additions & 2 deletions python/mozbuild/mozbuild/repackaging/msix.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,9 @@ def get_branding(use_official, topsrcdir, build_app, finder, log=None):
conf_vars = mozpath.join(topsrcdir, build_app, "confvars.sh")

def conf_vars_value(key):
lines = [line.strip() for line in open(conf_vars).readlines()]
lines = open(conf_vars).readlines()
for line in lines:
line = line.strip()
if line and line[0] == "#":
continue
if key not in line:
Expand Down Expand Up @@ -832,7 +833,7 @@ def powershell(argstring, check=True):
else:
thumbprint = None

if force or not thumbprint:
if not thumbprint:
thumbprint = (
powershell(
(
Expand Down
Loading

0 comments on commit 2684c49

Please sign in to comment.