Commit 8897189f authored by Giovanni Ortuño Urquidi's avatar Giovanni Ortuño Urquidi Committed by Commit Bot

system-web-apps: Adds ChromeOS specific properties to Web Apps

On most OSs these properties are stored in the OS itself, e.g. in
Windows an app is added to a folder so that it shows up in the
Applications Menu. For ChromeOS, we need to implement our own way of
storing this.

This CL adds a new property to WebApps: ChromeOSData, which
holds properties specific to Chrome OS and needed to integrate with
various UI surfaces.

Bug: 1054195
Change-Id: I23dab5aeb5f30c94d28db0062bb82b4f173047da
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2132900
Commit-Queue: Giovanni Ortuño Urquidi <ortuno@chromium.org>
Reviewed-by: default avatarNancy Wang <nancylingwang@chromium.org>
Reviewed-by: default avatarAlexey Baskakov <loyso@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759962}
parent bda43c49
......@@ -535,13 +535,25 @@ void WebApps::OnArcAppListPrefsDestroyed() {
void WebApps::SetShowInFields(apps::mojom::AppPtr& app,
const web_app::WebApp* web_app) {
// TODO(crbug.com/1054195): Make web_apps read this from
// system_web_app_manager.
if (web_app->chromeos_data().has_value()) {
auto& chromeos_data = web_app->chromeos_data().value();
app->show_in_launcher = chromeos_data.show_in_launcher
? apps::mojom::OptionalBool::kTrue
: apps::mojom::OptionalBool::kFalse;
app->show_in_search = chromeos_data.show_in_search
? apps::mojom::OptionalBool::kTrue
: apps::mojom::OptionalBool::kFalse;
app->show_in_management = chromeos_data.show_in_management
? apps::mojom::OptionalBool::kTrue
: apps::mojom::OptionalBool::kFalse;
return;
}
// Show the app everywhere by default.
auto show = apps::mojom::OptionalBool::kTrue;
app->show_in_launcher = show;
app->show_in_search = show;
app->show_in_management =
web_app->IsSystemApp() ? apps::mojom::OptionalBool::kFalse : show;
app->show_in_management = show;
}
void WebApps::PopulatePermissions(const web_app::WebApp* web_app,
......
......@@ -33,6 +33,8 @@ source_set("components") {
"policy/web_app_policy_manager.h",
"web_app_audio_focus_id_map.cc",
"web_app_audio_focus_id_map.h",
"web_app_chromeos_data.cc",
"web_app_chromeos_data.h",
"web_app_constants.cc",
"web_app_constants.h",
"web_app_data_retriever.cc",
......
......@@ -5,7 +5,9 @@
#include "chrome/browser/web_applications/components/external_install_options.h"
#include <ostream>
#include <string>
#include <tuple>
#include <vector>
#include "base/strings/string_util.h"
......@@ -34,14 +36,15 @@ bool ExternalInstallOptions::operator==(
const ExternalInstallOptions& other) const {
return std::tie(url, user_display_mode, install_source,
add_to_applications_menu, add_to_desktop,
add_to_quick_launch_bar, override_previous_user_uninstall,
bypass_service_worker_check, require_manifest,
force_reinstall, wait_for_windows_closed, install_placeholder,
reinstall_placeholder, uninstall_and_replace,
additional_search_terms) ==
add_to_quick_launch_bar, add_to_search, add_to_management,
override_previous_user_uninstall, bypass_service_worker_check,
require_manifest, force_reinstall, wait_for_windows_closed,
install_placeholder, reinstall_placeholder,
uninstall_and_replace, additional_search_terms) ==
std::tie(other.url, other.user_display_mode, other.install_source,
other.add_to_applications_menu, other.add_to_desktop,
other.add_to_quick_launch_bar,
other.add_to_quick_launch_bar, other.add_to_search,
other.add_to_management,
other.override_previous_user_uninstall,
other.bypass_service_worker_check, other.require_manifest,
other.force_reinstall, other.wait_for_windows_closed,
......@@ -60,6 +63,8 @@ std::ostream& operator<<(std::ostream& out,
<< "\n add_to_desktop: " << install_options.add_to_desktop
<< "\n add_to_quick_launch_bar: "
<< install_options.add_to_quick_launch_bar
<< "\n add_to_search: " << install_options.add_to_search
<< "\n add_to_management: " << install_options.add_to_management
<< "\n override_previous_user_uninstall: "
<< install_options.override_previous_user_uninstall
<< "\n bypass_service_worker_check: "
......@@ -90,6 +95,8 @@ InstallManager::InstallParams ConvertExternalInstallOptionsToParams(
params.add_to_applications_menu = install_options.add_to_applications_menu;
params.add_to_desktop = install_options.add_to_desktop;
params.add_to_quick_launch_bar = install_options.add_to_quick_launch_bar;
params.add_to_search = install_options.add_to_search;
params.add_to_management = install_options.add_to_management;
params.bypass_service_worker_check =
install_options.bypass_service_worker_check;
......
......@@ -6,6 +6,8 @@
#define CHROME_BROWSER_WEB_APPLICATIONS_COMPONENTS_EXTERNAL_INSTALL_OPTIONS_H_
#include <iosfwd>
#include <string>
#include <vector>
#include "chrome/browser/web_applications/components/install_manager.h"
#include "chrome/browser/web_applications/components/web_app_constants.h"
......@@ -32,8 +34,7 @@ struct ExternalInstallOptions {
ExternalInstallSource install_source;
// If true, a shortcut is added to the Applications folder on macOS, and Start
// Menu on Linux and Windows. On Chrome OS, all installed apps show up in the
// app list, so there is no need to do anything there. If false, we skip
// Menu on Linux and Windows and launcher on Chrome OS. If false, we skip
// adding a shortcut to desktop as well, regardless of the value of
// |add_to_desktop|.
// TODO(ortuno): Make adding a shortcut to the applications menu independent
......@@ -49,6 +50,14 @@ struct ExternalInstallOptions {
// Windows. Currently this only works on Chrome OS.
bool add_to_quick_launch_bar = true;
// If true, the app can be searched for on Chrome OS. Has no effect on other
// platforms.
bool add_to_search = true;
// If true, the app is shown in App Management on Chrome OS. Has no effect on
// other platforms.
bool add_to_management = true;
// Whether the app should be reinstalled even if the user has previously
// uninstalled it.
bool override_previous_user_uninstall = false;
......
......@@ -4,6 +4,8 @@
#include "chrome/browser/web_applications/components/install_finalizer.h"
#include <utility>
#include "base/bind.h"
#include "base/callback.h"
#include "base/logging.h"
......@@ -15,6 +17,13 @@
namespace web_app {
InstallFinalizer::FinalizeOptions::FinalizeOptions() = default;
InstallFinalizer::FinalizeOptions::~FinalizeOptions() = default;
InstallFinalizer::FinalizeOptions::FinalizeOptions(const FinalizeOptions&) =
default;
void InstallFinalizer::UninstallExternalWebAppByUrl(
const GURL& app_url,
ExternalInstallSource external_install_source,
......
......@@ -8,7 +8,9 @@
#include <memory>
#include "base/callback_forward.h"
#include "base/optional.h"
#include "chrome/browser/installable/installable_metrics.h"
#include "chrome/browser/web_applications/components/web_app_chromeos_data.h"
#include "chrome/browser/web_applications/components/web_app_id.h"
struct WebApplicationInfo;
......@@ -35,8 +37,14 @@ class InstallFinalizer {
using UninstallWebAppCallback = base::OnceCallback<void(bool uninstalled)>;
struct FinalizeOptions {
FinalizeOptions();
~FinalizeOptions();
FinalizeOptions(const FinalizeOptions&);
WebappInstallSource install_source = WebappInstallSource::COUNT;
bool locally_installed = true;
base::Optional<WebAppChromeOsData> chromeos_data;
};
// Write the WebApp data to disk and register the app.
......
......@@ -6,9 +6,12 @@
#define CHROME_BROWSER_WEB_APPLICATIONS_COMPONENTS_INSTALL_MANAGER_H_
#include <memory>
#include <string>
#include <vector>
#include "base/callback_forward.h"
#include "base/optional.h"
#include "chrome/browser/web_applications/components/web_app_chromeos_data.h"
#include "chrome/browser/web_applications/components/web_app_constants.h"
#include "chrome/browser/web_applications/components/web_app_id.h"
#include "chrome/browser/web_applications/components/web_app_install_utils.h"
......@@ -116,6 +119,10 @@ class InstallManager {
bool add_to_desktop = true;
bool add_to_quick_launch_bar = true;
// These have no effect outside of Chrome OS.
bool add_to_search = true;
bool add_to_management = true;
bool bypass_service_worker_check = false;
bool require_manifest = false;
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/web_applications/components/web_app_chromeos_data.h"
#include <ios>
#include <ostream>
#include <tuple>
namespace web_app {
bool operator==(const WebAppChromeOsData& chromeos_data1,
const WebAppChromeOsData& chromeos_data2) {
return std::tie(chromeos_data1.show_in_launcher,
chromeos_data1.show_in_search,
chromeos_data1.show_in_management) ==
std::tie(chromeos_data2.show_in_launcher,
chromeos_data2.show_in_search,
chromeos_data2.show_in_management);
}
std::ostream& operator<<(std::ostream& out,
const WebAppChromeOsData& chromeos_data) {
out << " show_in_launcher: " << chromeos_data.show_in_launcher << std::endl;
out << " show_in_search: " << chromeos_data.show_in_search << std::endl;
out << " show_in_management: " << chromeos_data.show_in_management
<< std::endl;
return out;
}
} // namespace web_app
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_WEB_APPLICATIONS_COMPONENTS_WEB_APP_CHROMEOS_DATA_H_
#define CHROME_BROWSER_WEB_APPLICATIONS_COMPONENTS_WEB_APP_CHROMEOS_DATA_H_
#include <iosfwd>
namespace web_app {
struct WebAppChromeOsData {
// By default an app is shown everywhere.
bool show_in_launcher = true;
bool show_in_search = true;
bool show_in_management = true;
};
// For logging and debugging purposes.
std::ostream& operator<<(std::ostream& out, const WebAppChromeOsData& data);
bool operator==(const WebAppChromeOsData& chromeos_data1,
const WebAppChromeOsData& chromeos_data2);
bool operator!=(const WebAppChromeOsData& chromeos_data1,
const WebAppChromeOsData& chromeos_data2);
} // namespace web_app
#endif // CHROME_BROWSER_WEB_APPLICATIONS_COMPONENTS_WEB_APP_CHROMEOS_DATA_H_
......@@ -117,4 +117,12 @@ std::string GetProfileCategoryForLogging(Profile* profile) {
#endif
}
bool IsChromeOs() {
#if defined(OS_CHROMEOS)
return true;
#else
return false;
#endif
}
} // namespace web_app
......@@ -66,6 +66,9 @@ base::FilePath GetWebAppsTempDirectory(
// tool/metrics/histograms/histograms.xml: "SystemWebAppProfileCategory".
std::string GetProfileCategoryForLogging(Profile* profile);
// Returns true if the WebApp should have `web_app::WebAppChromeOsData()`.
bool IsChromeOs();
} // namespace web_app
#endif // CHROME_BROWSER_WEB_APPLICATIONS_COMPONENTS_WEB_APP_UTILS_H_
......@@ -57,9 +57,11 @@ GURL AppUrl3() {
ExternalInstallOptions GetWindowedInstallOptions() {
ExternalInstallOptions options(AppUrl1(), DisplayMode::kStandalone,
ExternalInstallSource::kSystemInstalled);
options.add_to_applications_menu = false;
options.add_to_applications_menu = true;
options.add_to_desktop = false;
options.add_to_quick_launch_bar = false;
options.add_to_search = true;
options.add_to_management = false;
options.bypass_service_worker_check = true;
options.force_reinstall = true;
return options;
......
......@@ -44,6 +44,13 @@ message SourcesProto {
required bool default = 5;
}
// Properties for integrating with Chrome OS UI surfaces.
message ChromeOSDataProto {
required bool show_in_launcher = 1;
required bool show_in_search = 2;
required bool show_in_management = 3;
}
// Full WebApp object data. See detailed comments in
// chrome/browser/web_applications/web_app.h. Note on database identities:
// app_id is a hash of launch_url. app_id is the client tag for sync system.
......@@ -84,4 +91,8 @@ message WebAppProto {
repeated WebAppFileHandlerProto file_handlers = 12;
// A list of additional search terms to use when searching for the app.
repeated string additional_search_terms = 13;
// Even though |chromeos_data| is optional, it should always exist on
// ChromeOS.
optional ChromeOSDataProto chromeos_data = 14;
}
......@@ -4,6 +4,7 @@
#include "chrome/browser/web_applications/system_web_app_manager.h"
#include <algorithm>
#include <string>
#include <tuple>
#include <utility>
......@@ -164,9 +165,11 @@ ExternalInstallOptions CreateInstallOptionsForSystemApp(
ExternalInstallOptions install_options(
info.install_url, DisplayMode::kStandalone,
ExternalInstallSource::kSystemInstalled);
install_options.add_to_applications_menu = false;
install_options.add_to_applications_menu = info.show_in_launcher;
install_options.add_to_desktop = false;
install_options.add_to_quick_launch_bar = false;
install_options.add_to_search = info.show_in_search;
install_options.add_to_management = false;
install_options.bypass_service_worker_check = true;
install_options.force_reinstall = force_update;
install_options.uninstall_and_replace = info.uninstall_and_replace;
......
......@@ -175,6 +175,8 @@ IN_PROC_BROWSER_TEST_P(SystemWebAppManagerBrowserTest, Install) {
proxy->AppRegistryCache().ForOneApp(
app_id, [](const apps::AppUpdate& update) {
EXPECT_EQ(apps::mojom::OptionalBool::kTrue, update.ShowInLauncher());
EXPECT_EQ(apps::mojom::OptionalBool::kTrue, update.ShowInSearch());
EXPECT_EQ(apps::mojom::OptionalBool::kFalse, update.ShowInManagement());
});
}
......@@ -727,21 +729,14 @@ class SystemWebAppManagerNotShownInLauncherTest
IN_PROC_BROWSER_TEST_P(SystemWebAppManagerNotShownInLauncherTest,
NotShownInLauncher) {
// TODO(crbug.com/1054195): Make the expectation unconditional.
const web_app::ProviderType provider = provider_type();
WaitForSystemAppInstallAndLaunch(GetMockAppType());
AppId app_id = GetManager().GetAppIdForSystemApp(GetMockAppType()).value();
apps::AppServiceProxy* proxy =
apps::AppServiceProxyFactory::GetForProfile(browser()->profile());
proxy->AppRegistryCache().ForOneApp(
app_id, [provider](const apps::AppUpdate& update) {
if (provider == ProviderType::kWebApps) {
EXPECT_EQ(apps::mojom::OptionalBool::kTrue, update.ShowInLauncher());
} else {
EXPECT_EQ(apps::mojom::OptionalBool::kFalse, update.ShowInLauncher());
}
app_id, [](const apps::AppUpdate& update) {
EXPECT_EQ(apps::mojom::OptionalBool::kFalse, update.ShowInLauncher());
});
// OS Integration only relevant for Chrome OS.
#if defined(OS_CHROMEOS)
......@@ -753,15 +748,7 @@ IN_PROC_BROWSER_TEST_P(SystemWebAppManagerNotShownInLauncherTest,
const ChromeAppListItem* mock_app = model_updater->FindItem(app_id);
// |mock_app| shouldn't be found in |AppList| because it should be hidden in
// launcher.
if (provider == ProviderType::kWebApps) {
// TODO(crbug.com/877898): |mock_app| should be hidden but web_apps.cc does
// not currently read from system_web_app_manager.cc. When
// DesktopPWAsWithoutExtensions launches this should change to
// EXPECT_FALSE().
EXPECT_TRUE(mock_app);
} else {
EXPECT_FALSE(mock_app);
}
EXPECT_FALSE(mock_app);
#endif // defined(OS_CHROMEOS)
}
......@@ -777,24 +764,14 @@ class SystemWebAppManagerNotShownInSearchTest
IN_PROC_BROWSER_TEST_P(SystemWebAppManagerNotShownInSearchTest,
NotShownInSearch) {
const web_app::ProviderType provider = provider_type();
WaitForSystemAppInstallAndLaunch(GetMockAppType());
AppId app_id = GetManager().GetAppIdForSystemApp(GetMockAppType()).value();
apps::AppServiceProxy* proxy =
apps::AppServiceProxyFactory::GetForProfile(browser()->profile());
proxy->AppRegistryCache().ForOneApp(
app_id, [provider](const apps::AppUpdate& update) {
if (provider == ProviderType::kWebApps) {
// TODO(crbug.com/877898): |mock_app| should be hidden but web_apps.cc
// does not currently read from system_web_app_manager.cc. When
// DesktopPWAsWithoutExtensions launches remove the special case for
// kWebApps, ShowInSearch() should return false.
EXPECT_EQ(apps::mojom::OptionalBool::kTrue, update.ShowInSearch());
} else {
EXPECT_EQ(apps::mojom::OptionalBool::kFalse, update.ShowInSearch());
}
app_id, [](const apps::AppUpdate& update) {
EXPECT_EQ(apps::mojom::OptionalBool::kFalse, update.ShowInSearch());
});
}
......@@ -822,8 +799,6 @@ IN_PROC_BROWSER_TEST_P(SystemWebAppManagerAdditionalSearchTermsTest,
});
}
// These tests use the App Service which is only enabled on Chrome OS.
#if defined(OS_CHROMEOS)
// Tests that SWA-specific data is correctly migrated to Web Apps without
// Extensions.
class SystemWebAppManagerMigrationTest
......@@ -846,39 +821,53 @@ class SystemWebAppManagerMigrationTest
}
~SystemWebAppManagerMigrationTest() override = default;
protected:
std::vector<std::string> GetAppAdditionalSearchTerms() {
AppId app_id = GetManager().GetAppIdForSystemApp(GetMockAppType()).value();
std::vector<std::string> additional_search_terms;
apps::AppServiceProxy* proxy =
apps::AppServiceProxyFactory::GetForProfile(browser()->profile());
const bool app_found = proxy->AppRegistryCache().ForOneApp(
app_id, [&additional_search_terms](const apps::AppUpdate& update) {
additional_search_terms = update.AdditionalSearchTerms();
});
CHECK(app_found);
return additional_search_terms;
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
// These tests use the App Service which is only enabled on Chrome OS.
#if defined(OS_CHROMEOS)
#define MAYBE_PRE_ExtraDataIsMigrated PRE_ExtraDataIsMigrated
#else
#define MAYBE_PRE_ExtraDataIsMigrated DISABLED_PRE_ExtraDataIsMigrated
#endif
IN_PROC_BROWSER_TEST_F(SystemWebAppManagerMigrationTest,
PRE_ExtraDataIsMigrated) {
MAYBE_PRE_ExtraDataIsMigrated) {
WaitForTestSystemAppInstall();
EXPECT_EQ(std::vector<std::string>({"Security"}),
GetAppAdditionalSearchTerms());
AppId app_id = GetManager().GetAppIdForSystemApp(GetMockAppType()).value();
apps::AppServiceProxy* proxy =
apps::AppServiceProxyFactory::GetForProfile(browser()->profile());
const bool app_found = proxy->AppRegistryCache().ForOneApp(
app_id, [](const apps::AppUpdate& update) {
EXPECT_EQ(std::vector<std::string>({"Security"}),
update.AdditionalSearchTerms());
EXPECT_EQ(apps::mojom::OptionalBool::kFalse, update.ShowInManagement());
});
ASSERT_TRUE(app_found);
}
IN_PROC_BROWSER_TEST_F(SystemWebAppManagerMigrationTest, ExtraDataIsMigrated) {
// These tests use the App Service which is only enabled on Chrome OS.
#if defined(OS_CHROMEOS)
#define MAYBE_ExtraDataIsMigrated ExtraDataIsMigrated
#else
#define MAYBE_ExtraDataIsMigrated DISABLED_ExtraDataIsMigrated
#endif
IN_PROC_BROWSER_TEST_F(SystemWebAppManagerMigrationTest,
MAYBE_ExtraDataIsMigrated) {
WaitForTestSystemAppInstall();
EXPECT_EQ(std::vector<std::string>({"Security"}),
GetAppAdditionalSearchTerms());
AppId app_id = GetManager().GetAppIdForSystemApp(GetMockAppType()).value();
apps::AppServiceProxy* proxy =
apps::AppServiceProxyFactory::GetForProfile(browser()->profile());
const bool app_found = proxy->AppRegistryCache().ForOneApp(
app_id, [](const apps::AppUpdate& update) {
EXPECT_EQ(std::vector<std::string>({"Security"}),
update.AdditionalSearchTerms());
EXPECT_EQ(apps::mojom::OptionalBool::kFalse, update.ShowInManagement());
});
ASSERT_TRUE(app_found);
}
#endif // defined(OS_CHROMEOS)
class SystemWebAppManagerChromeUntrustedTest
: public SystemWebAppManagerBrowserTest {
......
......@@ -8,9 +8,12 @@
#include <ios>
#include <ostream>
#include <tuple>
#include <utility>
#include "base/logging.h"
#include "chrome/browser/web_applications/components/web_app_chromeos_data.h"
#include "chrome/browser/web_applications/components/web_app_constants.h"
#include "chrome/browser/web_applications/components/web_app_utils.h"
#include "third_party/blink/public/common/manifest/manifest_util.h"
#include "ui/gfx/color_utils.h"
......@@ -28,7 +31,9 @@ namespace web_app {
WebApp::WebApp(const AppId& app_id)
: app_id_(app_id),
display_mode_(DisplayMode::kUndefined),
user_display_mode_(DisplayMode::kUndefined) {}
user_display_mode_(DisplayMode::kUndefined),
chromeos_data_(IsChromeOs() ? base::make_optional<WebAppChromeOsData>()
: base::nullopt) {}
WebApp::~WebApp() = default;
......@@ -141,6 +146,11 @@ void WebApp::SetUserDisplayMode(DisplayMode user_display_mode) {
}
}
void WebApp::SetWebAppChromeOsData(
base::Optional<WebAppChromeOsData> chromeos_data) {
chromeos_data_ = std::move(chromeos_data);
}
void WebApp::SetIsLocallyInstalled(bool is_locally_installed) {
is_locally_installed_ = is_locally_installed;
}
......@@ -213,6 +223,10 @@ std::ostream& operator<<(std::ostream& out, const WebApp& app) {
for (const std::string& additional_search_term : app.additional_search_terms_)
out << " additional_search_term: " << additional_search_term << std::endl;
out << " chromeos_data: " << app.chromeos_data_.has_value() << std::endl;
if (app.chromeos_data_.has_value())
out << app.chromeos_data_.value();
return out;
}
......@@ -232,16 +246,16 @@ bool operator==(const WebApp& app1, const WebApp& app2) {
app1.description_, app1.scope_, app1.theme_color_,
app1.icon_infos_, app1.downloaded_icon_sizes_,
app1.display_mode_, app1.user_display_mode_,
app1.is_locally_installed_, app1.is_in_sync_install_,
app1.file_handlers_, app1.additional_search_terms_,
app1.sync_data_) ==
app1.chromeos_data_, app1.is_locally_installed_,
app1.is_in_sync_install_, app1.file_handlers_,
app1.additional_search_terms_, app1.sync_data_) ==
std::tie(app2.app_id_, app2.sources_, app2.name_, app2.launch_url_,
app2.description_, app2.scope_, app2.theme_color_,
app2.icon_infos_, app2.downloaded_icon_sizes_,
app2.display_mode_, app2.user_display_mode_,
app2.is_locally_installed_, app2.is_in_sync_install_,
app2.file_handlers_, app2.additional_search_terms_,
app2.sync_data_);
app2.chromeos_data_, app2.is_locally_installed_,
app2.is_in_sync_install_, app2.file_handlers_,
app2.additional_search_terms_, app2.sync_data_);
}
bool operator!=(const WebApp& app1, const WebApp& app2) {
......
......@@ -11,6 +11,7 @@
#include <vector>
#include "base/optional.h"
#include "chrome/browser/web_applications/components/web_app_chromeos_data.h"
#include "chrome/browser/web_applications/components/web_app_constants.h"
#include "chrome/browser/web_applications/components/web_app_id.h"
#include "chrome/common/web_application_info.h"
......@@ -49,6 +50,10 @@ class WebApp {
DisplayMode user_display_mode() const { return user_display_mode_; }
const base::Optional<WebAppChromeOsData>& chromeos_data() const {
return chromeos_data_;
}
// Locally installed apps have shortcuts installed on various UI surfaces.
// If app isn't locally installed, it is excluded from UIs and only listed as
// a part of user's app library.
......@@ -117,6 +122,7 @@ class WebApp {
void SetThemeColor(base::Optional<SkColor> theme_color);
void SetDisplayMode(DisplayMode display_mode);
void SetUserDisplayMode(DisplayMode user_display_mode);
void SetWebAppChromeOsData(base::Optional<WebAppChromeOsData> chromeos_data);
void SetIsLocallyInstalled(bool is_locally_installed);
void SetIsInSyncInstall(bool is_in_sync_install);
void SetIconInfos(std::vector<WebApplicationIconInfo> icon_infos);
......@@ -150,6 +156,7 @@ class WebApp {
base::Optional<SkColor> theme_color_;
DisplayMode display_mode_;
DisplayMode user_display_mode_;
base::Optional<WebAppChromeOsData> chromeos_data_;
bool is_locally_installed_ = true;
bool is_in_sync_install_ = false;
std::vector<WebApplicationIconInfo> icon_infos_;
......
......@@ -4,10 +4,15 @@
#include "chrome/browser/web_applications/web_app_database.h"
#include <string>
#include <utility>
#include <vector>
#include "base/bind.h"
#include "base/callback.h"
#include "base/stl_util.h"
#include "chrome/browser/web_applications/components/web_app_helpers.h"
#include "chrome/browser/web_applications/components/web_app_utils.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/browser/web_applications/web_app_database_factory.h"
#include "chrome/browser/web_applications/web_app_registry_update.h"
......@@ -119,6 +124,15 @@ std::unique_ptr<WebAppProto> WebAppDatabase::CreateWebAppProto(
if (web_app.theme_color().has_value())
local_data->set_theme_color(web_app.theme_color().value());
if (web_app.chromeos_data().has_value()) {
auto& chromeos_data = web_app.chromeos_data().value();
auto* mutable_chromeos_data = local_data->mutable_chromeos_data();
mutable_chromeos_data->set_show_in_launcher(chromeos_data.show_in_launcher);
mutable_chromeos_data->set_show_in_search(chromeos_data.show_in_search);
mutable_chromeos_data->set_show_in_management(
chromeos_data.show_in_management);
}
local_data->set_is_in_sync_install(web_app.is_in_sync_install());
// Set sync_data to sync proto.
......@@ -220,6 +234,30 @@ std::unique_ptr<WebApp> WebAppDatabase::CreateWebApp(
}
web_app->SetIsLocallyInstalled(local_data.is_locally_installed());
auto& chromeos_data_proto = local_data.chromeos_data();
if (IsChromeOs() && !local_data.has_chromeos_data()) {
DLOG(ERROR) << "WebApp proto parse error: no chromeos_data field. The web "
<< "app might have been installed when running on an OS other "
<< "than Chrome OS.";
return nullptr;
}
if (!IsChromeOs() && local_data.has_chromeos_data()) {
DLOG(ERROR) << "WebApp proto parse error: has chromeos_data field. The web "
<< "app might have been installed when running on Chrome OS.";
return nullptr;
}
if (local_data.has_chromeos_data()) {
auto chromeos_data = base::make_optional<WebAppChromeOsData>();
chromeos_data->show_in_launcher = chromeos_data_proto.show_in_launcher();
chromeos_data->show_in_search = chromeos_data_proto.show_in_search();
chromeos_data->show_in_management =
chromeos_data_proto.show_in_management();
web_app->SetWebAppChromeOsData(std::move(chromeos_data));
}
// Optional fields:
if (local_data.has_display_mode())
web_app->SetDisplayMode(ToMojomDisplayMode(local_data.display_mode()));
......
......@@ -5,6 +5,9 @@
#include "chrome/browser/web_applications/web_app_database.h"
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/bind_helpers.h"
#include "base/run_loop.h"
......@@ -12,6 +15,7 @@
#include "base/test/bind_test_util.h"
#include "chrome/browser/web_applications/components/web_app_constants.h"
#include "chrome/browser/web_applications/components/web_app_helpers.h"
#include "chrome/browser/web_applications/components/web_app_utils.h"
#include "chrome/browser/web_applications/proto/web_app.pb.h"
#include "chrome/browser/web_applications/test/test_web_app_database_factory.h"
#include "chrome/browser/web_applications/test/test_web_app_registry_controller.h"
......@@ -126,6 +130,14 @@ class WebAppDatabaseTest : public WebAppTest {
}
app->SetAdditionalSearchTerms(std::move(additional_search_terms));
if (IsChromeOs()) {
auto chromeos_data = base::make_optional<WebAppChromeOsData>();
chromeos_data->show_in_launcher = suffix & 0b001;
chromeos_data->show_in_search = suffix & 0b010;
chromeos_data->show_in_management = suffix & 0b100;
app->SetWebAppChromeOsData(std::move(chromeos_data));
}
WebApp::SyncData sync_data;
sync_data.name = "Sync" + name;
sync_data.theme_color = synced_theme_color;
......@@ -301,6 +313,9 @@ TEST_F(WebAppDatabaseTest, WebAppWithoutOptionalFields) {
app->SetName(name);
app->SetUserDisplayMode(user_display_mode);
app->SetIsLocallyInstalled(false);
// chromeos_data should always be set on ChromeOS.
if (IsChromeOs())
app->SetWebAppChromeOsData(base::make_optional<WebAppChromeOsData>());
EXPECT_FALSE(app->HasAnySources());
for (int i = Source::kMinValue; i <= Source::kMaxValue; ++i) {
......@@ -334,6 +349,15 @@ TEST_F(WebAppDatabaseTest, WebAppWithoutOptionalFields) {
EXPECT_EQ(user_display_mode, app_copy->user_display_mode());
EXPECT_FALSE(app_copy->is_locally_installed());
auto& chromeos_data = app_copy->chromeos_data();
if (IsChromeOs()) {
EXPECT_TRUE(chromeos_data->show_in_launcher);
EXPECT_TRUE(chromeos_data->show_in_search);
EXPECT_TRUE(chromeos_data->show_in_management);
} else {
EXPECT_FALSE(chromeos_data.has_value());
}
for (int i = Source::kMinValue; i <= Source::kMaxValue; ++i) {
EXPECT_TRUE(app_copy->HasAnySources());
app_copy->RemoveSource(static_cast<Source::Type>(i));
......
......@@ -4,6 +4,9 @@
#include <utility>
#include <map>
#include <vector>
#include "chrome/browser/web_applications/web_app_install_finalizer.h"
#include "base/bind.h"
......@@ -163,6 +166,11 @@ void WebAppInstallFinalizer::FinalizeInstall(
: DisplayMode::kBrowser);
}
// `WebApp::chromeos_data` has a default value already. Only override if the
// caller provided a new value.
if (options.chromeos_data.has_value())
web_app->SetWebAppChromeOsData(options.chromeos_data.value());
web_app->SetAdditionalSearchTerms(web_app_info.additional_search_terms);
web_app->AddSource(source);
web_app->SetIsInSyncInstall(false);
......
......@@ -694,6 +694,16 @@ void WebAppInstallTask::OnDialogCompleted(
if (install_params_) {
finalize_options.locally_installed = install_params_->locally_installed;
if (IsChromeOs()) {
finalize_options.chromeos_data.emplace();
finalize_options.chromeos_data->show_in_launcher =
install_params_->add_to_applications_menu;
finalize_options.chromeos_data->show_in_search =
install_params_->add_to_search;
finalize_options.chromeos_data->show_in_management =
install_params_->add_to_management;
}
if (install_params_->user_display_mode != DisplayMode::kUndefined) {
web_app_info_copy.open_as_window =
install_params_->user_display_mode != DisplayMode::kBrowser;
......
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