Skip to content

Commit

Permalink
Update to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhnchris committed Feb 25, 2022
1 parent 9157617 commit 61b2a31
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
16 changes: 13 additions & 3 deletions browser-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ CefRefPtr<CefResourceRequestHandler> BrowserClient::GetResourceRequestHandler(
return nullptr;
}

CefResourceRequestHandler::ReturnValue BrowserClient::OnBeforeResourceLoad(
CefRefPtr<CefBrowser>, CefRefPtr<CefFrame>, CefRefPtr<CefRequest>,
CefRefPtr<CefCallback>)
CefResourceRequestHandler::ReturnValue
BrowserClient::OnBeforeResourceLoad(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame>,
CefRefPtr<CefRequest>,
CefRefPtr<CefCallback>)
{
return RV_CONTINUE;
}
Expand Down Expand Up @@ -679,6 +680,15 @@ void BrowserClient::OnLoadEnd(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame> frame,

frame->ExecuteJavaScript(script, "", 0);
}

if (bs->javascript_active) {
std::string javascript;
javascript = bs->javascript;
if (!bs->javascript.empty())
frame->ExecuteJavaScript(javascript, "", 0);
/*frame->ExecuteJavaScript(javascript, frame->GetURL(),
0);*/
}
}

bool BrowserClient::OnConsoleMessage(CefRefPtr<CefBrowser>,
Expand Down
14 changes: 14 additions & 0 deletions obs-browser-plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ static void browser_source_get_defaults(obs_data_t *settings)
(int)DEFAULT_CONTROL_LEVEL);
obs_data_set_default_string(settings, "css", default_css);
obs_data_set_default_bool(settings, "reroute_audio", false);

obs_data_set_default_string(settings, "javascript", "");
obs_data_set_default_bool(settings, "javascript_active", false);
}

static bool is_local_file_modified(obs_properties_t *props, obs_property_t *,
Expand Down Expand Up @@ -208,6 +211,17 @@ static obs_properties_t *browser_source_get_properties(void *data)
obs_properties_add_bool(props, "restart_when_active",
obs_module_text("RefreshBrowserActive"));

obs_property_t *j = obs_properties_add_text(
props, "javascript", obs_module_text("JavaScript"),
OBS_TEXT_MULTILINE);
obs_property_text_set_monospace(j, true);

prop = obs_properties_add_bool(props, "javascript_active",
obs_module_text("JavaScriptActive"));

obs_property_set_long_description(
j, obs_module_text("JavaScript.ToolTip"));

obs_property_t *controlLevel = obs_properties_add_list(
props, "webpage_control_level",
obs_module_text("WebpageControlLevel"), OBS_COMBO_TYPE_LIST,
Expand Down
12 changes: 11 additions & 1 deletion obs-browser-source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,8 @@ void BrowserSource::Update(obs_data_t *settings)
ControlLevel n_webpage_control_level;
std::string n_url;
std::string n_css;
std::string n_javascript;
bool n_javascript_active;

n_is_local = obs_data_get_bool(settings, "is_local_file");
n_width = (int)obs_data_get_int(settings, "width");
Expand All @@ -518,6 +520,9 @@ void BrowserSource::Update(obs_data_t *settings)
n_webpage_control_level = static_cast<ControlLevel>(
obs_data_get_int(settings, "webpage_control_level"));

n_javascript_active = obs_data_get_bool(settings, "javascript_active");
n_javascript = obs_data_get_string(settings, "javascript");

if (n_is_local && !n_url.empty()) {
n_url = CefURIEncode(n_url, false);

Expand Down Expand Up @@ -563,7 +568,9 @@ void BrowserSource::Update(obs_data_t *settings)
n_fps == fps && n_shutdown == shutdown_on_invisible &&
n_restart == restart && n_css == css && n_url == url &&
n_reroute == reroute_audio &&
n_webpage_control_level == webpage_control_level) {
n_webpage_control_level == webpage_control_level &&
n_javascript_active == javascript_active &&
n_javascript == javascript) {

if (n_width == width && n_height == height)
return;
Expand Down Expand Up @@ -598,6 +605,9 @@ void BrowserSource::Update(obs_data_t *settings)
css = n_css;
url = n_url;

javascript = n_javascript;
javascript_active = n_javascript_active;

obs_source_set_audio_active(source, reroute_audio);
}

Expand Down
2 changes: 2 additions & 0 deletions obs-browser-source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ struct BrowserSource {

std::string url;
std::string css;
std::string javascript;
bool javascript_active = false;
gs_texture_t *texture = nullptr;
gs_texture_t *extra_texture = nullptr;
uint32_t last_cx = 0;
Expand Down

0 comments on commit 61b2a31

Please sign in to comment.