| 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 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1183 TemplateURL* MakePrepopulatedTemplateURLFromPrepopulateEngine( | 1183 TemplateURL* MakePrepopulatedTemplateURLFromPrepopulateEngine( |
| 1184 Profile* profile, | 1184 Profile* profile, |
| 1185 const PrepopulatedEngine& engine) { | 1185 const PrepopulatedEngine& engine) { |
| 1186 | 1186 |
| 1187 base::ListValue alternate_urls; | 1187 base::ListValue alternate_urls; |
| 1188 if (engine.alternate_urls) { | 1188 if (engine.alternate_urls) { |
| 1189 for (size_t i = 0; i < engine.alternate_urls_size; ++i) | 1189 for (size_t i = 0; i < engine.alternate_urls_size; ++i) |
| 1190 alternate_urls.AppendString(std::string(engine.alternate_urls[i])); | 1190 alternate_urls.AppendString(std::string(engine.alternate_urls[i])); |
| 1191 } | 1191 } |
| 1192 | 1192 |
| 1193 return MakePrepopulatedTemplateURL(profile, WideToUTF16(engine.name), | 1193 return MakePrepopulatedTemplateURL(profile, base::WideToUTF16(engine.name), |
| 1194 WideToUTF16(engine.keyword), engine.search_url, engine.suggest_url, | 1194 base::WideToUTF16(engine.keyword), engine.search_url, engine.suggest_url, |
| 1195 engine.instant_url, engine.image_url, engine.new_tab_url, | 1195 engine.instant_url, engine.image_url, engine.new_tab_url, |
| 1196 engine.search_url_post_params, engine.suggest_url_post_params, | 1196 engine.search_url_post_params, engine.suggest_url_post_params, |
| 1197 engine.instant_url_post_params, engine.image_url_post_params, | 1197 engine.instant_url_post_params, engine.image_url_post_params, |
| 1198 engine.favicon_url, engine.encoding, alternate_urls, | 1198 engine.favicon_url, engine.encoding, alternate_urls, |
| 1199 engine.search_terms_replacement_key, engine.id); | 1199 engine.search_terms_replacement_key, engine.id); |
| 1200 } | 1200 } |
| 1201 | 1201 |
| 1202 bool SameDomain(const GURL& given_url, const GURL& prepopulated_url) { | 1202 bool SameDomain(const GURL& given_url, const GURL& prepopulated_url) { |
| 1203 return prepopulated_url.is_valid() && | 1203 return prepopulated_url.is_valid() && |
| 1204 net::registry_controlled_domains::SameDomainOrHost( | 1204 net::registry_controlled_domains::SameDomainOrHost( |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1295 SearchEngineType GetEngineType(const TemplateURL& url) { | 1295 SearchEngineType GetEngineType(const TemplateURL& url) { |
| 1296 // Restricted to UI thread because ReplaceSearchTerms() is so restricted. | 1296 // Restricted to UI thread because ReplaceSearchTerms() is so restricted. |
| 1297 using content::BrowserThread; | 1297 using content::BrowserThread; |
| 1298 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) || | 1298 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) || |
| 1299 BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1299 BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1300 | 1300 |
| 1301 // By calling ReplaceSearchTerms, we ensure that even TemplateURLs whose URLs | 1301 // By calling ReplaceSearchTerms, we ensure that even TemplateURLs whose URLs |
| 1302 // can't be directly inspected (e.g. due to containing {google:baseURL}) can | 1302 // can't be directly inspected (e.g. due to containing {google:baseURL}) can |
| 1303 // be converted to GURLs we can look at. | 1303 // be converted to GURLs we can look at. |
| 1304 GURL gurl(url.url_ref().ReplaceSearchTerms(TemplateURLRef::SearchTermsArgs( | 1304 GURL gurl(url.url_ref().ReplaceSearchTerms(TemplateURLRef::SearchTermsArgs( |
| 1305 ASCIIToUTF16("x")))); | 1305 base::ASCIIToUTF16("x")))); |
| 1306 return gurl.is_valid() ? GetEngineType(gurl) : SEARCH_ENGINE_OTHER; | 1306 return gurl.is_valid() ? GetEngineType(gurl) : SEARCH_ENGINE_OTHER; |
| 1307 } | 1307 } |
| 1308 | 1308 |
| 1309 SearchEngineType GetEngineType(const GURL& url) { | 1309 SearchEngineType GetEngineType(const GURL& url) { |
| 1310 DCHECK(url.is_valid()); | 1310 DCHECK(url.is_valid()); |
| 1311 | 1311 |
| 1312 // Check using TLD+1s, in order to more aggressively match search engine types | 1312 // Check using TLD+1s, in order to more aggressively match search engine types |
| 1313 // for data imported from other browsers. | 1313 // for data imported from other browsers. |
| 1314 // | 1314 // |
| 1315 // First special-case Google, because the prepopulate URL for it will not | 1315 // First special-case Google, because the prepopulate URL for it will not |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1336 } | 1336 } |
| 1337 | 1337 |
| 1338 GURL GetLogoURL(const TemplateURL& template_url, LogoSize size) { | 1338 GURL GetLogoURL(const TemplateURL& template_url, LogoSize size) { |
| 1339 if (GetEngineType(template_url) != SEARCH_ENGINE_GOOGLE) | 1339 if (GetEngineType(template_url) != SEARCH_ENGINE_GOOGLE) |
| 1340 return GURL(); | 1340 return GURL(); |
| 1341 return GURL((size == LOGO_200_PERCENT) ? | 1341 return GURL((size == LOGO_200_PERCENT) ? |
| 1342 google_logos.logo_200_percent_url : google_logos.logo_100_percent_url); | 1342 google_logos.logo_200_percent_url : google_logos.logo_100_percent_url); |
| 1343 } | 1343 } |
| 1344 | 1344 |
| 1345 } // namespace TemplateURLPrepopulateData | 1345 } // namespace TemplateURLPrepopulateData |
| OLD | NEW |