Commit 8c10f214 authored by nancy's avatar nancy Committed by Commit Bot

Add IsCommandIdEnabled function for AppServiceContextMenu.

Check whether extensions::ContextMenuMatcher commands are enabled in
AppServiceContextMenu, which is the current implementation:
https://cs.chromium.org/chromium/src/chrome/browser/ui/app_list/extension_app_context_menu.cc?l=167

Also update set LaunchType command to add SetAppUserDisplayMode function
for Web apps when kDesktopPWAsWithoutExtensions is enabled:
https://cs.chromium.org/chromium/src/chrome/browser/ui/app_list/web_app_context_menu.cc?l=131

BUG=1038487

Change-Id: Ib8e6582313938dca6291aabbc872a094e4a994bc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2025010Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#736079}
parent ca43517b
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "chrome/browser/ui/app_list/extension_app_utils.h" #include "chrome/browser/ui/app_list/extension_app_utils.h"
#include "chrome/browser/ui/chrome_pages.h" #include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/webui/settings/chromeos/app_management/app_management_uma.h" #include "chrome/browser/ui/webui/settings/chromeos/app_management/app_management_uma.h"
#include "chrome/browser/web_applications/components/app_registry_controller.h"
#include "chrome/browser/web_applications/web_app_provider.h" #include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
...@@ -122,14 +123,7 @@ void AppServiceContextMenu::ExecuteCommand(int command_id, int event_flags) { ...@@ -122,14 +123,7 @@ void AppServiceContextMenu::ExecuteCommand(int command_id, int event_flags) {
default: default:
if (command_id >= ash::USE_LAUNCH_TYPE_COMMAND_START && if (command_id >= ash::USE_LAUNCH_TYPE_COMMAND_START &&
command_id < ash::USE_LAUNCH_TYPE_COMMAND_END) { command_id < ash::USE_LAUNCH_TYPE_COMMAND_END) {
// Hosted apps can only toggle between LAUNCH_TYPE_WINDOW and SetLaunchType(command_id);
// LAUNCH_TYPE_REGULAR.
extensions::LaunchType launch_type =
(controller()->GetExtensionLaunchType(profile(), app_id()) ==
extensions::LAUNCH_TYPE_WINDOW)
? extensions::LAUNCH_TYPE_REGULAR
: extensions::LAUNCH_TYPE_WINDOW;
controller()->SetExtensionLaunchType(profile(), app_id(), launch_type);
return; return;
} }
...@@ -194,6 +188,14 @@ bool AppServiceContextMenu::IsCommandIdChecked(int command_id) const { ...@@ -194,6 +188,14 @@ bool AppServiceContextMenu::IsCommandIdChecked(int command_id) const {
} }
} }
bool AppServiceContextMenu::IsCommandIdEnabled(int command_id) const {
if (extensions::ContextMenuMatcher::IsExtensionsCustomCommandId(command_id) &&
extension_menu_items_) {
return extension_menu_items_->IsCommandIdEnabled(command_id);
}
return AppContextMenu::IsCommandIdEnabled(command_id);
}
void AppServiceContextMenu::OnGetMenuModel( void AppServiceContextMenu::OnGetMenuModel(
GetMenuModelCallback callback, GetMenuModelCallback callback,
apps::mojom::MenuItemsPtr menu_items) { apps::mojom::MenuItemsPtr menu_items) {
...@@ -287,3 +289,43 @@ void AppServiceContextMenu::ShowAppInfo() { ...@@ -287,3 +289,43 @@ void AppServiceContextMenu::ShowAppInfo() {
controller()->DoShowAppInfoFlow(profile(), app_id()); controller()->DoShowAppInfoFlow(profile(), app_id());
} }
void AppServiceContextMenu::SetLaunchType(int command_id) {
switch (app_type_) {
case apps::mojom::AppType::kWeb:
if (base::FeatureList::IsEnabled(
features::kDesktopPWAsWithoutExtensions)) {
// Web apps can only toggle between kStandalone and kBrowser.
web_app::DisplayMode user_display_mode =
ConvertUseLaunchTypeCommandToDisplayMode(command_id);
if (user_display_mode != web_app::DisplayMode::kUndefined) {
auto* provider = web_app::WebAppProvider::Get(profile());
DCHECK(provider);
provider->registry_controller().SetAppUserDisplayMode(
app_id(), user_display_mode);
}
return;
}
// Otherwise deliberately fall through to fallback on Bookmark Apps.
FALLTHROUGH;
case apps::mojom::AppType::kExtension: {
// Hosted apps can only toggle between LAUNCH_TYPE_WINDOW and
// LAUNCH_TYPE_REGULAR.
extensions::LaunchType launch_type =
(controller()->GetExtensionLaunchType(profile(), app_id()) ==
extensions::LAUNCH_TYPE_WINDOW)
? extensions::LAUNCH_TYPE_REGULAR
: extensions::LAUNCH_TYPE_WINDOW;
controller()->SetExtensionLaunchType(profile(), app_id(), launch_type);
return;
}
case apps::mojom::AppType::kArc:
FALLTHROUGH;
case apps::mojom::AppType::kCrostini:
FALLTHROUGH;
case apps::mojom::AppType::kBuiltIn:
FALLTHROUGH;
default:
return;
}
}
...@@ -33,10 +33,14 @@ class AppServiceContextMenu : public app_list::AppContextMenu { ...@@ -33,10 +33,14 @@ class AppServiceContextMenu : public app_list::AppContextMenu {
AppListControllerDelegate* controller); AppListControllerDelegate* controller);
~AppServiceContextMenu() override; ~AppServiceContextMenu() override;
AppServiceContextMenu(const AppServiceContextMenu&) = delete;
AppServiceContextMenu& operator=(const AppServiceContextMenu&) = delete;
// AppContextMenu overrides: // AppContextMenu overrides:
void GetMenuModel(GetMenuModelCallback callback) override; void GetMenuModel(GetMenuModelCallback callback) override;
void ExecuteCommand(int command_id, int event_flags) override; void ExecuteCommand(int command_id, int event_flags) override;
bool IsCommandIdChecked(int command_id) const override; bool IsCommandIdChecked(int command_id) const override;
bool IsCommandIdEnabled(int command_id) const override;
private: private:
void OnGetMenuModel(GetMenuModelCallback callback, void OnGetMenuModel(GetMenuModelCallback callback,
...@@ -54,6 +58,8 @@ class AppServiceContextMenu : public app_list::AppContextMenu { ...@@ -54,6 +58,8 @@ class AppServiceContextMenu : public app_list::AppContextMenu {
void ShowAppInfo(); void ShowAppInfo();
void SetLaunchType(int command_id);
apps::mojom::AppType app_type_; apps::mojom::AppType app_type_;
// The SimpleMenuModel used to hold the submenu items. // The SimpleMenuModel used to hold the submenu items.
......
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