#include "chrome/browser/ui/views/extensions/extensions_menu_view_controller.h"
#include <algorithm>
#include "base/functional/bind.h"
#include "base/i18n/case_conversion.h"
#include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h"
#include "base/notreached.h"
#include "chrome/browser/extensions/extension_action_runner.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/extensions/permissions/site_permissions_helper.h"
#include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/extensions/extension_action_view_controller.h"
#include "chrome/browser/ui/extensions/extensions_container.h"
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
#include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h"
#include "chrome/browser/ui/toolbar/toolbar_actions_model.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/browser/ui/views/extensions/extensions_dialogs_utils.h"
#include "chrome/browser/ui/views/extensions/extensions_menu_item_view.h"
#include "chrome/browser/ui/views/extensions/extensions_menu_main_page_view.h"
#include "chrome/browser/ui/views/extensions/extensions_menu_site_permissions_page_view.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/permissions_manager.h"
#include "extensions/common/extension_id.h"
#include "ui/base/metadata/metadata_types.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h"
#include "ui/views/view_utils.h"
#include "ui/views/widget/widget.h"
namespace {
PermissionsManager;
SitePermissionsHelper;
const extensions::Extension* GetExtension(
Browser* browser,
extensions::ExtensionId extension_id) { … }
std::vector<std::string> SortExtensionsByName(
ToolbarActionsModel& toolbar_model) { … }
size_t FindIndex(ToolbarActionsModel& toolbar_model,
const ToolbarActionsModel::ActionId& action_id) { … }
ExtensionsMenuMainPageView* GetMainPage(views::View* page) { … }
ExtensionsMenuSitePermissionsPageView* GetSitePermissionsPage(
views::View* page) { … }
bool HasEnterpriseForcedAccess(const extensions::Extension& extension,
Profile& profile) { … }
bool IsSiteSettingsToggleVisible(const ToolbarActionsModel& toolbar_model,
content::WebContents* web_contents) { … }
bool IsSiteSettingsToggleOn(Browser* browser,
content::WebContents* web_contents) { … }
bool IsSitePermissionsButtonVisible(const extensions::Extension& extension,
Profile& profile,
const ToolbarActionsModel& toolbar_model,
content::WebContents& web_contents) { … }
bool CanUserCustomizeExtensionSiteAccess(
const extensions::Extension& extension,
Profile& profile,
const ToolbarActionsModel& toolbar_model,
content::WebContents& web_contents) { … }
ExtensionMenuItemView::SitePermissionsButtonState GetSitePermissionsButtonState(
const extensions::Extension& extension,
Profile& profile,
const ToolbarActionsModel& toolbar_model,
content::WebContents& web_contents) { … }
ExtensionMenuItemView::SitePermissionsButtonAccess
GetSitePermissionsButtonAccess(const extensions::Extension& extension,
Profile& profile,
const ToolbarActionsModel& toolbar_model,
content::WebContents& web_contents) { … }
ExtensionMenuItemView::SiteAccessToggleState GetSiteAccessToggleState(
const extensions::Extension& extension,
Profile& profile,
const ToolbarActionsModel& toolbar_model,
content::WebContents& web_contents) { … }
ExtensionsMenuMainPageView::MessageSectionState GetMessageSectionState(
Profile& profile,
const ToolbarActionsModel& toolbar_model,
content::WebContents& web_contents) { … }
void LogSiteAccessUpdate(PermissionsManager::UserSiteAccess site_access) { … }
}
ExtensionsMenuViewController::ExtensionsMenuViewController(
Browser* browser,
ExtensionsContainer* extensions_container,
views::View* bubble_contents,
views::BubbleDialogDelegate* bubble_delegate)
: … { … }
ExtensionsMenuViewController::~ExtensionsMenuViewController() { … }
void ExtensionsMenuViewController::OpenMainPage() { … }
void ExtensionsMenuViewController::OpenSitePermissionsPage(
const extensions::ExtensionId& extension_id) { … }
void ExtensionsMenuViewController::CloseBubble() { … }
void ExtensionsMenuViewController::OnSiteAccessSelected(
const extensions::ExtensionId& extension_id,
PermissionsManager::UserSiteAccess site_access) { … }
void ExtensionsMenuViewController::OnSiteSettingsToggleButtonPressed(
bool is_on) { … }
void ExtensionsMenuViewController::OnExtensionToggleSelected(
const extensions::ExtensionId& extension_id,
bool is_on) { … }
void ExtensionsMenuViewController::OnReloadPageButtonClicked() { … }
void ExtensionsMenuViewController::OnAllowExtensionClicked(
const extensions::ExtensionId& extension_id) { … }
void ExtensionsMenuViewController::OnDismissExtensionClicked(
const extensions::ExtensionId& extension_id) { … }
void ExtensionsMenuViewController::OnShowRequestsTogglePressed(
const extensions::ExtensionId& extension_id,
bool is_on) { … }
void ExtensionsMenuViewController::TabChangedAt(content::WebContents* contents,
int index,
TabChangeType change_type) { … }
void ExtensionsMenuViewController::OnTabStripModelChanged(
TabStripModel* tab_strip_model,
const TabStripModelChange& change,
const TabStripSelectionChange& selection) { … }
void ExtensionsMenuViewController::UpdatePage(
content::WebContents* web_contents) { … }
void ExtensionsMenuViewController::UpdateMainPage(
ExtensionsMenuMainPageView* main_page,
content::WebContents* web_contents) { … }
void ExtensionsMenuViewController::UpdateSitePermissionsPage(
ExtensionsMenuSitePermissionsPageView* site_permissions_page,
content::WebContents* web_contents) { … }
void ExtensionsMenuViewController::OnToolbarActionAdded(
const ToolbarActionsModel::ActionId& action_id) { … }
void ExtensionsMenuViewController::OnToolbarActionRemoved(
const ToolbarActionsModel::ActionId& action_id) { … }
void ExtensionsMenuViewController::OnToolbarActionUpdated(
const ToolbarActionsModel::ActionId& action_id) { … }
void ExtensionsMenuViewController::OnToolbarModelInitialized() { … }
void ExtensionsMenuViewController::OnToolbarPinnedActionsChanged() { … }
void ExtensionsMenuViewController::OnUserPermissionsSettingsChanged(
const PermissionsManager::UserPermissionsSettings& settings) { … }
void ExtensionsMenuViewController::OnShowAccessRequestsInToolbarChanged(
const extensions::ExtensionId& extension_id,
bool can_show_requests) { … }
void ExtensionsMenuViewController::OnSiteAccessRequestDismissedByUser(
const extensions::ExtensionId& extension_id,
const url::Origin& origin) { … }
void ExtensionsMenuViewController::OnSiteAccessRequestAdded(
const extensions::ExtensionId& extension_id,
int tab_id) { … }
void ExtensionsMenuViewController::OnSiteAccessRequestUpdated(
const extensions::ExtensionId& extension_id,
int tab_id) { … }
void ExtensionsMenuViewController::OnSiteAccessRequestRemoved(
const extensions::ExtensionId& extension_id,
int tab_id) { … }
void ExtensionsMenuViewController::OnSiteAccessRequestsCleared(int tab_id) { … }
ExtensionsMenuMainPageView*
ExtensionsMenuViewController::GetMainPageViewForTesting() { … }
ExtensionsMenuSitePermissionsPageView*
ExtensionsMenuViewController::GetSitePermissionsPageForTesting() { … }
void ExtensionsMenuViewController::SwitchToPage(
std::unique_ptr<views::View> page) { … }
void ExtensionsMenuViewController::PopulateMainPage(
ExtensionsMenuMainPageView* main_page) { … }
void ExtensionsMenuViewController::InsertMenuItemMainPage(
ExtensionsMenuMainPageView* main_page,
const extensions::ExtensionId& extension_id,
int index) { … }
void ExtensionsMenuViewController::AddOrUpdateExtensionRequestingAccess(
ExtensionsMenuMainPageView* main_page,
const extensions::ExtensionId& extension_id,
int index,
content::WebContents* web_contents) { … }
content::WebContents* ExtensionsMenuViewController::GetActiveWebContents()
const { … }