Commit cafda50c authored by khmel's avatar khmel Committed by Commit bot

arc: Fix Arc app item context menu.

This fixes arc context menu. Original bug requests to make
"Show app info" menu item disable when Arc is not ready only.
This also includes following related fixes:
  1. "Show app info" is disabled until Arc is started.
  2. Before "Uninstall" was not shown when Arc is not started.
     This also makes it disable in this case for consistency.
  3. Add separator before "Uninstall/Show app info" group regardless
     "Uninstall" item is shown or not. Before, "Show app info" menu
     was not separated in case uninstall was not present.
  4. "Uninstall" shortcut is available always, regardless of
     Arc enabled or disabled.
  5. No menu items for non-existing Arc app.
TEST=Manually on the device.
TEST=Extended unit_tests.
BUG=652741
BUG=b/30646620

Review-Url: https://codereview.chromium.org/2393453002
Cr-Commit-Position: refs/heads/master@{#422831}
parent d47244ce
......@@ -24,6 +24,15 @@ ArcAppContextMenu::~ArcAppContextMenu() {
}
void ArcAppContextMenu::BuildMenu(ui::SimpleMenuModel* menu_model) {
const ArcAppListPrefs* arc_prefs = ArcAppListPrefs::Get(profile());
DCHECK(arc_prefs);
std::unique_ptr<ArcAppListPrefs::AppInfo> app_info =
arc_prefs->GetApp(app_id());
if (!app_info) {
LOG(ERROR) << "App " << app_id() << " is not available.";
return;
}
if (!controller()->IsAppOpen(app_id())) {
menu_model->AddItemWithStringId(LAUNCH_NEW,
IDS_APP_CONTEXT_MENU_ACTIVATE_ARC);
......@@ -31,21 +40,38 @@ void ArcAppContextMenu::BuildMenu(ui::SimpleMenuModel* menu_model) {
}
// Create default items.
app_list::AppContextMenu::BuildMenu(menu_model);
if (CanBeUninstalled()) {
menu_model->AddSeparator(ui::NORMAL_SEPARATOR);
const ArcAppListPrefs* arc_prefs = ArcAppListPrefs::Get(profile());
DCHECK(arc_prefs);
if (arc_prefs->IsShortcut(app_id())) {
menu_model->AddItemWithStringId(UNINSTALL, IDS_APP_LIST_REMOVE_SHORTCUT);
} else {
menu_model->AddItemWithStringId(UNINSTALL, IDS_APP_LIST_UNINSTALL_ITEM);
}
}
menu_model->AddSeparator(ui::NORMAL_SEPARATOR);
if (arc_prefs->IsShortcut(app_id()))
menu_model->AddItemWithStringId(UNINSTALL, IDS_APP_LIST_REMOVE_SHORTCUT);
else if (!app_info->sticky)
menu_model->AddItemWithStringId(UNINSTALL, IDS_APP_LIST_UNINSTALL_ITEM);
// App Info item.
menu_model->AddItemWithStringId(SHOW_APP_INFO,
IDS_APP_CONTEXT_MENU_SHOW_INFO);
}
bool ArcAppContextMenu::IsCommandIdEnabled(int command_id) const {
const ArcAppListPrefs* arc_prefs = ArcAppListPrefs::Get(profile());
DCHECK(arc_prefs);
std::unique_ptr<ArcAppListPrefs::AppInfo> app_info =
arc_prefs->GetApp(app_id());
switch (command_id) {
case UNINSTALL:
return app_info &&
!app_info->sticky &&
(app_info->ready || app_info->shortcut);
case SHOW_APP_INFO:
return app_info && app_info->ready;
default:
return app_list::AppContextMenu::IsCommandIdEnabled(command_id);
}
return false;
}
void ArcAppContextMenu::ExecuteCommand(int command_id, int event_flags) {
switch (command_id) {
case LAUNCH_NEW:
......@@ -96,11 +122,3 @@ void ArcAppContextMenu::ShowPackageInfo() {
if (arc::ShowPackageInfo(app_info->package_name))
controller()->DismissView();
}
bool ArcAppContextMenu::CanBeUninstalled() const {
const ArcAppListPrefs* arc_prefs = ArcAppListPrefs::Get(profile());
DCHECK(arc_prefs);
std::unique_ptr<ArcAppListPrefs::AppInfo> app_info =
arc_prefs->GetApp(app_id());
return app_info && app_info->ready && !app_info->sticky;
}
......@@ -30,15 +30,13 @@ class ArcAppContextMenu : public app_list::AppContextMenu {
// ui::SimpleMenuModel::Delegate overrides:
void ExecuteCommand(int command_id, int event_flags) override;
bool IsCommandIdEnabled(int command_id) const override;
private:
void IsAppOpen();
void UninstallPackage();
void ShowPackageInfo();
bool CanBeUninstalled() const;
bool IsShortcut() const;
DISALLOW_COPY_AND_ASSIGN(ArcAppContextMenu);
};
......
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