mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
chrome: Add ability to handle chrome menu/keyboard commands (fixes issue #3280)
This change adds a CefCommandHandler::OnChromeCommand callback for optionally handling Chrome commands triggered via menus or keyboard shortcuts. Supported command IDs are listed in a new cef_command_ids.h header file. To test: Run `cefclient --enable-chrome-runtime --hide-controls`. Most commands will blocked and removed from context menus.
This commit is contained in:
@ -28,6 +28,7 @@ class ClientDownloadImageCallback;
|
||||
// Client handler abstract base class. Provides common functionality shared by
|
||||
// all concrete client handler implementations.
|
||||
class ClientHandler : public CefClient,
|
||||
public CefCommandHandler,
|
||||
public CefContextMenuHandler,
|
||||
public CefDisplayHandler,
|
||||
public CefDownloadHandler,
|
||||
@ -93,6 +94,7 @@ class ClientHandler : public CefClient,
|
||||
// |delegate| must outlive this object or DetachDelegate() must be called.
|
||||
ClientHandler(Delegate* delegate,
|
||||
bool is_osr,
|
||||
bool with_controls,
|
||||
const std::string& startup_url);
|
||||
|
||||
// This object may outlive the Delegate object so it's necessary for the
|
||||
@ -100,6 +102,7 @@ class ClientHandler : public CefClient,
|
||||
void DetachDelegate();
|
||||
|
||||
// CefClient methods
|
||||
CefRefPtr<CefCommandHandler> GetCommandHandler() override { return this; }
|
||||
CefRefPtr<CefContextMenuHandler> GetContextMenuHandler() override {
|
||||
return this;
|
||||
}
|
||||
@ -128,6 +131,11 @@ class ClientHandler : public CefClient,
|
||||
}
|
||||
#endif
|
||||
|
||||
// CefCommandHandler methods
|
||||
bool OnChromeCommand(CefRefPtr<CefBrowser> browser,
|
||||
int command_id,
|
||||
cef_window_open_disposition_t disposition) override;
|
||||
|
||||
// CefContextMenuHandler methods
|
||||
void OnBeforeContextMenu(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
@ -312,9 +320,6 @@ class ClientHandler : public CefClient,
|
||||
// Returns the startup URL.
|
||||
std::string startup_url() const { return startup_url_; }
|
||||
|
||||
// Returns true if this handler uses off-screen rendering.
|
||||
bool is_osr() const { return is_osr_; }
|
||||
|
||||
// Set/get whether the client should download favicon images. Only safe to
|
||||
// call immediately after client creation or on the browser process UI thread.
|
||||
bool download_favicon_images() const { return download_favicon_images_; }
|
||||
@ -355,12 +360,19 @@ class ClientHandler : public CefClient,
|
||||
|
||||
void SetOfflineState(CefRefPtr<CefBrowser> browser, bool offline);
|
||||
|
||||
// Filter menu and keyboard shortcut commands.
|
||||
void FilterMenuModel(CefRefPtr<CefMenuModel> model);
|
||||
bool IsAllowedCommandId(int command_id);
|
||||
|
||||
// THREAD SAFE MEMBERS
|
||||
// The following members may be accessed from any thread.
|
||||
|
||||
// True if this handler uses off-screen rendering.
|
||||
const bool is_osr_;
|
||||
|
||||
// True if this handler shows controls.
|
||||
const bool with_controls_;
|
||||
|
||||
// The startup URL.
|
||||
const std::string startup_url_;
|
||||
|
||||
|
Reference in New Issue
Block a user