Skip to content
Merged
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
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ target_sources(
deps/wide-string.cpp
deps/wide-string.hpp
obs-browser-plugin.cpp
obs-browser-source-audio.cpp
obs-browser-source.cpp
obs-browser-source.hpp)

Expand Down
86 changes: 0 additions & 86 deletions browser-app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,7 @@ void BrowserApp::OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFr
obsStudioObj->SetValue(name, func, V8_PROPERTY_ATTRIBUTE_NONE);
}

#if !ENABLE_WASHIDDEN
int id = browser->GetIdentifier();
if (browserVis.find(id) != browserVis.end()) {
SetDocumentVisibility(browser, browserVis[id]);
}
#else
UNUSED_PARAMETER(browser);
#endif
}

void BrowserApp::ExecuteJSFunction(CefRefPtr<CefBrowser> browser, const char *functionName, CefV8ValueList arguments)
Expand Down Expand Up @@ -158,81 +151,6 @@ void BrowserApp::ExecuteJSFunction(CefRefPtr<CefBrowser> browser, const char *fu
}
}

#if !ENABLE_WASHIDDEN
void BrowserApp::SetFrameDocumentVisibility(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, bool isVisible)
{
UNUSED_PARAMETER(browser);

CefRefPtr<CefV8Context> context = frame->GetV8Context();

context->Enter();

CefRefPtr<CefV8Value> globalObj = context->GetGlobal();

CefRefPtr<CefV8Value> documentObject = globalObj->GetValue("document");

if (!!documentObject) {
documentObject->SetValue("hidden", CefV8Value::CreateBool(!isVisible), V8_PROPERTY_ATTRIBUTE_READONLY);

documentObject->SetValue("visibilityState", CefV8Value::CreateString(isVisible ? "visible" : "hidden"),
V8_PROPERTY_ATTRIBUTE_READONLY);

std::string script = "new CustomEvent('visibilitychange', {});";

CefRefPtr<CefV8Value> returnValue;
CefRefPtr<CefV8Exception> exception;

/* Create the CustomEvent object
* We have to use eval to invoke the new operator */
bool success = context->Eval(script, frame->GetURL(), 0, returnValue, exception);

if (success) {
CefV8ValueList arguments;
arguments.push_back(returnValue);

CefRefPtr<CefV8Value> dispatchEvent = documentObject->GetValue("dispatchEvent");

/* Dispatch visibilitychange event on the document
* object */
dispatchEvent->ExecuteFunction(documentObject, arguments);
}
}

context->Exit();
}

void BrowserApp::SetDocumentVisibility(CefRefPtr<CefBrowser> browser, bool isVisible)
{
/* This method might be called before OnContextCreated
* call is made. We'll save the requested visibility
* state here, and use it later in OnContextCreated to
* set initial page visibility state. */
browserVis[browser->GetIdentifier()] = isVisible;

std::vector<int64> frameIdentifiers;
/* Set visibility state for every frame in the browser
*
* According to the Page Visibility API documentation:
* https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API
*
* "Visibility states of an <iframe> are the same as
* the parent document. Hiding an <iframe> using CSS
* properties (such as display: none;) doesn't trigger
* visibility events or change the state of the document
* contained within the frame."
*
* Thus, we set the same visibility state for every frame of the browser.
*/
browser->GetFrameIdentifiers(frameIdentifiers);

for (int64 frameId : frameIdentifiers) {
CefRefPtr<CefFrame> frame = browser->GetFrame(frameId);

SetFrameDocumentVisibility(browser, frame, isVisible);
}
}
#endif

CefRefPtr<CefV8Value> CefValueToCefV8Value(CefRefPtr<CefValue> value)
{
CefRefPtr<CefV8Value> result;
Expand Down Expand Up @@ -299,10 +217,6 @@ bool BrowserApp::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefRefP

ExecuteJSFunction(browser, "onVisibilityChange", arguments);

#if !ENABLE_WASHIDDEN
SetDocumentVisibility(browser, args->GetBool(0));
#endif

} else if (message->GetName() == "Active") {
CefV8ValueList arguments;
arguments.push_back(CefV8Value::CreateBool(args->GetBool(0)));
Expand Down
7 changes: 0 additions & 7 deletions browser-app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,5 @@ class BrowserApp : public CefApp, public CefRenderProcessHandler, public CefBrow
QTimer frameTimer;
#endif

#if !ENABLE_WASHIDDEN
std::unordered_map<int, bool> browserVis;

void SetFrameDocumentVisibility(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, bool isVisible);
void SetDocumentVisibility(CefRefPtr<CefBrowser> browser, bool isVisible);
#endif

IMPLEMENT_REFCOUNTING(BrowserApp);
};
77 changes: 0 additions & 77 deletions browser-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ CefRefPtr<CefAudioHandler> BrowserClient::GetAudioHandler()
return reroute_audio ? this : nullptr;
}

#if CHROME_VERSION_BUILD >= 4638
CefRefPtr<CefRequestHandler> BrowserClient::GetRequestHandler()
{
return this;
Expand Down Expand Up @@ -120,7 +119,6 @@ CefResourceRequestHandler::ReturnValue BrowserClient::OnBeforeResourceLoad(CefRe
{
return RV_CONTINUE;
}
#endif

bool BrowserClient::OnBeforePopup(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame>,
#if CHROME_VERSION_BUILD >= 6834
Expand Down Expand Up @@ -535,7 +533,6 @@ static speaker_layout GetSpeakerLayout(CefAudioHandler::ChannelLayout cefLayout)
}
}

#if CHROME_VERSION_BUILD >= 4103
void BrowserClient::OnAudioStreamStarted(CefRefPtr<CefBrowser> browser, const CefAudioParameters &params_,
int channels_)
{
Expand Down Expand Up @@ -608,80 +605,6 @@ bool BrowserClient::GetAudioParameters(CefRefPtr<CefBrowser> browser, CefAudioPa
params.frames_per_buffer = kFramesPerBuffer;
return true;
}
#elif CHROME_VERSION_BUILD < 4103
void BrowserClient::OnAudioStreamStarted(CefRefPtr<CefBrowser> browser, int id, int, ChannelLayout channel_layout,
int sample_rate, int)
{
UNUSED_PARAMETER(browser);
if (!valid()) {
return;
}

AudioStream &stream = bs->audio_streams[id];
if (!stream.source) {
stream.source = obs_source_create_private("audio_line", nullptr, nullptr);

obs_source_add_active_child(bs->source, stream.source);

std::lock_guard<std::mutex> lock(bs->audio_sources_mutex);
bs->audio_sources.push_back(stream.source);
}

stream.speakers = GetSpeakerLayout(channel_layout);
stream.channels = get_audio_channels(stream.speakers);
stream.sample_rate = sample_rate;
}

void BrowserClient::OnAudioStreamPacket(CefRefPtr<CefBrowser> browser, int id, const float **data, int frames,
int64_t pts)
{
UNUSED_PARAMETER(browser);
if (!valid()) {
return;
}

AudioStream &stream = bs->audio_streams[id];
struct obs_source_audio audio = {};

const uint8_t **pcm = (const uint8_t **)data;
for (int i = 0; i < stream.channels; i++)
audio.data[i] = pcm[i];

audio.samples_per_sec = stream.sample_rate;
audio.frames = frames;
audio.format = AUDIO_FORMAT_FLOAT_PLANAR;
audio.speakers = stream.speakers;
audio.timestamp = (uint64_t)pts * 1000000LLU;

obs_source_output_audio(stream.source, &audio);
}

void BrowserClient::OnAudioStreamStopped(CefRefPtr<CefBrowser> browser, int id)
{
UNUSED_PARAMETER(browser);
if (!valid()) {
return;
}

auto pair = bs->audio_streams.find(id);
if (pair == bs->audio_streams.end()) {
return;
}

AudioStream &stream = pair->second;
{
std::lock_guard<std::mutex> lock(bs->audio_sources_mutex);
for (size_t i = 0; i < bs->audio_sources.size(); i++) {
obs_source_t *source = bs->audio_sources[i];
if (source == stream.source) {
bs->audio_sources.erase(bs->audio_sources.begin() + i);
break;
}
}
}
bs->audio_streams.erase(pair);
}
#endif

void BrowserClient::OnLoadEnd(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame> frame, int)
{
Expand Down
21 changes: 3 additions & 18 deletions browser-client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ class BrowserClient : public CefClient,
public CefDisplayHandler,
public CefLifeSpanHandler,
public CefRequestHandler,
#if CHROME_VERSION_BUILD >= 4638
public CefResourceRequestHandler,
#endif
public CefContextMenuHandler,
public CefRenderHandler,
public CefAudioHandler,
Expand All @@ -50,12 +48,11 @@ class BrowserClient : public CefClient,
CefRect popupRect;
CefRect originalPopupRect;

#if CHROME_VERSION_BUILD >= 4103
int sample_rate;
int channels;
ChannelLayout channel_layout;
int frames_per_buffer;
#endif

inline BrowserClient(BrowserSource *bs_, bool sharing_avail, bool reroute_audio_,
ControlLevel webpage_control_level_)
: sharing_available(sharing_avail),
Expand All @@ -70,9 +67,7 @@ class BrowserClient : public CefClient,
virtual CefRefPtr<CefRenderHandler> GetRenderHandler() override;
virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() override;
virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() override;
#if CHROME_VERSION_BUILD >= 4638
virtual CefRefPtr<CefRequestHandler> GetRequestHandler() override;
#endif
virtual CefRefPtr<CefContextMenuHandler> GetContextMenuHandler() override;
virtual CefRefPtr<CefAudioHandler> GetAudioHandler() override;

Expand All @@ -95,7 +90,7 @@ class BrowserClient : public CefClient,
const CefPopupFeatures &popupFeatures, CefWindowInfo &windowInfo,
CefRefPtr<CefClient> &client, CefBrowserSettings &settings,
CefRefPtr<CefDictionaryValue> &extra_info, bool *no_javascript_access) override;
#if CHROME_VERSION_BUILD >= 4638

/* CefRequestHandler */
virtual CefRefPtr<CefResourceRequestHandler>
GetResourceRequestHandler(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
Expand All @@ -113,7 +108,6 @@ class BrowserClient : public CefClient,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
CefRefPtr<CefCallback> callback) override;
#endif

/* CefContextMenuHandler */
virtual void OnBeforeContextMenu(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
Expand All @@ -137,7 +131,7 @@ class BrowserClient : public CefClient,
const RectList &dirtyRects, void *shared_handle, bool new_texture) override;
#endif
#endif
#if CHROME_VERSION_BUILD >= 4103

virtual void OnAudioStreamPacket(CefRefPtr<CefBrowser> browser, const float **data, int frames,
int64_t pts) override;

Expand All @@ -148,16 +142,7 @@ class BrowserClient : public CefClient,
virtual void OnAudioStreamError(CefRefPtr<CefBrowser> browser, const CefString &message) override;
const int kFramesPerBuffer = 1024;
virtual bool GetAudioParameters(CefRefPtr<CefBrowser> browser, CefAudioParameters &params) override;
#else
virtual void OnAudioStreamPacket(CefRefPtr<CefBrowser> browser, int audio_stream_id, const float **data,
int frames, int64_t pts) override;

virtual void OnAudioStreamStopped(CefRefPtr<CefBrowser> browser, int audio_stream_id);

virtual void OnAudioStreamStarted(CefRefPtr<CefBrowser> browser, int audio_stream_id, int channels,
ChannelLayout channel_layout, int sample_rate,
int frames_per_buffer) override;
#endif
/* CefLoadHandler */
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, int httpStatusCode) override;

Expand Down
2 changes: 0 additions & 2 deletions browser-scheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "wide-string.hpp"
#include <include/wrapper/cef_stream_resource_handler.h>

#if !ENABLE_LOCAL_FILE_URL_SCHEME
CefRefPtr<CefResourceHandler> BrowserSchemeHandlerFactory::Create(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame>,
const CefString &, CefRefPtr<CefRequest> request)
{
Expand Down Expand Up @@ -57,4 +56,3 @@ CefRefPtr<CefResourceHandler> BrowserSchemeHandlerFactory::Create(CefRefPtr<CefB
return nullptr;
}
}
#endif
8 changes: 0 additions & 8 deletions browser-scheme.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,10 @@
#include <string>
#include <fstream>

#if CHROME_VERSION_BUILD < 4638
#define ENABLE_LOCAL_FILE_URL_SCHEME 1
#else
#define ENABLE_LOCAL_FILE_URL_SCHEME 0
#endif

#if !ENABLE_LOCAL_FILE_URL_SCHEME
class BrowserSchemeHandlerFactory : public CefSchemeHandlerFactory {
public:
virtual CefRefPtr<CefResourceHandler> Create(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame>,
const CefString &, CefRefPtr<CefRequest> request) override;

IMPLEMENT_REFCOUNTING(BrowserSchemeHandlerFactory);
};
#endif
6 changes: 0 additions & 6 deletions cef-headers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@
#include "include/wrapper/cef_library_loader.h"
#endif

#if CHROME_VERSION_BUILD >= 4430
#define ENABLE_WASHIDDEN 1
#else
#define ENABLE_WASHIDDEN 0
#endif

#if !defined(_WIN32) && !defined(__APPLE__) && \
(CHROME_VERSION_BUILD >= 6943 || (CHROME_VERSION_BUILD > 6337 && defined(CEF_OSR_EXTRA_INFO)))
#define ENABLE_BROWSER_SHARED_TEXTURE
Expand Down
Loading