Skip to content

Truly independent web browser

LibWebView: Keep a row's favicon and title when a bookmark takes over

Andreas Klinga9737ee5256d
diff --git a/Documentation/Omnibox.md b/Documentation/Omnibox.md
index 3b34d54cda9..45e82bcc575 100644
--- a/Documentation/Omnibox.md
+++ b/Documentation/Omnibox.md
@@ -92,7 +92,7 @@ whose title and favicon are kept.
When history, bookmark, and adaptive candidates identify the same URL, their score components and
eligibility flags are combined. Bookmark presentation is preferred so its title and favicon remain
-visible.
+visible. A bookmark without a title or favicon takes those of the other candidate.
When rows for the root of the same origin are folded into one, such as `example.com` and
`www.example.com`, the row that is kept takes the favicon and title of a folded row if it has none.
diff --git a/Libraries/LibWebView/AutocompleteMuxer.cpp b/Libraries/LibWebView/AutocompleteMuxer.cpp
index d7110ba7611..6f68aca8e1a 100644
--- a/Libraries/LibWebView/AutocompleteMuxer.cpp
+++ b/Libraries/LibWebView/AutocompleteMuxer.cpp
@@ -301,13 +301,6 @@ static void merge_suggestion(AutocompleteSuggestion& existing, SuggestionDestina
if (suggestion_has_preferred_presentation) {
swap(existing, suggestion);
swap(existing_destination, destination);
- } else {
- if (!existing.title.has_value() && suggestion.title.has_value())
- existing.title = move(suggestion.title);
- if (!existing.subtitle.has_value() && suggestion.subtitle.has_value())
- existing.subtitle = move(suggestion.subtitle);
- if (!existing.favicon_png.has_value() && suggestion.favicon_png.has_value())
- existing.favicon_png = move(suggestion.favicon_png);
}
// NB: The addresses of the two rows may differ by a trailing slash or tracking parameters. The row goes to the one
@@ -319,6 +312,15 @@ static void merge_suggestion(AutocompleteSuggestion& existing, SuggestionDestina
existing_destination = move(destination);
}
+ // NB: The row whose presentation is kept may lack parts of it, such as a bookmark saved without a favicon, so it
+ // takes those of the other row.
+ if (!existing.title.has_value() && suggestion.title.has_value())
+ existing.title = move(suggestion.title);
+ if (!existing.subtitle.has_value() && suggestion.subtitle.has_value())
+ existing.subtitle = move(suggestion.subtitle);
+ if (!existing.favicon_png.has_value() && suggestion.favicon_png.has_value())
+ existing.favicon_png = move(suggestion.favicon_png);
+
existing.is_verbatim = is_verbatim;
existing.can_be_automatically_selected = can_be_automatically_selected;
existing.can_be_inline_completed = can_be_inline_completed;
diff --git a/Tests/LibWebView/TestAutocompleteMuxer.cpp b/Tests/LibWebView/TestAutocompleteMuxer.cpp
index b5b986948cd..06e95488045 100644
--- a/Tests/LibWebView/TestAutocompleteMuxer.cpp
+++ b/Tests/LibWebView/TestAutocompleteMuxer.cpp
@@ -415,6 +415,25 @@ TEST_CASE(a_results_page_shows_as_its_search_only_for_a_query_that_starts_a_word
EXPECT_EQ(row_for("bersee"sv, "https://duckduckgo.com/?q=%C3%BCbersee"sv).source, WebView::AutocompleteSuggestionSource::History);
}
+TEST_CASE(a_bookmark_without_a_favicon_or_title_keeps_those_of_the_history_row)
+{
+ auto visited = history("https://example.com/"sv, 900);
+ visited.title = "Example"_string;
+ visited.favicon_png = MUST(ByteBuffer::copy("favicon"sv.bytes()));
+
+ auto results = WebView::mux_autocomplete_suggestions(
+ "example"sv,
+ {},
+ { move(visited), bookmark("https://example.com/"sv, 925) },
+ {},
+ 8);
+
+ EXPECT_EQ(results.size(), 1u);
+ EXPECT_EQ(results[0].source, WebView::AutocompleteSuggestionSource::Bookmark);
+ EXPECT_EQ(results[0].title, "Example"sv);
+ EXPECT(results[0].favicon_png.has_value());
+}
+
TEST_CASE(http_and_https_destinations_are_not_deduplicated)
{
auto results = WebView::mux_autocomplete_suggestions(