OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/i18n/case_conversion.h" | 7 #include "base/i18n/case_conversion.h" |
8 #include "base/i18n/icu_string_conversions.h" | 8 #include "base/i18n/icu_string_conversions.h" |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 static const char kGoogleAcceptedSuggestionParameter[] = | 45 static const char kGoogleAcceptedSuggestionParameter[] = |
46 "google:acceptedSuggestion"; | 46 "google:acceptedSuggestion"; |
47 // Host/Domain Google searches are relative to. | 47 // Host/Domain Google searches are relative to. |
48 static const char kGoogleBaseURLParameter[] = "google:baseURL"; | 48 static const char kGoogleBaseURLParameter[] = "google:baseURL"; |
49 static const char kGoogleBaseURLParameterFull[] = "{google:baseURL}"; | 49 static const char kGoogleBaseURLParameterFull[] = "{google:baseURL}"; |
50 // Like google:baseURL, but for the Search Suggest capability. | 50 // Like google:baseURL, but for the Search Suggest capability. |
51 static const char kGoogleBaseSuggestURLParameter[] = | 51 static const char kGoogleBaseSuggestURLParameter[] = |
52 "google:baseSuggestURL"; | 52 "google:baseSuggestURL"; |
53 static const char kGoogleBaseSuggestURLParameterFull[] = | 53 static const char kGoogleBaseSuggestURLParameterFull[] = |
54 "{google:baseSuggestURL}"; | 54 "{google:baseSuggestURL}"; |
| 55 static const char kGoogleInstantFieldTrialGroupParameter[] = |
| 56 "google:instantFieldTrialGroupParameter"; |
55 static const char kGoogleOriginalQueryForSuggestionParameter[] = | 57 static const char kGoogleOriginalQueryForSuggestionParameter[] = |
56 "google:originalQueryForSuggestion"; | 58 "google:originalQueryForSuggestion"; |
57 static const char kGoogleRLZParameter[] = "google:RLZ"; | 59 static const char kGoogleRLZParameter[] = "google:RLZ"; |
58 // Same as kSearchTermsParameter, with no escaping. | 60 // Same as kSearchTermsParameter, with no escaping. |
59 static const char kGoogleSearchFieldtrialParameter[] = | 61 static const char kGoogleSearchFieldtrialParameter[] = |
60 "google:searchFieldtrialParameter"; | 62 "google:searchFieldtrialParameter"; |
61 static const char kGoogleUnescapedSearchTermsParameter[] = | 63 static const char kGoogleUnescapedSearchTermsParameter[] = |
62 "google:unescapedSearchTerms"; | 64 "google:unescapedSearchTerms"; |
63 static const char kGoogleUnescapedSearchTermsParameterFull[] = | 65 static const char kGoogleUnescapedSearchTermsParameterFull[] = |
64 "{google:unescapedSearchTerms}"; | 66 "{google:unescapedSearchTerms}"; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 replacements->push_back(Replacement(ENCODING, start)); | 141 replacements->push_back(Replacement(ENCODING, start)); |
140 } else if (parameter == kOutputEncodingParameter) { | 142 } else if (parameter == kOutputEncodingParameter) { |
141 if (!optional) | 143 if (!optional) |
142 url->insert(start, kOutputEncodingType); | 144 url->insert(start, kOutputEncodingType); |
143 } else if (parameter == kGoogleAcceptedSuggestionParameter) { | 145 } else if (parameter == kGoogleAcceptedSuggestionParameter) { |
144 replacements->push_back(Replacement(GOOGLE_ACCEPTED_SUGGESTION, start)); | 146 replacements->push_back(Replacement(GOOGLE_ACCEPTED_SUGGESTION, start)); |
145 } else if (parameter == kGoogleBaseURLParameter) { | 147 } else if (parameter == kGoogleBaseURLParameter) { |
146 replacements->push_back(Replacement(GOOGLE_BASE_URL, start)); | 148 replacements->push_back(Replacement(GOOGLE_BASE_URL, start)); |
147 } else if (parameter == kGoogleBaseSuggestURLParameter) { | 149 } else if (parameter == kGoogleBaseSuggestURLParameter) { |
148 replacements->push_back(Replacement(GOOGLE_BASE_SUGGEST_URL, start)); | 150 replacements->push_back(Replacement(GOOGLE_BASE_SUGGEST_URL, start)); |
| 151 } else if (parameter == kGoogleInstantFieldTrialGroupParameter) { |
| 152 replacements->push_back(Replacement(GOOGLE_INSTANT_FIELD_TRIAL_GROUP, |
| 153 start)); |
149 } else if (parameter == kGoogleOriginalQueryForSuggestionParameter) { | 154 } else if (parameter == kGoogleOriginalQueryForSuggestionParameter) { |
150 replacements->push_back(Replacement(GOOGLE_ORIGINAL_QUERY_FOR_SUGGESTION, | 155 replacements->push_back(Replacement(GOOGLE_ORIGINAL_QUERY_FOR_SUGGESTION, |
151 start)); | 156 start)); |
152 } else if (parameter == kGoogleRLZParameter) { | 157 } else if (parameter == kGoogleRLZParameter) { |
153 replacements->push_back(Replacement(GOOGLE_RLZ, start)); | 158 replacements->push_back(Replacement(GOOGLE_RLZ, start)); |
154 } else if (parameter == kGoogleSearchFieldtrialParameter) { | 159 } else if (parameter == kGoogleSearchFieldtrialParameter) { |
155 replacements->push_back(Replacement(GOOGLE_SEARCH_FIELDTRIAL_GROUP, start)); | 160 replacements->push_back(Replacement(GOOGLE_SEARCH_FIELDTRIAL_GROUP, start)); |
156 } else if (parameter == kGoogleUnescapedSearchTermsParameter) { | 161 } else if (parameter == kGoogleUnescapedSearchTermsParameter) { |
157 replacements->push_back(Replacement(GOOGLE_UNESCAPED_SEARCH_TERMS, start)); | 162 replacements->push_back(Replacement(GOOGLE_UNESCAPED_SEARCH_TERMS, start)); |
158 } else { | 163 } else { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 // static | 278 // static |
274 void TemplateURLRef::SetGoogleBaseURL(std::string* google_base_url) { | 279 void TemplateURLRef::SetGoogleBaseURL(std::string* google_base_url) { |
275 UIThreadSearchTermsData::SetGoogleBaseURL(google_base_url); | 280 UIThreadSearchTermsData::SetGoogleBaseURL(google_base_url); |
276 } | 281 } |
277 | 282 |
278 std::string TemplateURLRef::ReplaceSearchTerms( | 283 std::string TemplateURLRef::ReplaceSearchTerms( |
279 const TemplateURL& host, | 284 const TemplateURL& host, |
280 const string16& terms, | 285 const string16& terms, |
281 int accepted_suggestion, | 286 int accepted_suggestion, |
282 const string16& original_query_for_suggestion) const { | 287 const string16& original_query_for_suggestion) const { |
| 288 return ReplaceSearchTermsUsingProfile(NULL, |
| 289 host, |
| 290 terms, |
| 291 accepted_suggestion, |
| 292 original_query_for_suggestion); |
| 293 } |
| 294 |
| 295 std::string TemplateURLRef::ReplaceSearchTermsUsingProfile( |
| 296 Profile* profile, |
| 297 const TemplateURL& host, |
| 298 const string16& terms, |
| 299 int accepted_suggestion, |
| 300 const string16& original_query_for_suggestion) const { |
283 UIThreadSearchTermsData search_terms_data; | 301 UIThreadSearchTermsData search_terms_data; |
| 302 search_terms_data.set_profile(profile); |
284 return ReplaceSearchTermsUsingTermsData(host, | 303 return ReplaceSearchTermsUsingTermsData(host, |
285 terms, | 304 terms, |
286 accepted_suggestion, | 305 accepted_suggestion, |
287 original_query_for_suggestion, | 306 original_query_for_suggestion, |
288 search_terms_data); | 307 search_terms_data); |
289 } | 308 } |
290 | 309 |
291 std::string TemplateURLRef::ReplaceSearchTermsUsingTermsData( | 310 std::string TemplateURLRef::ReplaceSearchTermsUsingTermsData( |
292 const TemplateURL& host, | 311 const TemplateURL& host, |
293 const string16& terms, | 312 const string16& terms, |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 break; | 387 break; |
369 | 388 |
370 case GOOGLE_BASE_URL: | 389 case GOOGLE_BASE_URL: |
371 url.insert(i->index, search_terms_data.GoogleBaseURLValue()); | 390 url.insert(i->index, search_terms_data.GoogleBaseURLValue()); |
372 break; | 391 break; |
373 | 392 |
374 case GOOGLE_BASE_SUGGEST_URL: | 393 case GOOGLE_BASE_SUGGEST_URL: |
375 url.insert(i->index, search_terms_data.GoogleBaseSuggestURLValue()); | 394 url.insert(i->index, search_terms_data.GoogleBaseSuggestURLValue()); |
376 break; | 395 break; |
377 | 396 |
| 397 case GOOGLE_INSTANT_FIELD_TRIAL_GROUP: |
| 398 url.insert(i->index, search_terms_data.InstantFieldTrialUrlParam()); |
| 399 break; |
| 400 |
378 case GOOGLE_ORIGINAL_QUERY_FOR_SUGGESTION: | 401 case GOOGLE_ORIGINAL_QUERY_FOR_SUGGESTION: |
379 if (accepted_suggestion >= 0) | 402 if (accepted_suggestion >= 0) |
380 url.insert(i->index, "oq=" + UTF16ToUTF8(encoded_original_query) + | 403 url.insert(i->index, "oq=" + UTF16ToUTF8(encoded_original_query) + |
381 "&"); | 404 "&"); |
382 break; | 405 break; |
383 | 406 |
384 case GOOGLE_RLZ: { | 407 case GOOGLE_RLZ: { |
385 // On platforms that don't have RLZ, we still want this branch | 408 // On platforms that don't have RLZ, we still want this branch |
386 // to happen so that we replace the RLZ template with the | 409 // to happen so that we replace the RLZ template with the |
387 // empty string. (If we don't handle this case, we hit a | 410 // empty string. (If we don't handle this case, we hit a |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 } | 752 } |
730 | 753 |
731 std::string TemplateURL::GetExtensionId() const { | 754 std::string TemplateURL::GetExtensionId() const { |
732 DCHECK(IsExtensionKeyword()); | 755 DCHECK(IsExtensionKeyword()); |
733 return GURL(url_.url()).host(); | 756 return GURL(url_.url()).host(); |
734 } | 757 } |
735 | 758 |
736 bool TemplateURL::IsExtensionKeyword() const { | 759 bool TemplateURL::IsExtensionKeyword() const { |
737 return GURL(url_.url()).SchemeIs(chrome::kExtensionScheme); | 760 return GURL(url_.url()).SchemeIs(chrome::kExtensionScheme); |
738 } | 761 } |
OLD | NEW |