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:
@@ -10,6 +10,7 @@
|
||||
|
||||
#include "base/memory/scoped_refptr.h"
|
||||
#include "content/public/browser/web_contents_delegate.h"
|
||||
#include "ui/base/window_open_disposition.h"
|
||||
|
||||
class Browser;
|
||||
|
||||
@@ -47,6 +48,13 @@ class BrowserDelegate : public content::WebContentsDelegate {
|
||||
virtual bool ShowStatusBubble(bool show_by_default) {
|
||||
return show_by_default;
|
||||
}
|
||||
|
||||
// Return true to handle (or disable) a command. ID values come from
|
||||
// chrome/app/chrome_command_ids.h.
|
||||
virtual bool HandleCommand(int command_id,
|
||||
WindowOpenDisposition disposition) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace cef
|
||||
|
@@ -88,6 +88,20 @@ bool ChromeBrowserDelegate::ShowStatusBubble(bool show_by_default) {
|
||||
return *show_status_bubble_;
|
||||
}
|
||||
|
||||
bool ChromeBrowserDelegate::HandleCommand(int command_id,
|
||||
WindowOpenDisposition disposition) {
|
||||
if (auto browser = ChromeBrowserHostImpl::GetBrowserForBrowser(browser_)) {
|
||||
if (auto client = browser->GetClient()) {
|
||||
if (auto handler = client->GetCommandHandler()) {
|
||||
return handler->OnChromeCommand(
|
||||
browser.get(), command_id,
|
||||
static_cast<cef_window_open_disposition_t>(disposition));
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ChromeBrowserDelegate::WebContentsCreated(
|
||||
content::WebContents* source_contents,
|
||||
int opener_render_process_id,
|
||||
|
@@ -52,6 +52,8 @@ class ChromeBrowserDelegate : public cef::BrowserDelegate {
|
||||
void SetAsDelegate(content::WebContents* web_contents,
|
||||
bool set_delegate) override;
|
||||
bool ShowStatusBubble(bool show_by_default) override;
|
||||
bool HandleCommand(int command_id,
|
||||
WindowOpenDisposition disposition) override;
|
||||
|
||||
// WebContentsDelegate methods:
|
||||
void WebContentsCreated(content::WebContents* source_contents,
|
||||
|
Reference in New Issue
Block a user