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

desktop-pwas: Multi-profile support for pwa file registration.

When the same app is installed in multiple profiles, the open with
context menu needs to distinguish between the different profiles.
We do this by adding the profile name in parentheses after the app name,
e.g., "foo app (Profile1)". This CL detects when registering and
unregistering an app changes the app from being installed in
multiple profiles or just a single profile, and updates the app name.

This is similar to the way we badge/unbadge pinned taskbar icons when
the user switches between having multiple profiles and
having a single-profile.

Bug: 960245
Change-Id: I4c2a50c55cd8ab45be05eb023b162afc4f634cd0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2023283
Commit-Queue: David Bienvenu <davidbienvenu@chromium.org>
Reviewed-by: default avatarAlexey Baskakov <loyso@chromium.org>
Reviewed-by: default avatarGreg Thompson <grt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738802}
parent d97c6e27
...@@ -14,8 +14,9 @@ ...@@ -14,8 +14,9 @@
namespace web_app { namespace web_app {
// Returns the Windows ProgId for the web app with the passed |app_id| in // Returns the Windows ProgId for the web app with the passed |app_id| in
// |profile|. // |profile_path|.
base::string16 GetProgIdForApp(Profile* profile, const AppId& app_id); base::string16 GetProgIdForApp(const base::FilePath& profile_path,
const AppId& app_id);
// The name of "Last Browser" file, where UpdateChromeExePath() stores the path // The name of "Last Browser" file, where UpdateChromeExePath() stores the path
// of the last Chrome executable to use the containing user-data directory. // of the last Chrome executable to use the containing user-data directory.
......
...@@ -1541,6 +1541,13 @@ ShellUtil::ShortcutProperties::ShortcutProperties( ...@@ -1541,6 +1541,13 @@ ShellUtil::ShortcutProperties::ShortcutProperties(
ShellUtil::ShortcutProperties::~ShortcutProperties() { ShellUtil::ShortcutProperties::~ShortcutProperties() {
} }
ShellUtil::FileAssociationsAndAppName::FileAssociationsAndAppName() = default;
ShellUtil::FileAssociationsAndAppName::FileAssociationsAndAppName(
FileAssociationsAndAppName&& other) = default;
ShellUtil::FileAssociationsAndAppName::~FileAssociationsAndAppName() = default;
bool ShellUtil::QuickIsChromeRegisteredInHKLM(const base::FilePath& chrome_exe, bool ShellUtil::QuickIsChromeRegisteredInHKLM(const base::FilePath& chrome_exe,
const base::string16& suffix) { const base::string16& suffix) {
return QuickIsChromeRegistered(chrome_exe, suffix, return QuickIsChromeRegistered(chrome_exe, suffix,
...@@ -2479,6 +2486,43 @@ bool ShellUtil::DeleteFileAssociations(const base::string16& prog_id) { ...@@ -2479,6 +2486,43 @@ bool ShellUtil::DeleteFileAssociations(const base::string16& prog_id) {
WorkItem::kWow64Default); WorkItem::kWow64Default);
} }
// static
ShellUtil::FileAssociationsAndAppName ShellUtil::GetFileAssociationsAndAppName(
const base::string16& prog_id) {
FileAssociationsAndAppName file_associations_and_app_name;
// Get list of handled file extensions from value FileExtensions at
// HKEY_CURRENT_USER\Software\Classes\|prog_id|.
base::string16 prog_id_path(kRegClasses);
prog_id_path.push_back(base::FilePath::kSeparators[0]);
prog_id_path.append(prog_id);
RegKey file_extensions_key(HKEY_CURRENT_USER, prog_id_path.c_str(),
KEY_QUERY_VALUE);
base::string16 handled_file_extensions;
if (file_extensions_key.ReadValue(
L"FileExtensions", &handled_file_extensions) != ERROR_SUCCESS) {
return FileAssociationsAndAppName();
}
std::vector<base::StringPiece16> file_associations_vec =
base::SplitStringPiece(base::StringPiece16(handled_file_extensions),
base::StringPiece16(L";"), base::TRIM_WHITESPACE,
base::SPLIT_WANT_NONEMPTY);
for (const auto& file_extension : file_associations_vec) {
// Skip over the leading '.' so that we return the same
// extensions as were passed to AddFileAssociations.
file_associations_and_app_name.file_associations.emplace(
file_extension.substr(1));
}
prog_id_path.append(kRegApplication);
RegKey prog_id_key(HKEY_CURRENT_USER, prog_id_path.c_str(), KEY_QUERY_VALUE);
if (prog_id_key.ReadValue(kRegApplicationName,
&file_associations_and_app_name.app_name) !=
ERROR_SUCCESS) {
return FileAssociationsAndAppName();
}
return file_associations_and_app_name;
}
// static // static
base::FilePath ShellUtil::GetApplicationPathForProgId( base::FilePath ShellUtil::GetApplicationPathForProgId(
const base::string16& prog_id) { const base::string16& prog_id) {
......
...@@ -222,6 +222,15 @@ class ShellUtil { ...@@ -222,6 +222,15 @@ class ShellUtil {
uint32_t options; uint32_t options;
}; };
struct FileAssociationsAndAppName {
FileAssociationsAndAppName();
FileAssociationsAndAppName(FileAssociationsAndAppName&& other);
~FileAssociationsAndAppName();
std::set<base::string16> file_associations;
base::string16 app_name;
};
// Relative path of the URL Protocol registry entry (prefixed with '\'). // Relative path of the URL Protocol registry entry (prefixed with '\').
static const wchar_t* kRegURLProtocol; static const wchar_t* kRegURLProtocol;
...@@ -651,6 +660,12 @@ class ShellUtil { ...@@ -651,6 +660,12 @@ class ShellUtil {
// with this name will be deleted. // with this name will be deleted.
static bool DeleteFileAssociations(const base::string16& prog_id); static bool DeleteFileAssociations(const base::string16& prog_id);
// Returns the app name and file associations registered for a particular
// application in the Windows registry. If there is no entry in the registry
// for |prog_id|, nothing will be returned.
static FileAssociationsAndAppName GetFileAssociationsAndAppName(
const base::string16& prog_id);
// Retrieves the file path of the application registered as the // Retrieves the file path of the application registered as the
// shell->open->command for |prog_id|. This only queries the user's // 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 // registered applications in HKCU. If |prog_id| is for an app that is
......
...@@ -940,6 +940,22 @@ TEST_F(ShellUtilRegistryTest, DeleteFileAssociations) { ...@@ -940,6 +940,22 @@ TEST_F(ShellUtilRegistryTest, DeleteFileAssociations) {
EXPECT_EQ(L"SomeOtherApp", value); EXPECT_EQ(L"SomeOtherApp", value);
} }
TEST_F(ShellUtilRegistryTest, GetFileAssociationsAndAppName) {
ShellUtil::FileAssociationsAndAppName empty_file_associations_and_app_name(
ShellUtil::GetFileAssociationsAndAppName(kTestProgid));
EXPECT_TRUE(empty_file_associations_and_app_name.app_name.empty());
// Add file associations and test that GetFileAssociationsAndAppName returns
// the registered file associations and app name.
ASSERT_TRUE(ShellUtil::AddFileAssociations(
kTestProgid, OpenCommand(), kTestApplicationName, kTestFileTypeName,
base::FilePath(kTestIconPath), FileExtensions()));
ShellUtil::FileAssociationsAndAppName file_associations_and_app_name(
ShellUtil::GetFileAssociationsAndAppName(kTestProgid));
EXPECT_EQ(file_associations_and_app_name.app_name, kTestApplicationName);
EXPECT_EQ(file_associations_and_app_name.file_associations, FileExtensions());
}
TEST_F(ShellUtilRegistryTest, GetApplicationForProgId) { TEST_F(ShellUtilRegistryTest, GetApplicationForProgId) {
// Create file associations. // Create file associations.
ASSERT_TRUE(ShellUtil::AddFileAssociations( ASSERT_TRUE(ShellUtil::AddFileAssociations(
......
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