OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 5 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
6 | 6 |
7 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 7 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
8 #include <locale.h> | 8 #include <locale.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "chrome/browser/search_engines/template_url.h" | 25 #include "chrome/browser/search_engines/template_url.h" |
26 #include "chrome/browser/search_engines/template_url_service.h" | 26 #include "chrome/browser/search_engines/template_url_service.h" |
27 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
28 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
29 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
30 #include "googleurl/src/gurl.h" | 30 #include "googleurl/src/gurl.h" |
31 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
32 #include "grit/theme_resources.h" | 32 #include "grit/theme_resources.h" |
33 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
34 | 34 |
| 35 #include "prepopulated_engines.h" |
| 36 |
35 #if defined(OS_WIN) | 37 #if defined(OS_WIN) |
36 #undef IN // On Windows, windef.h defines this, which screws up "India" cases. | 38 #undef IN // On Windows, windef.h defines this, which screws up "India" cases. |
37 #elif defined(OS_MACOSX) | 39 #elif defined(OS_MACOSX) |
38 #include "base/mac/scoped_cftyperef.h" | 40 #include "base/mac/scoped_cftyperef.h" |
39 #endif | 41 #endif |
40 | 42 |
41 namespace { | 43 namespace TemplateURLPrepopulateData { |
42 | 44 |
43 // NOTE: See comments in GetDataVersion() below! You should probably not change | 45 // NOTE: See comments in GetDataVersion() below! You should probably not change |
44 // the data in this file without changing the result of that function! | 46 // the data in this file without changing the result of that function! |
45 | 47 |
46 // Engine definitions ////////////////////////////////////////////////////////// | |
47 | |
48 struct PrepopulatedEngine { | |
49 const wchar_t* const name; | |
50 const wchar_t* const keyword; | |
51 const char* const favicon_url; // If NULL, there is no favicon. | |
52 const char* const search_url; | |
53 const char* const encoding; | |
54 const char* const suggest_url; // If NULL, this engine does not support | |
55 // suggestions. | |
56 const char* const instant_url; // If NULL, this engine does not support | |
57 // instant. | |
58 // A JSON array containing a list of URL patterns that can be used, in | |
59 // addition to |search_url|, to extract search terms from a URL. Can be NULL. | |
60 const char* const alternate_urls; | |
61 // SEARCH_ENGINE_OTHER if there is no matching type. | |
62 const SearchEngineType type; | |
63 // Unique id for this prepopulate engine (corresponds to | |
64 // TemplateURL::prepopulate_id). This ID must be greater than zero and must | |
65 // remain the same for a particular site regardless of how the url changes; | |
66 // the ID is used when modifying engine data in subsequent versions, so that | |
67 // we can find the "old" entry to update even when the name or URL changes. | |
68 // | |
69 // This ID must be "unique" within one country's prepopulated data, but two | |
70 // entries can share an ID if they represent the "same" engine (e.g. Yahoo! US | |
71 // vs. Yahoo! UK) and will not appear in the same user-visible data set. This | |
72 // facilitates changes like adding more specific per-country data in the | |
73 // future; in such a case the localized engines will transparently replace the | |
74 // previous, non-localized versions. For engines where we need two instances | |
75 // to appear for one country (e.g. Bing Search U.S. English and Spanish), we | |
76 // must use two different unique IDs (and different keywords). | |
77 // | |
78 // The following unique IDs are available: | |
79 // 53, 56, 58, 60, 61, 64, 65, 66, 70, 74, 78, 79, 80, 81, 84, 86, 88, 91, | |
80 // 92, 93, 94, 95, 96, 97, 98, 99, 102+ | |
81 // | |
82 // IDs > 1000 are reserved for distribution custom engines. | |
83 // | |
84 // NOTES: | |
85 // CHANGE THE ABOVE NUMBERS IF YOU ADD A NEW ENGINE; ID conflicts = bad! | |
86 // CHANGE kMaxPrepopulatedEngineID below if you add new engine outside | |
87 // of the current range or it will not be counted in stats. | |
88 const int id; | |
89 }; | |
90 | |
91 // Prepopulated engines //////////////////////////////////////////////////////// | 48 // Prepopulated engines //////////////////////////////////////////////////////// |
92 | 49 |
93 // The following engines are included in country lists and are added to the list | 50 // The following engines are included in country lists and are added to the list |
94 // of search engines on the first run depending on user's country. | 51 // of search engines on the first run depending on user's country. |
95 | 52 |
96 const PrepopulatedEngine abcsok = { | |
97 L"ABC S\x00f8k", | |
98 L"abcsok.no", | |
99 "http://abcsok.no/favicon.ico", | |
100 "http://abcsok.no/index.html?q={searchTerms}", | |
101 "UTF-8", | |
102 NULL, | |
103 NULL, | |
104 NULL, | |
105 SEARCH_ENGINE_ABCSOK, | |
106 72, | |
107 }; | |
108 | |
109 const PrepopulatedEngine altavista = { | |
110 L"AltaVista", | |
111 L"altavista.com", | |
112 "http://www.altavista.com/favicon.ico", | |
113 "http://www.altavista.com/web/results?q={searchTerms}", | |
114 "UTF-8", | |
115 NULL, | |
116 NULL, | |
117 NULL, | |
118 SEARCH_ENGINE_ALTAVISTA, | |
119 89, | |
120 }; | |
121 | |
122 const PrepopulatedEngine altavista_ar = { | 53 const PrepopulatedEngine altavista_ar = { |
123 L"AltaVista", | 54 L"AltaVista", |
124 L"ar.altavista.com", | 55 L"ar.altavista.com", |
125 "http://ar.altavista.com/favicon.ico", | 56 "http://ar.altavista.com/favicon.ico", |
126 "http://ar.altavista.com/web/results?q={searchTerms}", | 57 "http://ar.altavista.com/web/results?q={searchTerms}", |
127 "UTF-8", | 58 "UTF-8", |
128 NULL, | 59 NULL, |
129 NULL, | 60 NULL, |
130 NULL, | 61 NULL, |
131 SEARCH_ENGINE_ALTAVISTA, | 62 SEARCH_ENGINE_ALTAVISTA, |
(...skipping 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1167 "http://goo.ne.jp/favicon.ico", | 1098 "http://goo.ne.jp/favicon.ico", |
1168 "http://search.goo.ne.jp/web.jsp?MT={searchTerms}&IE={inputEncoding}", | 1099 "http://search.goo.ne.jp/web.jsp?MT={searchTerms}&IE={inputEncoding}", |
1169 "UTF-8", | 1100 "UTF-8", |
1170 NULL, | 1101 NULL, |
1171 NULL, | 1102 NULL, |
1172 NULL, | 1103 NULL, |
1173 SEARCH_ENGINE_GOO, | 1104 SEARCH_ENGINE_GOO, |
1174 23, | 1105 23, |
1175 }; | 1106 }; |
1176 | 1107 |
1177 const PrepopulatedEngine google = { | |
1178 L"Google", | |
1179 L"google.com", // This will be dynamically updated by the TemplateURL system. | |
1180 "http://www.google.com/favicon.ico", | |
1181 "{google:baseURL}search?q={searchTerms}&{google:RLZ}" | |
1182 "{google:acceptedSuggestion}{google:originalQueryForSuggestion}" | |
1183 "{google:assistedQueryStats}{google:searchFieldtrialParameter}" | |
1184 "sourceid=chrome&ie={inputEncoding}", | |
1185 "UTF-8", | |
1186 "{google:baseSuggestURL}search?{google:searchFieldtrialParameter}" | |
1187 "client=chrome&hl={language}&q={searchTerms}&" | |
1188 "sugkey={google:suggestAPIKeyParameter}", | |
1189 "{google:baseURL}webhp?sourceid=chrome-instant&{google:RLZ}" | |
1190 "{google:instantEnabledParameter}ie={inputEncoding}", | |
1191 "[\"{google:baseURL}#q={searchTerms}\", " | |
1192 "\"{google:baseURL}search#q={searchTerms}\", " | |
1193 "\"{google:baseURL}webhp#q={searchTerms}\"]", | |
1194 SEARCH_ENGINE_GOOGLE, | |
1195 1, | |
1196 }; | |
1197 | |
1198 const PrepopulatedEngine guruji = { | 1108 const PrepopulatedEngine guruji = { |
1199 L"guruji", | 1109 L"guruji", |
1200 L"guruji.com", | 1110 L"guruji.com", |
1201 "http://guruji.com/favicon.ico", | 1111 "http://guruji.com/favicon.ico", |
1202 "http://guruji.com/search?q={searchTerms}", | 1112 "http://guruji.com/search?q={searchTerms}", |
1203 "UTF-8", | 1113 "UTF-8", |
1204 NULL, | 1114 NULL, |
1205 NULL, | 1115 NULL, |
1206 NULL, | 1116 NULL, |
1207 SEARCH_ENGINE_OTHER, | 1117 SEARCH_ENGINE_OTHER, |
(...skipping 2269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3477 }; | 3387 }; |
3478 | 3388 |
3479 const LogoURLs google_logos = { | 3389 const LogoURLs google_logos = { |
3480 "https://www.google.com/images/chrome_search/google_logo.png", | 3390 "https://www.google.com/images/chrome_search/google_logo.png", |
3481 "https://www.google.com/images/chrome_search/google_logo_2x.png", | 3391 "https://www.google.com/images/chrome_search/google_logo_2x.png", |
3482 }; | 3392 }; |
3483 | 3393 |
3484 | 3394 |
3485 //////////////////////////////////////////////////////////////////////////////// | 3395 //////////////////////////////////////////////////////////////////////////////// |
3486 | 3396 |
3487 } // namespace | |
3488 | |
3489 namespace TemplateURLPrepopulateData { | |
3490 | |
3491 // The following id is for UMA stats only. Please update | 3397 // The following id is for UMA stats only. Please update |
3492 // kMaxPrepopulatedEngineID if it changes upwards. | 3398 // kMaxPrepopulatedEngineID if it changes upwards. |
3493 const int kMaxPrepopulatedEngineID = 101; | 3399 const int kMaxPrepopulatedEngineID = 101; |
3494 | 3400 |
3495 void RegisterUserPrefs(PrefService* prefs) { | 3401 void RegisterUserPrefs(PrefService* prefs) { |
3496 prefs->RegisterIntegerPref(prefs::kCountryIDAtInstall, | 3402 prefs->RegisterIntegerPref(prefs::kCountryIDAtInstall, |
3497 kCountryIDUnknown, | 3403 kCountryIDUnknown, |
3498 PrefService::UNSYNCABLE_PREF); | 3404 PrefService::UNSYNCABLE_PREF); |
3499 prefs->RegisterListPref(prefs::kSearchProviderOverrides, | 3405 prefs->RegisterListPref(prefs::kSearchProviderOverrides, |
3500 PrefService::UNSYNCABLE_PREF); | 3406 PrefService::UNSYNCABLE_PREF); |
3501 prefs->RegisterIntegerPref(prefs::kSearchProviderOverridesVersion, | 3407 prefs->RegisterIntegerPref(prefs::kSearchProviderOverridesVersion, |
3502 -1, | 3408 -1, |
3503 PrefService::UNSYNCABLE_PREF); | 3409 PrefService::UNSYNCABLE_PREF); |
3504 // Obsolete pref, for migration. | 3410 // Obsolete pref, for migration. |
3505 prefs->RegisterIntegerPref(prefs::kGeoIDAtInstall, | 3411 prefs->RegisterIntegerPref(prefs::kGeoIDAtInstall, |
3506 -1, | 3412 -1, |
3507 PrefService::UNSYNCABLE_PREF); | 3413 PrefService::UNSYNCABLE_PREF); |
3508 } | 3414 } |
3509 | 3415 |
3510 int GetDataVersion(PrefService* prefs) { | 3416 int GetDataVersion(PrefService* prefs) { |
3511 // Increment this if you change the above data in ways that mean users with | |
3512 // existing data should get a new version. | |
3513 const int kCurrentDataVersion = 45; | |
3514 // Allow tests to override the local version. | 3417 // Allow tests to override the local version. |
3515 return (prefs && prefs->HasPrefPath(prefs::kSearchProviderOverridesVersion)) ? | 3418 return (prefs && prefs->HasPrefPath(prefs::kSearchProviderOverridesVersion)) ? |
3516 prefs->GetInteger(prefs::kSearchProviderOverridesVersion) : | 3419 prefs->GetInteger(prefs::kSearchProviderOverridesVersion) : |
3517 kCurrentDataVersion; | 3420 kCurrentDataVersion; |
3518 } | 3421 } |
3519 | 3422 |
3520 TemplateURL* MakePrepopulatedTemplateURL(Profile* profile, | 3423 TemplateURL* MakePrepopulatedTemplateURL(Profile* profile, |
3521 const string16& name, | 3424 const string16& name, |
3522 const string16& keyword, | 3425 const string16& keyword, |
3523 const base::StringPiece& search_url, | 3426 const base::StringPiece& search_url, |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3708 g_country_code_at_install = kCountryIDUnknown; | 3611 g_country_code_at_install = kCountryIDUnknown; |
3709 } else { | 3612 } else { |
3710 g_country_code_at_install = | 3613 g_country_code_at_install = |
3711 CountryCharsToCountryIDWithUpdate(country_code[0], country_code[1]); | 3614 CountryCharsToCountryIDWithUpdate(country_code[0], country_code[1]); |
3712 } | 3615 } |
3713 } | 3616 } |
3714 | 3617 |
3715 #endif | 3618 #endif |
3716 | 3619 |
3717 } // namespace TemplateURLPrepopulateData | 3620 } // namespace TemplateURLPrepopulateData |
OLD | NEW |