diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2022-04-08 01:46:47 +0430 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-04-09 12:21:43 +0200 |
commit | a42e03b01a7c2c98377f3851cb4e5f07d7e3ba35 (patch) | |
tree | 812e97db21dee65573b5a669a2b643ee4ea83426 /Userland/Applications | |
parent | f9fc28931fe42700bbfc8964a0a7ceb5940a46f7 (diff) | |
download | serenity-a42e03b01a7c2c98377f3851cb4e5f07d7e3ba35.zip |
Browser+LibWeb+WebContent: Implement per-URL-pattern proxies
...at least for SOCKS5.
Diffstat (limited to 'Userland/Applications')
-rw-r--r-- | Userland/Applications/Browser/Browser.h | 2 | ||||
-rw-r--r-- | Userland/Applications/Browser/BrowserWindow.cpp | 29 | ||||
-rw-r--r-- | Userland/Applications/Browser/BrowserWindow.h | 1 | ||||
-rw-r--r-- | Userland/Applications/Browser/Tab.cpp | 7 | ||||
-rw-r--r-- | Userland/Applications/Browser/Tab.h | 1 | ||||
-rw-r--r-- | Userland/Applications/Browser/main.cpp | 16 |
6 files changed, 51 insertions, 5 deletions
diff --git a/Userland/Applications/Browser/Browser.h b/Userland/Applications/Browser/Browser.h index fccb78d47b..b9d186e4ae 100644 --- a/Userland/Applications/Browser/Browser.h +++ b/Userland/Applications/Browser/Browser.h @@ -14,6 +14,8 @@ namespace Browser { extern String g_home_url; extern String g_search_engine; extern Vector<String> g_content_filters; +extern Vector<String> g_proxies; +extern HashMap<String, size_t> g_proxy_mappings; extern bool g_content_filters_enabled; extern IconBag g_icon_bag; diff --git a/Userland/Applications/Browser/BrowserWindow.cpp b/Userland/Applications/Browser/BrowserWindow.cpp index 7cf6e186e1..f67501427b 100644 --- a/Userland/Applications/Browser/BrowserWindow.cpp +++ b/Userland/Applications/Browser/BrowserWindow.cpp @@ -575,15 +575,34 @@ void BrowserWindow::content_filters_changed() }); } +void BrowserWindow::proxy_mappings_changed() +{ + tab_widget().for_each_child_of_type<Browser::Tab>([](auto& tab) { + tab.proxy_mappings_changed(); + return IterationDecision::Continue; + }); +} + void BrowserWindow::config_string_did_change(String const& domain, String const& group, String const& key, String const& value) { - if (domain != "Browser" || group != "Preferences") + if (domain != "Browser") return; - if (key == "SearchEngine") - Browser::g_search_engine = value; - else if (key == "Home") - Browser::g_home_url = value; + if (group == "Preferences") { + if (key == "SearchEngine") + Browser::g_search_engine = value; + else if (key == "Home") + Browser::g_home_url = value; + } else if (group.starts_with("Proxy:")) { + dbgln("Proxy mapping changed: {}/{} = {}", group, key, value); + auto proxy_spec = group.substring_view(6); + auto existing_proxy = Browser::g_proxies.find(proxy_spec); + if (existing_proxy.is_end()) + Browser::g_proxies.append(proxy_spec); + + Browser::g_proxy_mappings.set(key, existing_proxy.index()); + proxy_mappings_changed(); + } // TODO: ColorScheme } diff --git a/Userland/Applications/Browser/BrowserWindow.h b/Userland/Applications/Browser/BrowserWindow.h index 88e4496349..fe6e9e3efe 100644 --- a/Userland/Applications/Browser/BrowserWindow.h +++ b/Userland/Applications/Browser/BrowserWindow.h @@ -41,6 +41,7 @@ public: GUI::Action& inspect_dom_node_action() { return *m_inspect_dom_node_action; } void content_filters_changed(); + void proxy_mappings_changed(); private: explicit BrowserWindow(CookieJar&, URL); diff --git a/Userland/Applications/Browser/Tab.cpp b/Userland/Applications/Browser/Tab.cpp index e634b2e58f..745ae88556 100644 --- a/Userland/Applications/Browser/Tab.cpp +++ b/Userland/Applications/Browser/Tab.cpp @@ -118,6 +118,8 @@ Tab::Tab(BrowserWindow& window) else m_web_content_view->set_content_filters({}); + m_web_content_view->set_proxy_mappings(g_proxies, g_proxy_mappings); + auto& go_back_button = toolbar.add_action(window.go_back_action()); go_back_button.on_context_menu_request = [this](auto& context_menu_event) { if (!m_history.can_go_back()) @@ -516,6 +518,11 @@ void Tab::content_filters_changed() m_web_content_view->set_content_filters({}); } +void Tab::proxy_mappings_changed() +{ + m_web_content_view->set_proxy_mappings(g_proxies, g_proxy_mappings); +} + void Tab::action_entered(GUI::Action& action) { m_statusbar->set_override_text(action.status_tip()); diff --git a/Userland/Applications/Browser/Tab.h b/Userland/Applications/Browser/Tab.h index 2e2ee353a7..a7bd6f33dc 100644 --- a/Userland/Applications/Browser/Tab.h +++ b/Userland/Applications/Browser/Tab.h @@ -51,6 +51,7 @@ public: void did_become_active(); void context_menu_requested(Gfx::IntPoint const& screen_position); void content_filters_changed(); + void proxy_mappings_changed(); void action_entered(GUI::Action&); void action_left(GUI::Action&); diff --git a/Userland/Applications/Browser/main.cpp b/Userland/Applications/Browser/main.cpp index 1842e32f1c..e963e312c3 100644 --- a/Userland/Applications/Browser/main.cpp +++ b/Userland/Applications/Browser/main.cpp @@ -31,6 +31,8 @@ String g_search_engine; String g_home_url; Vector<String> g_content_filters; bool g_content_filters_enabled { true }; +Vector<String> g_proxies; +HashMap<String, size_t> g_proxy_mappings; IconBag g_icon_bag; } @@ -96,6 +98,20 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) TRY(load_content_filters()); + for (auto& group : Config::list_groups("Browser")) { + if (!group.starts_with("Proxy:")) + continue; + + for (auto& key : Config::list_keys("Browser", group)) { + auto proxy_spec = group.substring_view(6); + auto existing_proxy = Browser::g_proxies.find(proxy_spec); + if (existing_proxy.is_end()) + Browser::g_proxies.append(proxy_spec); + + Browser::g_proxy_mappings.set(key, existing_proxy.index()); + } + } + URL first_url = Browser::url_from_user_input(Browser::g_home_url); if (specified_url) { if (Core::File::exists(specified_url)) { |