From 9a8d09589c4b7307454c284df1af079f9d11bbd9 Mon Sep 17 00:00:00 2001 From: Brian Clifton Date: Mon, 5 Oct 2020 22:45:51 -0700 Subject: [PATCH] Add Yandex as default for several Russian speaking locales. Fixes https://github.com/brave/brave-browser/issues/12327 --- ..._template_url_prepopulate_data_unittest.cc | 59 +++++++++++++ .../template_url_prepopulate_data.cc | 85 ++++++++++++++++--- .../brave_prepopulated_engines.cc | 18 +++- .../brave_prepopulated_engines.h | 2 + 4 files changed, 153 insertions(+), 11 deletions(-) diff --git a/chromium_src/components/search_engines/brave_template_url_prepopulate_data_unittest.cc b/chromium_src/components/search_engines/brave_template_url_prepopulate_data_unittest.cc index 14b64dbaf856..4f4bf5a49812 100644 --- a/chromium_src/components/search_engines/brave_template_url_prepopulate_data_unittest.cc +++ b/chromium_src/components/search_engines/brave_template_url_prepopulate_data_unittest.cc @@ -15,6 +15,7 @@ #include "base/stl_util.h" #include "base/strings/utf_string_conversions.h" #include "base/values.h" +#include "brave/common/pref_names.h" #include "brave/components/search_engines/brave_prepopulated_engines.h" #include "components/google/core/common/google_switches.h" #include "components/search_engines/search_engines_pref_names.h" @@ -60,10 +61,18 @@ class BraveTemplateURLPrepopulateDataTest : public testing::Test { public: void SetUp() override { TemplateURLPrepopulateData::RegisterProfilePrefs(prefs_.registry()); + // Real registration happens in `brave/browser/brave_profile_prefs.cc` + // Calling brave::RegisterProfilePrefs() causes some problems though + auto* registry = prefs_.registry(); + registry->RegisterIntegerPref( + kBraveDefaultSearchVersion, + TemplateURLPrepopulateData::kBraveCurrentDataVersion); } void CheckForCountry(char digit1, char digit2, const std::string& expected) { prefs_.SetInteger(kCountryIDAtInstall, digit1 << 8 | digit2); + prefs_.SetInteger(kBraveDefaultSearchVersion, + TemplateURLPrepopulateData::kBraveCurrentDataVersion); size_t default_index; std::vector> t_urls = TemplateURLPrepopulateData::GetPrepopulatedEngines(&prefs_, @@ -173,3 +182,53 @@ TEST_F(BraveTemplateURLPrepopulateDataTest, DefaultSearchProvidersForIreland) { CheckForCountry('I', 'E', "DuckDuckGo"); } + +TEST_F(BraveTemplateURLPrepopulateDataTest, + DefaultSearchProvidersForRepublicOfArmenia) { + CheckForCountry('A', 'M', "Yandex"); +} + +TEST_F(BraveTemplateURLPrepopulateDataTest, + DefaultSearchProvidersForRepublicOfAzerbaijan) { + CheckForCountry('A', 'Z', "Yandex"); +} + +TEST_F(BraveTemplateURLPrepopulateDataTest, + DefaultSearchProvidersForRepublicOfBelarus) { + CheckForCountry('B', 'Y', "Yandex"); +} + +TEST_F(BraveTemplateURLPrepopulateDataTest, + DefaultSearchProvidersForKyrgyzRepublic) { + CheckForCountry('K', 'G', "Yandex"); +} + +TEST_F(BraveTemplateURLPrepopulateDataTest, + DefaultSearchProvidersForRepublicOfKazakhstan) { + CheckForCountry('K', 'Z', "Yandex"); +} + +TEST_F(BraveTemplateURLPrepopulateDataTest, + DefaultSearchProvidersForRepublicOfMoldova) { + CheckForCountry('M', 'D', "Yandex"); +} + +TEST_F(BraveTemplateURLPrepopulateDataTest, + DefaultSearchProvidersForRussianFederation) { + CheckForCountry('R', 'U', "Yandex"); +} + +TEST_F(BraveTemplateURLPrepopulateDataTest, + DefaultSearchProvidersForRepublicOfTajikistan) { + CheckForCountry('T', 'J', "Yandex"); +} + +TEST_F(BraveTemplateURLPrepopulateDataTest, + DefaultSearchProvidersForTurkmenistan) { + CheckForCountry('T', 'M', "Yandex"); +} + +TEST_F(BraveTemplateURLPrepopulateDataTest, + DefaultSearchProvidersForRepublicOfUzbekistan) { + CheckForCountry('U', 'Z', "Yandex"); +} diff --git a/chromium_src/components/search_engines/template_url_prepopulate_data.cc b/chromium_src/components/search_engines/template_url_prepopulate_data.cc index 569fe19377a4..407dd6f81a91 100644 --- a/chromium_src/components/search_engines/template_url_prepopulate_data.cc +++ b/chromium_src/components/search_engines/template_url_prepopulate_data.cc @@ -60,6 +60,15 @@ const std::vector brave_engines_with_yahoo = { PREPOPULATED_ENGINE_ID_STARTPAGE, }; +const std::vector brave_engines_with_yandex = { + PREPOPULATED_ENGINE_ID_YANDEX, + PREPOPULATED_ENGINE_ID_GOOGLE, + PREPOPULATED_ENGINE_ID_DUCKDUCKGO, + PREPOPULATED_ENGINE_ID_QWANT, + PREPOPULATED_ENGINE_ID_BING, + PREPOPULATED_ENGINE_ID_STARTPAGE, +}; + const std::vector brave_engines_DE = { PREPOPULATED_ENGINE_ID_YAHOO, PREPOPULATED_ENGINE_ID_DUCKDUCKGO_DE, @@ -90,6 +99,10 @@ const std::vector brave_engines_AU_NZ_IE = { // that don't use the default list. const std::map*> default_engines_by_country_id_map = { + {country_codes::CountryCharsToCountryID('A', 'M'), + &brave_engines_with_yandex}, + {country_codes::CountryCharsToCountryID('A', 'Z'), + &brave_engines_with_yandex}, {country_codes::CountryCharsToCountryID('A', 'R'), &brave_engines_with_yahoo}, {country_codes::CountryCharsToCountryID('A', 'T'), @@ -98,6 +111,8 @@ const std::map*> &brave_engines_AU_NZ_IE}, {country_codes::CountryCharsToCountryID('B', 'R'), &brave_engines_with_yahoo}, + {country_codes::CountryCharsToCountryID('B', 'Y'), + &brave_engines_with_yandex}, {country_codes::CountryCharsToCountryID('C', 'A'), &brave_engines_with_yahoo}, {country_codes::CountryCharsToCountryID('C', 'H'), @@ -128,6 +143,12 @@ const std::map*> &brave_engines_with_yahoo}, {country_codes::CountryCharsToCountryID('I', 'T'), &brave_engines_with_yahoo}, + {country_codes::CountryCharsToCountryID('K', 'G'), + &brave_engines_with_yandex}, + {country_codes::CountryCharsToCountryID('K', 'Z'), + &brave_engines_with_yandex}, + {country_codes::CountryCharsToCountryID('M', 'D'), + &brave_engines_with_yandex}, {country_codes::CountryCharsToCountryID('M', 'X'), &brave_engines_with_yahoo}, {country_codes::CountryCharsToCountryID('M', 'Y'), @@ -142,16 +163,24 @@ const std::map*> &brave_engines_with_yahoo}, {country_codes::CountryCharsToCountryID('P', 'H'), &brave_engines_with_yahoo}, + {country_codes::CountryCharsToCountryID('R', 'U'), + &brave_engines_with_yandex}, {country_codes::CountryCharsToCountryID('S', 'E'), &brave_engines_with_yahoo}, {country_codes::CountryCharsToCountryID('S', 'G'), &brave_engines_with_yahoo}, {country_codes::CountryCharsToCountryID('T', 'H'), &brave_engines_with_yahoo}, + {country_codes::CountryCharsToCountryID('T', 'J'), + &brave_engines_with_yandex}, + {country_codes::CountryCharsToCountryID('T', 'M'), + &brave_engines_with_yandex}, {country_codes::CountryCharsToCountryID('T', 'W'), &brave_engines_with_yahoo}, {country_codes::CountryCharsToCountryID('U', 'S'), &brave_engines_with_yahoo}, + {country_codes::CountryCharsToCountryID('U', 'Z'), + &brave_engines_with_yandex}, {country_codes::CountryCharsToCountryID('V', 'E'), &brave_engines_with_yahoo}, {country_codes::CountryCharsToCountryID('V', 'N'), @@ -175,16 +204,52 @@ BravePrepopulatedEngineID GetDefaultSearchEngine(int country_id, int version) { {country_codes::CountryCharsToCountryID('N', 'Z'), PREPOPULATED_ENGINE_ID_DUCKDUCKGO_AU_NZ_IE}, }); - switch (version) { - case 6: - FALLTHROUGH; - default: { - auto it = content_v6->find(country_id); - if (it == content_v6->end()) { - return default_v6; - } - return it->second; - } break; + static const base::NoDestructor> + content_v8({ + {country_codes::CountryCharsToCountryID('A', 'M'), + PREPOPULATED_ENGINE_ID_YANDEX}, + {country_codes::CountryCharsToCountryID('A', 'Z'), + PREPOPULATED_ENGINE_ID_YANDEX}, + {country_codes::CountryCharsToCountryID('A', 'U'), + PREPOPULATED_ENGINE_ID_DUCKDUCKGO_AU_NZ_IE}, + {country_codes::CountryCharsToCountryID('B', 'Y'), + PREPOPULATED_ENGINE_ID_YANDEX}, + {country_codes::CountryCharsToCountryID('D', 'E'), + PREPOPULATED_ENGINE_ID_DUCKDUCKGO_DE}, + {country_codes::CountryCharsToCountryID('F', 'R'), + PREPOPULATED_ENGINE_ID_QWANT}, + {country_codes::CountryCharsToCountryID('I', 'E'), + PREPOPULATED_ENGINE_ID_DUCKDUCKGO_AU_NZ_IE}, + {country_codes::CountryCharsToCountryID('K', 'G'), + PREPOPULATED_ENGINE_ID_YANDEX}, + {country_codes::CountryCharsToCountryID('K', 'Z'), + PREPOPULATED_ENGINE_ID_YANDEX}, + {country_codes::CountryCharsToCountryID('M', 'D'), + PREPOPULATED_ENGINE_ID_YANDEX}, + {country_codes::CountryCharsToCountryID('N', 'Z'), + PREPOPULATED_ENGINE_ID_DUCKDUCKGO_AU_NZ_IE}, + {country_codes::CountryCharsToCountryID('R', 'U'), + PREPOPULATED_ENGINE_ID_YANDEX}, + {country_codes::CountryCharsToCountryID('T', 'J'), + PREPOPULATED_ENGINE_ID_YANDEX}, + {country_codes::CountryCharsToCountryID('T', 'M'), + PREPOPULATED_ENGINE_ID_YANDEX}, + {country_codes::CountryCharsToCountryID('U', 'Z'), + PREPOPULATED_ENGINE_ID_YANDEX}, + }); + if (version > 7) { + auto it = content_v8->find(country_id); + if (it == content_v8->end()) { + return default_v6; + } + return it->second; + } else { + auto it = content_v6->find(country_id); + if (it == content_v6->end()) { + return default_v6; + } + return it->second; } } diff --git a/components/search_engines/brave_prepopulated_engines.cc b/components/search_engines/brave_prepopulated_engines.cc index 4a42461ecb28..17d04a321c29 100644 --- a/components/search_engines/brave_prepopulated_engines.cc +++ b/components/search_engines/brave_prepopulated_engines.cc @@ -12,7 +12,7 @@ namespace TemplateURLPrepopulateData { // IMPORTANT! Make sure to bump this value if you make changes to the // engines below or add/remove engines. -const int kBraveCurrentDataVersion = 7; +const int kBraveCurrentDataVersion = 8; // DO NOT CHANGE THIS ONE. Used for backfilling kBraveDefaultSearchVersion. const int kBraveFirstTrackedDataVersion = 6; @@ -23,6 +23,7 @@ const std::map brave_engines_map = { {PREPOPULATED_ENGINE_ID_GOOGLE, &google}, {PREPOPULATED_ENGINE_ID_YAHOO, &brave_yahoo}, + {PREPOPULATED_ENGINE_ID_YANDEX, &brave_yandex}, {PREPOPULATED_ENGINE_ID_YAHOO_AR, &brave_yahoo_ar}, {PREPOPULATED_ENGINE_ID_YAHOO_AT, &brave_yahoo_at}, {PREPOPULATED_ENGINE_ID_YAHOO_AU, &brave_yahoo_au}, @@ -195,6 +196,21 @@ const PrepopulatedEngine startpage = { PREPOPULATED_ENGINE_ID_STARTPAGE, }; +const PrepopulatedEngine brave_yandex = + ModifyEngineParams(yandex_com, + L"Yandex", + NULL, + "https://yandex.ru/search/?clid=" +#if defined(OS_ANDROID) + "2423859" +#else + "2353835" +#endif + "&text={searchTerms}", + "https://suggest.yandex.com/suggest-ff.cgi?" + "part={searchTerms}&uil=en&v=3&sn=5&srv=brave_desktop", + PREPOPULATED_ENGINE_ID_YANDEX); + #define kBraveYahooName L"Yahoo" #define kBraveYahooKeyword L":y" #define BRAVE_YAHOO_SEARCH_URL(PREFIX) \ diff --git a/components/search_engines/brave_prepopulated_engines.h b/components/search_engines/brave_prepopulated_engines.h index 85c5f1cdd5b7..140bb0c63655 100644 --- a/components/search_engines/brave_prepopulated_engines.h +++ b/components/search_engines/brave_prepopulated_engines.h @@ -30,6 +30,7 @@ enum BravePrepopulatedEngineID : unsigned int { // These engine IDs are already defined in prepopulated_engines.json PREPOPULATED_ENGINE_ID_GOOGLE = 1, PREPOPULATED_ENGINE_ID_BING = 3, + PREPOPULATED_ENGINE_ID_YANDEX = 15, // These engine IDs are not defined in Chromium BRAVE_PREPOPULATED_ENGINES_START = 500, PREPOPULATED_ENGINE_ID_AMAZON = 500, // No longer in defaults (2/2019). @@ -96,6 +97,7 @@ extern const PrepopulatedEngine duckduckgo_lite; #endif extern const PrepopulatedEngine qwant; extern const PrepopulatedEngine startpage; +extern const PrepopulatedEngine brave_yandex; // Yahoo has unique URLs per region extern const PrepopulatedEngine brave_yahoo;