Skip to content
This repository has been archived by the owner on Jan 15, 2023. It is now read-only.

How to hide the right click menu? #18

Closed
JackHuang1103 opened this issue May 29, 2018 · 5 comments
Closed

How to hide the right click menu? #18

JackHuang1103 opened this issue May 29, 2018 · 5 comments

Comments

@JackHuang1103
Copy link

Hi,

It's not a issue, maybe it's feature reqiure, how to hide the right click menu? is there any option to do that? I don't want user click the right menu the "Show DevTools" and "Close DevTools" to review source code.

Thanks,
Jack

@mattkol
Copy link
Member

mattkol commented May 29, 2018

Chromely is fully configurable. Almost all features can be configured. Please be familiar with Configuration wiki. This is where the features are added or removed.

In this case you want to configure a custom handler. Please see wiki @ How to Add Custom Handlers

So to give you a guide .. in Program.cs file you will need to add the RegisterCustomHandler method to the fluent configuration. You can register as many valid handlers allowed either for CefSharp or CefGlue.

Note that if none is registered it will use the default.

ChromelyConfiguration config = ChromelyConfiguration
                              .Create()
                              .....
                             .RegisterCustomHandler(CefHandlerKey.ContextMenuHandler, typeof(CustomContextMenuHandler));
                              ....

So assuming this is CefGlue app, CustomContextMenuHandler is a custom handler that must inherit from CefContextMenuHandler see the default

So the custom class can be like:

    public class CustomContextMenuHandler : CefContextMenuHandler
    {
        protected override void OnBeforeContextMenu(CefBrowser browser, CefFrame frame, CefContextMenuParams state, CefMenuModel model)
        {
            // To disable the menu then call clear
            model.Clear();

            // Removing existing menu item
            // Remove "View Source" option
            model.Remove((int)CefMenuId.ViewSource);
        }


        protected override bool RunContextMenu(CefBrowser browser, CefFrame frame, CefContextMenuParams parameters, CefMenuModel model, CefRunContextMenuCallback callback)
        {
            return false;
        }

        protected override bool OnContextMenuCommand(CefBrowser browser, CefFrame frame, CefContextMenuParams state, int commandId, CefEventFlags eventFlags)
        {
            return false;
        }

        protected override void OnContextMenuDismissed(CefBrowser browser, CefFrame frame)
        {
        }

        private class DevToolsWebClient : CefClient
        {
        }
	}

This will remove those commands. You can add more commands as you like.

I may have to reconsider making this the default and create a separate handler for debugging purpose. I will look into that.

Please let me know if you have more questions.

@JackHuang1103
Copy link
Author

thanks mattkol,

I used CefSharp and implement handler class like below to hide the menu, it works well, thanks a lot for your help.

One more question, I find CefSharp based on version 63, and CefGlue based on 65, why CefSharp used the lower version and not up to date?

public class CustomContextMenuHandler : IContextMenuHandler
{
void IContextMenuHandler.OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model)
{
// To disable the menu then call clear
model.Clear();

        // Removing existing menu item
        // Remove "View Source" option
        model.Remove(CefMenuCommand.ViewSource);

    }

    bool IContextMenuHandler.OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags)
    {
        return false;
    }

    void IContextMenuHandler.OnContextMenuDismissed(IWebBrowser browserControl, IBrowser browser, IFrame frame)
    {
    }

    bool IContextMenuHandler.RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
    {
        return false;
    }

}

Thanks,
Jack

@mattkol
Copy link
Member

mattkol commented May 30, 2018

Hi Jack,

Good to know the issue is fixed.

On CefSharp/CefGlue version, since Chromely is a consumer of these products, I think it will be more appropriate to release Chromely based on their version final releases.

CefSharp v65 is pre-release, As soon as it is a final release, Chromely will be updated.

CefGlue current release is v66. This will be done soon.

Thanks.

@JackHuang1103
Copy link
Author

Got it, thanks a lot and good job!

@mattkol
Copy link
Member

mattkol commented May 31, 2018

Appreciated! Thanks.

@mattkol mattkol closed this as completed May 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants