Commit 82b618bb authored by Giovanni Ortuño Urquidi's avatar Giovanni Ortuño Urquidi Committed by Commit Bot

desktop-pwas: Adds ability to use the default launch container to PendingAppManager

WebAppPolicyManager allows admins to not specify a launch container.
When this is the case the installed app should launch in the default
container: windows for PWAs and tabs for non-PWAs.

Adds a new enum value to PendingAppManager::LaunchContainer to
indicate that the default launch container should be used and changes
WebAppPolicyManager to set that value when appropriate.

Bug: 877398
Change-Id: I4c99d3b53bc7c29a50c6961da78d046bc7ef7819
Reviewed-on: https://chromium-review.googlesource.com/1188203
Commit-Queue: Giovanni Ortuño Urquidi <ortuno@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585792}
parent cdc4d73b
......@@ -72,11 +72,8 @@ void WebAppPolicyManager::RefreshPolicyInstalledApps() {
launch_container->GetString() == kLaunchContainerTabValue);
PendingAppManager::LaunchContainer container;
// TODO(crbug.com/864904): Remove this default once PendingAppManager
// supports not setting the launch container.
if (!launch_container)
container = PendingAppManager::LaunchContainer::kTab;
container = PendingAppManager::LaunchContainer::kDefault;
else if (launch_container->GetString() == kLaunchContainerWindowValue)
container = PendingAppManager::LaunchContainer::kWindow;
else
......
......@@ -111,4 +111,33 @@ TEST_F(WebAppPolicyManagerTest, TwoForceInstalledApps) {
EXPECT_EQ(apps_to_install, expected_apps_to_install);
}
TEST_F(WebAppPolicyManagerTest, ForceInstallAppWithNoForcedLaunchContainer) {
auto prefs = std::make_unique<TestingPrefServiceSyncable>();
RegisterUserProfilePrefs(prefs->registry());
base::Value list(base::Value::Type::LIST);
{
base::Value item1(base::Value::Type::DICTIONARY);
item1.SetKey(kUrlKey, base::Value(kUrl1));
list.GetList().push_back(std::move(item1));
prefs->Set(prefs::kWebAppInstallForceList, std::move(list));
}
auto pending_app_manager = std::make_unique<TestPendingAppManager>();
WebAppPolicyManager web_app_policy_manager(prefs.get(),
pending_app_manager.get());
base::RunLoop().RunUntilIdle();
const auto& apps_to_install = pending_app_manager->installed_apps();
std::vector<PendingAppManager::AppInfo> expected_apps_to_install;
expected_apps_to_install.emplace_back(
GURL(kUrl1), PendingAppManager::LaunchContainer::kDefault,
false /* create_shortcuts */);
EXPECT_EQ(apps_to_install, expected_apps_to_install);
}
} // namespace web_app
......@@ -31,6 +31,10 @@ class PendingAppManager {
// How the app will be launched after installation.
enum class LaunchContainer {
// When `kDefault` is used, the app will launch in a window if the site is
// "installable" (also referred to as Progressive Web App) and in a tab if
// the site is not "installable".
kDefault,
kTab,
kWindow,
};
......
......@@ -107,6 +107,8 @@ void BookmarkAppInstallationTask::OnGetWebApplicationInfo(
WebappInstallSource::MENU_BROWSER_TAB);
switch (app_info_.launch_container) {
case web_app::PendingAppManager::LaunchContainer::kDefault:
break;
case web_app::PendingAppManager::LaunchContainer::kTab:
helper_->set_forced_launch_type(LAUNCH_TYPE_REGULAR);
break;
......
......@@ -415,4 +415,26 @@ TEST_F(BookmarkAppInstallationTaskTest,
EXPECT_EQ(LAUNCH_TYPE_REGULAR, test_helper().forced_launch_type().value());
}
TEST_F(BookmarkAppInstallationTaskTest,
WebAppOrShortcutFromContents_NoForcedContainer) {
const GURL app_url(kWebAppUrl);
web_app::PendingAppManager::AppInfo app_info(
app_url, web_app::PendingAppManager::LaunchContainer::kDefault);
auto task = std::make_unique<BookmarkAppInstallationTask>(
profile(), std::move(app_info));
SetTestingFactories(task.get(), app_url);
task->InstallWebAppOrShortcutFromWebContents(
web_contents(),
base::BindOnce(&BookmarkAppInstallationTaskTest::OnInstallationTaskResult,
base::Unretained(this), base::DoNothing().Once()));
content::RunAllTasksUntilIdle();
test_helper().CompleteInstallation();
EXPECT_TRUE(app_installed());
EXPECT_FALSE(test_helper().forced_launch_type().has_value());
}
} // namespace extensions
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