#include "libcef_dll/cpptoc/context_menu_handler_cpptoc.h"
#include "libcef_dll/ctocpp/browser_ctocpp.h"
#include "libcef_dll/ctocpp/context_menu_params_ctocpp.h"
#include "libcef_dll/ctocpp/frame_ctocpp.h"
#include "libcef_dll/ctocpp/menu_model_ctocpp.h"
#include "libcef_dll/ctocpp/run_context_menu_callback_ctocpp.h"
#include "libcef_dll/shutdown_checker.h"
namespace {
void CEF_CALLBACK context_menu_handler_on_before_context_menu(
struct _cef_context_menu_handler_t* self,
cef_browser_t* browser,
struct _cef_frame_t* frame,
struct _cef_context_menu_params_t* params,
struct _cef_menu_model_t* model) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return;
DCHECK(browser);
if (!browser)
return;
DCHECK(frame);
if (!frame)
return;
DCHECK(params);
if (!params)
return;
DCHECK(model);
if (!model)
return;
CefContextMenuHandlerCppToC::Get(self)->OnBeforeContextMenu(
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame),
CefContextMenuParamsCToCpp::Wrap(params),
CefMenuModelCToCpp::Wrap(model));
}
int CEF_CALLBACK context_menu_handler_run_context_menu(
struct _cef_context_menu_handler_t* self,
cef_browser_t* browser,
struct _cef_frame_t* frame,
struct _cef_context_menu_params_t* params,
struct _cef_menu_model_t* model,
cef_run_context_menu_callback_t* callback) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return 0;
DCHECK(browser);
if (!browser)
return 0;
DCHECK(frame);
if (!frame)
return 0;
DCHECK(params);
if (!params)
return 0;
DCHECK(model);
if (!model)
return 0;
DCHECK(callback);
if (!callback)
return 0;
bool _retval = CefContextMenuHandlerCppToC::Get(self)->RunContextMenu(
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame),
CefContextMenuParamsCToCpp::Wrap(params), CefMenuModelCToCpp::Wrap(model),
CefRunContextMenuCallbackCToCpp::Wrap(callback));
return _retval;
}
int CEF_CALLBACK context_menu_handler_on_context_menu_command(
struct _cef_context_menu_handler_t* self,
cef_browser_t* browser,
struct _cef_frame_t* frame,
struct _cef_context_menu_params_t* params,
int command_id,
cef_event_flags_t event_flags) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return 0;
DCHECK(browser);
if (!browser)
return 0;
DCHECK(frame);
if (!frame)
return 0;
DCHECK(params);
if (!params)
return 0;
bool _retval = CefContextMenuHandlerCppToC::Get(self)->OnContextMenuCommand(
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame),
CefContextMenuParamsCToCpp::Wrap(params), command_id, event_flags);
return _retval;
}
void CEF_CALLBACK context_menu_handler_on_context_menu_dismissed(
struct _cef_context_menu_handler_t* self,
cef_browser_t* browser,
struct _cef_frame_t* frame) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return;
DCHECK(browser);
if (!browser)
return;
DCHECK(frame);
if (!frame)
return;
CefContextMenuHandlerCppToC::Get(self)->OnContextMenuDismissed(
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame));
}
}
CefContextMenuHandlerCppToC::CefContextMenuHandlerCppToC() {
GetStruct()->on_before_context_menu =
context_menu_handler_on_before_context_menu;
GetStruct()->run_context_menu = context_menu_handler_run_context_menu;
GetStruct()->on_context_menu_command =
context_menu_handler_on_context_menu_command;
GetStruct()->on_context_menu_dismissed =
context_menu_handler_on_context_menu_dismissed;
}
CefContextMenuHandlerCppToC::~CefContextMenuHandlerCppToC() {
shutdown_checker::AssertNotShutdown();
}
template <>
CefRefPtr<CefContextMenuHandler> CefCppToCRefCounted<
CefContextMenuHandlerCppToC,
CefContextMenuHandler,
cef_context_menu_handler_t>::UnwrapDerived(CefWrapperType type,
cef_context_menu_handler_t* s) {
NOTREACHED() << "Unexpected class type: " << type;
return nullptr;
}
template <>
CefWrapperType CefCppToCRefCounted<CefContextMenuHandlerCppToC,
CefContextMenuHandler,
cef_context_menu_handler_t>::kWrapperType =
WT_CONTEXT_MENU_HANDLER;