#pragma once #include "config.h" #include "profile_config.h" #include "include/cef_app.h" #include "include/cef_command_line.h" #include "include/capi/cef_origin_whitelist_capi.h" class BrowserApp : public CefApp, public CefBrowserProcessHandler { public: BrowserApp() { Config::getInstance().loadCefFlags(); } virtual CefRefPtr GetBrowserProcessHandler() override { return this; } virtual void OnBeforeCommandLineProcessing( const CefString &process_type, CefRefPtr command_line) override { const auto &flags = Config::getInstance().getCefFlags(); const auto &flags_with_value = Config::getInstance().getCefFlagsWithValue(); for (const auto &flag : flags) { command_line->AppendSwitch(flag); } for (const auto &pair : flags_with_value) { command_line->AppendSwitchWithValue(pair.first, pair.second); } ProfileConfig &profile_config = ProfileConfig::getInstance(); if (profile_config.isProxyEnabled() && !profile_config.getProxyServer().empty()) { command_line->AppendSwitchWithValue("proxy-server", profile_config.getProxyServer()); if (!profile_config.getProxyBypassList().empty()) { command_line->AppendSwitchWithValue("proxy-bypass-list", profile_config.getProxyBypassList()); } } // No forced Tor proxy and no host-resolver scrub: when proxy is disabled, // CEF uses the system resolver, so /etc/hosts (porno-blocklist) works. // .onion hosts only resolve when a Tor SOCKS proxy is configured in // browser.conf (proxy_enabled=true, proxy_server=socks5://127.0.0.1:9051). // Add cross-origin whitelist entry for file uploads: // Allow http://127.0.0.1 as target for HTTPS page requests (bypasses loopback CORS block) { CefString source_origin("https://studio.youtube.com"); CefString target_protocol("http"); CefString target_domain("127.0.0.1"); bool allow_target_subdomains = false; cef_add_cross_origin_whitelist_entry(source_origin.GetStruct(), target_protocol.GetStruct(), target_domain.GetStruct(), allow_target_subdomains); } } private: IMPLEMENT_REFCOUNTING(BrowserApp); };