feat: OnContextCreated & Execute
This commit is contained in:
parent
2a27c65ece
commit
a96dc337e6
|
|
@ -4,7 +4,7 @@ project(aya-cef-subprocess)
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
||||||
|
|
||||||
# JACKDS DOING BELOW:
|
# JACKDS DOING BELOW: <== You smell like poop
|
||||||
set(CEF_USE_SANDBOX TRUE CACHE BOOL "Force turning off of sandbox")
|
set(CEF_USE_SANDBOX TRUE CACHE BOOL "Force turning off of sandbox")
|
||||||
set(CEF_VERSION 123.0.13+gfc703fb+chromium-123.0.6312.124)
|
set(CEF_VERSION 123.0.13+gfc703fb+chromium-123.0.6312.124)
|
||||||
set(cefName cef_binary_${CEF_VERSION}_windows64)
|
set(cefName cef_binary_${CEF_VERSION}_windows64)
|
||||||
|
|
|
||||||
50
main.cpp
50
main.cpp
|
|
@ -1,6 +1,12 @@
|
||||||
|
// libcef
|
||||||
|
#include "include/cef_frame_handler.h"
|
||||||
|
#include <include/base/cef_bind.h>
|
||||||
|
#include <include/wrapper/cef_closure_task.h>
|
||||||
#include <include/cef_base.h>
|
#include <include/cef_base.h>
|
||||||
#include <include/cef_app.h>
|
#include <include/cef_app.h>
|
||||||
|
#include <include/cef_browser.h>
|
||||||
|
#include <include/cef_client.h>
|
||||||
|
#include <include/cef_render_process_handler.h>
|
||||||
|
|
||||||
class AyaCEFApp : public CefApp {
|
class AyaCEFApp : public CefApp {
|
||||||
|
|
||||||
|
|
@ -11,13 +17,53 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class AyaSubProcess : public AyaCEFApp , public CefRenderProcessHandler {
|
class AyaSubProcess
|
||||||
|
: public AyaCEFApp
|
||||||
|
, public CefRenderProcessHandler
|
||||||
|
, public CefV8Handler
|
||||||
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler() override {
|
virtual CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler() override {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OnContextCreated(CefRefPtr<CefBrowser> browser,
|
||||||
|
CefRefPtr<CefFrame> frame,
|
||||||
|
CefRefPtr<CefV8Context> context) override
|
||||||
|
{
|
||||||
|
CefRefPtr<CefV8Value> global = context->GetGlobal();
|
||||||
|
CefRefPtr<CefV8Value> func = CefV8Value::CreateFunction("sendResultToCpp", this);
|
||||||
|
global->SetValue("sendResultToCpp", func, V8_PROPERTY_ATTRIBUTE_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Execute(const CefString& name,
|
||||||
|
CefRefPtr<CefV8Value> object,
|
||||||
|
const CefV8ValueList& arguments,
|
||||||
|
CefRefPtr<CefV8Value>& retval,
|
||||||
|
CefString& exception) override
|
||||||
|
{
|
||||||
|
// this should start to become a tuple of some kind because this is
|
||||||
|
// shit if we want to let users have more control over js w/ lua
|
||||||
|
|
||||||
|
// but this is good enough as a poc & can be used for replication
|
||||||
|
// across different clients connected to a server
|
||||||
|
if (name == "sendResultToCpp" && arguments.size() == 1 && arguments[0]->IsString()) {
|
||||||
|
CefRefPtr<CefProcessMessage> msg = CefProcessMessage::Create("resultMessage");
|
||||||
|
|
||||||
|
CefRefPtr<CefListValue> args = msg->GetArgumentList();
|
||||||
|
args->SetString(0, arguments[0]->GetStringValue());
|
||||||
|
|
||||||
|
CefRefPtr<CefBrowser> browser = CefV8Context::GetCurrentContext()->GetBrowser();
|
||||||
|
CefRefPtr<CefFrame> frame = browser->GetMainFrame();
|
||||||
|
|
||||||
|
frame->SendProcessMessage(PID_BROWSER, msg);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IMPLEMENT_REFCOUNTING(AyaSubProcess);
|
IMPLEMENT_REFCOUNTING(AyaSubProcess);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue