]> git.sesse.net Git - nageru/commitdiff
Implement HTMLInput::execute_javascript_async().
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 25 Feb 2018 15:26:58 +0000 (16:26 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 26 Feb 2018 17:06:16 +0000 (18:06 +0100)
cef_capture.cpp
cef_capture.h
theme.cpp

index 9c4f68c8f6d875ea40a1e03b3d7b015b392efea0..1836eb88f9cf474b9cc5c4287b3b7c011f39ac4c 100644 (file)
@@ -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("<theme eval>");
+               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();
index be5402fda9deb31c0a94cfe756b056250c999fe4..11cdc33f76450daace314004c5c63a8e42c81992 100644 (file)
@@ -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);
 
index 71970c90f3ac4e849f3c0252172cb558f65544bc..091495f9cae0e78836a7b6c7f3f42480ffbadb0d 100644 (file)
--- 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 }
 };