#include "chrome/browser/extensions/menu_manager.h"
#include <memory>
#include <tuple>
#include <utility>
#include "base/check_op.h"
#include "base/containers/contains.h"
#include "base/containers/to_value_list.h"
#include "base/functional/bind.h"
#include "base/json/json_writer.h"
#include "base/notreached.h"
#include "base/observer_list.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/extensions/extension_menu_icon_loader.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/extensions/menu_manager_factory.h"
#include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/api/chrome_web_view_internal.h"
#include "chrome/common/extensions/api/context_menus.h"
#include "components/guest_view/common/guest_view_constants.h"
#include "content/public/browser/child_process_host.h"
#include "content/public/browser/context_menu_params.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_api_frame_id_map.h"
#include "extensions/browser/guest_view/web_view/web_view_guest.h"
#include "extensions/browser/state_store.h"
#include "extensions/common/extension.h"
#include "extensions/common/manifest_handlers/background_info.h"
#include "extensions/common/mojom/event_dispatcher.mojom.h"
#include "ipc/ipc_message.h"
#include "third_party/blink/public/mojom/context_menu/context_menu.mojom.h"
#include "ui/gfx/favicon_size.h"
#include "ui/gfx/text_elider.h"
ChildProcessHost;
WebContents;
kInstanceIDNone;
namespace extensions {
namespace {
const char kContextMenusKey[] = …;
const char kCheckedKey[] = …;
const char kContextsKey[] = …;
const char kDocumentURLPatternsKey[] = …;
const char kEnabledKey[] = …;
const char kMenuManagerIncognitoKey[] = …;
const char kParentUIDKey[] = …;
const char kStringUIDKey[] = …;
const char kTargetURLPatternsKey[] = …;
const char kTitleKey[] = …;
const char kMenuManagerTypeKey[] = …;
const char kVisibleKey[] = …;
constexpr int kWriteDelayInSeconds = …;
void SetIdKeyValue(base::Value::Dict& properties,
const char* key,
const MenuItem::Id& id) { … }
MenuItem::OwnedList MenuItemsFromValue(
const std::string& extension_id,
const std::optional<base::Value>& value) { … }
bool GetStringList(const base::Value::Dict& dict,
const std::string& key,
std::vector<std::string>* out) { … }
}
MenuItem::MenuItem(const Id& id,
const std::string& title,
bool checked,
bool visible,
bool enabled,
Type type,
const ContextList& contexts)
: … { … }
MenuItem::~MenuItem() { … }
std::unique_ptr<MenuItem> MenuItem::ReleaseChild(const Id& child_id,
bool recursive) { … }
void MenuItem::GetFlattenedSubtree(MenuItem::List* list) { … }
std::set<MenuItem::Id> MenuItem::RemoveAllDescendants() { … }
std::u16string MenuItem::TitleWithReplacement(const std::u16string& selection,
size_t max_length) const { … }
bool MenuItem::SetChecked(bool checked) { … }
void MenuItem::AddChild(std::unique_ptr<MenuItem> item) { … }
base::Value::Dict MenuItem::ToValue() const { … }
std::unique_ptr<MenuItem> MenuItem::Populate(const std::string& extension_id,
const base::Value::Dict& value,
std::string* error) { … }
bool MenuItem::PopulateURLPatterns(
const std::vector<std::string>* document_url_patterns,
const std::vector<std::string>* target_url_patterns,
std::string* error) { … }
const char MenuManager::kOnContextMenus[] = …;
const char MenuManager::kOnWebviewContextMenus[] = …;
MenuManager::MenuManager(content::BrowserContext* context, StateStore* store)
: … { … }
MenuManager::~MenuManager() = default;
MenuManager* MenuManager::Get(content::BrowserContext* context) { … }
std::set<MenuItem::ExtensionKey> MenuManager::ExtensionIds() { … }
const MenuItem::OwnedList* MenuManager::MenuItems(
const MenuItem::ExtensionKey& key) const { … }
bool MenuManager::AddContextItem(const Extension* extension,
std::unique_ptr<MenuItem> item) { … }
bool MenuManager::AddChildItem(const MenuItem::Id& parent_id,
std::unique_ptr<MenuItem> child) { … }
bool MenuManager::DescendantOf(MenuItem* item,
const MenuItem::Id& ancestor_id) { … }
bool MenuManager::ChangeParent(const MenuItem::Id& child_id,
const MenuItem::Id* parent_id) { … }
bool MenuManager::RemoveContextMenuItem(const MenuItem::Id& id) { … }
void MenuManager::RemoveAllContextItems(
const MenuItem::ExtensionKey& extension_key) { … }
MenuItem* MenuManager::GetItemById(const MenuItem::Id& id) const { … }
void MenuManager::RadioItemSelected(MenuItem* item) { … }
static void AddURLProperty(base::Value::Dict& dictionary,
const std::string& key,
const GURL& url) { … }
void MenuManager::ExecuteCommand(content::BrowserContext* context,
WebContents* web_contents,
content::RenderFrameHost* render_frame_host,
const content::ContextMenuParams& params,
const MenuItem::Id& menu_item_id) { … }
void MenuManager::SanitizeRadioListsInMenu(
const MenuItem::OwnedList& item_list) { … }
bool MenuManager::ItemUpdated(const MenuItem::Id& id) { … }
void MenuManager::WriteToStorage(const Extension* extension,
const MenuItem::ExtensionKey& extension_key) { … }
void MenuManager::WriteToStorageInternal(
const MenuItem::ExtensionKey& extension_key) { … }
void MenuManager::ReadFromStorage(const std::string& extension_id,
std::optional<base::Value> value) { … }
void MenuManager::OnExtensionLoaded(content::BrowserContext* browser_context,
const Extension* extension) { … }
void MenuManager::OnExtensionUnloaded(content::BrowserContext* browser_context,
const Extension* extension,
UnloadedExtensionReason reason) { … }
void MenuManager::OnOffTheRecordProfileCreated(Profile* off_the_record) { … }
void MenuManager::OnProfileWillBeDestroyed(Profile* profile) { … }
gfx::Image MenuManager::GetIconForExtensionKey(
const MenuItem::ExtensionKey& extension_key) { … }
void MenuManager::RemoveAllIncognitoContextItems() { … }
void MenuManager::AddObserver(TestObserver* observer) { … }
void MenuManager::SetMenuIconLoader(
MenuItem::ExtensionKey extension_key,
std::unique_ptr<MenuIconLoader> menu_icon_loader) { … }
MenuIconLoader* MenuManager::GetMenuIconLoader(
MenuItem::ExtensionKey extension_key) { … }
void MenuManager::RemoveObserver(TestObserver* observer) { … }
MenuItem::ExtensionKey::ExtensionKey()
: … { … }
MenuItem::ExtensionKey::ExtensionKey(const std::string& extension_id)
: … { … }
MenuItem::ExtensionKey::ExtensionKey(const std::string& extension_id,
int webview_embedder_process_id,
int webview_embedder_frame_id,
int webview_instance_id)
: … { … }
bool MenuItem::ExtensionKey::operator==(const ExtensionKey& other) const { … }
bool MenuItem::ExtensionKey::operator<(const ExtensionKey& other) const { … }
bool MenuItem::ExtensionKey::operator!=(const ExtensionKey& other) const { … }
bool MenuItem::ExtensionKey::empty() const { … }
MenuItem::Id::Id() : … { … }
MenuItem::Id::Id(bool incognito, const MenuItem::ExtensionKey& extension_key)
: … { … }
MenuItem::Id::~Id() { … }
bool MenuItem::Id::operator==(const Id& other) const { … }
bool MenuItem::Id::operator!=(const Id& other) const { … }
bool MenuItem::Id::operator<(const Id& other) const { … }
}