| 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 1073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1084 SEARCH_ENGINE_GOO, | 1084 SEARCH_ENGINE_GOO, |
| 1085 23, | 1085 23, |
| 1086 }; | 1086 }; |
| 1087 | 1087 |
| 1088 const PrepopulatedEngine google = { | 1088 const PrepopulatedEngine google = { |
| 1089 L"Google", | 1089 L"Google", |
| 1090 L"google.com", // This will be dynamically updated by the TemplateURL system. | 1090 L"google.com", // This will be dynamically updated by the TemplateURL system. |
| 1091 "http://www.google.com/favicon.ico", | 1091 "http://www.google.com/favicon.ico", |
| 1092 "{google:baseURL}search?q={searchTerms}&{google:RLZ}" | 1092 "{google:baseURL}search?q={searchTerms}&{google:RLZ}" |
| 1093 "{google:acceptedSuggestion}{google:originalQueryForSuggestion}" | 1093 "{google:acceptedSuggestion}{google:originalQueryForSuggestion}" |
| 1094 "{google:searchFieldtrialParameter}sourceid=chrome&ie={inputEncoding}", | 1094 "{google:assistedQueryStats}{google:searchFieldtrialParameter}" |
| 1095 "sourceid=chrome&ie={inputEncoding}", |
| 1095 "UTF-8", | 1096 "UTF-8", |
| 1096 "{google:baseSuggestURL}search?{google:searchFieldtrialParameter}" | 1097 "{google:baseSuggestURL}search?{google:searchFieldtrialParameter}" |
| 1097 "client=chrome&hl={language}&q={searchTerms}", | 1098 "client=chrome&hl={language}&q={searchTerms}", |
| 1098 "{google:baseURL}webhp?{google:RLZ}sourceid=chrome-instant&" | 1099 "{google:baseURL}webhp?{google:RLZ}sourceid=chrome-instant&" |
| 1099 "ie={inputEncoding}{google:instantEnabledParameter}{searchTerms}", | 1100 "ie={inputEncoding}{google:instantEnabledParameter}{searchTerms}", |
| 1100 SEARCH_ENGINE_GOOGLE, | 1101 SEARCH_ENGINE_GOOGLE, |
| 1101 1, | 1102 1, |
| 1102 }; | 1103 }; |
| 1103 | 1104 |
| 1104 const PrepopulatedEngine guruji = { | 1105 const PrepopulatedEngine guruji = { |
| (...skipping 2306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3411 BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3412 BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 3412 | 3413 |
| 3413 // We may get a valid URL, or we may get the Google prepopulate URL which | 3414 // We may get a valid URL, or we may get the Google prepopulate URL which |
| 3414 // can't be converted directly to a GURL. To handle the latter, we first | 3415 // can't be converted directly to a GURL. To handle the latter, we first |
| 3415 // construct a TemplateURL from the provided |url|, then call | 3416 // construct a TemplateURL from the provided |url|, then call |
| 3416 // ReplaceSearchTerms(). This should return a valid URL even when the input | 3417 // ReplaceSearchTerms(). This should return a valid URL even when the input |
| 3417 // has Google base URLs. | 3418 // has Google base URLs. |
| 3418 TemplateURLData data; | 3419 TemplateURLData data; |
| 3419 data.SetURL(url); | 3420 data.SetURL(url); |
| 3420 TemplateURL turl(NULL, data); | 3421 TemplateURL turl(NULL, data); |
| 3421 GURL as_gurl(turl.url_ref().ReplaceSearchTerms(ASCIIToUTF16("x"), | 3422 GURL as_gurl(turl.url_ref().ReplaceSearchTerms( |
| 3422 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); | 3423 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("x")))); |
| 3423 if (!as_gurl.is_valid()) | 3424 if (!as_gurl.is_valid()) |
| 3424 return SEARCH_ENGINE_OTHER; | 3425 return SEARCH_ENGINE_OTHER; |
| 3425 | 3426 |
| 3426 // Check using origins, in order to more aggressively match search engine | 3427 // Check using origins, in order to more aggressively match search engine |
| 3427 // types for data imported from other browsers. | 3428 // types for data imported from other browsers. |
| 3428 // | 3429 // |
| 3429 // First special-case Google, because the prepopulate URL for it will not | 3430 // First special-case Google, because the prepopulate URL for it will not |
| 3430 // convert to a GURL and thus won't have an origin. Instead see if the | 3431 // convert to a GURL and thus won't have an origin. Instead see if the |
| 3431 // incoming URL's host is "[*.]google.<TLD>". | 3432 // incoming URL's host is "[*.]google.<TLD>". |
| 3432 if (google_util::IsGoogleHostname(as_gurl.host(), | 3433 if (google_util::IsGoogleHostname(as_gurl.host(), |
| 3433 google_util::DISALLOW_SUBDOMAIN)) | 3434 google_util::DISALLOW_SUBDOMAIN)) |
| 3434 return google.type; | 3435 return google.type; |
| 3435 | 3436 |
| 3436 // Now check the rest of the prepopulate data. | 3437 // Now check the rest of the prepopulate data. |
| 3437 GURL origin(as_gurl.GetOrigin()); | 3438 GURL origin(as_gurl.GetOrigin()); |
| 3438 for (size_t i = 0; i < arraysize(kAllEngines); ++i) { | 3439 for (size_t i = 0; i < arraysize(kAllEngines); ++i) { |
| 3439 GURL engine_url(kAllEngines[i]->search_url); | 3440 GURL engine_url(kAllEngines[i]->search_url); |
| 3440 if (engine_url.is_valid() && (origin == engine_url.GetOrigin())) | 3441 if (engine_url.is_valid() && (origin == engine_url.GetOrigin())) |
| 3441 return kAllEngines[i]->type; | 3442 return kAllEngines[i]->type; |
| 3442 } | 3443 } |
| 3443 | 3444 |
| 3444 return SEARCH_ENGINE_OTHER; | 3445 return SEARCH_ENGINE_OTHER; |
| 3445 } | 3446 } |
| 3446 | 3447 |
| 3447 } // namespace TemplateURLPrepopulateData | 3448 } // namespace TemplateURLPrepopulateData |
| OLD | NEW |