// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_ASH_SHELF_STANDALONE_BROWSER_EXTENSION_APP_CONTEXT_MENU_H_
#define CHROME_BROWSER_UI_ASH_SHELF_STANDALONE_BROWSER_EXTENSION_APP_CONTEXT_MENU_H_
#include <string>
#include "base/memory/weak_ptr.h"
#include "ui/base/models/simple_menu_model.h"
// This class is responsible for displaying a context menu for a
// standalone-browser based extension app. Note that this class is used for both
// the context menu in the app list and the shelf. Any future UI surfaces in ash
// that show context menus should also use this class.
//
// Consumers of this class are responsible for ensuring that this instance
// outlives any menu models generated by this class.
class StandaloneBrowserExtensionAppContextMenu
: public ui::SimpleMenuModel::Delegate {
public:
// Describes the source of the context menu.
enum class Source { kShelf, kAppList };
StandaloneBrowserExtensionAppContextMenu(const std::string& app_id,
Source source);
~StandaloneBrowserExtensionAppContextMenu() override;
StandaloneBrowserExtensionAppContextMenu(
const StandaloneBrowserExtensionAppContextMenu&) = delete;
StandaloneBrowserExtensionAppContextMenu& operator=(
const StandaloneBrowserExtensionAppContextMenu&) = delete;
// Asynchronously generates a SimpleMenuModel.
using GetMenuModelCallback =
base::OnceCallback<void(std::unique_ptr<ui::SimpleMenuModel>)>;
void GetMenuModel(GetMenuModelCallback callback);
// SimpleMenuModel::Delegate override:
void ExecuteCommand(int command_id, int event_flags) override;
private:
// Called asynchronously by GetMenuModel.
void OnGetMenuModel(GetMenuModelCallback callback);
const std::string app_id_;
const Source source_;
base::WeakPtrFactory<StandaloneBrowserExtensionAppContextMenu>
weak_ptr_factory_{this};
};
#endif // CHROME_BROWSER_UI_ASH_SHELF_STANDALONE_BROWSER_EXTENSION_APP_CONTEXT_MENU_H_