Commit cf430c01 authored by Jesse McKenna's avatar Jesse McKenna Committed by Commit Bot

Reland "desktop-pwas: Set display name for Open With menu"

This relands crrev.com/c/1810242, reverted by crrev.com/c/1815802.

Unit test ShellUtilRegistryTest.AddFileAssociations was failing on
Windows 7 bots when checking for registry key
HKCU\Software\Classes\<progID>\Application, because this key is only
created by ShellUtil::AddFileAssociations() on Windows 8 and later. I
changed this CHECK() to only take place when on Windows 8 or later.

Original change description:

When an application is registered as a handler for a file type, the name
that is displayed in the "Open With..." menu for that file type is
controlled by registry value
HKCR/<application ProgID>/Application::ApplicationName.

This change extends ShellUtil::AddFileAssociations(), which will soon be
used to register Progressive Web Apps (PWAs) as file handlers on
Windows, to set ApplicationName. This enables PWAs registered as file
handlers to appear in the "Open With..." menu with a readable display
name such as "My PWA".

Bug: 960245
Change-Id: I0790faa2b3eedec82ace2c324ff582515af048aa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1818429
Commit-Queue: Jesse McKenna <jessemckenna@google.com>
Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699518}
parent 0880f2d6
...@@ -2386,6 +2386,7 @@ bool ShellUtil::GetOldUserSpecificRegistrySuffix(base::string16* suffix) { ...@@ -2386,6 +2386,7 @@ bool ShellUtil::GetOldUserSpecificRegistrySuffix(base::string16* suffix) {
bool ShellUtil::AddFileAssociations( bool ShellUtil::AddFileAssociations(
const base::string16& prog_id, const base::string16& prog_id,
const base::CommandLine& command_line, const base::CommandLine& command_line,
const base::string16& application_name,
const base::string16& file_type_name, const base::string16& file_type_name,
const base::FilePath& icon_path, const base::FilePath& icon_path,
const std::set<base::string16>& file_extensions) { const std::set<base::string16>& file_extensions) {
...@@ -2394,6 +2395,7 @@ bool ShellUtil::AddFileAssociations( ...@@ -2394,6 +2395,7 @@ bool ShellUtil::AddFileAssociations(
// Create a class for this app. // Create a class for this app.
ApplicationInfo app_info; ApplicationInfo app_info;
app_info.prog_id = prog_id; app_info.prog_id = prog_id;
app_info.application_name = application_name;
app_info.file_type_name = file_type_name; app_info.file_type_name = file_type_name;
app_info.file_type_icon_path = icon_path; app_info.file_type_icon_path = icon_path;
app_info.file_type_icon_index = 0; app_info.file_type_icon_index = 0;
......
...@@ -628,6 +628,8 @@ class ShellUtil { ...@@ -628,6 +628,8 @@ class ShellUtil {
// |command_line| is the command to execute when opening a file via this // |command_line| is the command to execute when opening a file via this
// association. It should contain "%1" (to tell Windows to pass the filename // association. It should contain "%1" (to tell Windows to pass the filename
// as an argument). // as an argument).
// |application_name| is the friendly name displayed for this application in
// the Open With menu.
// |file_type_name| and |icon_path| are the friendly name, and the path of the // |file_type_name| and |icon_path| are the friendly name, and the path of the
// icon, respectively, that will be used for files of these types when // icon, respectively, that will be used for files of these types when
// associated with this application by default. (They are NOT the name/icon // associated with this application by default. (They are NOT the name/icon
...@@ -638,6 +640,7 @@ class ShellUtil { ...@@ -638,6 +640,7 @@ class ShellUtil {
static bool AddFileAssociations( static bool AddFileAssociations(
const base::string16& prog_id, const base::string16& prog_id,
const base::CommandLine& command_line, const base::CommandLine& command_line,
const base::string16& application_name,
const base::string16& file_type_name, const base::string16& file_type_name,
const base::FilePath& icon_path, const base::FilePath& icon_path,
const std::set<base::string16>& file_extensions); const std::set<base::string16>& file_extensions);
......
...@@ -41,6 +41,7 @@ const wchar_t kOtherIco[] = L"other.ico"; ...@@ -41,6 +41,7 @@ const wchar_t kOtherIco[] = L"other.ico";
// For registry tests. // For registry tests.
const wchar_t kTestProgid[] = L"TestApp"; const wchar_t kTestProgid[] = L"TestApp";
const wchar_t kTestOpenCommand[] = L"C:\\test.exe"; const wchar_t kTestOpenCommand[] = L"C:\\test.exe";
const wchar_t kTestApplicationName[] = L"Test Application";
const wchar_t kTestFileTypeName[] = L"Test File Type"; const wchar_t kTestFileTypeName[] = L"Test File Type";
const wchar_t kTestIconPath[] = L"D:\\test.ico"; const wchar_t kTestIconPath[] = L"D:\\test.ico";
const wchar_t* kTestFileExtensions[] = { const wchar_t* kTestFileExtensions[] = {
...@@ -832,11 +833,9 @@ class ShellUtilRegistryTest : public testing::Test { ...@@ -832,11 +833,9 @@ class ShellUtilRegistryTest : public testing::Test {
TEST_F(ShellUtilRegistryTest, AddFileAssociations) { TEST_F(ShellUtilRegistryTest, AddFileAssociations) {
// Create file associations. // Create file associations.
EXPECT_TRUE(ShellUtil::AddFileAssociations(kTestProgid, EXPECT_TRUE(ShellUtil::AddFileAssociations(
OpenCommand(), kTestProgid, OpenCommand(), kTestApplicationName, kTestFileTypeName,
kTestFileTypeName, base::FilePath(kTestIconPath), FileExtensions()));
base::FilePath(kTestIconPath),
FileExtensions()));
// Ensure that the registry keys have been correctly set. // Ensure that the registry keys have been correctly set.
base::win::RegKey key; base::win::RegKey key;
...@@ -861,6 +860,15 @@ TEST_F(ShellUtilRegistryTest, AddFileAssociations) { ...@@ -861,6 +860,15 @@ TEST_F(ShellUtilRegistryTest, AddFileAssociations) {
EXPECT_EQ(ERROR_SUCCESS, key.ReadValue(L"", &value)); EXPECT_EQ(ERROR_SUCCESS, key.ReadValue(L"", &value));
EXPECT_EQ(L"\"C:\\test.exe\" \"%1\"", value); EXPECT_EQ(L"\"C:\\test.exe\" \"%1\"", value);
// The Application subkey and values are only required by Windows 8 and later.
if (base::win::GetVersion() >= base::win::Version::WIN8) {
ASSERT_EQ(ERROR_SUCCESS,
key.Open(HKEY_CURRENT_USER,
L"Software\\Classes\\TestApp\\Application", KEY_READ));
EXPECT_EQ(ERROR_SUCCESS, key.ReadValue(L"ApplicationName", &value));
EXPECT_EQ(L"Test Application", value);
}
// .test1 should be default-associated with our test app. // .test1 should be default-associated with our test app.
ASSERT_EQ( ASSERT_EQ(
ERROR_SUCCESS, ERROR_SUCCESS,
...@@ -893,11 +901,9 @@ TEST_F(ShellUtilRegistryTest, AddFileAssociations) { ...@@ -893,11 +901,9 @@ TEST_F(ShellUtilRegistryTest, AddFileAssociations) {
TEST_F(ShellUtilRegistryTest, DeleteFileAssociations) { TEST_F(ShellUtilRegistryTest, DeleteFileAssociations) {
// Create file associations. // Create file associations.
EXPECT_TRUE(ShellUtil::AddFileAssociations(kTestProgid, EXPECT_TRUE(ShellUtil::AddFileAssociations(
OpenCommand(), kTestProgid, OpenCommand(), kTestApplicationName, kTestFileTypeName,
kTestFileTypeName, base::FilePath(kTestIconPath), FileExtensions()));
base::FilePath(kTestIconPath),
FileExtensions()));
// Delete them. // Delete them.
EXPECT_TRUE(ShellUtil::DeleteFileAssociations(kTestProgid)); EXPECT_TRUE(ShellUtil::DeleteFileAssociations(kTestProgid));
......
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