| 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 26 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 // NOTE: See comments in GetDataVersion() below! You should probably not change | 40 // NOTE: See comments in GetDataVersion() below! You should probably not change |
| 41 // the data in this file without changing the result of that function! | 41 // the data in this file without changing the result of that function! |
| 42 | 42 |
| 43 // Engine definitions ////////////////////////////////////////////////////////// | 43 // Engine definitions ////////////////////////////////////////////////////////// |
| 44 | 44 |
| 45 struct PrepopulatedEngine { | 45 struct PrepopulatedEngine { |
| 46 const wchar_t* const name; | 46 const wchar_t* const name; |
| 47 // If empty, we'll autogenerate a keyword based on the search_url every time | |
| 48 // someone asks. Only entries which need keywords to auto-track a dynamically | |
| 49 // generated search URL should use this. | |
| 50 const wchar_t* const keyword; | 47 const wchar_t* const keyword; |
| 51 const char* const favicon_url; // If NULL, there is no favicon. | 48 const char* const favicon_url; // If NULL, there is no favicon. |
| 52 const char* const search_url; | 49 const char* const search_url; |
| 53 const char* const encoding; | 50 const char* const encoding; |
| 54 const char* const suggest_url; // If NULL, this engine does not support | 51 const char* const suggest_url; // If NULL, this engine does not support |
| 55 // suggestions. | 52 // suggestions. |
| 56 const char* const instant_url; // If NULL, this engine does not support | 53 const char* const instant_url; // If NULL, this engine does not support |
| 57 // instant. | 54 // instant. |
| 58 // SEARCH_ENGINE_OTHER if there is no matching type. | 55 // SEARCH_ENGINE_OTHER if there is no matching type. |
| 59 const SearchEngineType type; | 56 const SearchEngineType type; |
| (...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1078 "http://search.goo.ne.jp/web.jsp?MT={searchTerms}&IE={inputEncoding}", | 1075 "http://search.goo.ne.jp/web.jsp?MT={searchTerms}&IE={inputEncoding}", |
| 1079 "UTF-8", | 1076 "UTF-8", |
| 1080 NULL, | 1077 NULL, |
| 1081 NULL, | 1078 NULL, |
| 1082 SEARCH_ENGINE_GOO, | 1079 SEARCH_ENGINE_GOO, |
| 1083 23, | 1080 23, |
| 1084 }; | 1081 }; |
| 1085 | 1082 |
| 1086 const PrepopulatedEngine google = { | 1083 const PrepopulatedEngine google = { |
| 1087 L"Google", | 1084 L"Google", |
| 1088 L"", | 1085 L"google.com", // This will be dynamically updated by the TemplateURL system. |
| 1089 "http://www.google.com/favicon.ico", | 1086 "http://www.google.com/favicon.ico", |
| 1090 "{google:baseURL}search?{google:RLZ}{google:acceptedSuggestion}" | 1087 "{google:baseURL}search?{google:RLZ}{google:acceptedSuggestion}" |
| 1091 "{google:originalQueryForSuggestion}{google:searchFieldtrialParameter}" | 1088 "{google:originalQueryForSuggestion}{google:searchFieldtrialParameter}" |
| 1092 "sourceid=chrome&ie={inputEncoding}&q={searchTerms}", | 1089 "sourceid=chrome&ie={inputEncoding}&q={searchTerms}", |
| 1093 "UTF-8", | 1090 "UTF-8", |
| 1094 "{google:baseSuggestURL}search?{google:searchFieldtrialParameter}" | 1091 "{google:baseSuggestURL}search?{google:searchFieldtrialParameter}" |
| 1095 "client=chrome&hl={language}&q={searchTerms}", | 1092 "client=chrome&hl={language}&q={searchTerms}", |
| 1096 "{google:baseURL}webhp?{google:RLZ}sourceid=chrome-instant&" | 1093 "{google:baseURL}webhp?{google:RLZ}sourceid=chrome-instant&" |
| 1097 "ie={inputEncoding}{google:instantEnabledParameter}{searchTerms}", | 1094 "ie={inputEncoding}{google:instantEnabledParameter}{searchTerms}", |
| 1098 SEARCH_ENGINE_GOOGLE, | 1095 SEARCH_ENGINE_GOOGLE, |
| (...skipping 2052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3151 const string16& name, | 3148 const string16& name, |
| 3152 const string16& keyword, | 3149 const string16& keyword, |
| 3153 const base::StringPiece& search_url, | 3150 const base::StringPiece& search_url, |
| 3154 const base::StringPiece& suggest_url, | 3151 const base::StringPiece& suggest_url, |
| 3155 const base::StringPiece& instant_url, | 3152 const base::StringPiece& instant_url, |
| 3156 const base::StringPiece& favicon_url, | 3153 const base::StringPiece& favicon_url, |
| 3157 const base::StringPiece& encoding, | 3154 const base::StringPiece& encoding, |
| 3158 int id) { | 3155 int id) { |
| 3159 TemplateURLData data; | 3156 TemplateURLData data; |
| 3160 data.short_name = name; | 3157 data.short_name = name; |
| 3161 if (keyword.empty()) | 3158 data.SetKeyword(keyword); |
| 3162 data.SetAutogenerateKeyword(true); | |
| 3163 else | |
| 3164 data.SetKeyword(keyword); | |
| 3165 data.SetURL(search_url.as_string()); | 3159 data.SetURL(search_url.as_string()); |
| 3166 data.suggestions_url = suggest_url.as_string(); | 3160 data.suggestions_url = suggest_url.as_string(); |
| 3167 data.instant_url = instant_url.as_string(); | 3161 data.instant_url = instant_url.as_string(); |
| 3168 data.favicon_url = GURL(favicon_url.as_string()); | 3162 data.favicon_url = GURL(favicon_url.as_string()); |
| 3169 data.show_in_default_list = true; | 3163 data.show_in_default_list = true; |
| 3170 data.safe_for_autoreplace = true; | 3164 data.safe_for_autoreplace = true; |
| 3171 data.input_encodings.push_back(encoding.as_string()); | 3165 data.input_encodings.push_back(encoding.as_string()); |
| 3172 data.date_created = base::Time(); | 3166 data.date_created = base::Time(); |
| 3173 data.last_modified = base::Time(); | 3167 data.last_modified = base::Time(); |
| 3174 data.prepopulate_id = id; | 3168 data.prepopulate_id = id; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 3201 if (list->GetDictionary(i, &engine) && | 3195 if (list->GetDictionary(i, &engine) && |
| 3202 engine->Get("name", &val) && val->GetAsString(&name) && | 3196 engine->Get("name", &val) && val->GetAsString(&name) && |
| 3203 engine->Get("keyword", &val) && val->GetAsString(&keyword) && | 3197 engine->Get("keyword", &val) && val->GetAsString(&keyword) && |
| 3204 engine->Get("search_url", &val) && val->GetAsString(&search_url) && | 3198 engine->Get("search_url", &val) && val->GetAsString(&search_url) && |
| 3205 engine->Get("suggest_url", &val) && val->GetAsString(&suggest_url) && | 3199 engine->Get("suggest_url", &val) && val->GetAsString(&suggest_url) && |
| 3206 engine->Get("instant_url", &val) && val->GetAsString(&instant_url) && | 3200 engine->Get("instant_url", &val) && val->GetAsString(&instant_url) && |
| 3207 engine->Get("favicon_url", &val) && val->GetAsString(&favicon_url) && | 3201 engine->Get("favicon_url", &val) && val->GetAsString(&favicon_url) && |
| 3208 engine->Get("encoding", &val) && val->GetAsString(&encoding) && | 3202 engine->Get("encoding", &val) && val->GetAsString(&encoding) && |
| 3209 engine->Get("id", &val) && val->GetAsInteger(&id)) { | 3203 engine->Get("id", &val) && val->GetAsInteger(&id)) { |
| 3210 // These next fields are not allowed to be empty. | 3204 // These next fields are not allowed to be empty. |
| 3211 if (name.empty() || search_url.empty() || favicon_url.empty() || | 3205 if (name.empty() || keyword.empty() || search_url.empty() || |
| 3212 encoding.empty()) | 3206 favicon_url.empty() || encoding.empty()) |
| 3213 return; | 3207 return; |
| 3214 } else { | 3208 } else { |
| 3215 // Got a parsing error. No big deal. | 3209 // Got a parsing error. No big deal. |
| 3216 continue; | 3210 continue; |
| 3217 } | 3211 } |
| 3218 t_urls->push_back(MakePrepopulatedTemplateURL(profile, name, keyword, | 3212 t_urls->push_back(MakePrepopulatedTemplateURL(profile, name, keyword, |
| 3219 search_url, suggest_url, instant_url, favicon_url, encoding, id)); | 3213 search_url, suggest_url, instant_url, favicon_url, encoding, id)); |
| 3220 } | 3214 } |
| 3221 } | 3215 } |
| 3222 | 3216 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3305 UTF8ToUTF16(as_gurl.host()) : | 3299 UTF8ToUTF16(as_gurl.host()) : |
| 3306 l10n_util::GetStringUTF16(IDS_UNKNOWN_SEARCH_ENGINE_NAME); | 3300 l10n_util::GetStringUTF16(IDS_UNKNOWN_SEARCH_ENGINE_NAME); |
| 3307 } | 3301 } |
| 3308 | 3302 |
| 3309 SearchEngineType GetEngineType(const std::string& url) { | 3303 SearchEngineType GetEngineType(const std::string& url) { |
| 3310 const PrepopulatedEngine* engine = GetEngineForURL(url); | 3304 const PrepopulatedEngine* engine = GetEngineForURL(url); |
| 3311 return engine ? engine->type : SEARCH_ENGINE_OTHER; | 3305 return engine ? engine->type : SEARCH_ENGINE_OTHER; |
| 3312 } | 3306 } |
| 3313 | 3307 |
| 3314 } // namespace TemplateURLPrepopulateData | 3308 } // namespace TemplateURLPrepopulateData |
| OLD | NEW |