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
22 changes: 22 additions & 0 deletions browser-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ CefRefPtr<CefDisplayHandler> BrowserClient::GetDisplayHandler()
return this;
}

#if CHROME_VERSION_BUILD >= 6533
CefRefPtr<CefPermissionHandler> BrowserClient::GetPermissionHandler()
{
return this;
}
#endif

CefRefPtr<CefLifeSpanHandler> BrowserClient::GetLifeSpanHandler()
{
return this;
Expand Down Expand Up @@ -306,6 +313,21 @@ bool BrowserClient::OnTooltip(CefRefPtr<CefBrowser>, CefString &text)
return true;
}

#if CHROME_VERSION_BUILD >= 6533
/* CefPermissionHandler */
bool BrowserClient::OnShowPermissionPrompt(CefRefPtr<CefBrowser>, uint64_t, const CefString &,
uint32_t requested_permissions,
CefRefPtr<CefPermissionPromptCallback> callback)
{
// Implicitly allow Localhost access to retain previous behavior for now
if ((requested_permissions & CEF_PERMISSION_TYPE_LOOPBACK_NETWORK) != 0) {
callback->Continue(CEF_PERMISSION_RESULT_ACCEPT);
return true;
}
return false;
}
#endif

void BrowserClient::OnPaint(CefRefPtr<CefBrowser>, PaintElementType type, const RectList &, const void *buffer,
int width, int height)
{
Expand Down
13 changes: 13 additions & 0 deletions browser-client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ struct BrowserSource;

class BrowserClient : public CefClient,
public CefDisplayHandler,
#if CHROME_VERSION_BUILD >= 6533
public CefPermissionHandler,
#endif
public CefLifeSpanHandler,
public CefRequestHandler,
public CefResourceRequestHandler,
Expand Down Expand Up @@ -66,6 +69,9 @@ class BrowserClient : public CefClient,
virtual CefRefPtr<CefLoadHandler> GetLoadHandler() override;
virtual CefRefPtr<CefRenderHandler> GetRenderHandler() override;
virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() override;
#if CHROME_VERSION_BUILD >= 6533
virtual CefRefPtr<CefPermissionHandler> GetPermissionHandler() override;
#endif
virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() override;
virtual CefRefPtr<CefRequestHandler> GetRequestHandler() override;
virtual CefRefPtr<CefContextMenuHandler> GetContextMenuHandler() override;
Expand All @@ -80,6 +86,13 @@ class BrowserClient : public CefClient,
const CefString &source, int line) override;
virtual bool OnTooltip(CefRefPtr<CefBrowser> browser, CefString &text) override;

/* CefPermissionHandler */
#if CHROME_VERSION_BUILD >= 6533
virtual bool OnShowPermissionPrompt(CefRefPtr<CefBrowser> browser, uint64_t prompt_id,
const CefString &requesting_origin, uint32_t requested_permissions,
CefRefPtr<CefPermissionPromptCallback> callback) override;
#endif

/* CefLifeSpanHandler */
virtual bool OnBeforePopup(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
#if CHROME_VERSION_BUILD >= 6834
Expand Down
10 changes: 10 additions & 0 deletions browser-scheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ CefRefPtr<CefResourceHandler> BrowserSchemeHandlerFactory::Create(CefRefPtr<CefB
return nullptr;
}

CefString frameURL = browser->GetMainFrame()->GetURL();
if (!frameURL.empty()) {
CefURLParts frameParts;
CefParseURL(frameURL, frameParts);
std::string frameOrigin = CefString(&frameParts.origin);
if (frameOrigin != "http://absolute/") {
return nullptr;
}
}

CefURLParts parts;
CefParseURL(request->GetURL(), parts);

Expand Down
2 changes: 1 addition & 1 deletion browser-version.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#define OBS_BROWSER_VERSION_MAJOR 2
#define OBS_BROWSER_VERSION_MINOR 27
#define OBS_BROWSER_VERSION_PATCH 1
#define OBS_BROWSER_VERSION_PATCH 3

#ifndef MAKE_SEMANTIC_VERSION
#define MAKE_SEMANTIC_VERSION(major, minor, patch) ((major << 24) | (minor << 16) | patch)
Expand Down
71 changes: 42 additions & 29 deletions obs-browser-plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ static std::wstring deviceId;

bool hwaccel = false;

namespace {
// Naive conversions between char* (Ex. from libobs) and filesystem::path using the platform codepage.
std::filesystem::path pathFromUtf8(const char *path)
{
return std::filesystem::path{reinterpret_cast<const char8_t *>(path)};
}

std::string utf8BytesFromPath(std::filesystem::path path)
{
const std::u8string u8 = path.u8string();
return std::string{u8.begin(), u8.end()};
}
} // namespace

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

#ifdef ENABLE_BROWSER_QT_LOOP
Expand Down Expand Up @@ -744,15 +758,15 @@ static void check_hwaccel_support(void)
#endif

#if CHROME_VERSION_BUILD > 6533
static void MigrateProfileConfigDir(std::string oldDir, std::string newDir, bool makeDirs)
static void MigrateProfileConfigDir(filesystem::path oldDir, filesystem::path newDir, bool makeDirs)
{
namespace fs = std::filesystem;

BPtr<char> configPath = obs_module_config_path(".");
fs::path rootPath{configPath.Get()};
fs::path rootPath{pathFromUtf8(configPath.Get())};

fs::path oldPath = rootPath / fs::path(oldDir);
fs::path newPath = rootPath / fs::path(newDir);
fs::path oldPath = rootPath / oldDir;
fs::path newPath = rootPath / newDir;

if (!fs::exists(oldPath)) {
return;
Expand All @@ -769,21 +783,20 @@ static void MigrateProfileConfigDir(std::string oldDir, std::string newDir, bool
}
}

static void MigrateDefaultProfileSubdirs(std::string parent, bool makeDirs)
static void MigrateDefaultProfileSubdirs(filesystem::path parent, bool makeDirs)
{
constexpr std::array<std::string_view, 3> kMigrationDirectories{
"Local Storage",
"Session Storage",
"Network",
namespace fs = std::filesystem;

constexpr std::array<std::u8string_view, 3> kMigrationDirectories{
u8"Local Storage",
u8"Session Storage",
u8"Network",
};
constexpr std::string_view kDefaultDirectoryPrefix{"Default/"};
constexpr std::u8string_view kDefaultDirectoryPrefix{u8"Default"};

for (std::string_view directory : kMigrationDirectories) {
std::string oldDirectory{parent};
oldDirectory.append(directory);
std::string newDirectory{parent};
newDirectory.append(kDefaultDirectoryPrefix);
newDirectory.append(directory);
for (std::u8string_view directory : kMigrationDirectories) {
fs::path oldDirectory = parent / directory;
fs::path newDirectory = parent / kDefaultDirectoryPrefix / directory;

MigrateProfileConfigDir(oldDirectory, newDirectory, makeDirs);
}
Expand All @@ -793,15 +806,15 @@ static void MigrateToChromeRuntime()
{
namespace fs = std::filesystem;
BPtr<char> defaultConfigPath = obs_module_config_path("Default");
fs::path defaultPath{defaultConfigPath.Get()};
fs::path defaultPath{pathFromUtf8(defaultConfigPath.Get())};
// User has already previously launched with Chrome Runtime
if (fs::exists(defaultPath)) {
blog(LOG_INFO, "[obs-browser]: Chrome Runtime Default profile detected. No migration necessary.");
return;
}

BPtr<char> localPrefsConfigPath = obs_module_config_path("LocalPrefs.json");
fs::path localPrefs{localPrefsConfigPath.Get()};
fs::path localPrefs{pathFromUtf8(localPrefsConfigPath.Get())};
// User has never launched old OBS Browser before
if (!fs::exists(localPrefs)) {
blog(LOG_DEBUG, "[obs-browser]: Alloy Runtime preferences not found. No migration necessary.");
Expand All @@ -819,7 +832,7 @@ static void MigrateToChromeRuntime()
MigrateDefaultProfileSubdirs("", false);

BPtr<char> newLocalPrefsConfigPath = obs_module_config_path("Local State");
fs::path newLocalPrefs{newLocalPrefsConfigPath.Get()};
fs::path newLocalPrefs{pathFromUtf8(newLocalPrefsConfigPath.Get())};
try {
fs::copy(localPrefs, newLocalPrefs);
} catch (const fs::filesystem_error &error) {
Expand All @@ -829,24 +842,24 @@ static void MigrateToChromeRuntime()
constexpr std::string_view prefix = "obs_profile_cookies";

BPtr<char> serviceProfilesPath = obs_module_config_path(prefix.data());
fs::path serviceProfiles{serviceProfilesPath.Get()};
fs::path serviceProfiles{pathFromUtf8(serviceProfilesPath.Get())};
if (fs::exists(serviceProfiles)) {
// User has service integration cookies that also must be copied
for (auto const &dir_entry : std::filesystem::directory_iterator{serviceProfiles}) {
if (!dir_entry.is_directory()) {
continue;
}
std::string name{dir_entry.path().filename().string()};
std::string oldDir{prefix};
oldDir.append("/");
oldDir.append(name);

std::string newDir{prefix};
newDir.append("_");
newDir.append(name);
fs::path name{dir_entry.path().filename()};

fs::path oldDir = fs::path{prefix} / name;

fs::path newDir{prefix};
newDir += "_";
newDir += name;

MigrateProfileConfigDir(oldDir, newDir, true);

blog(LOG_INFO, "[obs-browser]: Migrated cookies for %s.", name.c_str());
blog(LOG_INFO, "[obs-browser]: Migrated cookies for %s.", utf8BytesFromPath(name).c_str());
}
}

Expand Down
18 changes: 18 additions & 0 deletions panel/browser-panel-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ CefRefPtr<CefCommandHandler> QCefBrowserClient::GetCommandHandler()
{
return this;
}

CefRefPtr<CefPermissionHandler> QCefBrowserClient::GetPermissionHandler()
{
return this;
}
#endif

CefRefPtr<CefRequestHandler> QCefBrowserClient::GetRequestHandler()
Expand Down Expand Up @@ -81,6 +86,19 @@ bool QCefBrowserClient::OnChromeCommand(CefRefPtr<CefBrowser>, int, cef_window_o
{
return true;
}

/* CefPermissionHandler */
bool QCefBrowserClient::OnShowPermissionPrompt(CefRefPtr<CefBrowser>, uint64_t, const CefString &,
uint32_t requested_permissions,
CefRefPtr<CefPermissionPromptCallback> callback)
{
// Implicitly allow Localhost access to retain previous behavior for now
if ((requested_permissions & CEF_PERMISSION_TYPE_LOOPBACK_NETWORK) != 0) {
callback->Continue(CEF_PERMISSION_RESULT_ACCEPT);
return true;
}
return false;
}
#endif

/* CefDisplayHandler */
Expand Down
8 changes: 8 additions & 0 deletions panel/browser-panel-client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class QCefBrowserClient : public CefClient,
public CefDisplayHandler,
#if CHROME_VERSION_BUILD >= 6533
public CefCommandHandler,
public CefPermissionHandler,
#endif
public CefRequestHandler,
public CefLifeSpanHandler,
Expand All @@ -31,6 +32,7 @@ class QCefBrowserClient : public CefClient,
virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() override;
#if CHROME_VERSION_BUILD >= 6533
virtual CefRefPtr<CefCommandHandler> GetCommandHandler() override;
virtual CefRefPtr<CefPermissionHandler> GetPermissionHandler() override;
#endif
virtual CefRefPtr<CefRequestHandler> GetRequestHandler() override;
virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() override;
Expand All @@ -43,6 +45,12 @@ class QCefBrowserClient : public CefClient,
#if CHROME_VERSION_BUILD >= 6533
virtual bool OnChromeCommand(CefRefPtr<CefBrowser> browser, int command_id,
cef_window_open_disposition_t disposition) override;

/* CefPermissionHandler */
virtual bool OnShowPermissionPrompt(CefRefPtr<CefBrowser> browser, uint64_t prompt_id,
const CefString &requesting_origin, uint32_t requested_permissions,
CefRefPtr<CefPermissionPromptCallback> callback) override;

#endif

/* CefDisplayHandler */
Expand Down