#include "libcef_dll/cpptoc/v8context_cpptoc.h"
#include "libcef_dll/cpptoc/browser_cpptoc.h"
#include "libcef_dll/cpptoc/frame_cpptoc.h"
#include "libcef_dll/cpptoc/task_runner_cpptoc.h"
#include "libcef_dll/cpptoc/v8exception_cpptoc.h"
#include "libcef_dll/cpptoc/v8value_cpptoc.h"
CEF_EXPORT cef_v8context_t* cef_v8context_get_current_context() {
CefRefPtr<CefV8Context> _retval = CefV8Context::GetCurrentContext();
return CefV8ContextCppToC::Wrap(_retval);
}
CEF_EXPORT cef_v8context_t* cef_v8context_get_entered_context() {
CefRefPtr<CefV8Context> _retval = CefV8Context::GetEnteredContext();
return CefV8ContextCppToC::Wrap(_retval);
}
CEF_EXPORT int cef_v8context_in_context() {
bool _retval = CefV8Context::InContext();
return _retval;
}
namespace {
cef_task_runner_t* CEF_CALLBACK
v8context_get_task_runner(struct _cef_v8context_t* self) {
DCHECK(self);
if (!self)
return NULL;
CefRefPtr<CefTaskRunner> _retval =
CefV8ContextCppToC::Get(self)->GetTaskRunner();
return CefTaskRunnerCppToC::Wrap(_retval);
}
int CEF_CALLBACK v8context_is_valid(struct _cef_v8context_t* self) {
DCHECK(self);
if (!self)
return 0;
bool _retval = CefV8ContextCppToC::Get(self)->IsValid();
return _retval;
}
cef_browser_t* CEF_CALLBACK
v8context_get_browser(struct _cef_v8context_t* self) {
DCHECK(self);
if (!self)
return NULL;
CefRefPtr<CefBrowser> _retval = CefV8ContextCppToC::Get(self)->GetBrowser();
return CefBrowserCppToC::Wrap(_retval);
}
cef_frame_t* CEF_CALLBACK v8context_get_frame(struct _cef_v8context_t* self) {
DCHECK(self);
if (!self)
return NULL;
CefRefPtr<CefFrame> _retval = CefV8ContextCppToC::Get(self)->GetFrame();
return CefFrameCppToC::Wrap(_retval);
}
struct _cef_v8value_t* CEF_CALLBACK
v8context_get_global(struct _cef_v8context_t* self) {
DCHECK(self);
if (!self)
return NULL;
CefRefPtr<CefV8Value> _retval = CefV8ContextCppToC::Get(self)->GetGlobal();
return CefV8ValueCppToC::Wrap(_retval);
}
int CEF_CALLBACK v8context_enter(struct _cef_v8context_t* self) {
DCHECK(self);
if (!self)
return 0;
bool _retval = CefV8ContextCppToC::Get(self)->Enter();
return _retval;
}
int CEF_CALLBACK v8context_exit(struct _cef_v8context_t* self) {
DCHECK(self);
if (!self)
return 0;
bool _retval = CefV8ContextCppToC::Get(self)->Exit();
return _retval;
}
int CEF_CALLBACK v8context_is_same(struct _cef_v8context_t* self,
struct _cef_v8context_t* that) {
DCHECK(self);
if (!self)
return 0;
DCHECK(that);
if (!that)
return 0;
bool _retval =
CefV8ContextCppToC::Get(self)->IsSame(CefV8ContextCppToC::Unwrap(that));
return _retval;
}
int CEF_CALLBACK v8context_eval(struct _cef_v8context_t* self,
const cef_string_t* code,
const cef_string_t* script_url,
int start_line,
struct _cef_v8value_t** retval,
struct _cef_v8exception_t** exception) {
DCHECK(self);
if (!self)
return 0;
DCHECK(code);
if (!code)
return 0;
DCHECK(retval);
if (!retval)
return 0;
DCHECK(exception);
if (!exception)
return 0;
CefRefPtr<CefV8Value> retvalPtr;
if (retval && *retval)
retvalPtr = CefV8ValueCppToC::Unwrap(*retval);
CefV8Value* retvalOrig = retvalPtr.get();
CefRefPtr<CefV8Exception> exceptionPtr;
if (exception && *exception)
exceptionPtr = CefV8ExceptionCppToC::Unwrap(*exception);
CefV8Exception* exceptionOrig = exceptionPtr.get();
bool _retval = CefV8ContextCppToC::Get(self)->Eval(
CefString(code), CefString(script_url), start_line, retvalPtr,
exceptionPtr);
if (retval) {
if (retvalPtr.get()) {
if (retvalPtr.get() != retvalOrig) {
*retval = CefV8ValueCppToC::Wrap(retvalPtr);
}
} else {
*retval = nullptr;
}
}
if (exception) {
if (exceptionPtr.get()) {
if (exceptionPtr.get() != exceptionOrig) {
*exception = CefV8ExceptionCppToC::Wrap(exceptionPtr);
}
} else {
*exception = nullptr;
}
}
return _retval;
}
}
CefV8ContextCppToC::CefV8ContextCppToC() {
GetStruct()->get_task_runner = v8context_get_task_runner;
GetStruct()->is_valid = v8context_is_valid;
GetStruct()->get_browser = v8context_get_browser;
GetStruct()->get_frame = v8context_get_frame;
GetStruct()->get_global = v8context_get_global;
GetStruct()->enter = v8context_enter;
GetStruct()->exit = v8context_exit;
GetStruct()->is_same = v8context_is_same;
GetStruct()->eval = v8context_eval;
}
CefV8ContextCppToC::~CefV8ContextCppToC() {}
template <>
CefRefPtr<CefV8Context>
CefCppToCRefCounted<CefV8ContextCppToC, CefV8Context, cef_v8context_t>::
UnwrapDerived(CefWrapperType type, cef_v8context_t* s) {
NOTREACHED() << "Unexpected class type: " << type;
return nullptr;
}
template <>
CefWrapperType CefCppToCRefCounted<CefV8ContextCppToC,
CefV8Context,
cef_v8context_t>::kWrapperType =
WT_V8CONTEXT;