Skip to content

Commit

Permalink
[waffle]Stop using favicon loader to load search engine icons
Browse files Browse the repository at this point in the history
Use the icons that are supplied by the search engine providers and
that are included in the binary.

We use the favicon service to load the icons for custom search
engines.

Screenshots: http://b/304234626#comment2
Fixed: b:304234626
Change-Id: I09dbc03da652ec6d0db02cd4c133762d1f4351f4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4966784
Commit-Queue: John Lee <johntlee@chromium.org>
Auto-Submit: Jack Yammine <jyammine@google.com>
Reviewed-by: Nicolas Dossou-Gbété <dgn@chromium.org>
Reviewed-by: John Lee <johntlee@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1216264}
  • Loading branch information
Jack Yammine authored and Chromium LUCI CQ committed Oct 27, 2023
1 parent 7624416 commit 590d7f8
Show file tree
Hide file tree
Showing 18 changed files with 178 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@

<div class="list-item cr-row" role="row">
<span role="cell" id="name-column">
<site-favicon
favicon-url="[[engine.iconURL]]"
url="[[engine.url]]">
<site-favicon favicon-url="[[engine.iconURL]]" url="[[engine.url]]"
icon-path="[[engine.iconPath]]">
</site-favicon>
<div>[[engine.displayName]]</div>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export class SettingsSearchEngineEntryElement extends PolymerElement {

showQueryUrl: {type: Boolean, value: false, reflectToAttribute: true},


isDefault: {
reflectToAttribute: true,
type: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface SearchEngine {
displayName: string;
extension?: {id: string, name: string, canBeDisabled: boolean, icon: string};
iconURL?: string;
iconPath: string;
id: number;
isOmniboxExtension: boolean;
keyword: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@
align-items: center;
display: flex;
flex-direction: row;
gap: 12px;
gap: 16px;
}

site-favicon {
--site-favicon-border-radius: 4px;
--site-favicon-height: 24px;
--site-favicon-width: 24px;
}

#setAsDefaultButton {
Expand Down Expand Up @@ -56,7 +62,8 @@
<template is="dom-repeat" items="[[searchEngines]]">
<cr-radio-button class="label-first" name="[[item.id]]">
<div class="search-engine">
<site-favicon favicon-url="[[item.iconURL]]" url="[[item.url]]">
<site-favicon favicon-url="[[item.iconURL]]" url="[[item.url]]"
icon-path="[[item.iconPath]]">
</site-favicon>
[[item.name]]
</div>
Expand Down
21 changes: 11 additions & 10 deletions chrome/browser/resources/settings/search_page/search_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
min-height: var(--cr-section-min-height);
}

.cr-row.search-engine {
.default-search-engine .cr-row {
--cr-section-min-height: 55px;
gap: 12px;
padding: 0;
}

Expand All @@ -17,11 +19,10 @@
margin-inline-end: auto;
}

.search-engine {
align-items: center;
display: flex;
flex-direction: row;
gap: 12px;
site-favicon {
--site-favicon-border-radius: 4px;
--site-favicon-height: 24px;
--site-favicon-width: 24px;
}

</style>
Expand All @@ -47,10 +48,10 @@
prefs.default_search_provider_data.template_url_data]]">
</cr-policy-pref-indicator>
</template>
<div class="cr-row first search-engine">
<site-favicon
favicon-url="[[defaultSearchEngine_.iconURL]]"
url="[[defaultSearchEngine_.url]]">
<div class="cr-row first">
<site-favicon favicon-url="[[defaultSearchEngine_.iconURL]]"
url="[[defaultSearchEngine_.url]]"
icon-path="[[defaultSearchEngine_.iconPath]]">
</site-favicon>
<div class="search-engine-name">[[defaultSearchEngine_.name]]</div>
<cr-button id="openDialogButton"
Expand Down
17 changes: 3 additions & 14 deletions chrome/browser/resources/settings/search_page/search_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,7 @@ export class SettingsSearchPageElement extends SettingsSearchPageElementBase {
/**
* List of search engines available.
*/
searchEngines_: {
type: Array,
value() {
return [];
},
},
searchEngines_: Array,

// Whether the `kSearchEngineChoiceSettingsUi` feature is enabled or not.
searchEngineChoiceSettingsUi_: {
Expand All @@ -66,9 +61,6 @@ export class SettingsSearchPageElement extends SettingsSearchPageElementBase {
},

// The selected default search engine.
// This depends on `searchEngines_` because we want to update the
// `defaultSearchEngine_` variable every time the search engine list is
// updated.
defaultSearchEngine_: {
type: Object,
computed: 'computeDefaultSearchEngine_(searchEngines_)',
Expand Down Expand Up @@ -143,15 +135,12 @@ export class SettingsSearchPageElement extends SettingsSearchPageElementBase {
return pref.enforcement === chrome.settingsPrivate.Enforcement.ENFORCED;
}

private computeDefaultSearchEngine_(): SearchEngine|null {
private computeDefaultSearchEngine_() {
if (!this.searchEngines_.length || !this.searchEngineChoiceSettingsUi_) {
return null;
}

const defaultSearchEngine =
this.searchEngines_.find(searchEngine => searchEngine.default);
assert(defaultSearchEngine);
return defaultSearchEngine;
return this.searchEngines_.find(engine => engine.default)!;
}

private onOpenDialogButtonClick_() {
Expand Down
14 changes: 5 additions & 9 deletions chrome/browser/resources/settings/site_favicon.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
<style>
:host {
--site-favicon-height: 16px;
--site-favicon-width: 16px;
}

#favicon {
background-repeat: no-repeat;
background-size: contain;
border-radius: inherit;
border-radius: var(--site-favicon-border-radius, inherit);
display: block;
height: var(--site-favicon-height);
width: var(--site-favicon-width);
height: var(--site-favicon-height, 16px);
width: var(--site-favicon-width, 16px);
}
</style>
<div
id="favicon"
style="background-image: [[getBackgroundImage_(faviconUrl, url)]]">
style="background-image:
[[getBackgroundImage_(faviconUrl, url, iconPath)]]">
</div>
8 changes: 7 additions & 1 deletion chrome/browser/resources/settings/site_favicon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,21 @@ export class SiteFaviconElement extends PolymerElement {
return {
faviconUrl: String,
url: String,
// The icon's local path. We don't need to fetch the icon from the url if
// the path is not empty.
iconPath: String,
};
}

faviconUrl: string;
url: string;
iconPath: string;

private getBackgroundImage_() {
let backgroundImage = getFavicon('');
if (this.faviconUrl) {
if (this.iconPath) {
backgroundImage = 'url(' + this.iconPath + ')';
} else if (this.faviconUrl) {
const url = this.ensureUrlHasScheme_(this.faviconUrl);
backgroundImage = getFavicon(url);
} else if (this.url) {
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,7 @@ static_library("ui") {
"webui/realbox/realbox_handler.h",
"webui/sanitized_image_source.cc",
"webui/sanitized_image_source.h",
"webui/search_engine_choice/generated_icon_utils.cc",
"webui/search_engine_choice/icon_utils.cc",
"webui/search_engine_choice/icon_utils.h",
"webui/settings/about_handler.cc",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/webui/search_engine_choice/icon_utils.h"

#include "base/check_op.h"
#include "build/branding_buildflags.h"
#include "components/grit/components_scaled_resources.h"
#include "content/public/browser/web_ui_data_source.h"

// This code is generated using `generate_search_engine_icons.py`. Don't modify
// it manually.
void AddGeneratedIconResources(content::WebUIDataSource* source,
const std::string& directory) {
CHECK(source);
CHECK_EQ(directory.back(), '/');
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
source->AddResourcePath(directory + "google_com.png", IDR_GOOGLE_COM_PNG);
#endif
source->AddResourcePath(directory + "baidu_com.png", IDR_BAIDU_COM_PNG);
source->AddResourcePath(directory + "bing_com.png", IDR_BING_COM_PNG);
source->AddResourcePath(directory + "search_brave_com.png",
IDR_SEARCH_BRAVE_COM_PNG);
source->AddResourcePath(directory + "coccoc_com.png", IDR_COCCOC_COM_PNG);
source->AddResourcePath(directory + "daum_net.png", IDR_DAUM_NET_PNG);
source->AddResourcePath(directory + "duckduckgo_com.png",
IDR_DUCKDUCKGO_COM_PNG);
source->AddResourcePath(directory + "ecosia_org.png", IDR_ECOSIA_ORG_PNG);
source->AddResourcePath(directory + "karmasearch_org.png",
IDR_KARMASEARCH_ORG_PNG);
source->AddResourcePath(directory + "lilo_org.png", IDR_LILO_ORG_PNG);
source->AddResourcePath(directory + "mail_ru.png", IDR_MAIL_RU_PNG);
source->AddResourcePath(directory + "mojeek_com.png", IDR_MOJEEK_COM_PNG);
source->AddResourcePath(directory + "naver_com.png", IDR_NAVER_COM_PNG);
source->AddResourcePath(directory + "nona_de.png", IDR_NONA_DE_PNG);
source->AddResourcePath(directory + "panda_search_org.png",
IDR_PANDA_SEARCH_ORG_PNG);
source->AddResourcePath(directory + "quendu_com.png", IDR_QUENDU_COM_PNG);
source->AddResourcePath(directory + "qwant_com.png", IDR_QWANT_COM_PNG);
source->AddResourcePath(directory + "seznam_cz.png", IDR_SEZNAM_CZ_PNG);
source->AddResourcePath(directory + "seznam_sk.png", IDR_SEZNAM_SK_PNG);
source->AddResourcePath(directory + "so_com.png", IDR_SO_COM_PNG);
source->AddResourcePath(directory + "sogou_com.png", IDR_SOGOU_COM_PNG);
source->AddResourcePath(directory + "yahoo_com.png", IDR_YAHOO_COM_PNG);
source->AddResourcePath(directory + "ar_yahoo_com.png", IDR_AR_YAHOO_COM_PNG);
source->AddResourcePath(directory + "at_yahoo_com.png", IDR_AT_YAHOO_COM_PNG);
source->AddResourcePath(directory + "au_yahoo_com.png", IDR_AU_YAHOO_COM_PNG);
source->AddResourcePath(directory + "br_yahoo_com.png", IDR_BR_YAHOO_COM_PNG);
source->AddResourcePath(directory + "ca_yahoo_com.png", IDR_CA_YAHOO_COM_PNG);
source->AddResourcePath(directory + "ch_yahoo_com.png", IDR_CH_YAHOO_COM_PNG);
source->AddResourcePath(directory + "cl_yahoo_com.png", IDR_CL_YAHOO_COM_PNG);
source->AddResourcePath(directory + "co_yahoo_com.png", IDR_CO_YAHOO_COM_PNG);
source->AddResourcePath(directory + "de_yahoo_com.png", IDR_DE_YAHOO_COM_PNG);
source->AddResourcePath(directory + "dk_yahoo_com.png", IDR_DK_YAHOO_COM_PNG);
source->AddResourcePath(directory + "es_yahoo_com.png", IDR_ES_YAHOO_COM_PNG);
source->AddResourcePath(directory + "fi_yahoo_com.png", IDR_FI_YAHOO_COM_PNG);
source->AddResourcePath(directory + "fr_yahoo_com.png", IDR_FR_YAHOO_COM_PNG);
source->AddResourcePath(directory + "hk_yahoo_com.png", IDR_HK_YAHOO_COM_PNG);
source->AddResourcePath(directory + "id_yahoo_com.png", IDR_ID_YAHOO_COM_PNG);
source->AddResourcePath(directory + "in_yahoo_com.png", IDR_IN_YAHOO_COM_PNG);
source->AddResourcePath(directory + "yahoo_co_jp.png", IDR_YAHOO_CO_JP_PNG);
source->AddResourcePath(directory + "mx_yahoo_com.png", IDR_MX_YAHOO_COM_PNG);
source->AddResourcePath(directory + "malaysia_yahoo_com.png",
IDR_MALAYSIA_YAHOO_COM_PNG);
source->AddResourcePath(directory + "nl_yahoo_com.png", IDR_NL_YAHOO_COM_PNG);
source->AddResourcePath(directory + "nz_yahoo_com.png", IDR_NZ_YAHOO_COM_PNG);
source->AddResourcePath(directory + "pe_yahoo_com.png", IDR_PE_YAHOO_COM_PNG);
source->AddResourcePath(directory + "ph_yahoo_com.png", IDR_PH_YAHOO_COM_PNG);
source->AddResourcePath(directory + "se_yahoo_com.png", IDR_SE_YAHOO_COM_PNG);
source->AddResourcePath(directory + "sg_yahoo_com.png", IDR_SG_YAHOO_COM_PNG);
source->AddResourcePath(directory + "th_yahoo_com.png", IDR_TH_YAHOO_COM_PNG);
source->AddResourcePath(directory + "tr_yahoo_com.png", IDR_TR_YAHOO_COM_PNG);
source->AddResourcePath(directory + "tw_yahoo_com.png", IDR_TW_YAHOO_COM_PNG);
source->AddResourcePath(directory + "uk_yahoo_com.png", IDR_UK_YAHOO_COM_PNG);
source->AddResourcePath(directory + "yandex_by.png", IDR_YANDEX_BY_PNG);
source->AddResourcePath(directory + "yandex_com.png", IDR_YANDEX_COM_PNG);
source->AddResourcePath(directory + "yandex_kz.png", IDR_YANDEX_KZ_PNG);
source->AddResourcePath(directory + "yandex_ru.png", IDR_YANDEX_RU_PNG);
source->AddResourcePath(directory + "yandex_com_tr.png",
IDR_YANDEX_COM_TR_PNG);
source->AddResourcePath(directory + "yep_com.png", IDR_YEP_COM_PNG);
source->AddResourcePath(directory + "info_com.png", IDR_INFO_COM_PNG);
source->AddResourcePath(directory + "metager_de.png", IDR_METAGER_DE_PNG);
source->AddResourcePath(directory + "oceanhero_today.png",
IDR_OCEANHERO_TODAY_PNG);
source->AddResourcePath(directory + "privacywall_org.png",
IDR_PRIVACYWALL_ORG_PNG);
}
94 changes: 13 additions & 81 deletions chrome/browser/ui/webui/search_engine_choice/icon_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,86 +4,18 @@

#include "chrome/browser/ui/webui/search_engine_choice/icon_utils.h"

#include "base/check_op.h"
#include "build/branding_buildflags.h"
#include "components/grit/components_scaled_resources.h"
#include "content/public/browser/web_ui_data_source.h"
#include <algorithm>

// This code is generated using `generate_search_engine_icons.py`. Don't modify
// it manually.
void AddGeneratedIconResources(content::WebUIDataSource* source,
const std::string& directory) {
CHECK(source);
CHECK_EQ(directory.back(), '/');
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
source->AddResourcePath(directory + "google_com.png", IDR_GOOGLE_COM_PNG);
#endif
source->AddResourcePath(directory + "baidu_com.png", IDR_BAIDU_COM_PNG);
source->AddResourcePath(directory + "bing_com.png", IDR_BING_COM_PNG);
source->AddResourcePath(directory + "search_brave_com.png",
IDR_SEARCH_BRAVE_COM_PNG);
source->AddResourcePath(directory + "coccoc_com.png", IDR_COCCOC_COM_PNG);
source->AddResourcePath(directory + "daum_net.png", IDR_DAUM_NET_PNG);
source->AddResourcePath(directory + "duckduckgo_com.png",
IDR_DUCKDUCKGO_COM_PNG);
source->AddResourcePath(directory + "ecosia_org.png", IDR_ECOSIA_ORG_PNG);
source->AddResourcePath(directory + "karmasearch_org.png",
IDR_KARMASEARCH_ORG_PNG);
source->AddResourcePath(directory + "lilo_org.png", IDR_LILO_ORG_PNG);
source->AddResourcePath(directory + "mail_ru.png", IDR_MAIL_RU_PNG);
source->AddResourcePath(directory + "mojeek_com.png", IDR_MOJEEK_COM_PNG);
source->AddResourcePath(directory + "naver_com.png", IDR_NAVER_COM_PNG);
source->AddResourcePath(directory + "nona_de.png", IDR_NONA_DE_PNG);
source->AddResourcePath(directory + "panda_search_org.png",
IDR_PANDA_SEARCH_ORG_PNG);
source->AddResourcePath(directory + "quendu_com.png", IDR_QUENDU_COM_PNG);
source->AddResourcePath(directory + "qwant_com.png", IDR_QWANT_COM_PNG);
source->AddResourcePath(directory + "seznam_cz.png", IDR_SEZNAM_CZ_PNG);
source->AddResourcePath(directory + "seznam_sk.png", IDR_SEZNAM_SK_PNG);
source->AddResourcePath(directory + "so_com.png", IDR_SO_COM_PNG);
source->AddResourcePath(directory + "sogou_com.png", IDR_SOGOU_COM_PNG);
source->AddResourcePath(directory + "yahoo_com.png", IDR_YAHOO_COM_PNG);
source->AddResourcePath(directory + "ar_yahoo_com.png", IDR_AR_YAHOO_COM_PNG);
source->AddResourcePath(directory + "at_yahoo_com.png", IDR_AT_YAHOO_COM_PNG);
source->AddResourcePath(directory + "au_yahoo_com.png", IDR_AU_YAHOO_COM_PNG);
source->AddResourcePath(directory + "br_yahoo_com.png", IDR_BR_YAHOO_COM_PNG);
source->AddResourcePath(directory + "ca_yahoo_com.png", IDR_CA_YAHOO_COM_PNG);
source->AddResourcePath(directory + "ch_yahoo_com.png", IDR_CH_YAHOO_COM_PNG);
source->AddResourcePath(directory + "cl_yahoo_com.png", IDR_CL_YAHOO_COM_PNG);
source->AddResourcePath(directory + "co_yahoo_com.png", IDR_CO_YAHOO_COM_PNG);
source->AddResourcePath(directory + "de_yahoo_com.png", IDR_DE_YAHOO_COM_PNG);
source->AddResourcePath(directory + "dk_yahoo_com.png", IDR_DK_YAHOO_COM_PNG);
source->AddResourcePath(directory + "es_yahoo_com.png", IDR_ES_YAHOO_COM_PNG);
source->AddResourcePath(directory + "fi_yahoo_com.png", IDR_FI_YAHOO_COM_PNG);
source->AddResourcePath(directory + "fr_yahoo_com.png", IDR_FR_YAHOO_COM_PNG);
source->AddResourcePath(directory + "hk_yahoo_com.png", IDR_HK_YAHOO_COM_PNG);
source->AddResourcePath(directory + "id_yahoo_com.png", IDR_ID_YAHOO_COM_PNG);
source->AddResourcePath(directory + "in_yahoo_com.png", IDR_IN_YAHOO_COM_PNG);
source->AddResourcePath(directory + "yahoo_co_jp.png", IDR_YAHOO_CO_JP_PNG);
source->AddResourcePath(directory + "mx_yahoo_com.png", IDR_MX_YAHOO_COM_PNG);
source->AddResourcePath(directory + "malaysia_yahoo_com.png",
IDR_MALAYSIA_YAHOO_COM_PNG);
source->AddResourcePath(directory + "nl_yahoo_com.png", IDR_NL_YAHOO_COM_PNG);
source->AddResourcePath(directory + "nz_yahoo_com.png", IDR_NZ_YAHOO_COM_PNG);
source->AddResourcePath(directory + "pe_yahoo_com.png", IDR_PE_YAHOO_COM_PNG);
source->AddResourcePath(directory + "ph_yahoo_com.png", IDR_PH_YAHOO_COM_PNG);
source->AddResourcePath(directory + "se_yahoo_com.png", IDR_SE_YAHOO_COM_PNG);
source->AddResourcePath(directory + "sg_yahoo_com.png", IDR_SG_YAHOO_COM_PNG);
source->AddResourcePath(directory + "th_yahoo_com.png", IDR_TH_YAHOO_COM_PNG);
source->AddResourcePath(directory + "tr_yahoo_com.png", IDR_TR_YAHOO_COM_PNG);
source->AddResourcePath(directory + "tw_yahoo_com.png", IDR_TW_YAHOO_COM_PNG);
source->AddResourcePath(directory + "uk_yahoo_com.png", IDR_UK_YAHOO_COM_PNG);
source->AddResourcePath(directory + "yandex_by.png", IDR_YANDEX_BY_PNG);
source->AddResourcePath(directory + "yandex_com.png", IDR_YANDEX_COM_PNG);
source->AddResourcePath(directory + "yandex_kz.png", IDR_YANDEX_KZ_PNG);
source->AddResourcePath(directory + "yandex_ru.png", IDR_YANDEX_RU_PNG);
source->AddResourcePath(directory + "yandex_com_tr.png",
IDR_YANDEX_COM_TR_PNG);
source->AddResourcePath(directory + "yep_com.png", IDR_YEP_COM_PNG);
source->AddResourcePath(directory + "info_com.png", IDR_INFO_COM_PNG);
source->AddResourcePath(directory + "metager_de.png", IDR_METAGER_DE_PNG);
source->AddResourcePath(directory + "oceanhero_today.png",
IDR_OCEANHERO_TODAY_PNG);
source->AddResourcePath(directory + "privacywall_org.png",
IDR_PRIVACYWALL_ORG_PNG);
#include "base/check.h"

std::u16string GetGeneratedIconPath(
const std::u16string& keyword,
const std::u16string& parent_directory_path) {
CHECK(parent_directory_path.back() == '/');

std::u16string engine_keyword = keyword;
std::replace(engine_keyword.begin(), engine_keyword.end(), '.', '_');
std::replace(engine_keyword.begin(), engine_keyword.end(), '-', '_');

return parent_directory_path + engine_keyword + u".png";
}
9 changes: 9 additions & 0 deletions chrome/browser/ui/webui/search_engine_choice/icon_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,13 @@ class WebUIDataSource;
void AddGeneratedIconResources(content::WebUIDataSource* source,
const std::string& directory);

// Returns the path of the icon generated by AddGeneratedIconResources.
// The path is of the format 'keyword'.png while replacing all the '.' and
// '-' in 'keyword' by '_'. `keyword` is the search engine keyword.
// `parent_directory_path` is the path where the icons should be found and
// should always end with '/'.
std::u16string GetGeneratedIconPath(
const std::u16string& keyword,
const std::u16string& parent_directory_path);

#endif // CHROME_BROWSER_UI_WEBUI_SEARCH_ENGINE_CHOICE_ICON_UTILS_H_

0 comments on commit 590d7f8

Please sign in to comment.