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 3542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3553 void GetPrepopulatedTemplateFromPrefs(Profile* profile, | 3553 void GetPrepopulatedTemplateFromPrefs(Profile* profile, |
3554 std::vector<TemplateURL*>* t_urls) { | 3554 std::vector<TemplateURL*>* t_urls) { |
3555 if (!profile) | 3555 if (!profile) |
3556 return; | 3556 return; |
3557 | 3557 |
3558 const ListValue* list = | 3558 const ListValue* list = |
3559 profile->GetPrefs()->GetList(prefs::kSearchProviderOverrides); | 3559 profile->GetPrefs()->GetList(prefs::kSearchProviderOverrides); |
3560 if (!list) | 3560 if (!list) |
3561 return; | 3561 return; |
3562 | 3562 |
3563 string16 name; | |
3564 string16 keyword; | |
3565 std::string search_url; | |
3566 std::string suggest_url; | |
3567 std::string instant_url; | |
3568 const ListValue* alternate_urls = NULL; | |
3569 std::string favicon_url; | |
3570 std::string encoding; | |
3571 int id; | |
3572 | |
3573 size_t num_engines = list->GetSize(); | 3563 size_t num_engines = list->GetSize(); |
3574 for (size_t i = 0; i != num_engines; ++i) { | 3564 for (size_t i = 0; i != num_engines; ++i) { |
3575 const DictionaryValue* engine; | 3565 const DictionaryValue* engine; |
| 3566 string16 name; |
| 3567 string16 keyword; |
| 3568 std::string search_url; |
| 3569 std::string favicon_url; |
| 3570 std::string encoding; |
| 3571 int id; |
| 3572 // The following fields are required for each search engine configuration. |
3576 if (list->GetDictionary(i, &engine) && | 3573 if (list->GetDictionary(i, &engine) && |
3577 engine->GetString("name", &name) && | 3574 engine->GetString("name", &name) && !name.empty() && |
3578 engine->GetString("keyword", &keyword) && | 3575 engine->GetString("keyword", &keyword) && !keyword.empty() && |
3579 engine->GetString("search_url", &search_url) && | 3576 engine->GetString("search_url", &search_url) && !search_url.empty() && |
3580 engine->GetString("suggest_url", &suggest_url) && | |
3581 engine->GetString("instant_url", &instant_url) && | |
3582 engine->GetList("alternate_urls", &alternate_urls) && | |
3583 engine->GetString("favicon_url", &favicon_url) && | 3577 engine->GetString("favicon_url", &favicon_url) && |
3584 engine->GetString("encoding", &encoding) && | 3578 !favicon_url.empty() && |
| 3579 engine->GetString("encoding", &encoding) && !encoding.empty() && |
3585 engine->GetInteger("id", &id)) { | 3580 engine->GetInteger("id", &id)) { |
3586 // These next fields are not allowed to be empty. | 3581 // These fields are optional. |
3587 if (name.empty() || keyword.empty() || search_url.empty() || | 3582 std::string suggest_url; |
3588 favicon_url.empty() || encoding.empty()) | 3583 std::string instant_url; |
3589 return; | 3584 ListValue empty_list; |
3590 } else { | 3585 const ListValue* alternate_urls = &empty_list; |
3591 // Got a parsing error. No big deal. | 3586 engine->GetString("suggest_url", &suggest_url); |
3592 continue; | 3587 engine->GetString("instant_url", &instant_url); |
| 3588 engine->GetList("alternate_urls", &alternate_urls); |
| 3589 t_urls->push_back(MakePrepopulatedTemplateURL(profile, name, keyword, |
| 3590 search_url, suggest_url, instant_url, *alternate_urls, favicon_url, |
| 3591 encoding, id)); |
3593 } | 3592 } |
3594 t_urls->push_back(MakePrepopulatedTemplateURL(profile, name, keyword, | |
3595 search_url, suggest_url, instant_url, *alternate_urls, favicon_url, | |
3596 encoding, id)); | |
3597 } | 3593 } |
3598 } | 3594 } |
3599 | 3595 |
3600 // The caller owns the returned TemplateURL. | 3596 // The caller owns the returned TemplateURL. |
3601 TemplateURL* MakePrepopulatedTemplateURLFromPrepopulateEngine( | 3597 TemplateURL* MakePrepopulatedTemplateURLFromPrepopulateEngine( |
3602 Profile* profile, | 3598 Profile* profile, |
3603 const PrepopulatedEngine& engine) { | 3599 const PrepopulatedEngine& engine) { |
3604 | 3600 |
3605 // Use an empty list if there are no alternate_urls. | 3601 // Use an empty list if there are no alternate_urls. |
3606 ListValue empty_list; | 3602 ListValue empty_list; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3711 g_country_code_at_install = kCountryIDUnknown; | 3707 g_country_code_at_install = kCountryIDUnknown; |
3712 } else { | 3708 } else { |
3713 g_country_code_at_install = | 3709 g_country_code_at_install = |
3714 CountryCharsToCountryIDWithUpdate(country_code[0], country_code[1]); | 3710 CountryCharsToCountryIDWithUpdate(country_code[0], country_code[1]); |
3715 } | 3711 } |
3716 } | 3712 } |
3717 | 3713 |
3718 #endif | 3714 #endif |
3719 | 3715 |
3720 } // namespace TemplateURLPrepopulateData | 3716 } // namespace TemplateURLPrepopulateData |
OLD | NEW |