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:
Marshall Greenblatt
2022-03-22 14:31:30 -04:00
parent 13ca38e4e0
commit 2f5838eaaa
44 changed files with 703 additions and 44 deletions

View File

@@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=f31f5010a3c5c4624b93d994b6fce1e795eeac93$
// $hash=8e158f3ea54211b95f0b716b1eeec2ff475f1245$
//
#include "libcef_dll/ctocpp/client_ctocpp.h"
@@ -17,6 +17,7 @@
#include "libcef_dll/cpptoc/frame_cpptoc.h"
#include "libcef_dll/cpptoc/process_message_cpptoc.h"
#include "libcef_dll/ctocpp/audio_handler_ctocpp.h"
#include "libcef_dll/ctocpp/command_handler_ctocpp.h"
#include "libcef_dll/ctocpp/context_menu_handler_ctocpp.h"
#include "libcef_dll/ctocpp/dialog_handler_ctocpp.h"
#include "libcef_dll/ctocpp/display_handler_ctocpp.h"
@@ -50,6 +51,21 @@ CefRefPtr<CefAudioHandler> CefClientCToCpp::GetAudioHandler() {
return CefAudioHandlerCToCpp::Wrap(_retval);
}
NO_SANITIZE("cfi-icall")
CefRefPtr<CefCommandHandler> CefClientCToCpp::GetCommandHandler() {
cef_client_t* _struct = GetStruct();
if (CEF_MEMBER_MISSING(_struct, get_command_handler))
return nullptr;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Execute
cef_command_handler_t* _retval = _struct->get_command_handler(_struct);
// Return type: refptr_same
return CefCommandHandlerCToCpp::Wrap(_retval);
}
NO_SANITIZE("cfi-icall")
CefRefPtr<CefContextMenuHandler> CefClientCToCpp::GetContextMenuHandler() {
cef_client_t* _struct = GetStruct();

View File

@@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=c4370b0b3a14c9739b5a639eda06c286f6981e10$
// $hash=69f82ee575779deaf1d3581dbedcf8aa75f35710$
//
#ifndef CEF_LIBCEF_DLL_CTOCPP_CLIENT_CTOCPP_H_
@@ -34,6 +34,7 @@ class CefClientCToCpp
// CefClient methods.
CefRefPtr<CefAudioHandler> GetAudioHandler() override;
CefRefPtr<CefCommandHandler> GetCommandHandler() override;
CefRefPtr<CefContextMenuHandler> GetContextMenuHandler() override;
CefRefPtr<CefDialogHandler> GetDialogHandler() override;
CefRefPtr<CefDisplayHandler> GetDisplayHandler() override;

View File

@@ -0,0 +1,71 @@
// Copyright (c) 2022 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool. If making changes by
// hand only do so within the body of existing method and function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=431d97965f00a504f09790fd524ee23f69f16a82$
//
#include "libcef_dll/ctocpp/command_handler_ctocpp.h"
#include "libcef_dll/cpptoc/browser_cpptoc.h"
#include "libcef_dll/shutdown_checker.h"
// VIRTUAL METHODS - Body may be edited by hand.
NO_SANITIZE("cfi-icall")
bool CefCommandHandlerCToCpp::OnChromeCommand(
CefRefPtr<CefBrowser> browser,
int command_id,
cef_window_open_disposition_t disposition) {
shutdown_checker::AssertNotShutdown();
cef_command_handler_t* _struct = GetStruct();
if (CEF_MEMBER_MISSING(_struct, on_chrome_command))
return false;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: browser; type: refptr_diff
DCHECK(browser.get());
if (!browser.get())
return false;
// Execute
int _retval = _struct->on_chrome_command(
_struct, CefBrowserCppToC::Wrap(browser), command_id, disposition);
// Return type: bool
return _retval ? true : false;
}
// CONSTRUCTOR - Do not edit by hand.
CefCommandHandlerCToCpp::CefCommandHandlerCToCpp() {}
// DESTRUCTOR - Do not edit by hand.
CefCommandHandlerCToCpp::~CefCommandHandlerCToCpp() {
shutdown_checker::AssertNotShutdown();
}
template <>
cef_command_handler_t* CefCToCppRefCounted<
CefCommandHandlerCToCpp,
CefCommandHandler,
cef_command_handler_t>::UnwrapDerived(CefWrapperType type,
CefCommandHandler* c) {
NOTREACHED() << "Unexpected class type: " << type;
return nullptr;
}
template <>
CefWrapperType CefCToCppRefCounted<CefCommandHandlerCToCpp,
CefCommandHandler,
cef_command_handler_t>::kWrapperType =
WT_COMMAND_HANDLER;

View File

@@ -0,0 +1,43 @@
// Copyright (c) 2022 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool. If making changes by
// hand only do so within the body of existing method and function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=986b761d9c3bca7980b4144bb0802a9eafff9e0e$
//
#ifndef CEF_LIBCEF_DLL_CTOCPP_COMMAND_HANDLER_CTOCPP_H_
#define CEF_LIBCEF_DLL_CTOCPP_COMMAND_HANDLER_CTOCPP_H_
#pragma once
#if !defined(BUILDING_CEF_SHARED)
#error This file can be included DLL-side only
#endif
#include "include/capi/cef_command_handler_capi.h"
#include "include/cef_command_handler.h"
#include "libcef_dll/ctocpp/ctocpp_ref_counted.h"
// Wrap a C structure with a C++ class.
// This class may be instantiated and accessed DLL-side only.
class CefCommandHandlerCToCpp
: public CefCToCppRefCounted<CefCommandHandlerCToCpp,
CefCommandHandler,
cef_command_handler_t> {
public:
CefCommandHandlerCToCpp();
virtual ~CefCommandHandlerCToCpp();
// CefCommandHandler methods.
bool OnChromeCommand(CefRefPtr<CefBrowser> browser,
int command_id,
cef_window_open_disposition_t disposition) override;
};
#endif // CEF_LIBCEF_DLL_CTOCPP_COMMAND_HANDLER_CTOCPP_H_