#include "chrome/browser/ui/extensions/extension_action_view_controller.h"
#include <memory>
#include <string>
#include <utility>
#include "base/check_op.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_functions.h"
#include "base/strings/strcat.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/extensions/api/side_panel/side_panel_service.h"
#include "chrome/browser/extensions/commands/command_service.h"
#include "chrome/browser/extensions/extension_action_runner.h"
#include "chrome/browser/extensions/extension_context_menu_model.h"
#include "chrome/browser/extensions/extension_view.h"
#include "chrome/browser/extensions/extension_view_host.h"
#include "chrome/browser/extensions/extension_view_host_factory.h"
#include "chrome/browser/extensions/permissions/site_permissions_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/extensions/extension_action_platform_delegate.h"
#include "chrome/browser/ui/extensions/extension_popup_types.h"
#include "chrome/browser/ui/extensions/extension_side_panel_utils.h"
#include "chrome/browser/ui/extensions/extensions_container.h"
#include "chrome/browser/ui/extensions/icon_with_badge_image_source.h"
#include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h"
#include "chrome/grit/generated_resources.h"
#include "components/sessions/content/session_tab_helper.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_action.h"
#include "extensions/browser/extension_action_manager.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/api/extension_action/action_info.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_features.h"
#include "extensions/common/manifest_constants.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/models/image_model.h"
#include "ui/color/color_provider_manager.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/native_theme/native_theme.h"
ActionInfo;
CommandService;
ExtensionActionRunner;
PermissionsManager;
namespace {
void RecordInvocationSource(
ToolbarActionViewController::InvocationSource source) { … }
ExtensionActionViewController::HoverCardState::SiteAccess
GetHoverCardSiteAccessState(
extensions::PermissionsManager::UserSiteSetting site_setting,
extensions::SitePermissionsHelper::SiteInteraction site_interaction) { … }
ExtensionActionViewController::HoverCardState::AdminPolicy
GetHoverCardPolicyState(Browser* browser,
const extensions::ExtensionId& extension_id) { … }
}
std::unique_ptr<ExtensionActionViewController>
ExtensionActionViewController::Create(
const extensions::ExtensionId& extension_id,
Browser* browser,
ExtensionsContainer* extensions_container) { … }
bool ExtensionActionViewController::AnyActionHasCurrentSiteAccess(
const std::vector<std::unique_ptr<ToolbarActionViewController>>& actions,
content::WebContents* web_contents) { … }
ExtensionActionViewController::ExtensionActionViewController(
scoped_refptr<const extensions::Extension> extension,
Browser* browser,
extensions::ExtensionAction* extension_action,
extensions::ExtensionRegistry* extension_registry,
ExtensionsContainer* extensions_container)
: … { … }
ExtensionActionViewController::~ExtensionActionViewController() { … }
std::string ExtensionActionViewController::GetId() const { … }
void ExtensionActionViewController::SetDelegate(
ToolbarActionViewDelegate* delegate) { … }
ui::ImageModel ExtensionActionViewController::GetIcon(
content::WebContents* web_contents,
const gfx::Size& size) { … }
std::u16string ExtensionActionViewController::GetActionName() const { … }
std::u16string ExtensionActionViewController::GetActionTitle(
content::WebContents* web_contents) const { … }
std::u16string ExtensionActionViewController::GetAccessibleName(
content::WebContents* web_contents) const { … }
std::u16string ExtensionActionViewController::GetTooltip(
content::WebContents* web_contents) const { … }
bool ExtensionActionViewController::IsEnabled(
content::WebContents* web_contents) const { … }
bool ExtensionActionViewController::IsShowingPopup() const { … }
void ExtensionActionViewController::HidePopup() { … }
gfx::NativeView ExtensionActionViewController::GetPopupNativeView() { … }
ui::MenuModel* ExtensionActionViewController::GetContextMenu(
extensions::ExtensionContextMenuModel::ContextMenuSource
context_menu_source) { … }
void ExtensionActionViewController::OnContextMenuShown(
extensions::ExtensionContextMenuModel::ContextMenuSource source) { … }
void ExtensionActionViewController::OnContextMenuClosed(
extensions::ExtensionContextMenuModel::ContextMenuSource source) { … }
void ExtensionActionViewController::ExecuteUserAction(InvocationSource source) { … }
void ExtensionActionViewController::TriggerPopupForAPI(
ShowPopupCallback callback) { … }
void ExtensionActionViewController::UpdateState() { … }
void ExtensionActionViewController::UpdateHoverCard(
ToolbarActionView* action_view,
ToolbarActionHoverCardUpdateType update_type) { … }
void ExtensionActionViewController::RegisterCommand() { … }
void ExtensionActionViewController::UnregisterCommand() { … }
void ExtensionActionViewController::InspectPopup() { … }
void ExtensionActionViewController::TriggerPopupForAPI() { … }
void ExtensionActionViewController::OnIconUpdated() { … }
void ExtensionActionViewController::OnExtensionHostDestroyed(
extensions::ExtensionHost* host) { … }
extensions::SitePermissionsHelper::SiteInteraction
ExtensionActionViewController::GetSiteInteraction(
content::WebContents* web_contents) const { … }
bool ExtensionActionViewController::ExtensionIsValid() const { … }
bool ExtensionActionViewController::GetExtensionCommand(
extensions::Command* command) const { … }
ToolbarActionViewController::HoverCardState
ExtensionActionViewController::GetHoverCardState(
content::WebContents* web_contents) const { … }
bool ExtensionActionViewController::CanHandleAccelerators() const { … }
std::unique_ptr<IconWithBadgeImageSource>
ExtensionActionViewController::GetIconImageSourceForTesting(
content::WebContents* web_contents,
const gfx::Size& size) { … }
ExtensionActionViewController*
ExtensionActionViewController::GetPreferredPopupViewController() { … }
void ExtensionActionViewController::TriggerPopup(PopupShowAction show_action,
bool by_user,
ShowPopupCallback callback) { … }
void ExtensionActionViewController::ShowPopup(
std::unique_ptr<extensions::ExtensionViewHost> popup_host,
bool by_user,
PopupShowAction show_action,
ShowPopupCallback callback) { … }
void ExtensionActionViewController::OnPopupClosed() { … }
std::unique_ptr<IconWithBadgeImageSource>
ExtensionActionViewController::GetIconImageSource(
content::WebContents* web_contents,
const gfx::Size& size) { … }