| 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 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1103 PrefServiceSyncable::UNSYNCABLE_PREF); | 1103 PrefServiceSyncable::UNSYNCABLE_PREF); |
| 1104 } | 1104 } |
| 1105 | 1105 |
| 1106 int GetDataVersion(PrefService* prefs) { | 1106 int GetDataVersion(PrefService* prefs) { |
| 1107 // Allow tests to override the local version. | 1107 // Allow tests to override the local version. |
| 1108 return (prefs && prefs->HasPrefPath(prefs::kSearchProviderOverridesVersion)) ? | 1108 return (prefs && prefs->HasPrefPath(prefs::kSearchProviderOverridesVersion)) ? |
| 1109 prefs->GetInteger(prefs::kSearchProviderOverridesVersion) : | 1109 prefs->GetInteger(prefs::kSearchProviderOverridesVersion) : |
| 1110 kCurrentDataVersion; | 1110 kCurrentDataVersion; |
| 1111 } | 1111 } |
| 1112 | 1112 |
| 1113 TemplateURL* MakePrepopulatedTemplateURL(Profile* profile, | 1113 TemplateURL* MakePrepopulatedTemplateURL( |
| 1114 const string16& name, | 1114 Profile* profile, |
| 1115 const string16& keyword, | 1115 const string16& name, |
| 1116 const base::StringPiece& search_url, | 1116 const string16& keyword, |
| 1117 const base::StringPiece& suggest_url, | 1117 const base::StringPiece& search_url, |
| 1118 const base::StringPiece& instant_url, | 1118 const base::StringPiece& suggest_url, |
| 1119 const ListValue& alternate_urls, | 1119 const base::StringPiece& instant_url, |
| 1120 const base::StringPiece& favicon_url, | 1120 const base::StringPiece& favicon_url, |
| 1121 const base::StringPiece& encoding, | 1121 const base::StringPiece& encoding, |
| 1122 int id) { | 1122 const ListValue& alternate_urls, |
| 1123 const base::StringPiece& search_terms_replacement_key, |
| 1124 int id) { |
| 1123 | 1125 |
| 1124 TemplateURLData data; | 1126 TemplateURLData data; |
| 1125 | 1127 |
| 1126 data.short_name = name; | 1128 data.short_name = name; |
| 1127 data.SetKeyword(keyword); | 1129 data.SetKeyword(keyword); |
| 1128 data.SetURL(search_url.as_string()); | 1130 data.SetURL(search_url.as_string()); |
| 1129 data.suggestions_url = suggest_url.as_string(); | 1131 data.suggestions_url = suggest_url.as_string(); |
| 1130 data.instant_url = instant_url.as_string(); | 1132 data.instant_url = instant_url.as_string(); |
| 1131 for (size_t i = 0; i < alternate_urls.GetSize(); ++i) { | |
| 1132 std::string alternate_url; | |
| 1133 alternate_urls.GetString(i, &alternate_url); | |
| 1134 DCHECK(!alternate_url.empty()); | |
| 1135 data.alternate_urls.push_back(alternate_url); | |
| 1136 } | |
| 1137 data.favicon_url = GURL(favicon_url.as_string()); | 1133 data.favicon_url = GURL(favicon_url.as_string()); |
| 1138 data.show_in_default_list = true; | 1134 data.show_in_default_list = true; |
| 1139 data.safe_for_autoreplace = true; | 1135 data.safe_for_autoreplace = true; |
| 1140 data.input_encodings.push_back(encoding.as_string()); | 1136 data.input_encodings.push_back(encoding.as_string()); |
| 1141 data.date_created = base::Time(); | 1137 data.date_created = base::Time(); |
| 1142 data.last_modified = base::Time(); | 1138 data.last_modified = base::Time(); |
| 1143 data.prepopulate_id = id; | 1139 data.prepopulate_id = id; |
| 1140 for (size_t i = 0; i < alternate_urls.GetSize(); ++i) { |
| 1141 std::string alternate_url; |
| 1142 alternate_urls.GetString(i, &alternate_url); |
| 1143 DCHECK(!alternate_url.empty()); |
| 1144 data.alternate_urls.push_back(alternate_url); |
| 1145 } |
| 1146 data.search_terms_replacement_key = search_terms_replacement_key.as_string(); |
| 1144 return new TemplateURL(profile, data); | 1147 return new TemplateURL(profile, data); |
| 1145 } | 1148 } |
| 1146 | 1149 |
| 1147 void GetPrepopulatedTemplateFromPrefs(Profile* profile, | 1150 void GetPrepopulatedTemplateFromPrefs(Profile* profile, |
| 1148 std::vector<TemplateURL*>* t_urls) { | 1151 std::vector<TemplateURL*>* t_urls) { |
| 1149 if (!profile) | 1152 if (!profile) |
| 1150 return; | 1153 return; |
| 1151 | 1154 |
| 1152 const ListValue* list = | 1155 const ListValue* list = |
| 1153 profile->GetPrefs()->GetList(prefs::kSearchProviderOverrides); | 1156 profile->GetPrefs()->GetList(prefs::kSearchProviderOverrides); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1170 engine->GetString("search_url", &search_url) && !search_url.empty() && | 1173 engine->GetString("search_url", &search_url) && !search_url.empty() && |
| 1171 engine->GetString("favicon_url", &favicon_url) && | 1174 engine->GetString("favicon_url", &favicon_url) && |
| 1172 !favicon_url.empty() && | 1175 !favicon_url.empty() && |
| 1173 engine->GetString("encoding", &encoding) && !encoding.empty() && | 1176 engine->GetString("encoding", &encoding) && !encoding.empty() && |
| 1174 engine->GetInteger("id", &id)) { | 1177 engine->GetInteger("id", &id)) { |
| 1175 // These fields are optional. | 1178 // These fields are optional. |
| 1176 std::string suggest_url; | 1179 std::string suggest_url; |
| 1177 std::string instant_url; | 1180 std::string instant_url; |
| 1178 ListValue empty_list; | 1181 ListValue empty_list; |
| 1179 const ListValue* alternate_urls = &empty_list; | 1182 const ListValue* alternate_urls = &empty_list; |
| 1183 std::string search_terms_replacement_key; |
| 1180 engine->GetString("suggest_url", &suggest_url); | 1184 engine->GetString("suggest_url", &suggest_url); |
| 1181 engine->GetString("instant_url", &instant_url); | 1185 engine->GetString("instant_url", &instant_url); |
| 1182 engine->GetList("alternate_urls", &alternate_urls); | 1186 engine->GetList("alternate_urls", &alternate_urls); |
| 1187 engine->GetString("search_terms_replacement_key", |
| 1188 &search_terms_replacement_key); |
| 1183 t_urls->push_back(MakePrepopulatedTemplateURL(profile, name, keyword, | 1189 t_urls->push_back(MakePrepopulatedTemplateURL(profile, name, keyword, |
| 1184 search_url, suggest_url, instant_url, *alternate_urls, favicon_url, | 1190 search_url, suggest_url, instant_url, favicon_url, encoding, |
| 1185 encoding, id)); | 1191 *alternate_urls, search_terms_replacement_key, id)); |
| 1186 } | 1192 } |
| 1187 } | 1193 } |
| 1188 } | 1194 } |
| 1189 | 1195 |
| 1190 // The caller owns the returned TemplateURL. | 1196 // The caller owns the returned TemplateURL. |
| 1191 TemplateURL* MakePrepopulatedTemplateURLFromPrepopulateEngine( | 1197 TemplateURL* MakePrepopulatedTemplateURLFromPrepopulateEngine( |
| 1192 Profile* profile, | 1198 Profile* profile, |
| 1193 const PrepopulatedEngine& engine) { | 1199 const PrepopulatedEngine& engine) { |
| 1194 | 1200 |
| 1195 ListValue alternate_urls; | 1201 ListValue alternate_urls; |
| 1196 if (engine.alternate_urls) { | 1202 if (engine.alternate_urls) { |
| 1197 for (size_t i = 0; i < engine.alternate_urls_size; ++i) | 1203 for (size_t i = 0; i < engine.alternate_urls_size; ++i) |
| 1198 alternate_urls.AppendString(std::string(engine.alternate_urls[i])); | 1204 alternate_urls.AppendString(std::string(engine.alternate_urls[i])); |
| 1199 } | 1205 } |
| 1200 | 1206 |
| 1201 return MakePrepopulatedTemplateURL(profile, WideToUTF16(engine.name), | 1207 return MakePrepopulatedTemplateURL(profile, WideToUTF16(engine.name), |
| 1202 WideToUTF16(engine.keyword), engine.search_url, engine.suggest_url, | 1208 WideToUTF16(engine.keyword), engine.search_url, engine.suggest_url, |
| 1203 engine.instant_url, alternate_urls, | 1209 engine.instant_url, engine.favicon_url, engine.encoding, alternate_urls, |
| 1204 engine.favicon_url, engine.encoding, engine.id); | 1210 engine.search_terms_replacement_key, engine.id); |
| 1205 } | 1211 } |
| 1206 | 1212 |
| 1207 void GetPrepopulatedEngines(Profile* profile, | 1213 void GetPrepopulatedEngines(Profile* profile, |
| 1208 std::vector<TemplateURL*>* t_urls, | 1214 std::vector<TemplateURL*>* t_urls, |
| 1209 size_t* default_search_provider_index) { | 1215 size_t* default_search_provider_index) { |
| 1210 // If there is a set of search engines in the preferences file, it overrides | 1216 // If there is a set of search engines in the preferences file, it overrides |
| 1211 // the built-in set. | 1217 // the built-in set. |
| 1212 *default_search_provider_index = 0; | 1218 *default_search_provider_index = 0; |
| 1213 GetPrepopulatedTemplateFromPrefs(profile, t_urls); | 1219 GetPrepopulatedTemplateFromPrefs(profile, t_urls); |
| 1214 if (!t_urls->empty()) | 1220 if (!t_urls->empty()) |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1281 GURL GetLogoURL(const TemplateURL& template_url, LogoSize size) { | 1287 GURL GetLogoURL(const TemplateURL& template_url, LogoSize size) { |
| 1282 if (GetEngineType(template_url.url()) == SEARCH_ENGINE_GOOGLE) { | 1288 if (GetEngineType(template_url.url()) == SEARCH_ENGINE_GOOGLE) { |
| 1283 return GURL((size == LOGO_200_PERCENT) ? | 1289 return GURL((size == LOGO_200_PERCENT) ? |
| 1284 google_logos.logo_200_percent_url : | 1290 google_logos.logo_200_percent_url : |
| 1285 google_logos.logo_100_percent_url); | 1291 google_logos.logo_100_percent_url); |
| 1286 } | 1292 } |
| 1287 return GURL(); | 1293 return GURL(); |
| 1288 } | 1294 } |
| 1289 | 1295 |
| 1290 } // namespace TemplateURLPrepopulateData | 1296 } // namespace TemplateURLPrepopulateData |
| OLD | NEW |