2021-04-09 01:15:51 +02:00
|
|
|
diff --git chrome/browser/renderer_context_menu/render_view_context_menu.cc chrome/browser/renderer_context_menu/render_view_context_menu.cc
|
2024-02-22 19:36:15 +01:00
|
|
|
index 25f2e8f6c4f09..25c21e4552f8a 100644
|
2021-04-09 01:15:51 +02:00
|
|
|
--- chrome/browser/renderer_context_menu/render_view_context_menu.cc
|
|
|
|
+++ chrome/browser/renderer_context_menu/render_view_context_menu.cc
|
2024-01-26 03:12:43 +01:00
|
|
|
@@ -360,6 +360,13 @@ base::OnceCallback<void(RenderViewContextMenu*)>* GetMenuShownCallback() {
|
2021-04-09 01:15:51 +02:00
|
|
|
return callback.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+RenderViewContextMenu::MenuCreatedCallback* GetMenuCreatedCallback() {
|
|
|
|
+ static base::NoDestructor<RenderViewContextMenu::MenuCreatedCallback>
|
|
|
|
+ callback;
|
|
|
|
+ return callback.get();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
enum class UmaEnumIdLookupType {
|
|
|
|
GeneralEnumId,
|
|
|
|
ContextSpecificEnumId,
|
2024-01-26 03:12:43 +01:00
|
|
|
@@ -616,6 +623,10 @@ int FindUMAEnumValueForCommand(int id, UmaEnumIdLookupType type) {
|
2022-07-21 19:26:10 +02:00
|
|
|
if (ContextMenuMatcher::IsExtensionsCustomCommandId(id))
|
|
|
|
return 1;
|
2021-04-09 01:15:51 +02:00
|
|
|
|
|
|
|
+ // Match the MENU_ID_USER_FIRST to MENU_ID_USER_LAST range from cef_types.h.
|
|
|
|
+ if (id >= 26500 && id <= 28500)
|
|
|
|
+ return 1;
|
|
|
|
+
|
|
|
|
id = CollapseCommandsForUMA(id);
|
|
|
|
const auto& map = GetIdcToUmaMap(type);
|
|
|
|
auto it = map.find(id);
|
2024-02-22 19:36:15 +01:00
|
|
|
@@ -863,6 +874,14 @@ RenderViewContextMenu::RenderViewContextMenu(
|
2023-01-30 18:43:54 +01:00
|
|
|
pdf_ocr_submenu_model_ = std::make_unique<ui::SimpleMenuModel>(this);
|
|
|
|
#endif // BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
|
2023-08-09 23:17:17 +02:00
|
|
|
|
2021-04-09 01:15:51 +02:00
|
|
|
+ auto* cb = GetMenuCreatedCallback();
|
|
|
|
+ if (!cb->is_null()) {
|
|
|
|
+ first_observer_ = cb->Run(this);
|
|
|
|
+ if (first_observer_) {
|
|
|
|
+ observers_.AddObserver(first_observer_.get());
|
|
|
|
+ }
|
|
|
|
+ }
|
2023-08-09 23:17:17 +02:00
|
|
|
+
|
|
|
|
observers_.AddObserver(&autofill_context_menu_manager_);
|
2021-04-09 01:15:51 +02:00
|
|
|
}
|
|
|
|
|
2024-02-22 19:36:15 +01:00
|
|
|
@@ -1337,6 +1356,12 @@ void RenderViewContextMenu::InitMenu() {
|
2023-06-26 12:13:38 +02:00
|
|
|
autofill::PopupHidingReason::kContextMenuOpened);
|
|
|
|
}
|
|
|
|
}
|
2021-04-09 01:15:51 +02:00
|
|
|
+
|
|
|
|
+ if (first_observer_) {
|
|
|
|
+ // Do this last so that the observer can optionally modify previously
|
|
|
|
+ // created items.
|
|
|
|
+ first_observer_->InitMenu(params_);
|
|
|
|
+ }
|
|
|
|
}
|
|
|
|
|
|
|
|
Profile* RenderViewContextMenu::GetProfile() const {
|
2024-02-22 19:36:15 +01:00
|
|
|
@@ -3556,6 +3581,12 @@ void RenderViewContextMenu::RegisterExecutePluginActionCallbackForTesting(
|
2021-11-10 22:57:31 +01:00
|
|
|
execute_plugin_action_callback_ = std::move(cb);
|
2021-04-09 01:15:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
+// static
|
|
|
|
+void RenderViewContextMenu::RegisterMenuCreatedCallback(
|
|
|
|
+ MenuCreatedCallback cb) {
|
|
|
|
+ *GetMenuCreatedCallback() = cb;
|
|
|
|
+}
|
|
|
|
+
|
2021-12-16 23:35:54 +01:00
|
|
|
custom_handlers::ProtocolHandlerRegistry::ProtocolHandlerList
|
2021-04-09 01:15:51 +02:00
|
|
|
RenderViewContextMenu::GetHandlersForLinkUrl() {
|
2021-12-16 23:35:54 +01:00
|
|
|
custom_handlers::ProtocolHandlerRegistry::ProtocolHandlerList handlers =
|
2021-04-09 01:15:51 +02:00
|
|
|
diff --git chrome/browser/renderer_context_menu/render_view_context_menu.h chrome/browser/renderer_context_menu/render_view_context_menu.h
|
2024-02-22 19:36:15 +01:00
|
|
|
index e4041eee0e29e..7d5e3aa1d8cfb 100644
|
2021-04-09 01:15:51 +02:00
|
|
|
--- chrome/browser/renderer_context_menu/render_view_context_menu.h
|
|
|
|
+++ chrome/browser/renderer_context_menu/render_view_context_menu.h
|
2024-01-26 03:12:43 +01:00
|
|
|
@@ -159,6 +159,12 @@ class RenderViewContextMenu
|
2022-10-17 19:27:40 +02:00
|
|
|
}
|
|
|
|
#endif
|
2021-04-09 01:15:51 +02:00
|
|
|
|
|
|
|
+ // Registers a callback that will be called each time a context menu is
|
|
|
|
+ // created.
|
|
|
|
+ using MenuCreatedCallback = base::RepeatingCallback<
|
|
|
|
+ std::unique_ptr<RenderViewContextMenuObserver>(RenderViewContextMenu*)>;
|
|
|
|
+ static void RegisterMenuCreatedCallback(MenuCreatedCallback cb);
|
|
|
|
+
|
|
|
|
protected:
|
|
|
|
Profile* GetProfile() const;
|
|
|
|
|
2024-01-26 03:12:43 +01:00
|
|
|
@@ -471,6 +477,9 @@ class RenderViewContextMenu
|
2021-07-23 18:40:13 +02:00
|
|
|
// built.
|
|
|
|
bool is_protocol_submenu_valid_ = false;
|
2021-04-09 01:15:51 +02:00
|
|
|
|
|
|
|
+ // An observer returned via MenuCreatedCallback that will be called first.
|
|
|
|
+ std::unique_ptr<RenderViewContextMenuObserver> first_observer_;
|
|
|
|
+
|
|
|
|
// An observer that handles spelling suggestions, "Add to dictionary", and
|
|
|
|
// "Use enhanced spell check" items.
|
|
|
|
std::unique_ptr<SpellingMenuObserver> spelling_suggestions_menu_observer_;
|
|
|
|
diff --git chrome/browser/ui/views/renderer_context_menu/render_view_context_menu_views.cc chrome/browser/ui/views/renderer_context_menu/render_view_context_menu_views.cc
|
2024-01-26 03:12:43 +01:00
|
|
|
index c88a77a0b49e2..785ded198741e 100644
|
2021-04-09 01:15:51 +02:00
|
|
|
--- chrome/browser/ui/views/renderer_context_menu/render_view_context_menu_views.cc
|
|
|
|
+++ chrome/browser/ui/views/renderer_context_menu/render_view_context_menu_views.cc
|
2023-01-30 18:43:54 +01:00
|
|
|
@@ -149,6 +149,9 @@ void RenderViewContextMenuViews::RunMenuAt(views::Widget* parent,
|
2021-04-09 01:15:51 +02:00
|
|
|
bool RenderViewContextMenuViews::GetAcceleratorForCommandId(
|
|
|
|
int command_id,
|
|
|
|
ui::Accelerator* accel) const {
|
|
|
|
+ if (RenderViewContextMenu::GetAcceleratorForCommandId(command_id, accel))
|
|
|
|
+ return true;
|
|
|
|
+
|
|
|
|
// There are no formally defined accelerators we can query so we assume
|
|
|
|
// that Ctrl+C, Ctrl+V, Ctrl+X, Ctrl-A, etc do what they normally do.
|
|
|
|
switch (command_id) {
|
|
|
|
diff --git components/renderer_context_menu/render_view_context_menu_base.cc components/renderer_context_menu/render_view_context_menu_base.cc
|
2024-02-22 19:36:15 +01:00
|
|
|
index c49b49d76d7cc..842a6fae5d8e4 100644
|
2021-04-09 01:15:51 +02:00
|
|
|
--- components/renderer_context_menu/render_view_context_menu_base.cc
|
|
|
|
+++ components/renderer_context_menu/render_view_context_menu_base.cc
|
2024-01-26 03:12:43 +01:00
|
|
|
@@ -374,6 +374,17 @@ bool RenderViewContextMenuBase::IsCommandIdChecked(int id) const {
|
2021-04-09 01:15:51 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
+bool RenderViewContextMenuBase::GetAcceleratorForCommandId(
|
|
|
|
+ int id,
|
|
|
|
+ ui::Accelerator* accelerator) const {
|
|
|
|
+ for (auto& observer : observers_) {
|
|
|
|
+ if (observer.IsCommandIdSupported(id))
|
|
|
|
+ return observer.GetAccelerator(id, accelerator);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return false;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
void RenderViewContextMenuBase::ExecuteCommand(int id, int event_flags) {
|
|
|
|
command_executed_ = true;
|
|
|
|
RecordUsedItem(id);
|
|
|
|
diff --git components/renderer_context_menu/render_view_context_menu_base.h components/renderer_context_menu/render_view_context_menu_base.h
|
2024-02-22 19:36:15 +01:00
|
|
|
index 33de73c75ef8c..c0ef8b7f8ba07 100644
|
2021-04-09 01:15:51 +02:00
|
|
|
--- components/renderer_context_menu/render_view_context_menu_base.h
|
|
|
|
+++ components/renderer_context_menu/render_view_context_menu_base.h
|
2023-02-27 19:52:38 +01:00
|
|
|
@@ -87,6 +87,9 @@ class RenderViewContextMenuBase : public ui::SimpleMenuModel::Delegate,
|
2021-04-09 01:15:51 +02:00
|
|
|
|
|
|
|
const ui::SimpleMenuModel& menu_model() const { return menu_model_; }
|
|
|
|
const content::ContextMenuParams& params() const { return params_; }
|
|
|
|
+ content::WebContents* source_web_contents() const {
|
|
|
|
+ return source_web_contents_;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// Returns true if the specified command id is known and valid for
|
|
|
|
// this menu. If the command is known |enabled| is set to indicate
|
2023-02-27 19:52:38 +01:00
|
|
|
@@ -95,6 +98,9 @@ class RenderViewContextMenuBase : public ui::SimpleMenuModel::Delegate,
|
2021-04-09 01:15:51 +02:00
|
|
|
|
|
|
|
// SimpleMenuModel::Delegate implementation.
|
|
|
|
bool IsCommandIdChecked(int command_id) const override;
|
|
|
|
+ bool GetAcceleratorForCommandId(
|
|
|
|
+ int command_id,
|
|
|
|
+ ui::Accelerator* accelerator) const override;
|
|
|
|
void ExecuteCommand(int command_id, int event_flags) override;
|
|
|
|
void OnMenuWillShow(ui::SimpleMenuModel* source) override;
|
|
|
|
void MenuClosed(ui::SimpleMenuModel* source) override;
|
|
|
|
diff --git components/renderer_context_menu/render_view_context_menu_observer.cc components/renderer_context_menu/render_view_context_menu_observer.cc
|
2022-09-26 21:30:45 +02:00
|
|
|
index 9fdda1636003d..538bd05a41296 100644
|
2021-04-09 01:15:51 +02:00
|
|
|
--- components/renderer_context_menu/render_view_context_menu_observer.cc
|
|
|
|
+++ components/renderer_context_menu/render_view_context_menu_observer.cc
|
|
|
|
@@ -15,3 +15,8 @@ bool RenderViewContextMenuObserver::IsCommandIdChecked(int command_id) {
|
|
|
|
bool RenderViewContextMenuObserver::IsCommandIdEnabled(int command_id) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+bool RenderViewContextMenuObserver::GetAccelerator(int command_id,
|
|
|
|
+ ui::Accelerator* accel) {
|
|
|
|
+ return false;
|
|
|
|
+}
|
|
|
|
diff --git components/renderer_context_menu/render_view_context_menu_observer.h components/renderer_context_menu/render_view_context_menu_observer.h
|
2022-09-26 21:30:45 +02:00
|
|
|
index 0527c57abd51c..70bebcbb50461 100644
|
2021-04-09 01:15:51 +02:00
|
|
|
--- components/renderer_context_menu/render_view_context_menu_observer.h
|
|
|
|
+++ components/renderer_context_menu/render_view_context_menu_observer.h
|
|
|
|
@@ -11,6 +11,10 @@ namespace content {
|
|
|
|
struct ContextMenuParams;
|
|
|
|
}
|
|
|
|
|
|
|
|
+namespace ui {
|
|
|
|
+class Accelerator;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
// The interface used for implementing context-menu items. The following
|
|
|
|
// instruction describe how to implement a context-menu item with this
|
|
|
|
// interface.
|
|
|
|
@@ -100,6 +104,8 @@ class RenderViewContextMenuObserver {
|
|
|
|
virtual bool IsCommandIdChecked(int command_id);
|
|
|
|
virtual bool IsCommandIdEnabled(int command_id);
|
|
|
|
|
|
|
|
+ virtual bool GetAccelerator(int command_id, ui::Accelerator* accel);
|
|
|
|
+
|
|
|
|
// Called when a user selects the specified context-menu item. This is
|
|
|
|
// only called when the observer returns true for IsCommandIdSupported()
|
|
|
|
// for that |command_id|.
|