diff --git a/Userland/Applications/Browser/CMakeLists.txt b/Userland/Applications/Browser/CMakeLists.txt index 69a5a1bf753..b9a7b0def7f 100644 --- a/Userland/Applications/Browser/CMakeLists.txt +++ b/Userland/Applications/Browser/CMakeLists.txt @@ -41,5 +41,5 @@ set(GENERATED_SOURCES ) serenity_app(Browser ICON app-browser) -target_link_libraries(Browser PRIVATE LibCore LibFileSystem LibWebView LibWeb LibProtocol LibGUI LibDesktop LibConfig LibGfx LibIPC LibJS LibLocale LibMain LibSyntax LibSQL) +target_link_libraries(Browser PRIVATE LibCore LibFileSystem LibWebView LibWeb LibProtocol LibPublicSuffix LibGUI LibDesktop LibConfig LibGfx LibIPC LibJS LibLocale LibMain LibSyntax LibSQL) link_with_locale_data(Browser) diff --git a/Userland/Applications/Browser/Tab.cpp b/Userland/Applications/Browser/Tab.cpp index 3aa09536a40..d06dc3e1136 100644 --- a/Userland/Applications/Browser/Tab.cpp +++ b/Userland/Applications/Browser/Tab.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -51,9 +52,6 @@ Tab::~Tab() URL url_from_user_input(DeprecatedString const& input) { - if (input.starts_with('?') && !g_search_engine.is_empty()) - return URL(g_search_engine.replace("{}"sv, URL::percent_encode(input.substring_view(1)), ReplaceMode::FirstOnly)); - URL url_with_http_schema = URL(DeprecatedString::formatted("https://{}", input)); if (url_with_http_schema.is_valid() && url_with_http_schema.port().has_value()) return url_with_http_schema; @@ -169,7 +167,7 @@ Tab::Tab(BrowserWindow& window) toolbar.add_action(window.reload_action()); m_location_box = toolbar.add(); - m_location_box->set_placeholder("Address"sv); + m_location_box->set_placeholder("Search or enter address"sv); m_location_box->on_return_pressed = [this] { auto url = url_from_location_bar(); @@ -647,11 +645,6 @@ void Tab::update_reset_zoom_button() Optional Tab::url_from_location_bar(MayAppendTLD may_append_tld) { - if (m_location_box->text().starts_with('?') && g_search_engine.is_empty()) { - GUI::MessageBox::show(&this->window(), "Select a search engine in the Settings menu before searching."sv, "No search engine selected"sv, GUI::MessageBox::Type::Information); - return {}; - } - DeprecatedString text = m_location_box->text(); StringBuilder builder; @@ -664,8 +657,17 @@ Optional Tab::url_from_location_bar(MayAppendTLD may_append_tld) } auto final_text = builder.to_deprecated_string(); - auto url = url_from_user_input(final_text); - return url; + auto error_or_absolute_url = PublicSuffix::absolute_url(final_text); + if (error_or_absolute_url.is_error()) { + if (g_search_engine.is_empty()) { + GUI::MessageBox::show(&this->window(), "Select a search engine in the Settings menu before searching."sv, "No search engine selected"sv, GUI::MessageBox::Type::Information); + return {}; + } + + return URL(g_search_engine.replace("{}"sv, URL::percent_encode(final_text), ReplaceMode::FirstOnly)); + } + + return URL(error_or_absolute_url.release_value()); } void Tab::load(const URL& url, LoadType load_type) diff --git a/Userland/Applications/BrowserSettings/BrowserSettingsWidget.gml b/Userland/Applications/BrowserSettings/BrowserSettingsWidget.gml index 71099ed048c..3823dc4d961 100644 --- a/Userland/Applications/BrowserSettings/BrowserSettingsWidget.gml +++ b/Userland/Applications/BrowserSettings/BrowserSettingsWidget.gml @@ -129,7 +129,7 @@ } @GUI::CheckBox { - text: "Search using '?' in the URL box" + text: "Search in the URL box" name: "enable_search_engine_checkbox" } } diff --git a/Userland/Applications/BrowserSettings/Defaults.h b/Userland/Applications/BrowserSettings/Defaults.h index 38a92790e3c..8e3046ea9cf 100644 --- a/Userland/Applications/BrowserSettings/Defaults.h +++ b/Userland/Applications/BrowserSettings/Defaults.h @@ -12,7 +12,7 @@ namespace Browser { static constexpr StringView default_homepage_url = "file:///res/html/misc/welcome.html"sv; static constexpr StringView default_new_tab_url = "file:///res/html/misc/new-tab.html"sv; -static constexpr StringView default_search_engine = ""sv; +static constexpr StringView default_search_engine = "https://www.google.com/search?q={}"sv; static constexpr StringView default_color_scheme = "auto"sv; static constexpr bool default_enable_content_filters = true; static constexpr bool default_show_bookmarks_bar = true;