Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

obs-browser: flush panel cookie store on exit #155

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
68 changes: 68 additions & 0 deletions obs-browser-plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,72 @@ bool QueueCEFTask(std::function<void()> task)

/* ========================================================================= */

static std::mutex cookie_managers_mutex;
static std::vector<CefRefPtr<CefCookieManager>> cookie_managers;

void register_cookie_manager(CefRefPtr<CefCookieManager> cm)
{
std::lock_guard<std::mutex> guard(cookie_managers_mutex);

cookie_managers.emplace_back(cm);
}

static void flush_cookie_manager(CefRefPtr<CefCookieManager> cm)
{
os_event_t* complete_event;

os_event_init(&complete_event, OS_EVENT_TYPE_AUTO);

class CompletionCallback : public CefCompletionCallback
{
public:
CompletionCallback(os_event_t* complete_event) : m_complete_event(complete_event)
{
}

virtual void OnComplete() override
{
os_event_signal(m_complete_event);
}

IMPLEMENT_REFCOUNTING(CompletionCallback);

private:
os_event_t* m_complete_event;
};

CefRefPtr<CefCompletionCallback> callback =
new CompletionCallback(complete_event);

auto task = [&]() {
if (!cm->FlushStore(callback)) {
blog(LOG_WARNING,
"Failed flushing cookie store");

os_event_signal(complete_event);
}
else {
blog(LOG_INFO, "Flushed cookie store");
}
};

CefPostTask(TID_IO, CefRefPtr<BrowserTask>(new BrowserTask(task)));

os_event_wait(complete_event);
os_event_destroy(complete_event);
}

static void flush_cookie_managers()
{
std::lock_guard<std::mutex> guard(cookie_managers_mutex);

for (auto cm : cookie_managers) {
flush_cookie_manager(cm);
}
}

/* ========================================================================= */

static const char *default_css = "\
body { \
background-color: rgba(0, 0, 0, 0); \
Expand Down Expand Up @@ -500,6 +566,8 @@ bool obs_module_load(void)

void obs_module_unload(void)
{
flush_cookie_managers();

if (manager_thread.joinable()) {
while (!QueueCEFTask([] () {CefQuitMessageLoop();}))
os_sleep_ms(5);
Expand Down
4 changes: 4 additions & 0 deletions panel/browser-panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ extern bool QueueCEFTask(std::function<void()> task);
extern "C" void obs_browser_initialize(void);
extern os_event_t *cef_started_event;

void register_cookie_manager(CefRefPtr<CefCookieManager> cm);

std::mutex popup_whitelist_mutex;
std::vector<PopupWhitelistInfo> popup_whitelist;
std::vector<PopupWhitelistInfo> forced_popups;
Expand Down Expand Up @@ -83,6 +85,8 @@ struct QCefCookieManagerInternal : QCefCookieManager {
if (!cm)
throw "Failed to create cookie manager";

register_cookie_manager(cm);

rch = new QCefRequestContextHandler(cm);

rc = CefRequestContext::CreateContext(
Expand Down