| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/string16.h" |
| 12 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 13 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 14 #include "chrome/browser/pref_service.h" | 15 #include "chrome/browser/pref_service.h" |
| 15 #include "chrome/browser/search_engines/template_url.h" | 16 #include "chrome/browser/search_engines/template_url.h" |
| 16 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 18 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
| 19 | 20 |
| 20 #if defined(OS_WIN) | 21 #if defined(OS_WIN) |
| 21 #undef IN // On Windows, windef.h defines this, which screws up "India" cases. | 22 #undef IN // On Windows, windef.h defines this, which screws up "India" cases. |
| (...skipping 3160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3182 return new_turl; | 3183 return new_turl; |
| 3183 } | 3184 } |
| 3184 | 3185 |
| 3185 void GetPrepopulatedTemplatefromPrefs(PrefService* prefs, | 3186 void GetPrepopulatedTemplatefromPrefs(PrefService* prefs, |
| 3186 std::vector<TemplateURL*>* t_urls) { | 3187 std::vector<TemplateURL*>* t_urls) { |
| 3187 const ListValue* list = | 3188 const ListValue* list = |
| 3188 prefs->GetList(prefs::kSearchProviderOverrides); | 3189 prefs->GetList(prefs::kSearchProviderOverrides); |
| 3189 if (!list) | 3190 if (!list) |
| 3190 return; | 3191 return; |
| 3191 | 3192 |
| 3192 std::wstring name; | 3193 string16 name; |
| 3193 std::wstring keyword; | 3194 string16 keyword; |
| 3194 std::wstring search_url; | 3195 std::string search_url; |
| 3195 std::wstring suggest_url; | 3196 std::string suggest_url; |
| 3196 std::string favicon_url; | 3197 std::string favicon_url; |
| 3197 std::string encoding; | 3198 std::string encoding; |
| 3198 int search_engine_type; | 3199 int search_engine_type; |
| 3199 int logo_id; | 3200 int logo_id; |
| 3200 int id; | 3201 int id; |
| 3201 | 3202 |
| 3202 size_t num_engines = list->GetSize(); | 3203 size_t num_engines = list->GetSize(); |
| 3203 for (size_t i = 0; i != num_engines; ++i) { | 3204 for (size_t i = 0; i != num_engines; ++i) { |
| 3204 Value* val; | 3205 Value* val; |
| 3205 DictionaryValue* engine; | 3206 DictionaryValue* engine; |
| 3206 list->GetDictionary(i, &engine); | 3207 list->GetDictionary(i, &engine); |
| 3207 if (engine->Get(L"name", &val) && val->GetAsString(&name) && | 3208 if (engine->Get("name", &val) && val->GetAsString(&name) && |
| 3208 engine->Get(L"keyword", &val) && val->GetAsString(&keyword) && | 3209 engine->Get("keyword", &val) && val->GetAsString(&keyword) && |
| 3209 engine->Get(L"search_url", &val) && val->GetAsString(&search_url) && | 3210 engine->Get("search_url", &val) && val->GetAsString(&search_url) && |
| 3210 engine->Get(L"suggest_url", &val) && val->GetAsString(&suggest_url) && | 3211 engine->Get("suggest_url", &val) && val->GetAsString(&suggest_url) && |
| 3211 engine->Get(L"favicon_url", &val) && val->GetAsString(&favicon_url) && | 3212 engine->Get("favicon_url", &val) && val->GetAsString(&favicon_url) && |
| 3212 engine->Get(L"encoding", &val) && val->GetAsString(&encoding) && | 3213 engine->Get("encoding", &val) && val->GetAsString(&encoding) && |
| 3213 engine->Get(L"search_engine_type", &val) && val->GetAsInteger( | 3214 engine->Get("search_engine_type", &val) && val->GetAsInteger( |
| 3214 &search_engine_type) && | 3215 &search_engine_type) && |
| 3215 engine->Get(L"logo_id", &val) && val->GetAsInteger(&logo_id) && | 3216 engine->Get("logo_id", &val) && val->GetAsInteger(&logo_id) && |
| 3216 engine->Get(L"id", &val) && val->GetAsInteger(&id)) { | 3217 engine->Get("id", &val) && val->GetAsInteger(&id)) { |
| 3217 // These next fields are not allowed to be empty. | 3218 // These next fields are not allowed to be empty. |
| 3218 if (search_url.empty() || favicon_url.empty() || encoding.empty()) | 3219 if (search_url.empty() || favicon_url.empty() || encoding.empty()) |
| 3219 return; | 3220 return; |
| 3220 } else { | 3221 } else { |
| 3221 // Got a parsing error. No big deal. | 3222 // Got a parsing error. No big deal. |
| 3222 continue; | 3223 continue; |
| 3223 } | 3224 } |
| 3224 t_urls->push_back(MakePrepopulatedTemplateURL(name.c_str(), | 3225 // TODO(viettrungluu): convert |MakePrepopulatedTemplateURL()| and get rid |
| 3225 keyword.c_str(), | 3226 // of conversions. |
| 3226 search_url.c_str(), | 3227 t_urls->push_back(MakePrepopulatedTemplateURL( |
| 3228 UTF16ToWideHack(name).c_str(), |
| 3229 UTF16ToWideHack(keyword).c_str(), |
| 3230 UTF8ToWide(search_url).c_str(), |
| 3227 favicon_url.c_str(), | 3231 favicon_url.c_str(), |
| 3228 suggest_url.c_str(), | 3232 UTF8ToWide(suggest_url).c_str(), |
| 3229 encoding.c_str(), | 3233 encoding.c_str(), |
| 3230 static_cast<SearchEngineType>(search_engine_type), | 3234 static_cast<SearchEngineType>(search_engine_type), |
| 3231 logo_id, | 3235 logo_id, |
| 3232 id)); | 3236 id)); |
| 3233 } | 3237 } |
| 3234 } | 3238 } |
| 3235 | 3239 |
| 3236 void GetPrepopulatedEngines(PrefService* prefs, | 3240 void GetPrepopulatedEngines(PrefService* prefs, |
| 3237 std::vector<TemplateURL*>* t_urls, | 3241 std::vector<TemplateURL*>* t_urls, |
| 3238 size_t* default_search_provider_index) { | 3242 size_t* default_search_provider_index) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3255 engines[i]->suggest_url, | 3259 engines[i]->suggest_url, |
| 3256 engines[i]->encoding, | 3260 engines[i]->encoding, |
| 3257 engines[i]->search_engine_type, | 3261 engines[i]->search_engine_type, |
| 3258 engines[i]->logo_id, | 3262 engines[i]->logo_id, |
| 3259 engines[i]->id); | 3263 engines[i]->id); |
| 3260 t_urls->push_back(turl); | 3264 t_urls->push_back(turl); |
| 3261 } | 3265 } |
| 3262 } | 3266 } |
| 3263 | 3267 |
| 3264 } // namespace TemplateURLPrepopulateData | 3268 } // namespace TemplateURLPrepopulateData |
| OLD | NEW |