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.h" | 5 #include "chrome/browser/search_engines/template_url.h" |
6 | 6 |
7 #include "base/guid.h" | 7 #include "base/guid.h" |
8 #include "base/i18n/case_conversion.h" | 8 #include "base/i18n/case_conversion.h" |
9 #include "base/i18n/icu_string_conversions.h" | 9 #include "base/i18n/icu_string_conversions.h" |
10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 const char kSearchTermsParameterFull[] = "{searchTerms}"; | 38 const char kSearchTermsParameterFull[] = "{searchTerms}"; |
39 const char kCountParameter[] = "count"; | 39 const char kCountParameter[] = "count"; |
40 const char kStartIndexParameter[] = "startIndex"; | 40 const char kStartIndexParameter[] = "startIndex"; |
41 const char kStartPageParameter[] = "startPage"; | 41 const char kStartPageParameter[] = "startPage"; |
42 const char kLanguageParameter[] = "language"; | 42 const char kLanguageParameter[] = "language"; |
43 const char kInputEncodingParameter[] = "inputEncoding"; | 43 const char kInputEncodingParameter[] = "inputEncoding"; |
44 const char kOutputEncodingParameter[] = "outputEncoding"; | 44 const char kOutputEncodingParameter[] = "outputEncoding"; |
45 | 45 |
46 const char kGoogleAcceptedSuggestionParameter[] = "google:acceptedSuggestion"; | 46 const char kGoogleAcceptedSuggestionParameter[] = "google:acceptedSuggestion"; |
47 const char kGoogleAssistedQueryStatsParameter[] = "google:assistedQueryStats"; | 47 const char kGoogleAssistedQueryStatsParameter[] = "google:assistedQueryStats"; |
| 48 |
48 // Host/Domain Google searches are relative to. | 49 // Host/Domain Google searches are relative to. |
49 const char kGoogleBaseURLParameter[] = "google:baseURL"; | 50 const char kGoogleBaseURLParameter[] = "google:baseURL"; |
50 const char kGoogleBaseURLParameterFull[] = "{google:baseURL}"; | 51 const char kGoogleBaseURLParameterFull[] = "{google:baseURL}"; |
| 52 |
51 // Like google:baseURL, but for the Search Suggest capability. | 53 // Like google:baseURL, but for the Search Suggest capability. |
52 const char kGoogleBaseSuggestURLParameter[] = "google:baseSuggestURL"; | 54 const char kGoogleBaseSuggestURLParameter[] = "google:baseSuggestURL"; |
53 const char kGoogleBaseSuggestURLParameterFull[] = "{google:baseSuggestURL}"; | 55 const char kGoogleBaseSuggestURLParameterFull[] = "{google:baseSuggestURL}"; |
| 56 |
54 const char kGoogleInstantEnabledParameter[] = "google:instantEnabledParameter"; | 57 const char kGoogleInstantEnabledParameter[] = "google:instantEnabledParameter"; |
55 const char kGoogleOriginalQueryForSuggestionParameter[] = | 58 const char kGoogleOriginalQueryForSuggestionParameter[] = |
56 "google:originalQueryForSuggestion"; | 59 "google:originalQueryForSuggestion"; |
57 const char kGoogleRLZParameter[] = "google:RLZ"; | 60 const char kGoogleRLZParameter[] = "google:RLZ"; |
58 // Same as kSearchTermsParameter, with no escaping. | 61 const char kGoogleSearchClient[] = "google:searchClient"; |
59 const char kGoogleSearchFieldtrialParameter[] = | 62 const char kGoogleSearchFieldtrialParameter[] = |
60 "google:searchFieldtrialParameter"; | 63 "google:searchFieldtrialParameter"; |
| 64 const char kGoogleSourceIdParameter[] = "google:sourceId"; |
61 const char kGoogleSuggestAPIKeyParameter[] = "google:suggestAPIKeyParameter"; | 65 const char kGoogleSuggestAPIKeyParameter[] = "google:suggestAPIKeyParameter"; |
| 66 |
| 67 // Same as kSearchTermsParameter, with no escaping. |
62 const char kGoogleUnescapedSearchTermsParameter[] = | 68 const char kGoogleUnescapedSearchTermsParameter[] = |
63 "google:unescapedSearchTerms"; | 69 "google:unescapedSearchTerms"; |
64 const char kGoogleUnescapedSearchTermsParameterFull[] = | 70 const char kGoogleUnescapedSearchTermsParameterFull[] = |
65 "{google:unescapedSearchTerms}"; | 71 "{google:unescapedSearchTerms}"; |
66 | 72 |
67 // Display value for kSearchTermsParameter. | 73 // Display value for kSearchTermsParameter. |
68 const char kDisplaySearchTerms[] = "%s"; | 74 const char kDisplaySearchTerms[] = "%s"; |
69 | 75 |
70 // Display value for kGoogleUnescapedSearchTermsParameter. | 76 // Display value for kGoogleUnescapedSearchTermsParameter. |
71 const char kDisplayUnescapedSearchTerms[] = "%S"; | 77 const char kDisplayUnescapedSearchTerms[] = "%S"; |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 url.insert(i->index, "oq=" + UTF16ToUTF8(encoded_original_query) + | 307 url.insert(i->index, "oq=" + UTF16ToUTF8(encoded_original_query) + |
302 "&"); | 308 "&"); |
303 } | 309 } |
304 break; | 310 break; |
305 | 311 |
306 case GOOGLE_RLZ: { | 312 case GOOGLE_RLZ: { |
307 // On platforms that don't have RLZ, we still want this branch | 313 // On platforms that don't have RLZ, we still want this branch |
308 // to happen so that we replace the RLZ template with the | 314 // to happen so that we replace the RLZ template with the |
309 // empty string. (If we don't handle this case, we hit a | 315 // empty string. (If we don't handle this case, we hit a |
310 // NOTREACHED below.) | 316 // NOTREACHED below.) |
311 #if defined(ENABLE_RLZ) | |
312 string16 rlz_string = search_terms_data.GetRlzParameterValue(); | 317 string16 rlz_string = search_terms_data.GetRlzParameterValue(); |
313 if (!rlz_string.empty()) { | 318 if (!rlz_string.empty()) { |
314 url.insert(i->index, "rlz=" + UTF16ToUTF8(rlz_string) + "&"); | 319 url.insert(i->index, "rlz=" + UTF16ToUTF8(rlz_string) + "&"); |
315 } | 320 } |
316 #endif | |
317 break; | 321 break; |
318 } | 322 } |
319 | 323 |
| 324 case GOOGLE_SEARCH_CLIENT: { |
| 325 std::string client = search_terms_data.GetSearchClient(); |
| 326 if (!client.empty()) |
| 327 url.insert(i->index, "client=" + client + "&"); |
| 328 break; |
| 329 } |
| 330 |
320 case GOOGLE_SEARCH_FIELDTRIAL_GROUP: | 331 case GOOGLE_SEARCH_FIELDTRIAL_GROUP: |
321 // We are not currently running any fieldtrials that modulate the search | 332 // We are not currently running any fieldtrials that modulate the search |
322 // url. If we do, then we'd have some conditional insert such as: | 333 // url. If we do, then we'd have some conditional insert such as: |
323 // url.insert(i->index, used_www ? "gcx=w&" : "gcx=c&"); | 334 // url.insert(i->index, used_www ? "gcx=w&" : "gcx=c&"); |
324 break; | 335 break; |
325 | 336 |
326 case GOOGLE_UNESCAPED_SEARCH_TERMS: { | 337 case GOOGLE_UNESCAPED_SEARCH_TERMS: { |
327 std::string unescaped_terms; | 338 std::string unescaped_terms; |
328 base::UTF16ToCodepage(search_terms_args.search_terms, | 339 base::UTF16ToCodepage(search_terms_args.search_terms, |
329 input_encoding.c_str(), | 340 input_encoding.c_str(), |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 replacements->push_back(Replacement(GOOGLE_BASE_URL, start)); | 552 replacements->push_back(Replacement(GOOGLE_BASE_URL, start)); |
542 } else if (parameter == kGoogleBaseSuggestURLParameter) { | 553 } else if (parameter == kGoogleBaseSuggestURLParameter) { |
543 replacements->push_back(Replacement(GOOGLE_BASE_SUGGEST_URL, start)); | 554 replacements->push_back(Replacement(GOOGLE_BASE_SUGGEST_URL, start)); |
544 } else if (parameter == kGoogleInstantEnabledParameter) { | 555 } else if (parameter == kGoogleInstantEnabledParameter) { |
545 replacements->push_back(Replacement(GOOGLE_INSTANT_ENABLED, start)); | 556 replacements->push_back(Replacement(GOOGLE_INSTANT_ENABLED, start)); |
546 } else if (parameter == kGoogleOriginalQueryForSuggestionParameter) { | 557 } else if (parameter == kGoogleOriginalQueryForSuggestionParameter) { |
547 replacements->push_back(Replacement(GOOGLE_ORIGINAL_QUERY_FOR_SUGGESTION, | 558 replacements->push_back(Replacement(GOOGLE_ORIGINAL_QUERY_FOR_SUGGESTION, |
548 start)); | 559 start)); |
549 } else if (parameter == kGoogleRLZParameter) { | 560 } else if (parameter == kGoogleRLZParameter) { |
550 replacements->push_back(Replacement(GOOGLE_RLZ, start)); | 561 replacements->push_back(Replacement(GOOGLE_RLZ, start)); |
| 562 } else if (parameter == kGoogleSearchClient) { |
| 563 replacements->push_back(Replacement(GOOGLE_SEARCH_CLIENT, start)); |
551 } else if (parameter == kGoogleSearchFieldtrialParameter) { | 564 } else if (parameter == kGoogleSearchFieldtrialParameter) { |
552 replacements->push_back(Replacement(GOOGLE_SEARCH_FIELDTRIAL_GROUP, start)); | 565 replacements->push_back(Replacement(GOOGLE_SEARCH_FIELDTRIAL_GROUP, start)); |
553 } else if (parameter == kGoogleSuggestAPIKeyParameter) { | 566 } else if (parameter == kGoogleSuggestAPIKeyParameter) { |
554 url->insert(start, | 567 url->insert(start, |
555 net::EscapeQueryParamValue(google_apis::GetAPIKey(), false)); | 568 net::EscapeQueryParamValue(google_apis::GetAPIKey(), false)); |
| 569 } else if (parameter == kGoogleSourceIdParameter) { |
| 570 #if defined(OS_ANDROID) |
| 571 url->insert(start, "sourceid=chrome-mobile&"); |
| 572 #else |
| 573 url->insert(start, "sourceid=chrome&"); |
| 574 #endif |
556 } else if (parameter == kGoogleUnescapedSearchTermsParameter) { | 575 } else if (parameter == kGoogleUnescapedSearchTermsParameter) { |
557 replacements->push_back(Replacement(GOOGLE_UNESCAPED_SEARCH_TERMS, start)); | 576 replacements->push_back(Replacement(GOOGLE_UNESCAPED_SEARCH_TERMS, start)); |
558 } else if (!prepopulated_) { | 577 } else if (!prepopulated_) { |
559 // If it's a prepopulated URL, we know that it's safe to remove unknown | 578 // If it's a prepopulated URL, we know that it's safe to remove unknown |
560 // parameters, so just ignore this and return true below. Otherwise it could | 579 // parameters, so just ignore this and return true below. Otherwise it could |
561 // be some garbage but can also be a javascript block. Put it back. | 580 // be some garbage but can also be a javascript block. Put it back. |
562 url->insert(start, full_parameter); | 581 url->insert(start, full_parameter); |
563 return false; | 582 return false; |
564 } | 583 } |
565 return true; | 584 return true; |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 } | 849 } |
831 | 850 |
832 void TemplateURL::ResetKeywordIfNecessary(bool force) { | 851 void TemplateURL::ResetKeywordIfNecessary(bool force) { |
833 if (IsGoogleSearchURLWithReplaceableKeyword() || force) { | 852 if (IsGoogleSearchURLWithReplaceableKeyword() || force) { |
834 DCHECK(!IsExtensionKeyword()); | 853 DCHECK(!IsExtensionKeyword()); |
835 GURL url(TemplateURLService::GenerateSearchURL(this)); | 854 GURL url(TemplateURLService::GenerateSearchURL(this)); |
836 if (url.is_valid()) | 855 if (url.is_valid()) |
837 data_.SetKeyword(TemplateURLService::GenerateKeyword(url)); | 856 data_.SetKeyword(TemplateURLService::GenerateKeyword(url)); |
838 } | 857 } |
839 } | 858 } |
OLD | NEW |