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 { |
283 UIThreadSearchTermsData search_terms_data; | 288 UIThreadSearchTermsData search_terms_data; |
Peter Kasting
2011/08/11 18:04:34
Nit: Just implement this function by calling Repla
sreeram
2011/08/11 18:22:19
Done.
| |
284 return ReplaceSearchTermsUsingTermsData(host, | 289 return ReplaceSearchTermsUsingTermsData(host, |
285 terms, | 290 terms, |
286 accepted_suggestion, | 291 accepted_suggestion, |
287 original_query_for_suggestion, | 292 original_query_for_suggestion, |
288 search_terms_data); | 293 search_terms_data); |
289 } | 294 } |
290 | 295 |
296 std::string TemplateURLRef::ReplaceSearchTermsUsingProfile( | |
297 Profile* profile, | |
298 const TemplateURL& host, | |
299 const string16& terms, | |
300 int accepted_suggestion, | |
301 const string16& original_query_for_suggestion) const { | |
302 UIThreadSearchTermsData search_terms_data; | |
303 search_terms_data.SetProfile(profile); | |
304 return ReplaceSearchTermsUsingTermsData(host, | |
305 terms, | |
306 accepted_suggestion, | |
307 original_query_for_suggestion, | |
308 search_terms_data); | |
309 } | |
310 | |
291 std::string TemplateURLRef::ReplaceSearchTermsUsingTermsData( | 311 std::string TemplateURLRef::ReplaceSearchTermsUsingTermsData( |
292 const TemplateURL& host, | 312 const TemplateURL& host, |
293 const string16& terms, | 313 const string16& terms, |
294 int accepted_suggestion, | 314 int accepted_suggestion, |
295 const string16& original_query_for_suggestion, | 315 const string16& original_query_for_suggestion, |
296 const SearchTermsData& search_terms_data) const { | 316 const SearchTermsData& search_terms_data) const { |
297 ParseIfNecessaryUsingTermsData(search_terms_data); | 317 ParseIfNecessaryUsingTermsData(search_terms_data); |
298 if (!valid_) | 318 if (!valid_) |
299 return std::string(); | 319 return std::string(); |
300 | 320 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
368 break; | 388 break; |
369 | 389 |
370 case GOOGLE_BASE_URL: | 390 case GOOGLE_BASE_URL: |
371 url.insert(i->index, search_terms_data.GoogleBaseURLValue()); | 391 url.insert(i->index, search_terms_data.GoogleBaseURLValue()); |
372 break; | 392 break; |
373 | 393 |
374 case GOOGLE_BASE_SUGGEST_URL: | 394 case GOOGLE_BASE_SUGGEST_URL: |
375 url.insert(i->index, search_terms_data.GoogleBaseSuggestURLValue()); | 395 url.insert(i->index, search_terms_data.GoogleBaseSuggestURLValue()); |
376 break; | 396 break; |
377 | 397 |
398 case GOOGLE_INSTANT_FIELD_TRIAL_GROUP: | |
399 url.insert(i->index, search_terms_data.InstantFieldTrialUrlParam()); | |
400 break; | |
401 | |
378 case GOOGLE_ORIGINAL_QUERY_FOR_SUGGESTION: | 402 case GOOGLE_ORIGINAL_QUERY_FOR_SUGGESTION: |
379 if (accepted_suggestion >= 0) | 403 if (accepted_suggestion >= 0) |
380 url.insert(i->index, "oq=" + UTF16ToUTF8(encoded_original_query) + | 404 url.insert(i->index, "oq=" + UTF16ToUTF8(encoded_original_query) + |
381 "&"); | 405 "&"); |
382 break; | 406 break; |
383 | 407 |
384 case GOOGLE_RLZ: { | 408 case GOOGLE_RLZ: { |
385 // On platforms that don't have RLZ, we still want this branch | 409 // On platforms that don't have RLZ, we still want this branch |
386 // to happen so that we replace the RLZ template with the | 410 // to happen so that we replace the RLZ template with the |
387 // empty string. (If we don't handle this case, we hit a | 411 // 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 } | 753 } |
730 | 754 |
731 std::string TemplateURL::GetExtensionId() const { | 755 std::string TemplateURL::GetExtensionId() const { |
732 DCHECK(IsExtensionKeyword()); | 756 DCHECK(IsExtensionKeyword()); |
733 return GURL(url_.url()).host(); | 757 return GURL(url_.url()).host(); |
734 } | 758 } |
735 | 759 |
736 bool TemplateURL::IsExtensionKeyword() const { | 760 bool TemplateURL::IsExtensionKeyword() const { |
737 return GURL(url_.url()).SchemeIs(chrome::kExtensionScheme); | 761 return GURL(url_.url()).SchemeIs(chrome::kExtensionScheme); |
738 } | 762 } |
OLD | NEW |