Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions browser-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ CefRefPtr<CefAudioHandler> BrowserClient::GetAudioHandler()
return reroute_audio ? this : nullptr;
}

CefRefPtr<CefPermissionHandler> BrowserClient::GetPermissionHandler()
{
return this;
}

CefRefPtr<CefRequestHandler> BrowserClient::GetRequestHandler()
{
return this;
Expand Down Expand Up @@ -653,3 +658,31 @@ bool BrowserClient::OnConsoleMessage(CefRefPtr<CefBrowser>, cef_log_severity_t l
source.ToString().c_str(), line);
return false;
}

bool BrowserClient::OnRequestMediaAccessPermission(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame>,
const CefString &requesting_origin, uint32_t requested_permissions,
CefRefPtr<CefMediaAccessCallback> callback)
{
const uint32_t desktop_bits = CEF_MEDIA_PERMISSION_DESKTOP_AUDIO_CAPTURE |
CEF_MEDIA_PERMISSION_DESKTOP_VIDEO_CAPTURE;

if (requested_permissions & desktop_bits) {
callback->Cancel();
return true;
}

if (!allow_media_access) {
callback->Cancel();
return true;
}

const char *sourceName = "<unknown>";

if (bs && bs->source)
sourceName = obs_source_get_name(bs->source);

blog(LOG_INFO, "[obs-browser: '%s'] Granting media access to '%s'", sourceName,
requesting_origin.ToString().c_str());
callback->Continue(requested_permissions);
return true;
}
12 changes: 10 additions & 2 deletions browser-client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ class BrowserClient : public CefClient,
public CefContextMenuHandler,
public CefRenderHandler,
public CefAudioHandler,
public CefLoadHandler {
public CefLoadHandler,
public CefPermissionHandler {

bool sharing_available = false;
bool reroute_audio = true;
ControlLevel webpage_control_level = DEFAULT_CONTROL_LEVEL;
bool allow_media_access = false;

inline bool valid() const;

Expand All @@ -54,10 +56,11 @@ class BrowserClient : public CefClient,
int frames_per_buffer;

inline BrowserClient(BrowserSource *bs_, bool sharing_avail, bool reroute_audio_,
ControlLevel webpage_control_level_)
ControlLevel webpage_control_level_, bool allow_media_access_)
: sharing_available(sharing_avail),
reroute_audio(reroute_audio_),
webpage_control_level(webpage_control_level_),
allow_media_access(allow_media_access_),
bs(bs_)
{
}
Expand All @@ -70,6 +73,7 @@ class BrowserClient : public CefClient,
virtual CefRefPtr<CefRequestHandler> GetRequestHandler() override;
virtual CefRefPtr<CefContextMenuHandler> GetContextMenuHandler() override;
virtual CefRefPtr<CefAudioHandler> GetAudioHandler() override;
virtual CefRefPtr<CefPermissionHandler> GetPermissionHandler() override;

virtual bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
CefProcessId source_process,
Expand Down Expand Up @@ -146,5 +150,9 @@ class BrowserClient : public CefClient,
/* CefLoadHandler */
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, int httpStatusCode) override;

virtual bool OnRequestMediaAccessPermission(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
const CefString &requesting_origin, uint32_t requested_permissions,
CefRefPtr<CefMediaAccessCallback> callback) override;

IMPLEMENT_REFCOUNTING(BrowserClient);
};
3 changes: 3 additions & 0 deletions data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ WebpageControlLevel.Level.Basic="Basic access to OBS (Save replay buffer, etc.)"
WebpageControlLevel.Level.Advanced="Advanced access to OBS (Change scenes, Start/Stop replay buffer, etc.)"
WebpageControlLevel.Level.All="Full access to OBS (Start/Stop streaming without warning, etc.)"

AllowMediaAccess="Allow access to camera and microphone"
AllowMediaAccess.ToolTip="Allows this page to use your camera and microphone without asking.\n\nOnly enable this for pages you trust. While enabled, the page can capture video and audio at any time the source exists, with no further confirmation.\n\nScreen capture is never granted by this setting."

Dialog.Alert="JavaScript Alert"
Dialog.Confirm="JavaScript Confirm"
Dialog.Prompt="JavaScript Prompt"
Expand Down
5 changes: 5 additions & 0 deletions obs-browser-plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ static void browser_source_get_defaults(obs_data_t *settings)
obs_data_set_default_int(settings, "webpage_control_level", (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_bool(settings, "allow_media_access", false);
}

static bool is_local_file_modified(obs_properties_t *props, obs_property_t *, obs_data_t *settings)
Expand Down Expand Up @@ -186,6 +187,10 @@ static obs_properties_t *browser_source_get_properties(void *data)

obs_properties_add_bool(props, "reroute_audio", obs_module_text("RerouteAudio"));

obs_property_t *media_access =
obs_properties_add_bool(props, "allow_media_access", obs_module_text("AllowMediaAccess"));
obs_property_set_long_description(media_access, obs_module_text("AllowMediaAccess.ToolTip"));

obs_property_t *fps_set = obs_properties_add_bool(props, "fps_custom", obs_module_text("CustomFrameRate"));
obs_property_set_modified_callback(fps_set, is_fps_custom);

Expand Down
10 changes: 7 additions & 3 deletions obs-browser-source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ bool BrowserSource::CreateBrowser()
bool hwaccel = false;
#endif

CefRefPtr<BrowserClient> browserClient =
new BrowserClient(this, hwaccel && tex_sharing_avail, reroute_audio, webpage_control_level);
CefRefPtr<BrowserClient> browserClient = new BrowserClient(
this, hwaccel && tex_sharing_avail, reroute_audio, webpage_control_level, allow_media_access);

CefWindowInfo windowInfo;
windowInfo.bounds.width = width;
Expand Down Expand Up @@ -465,6 +465,7 @@ void BrowserSource::Update(obs_data_t *settings)
bool n_shutdown;
bool n_restart;
bool n_reroute;
bool n_media_access;
ControlLevel n_webpage_control_level;
std::string n_url;
std::string n_css;
Expand All @@ -479,6 +480,7 @@ void BrowserSource::Update(obs_data_t *settings)
n_css = obs_data_get_string(settings, "css");
n_url = obs_data_get_string(settings, n_is_local ? "local_file" : "url");
n_reroute = obs_data_get_bool(settings, "reroute_audio");
n_media_access = obs_data_get_bool(settings, "allow_media_access");
n_webpage_control_level =
static_cast<ControlLevel>(obs_data_get_int(settings, "webpage_control_level"));

Expand All @@ -505,7 +507,8 @@ void BrowserSource::Update(obs_data_t *settings)

if (n_is_local == is_local && n_fps_custom == fps_custom && 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_reroute == reroute_audio && n_webpage_control_level == webpage_control_level &&
n_media_access == allow_media_access) {

if (n_width == width && n_height == height)
return;
Expand All @@ -531,6 +534,7 @@ void BrowserSource::Update(obs_data_t *settings)
fps_custom = n_fps_custom;
shutdown_on_invisible = n_shutdown;
reroute_audio = n_reroute;
allow_media_access = n_media_access;
webpage_control_level = n_webpage_control_level;
restart = n_restart;
css = n_css;
Expand Down
1 change: 1 addition & 0 deletions obs-browser-source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ struct BrowserSource {
bool reroute_audio = true;
std::atomic<bool> destroying = false;
ControlLevel webpage_control_level = DEFAULT_CONTROL_LEVEL;
bool allow_media_access = false;
#if defined(BROWSER_EXTERNAL_BEGIN_FRAME_ENABLED) && defined(ENABLE_BROWSER_SHARED_TEXTURE)
bool reset_frame = false;
#endif
Expand Down
Loading