Disable context menu in Chromium Embedded 3 (DCEF3)

I try to disable the right mouse button (context menu) in the Chromium Embedded window (DCEF3), but I do not get it, I did not find any settings to do this initially.

I can, for example, disable "View Source", I use the code below, but I really want to disable the context menu or do not want it to be displayed.

Note. I use this in the "Chromium.dll" libray DLL for use with the "Inno Setup" equal to Inno Web Brower.

procedure TInnoChromium.OnContextMenuCommand(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const params: ICefContextMenuParams; commandId: Integer; eventFlags: TCefEventFlags; out Result: Boolean); begin if (commandId = 132) then Result := True; // MENU_ID_VIEW_SOURCE end; 
+7
chromium-embedded inno-setup
source share
2 answers

To disable the context menu in DCEF 3, you need to handle the OnBeforeContextMenu event and clear its model parameter. That the reference state (underlined by me):

OnBeforeContextMenu

Called before the context menu is displayed. | Titles | provides information on the status of the context menu. | Model | initially contains the default context menu. Model | can be cleared to show the absence of a context menu or modified to display a custom menu. Do not keep links to | params | or | model | outside of this callback.

So, to completely disable the context menu, you will write something like this:

 uses cefvcl, ceflib; type TInnoChromium = class ... private FChromium: TChromium; procedure BeforeContextMenu(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; public constructor Create; end; implementation constructor TInnoChromium.Create; begin FChromium := TChromium.Create(nil); ... FChromium.OnBeforeContextMenu := BeforeContextMenu; end; procedure TInnoChromium.BeforeContextMenu(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const params: ICefContextMenuParams; const model: ICefMenuModel); begin // to disable the context menu clear the model parameter model.Clear; end; 
+16
source share

Note: in C ++ version:

 void ClientHandler::OnBeforeContextMenu( CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefContextMenuParams> params, CefRefPtr<CefMenuModel> model) { CEF_REQUIRE_UI_THREAD(); //Clear disables the context menu model->Clear(); } } 
+2
source share

All Articles