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 3266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3277 // and thus won't ever string-compare successfully against |url|. | 3277 // and thus won't ever string-compare successfully against |url|. |
3278 return (url == google.search_url) ? &google : NULL; | 3278 return (url == google.search_url) ? &google : NULL; |
3279 } | 3279 } |
3280 | 3280 |
3281 // For all other cases, check using origins, in order to more aggressively | 3281 // For all other cases, check using origins, in order to more aggressively |
3282 // match search engine types for data imported from other browsers. | 3282 // match search engine types for data imported from other browsers. |
3283 // | 3283 // |
3284 // First special-case Google, because the prepopulate URL for it will not | 3284 // First special-case Google, because the prepopulate URL for it will not |
3285 // convert to a GURL and thus won't have an origin. Instead see if the | 3285 // convert to a GURL and thus won't have an origin. Instead see if the |
3286 // incoming URL's host is "[*.]google.<TLD>". | 3286 // incoming URL's host is "[*.]google.<TLD>". |
3287 if (google_util::IsGoogleHostname(as_gurl.host())) | 3287 if (google_util::IsGoogleHostname(as_gurl.host(), |
| 3288 google_util::DISALLOW_SUBDOMAIN)) |
3288 return &google; | 3289 return &google; |
3289 | 3290 |
3290 // Now check the rest of the prepopulate data. | 3291 // Now check the rest of the prepopulate data. |
3291 GURL origin(as_gurl.GetOrigin()); | 3292 GURL origin(as_gurl.GetOrigin()); |
3292 for (size_t i = 0; i < arraysize(kAllEngines); ++i) { | 3293 for (size_t i = 0; i < arraysize(kAllEngines); ++i) { |
3293 GURL engine_url(kAllEngines[i]->search_url); | 3294 GURL engine_url(kAllEngines[i]->search_url); |
3294 if (engine_url.is_valid() && (origin == engine_url.GetOrigin())) | 3295 if (engine_url.is_valid() && (origin == engine_url.GetOrigin())) |
3295 return kAllEngines[i]; | 3296 return kAllEngines[i]; |
3296 } | 3297 } |
3297 | 3298 |
3298 return NULL; | 3299 return NULL; |
3299 } | 3300 } |
3300 | 3301 |
3301 string16 GetEngineName(const std::string& url) { | 3302 string16 GetEngineName(const std::string& url) { |
3302 const PrepopulatedEngine* engine = GetEngineForURL(url); | 3303 const PrepopulatedEngine* engine = GetEngineForURL(url); |
3303 if (engine) | 3304 if (engine) |
3304 return WideToUTF16(engine->name); | 3305 return WideToUTF16(engine->name); |
3305 GURL as_gurl(url); | 3306 GURL as_gurl(url); |
3306 return (as_gurl.is_valid() && !as_gurl.host().empty()) ? | 3307 return (as_gurl.is_valid() && !as_gurl.host().empty()) ? |
3307 UTF8ToUTF16(as_gurl.host()) : | 3308 UTF8ToUTF16(as_gurl.host()) : |
3308 l10n_util::GetStringUTF16(IDS_UNKNOWN_SEARCH_ENGINE_NAME); | 3309 l10n_util::GetStringUTF16(IDS_UNKNOWN_SEARCH_ENGINE_NAME); |
3309 } | 3310 } |
3310 | 3311 |
3311 SearchEngineType GetEngineType(const std::string& url) { | 3312 SearchEngineType GetEngineType(const std::string& url) { |
3312 const PrepopulatedEngine* engine = GetEngineForURL(url); | 3313 const PrepopulatedEngine* engine = GetEngineForURL(url); |
3313 return engine ? engine->type : SEARCH_ENGINE_OTHER; | 3314 return engine ? engine->type : SEARCH_ENGINE_OTHER; |
3314 } | 3315 } |
3315 | 3316 |
3316 } // namespace TemplateURLPrepopulateData | 3317 } // namespace TemplateURLPrepopulateData |
OLD | NEW |