diff --git a/browser-client.cpp b/browser-client.cpp index ef149c0..de4587e 100644 --- a/browser-client.cpp +++ b/browser-client.cpp @@ -56,6 +56,13 @@ CefRefPtr BrowserClient::GetDisplayHandler() return this; } +#if CHROME_VERSION_BUILD >= 6533 +CefRefPtr BrowserClient::GetPermissionHandler() +{ + return this; +} +#endif + CefRefPtr BrowserClient::GetLifeSpanHandler() { return this; @@ -306,6 +313,21 @@ bool BrowserClient::OnTooltip(CefRefPtr, CefString &text) return true; } +#if CHROME_VERSION_BUILD >= 6533 +/* CefPermissionHandler */ +bool BrowserClient::OnShowPermissionPrompt(CefRefPtr, uint64_t, const CefString &, + uint32_t requested_permissions, + CefRefPtr 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, PaintElementType type, const RectList &, const void *buffer, int width, int height) { diff --git a/browser-client.hpp b/browser-client.hpp index 851ee4e..5046b82 100644 --- a/browser-client.hpp +++ b/browser-client.hpp @@ -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, @@ -66,6 +69,9 @@ class BrowserClient : public CefClient, virtual CefRefPtr GetLoadHandler() override; virtual CefRefPtr GetRenderHandler() override; virtual CefRefPtr GetDisplayHandler() override; +#if CHROME_VERSION_BUILD >= 6533 + virtual CefRefPtr GetPermissionHandler() override; +#endif virtual CefRefPtr GetLifeSpanHandler() override; virtual CefRefPtr GetRequestHandler() override; virtual CefRefPtr GetContextMenuHandler() override; @@ -80,6 +86,13 @@ class BrowserClient : public CefClient, const CefString &source, int line) override; virtual bool OnTooltip(CefRefPtr browser, CefString &text) override; + /* CefPermissionHandler */ +#if CHROME_VERSION_BUILD >= 6533 + virtual bool OnShowPermissionPrompt(CefRefPtr browser, uint64_t prompt_id, + const CefString &requesting_origin, uint32_t requested_permissions, + CefRefPtr callback) override; +#endif + /* CefLifeSpanHandler */ virtual bool OnBeforePopup(CefRefPtr browser, CefRefPtr frame, #if CHROME_VERSION_BUILD >= 6834 diff --git a/browser-scheme.cpp b/browser-scheme.cpp index b9ea148..1da6ed3 100644 --- a/browser-scheme.cpp +++ b/browser-scheme.cpp @@ -28,6 +28,16 @@ CefRefPtr BrowserSchemeHandlerFactory::Create(CefRefPtrGetMainFrame()->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); diff --git a/browser-version.h b/browser-version.h index aa2c7af..73d4c83 100644 --- a/browser-version.h +++ b/browser-version.h @@ -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) diff --git a/obs-browser-plugin.cpp b/obs-browser-plugin.cpp index a26112f..acd4534 100644 --- a/obs-browser-plugin.cpp +++ b/obs-browser-plugin.cpp @@ -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(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 @@ -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 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; @@ -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 kMigrationDirectories{ - "Local Storage", - "Session Storage", - "Network", + namespace fs = std::filesystem; + + constexpr std::array 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); } @@ -793,7 +806,7 @@ static void MigrateToChromeRuntime() { namespace fs = std::filesystem; BPtr 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."); @@ -801,7 +814,7 @@ static void MigrateToChromeRuntime() } BPtr 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."); @@ -819,7 +832,7 @@ static void MigrateToChromeRuntime() MigrateDefaultProfileSubdirs("", false); BPtr 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) { @@ -829,24 +842,24 @@ static void MigrateToChromeRuntime() constexpr std::string_view prefix = "obs_profile_cookies"; BPtr 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()); } } diff --git a/panel/browser-panel-client.cpp b/panel/browser-panel-client.cpp index 555992c..4da3b8a 100644 --- a/panel/browser-panel-client.cpp +++ b/panel/browser-panel-client.cpp @@ -43,6 +43,11 @@ CefRefPtr QCefBrowserClient::GetCommandHandler() { return this; } + +CefRefPtr QCefBrowserClient::GetPermissionHandler() +{ + return this; +} #endif CefRefPtr QCefBrowserClient::GetRequestHandler() @@ -81,6 +86,19 @@ bool QCefBrowserClient::OnChromeCommand(CefRefPtr, int, cef_window_o { return true; } + +/* CefPermissionHandler */ +bool QCefBrowserClient::OnShowPermissionPrompt(CefRefPtr, uint64_t, const CefString &, + uint32_t requested_permissions, + CefRefPtr 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 */ diff --git a/panel/browser-panel-client.hpp b/panel/browser-panel-client.hpp index ea44000..ad23151 100644 --- a/panel/browser-panel-client.hpp +++ b/panel/browser-panel-client.hpp @@ -9,6 +9,7 @@ class QCefBrowserClient : public CefClient, public CefDisplayHandler, #if CHROME_VERSION_BUILD >= 6533 public CefCommandHandler, + public CefPermissionHandler, #endif public CefRequestHandler, public CefLifeSpanHandler, @@ -31,6 +32,7 @@ class QCefBrowserClient : public CefClient, virtual CefRefPtr GetDisplayHandler() override; #if CHROME_VERSION_BUILD >= 6533 virtual CefRefPtr GetCommandHandler() override; + virtual CefRefPtr GetPermissionHandler() override; #endif virtual CefRefPtr GetRequestHandler() override; virtual CefRefPtr GetLifeSpanHandler() override; @@ -43,6 +45,12 @@ class QCefBrowserClient : public CefClient, #if CHROME_VERSION_BUILD >= 6533 virtual bool OnChromeCommand(CefRefPtr browser, int command_id, cef_window_open_disposition_t disposition) override; + + /* CefPermissionHandler */ + virtual bool OnShowPermissionPrompt(CefRefPtr browser, uint64_t prompt_id, + const CefString &requesting_origin, uint32_t requested_permissions, + CefRefPtr callback) override; + #endif /* CefDisplayHandler */