Commit 99ac01ba authored by nancy's avatar nancy Committed by Commit Bot

Add Shelf context menu for Crostini in AppService.

Add Shelf menu items for Crostini in AppService:
https://cs.chromium.org/chromium/src/chrome/browser/ui/ash/launcher/crostini_shelf_context_menu.cc?l=55

Update the menu related interface to add display id, because Crostini
ueses display id for UI scaling menu items.

BUG=1038487

Change-Id: Ifd9c711dcbec5e7345178339c29f6c8436970e9d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2010603
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#733525}
parent 735aadb7
...@@ -296,6 +296,7 @@ void AppServiceProxy::UnpauseApps(const std::set<std::string>& app_ids) { ...@@ -296,6 +296,7 @@ void AppServiceProxy::UnpauseApps(const std::set<std::string>& app_ids) {
void AppServiceProxy::GetMenuModel(const std::string& app_id, void AppServiceProxy::GetMenuModel(const std::string& app_id,
apps::mojom::MenuType menu_type, apps::mojom::MenuType menu_type,
int64_t display_id,
GetMenuModelCallback callback) { GetMenuModelCallback callback) {
if (!app_service_.is_connected()) { if (!app_service_.is_connected()) {
return; return;
...@@ -304,7 +305,7 @@ void AppServiceProxy::GetMenuModel(const std::string& app_id, ...@@ -304,7 +305,7 @@ void AppServiceProxy::GetMenuModel(const std::string& app_id,
// TODO(crbug.com/1038487): change to use below code to call // TODO(crbug.com/1038487): change to use below code to call
// AppService->GetMenuModel when GetMenuModel is added to mojom. // AppService->GetMenuModel when GetMenuModel is added to mojom.
// apps::mojom::AppType app_type = cache_.GetAppType(app_id); // apps::mojom::AppType app_type = cache_.GetAppType(app_id);
// app_service_->GetMenuModel(app_type, app_id, menu_type, // app_service_->GetMenuModel(app_type, app_id, menu_type, display_id,
// std::move(callback)); // std::move(callback));
} }
......
...@@ -135,9 +135,11 @@ class AppServiceProxy : public KeyedService, ...@@ -135,9 +135,11 @@ class AppServiceProxy : public KeyedService,
// as false directly and removes the paused app icon effect. // as false directly and removes the paused app icon effect.
void UnpauseApps(const std::set<std::string>& app_ids); void UnpauseApps(const std::set<std::string>& app_ids);
// Returns the menu items for the given |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, void GetMenuModel(const std::string& app_id,
apps::mojom::MenuType menu_type, apps::mojom::MenuType menu_type,
int64_t display_id,
GetMenuModelCallback callback); GetMenuModelCallback callback);
// Opens native settings for the app with |app_id|. // Opens native settings for the app with |app_id|.
......
...@@ -492,6 +492,7 @@ void ArcApps::UnpauseApps(const std::string& app_id) { ...@@ -492,6 +492,7 @@ void ArcApps::UnpauseApps(const std::string& app_id) {
void ArcApps::GetMenuModel(const std::string& app_id, void ArcApps::GetMenuModel(const std::string& app_id,
apps::mojom::MenuType menu_type, apps::mojom::MenuType menu_type,
int64_t display_id,
GetMenuModelCallback callback) { GetMenuModelCallback callback) {
ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_); ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile_);
if (!prefs) { if (!prefs) {
......
...@@ -88,6 +88,7 @@ class ArcApps : public KeyedService, ...@@ -88,6 +88,7 @@ class ArcApps : public KeyedService,
void UnpauseApps(const std::string& app_id) override; void UnpauseApps(const std::string& app_id) override;
void GetMenuModel(const std::string& app_id, void GetMenuModel(const std::string& app_id,
apps::mojom::MenuType menu_type, apps::mojom::MenuType menu_type,
int64_t display_id,
GetMenuModelCallback callback); GetMenuModelCallback callback);
void OpenNativeSettings(const std::string& app_id) override; void OpenNativeSettings(const std::string& app_id) override;
void OnPreferredAppSet(const std::string& app_id, void OnPreferredAppSet(const std::string& app_id,
......
...@@ -192,6 +192,7 @@ void BuiltInChromeOsApps::UnpauseApps(const std::string& app_id) { ...@@ -192,6 +192,7 @@ void BuiltInChromeOsApps::UnpauseApps(const std::string& app_id) {
void BuiltInChromeOsApps::GetMenuModel(const std::string& app_id, void BuiltInChromeOsApps::GetMenuModel(const std::string& app_id,
apps::mojom::MenuType menu_type, apps::mojom::MenuType menu_type,
int64_t display_id,
GetMenuModelCallback callback) { GetMenuModelCallback callback) {
apps::mojom::MenuItemsPtr menu_items = apps::mojom::MenuItems::New(); apps::mojom::MenuItemsPtr menu_items = apps::mojom::MenuItems::New();
......
...@@ -63,6 +63,7 @@ class BuiltInChromeOsApps : public apps::mojom::Publisher { ...@@ -63,6 +63,7 @@ class BuiltInChromeOsApps : public apps::mojom::Publisher {
void UnpauseApps(const std::string& app_id) override; void UnpauseApps(const std::string& app_id) override;
void GetMenuModel(const std::string& app_id, void GetMenuModel(const std::string& app_id,
apps::mojom::MenuType menu_type, apps::mojom::MenuType menu_type,
int64_t display_id,
GetMenuModelCallback callback); GetMenuModelCallback callback);
void OpenNativeSettings(const std::string& app_id) override; void OpenNativeSettings(const std::string& app_id) override;
void OnPreferredAppSet(const std::string& app_id, void OnPreferredAppSet(const std::string& app_id,
......
...@@ -18,12 +18,37 @@ ...@@ -18,12 +18,37 @@
#include "chrome/grit/chrome_unscaled_resources.h" #include "chrome/grit/chrome_unscaled_resources.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "components/prefs/pref_change_registrar.h" #include "components/prefs/pref_change_registrar.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/strings/grit/ui_strings.h"
// TODO(crbug.com/826982): the equivalent of // TODO(crbug.com/826982): the equivalent of
// CrostiniAppModelBuilder::MaybeCreateRootFolder. Does some sort of "root // CrostiniAppModelBuilder::MaybeCreateRootFolder. Does some sort of "root
// folder" abstraction belong here (on the publisher side of the App Service) // folder" abstraction belong here (on the publisher side of the App Service)
// or should we hard-code that in one particular subscriber (the App List UI)? // or should we hard-code that in one particular subscriber (the App List UI)?
namespace {
bool ShouldShowDisplayDensityMenuItem(const std::string& app_id,
apps::mojom::MenuType menu_type,
int64_t display_id) {
// The default terminal app is crosh in a Chrome window and it doesn't run in
// the Crostini container so it doesn't support display density the same way.
if (menu_type != apps::mojom::MenuType::kShelf ||
app_id == crostini::GetTerminalId()) {
return false;
}
display::Display d;
if (!display::Screen::GetScreen()->GetDisplayWithDisplayId(display_id, &d)) {
return true;
}
return d.device_scale_factor() != 1.0;
}
} // namespace
namespace apps { namespace apps {
CrostiniApps::CrostiniApps( CrostiniApps::CrostiniApps(
...@@ -177,8 +202,14 @@ void CrostiniApps::UnpauseApps(const std::string& app_id) { ...@@ -177,8 +202,14 @@ void CrostiniApps::UnpauseApps(const std::string& app_id) {
void CrostiniApps::GetMenuModel(const std::string& app_id, void CrostiniApps::GetMenuModel(const std::string& app_id,
apps::mojom::MenuType menu_type, apps::mojom::MenuType menu_type,
int64_t display_id,
GetMenuModelCallback callback) { GetMenuModelCallback callback) {
apps::mojom::MenuItemsPtr menu_items = apps::mojom::MenuItems::New(); apps::mojom::MenuItemsPtr menu_items = apps::mojom::MenuItems::New();
if (menu_type == apps::mojom::MenuType::kShelf) {
AddCommandItem(ash::MENU_NEW_WINDOW, IDS_APP_LIST_NEW_WINDOW, &menu_items);
}
if (crostini::IsUninstallable(profile_, app_id)) { if (crostini::IsUninstallable(profile_, app_id)) {
AddCommandItem(ash::UNINSTALL, IDS_APP_LIST_UNINSTALL_ITEM, &menu_items); AddCommandItem(ash::UNINSTALL, IDS_APP_LIST_UNINSTALL_ITEM, &menu_items);
} }
...@@ -189,6 +220,31 @@ void CrostiniApps::GetMenuModel(const std::string& app_id, ...@@ -189,6 +220,31 @@ void CrostiniApps::GetMenuModel(const std::string& app_id,
&menu_items); &menu_items);
} }
if (ShouldAddOpenItem(app_id, menu_type, profile_)) {
AddCommandItem(ash::MENU_OPEN_NEW, IDS_APP_CONTEXT_MENU_ACTIVATE_ARC,
&menu_items);
}
if (ShouldAddCloseItem(app_id, menu_type, profile_)) {
AddCommandItem(ash::MENU_CLOSE, IDS_SHELF_CONTEXT_MENU_CLOSE, &menu_items);
}
// Offer users the ability to toggle per-application UI scaling.
// Some apps have high-density display support and do not require scaling
// to match the system display density, but others are density-unaware and
// look better when scaled to match the display density.
if (ShouldShowDisplayDensityMenuItem(app_id, menu_type, display_id)) {
base::Optional<crostini::CrostiniRegistryService::Registration>
registration = registry_->GetRegistration(app_id);
if (registration->IsScaled()) {
AddCommandItem(ash::CROSTINI_USE_HIGH_DENSITY,
IDS_CROSTINI_USE_HIGH_DENSITY, &menu_items);
} else {
AddCommandItem(ash::CROSTINI_USE_LOW_DENSITY,
IDS_CROSTINI_USE_LOW_DENSITY, &menu_items);
}
}
std::move(callback).Run(std::move(menu_items)); std::move(callback).Run(std::move(menu_items));
} }
......
...@@ -81,6 +81,7 @@ class CrostiniApps : public KeyedService, ...@@ -81,6 +81,7 @@ class CrostiniApps : public KeyedService,
void UnpauseApps(const std::string& app_id) override; void UnpauseApps(const std::string& app_id) override;
void GetMenuModel(const std::string& app_id, void GetMenuModel(const std::string& app_id,
apps::mojom::MenuType menu_type, apps::mojom::MenuType menu_type,
int64_t display_id,
GetMenuModelCallback callback); GetMenuModelCallback callback);
void OpenNativeSettings(const std::string& app_id) override; void OpenNativeSettings(const std::string& app_id) override;
void OnPreferredAppSet(const std::string& app_id, void OnPreferredAppSet(const std::string& app_id,
......
...@@ -647,6 +647,7 @@ void ExtensionApps::UnpauseApps(const std::string& app_id) { ...@@ -647,6 +647,7 @@ void ExtensionApps::UnpauseApps(const std::string& app_id) {
void ExtensionApps::GetMenuModel(const std::string& app_id, void ExtensionApps::GetMenuModel(const std::string& app_id,
apps::mojom::MenuType menu_type, apps::mojom::MenuType menu_type,
int64_t display_id,
GetMenuModelCallback callback) { GetMenuModelCallback callback) {
extensions::ExtensionRegistry* registry = extensions::ExtensionRegistry* registry =
extensions::ExtensionRegistry::Get(profile_); extensions::ExtensionRegistry::Get(profile_);
......
...@@ -108,6 +108,7 @@ class ExtensionApps : public apps::mojom::Publisher, ...@@ -108,6 +108,7 @@ class ExtensionApps : public apps::mojom::Publisher,
void UnpauseApps(const std::string& app_id) override; void UnpauseApps(const std::string& app_id) override;
void GetMenuModel(const std::string& app_id, void GetMenuModel(const std::string& app_id,
apps::mojom::MenuType menu_type, apps::mojom::MenuType menu_type,
int64_t display_id,
GetMenuModelCallback callback); GetMenuModelCallback callback);
void OpenNativeSettings(const std::string& app_id) override; void OpenNativeSettings(const std::string& app_id) override;
void OnPreferredAppSet(const std::string& app_id, void OnPreferredAppSet(const std::string& app_id,
......
...@@ -353,6 +353,7 @@ void WebApps::UnpauseApps(const std::string& app_id) { ...@@ -353,6 +353,7 @@ void WebApps::UnpauseApps(const std::string& app_id) {
void WebApps::GetMenuModel(const std::string& app_id, void WebApps::GetMenuModel(const std::string& app_id,
apps::mojom::MenuType menu_type, apps::mojom::MenuType menu_type,
int64_t display_id,
GetMenuModelCallback callback) { GetMenuModelCallback callback) {
const web_app::WebApp* web_app = GetWebApp(app_id); const web_app::WebApp* web_app = GetWebApp(app_id);
if (!web_app) { if (!web_app) {
......
...@@ -88,6 +88,7 @@ class WebApps : public apps::mojom::Publisher, ...@@ -88,6 +88,7 @@ class WebApps : public apps::mojom::Publisher,
void UnpauseApps(const std::string& app_id) override; void UnpauseApps(const std::string& app_id) override;
void GetMenuModel(const std::string& app_id, void GetMenuModel(const std::string& app_id,
apps::mojom::MenuType menu_type, apps::mojom::MenuType menu_type,
int64_t display_id,
GetMenuModelCallback callback); GetMenuModelCallback callback);
void OpenNativeSettings(const std::string& app_id) override; void OpenNativeSettings(const std::string& app_id) override;
void OnPreferredAppSet(const std::string& app_id, void OnPreferredAppSet(const std::string& app_id,
......
...@@ -187,6 +187,7 @@ void AppServiceImpl::UnpauseApps(apps::mojom::AppType app_type, ...@@ -187,6 +187,7 @@ void AppServiceImpl::UnpauseApps(apps::mojom::AppType app_type,
void AppServiceImpl::GetMenuModel(apps::mojom::AppType app_type, void AppServiceImpl::GetMenuModel(apps::mojom::AppType app_type,
const std::string& app_id, const std::string& app_id,
apps::mojom::MenuType menu_type, apps::mojom::MenuType menu_type,
int64_t display_id,
GetMenuModelCallback callback) { GetMenuModelCallback callback) {
auto iter = publishers_.find(app_type); auto iter = publishers_.find(app_type);
if (iter == publishers_.end()) { if (iter == publishers_.end()) {
...@@ -196,7 +197,8 @@ void AppServiceImpl::GetMenuModel(apps::mojom::AppType app_type, ...@@ -196,7 +197,8 @@ void AppServiceImpl::GetMenuModel(apps::mojom::AppType app_type,
// TODO(crbug.com/1038487): change to use below code to call // TODO(crbug.com/1038487): change to use below code to call
// AppServiceProxy->GetMenuModel when GetMenuModel is added to mojom. // AppServiceProxy->GetMenuModel when GetMenuModel is added to mojom.
// iter->second->GetMenuModel(app_id, menu_type, std::move(callback)); // iter->second->GetMenuModel(app_id, menu_type, display_id,
// std::move(callback));
} }
void AppServiceImpl::OpenNativeSettings(apps::mojom::AppType app_type, void AppServiceImpl::OpenNativeSettings(apps::mojom::AppType app_type,
......
...@@ -79,6 +79,7 @@ class AppServiceImpl : public apps::mojom::AppService { ...@@ -79,6 +79,7 @@ class AppServiceImpl : public apps::mojom::AppService {
void GetMenuModel(apps::mojom::AppType app_type, void GetMenuModel(apps::mojom::AppType app_type,
const std::string& app_id, const std::string& app_id,
apps::mojom::MenuType menu_type, apps::mojom::MenuType menu_type,
int64_t display_id,
GetMenuModelCallback callback); GetMenuModelCallback callback);
void OpenNativeSettings(apps::mojom::AppType app_type, void OpenNativeSettings(apps::mojom::AppType app_type,
const std::string& app_id) override; const std::string& app_id) override;
......
...@@ -100,6 +100,7 @@ class FakePublisher : public apps::mojom::Publisher { ...@@ -100,6 +100,7 @@ class FakePublisher : public apps::mojom::Publisher {
base::OnceCallback<void(apps::mojom::MenuItemsPtr)>; base::OnceCallback<void(apps::mojom::MenuItemsPtr)>;
void GetMenuModel(const std::string& app_id, void GetMenuModel(const std::string& app_id,
apps::mojom::MenuType menu_type, apps::mojom::MenuType menu_type,
int64_t display_id,
GetMenuModelCallback callback) {} GetMenuModelCallback callback) {}
void PauseApp(const std::string& app_id) override {} void PauseApp(const std::string& app_id) override {}
......
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