This source file includes following definitions.
- CountryCharsToCountryID
- CountryCharsToCountryIDWithUpdate
- GeoIDToCountryID
- GetCurrentCountryID
- GetCurrentCountryID
- GetCurrentCountryID
- GetCurrentCountryID
- GetCountryIDFromPrefs
- GetPrepopulationSetFromCountryID
- MakePrepopulatedTemplateURL
- GetPrepopulatedTemplateFromPrefs
- MakePrepopulatedTemplateURLFromPrepopulateEngine
- SameDomain
- InitCountryCode
- RegisterProfilePrefs
- GetDataVersion
- GetPrepopulatedEngines
- ClearPrepopulatedEnginesInPrefs
- GetPrepopulatedDefaultSearch
- GetEngineType
- GetEngineType
- GetLogoURL
#include "chrome/browser/search_engines/template_url_prepopulate_data.h"
#if defined(OS_POSIX) && !defined(OS_MACOSX)
#include <locale.h>
#endif
#include "base/logging.h"
#include "base/prefs/pref_service.h"
#include "base/stl_util.h"
#include "base/strings/string16.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/google/google_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/prepopulated_engines.h"
#include "chrome/browser/search_engines/search_terms_data.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/common/pref_names.h"
#include "components/user_prefs/pref_registry_syncable.h"
#include "content/public/browser/browser_thread.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "ui/base/l10n/l10n_util.h"
#include "url/gurl.h"
#if defined(OS_WIN)
#undef IN
#elif defined(OS_MACOSX)
#include "base/mac/scoped_cftyperef.h"
#endif
namespace TemplateURLPrepopulateData {
namespace {
const PrepopulatedEngine* engines_default[] =
{ &google, &bing, &yahoo, };
const PrepopulatedEngine* engines_AE[] =
{ &google, &yahoo_maktoob, &bing_ar_XA, &bing_en_XA, };
const PrepopulatedEngine* engines_AL[] =
{ &google, &yahoo, &bing_en_XA, &bing_ar_XA, };
const PrepopulatedEngine* engines_AR[] =
{ &google, &bing_es_AR, &yahoo_ar, };
const PrepopulatedEngine* engines_AT[] =
{ &google, &bing_de_AT, &yahoo_at, };
const PrepopulatedEngine* engines_AU[] =
{ &google, &bing_en_AU, &yahoo_au, };
const PrepopulatedEngine* engines_BA[] =
{ &google, &yahoo, &bing, };
const PrepopulatedEngine* engines_BE[] =
{ &google, &bing_nl_BE, &bing_fr_BE, &yahoo_be, &yahoo_fr_be, };
const PrepopulatedEngine* engines_BG[] =
{ &google, &bing, &ask, };
const PrepopulatedEngine* engines_BH[] =
{ &google, &yahoo_maktoob, &bing_en_XA, &bing_ar_XA, };
const PrepopulatedEngine* engines_BI[] =
{ &google, &yahoo, &bing, };
const PrepopulatedEngine* engines_BN[] =
{ &google, &yahoo_my, &bing, };
const PrepopulatedEngine* engines_BO[] =
{ &google, &bing_es_XL, &yahoo, };
const PrepopulatedEngine* engines_BR[] =
{ &google, &ask_br, &bing_pt_BR, &yahoo_br, };
const PrepopulatedEngine* engines_BY[] =
{ &google, &yahoo_ru, &bing_ru_RU, };
const PrepopulatedEngine* engines_BZ[] =
{ &google, &yahoo, &bing, };
const PrepopulatedEngine* engines_CA[] =
{ &google, &bing_en_CA, &bing_fr_CA, &ask, &yahoo_ca, &yahoo_qc, };
const PrepopulatedEngine* engines_CH[] =
{ &google, &bing_de_CH, &bing_fr_CH, &yahoo_ch, };
const PrepopulatedEngine* engines_CL[] =
{ &google, &bing_es_CL, &yahoo_cl, };
const PrepopulatedEngine* engines_CN[] =
{ &google, &baidu, &sogou, &soso, };
const PrepopulatedEngine* engines_CO[] =
{ &google, &bing_es_XL, &yahoo_co, };
const PrepopulatedEngine* engines_CR[] =
{ &google, &yahoo, &bing_es_XL, };
const PrepopulatedEngine* engines_CZ[] =
{ &google, &seznam, &bing, };
const PrepopulatedEngine* engines_DE[] =
{ &google, &bing_de_DE, &yahoo_de };
const PrepopulatedEngine* engines_DK[] =
{ &google, &bing_da_DK, &yahoo_dk, };
const PrepopulatedEngine* engines_DO[] =
{ &google, &yahoo, &bing_es_XL, };
const PrepopulatedEngine* engines_DZ[] =
{ &google, &bing_ar_XA, &bing_en_XA, &yahoo_maktoob, };
const PrepopulatedEngine* engines_EC[] =
{ &google, &bing_es_XL, &yahoo, };
const PrepopulatedEngine* engines_EE[] =
{ &google, &bing, &yahoo, };
const PrepopulatedEngine* engines_EG[] =
{ &google, &yahoo_maktoob, &bing_ar_XA, &bing_en_XA, };
const PrepopulatedEngine* engines_ES[] =
{ &google, &bing_es_ES, &yahoo_es, };
const PrepopulatedEngine* engines_FO[] =
{ &google, &bing_da_DK, &ask, };
const PrepopulatedEngine* engines_FI[] =
{ &google, &bing_fi_FI, &yahoo_fi, };
const PrepopulatedEngine* engines_FR[] =
{ &google, &bing_fr_FR, &yahoo_fr, };
const PrepopulatedEngine* engines_GB[] =
{ &google, &bing_en_GB, &yahoo_uk, &ask_uk, };
const PrepopulatedEngine* engines_GR[] =
{ &google, &bing, &yahoo_gr, };
const PrepopulatedEngine* engines_GT[] =
{ &google, &yahoo, &bing_es_XL, };
const PrepopulatedEngine* engines_HK[] =
{ &google, &yahoo_hk, &baidu, &bing_zh_HK, };
const PrepopulatedEngine* engines_HN[] =
{ &google, &yahoo, &bing_es_XL, };
const PrepopulatedEngine* engines_HR[] =
{ &google, &bing, &yahoo, };
const PrepopulatedEngine* engines_HU[] =
{ &google, &bing, &yahoo, };
const PrepopulatedEngine* engines_ID[] =
{ &google, &yahoo_id, &bing, };
const PrepopulatedEngine* engines_IE[] =
{ &google, &bing_en_IE, &yahoo_uk, };
const PrepopulatedEngine* engines_IL[] =
{ &google, &yahoo, &bing, };
const PrepopulatedEngine* engines_IN[] =
{ &google, &bing_en_IN, &yahoo_in, };
const PrepopulatedEngine* engines_IQ[] =
{ &google, &yahoo_maktoob, &bing_ar_XA, &bing_en_XA, };
const PrepopulatedEngine* engines_IR[] =
{ &google, &yahoo, &bing, };
const PrepopulatedEngine* engines_IS[] =
{ &google, &bing, &yahoo, };
const PrepopulatedEngine* engines_IT[] =
{ &google, &virgilio, &bing_it_IT, };
const PrepopulatedEngine* engines_JM[] =
{ &google, &yahoo, &bing, };
const PrepopulatedEngine* engines_JO[] =
{ &google, &yahoo_maktoob, &bing_ar_XA, &bing_en_XA, };
const PrepopulatedEngine* engines_JP[] =
{ &google, &yahoo_jp, &bing_ja_JP, };
const PrepopulatedEngine* engines_KE[] =
{ &google, &yahoo, &bing, };
const PrepopulatedEngine* engines_KW[] =
{ &google, &yahoo_maktoob, &bing_ar_XA, &bing_en_XA, };
const PrepopulatedEngine* engines_KR[] =
{ &google, &naver, &daum, &nate, };
const PrepopulatedEngine* engines_KZ[] =
{ &google, &bing, &yahoo, };
const PrepopulatedEngine* engines_LB[] =
{ &google, &yahoo_maktoob, &bing_ar_XA, &bing_en_XA, };
const PrepopulatedEngine* engines_LI[] =
{ &google, &bing_de_DE, &yahoo_de, };
const PrepopulatedEngine* engines_LT[] =
{ &google, &bing, &yandex_ru, };
const PrepopulatedEngine* engines_LU[] =
{ &google, &bing_fr_FR, &yahoo_fr, };
const PrepopulatedEngine* engines_LV[] =
{ &google, &yandex_ru, &bing, };
const PrepopulatedEngine* engines_LY[] =
{ &google, &yahoo_maktoob, &bing_ar_XA, &bing_en_XA, };
const PrepopulatedEngine* engines_MA[] =
{ &google, &bing_ar_XA, &bing_en_XA, &yahoo_maktoob, };
const PrepopulatedEngine* engines_MC[] =
{ &google, &yahoo_fr, &bing_fr_FR, };
const PrepopulatedEngine* engines_MD[] =
{ &google, &bing, &yahoo, };
const PrepopulatedEngine* engines_ME[] =
{ &google, &bing, &yahoo, };
const PrepopulatedEngine* engines_MK[] =
{ &google, &yahoo, &bing, };
const PrepopulatedEngine* engines_MX[] =
{ &google, &bing_es_MX, &yahoo_mx, };
const PrepopulatedEngine* engines_MY[] =
{ &google, &yahoo_my, &bing, };
const PrepopulatedEngine* engines_NI[] =
{ &google, &yahoo, &bing_es_XL, };
const PrepopulatedEngine* engines_NL[] =
{ &google, &yahoo_nl, &vinden, };
const PrepopulatedEngine* engines_NO[] =
{ &google, &bing_nb_NO, &kvasir, };
const PrepopulatedEngine* engines_NZ[] =
{ &google, &bing_en_NZ, &yahoo_nz, };
const PrepopulatedEngine* engines_OM[] =
{ &google, &bing_ar_XA, &yahoo_maktoob, &bing_en_XA, };
const PrepopulatedEngine* engines_PA[] =
{ &google, &yahoo, &bing_es_XL, };
const PrepopulatedEngine* engines_PE[] =
{ &google, &bing_es_XL, &yahoo_pe, };
const PrepopulatedEngine* engines_PH[] =
{ &google, &yahoo_ph, &bing_en_PH, };
const PrepopulatedEngine* engines_PK[] =
{ &google, &yahoo, &bing, };
const PrepopulatedEngine* engines_PR[] =
{ &google, &yahoo, &bing_es_XL, };
const PrepopulatedEngine* engines_PL[] =
{ &google, &onet, &bing_pl_PL, };
const PrepopulatedEngine* engines_PT[] =
{ &google, &bing_pt_PT, &yahoo, };
const PrepopulatedEngine* engines_PY[] =
{ &google, &bing_es_XL, &yahoo, };
const PrepopulatedEngine* engines_QA[] =
{ &google, &yahoo_maktoob, &bing_ar_XA, &bing_en_XA, };
const PrepopulatedEngine* engines_RO[] =
{ &google, &yahoo_ro, &bing, };
const PrepopulatedEngine* engines_RS[] =
{ &google, &bing, &yahoo, };
const PrepopulatedEngine* engines_RU[] =
{ &google, &yandex_ru, &mail_ru, };
const PrepopulatedEngine* engines_RW[] =
{ &google, &bing, &yahoo, };
const PrepopulatedEngine* engines_SA[] =
{ &google, &yahoo_maktoob, &bing_ar_XA, &bing_en_XA, };
const PrepopulatedEngine* engines_SE[] =
{ &google, &bing_sv_SE, &yahoo_se, };
const PrepopulatedEngine* engines_SG[] =
{ &google, &yahoo_sg, &bing_en_SG, };
const PrepopulatedEngine* engines_SI[] =
{ &google, &najdi, &ask, };
const PrepopulatedEngine* engines_SK[] =
{ &google, &bing, &yahoo, };
const PrepopulatedEngine* engines_SV[] =
{ &google, &yahoo, &bing_es_XL, };
const PrepopulatedEngine* engines_SY[] =
{ &google, &bing_ar_XA, &bing_en_XA, &yahoo_maktoob, };
const PrepopulatedEngine* engines_TH[] =
{ &google, &yahoo_th, &bing, };
const PrepopulatedEngine* engines_TN[] =
{ &google, &bing_ar_XA, &bing_en_XA, &yahoo_maktoob, };
const PrepopulatedEngine* engines_TR[] =
{ &google, &bing_tr_TR, &yahoo_tr, &yandex_tr, };
const PrepopulatedEngine* engines_TT[] =
{ &google, &bing, &yahoo, };
const PrepopulatedEngine* engines_TW[] =
{ &google, &yahoo_tw, &bing_zh_TW, };
const PrepopulatedEngine* engines_TZ[] =
{ &google, &yahoo, &bing, };
const PrepopulatedEngine* engines_UA[] =
{ &google, &yandex_ua, &bing_ru_RU, };
const PrepopulatedEngine* engines_US[] =
{ &google, &bing_en_US, &yahoo, &aol, &ask, };
const PrepopulatedEngine* engines_UY[] =
{ &google, &bing_es_XL, &yahoo, };
const PrepopulatedEngine* engines_VE[] =
{ &google, &bing_es_XL, &yahoo_ve, };
const PrepopulatedEngine* engines_VN[] =
{ &google, &yahoo_vn, &bing, };
const PrepopulatedEngine* engines_YE[] =
{ &google, &bing_ar_XA, &bing_en_XA, &yahoo_maktoob, };
const PrepopulatedEngine* engines_ZA[] =
{ &google, &bing, &yahoo_za, };
const PrepopulatedEngine* engines_ZW[] =
{ &google, &bing, &yahoo, &ask, };
const PrepopulatedEngine* kAllEngines[] = {
&aol, &ask, &ask_br, &ask_uk, &baidu,
&bing, &bing_ar_XA, &bing_da_DK, &bing_de_AT, &bing_de_CH,
&bing_de_DE, &bing_en_AU, &bing_en_CA, &bing_en_GB, &bing_en_IE,
&bing_en_IN, &bing_en_NZ, &bing_en_PH, &bing_en_SG, &bing_en_US,
&bing_en_XA, &bing_es_AR, &bing_es_CL, &bing_es_ES, &bing_es_MX,
&bing_es_XL, &bing_fi_FI, &bing_fr_BE, &bing_fr_CA, &bing_fr_CH,
&bing_fr_FR, &bing_it_IT, &bing_ja_JP, &bing_lv_LV, &bing_nb_NO,
&bing_nl_BE, &bing_pl_PL, &bing_pt_BR, &bing_pt_PT, &bing_ru_RU,
&bing_sv_SE, &bing_tr_TR, &bing_zh_HK, &bing_zh_TW, &daum,
&google, &kvasir, &mail_ru, &najdi, &nate,
&naver, &onet, &seznam, &sogou, &soso,
&vinden, &virgilio, &yahoo, &yahoo_ar, &yahoo_at,
&yahoo_au, &yahoo_be, &yahoo_br, &yahoo_ca, &yahoo_ch,
&yahoo_cl, &yahoo_co, &yahoo_de, &yahoo_dk, &yahoo_es,
&yahoo_fi, &yahoo_fr, &yahoo_fr_be, &yahoo_gr, &yahoo_hk,
&yahoo_id, &yahoo_in, &yahoo_jp, &yahoo_maktoob, &yahoo_mx,
&yahoo_my, &yahoo_nl, &yahoo_nz, &yahoo_pe, &yahoo_ph,
&yahoo_qc, &yahoo_ro, &yahoo_ru, &yahoo_se, &yahoo_sg,
&yahoo_th, &yahoo_tr, &yahoo_tw, &yahoo_uk, &yahoo_ve,
&yahoo_vn, &yahoo_za, &yandex_ru, &yandex_tr, &yandex_ua,
&atlas_cz, &atlas_sk, &avg, &babylon, &conduit,
&delfi_lt, &delfi_lv, &delta, &funmoods, &goo,
&imesh, &iminent, &in, &incredibar, &libero,
&neti, &nigma, &ok, &rambler, &sapo,
&search_results, &searchnu, &snapdo, &softonic, &sweetim,
&terra_ar, &terra_es, &tut, &walla, &wp,
&zoznam,
};
const struct LogoURLs {
const char* const logo_100_percent_url;
const char* const logo_200_percent_url;
} google_logos = {
"https://www.google.com/images/chrome_search/google_logo.png",
"https://www.google.com/images/chrome_search/google_logo_2x.png",
};
const int kCountryIDUnknown = -1;
inline int CountryCharsToCountryID(char c1, char c2) {
return c1 << 8 | c2;
}
int CountryCharsToCountryIDWithUpdate(char c1, char c2) {
if ((c1 == 'Y' && c2 == 'U') ||
(c1 == 'C' && c2 == 'S')) {
c1 = 'R';
c2 = 'S';
}
if (c1 == 'T' && c2 == 'P')
c2 = 'L';
return CountryCharsToCountryID(c1, c2);
}
#if defined(OS_WIN)
int GeoIDToCountryID(GEOID geo_id) {
const int kISOBufferSize = 3;
wchar_t isobuf[kISOBufferSize] = { 0 };
int retval = GetGeoInfo(geo_id, GEO_ISO2, isobuf, kISOBufferSize, 0);
if (retval == kISOBufferSize &&
!(isobuf[0] == L'X' && isobuf[1] == L'X'))
return CountryCharsToCountryIDWithUpdate(static_cast<char>(isobuf[0]),
static_cast<char>(isobuf[1]));
switch (geo_id) {
case 0x144:
return CountryCharsToCountryID('G', 'G');
case 0x148:
return CountryCharsToCountryID('J', 'E');
case 0x3B16:
return CountryCharsToCountryID('I', 'M');
case 0x7F:
case 0x102:
case 0x131:
case 0x146:
case 0x147:
case 0x149:
case 0x152:
case 0x52FA:
return CountryCharsToCountryID('U', 'M');
case 0x12F:
case 0x15C:
return CountryCharsToCountryID('S', 'H');
case 0x13A:
return CountryCharsToCountryID('I', 'O');
case 0x154:
case 0x155:
case 0x15A:
return CountryCharsToCountryID('U', 'S');
case 0x134:
return CountryCharsToCountryID('G', 'B');
case 0x143:
default:
return kCountryIDUnknown;
}
}
int GetCurrentCountryID() {
GEOID geo_id = GetUserGeoID(GEOCLASS_NATION);
return GeoIDToCountryID(geo_id);
}
#elif defined(OS_MACOSX)
int GetCurrentCountryID() {
base::ScopedCFTypeRef<CFLocaleRef> locale(CFLocaleCopyCurrent());
CFStringRef country = (CFStringRef)CFLocaleGetValue(locale.get(),
kCFLocaleCountryCode);
if (!country)
return kCountryIDUnknown;
UniChar isobuf[2];
CFRange char_range = CFRangeMake(0, 2);
CFStringGetCharacters(country, char_range, isobuf);
return CountryCharsToCountryIDWithUpdate(static_cast<char>(isobuf[0]),
static_cast<char>(isobuf[1]));
}
#elif defined(OS_ANDROID)
int g_country_code_at_install = kCountryIDUnknown;
int GetCurrentCountryID() {
return g_country_code_at_install;
}
#elif defined(OS_POSIX)
int GetCurrentCountryID() {
const char* locale = setlocale(LC_MESSAGES, NULL);
if (!locale)
return kCountryIDUnknown;
std::string locale_str(locale);
size_t begin = locale_str.find('_');
if (begin == std::string::npos || locale_str.size() - begin < 3)
return kCountryIDUnknown;
++begin;
size_t end = locale_str.find_first_of(".@", begin);
if (end == std::string::npos)
end = locale_str.size();
if (end - begin == 2) {
return CountryCharsToCountryIDWithUpdate(
base::ToUpperASCII(locale_str[begin]),
base::ToUpperASCII(locale_str[begin + 1]));
}
return kCountryIDUnknown;
}
#endif
int GetCountryIDFromPrefs(PrefService* prefs) {
if (!prefs)
return GetCurrentCountryID();
if (!prefs->HasPrefPath(prefs::kCountryIDAtInstall)) {
int new_country_id = GetCurrentCountryID();
#if defined(OS_WIN)
if (prefs->HasPrefPath(prefs::kGeoIDAtInstall)) {
int geo_id = prefs->GetInteger(prefs::kGeoIDAtInstall);
prefs->ClearPref(prefs::kGeoIDAtInstall);
new_country_id = GeoIDToCountryID(geo_id);
}
#endif
prefs->SetInteger(prefs::kCountryIDAtInstall, new_country_id);
}
return prefs->GetInteger(prefs::kCountryIDAtInstall);
}
void GetPrepopulationSetFromCountryID(PrefService* prefs,
const PrepopulatedEngine*** engines,
size_t* num_engines) {
switch (GetCountryIDFromPrefs(prefs)) {
#define CHAR_A 'A'
#define CHAR_B 'B'
#define CHAR_C 'C'
#define CHAR_D 'D'
#define CHAR_E 'E'
#define CHAR_F 'F'
#define CHAR_G 'G'
#define CHAR_H 'H'
#define CHAR_I 'I'
#define CHAR_J 'J'
#define CHAR_K 'K'
#define CHAR_L 'L'
#define CHAR_M 'M'
#define CHAR_N 'N'
#define CHAR_O 'O'
#define CHAR_P 'P'
#define CHAR_Q 'Q'
#define CHAR_R 'R'
#define CHAR_S 'S'
#define CHAR_T 'T'
#define CHAR_U 'U'
#define CHAR_V 'V'
#define CHAR_W 'W'
#define CHAR_X 'X'
#define CHAR_Y 'Y'
#define CHAR_Z 'Z'
#define CHAR(ch) CHAR_##ch
#define CODE_TO_ID(code1, code2)\
(CHAR(code1) << 8 | CHAR(code2))
#define UNHANDLED_COUNTRY(code1, code2)\
case CODE_TO_ID(code1, code2):
#define END_UNHANDLED_COUNTRIES(code1, code2)\
*engines = engines_##code1##code2;\
*num_engines = arraysize(engines_##code1##code2);\
return;
#define DECLARE_COUNTRY(code1, code2)\
UNHANDLED_COUNTRY(code1, code2)\
END_UNHANDLED_COUNTRIES(code1, code2)
DECLARE_COUNTRY(A, E)
DECLARE_COUNTRY(A, L)
DECLARE_COUNTRY(A, R)
DECLARE_COUNTRY(A, T)
DECLARE_COUNTRY(A, U)
DECLARE_COUNTRY(B, A)
DECLARE_COUNTRY(B, E)
DECLARE_COUNTRY(B, G)
DECLARE_COUNTRY(B, H)
DECLARE_COUNTRY(B, I)
DECLARE_COUNTRY(B, N)
DECLARE_COUNTRY(B, O)
DECLARE_COUNTRY(B, R)
DECLARE_COUNTRY(B, Y)
DECLARE_COUNTRY(B, Z)
DECLARE_COUNTRY(C, A)
DECLARE_COUNTRY(C, H)
DECLARE_COUNTRY(C, L)
DECLARE_COUNTRY(C, N)
DECLARE_COUNTRY(C, O)
DECLARE_COUNTRY(C, R)
DECLARE_COUNTRY(C, Z)
DECLARE_COUNTRY(D, E)
DECLARE_COUNTRY(D, K)
DECLARE_COUNTRY(D, O)
DECLARE_COUNTRY(D, Z)
DECLARE_COUNTRY(E, C)
DECLARE_COUNTRY(E, E)
DECLARE_COUNTRY(E, G)
DECLARE_COUNTRY(E, S)
DECLARE_COUNTRY(F, I)
DECLARE_COUNTRY(F, O)
DECLARE_COUNTRY(F, R)
DECLARE_COUNTRY(G, B)
DECLARE_COUNTRY(G, R)
DECLARE_COUNTRY(G, T)
DECLARE_COUNTRY(H, K)
DECLARE_COUNTRY(H, N)
DECLARE_COUNTRY(H, R)
DECLARE_COUNTRY(H, U)
DECLARE_COUNTRY(I, D)
DECLARE_COUNTRY(I, E)
DECLARE_COUNTRY(I, L)
DECLARE_COUNTRY(I, N)
DECLARE_COUNTRY(I, Q)
DECLARE_COUNTRY(I, R)
DECLARE_COUNTRY(I, S)
DECLARE_COUNTRY(I, T)
DECLARE_COUNTRY(J, M)
DECLARE_COUNTRY(J, O)
DECLARE_COUNTRY(J, P)
DECLARE_COUNTRY(K, E)
DECLARE_COUNTRY(K, R)
DECLARE_COUNTRY(K, W)
DECLARE_COUNTRY(K, Z)
DECLARE_COUNTRY(L, B)
DECLARE_COUNTRY(L, I)
DECLARE_COUNTRY(L, T)
DECLARE_COUNTRY(L, U)
DECLARE_COUNTRY(L, V)
DECLARE_COUNTRY(L, Y)
DECLARE_COUNTRY(M, A)
DECLARE_COUNTRY(M, C)
DECLARE_COUNTRY(M, D)
DECLARE_COUNTRY(M, E)
DECLARE_COUNTRY(M, K)
DECLARE_COUNTRY(M, X)
DECLARE_COUNTRY(M, Y)
DECLARE_COUNTRY(N, I)
DECLARE_COUNTRY(N, L)
DECLARE_COUNTRY(N, O)
DECLARE_COUNTRY(N, Z)
DECLARE_COUNTRY(O, M)
DECLARE_COUNTRY(P, A)
DECLARE_COUNTRY(P, E)
DECLARE_COUNTRY(P, H)
DECLARE_COUNTRY(P, K)
DECLARE_COUNTRY(P, L)
DECLARE_COUNTRY(P, R)
DECLARE_COUNTRY(P, T)
DECLARE_COUNTRY(P, Y)
DECLARE_COUNTRY(Q, A)
DECLARE_COUNTRY(R, O)
DECLARE_COUNTRY(R, S)
DECLARE_COUNTRY(R, U)
DECLARE_COUNTRY(R, W)
DECLARE_COUNTRY(S, A)
DECLARE_COUNTRY(S, E)
DECLARE_COUNTRY(S, G)
DECLARE_COUNTRY(S, I)
DECLARE_COUNTRY(S, K)
DECLARE_COUNTRY(S, V)
DECLARE_COUNTRY(S, Y)
DECLARE_COUNTRY(T, H)
DECLARE_COUNTRY(T, N)
DECLARE_COUNTRY(T, R)
DECLARE_COUNTRY(T, T)
DECLARE_COUNTRY(T, W)
DECLARE_COUNTRY(T, Z)
DECLARE_COUNTRY(U, A)
DECLARE_COUNTRY(U, S)
DECLARE_COUNTRY(U, Y)
DECLARE_COUNTRY(V, E)
DECLARE_COUNTRY(V, N)
DECLARE_COUNTRY(Y, E)
DECLARE_COUNTRY(Z, A)
DECLARE_COUNTRY(Z, W)
UNHANDLED_COUNTRY(C, C)
UNHANDLED_COUNTRY(C, X)
UNHANDLED_COUNTRY(H, M)
UNHANDLED_COUNTRY(N, F)
END_UNHANDLED_COUNTRIES(A, U)
UNHANDLED_COUNTRY(M, O)
END_UNHANDLED_COUNTRIES(C, N)
UNHANDLED_COUNTRY(G, L)
END_UNHANDLED_COUNTRIES(D, K)
UNHANDLED_COUNTRY(A, D)
END_UNHANDLED_COUNTRIES(E, S)
UNHANDLED_COUNTRY(A, X)
END_UNHANDLED_COUNTRIES(F, I)
UNHANDLED_COUNTRY(B, F)
UNHANDLED_COUNTRY(B, J)
UNHANDLED_COUNTRY(C, D)
UNHANDLED_COUNTRY(C, F)
UNHANDLED_COUNTRY(C, G)
UNHANDLED_COUNTRY(C, I)
UNHANDLED_COUNTRY(C, M)
UNHANDLED_COUNTRY(D, J)
UNHANDLED_COUNTRY(G, A)
UNHANDLED_COUNTRY(G, F)
UNHANDLED_COUNTRY(G, N)
UNHANDLED_COUNTRY(G, P)
UNHANDLED_COUNTRY(H, T)
#if defined(OS_WIN)
UNHANDLED_COUNTRY(I, P)
#endif
UNHANDLED_COUNTRY(M, L)
UNHANDLED_COUNTRY(M, Q)
UNHANDLED_COUNTRY(N, C)
UNHANDLED_COUNTRY(N, E)
UNHANDLED_COUNTRY(P, F)
UNHANDLED_COUNTRY(P, M)
UNHANDLED_COUNTRY(R, E)
UNHANDLED_COUNTRY(S, N)
UNHANDLED_COUNTRY(T, D)
UNHANDLED_COUNTRY(T, F)
UNHANDLED_COUNTRY(T, G)
UNHANDLED_COUNTRY(W, F)
UNHANDLED_COUNTRY(Y, T)
END_UNHANDLED_COUNTRIES(F, R)
UNHANDLED_COUNTRY(C, Y)
END_UNHANDLED_COUNTRIES(G, R)
UNHANDLED_COUNTRY(S, M)
UNHANDLED_COUNTRY(V, A)
END_UNHANDLED_COUNTRIES(I, T)
UNHANDLED_COUNTRY(E, H)
END_UNHANDLED_COUNTRIES(M, A)
UNHANDLED_COUNTRY(A, N)
UNHANDLED_COUNTRY(A, W)
END_UNHANDLED_COUNTRIES(N, L)
UNHANDLED_COUNTRY(B, V)
UNHANDLED_COUNTRY(S, J)
END_UNHANDLED_COUNTRIES(N, O)
UNHANDLED_COUNTRY(C, K)
UNHANDLED_COUNTRY(N, U)
UNHANDLED_COUNTRY(T, K)
END_UNHANDLED_COUNTRIES(N, Z)
UNHANDLED_COUNTRY(C, V)
UNHANDLED_COUNTRY(G, W)
UNHANDLED_COUNTRY(M, Z)
UNHANDLED_COUNTRY(S, T)
UNHANDLED_COUNTRY(T, L)
END_UNHANDLED_COUNTRIES(P, T)
UNHANDLED_COUNTRY(A, M)
UNHANDLED_COUNTRY(A, Z)
UNHANDLED_COUNTRY(K, G)
UNHANDLED_COUNTRY(T, J)
UNHANDLED_COUNTRY(T, M)
UNHANDLED_COUNTRY(U, Z)
END_UNHANDLED_COUNTRIES(R, U)
UNHANDLED_COUNTRY(M, R)
UNHANDLED_COUNTRY(P, S)
UNHANDLED_COUNTRY(S, D)
END_UNHANDLED_COUNTRIES(S, A)
UNHANDLED_COUNTRY(B, M)
UNHANDLED_COUNTRY(F, K)
UNHANDLED_COUNTRY(G, G)
UNHANDLED_COUNTRY(G, I)
UNHANDLED_COUNTRY(G, S)
UNHANDLED_COUNTRY(I, M)
UNHANDLED_COUNTRY(I, O)
UNHANDLED_COUNTRY(J, E)
UNHANDLED_COUNTRY(K, Y)
UNHANDLED_COUNTRY(M, S)
UNHANDLED_COUNTRY(M, T)
UNHANDLED_COUNTRY(P, N)
UNHANDLED_COUNTRY(S, H)
UNHANDLED_COUNTRY(T, C)
UNHANDLED_COUNTRY(V, G)
END_UNHANDLED_COUNTRIES(G, B)
UNHANDLED_COUNTRY(A, S)
UNHANDLED_COUNTRY(G, U)
UNHANDLED_COUNTRY(M, P)
UNHANDLED_COUNTRY(U, M)
UNHANDLED_COUNTRY(V, I)
END_UNHANDLED_COUNTRIES(U, S)
UNHANDLED_COUNTRY(A, F)
UNHANDLED_COUNTRY(A, G)
UNHANDLED_COUNTRY(A, I)
UNHANDLED_COUNTRY(A, O)
UNHANDLED_COUNTRY(A, Q)
UNHANDLED_COUNTRY(B, B)
UNHANDLED_COUNTRY(B, D)
UNHANDLED_COUNTRY(B, S)
UNHANDLED_COUNTRY(B, T)
UNHANDLED_COUNTRY(B, W)
UNHANDLED_COUNTRY(C, U)
UNHANDLED_COUNTRY(D, M)
UNHANDLED_COUNTRY(E, R)
UNHANDLED_COUNTRY(E, T)
UNHANDLED_COUNTRY(F, J)
UNHANDLED_COUNTRY(F, M)
UNHANDLED_COUNTRY(G, D)
UNHANDLED_COUNTRY(G, E)
UNHANDLED_COUNTRY(G, H)
UNHANDLED_COUNTRY(G, M)
UNHANDLED_COUNTRY(G, Q)
UNHANDLED_COUNTRY(G, Y)
UNHANDLED_COUNTRY(K, H)
UNHANDLED_COUNTRY(K, I)
UNHANDLED_COUNTRY(K, M)
UNHANDLED_COUNTRY(K, N)
UNHANDLED_COUNTRY(K, P)
UNHANDLED_COUNTRY(L, A)
UNHANDLED_COUNTRY(L, C)
UNHANDLED_COUNTRY(L, K)
UNHANDLED_COUNTRY(L, R)
UNHANDLED_COUNTRY(L, S)
UNHANDLED_COUNTRY(M, G)
UNHANDLED_COUNTRY(M, H)
UNHANDLED_COUNTRY(M, M)
UNHANDLED_COUNTRY(M, N)
UNHANDLED_COUNTRY(M, U)
UNHANDLED_COUNTRY(M, V)
UNHANDLED_COUNTRY(M, W)
UNHANDLED_COUNTRY(N, A)
UNHANDLED_COUNTRY(N, G)
UNHANDLED_COUNTRY(N, P)
UNHANDLED_COUNTRY(N, R)
UNHANDLED_COUNTRY(P, G)
UNHANDLED_COUNTRY(P, W)
UNHANDLED_COUNTRY(S, B)
UNHANDLED_COUNTRY(S, C)
UNHANDLED_COUNTRY(S, L)
UNHANDLED_COUNTRY(S, O)
UNHANDLED_COUNTRY(S, R)
UNHANDLED_COUNTRY(S, Z)
UNHANDLED_COUNTRY(T, O)
UNHANDLED_COUNTRY(T, V)
UNHANDLED_COUNTRY(U, G)
UNHANDLED_COUNTRY(V, C)
UNHANDLED_COUNTRY(V, U)
UNHANDLED_COUNTRY(W, S)
UNHANDLED_COUNTRY(Z, M)
case kCountryIDUnknown:
default:
END_UNHANDLED_COUNTRIES(def, ault)
}
}
TemplateURL* MakePrepopulatedTemplateURL(
Profile* profile,
const base::string16& name,
const base::string16& keyword,
const base::StringPiece& search_url,
const base::StringPiece& suggest_url,
const base::StringPiece& instant_url,
const base::StringPiece& image_url,
const base::StringPiece& new_tab_url,
const base::StringPiece& search_url_post_params,
const base::StringPiece& suggest_url_post_params,
const base::StringPiece& instant_url_post_params,
const base::StringPiece& image_url_post_params,
const base::StringPiece& favicon_url,
const base::StringPiece& encoding,
const base::ListValue& alternate_urls,
const base::StringPiece& search_terms_replacement_key,
int id) {
TemplateURLData data;
data.short_name = name;
data.SetKeyword(keyword);
data.SetURL(search_url.as_string());
data.suggestions_url = suggest_url.as_string();
data.instant_url = instant_url.as_string();
data.image_url = image_url.as_string();
data.new_tab_url = new_tab_url.as_string();
data.search_url_post_params = search_url_post_params.as_string();
data.suggestions_url_post_params = suggest_url_post_params.as_string();
data.instant_url_post_params = instant_url_post_params.as_string();
data.image_url_post_params = image_url_post_params.as_string();
data.favicon_url = GURL(favicon_url.as_string());
data.show_in_default_list = true;
data.safe_for_autoreplace = true;
data.input_encodings.push_back(encoding.as_string());
data.date_created = base::Time();
data.last_modified = base::Time();
data.prepopulate_id = id;
for (size_t i = 0; i < alternate_urls.GetSize(); ++i) {
std::string alternate_url;
alternate_urls.GetString(i, &alternate_url);
DCHECK(!alternate_url.empty());
data.alternate_urls.push_back(alternate_url);
}
data.search_terms_replacement_key = search_terms_replacement_key.as_string();
return new TemplateURL(profile, data);
}
ScopedVector<TemplateURL> GetPrepopulatedTemplateFromPrefs(Profile* profile) {
ScopedVector<TemplateURL> t_urls;
if (!profile)
return t_urls.Pass();
const base::ListValue* list =
profile->GetPrefs()->GetList(prefs::kSearchProviderOverrides);
if (!list)
return t_urls.Pass();
size_t num_engines = list->GetSize();
for (size_t i = 0; i != num_engines; ++i) {
const base::DictionaryValue* engine;
base::string16 name;
base::string16 keyword;
std::string search_url;
std::string favicon_url;
std::string encoding;
int id;
if (list->GetDictionary(i, &engine) &&
engine->GetString("name", &name) && !name.empty() &&
engine->GetString("keyword", &keyword) && !keyword.empty() &&
engine->GetString("search_url", &search_url) && !search_url.empty() &&
engine->GetString("favicon_url", &favicon_url) &&
!favicon_url.empty() &&
engine->GetString("encoding", &encoding) && !encoding.empty() &&
engine->GetInteger("id", &id)) {
std::string suggest_url;
std::string instant_url;
std::string image_url;
std::string new_tab_url;
std::string search_url_post_params;
std::string suggest_url_post_params;
std::string instant_url_post_params;
std::string image_url_post_params;
base::ListValue empty_list;
const base::ListValue* alternate_urls = &empty_list;
std::string search_terms_replacement_key;
engine->GetString("suggest_url", &suggest_url);
engine->GetString("instant_url", &instant_url);
engine->GetString("image_url", &image_url);
engine->GetString("new_tab_url", &new_tab_url);
engine->GetString("search_url_post_params", &search_url_post_params);
engine->GetString("suggest_url_post_params", &suggest_url_post_params);
engine->GetString("instant_url_post_params", &instant_url_post_params);
engine->GetString("image_url_post_params", &image_url_post_params);
engine->GetList("alternate_urls", &alternate_urls);
engine->GetString("search_terms_replacement_key",
&search_terms_replacement_key);
t_urls.push_back(MakePrepopulatedTemplateURL(profile, name, keyword,
search_url, suggest_url, instant_url, image_url, new_tab_url,
search_url_post_params, suggest_url_post_params,
instant_url_post_params, image_url_post_params,
favicon_url, encoding, *alternate_urls, search_terms_replacement_key,
id));
}
}
return t_urls.Pass();
}
TemplateURL* MakePrepopulatedTemplateURLFromPrepopulateEngine(
Profile* profile,
const PrepopulatedEngine& engine) {
base::ListValue alternate_urls;
if (engine.alternate_urls) {
for (size_t i = 0; i < engine.alternate_urls_size; ++i)
alternate_urls.AppendString(std::string(engine.alternate_urls[i]));
}
return MakePrepopulatedTemplateURL(profile, base::WideToUTF16(engine.name),
base::WideToUTF16(engine.keyword), engine.search_url, engine.suggest_url,
engine.instant_url, engine.image_url, engine.new_tab_url,
engine.search_url_post_params, engine.suggest_url_post_params,
engine.instant_url_post_params, engine.image_url_post_params,
engine.favicon_url, engine.encoding, alternate_urls,
engine.search_terms_replacement_key, engine.id);
}
bool SameDomain(const GURL& given_url, const GURL& prepopulated_url) {
return prepopulated_url.is_valid() &&
net::registry_controlled_domains::SameDomainOrHost(
given_url, prepopulated_url,
net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
}
}
#if defined(OS_ANDROID)
void InitCountryCode(const std::string& country_code) {
if (country_code.size() != 2) {
DLOG(ERROR) << "Invalid country code: " << country_code;
g_country_code_at_install = kCountryIDUnknown;
} else {
g_country_code_at_install =
CountryCharsToCountryIDWithUpdate(country_code[0], country_code[1]);
}
}
#endif
void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
registry->RegisterIntegerPref(
prefs::kCountryIDAtInstall,
kCountryIDUnknown,
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
registry->RegisterListPref(prefs::kSearchProviderOverrides,
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
registry->RegisterIntegerPref(
prefs::kSearchProviderOverridesVersion,
-1,
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
registry->RegisterIntegerPref(
prefs::kGeoIDAtInstall,
-1,
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
}
int GetDataVersion(PrefService* prefs) {
return (prefs && prefs->HasPrefPath(prefs::kSearchProviderOverridesVersion)) ?
prefs->GetInteger(prefs::kSearchProviderOverridesVersion) :
kCurrentDataVersion;
}
ScopedVector<TemplateURL> GetPrepopulatedEngines(
Profile* profile, size_t* default_search_provider_index) {
*default_search_provider_index = 0;
ScopedVector<TemplateURL> t_urls = GetPrepopulatedTemplateFromPrefs(profile);
if (!t_urls.empty())
return t_urls.Pass();
const PrepopulatedEngine** engines;
size_t num_engines;
GetPrepopulationSetFromCountryID(profile ? profile->GetPrefs() : NULL,
&engines, &num_engines);
for (size_t i = 0; i != num_engines; ++i) {
t_urls.push_back(
MakePrepopulatedTemplateURLFromPrepopulateEngine(profile, *engines[i]));
}
return t_urls.Pass();
}
void ClearPrepopulatedEnginesInPrefs(Profile* profile) {
if (!profile)
return;
PrefService* prefs = profile->GetPrefs();
DCHECK(prefs);
prefs->ClearPref(prefs::kSearchProviderOverrides);
prefs->ClearPref(prefs::kSearchProviderOverridesVersion);
}
TemplateURL* GetPrepopulatedDefaultSearch(Profile* profile) {
TemplateURL* default_search_provider = NULL;
size_t default_search_index;
ScopedVector<TemplateURL> loaded_urls = GetPrepopulatedEngines(
profile, &default_search_index);
if (default_search_index < loaded_urls.size()) {
default_search_provider = loaded_urls[default_search_index];
loaded_urls.weak_erase(loaded_urls.begin() + default_search_index);
}
return default_search_provider;
}
SearchEngineType GetEngineType(const TemplateURL& url) {
using content::BrowserThread;
DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) ||
BrowserThread::CurrentlyOn(BrowserThread::UI));
GURL gurl(url.url_ref().ReplaceSearchTerms(TemplateURLRef::SearchTermsArgs(
base::ASCIIToUTF16("x"))));
return gurl.is_valid() ? GetEngineType(gurl) : SEARCH_ENGINE_OTHER;
}
SearchEngineType GetEngineType(const GURL& url) {
DCHECK(url.is_valid());
if (google_util::IsGoogleHostname(url.host(),
google_util::DISALLOW_SUBDOMAIN))
return google.type;
for (size_t i = 0; i < arraysize(kAllEngines); ++i) {
if (SameDomain(url, GURL(kAllEngines[i]->search_url)))
return kAllEngines[i]->type;
for (size_t j = 0; j < kAllEngines[i]->alternate_urls_size; ++j) {
if (SameDomain(url, GURL(kAllEngines[i]->alternate_urls[j])))
return kAllEngines[i]->type;
}
}
return SEARCH_ENGINE_OTHER;
}
GURL GetLogoURL(const TemplateURL& template_url, LogoSize size) {
if (GetEngineType(template_url) != SEARCH_ENGINE_GOOGLE)
return GURL();
return GURL((size == LOGO_200_PERCENT) ?
google_logos.logo_200_percent_url : google_logos.logo_100_percent_url);
}
}