| 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 <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/format_macros.h" | 12 #include "base/format_macros.h" |
| 13 #include "base/i18n/icu_string_conversions.h" | 13 #include "base/i18n/icu_string_conversions.h" |
| 14 #include "base/i18n/rtl.h" | 14 #include "base/i18n/rtl.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/metrics/field_trial.h" | 16 #include "base/metrics/field_trial.h" |
| 17 #include "base/rand_util.h" | 17 #include "base/rand_util.h" |
| 18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/strings/string_split.h" | 19 #include "base/strings/string_split.h" |
| 20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 21 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 23 #include "chrome/browser/google/google_util.h" | 23 #include "chrome/browser/google/google_util.h" |
| 24 #include "chrome/browser/search/search.h" | 24 #include "chrome/browser/search/search.h" |
| 25 #include "chrome/browser/search_engines/template_url_service.h" | 25 #include "chrome/browser/search_engines/template_url_service.h" |
| 26 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
| 27 #include "chrome/common/chrome_version_info.h" | |
| 28 #include "components/metrics/proto/omnibox_input_type.pb.h" | 27 #include "components/metrics/proto/omnibox_input_type.pb.h" |
| 29 #include "components/search_engines/search_terms_data.h" | 28 #include "components/search_engines/search_terms_data.h" |
| 30 #include "extensions/common/constants.h" | 29 #include "extensions/common/constants.h" |
| 31 #include "google_apis/google_api_keys.h" | 30 #include "google_apis/google_api_keys.h" |
| 32 #include "net/base/escape.h" | 31 #include "net/base/escape.h" |
| 33 #include "net/base/mime_util.h" | 32 #include "net/base/mime_util.h" |
| 34 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
| 35 | 34 |
| 36 namespace { | 35 namespace { |
| 37 | 36 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 std::string::npos || | 160 std::string::npos || |
| 162 value_string.find(kGoogleUnescapedSearchTermsParameterFull, 0) != | 161 value_string.find(kGoogleUnescapedSearchTermsParameterFull, 0) != |
| 163 std::string::npos) { | 162 std::string::npos) { |
| 164 return params.substr(key.begin, key.len); | 163 return params.substr(key.begin, key.len); |
| 165 } | 164 } |
| 166 } | 165 } |
| 167 } | 166 } |
| 168 return std::string(); | 167 return std::string(); |
| 169 } | 168 } |
| 170 | 169 |
| 171 // Returns the string to use for replacements of type | |
| 172 // GOOGLE_IMAGE_SEARCH_SOURCE. | |
| 173 std::string GetGoogleImageSearchSource() { | |
| 174 chrome::VersionInfo version_info; | |
| 175 if (version_info.is_valid()) { | |
| 176 std::string version(version_info.Name() + " " + version_info.Version()); | |
| 177 if (version_info.IsOfficialBuild()) | |
| 178 version += " (Official)"; | |
| 179 version += " " + version_info.OSType(); | |
| 180 std::string modifier(version_info.GetVersionStringModifier()); | |
| 181 if (!modifier.empty()) | |
| 182 version += " " + modifier; | |
| 183 return version; | |
| 184 } | |
| 185 return "unknown"; | |
| 186 } | |
| 187 | |
| 188 bool IsTemplateParameterString(const std::string& param) { | 170 bool IsTemplateParameterString(const std::string& param) { |
| 189 return (param.length() > 2) && (*(param.begin()) == kStartParameter) && | 171 return (param.length() > 2) && (*(param.begin()) == kStartParameter) && |
| 190 (*(param.rbegin()) == kEndParameter); | 172 (*(param.rbegin()) == kEndParameter); |
| 191 } | 173 } |
| 192 | 174 |
| 193 bool ShowingSearchTermsOnSRP() { | 175 bool ShowingSearchTermsOnSRP() { |
| 194 return chrome::IsInstantExtendedAPIEnabled() && | 176 return chrome::IsInstantExtendedAPIEnabled() && |
| 195 chrome::IsQueryExtractionEnabled(); | 177 chrome::IsQueryExtractionEnabled(); |
| 196 } | 178 } |
| 197 | 179 |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 replacements->push_back(Replacement(GOOGLE_CURSOR_POSITION, start)); | 567 replacements->push_back(Replacement(GOOGLE_CURSOR_POSITION, start)); |
| 586 } else if (parameter == kGoogleForceInstantResultsParameter) { | 568 } else if (parameter == kGoogleForceInstantResultsParameter) { |
| 587 replacements->push_back(Replacement(GOOGLE_FORCE_INSTANT_RESULTS, start)); | 569 replacements->push_back(Replacement(GOOGLE_FORCE_INSTANT_RESULTS, start)); |
| 588 } else if (parameter == kGoogleImageOriginalHeight) { | 570 } else if (parameter == kGoogleImageOriginalHeight) { |
| 589 replacements->push_back( | 571 replacements->push_back( |
| 590 Replacement(TemplateURLRef::GOOGLE_IMAGE_ORIGINAL_HEIGHT, start)); | 572 Replacement(TemplateURLRef::GOOGLE_IMAGE_ORIGINAL_HEIGHT, start)); |
| 591 } else if (parameter == kGoogleImageOriginalWidth) { | 573 } else if (parameter == kGoogleImageOriginalWidth) { |
| 592 replacements->push_back( | 574 replacements->push_back( |
| 593 Replacement(TemplateURLRef::GOOGLE_IMAGE_ORIGINAL_WIDTH, start)); | 575 Replacement(TemplateURLRef::GOOGLE_IMAGE_ORIGINAL_WIDTH, start)); |
| 594 } else if (parameter == kGoogleImageSearchSource) { | 576 } else if (parameter == kGoogleImageSearchSource) { |
| 595 url->insert(start, GetGoogleImageSearchSource()); | 577 replacements->push_back( |
| 578 Replacement(TemplateURLRef::GOOGLE_IMAGE_SEARCH_SOURCE, start)); |
| 596 } else if (parameter == kGoogleImageThumbnailParameter) { | 579 } else if (parameter == kGoogleImageThumbnailParameter) { |
| 597 replacements->push_back( | 580 replacements->push_back( |
| 598 Replacement(TemplateURLRef::GOOGLE_IMAGE_THUMBNAIL, start)); | 581 Replacement(TemplateURLRef::GOOGLE_IMAGE_THUMBNAIL, start)); |
| 599 } else if (parameter == kGoogleImageURLParameter) { | 582 } else if (parameter == kGoogleImageURLParameter) { |
| 600 replacements->push_back(Replacement(TemplateURLRef::GOOGLE_IMAGE_URL, | 583 replacements->push_back(Replacement(TemplateURLRef::GOOGLE_IMAGE_URL, |
| 601 start)); | 584 start)); |
| 602 } else if (parameter == kGoogleInputTypeParameter) { | 585 } else if (parameter == kGoogleInputTypeParameter) { |
| 603 replacements->push_back(Replacement(TemplateURLRef::GOOGLE_INPUT_TYPE, | 586 replacements->push_back(Replacement(TemplateURLRef::GOOGLE_INPUT_TYPE, |
| 604 start)); | 587 start)); |
| 605 } else if (parameter == kGoogleInstantExtendedEnabledParameter) { | 588 } else if (parameter == kGoogleInstantExtendedEnabledParameter) { |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1106 | 1089 |
| 1107 case GOOGLE_IMAGE_ORIGINAL_HEIGHT: | 1090 case GOOGLE_IMAGE_ORIGINAL_HEIGHT: |
| 1108 if (!search_terms_args.image_original_size.IsEmpty()) { | 1091 if (!search_terms_args.image_original_size.IsEmpty()) { |
| 1109 HandleReplacement( | 1092 HandleReplacement( |
| 1110 std::string(), | 1093 std::string(), |
| 1111 base::IntToString(search_terms_args.image_original_size.height()), | 1094 base::IntToString(search_terms_args.image_original_size.height()), |
| 1112 *i, &url); | 1095 *i, &url); |
| 1113 } | 1096 } |
| 1114 break; | 1097 break; |
| 1115 | 1098 |
| 1099 case GOOGLE_IMAGE_SEARCH_SOURCE: |
| 1100 HandleReplacement( |
| 1101 std::string(), search_terms_data.GoogleImageSearchSource(), *i, |
| 1102 &url); |
| 1103 break; |
| 1104 |
| 1116 default: | 1105 default: |
| 1117 NOTREACHED(); | 1106 NOTREACHED(); |
| 1118 break; | 1107 break; |
| 1119 } | 1108 } |
| 1120 } | 1109 } |
| 1121 | 1110 |
| 1122 if (!post_params_.empty()) | 1111 if (!post_params_.empty()) |
| 1123 EncodeFormData(post_params_, post_content); | 1112 EncodeFormData(post_params_, post_content); |
| 1124 | 1113 |
| 1125 return url; | 1114 return url; |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1409 // patterns. This means that given patterns | 1398 // patterns. This means that given patterns |
| 1410 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], | 1399 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], |
| 1411 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would | 1400 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would |
| 1412 // return false. This is important for at least Google, where such URLs | 1401 // return false. This is important for at least Google, where such URLs |
| 1413 // are invalid. | 1402 // are invalid. |
| 1414 return !search_terms->empty(); | 1403 return !search_terms->empty(); |
| 1415 } | 1404 } |
| 1416 } | 1405 } |
| 1417 return false; | 1406 return false; |
| 1418 } | 1407 } |
| OLD | NEW |