| 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 "components/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/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 15 #include "base/strings/string_piece.h" | 15 #include "base/strings/string_piece.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "components/google/core/browser/google_util.h" | 18 #include "components/google/core/browser/google_util.h" |
| 19 #include "components/pref_registry/pref_registry_syncable.h" | 19 #include "components/pref_registry/pref_registry_syncable.h" |
| 20 #include "components/search_engines/prepopulated_engines.h" | 20 #include "components/search_engines/prepopulated_engines.h" |
| 21 #include "components/search_engines/search_engines_pref_names.h" | 21 #include "components/search_engines/search_engines_pref_names.h" |
| 22 #include "components/search_engines/template_url.h" | 22 #include "components/search_engines/template_url.h" |
| 23 #include "content/public/browser/browser_thread.h" | |
| 24 #include "grit/generated_resources.h" | |
| 25 #include "grit/theme_resources.h" | |
| 26 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 23 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 27 #include "ui/base/l10n/l10n_util.h" | |
| 28 #include "url/gurl.h" | 24 #include "url/gurl.h" |
| 29 | 25 |
| 30 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
| 31 #undef IN // On Windows, windef.h defines this, which screws up "India" cases. | 27 #undef IN // On Windows, windef.h defines this, which screws up "India" cases. |
| 32 #elif defined(OS_MACOSX) | 28 #elif defined(OS_MACOSX) |
| 33 #include "base/mac/scoped_cftyperef.h" | 29 #include "base/mac/scoped_cftyperef.h" |
| 34 #endif | 30 #endif |
| 35 | 31 |
| 36 namespace TemplateURLPrepopulateData { | 32 namespace TemplateURLPrepopulateData { |
| 37 | 33 |
| (...skipping 1221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1259 GetPrepopulatedEngines(prefs, &default_search_index); | 1255 GetPrepopulatedEngines(prefs, &default_search_index); |
| 1260 if (default_search_index < loaded_urls.size()) { | 1256 if (default_search_index < loaded_urls.size()) { |
| 1261 default_search_provider.reset(loaded_urls[default_search_index]); | 1257 default_search_provider.reset(loaded_urls[default_search_index]); |
| 1262 loaded_urls.weak_erase(loaded_urls.begin() + default_search_index); | 1258 loaded_urls.weak_erase(loaded_urls.begin() + default_search_index); |
| 1263 } | 1259 } |
| 1264 return default_search_provider.Pass(); | 1260 return default_search_provider.Pass(); |
| 1265 } | 1261 } |
| 1266 | 1262 |
| 1267 SearchEngineType GetEngineType(const TemplateURL& url, | 1263 SearchEngineType GetEngineType(const TemplateURL& url, |
| 1268 const SearchTermsData& search_terms_data) { | 1264 const SearchTermsData& search_terms_data) { |
| 1269 // Restricted to UI thread because ReplaceSearchTerms() is so restricted. | |
| 1270 using content::BrowserThread; | |
| 1271 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) || | |
| 1272 BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 1273 | |
| 1274 // By calling ReplaceSearchTerms, we ensure that even TemplateURLs whose URLs | 1265 // By calling ReplaceSearchTerms, we ensure that even TemplateURLs whose URLs |
| 1275 // can't be directly inspected (e.g. due to containing {google:baseURL}) can | 1266 // can't be directly inspected (e.g. due to containing {google:baseURL}) can |
| 1276 // be converted to GURLs we can look at. | 1267 // be converted to GURLs we can look at. |
| 1277 GURL gurl(url.url_ref().ReplaceSearchTerms(TemplateURLRef::SearchTermsArgs( | 1268 GURL gurl(url.url_ref().ReplaceSearchTerms(TemplateURLRef::SearchTermsArgs( |
| 1278 base::ASCIIToUTF16("x")), search_terms_data)); | 1269 base::ASCIIToUTF16("x")), search_terms_data)); |
| 1279 return gurl.is_valid() ? GetEngineType(gurl) : SEARCH_ENGINE_OTHER; | 1270 return gurl.is_valid() ? GetEngineType(gurl) : SEARCH_ENGINE_OTHER; |
| 1280 } | 1271 } |
| 1281 | 1272 |
| 1282 SearchEngineType GetEngineType(const GURL& url) { | 1273 SearchEngineType GetEngineType(const GURL& url) { |
| 1283 DCHECK(url.is_valid()); | 1274 DCHECK(url.is_valid()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1302 for (size_t j = 0; j < kAllEngines[i]->alternate_urls_size; ++j) { | 1293 for (size_t j = 0; j < kAllEngines[i]->alternate_urls_size; ++j) { |
| 1303 if (SameDomain(url, GURL(kAllEngines[i]->alternate_urls[j]))) | 1294 if (SameDomain(url, GURL(kAllEngines[i]->alternate_urls[j]))) |
| 1304 return kAllEngines[i]->type; | 1295 return kAllEngines[i]->type; |
| 1305 } | 1296 } |
| 1306 } | 1297 } |
| 1307 | 1298 |
| 1308 return SEARCH_ENGINE_OTHER; | 1299 return SEARCH_ENGINE_OTHER; |
| 1309 } | 1300 } |
| 1310 | 1301 |
| 1311 } // namespace TemplateURLPrepopulateData | 1302 } // namespace TemplateURLPrepopulateData |
| OLD | NEW |