From f7fba578a1f5e2ef2b0ede1ac058b3fdb95ab4b1 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 25 Feb 2018 16:26:58 +0100 Subject: [PATCH] Implement HTMLInput::execute_javascript_async(). --- cef_capture.cpp | 9 +++++++++ cef_capture.h | 1 + theme.cpp | 11 ++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/cef_capture.cpp b/cef_capture.cpp index 9c4f68c..1836eb8 100644 --- a/cef_capture.cpp +++ b/cef_capture.cpp @@ -71,6 +71,15 @@ void CEFCapture::set_max_fps(int max_fps) }); } +void CEFCapture::execute_javascript_async(const string &js) +{ + post_to_cef_ui_thread([this, js] { + CefString script_url(""); + int start_line = 1; + browser->GetMainFrame()->ExecuteJavaScript(js, script_url, start_line); + }); +} + void CEFCapture::OnPaint(const void *buffer, int width, int height) { steady_clock::time_point timestamp = steady_clock::now(); diff --git a/cef_capture.h b/cef_capture.h index be5402f..11cdc33 100644 --- a/cef_capture.h +++ b/cef_capture.h @@ -72,6 +72,7 @@ public: void set_url(const std::string &url); void reload(); void set_max_fps(int max_fps); + void execute_javascript_async(const std::string &js); void OnPaint(const void *buffer, int width, int height); diff --git a/theme.cpp b/theme.cpp index 71970c9..091495f 100644 --- a/theme.cpp +++ b/theme.cpp @@ -448,6 +448,15 @@ int HTMLInput_set_max_fps(lua_State* L) return 0; } +int HTMLInput_execute_javascript_async(lua_State* L) +{ + assert(lua_gettop(L) == 2); + CEFCapture **video_input = (CEFCapture **)luaL_checkudata(L, 1, "HTMLInput"); + string js = checkstdstring(L, 2); + (*video_input)->execute_javascript_async(js); + return 0; +} + int HTMLInput_get_signal_num(lua_State* L) { assert(lua_gettop(L) == 1); @@ -665,11 +674,11 @@ const luaL_Reg VideoInput_funcs[] = { }; const luaL_Reg HTMLInput_funcs[] = { - // TODO: execute_javascript { "new", HTMLInput_new }, { "set_url", HTMLInput_set_url }, { "reload", HTMLInput_reload }, { "set_max_fps", HTMLInput_set_max_fps }, + { "execute_javascript_async", HTMLInput_execute_javascript_async }, { "get_signal_num", HTMLInput_get_signal_num }, { NULL, NULL } }; -- 2.39.2