Commit 43a9a951 authored by Giovanni Ortuño Urquidi's avatar Giovanni Ortuño Urquidi Committed by Commit Bot

desktop-pwa: Introduce a new hide_from_use option for default apps

This CL helps fix two issues:

1. For default apps, `add_to_applications` is set based on
`create_shortcuts`, which according to its documentation controls
whether the app is pinned to the shelf. Currently, no default app sets
`create_shortcuts` to true, so `add_to_applications_menu` is always
false. This wasn't an issue with Extensions because the field was
ignored, but it is an issue with BMO where we use that field to decide
whether the app should show in the app launcher or not. To address
this issue, we could simply set `add_to_applications_menu` to true,
but that would be a problem for default apps that don't want to be
shown in the launcher.

2. Some default apps don't want to be shown in the launcher, but
currently there is no way for them to specify this.

To address both issues, we introduce a new `hide_from_user`
field for default apps. The value defaults to false, so it fixes issue
1. above, and can be set to true by apps that don't want to appear to
users, which addresses issue 2.

Also fixes some test files that were missing the user_type field.

Bug: 1084887
Change-Id: Id77a4f50eae3fb4517bca26b76aeb737161df431
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2210179
Commit-Queue: Giovanni Ortuño Urquidi <ortuno@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#770981}
parent 3f8ef593
......@@ -43,6 +43,13 @@ namespace {
// app that contains a link to the app manifest.
constexpr char kAppUrl[] = "app_url";
// kHideFromUser is an optional boolean which controls whether we add
// a shortcut to the relevant OS surface i.e. Application folder on macOS, Start
// Menu on Windows and Linux, and launcher on Chrome OS. Defaults to false if
// missing. If true, we also don't show the app in search or in app management
// on Chrome OS.
constexpr char kHideFromUser[] = "hide_from_user";
// kCreateShortcuts is an optional boolean which controls whether OS
// level shortcuts are created. On Chrome OS this controls whether the app is
// pinned to the shelf.
......@@ -159,6 +166,16 @@ std::vector<ExternalInstallOptions> ScanDir(const base::FilePath& dir,
continue;
}
bool hide_from_user = false;
value = dict->FindKey(kHideFromUser);
if (value) {
if (!value->is_bool()) {
LOG(ERROR) << file.value() << " had an invalid " << kHideFromUser;
continue;
}
hide_from_user = value->GetBool();
}
bool create_shortcuts = false;
value = dict->FindKey(kCreateShortcuts);
if (value) {
......@@ -169,6 +186,9 @@ std::vector<ExternalInstallOptions> ScanDir(const base::FilePath& dir,
create_shortcuts = value->GetBool();
}
// It doesn't make sense to hide the app and also create shortcuts for it.
DCHECK(!(hide_from_user && create_shortcuts));
value = dict->FindKeyOfType(kLaunchContainer, base::Value::Type::STRING);
if (!value) {
LOG(ERROR) << file.value() << " had an invalid " << kLaunchContainer;
......@@ -213,7 +233,9 @@ std::vector<ExternalInstallOptions> ScanDir(const base::FilePath& dir,
ExternalInstallOptions install_options(
std::move(app_url), user_display_mode,
ExternalInstallSource::kExternalDefault);
install_options.add_to_applications_menu = create_shortcuts;
install_options.add_to_applications_menu = !hide_from_user;
install_options.add_to_search = !hide_from_user;
install_options.add_to_management = !hide_from_user;
install_options.add_to_desktop = create_shortcuts;
install_options.add_to_quick_launch_bar = create_shortcuts;
install_options.require_manifest = true;
......
......@@ -193,6 +193,8 @@ TEST_F(ScanDirForExternalWebAppsTest, GoodJson) {
GURL("https://www.chromestatus.com/features"), DisplayMode::kBrowser,
ExternalInstallSource::kExternalDefault);
install_options.add_to_applications_menu = true;
install_options.add_to_search = true;
install_options.add_to_management = true;
install_options.add_to_desktop = true;
install_options.add_to_quick_launch_bar = true;
install_options.require_manifest = true;
......@@ -202,7 +204,9 @@ TEST_F(ScanDirForExternalWebAppsTest, GoodJson) {
ExternalInstallOptions install_options(
GURL("https://events.google.com/io2016/?utm_source=web_app_manifest"),
DisplayMode::kStandalone, ExternalInstallSource::kExternalDefault);
install_options.add_to_applications_menu = false;
install_options.add_to_applications_menu = true;
install_options.add_to_search = true;
install_options.add_to_management = true;
install_options.add_to_desktop = false;
install_options.add_to_quick_launch_bar = false;
install_options.require_manifest = true;
......@@ -268,12 +272,31 @@ TEST_F(ScanDirForExternalWebAppsTest, InvalidAppUrl) {
EXPECT_EQ(0u, app_infos.size());
}
TEST_F(ScanDirForExternalWebAppsTest, TrueHideFromUser) {
const auto app_infos = ScanTestDirForExternalWebApps("true_hide_from_user");
EXPECT_EQ(1u, app_infos.size());
const auto& app = app_infos[0];
EXPECT_FALSE(app.add_to_applications_menu);
EXPECT_FALSE(app.add_to_search);
EXPECT_FALSE(app.add_to_management);
}
TEST_F(ScanDirForExternalWebAppsTest, InvalidHideFromUser) {
const auto app_infos =
ScanTestDirForExternalWebApps("invalid_hide_from_user");
// The invalid_hide_from_user directory contains on JSON file which is correct
// except for an invalid "hide_from_user" field.
EXPECT_EQ(0u, app_infos.size());
}
TEST_F(ScanDirForExternalWebAppsTest, InvalidCreateShortcuts) {
const auto app_infos =
ScanTestDirForExternalWebApps("invalid_create_shortcuts");
// The invalid_create_shortcuts directory contains one JSON file which is
// correct except for an invalid "create_shortctus" field.
// correct except for an invalid "create_shortcuts" field.
EXPECT_EQ(0u, app_infos.size());
}
......
{
"app_url": "www.chromestatus.com/features",
"create_shortcuts": true,
"launch_container": "tab"
"launch_container": "tab",
"user_type": ["unmanaged"]
}
{
"app_url": "https://www.chromestatus.com/features",
"create_shortcuts": "schmerg",
"launch_container": "tab"
"launch_container": "tab",
"user_type": ["unmanaged"]
}
{
"app_url": "https://www.chromestatus.com/features",
"hide_from_user": "schmerg",
"launch_container": "tab",
"user_type": ["unmanaged"]
}
{
"create_shortcuts": true,
"launch_container": "tab"
"launch_container": "tab",
"user_type": ["unmanaged"]
}
{
"app_url": "https://www.chromestatus.com/features",
"hide_from_user": true,
"launch_container": "tab",
"user_type": ["unmanaged"]
}
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