Commit 3dd42b2f authored by nancy's avatar nancy Committed by Commit Bot

Add Shelf context menu for built_in apps in AppService.

Add Shelf menu items, MENU_OPEN_NEW and MENU_CLOSE, for built_in apps:
https://cs.chromium.org/chromium/src/chrome/browser/ui/ash/launcher/internal_app_shelf_context_menu.cc?l=25

BUG=1038487

Change-Id: I2b50bf2aa5f393b0e23645e72ac7b87b7b7d9534
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2009601Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#733488}
parent a0db5273
......@@ -194,10 +194,22 @@ void BuiltInChromeOsApps::GetMenuModel(const std::string& app_id,
apps::mojom::MenuType menu_type,
GetMenuModelCallback callback) {
apps::mojom::MenuItemsPtr menu_items = apps::mojom::MenuItems::New();
if (app_id == plugin_vm::kPluginVmAppId) {
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);
}
if (app_id == plugin_vm::kPluginVmAppId &&
plugin_vm::IsPluginVmRunning(profile_)) {
AddCommandItem(ash::STOP_APP, IDS_PLUGIN_VM_SHUT_DOWN_MENU_ITEM,
&menu_items);
}
std::move(callback).Run(std::move(menu_items));
}
......
......@@ -7,6 +7,8 @@
#include <utility>
#include "ash/public/cpp/app_menu_constants.h"
#include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
#include "chrome/grit/generated_resources.h"
namespace {
......@@ -65,4 +67,38 @@ void CreateOpenNewSubmenu(uint32_t string_id,
(*menu_items)->items.push_back(std::move(menu_item));
}
bool ShouldAddOpenItem(const std::string& app_id,
apps::mojom::MenuType menu_type,
Profile* profile) {
if (menu_type != apps::mojom::MenuType::kShelf) {
return false;
}
apps::AppServiceProxy* proxy =
apps::AppServiceProxyFactory::GetForProfile(profile);
DCHECK(proxy);
if (proxy->InstanceRegistry().GetWindows(app_id).empty()) {
return true;
}
return false;
}
bool ShouldAddCloseItem(const std::string& app_id,
apps::mojom::MenuType menu_type,
Profile* profile) {
if (menu_type != apps::mojom::MenuType::kShelf) {
return false;
}
apps::AppServiceProxy* proxy =
apps::AppServiceProxyFactory::GetForProfile(profile);
DCHECK(proxy);
if (proxy->InstanceRegistry().GetWindows(app_id).empty()) {
return false;
}
return true;
}
} // namespace apps
......@@ -7,6 +7,8 @@
#include "chrome/services/app_service/public/mojom/types.mojom.h"
class Profile;
namespace apps {
void AddCommandItem(uint32_t command_id,
......@@ -25,6 +27,14 @@ void AddRadioItem(uint32_t command_id,
void CreateOpenNewSubmenu(uint32_t string_id,
apps::mojom::MenuItemsPtr* menu_items);
bool ShouldAddOpenItem(const std::string& app_id,
apps::mojom::MenuType menu_type,
Profile* profile);
bool ShouldAddCloseItem(const std::string& app_id,
apps::mojom::MenuType menu_type,
Profile* profile);
} // namespace apps
#endif // CHROME_BROWSER_APPS_APP_SERVICE_MENU_UTIL_H_
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