Commit ffc5778e authored by David Bienvenu's avatar David Bienvenu Committed by Commit Bot

desktop-pwas: Add GetApplicationForProgId method to ShellUtil.

This will be used to find hard links to or copies of web_app_shim.exe
for a particular installed PWA, so they can be updated or deleted
when the PWA is uninstalled.

Bug: 960245
Change-Id: I62d6d6e263d0fdcdb2c5d4f89435cb657dd73a19
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1849417
Commit-Queue: David Bienvenu <davidbienvenu@chromium.org>
Reviewed-by: default avatarGreg Thompson <grt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705941}
parent eef6a093
......@@ -2479,6 +2479,22 @@ bool ShellUtil::DeleteFileAssociations(const base::string16& prog_id) {
WorkItem::kWow64Default);
}
// static
base::FilePath ShellUtil::GetApplicationPathForProgId(
const base::string16& prog_id) {
base::string16 prog_id_path(kRegClasses);
prog_id_path.push_back(base::FilePath::kSeparators[0]);
prog_id_path.append(prog_id);
prog_id_path.append(kRegShellOpen);
base::string16 command_line;
RegKey command_line_key(HKEY_CURRENT_USER, prog_id_path.c_str(),
KEY_QUERY_VALUE);
if (command_line_key.ReadValue(L"", &command_line) == ERROR_SUCCESS)
return base::CommandLine::FromString(command_line).GetProgram();
return base::FilePath();
}
// static
bool ShellUtil::AddRegistryEntries(
HKEY root,
......
......@@ -651,6 +651,14 @@ class ShellUtil {
// with this name will be deleted.
static bool DeleteFileAssociations(const base::string16& prog_id);
// Retrieves the file path of the application registered as the
// shell->open->command for |prog_id|. This only queries the user's
// registered applications in HKCU. If |prog_id| is for an app that is
// unrelated to the user's browser, it will still return the application
// registered for |prog_id|.
static base::FilePath GetApplicationPathForProgId(
const base::string16& prog_id);
// This method converts all the RegistryEntries from the given list to
// Set/CreateRegWorkItems and runs them using WorkItemList.
static bool AddRegistryEntries(
......
......@@ -903,7 +903,7 @@ TEST_F(ShellUtilRegistryTest, AddFileAssociations) {
TEST_F(ShellUtilRegistryTest, DeleteFileAssociations) {
// Create file associations.
EXPECT_TRUE(ShellUtil::AddFileAssociations(
ASSERT_TRUE(ShellUtil::AddFileAssociations(
kTestProgid, OpenCommand(), kTestApplicationName, kTestFileTypeName,
base::FilePath(kTestIconPath), FileExtensions()));
......@@ -940,6 +940,15 @@ TEST_F(ShellUtilRegistryTest, DeleteFileAssociations) {
EXPECT_EQ(L"SomeOtherApp", value);
}
TEST_F(ShellUtilRegistryTest, GetApplicationForProgId) {
// Create file associations.
ASSERT_TRUE(ShellUtil::AddFileAssociations(
kTestProgid, OpenCommand(), kTestApplicationName, kTestFileTypeName,
base::FilePath(kTestIconPath), FileExtensions()));
base::FilePath exe_path = ShellUtil::GetApplicationPathForProgId(kTestProgid);
EXPECT_EQ(exe_path, base::FilePath(kTestOpenCommand));
}
TEST(ShellUtilTest, BuildAppModelIdBasic) {
std::vector<base::string16> components;
const base::string16 base_app_id(install_static::GetBaseAppId());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment