Commit d7db2cd2 authored by Jeevan Shikaram's avatar Jeevan Shikaram Committed by Commit Bot

[PWAs-in-Play] Close web-only TWAs when an intent to open a PWA is sent.

When opening a web app from ARC++, if the web app is associated to a
web-only TWA, we want to close the ARC++ associated with the web app.

Bug: 1026230
Change-Id: If223f638ba361956a486c52007b953301a78c9e3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2220114Reviewed-by: default avatarNancy Wang <nancylingwang@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Jeevan Shikaram <jshikaram@chromium.org>
Cr-Commit-Position: refs/heads/master@{#773908}
parent d0543be4
......@@ -398,6 +398,14 @@ void AppServiceProxy::UnpauseApps(const std::set<std::string>& app_ids) {
}
#endif // OS_CHROMEOS
void AppServiceProxy::StopApp(const std::string& app_id) {
if (!app_service_.is_connected()) {
return;
}
apps::mojom::AppType app_type = cache_.GetAppType(app_id);
app_service_->StopApp(app_type, app_id);
}
void AppServiceProxy::GetMenuModel(
const std::string& app_id,
apps::mojom::MenuType menu_type,
......
......@@ -174,6 +174,9 @@ class AppServiceProxy : public KeyedService,
void UnpauseApps(const std::set<std::string>& app_ids);
#endif
// Stops the current running app for the given |app_id|.
void StopApp(const std::string& app_id);
// Returns the menu items for the given |app_id|. |display_id| is the id of
// the display from which the app is launched.
void GetMenuModel(const std::string& app_id,
......
......@@ -655,6 +655,10 @@ void ArcApps::UnpauseApps(const std::string& app_id) {
subscribers_);
}
void ArcApps::StopApp(const std::string& app_id) {
CloseTasks(app_id);
}
void ArcApps::GetMenuModel(const std::string& app_id,
apps::mojom::MenuType menu_type,
int64_t display_id,
......
......@@ -96,6 +96,7 @@ class ArcApps : public KeyedService,
bool report_abuse) override;
void PauseApp(const std::string& app_id) override;
void UnpauseApps(const std::string& app_id) override;
void StopApp(const std::string& app_id) override;
void GetMenuModel(const std::string& app_id,
apps::mojom::MenuType menu_type,
int64_t display_id,
......
......@@ -104,6 +104,12 @@ bool ApkWebAppService::IsWebOnlyTwa(const web_app::AppId& app_id) {
return v && v->GetBool();
}
bool ApkWebAppService::IsWebAppInstalledFromArc(
const web_app::AppId& web_app_id) {
return web_app::ExternallyInstalledWebAppPrefs::HasAppIdWithInstallSource(
profile_->GetPrefs(), web_app_id, web_app::ExternalInstallSource::kArc);
}
base::Optional<std::string> ApkWebAppService::GetPackageNameForWebApp(
const web_app::AppId& app_id) {
DictionaryPrefUpdate web_apps_to_apks(profile_->GetPrefs(),
......@@ -469,12 +475,6 @@ void ApkWebAppService::OnDidFinishInstall(
std::move(web_app_installed_callback_).Run(package_name, web_app_id);
}
bool ApkWebAppService::IsWebAppInstalledFromArc(
const web_app::AppId& web_app_id) {
return web_app::ExternallyInstalledWebAppPrefs::HasAppIdWithInstallSource(
profile_->GetPrefs(), web_app_id, web_app::ExternalInstallSource::kArc);
}
void ApkWebAppService::UpdatePackageInfo(
const std::string& app_id,
const arc::mojom::WebAppInfoPtr& web_app_info) {
......
......@@ -49,6 +49,8 @@ class ApkWebAppService : public KeyedService,
bool IsWebOnlyTwa(const web_app::AppId& app_id);
bool IsWebAppInstalledFromArc(const web_app::AppId& web_app_id);
base::Optional<std::string> GetPackageNameForWebApp(
const web_app::AppId& app_id);
......@@ -97,7 +99,6 @@ class ApkWebAppService : public KeyedService,
bool is_web_only_twa,
const base::Optional<std::string> sha256_fingerprint,
web_app::InstallResultCode code);
bool IsWebAppInstalledFromArc(const web_app::AppId& web_app_id);
void UpdatePackageInfo(const std::string& app_id,
const arc::mojom::WebAppInfoPtr& web_app_info);
......
......@@ -17,6 +17,7 @@
#include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
#include "chrome/browser/apps/app_service/launch_utils.h"
#include "chrome/browser/chromeos/apps/apk_web_app_service.h"
#include "chrome/browser/chromeos/apps/metrics/intent_handling_metrics.h"
#include "chrome/browser/chromeos/arc/arc_util.h"
#include "chrome/browser/chromeos/arc/arc_web_contents_data.h"
......@@ -484,6 +485,26 @@ void ChromeNewWindowClient::OpenWebAppFromArc(const GURL& url) {
proxy->LaunchAppWithUrl(*app_id, event_flags, url,
apps::mojom::LaunchSource::kFromArc,
display::kInvalidDisplayId);
chromeos::ApkWebAppService* apk_web_app_service =
chromeos::ApkWebAppService::Get(profile);
if (!apk_web_app_service ||
!apk_web_app_service->IsWebAppInstalledFromArc(app_id.value())) {
return;
}
ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile);
if (!prefs)
return;
base::Optional<std::string> package_name =
apk_web_app_service->GetPackageNameForWebApp(app_id.value());
if (!package_name.has_value())
return;
for (const auto& app_id : prefs->GetAppsForPackage(package_name.value())) {
proxy->StopApp(app_id);
}
}
void ChromeNewWindowClient::OpenArcCustomTab(
......
......@@ -267,6 +267,15 @@ void AppServiceImpl::UnpauseApps(apps::mojom::AppType app_type,
iter->second->UnpauseApps(app_id);
}
void AppServiceImpl::StopApp(apps::mojom::AppType app_type,
const std::string& app_id) {
auto iter = publishers_.find(app_type);
if (iter == publishers_.end()) {
return;
}
iter->second->StopApp(app_id);
}
void AppServiceImpl::GetMenuModel(apps::mojom::AppType app_type,
const std::string& app_id,
apps::mojom::MenuType menu_type,
......
......@@ -85,6 +85,8 @@ class AppServiceImpl : public apps::mojom::AppService {
const std::string& app_id) override;
void UnpauseApps(apps::mojom::AppType app_type,
const std::string& app_id) override;
void StopApp(apps::mojom::AppType app_type,
const std::string& app_id) override;
void GetMenuModel(apps::mojom::AppType app_type,
const std::string& app_id,
apps::mojom::MenuType menu_type,
......
......@@ -100,6 +100,10 @@ void PublisherBase::UnpauseApps(const std::string& app_id) {
NOTIMPLEMENTED();
}
void PublisherBase::StopApp(const std::string& app_id) {
NOTIMPLEMENTED();
}
void PublisherBase::GetMenuModel(const std::string& app_id,
apps::mojom::MenuType menu_type,
int64_t display_id,
......
......@@ -69,6 +69,7 @@ class PublisherBase : public apps::mojom::Publisher {
bool report_abuse) override;
void PauseApp(const std::string& app_id) override;
void UnpauseApps(const std::string& app_id) override;
void StopApp(const std::string& app_id) override;
void GetMenuModel(const std::string& app_id,
apps::mojom::MenuType menu_type,
int64_t display_id,
......
......@@ -84,6 +84,11 @@ interface AppService {
AppType app_type,
string app_id);
// Stops the current running app for the given |app_id|.
StopApp(
AppType app_type,
string app_id);
// Returns the menu items for an app with |app_id|.
GetMenuModel(
AppType app_type,
......@@ -175,6 +180,10 @@ interface Publisher {
UnpauseApps(
string app_id);
// Stops the current running app for the given |app_id|.
StopApp(
string app_id);
// Returns the menu items for an app with |app_id|.
GetMenuModel(
string app_id,
......
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