From ba8887f5860818db4a49f3bb48df5a3351032695 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 27 Apr 2023 12:54:51 +0200 Subject: [PATCH] feat: emit `context-menu` event from extensions (#38029) feat: emit context-menu event from extensions --- shell/browser/api/electron_api_web_contents.h | 5 +++-- .../extensions/electron_extensions_api_client.cc | 13 +++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/shell/browser/api/electron_api_web_contents.h b/shell/browser/api/electron_api_web_contents.h index b6e2bcb0414c..3c7e0ec1b62a 100644 --- a/shell/browser/api/electron_api_web_contents.h +++ b/shell/browser/api/electron_api_web_contents.h @@ -326,6 +326,9 @@ class WebContents : public ExclusiveAccessContext, const base::FilePath& file_path); v8::Local GetProcessMemoryInfo(v8::Isolate* isolate); + bool HandleContextMenu(content::RenderFrameHost& render_frame_host, + const content::ContextMenuParams& params) override; + // Properties. int32_t ID() const { return id_; } v8::Local Session(v8::Isolate* isolate); @@ -551,8 +554,6 @@ class WebContents : public ExclusiveAccessContext, void RendererResponsive( content::WebContents* source, content::RenderWidgetHost* render_widget_host) override; - bool HandleContextMenu(content::RenderFrameHost& render_frame_host, - const content::ContextMenuParams& params) override; void FindReply(content::WebContents* web_contents, int request_id, int number_of_matches, diff --git a/shell/browser/extensions/electron_extensions_api_client.cc b/shell/browser/extensions/electron_extensions_api_client.cc index 1a4c24700b9f..827044836e08 100644 --- a/shell/browser/extensions/electron_extensions_api_client.cc +++ b/shell/browser/extensions/electron_extensions_api_client.cc @@ -65,10 +65,19 @@ class ElectronMimeHandlerViewGuestDelegate // MimeHandlerViewGuestDelegate. bool HandleContextMenu(content::RenderFrameHost& render_frame_host, const content::ContextMenuParams& params) override { - // TODO(nornagon): surface this event to JS - LOG(INFO) << "HCM"; + auto* web_contents = + content::WebContents::FromRenderFrameHost(&render_frame_host); + if (!web_contents) + return true; + + electron::api::WebContents* api_web_contents = + electron::api::WebContents::From( + web_contents->GetOutermostWebContents()); + if (api_web_contents) + api_web_contents->HandleContextMenu(render_frame_host, params); return true; } + void RecordLoadMetric(bool in_main_frame, const std::string& mime_type) override {} };