Chromium Code Reviews| 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" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 "google:unescapedSearchTerms"; | 96 "google:unescapedSearchTerms"; |
| 97 const char kGoogleUnescapedSearchTermsParameterFull[] = | 97 const char kGoogleUnescapedSearchTermsParameterFull[] = |
| 98 "{google:unescapedSearchTerms}"; | 98 "{google:unescapedSearchTerms}"; |
| 99 | 99 |
| 100 const char kGoogleImageSearchSource[] = "google:imageSearchSource"; | 100 const char kGoogleImageSearchSource[] = "google:imageSearchSource"; |
| 101 const char kGoogleImageThumbnailParameter[] = "google:imageThumbnail"; | 101 const char kGoogleImageThumbnailParameter[] = "google:imageThumbnail"; |
| 102 const char kGoogleImageURLParameter[] = "google:imageURL"; | 102 const char kGoogleImageURLParameter[] = "google:imageURL"; |
| 103 const char kGoogleImageOriginalWidth[] = "google:imageOriginalWidth"; | 103 const char kGoogleImageOriginalWidth[] = "google:imageOriginalWidth"; |
| 104 const char kGoogleImageOriginalHeight[] = "google:imageOriginalHeight"; | 104 const char kGoogleImageOriginalHeight[] = "google:imageOriginalHeight"; |
| 105 | 105 |
| 106 // Contextual search parameters. | |
| 107 const char kGoogleContextualSearchVersion[] = "google:contextualSearchVersion"; | |
| 108 const char kGoogleContextualSearchStart[] = "google:contextualSearchStart"; | |
| 109 const char kGoogleContextualSearchEnd[] = "google:contextualSearchEnd"; | |
| 110 const char kGoogleContextualSearchContent[] = "google:contextualSearchContent"; | |
| 111 const char kGoogleContextualSearchBasePageURL[] = | |
| 112 "google:contextualSearchBasePageURL"; | |
| 113 const char kGoogleContextualSearchEncoding[] = | |
| 114 "google:contextualSearchEncoding"; | |
| 115 | |
| 106 // Display value for kSearchTermsParameter. | 116 // Display value for kSearchTermsParameter. |
| 107 const char kDisplaySearchTerms[] = "%s"; | 117 const char kDisplaySearchTerms[] = "%s"; |
| 108 | 118 |
| 109 // Display value for kGoogleUnescapedSearchTermsParameter. | 119 // Display value for kGoogleUnescapedSearchTermsParameter. |
| 110 const char kDisplayUnescapedSearchTerms[] = "%S"; | 120 const char kDisplayUnescapedSearchTerms[] = "%S"; |
| 111 | 121 |
| 112 // Used if the count parameter is not optional. Indicates we want 10 search | 122 // Used if the count parameter is not optional. Indicates we want 10 search |
| 113 // results. | 123 // results. |
| 114 const char kDefaultCount[] = "10"; | 124 const char kDefaultCount[] = "10"; |
| 115 | 125 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 | 208 |
| 199 | 209 |
| 200 // TemplateURLRef::SearchTermsArgs -------------------------------------------- | 210 // TemplateURLRef::SearchTermsArgs -------------------------------------------- |
| 201 | 211 |
| 202 TemplateURLRef::SearchTermsArgs::SearchTermsArgs( | 212 TemplateURLRef::SearchTermsArgs::SearchTermsArgs( |
| 203 const base::string16& search_terms) | 213 const base::string16& search_terms) |
| 204 : search_terms(search_terms), | 214 : search_terms(search_terms), |
| 205 accepted_suggestion(NO_SUGGESTIONS_AVAILABLE), | 215 accepted_suggestion(NO_SUGGESTIONS_AVAILABLE), |
| 206 cursor_position(base::string16::npos), | 216 cursor_position(base::string16::npos), |
| 207 omnibox_start_margin(-1), | 217 omnibox_start_margin(-1), |
| 218 contextual_search_version(-1), | |
| 219 contextual_search_start(-1), | |
| 220 contextual_search_end(-1), | |
| 208 page_classification(AutocompleteInput::INVALID_SPEC), | 221 page_classification(AutocompleteInput::INVALID_SPEC), |
| 209 bookmark_bar_pinned(false), | 222 bookmark_bar_pinned(false), |
| 210 append_extra_query_params(false), | 223 append_extra_query_params(false), |
| 211 force_instant_results(false), | 224 force_instant_results(false), |
| 212 from_app_list(false) { | 225 from_app_list(false) { |
| 213 } | 226 } |
| 214 | 227 |
| 215 TemplateURLRef::SearchTermsArgs::~SearchTermsArgs() { | 228 TemplateURLRef::SearchTermsArgs::~SearchTermsArgs() { |
| 216 } | 229 } |
| 217 | 230 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 244 showing_search_terms_(ShowingSearchTermsOnSRP()) { | 257 showing_search_terms_(ShowingSearchTermsOnSRP()) { |
| 245 DCHECK(owner_); | 258 DCHECK(owner_); |
| 246 DCHECK_LT(index_in_owner_, owner_->URLCount()); | 259 DCHECK_LT(index_in_owner_, owner_->URLCount()); |
| 247 } | 260 } |
| 248 | 261 |
| 249 TemplateURLRef::~TemplateURLRef() { | 262 TemplateURLRef::~TemplateURLRef() { |
| 250 } | 263 } |
| 251 | 264 |
| 252 std::string TemplateURLRef::GetURL() const { | 265 std::string TemplateURLRef::GetURL() const { |
| 253 switch (type_) { | 266 switch (type_) { |
| 254 case SEARCH: return owner_->url(); | 267 case SEARCH: return owner_->url(); |
| 255 case SUGGEST: return owner_->suggestions_url(); | 268 case SUGGEST: return owner_->suggestions_url(); |
| 256 case INSTANT: return owner_->instant_url(); | 269 case INSTANT: return owner_->instant_url(); |
| 257 case IMAGE: return owner_->image_url(); | 270 case IMAGE: return owner_->image_url(); |
| 258 case NEW_TAB: return owner_->new_tab_url(); | 271 case NEW_TAB: return owner_->new_tab_url(); |
| 259 case INDEXED: return owner_->GetURL(index_in_owner_); | 272 case CONTEXTUAL_SEARCH: return owner_->contextual_search_url(); |
| 260 default: NOTREACHED(); return std::string(); // NOLINT | 273 case INDEXED: return owner_->GetURL(index_in_owner_); |
| 274 default: NOTREACHED(); return std::string(); // NOLINT | |
| 261 } | 275 } |
| 262 } | 276 } |
| 263 | 277 |
| 264 std::string TemplateURLRef::GetPostParamsString() const { | 278 std::string TemplateURLRef::GetPostParamsString() const { |
| 265 switch (type_) { | 279 switch (type_) { |
| 266 case INDEXED: | 280 case INDEXED: |
| 267 case SEARCH: return owner_->search_url_post_params(); | 281 case SEARCH: return owner_->search_url_post_params(); |
| 268 case SUGGEST: return owner_->suggestions_url_post_params(); | 282 case SUGGEST: return owner_->suggestions_url_post_params(); |
| 269 case INSTANT: return owner_->instant_url_post_params(); | 283 case INSTANT: return owner_->instant_url_post_params(); |
| 270 case NEW_TAB: return std::string(); | 284 case NEW_TAB: return std::string(); |
| 271 case IMAGE: return owner_->image_url_post_params(); | 285 case CONTEXTUAL_SEARCH: return std::string(); |
| 286 case IMAGE: return owner_->image_url_post_params(); | |
| 272 default: NOTREACHED(); return std::string(); // NOLINT | 287 default: NOTREACHED(); return std::string(); // NOLINT |
| 273 } | 288 } |
| 274 } | 289 } |
| 275 | 290 |
| 276 bool TemplateURLRef::UsesPOSTMethodUsingTermsData( | 291 bool TemplateURLRef::UsesPOSTMethodUsingTermsData( |
| 277 const SearchTermsData* search_terms_data) const { | 292 const SearchTermsData* search_terms_data) const { |
| 278 if (search_terms_data) | 293 if (search_terms_data) |
| 279 ParseIfNecessaryUsingTermsData(*search_terms_data); | 294 ParseIfNecessaryUsingTermsData(*search_terms_data); |
| 280 else | 295 else |
| 281 ParseIfNecessary(); | 296 ParseIfNecessary(); |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 585 replacements->push_back(Replacement(GOOGLE_FORCE_INSTANT_RESULTS, start)); | 600 replacements->push_back(Replacement(GOOGLE_FORCE_INSTANT_RESULTS, start)); |
| 586 } else if (parameter == kGoogleInstantExtendedEnabledParameter) { | 601 } else if (parameter == kGoogleInstantExtendedEnabledParameter) { |
| 587 replacements->push_back(Replacement(GOOGLE_INSTANT_EXTENDED_ENABLED, | 602 replacements->push_back(Replacement(GOOGLE_INSTANT_EXTENDED_ENABLED, |
| 588 start)); | 603 start)); |
| 589 } else if (parameter == kGoogleInstantExtendedEnabledKey) { | 604 } else if (parameter == kGoogleInstantExtendedEnabledKey) { |
| 590 url->insert(start, google_util::kInstantExtendedAPIParam); | 605 url->insert(start, google_util::kInstantExtendedAPIParam); |
| 591 } else if (parameter == kGoogleNTPIsThemedParameter) { | 606 } else if (parameter == kGoogleNTPIsThemedParameter) { |
| 592 replacements->push_back(Replacement(GOOGLE_NTP_IS_THEMED, start)); | 607 replacements->push_back(Replacement(GOOGLE_NTP_IS_THEMED, start)); |
| 593 } else if (parameter == kGoogleOmniboxStartMarginParameter) { | 608 } else if (parameter == kGoogleOmniboxStartMarginParameter) { |
| 594 replacements->push_back(Replacement(GOOGLE_OMNIBOX_START_MARGIN, start)); | 609 replacements->push_back(Replacement(GOOGLE_OMNIBOX_START_MARGIN, start)); |
| 610 } else if (parameter == kGoogleContextualSearchVersion) { | |
| 611 replacements->push_back( | |
| 612 Replacement(GOOGLE_CONTEXTUAL_SEARCH_VERSION, start)); | |
| 613 } else if (parameter == kGoogleContextualSearchStart) { | |
| 614 replacements->push_back( | |
| 615 Replacement(GOOGLE_CONTEXTUAL_SEARCH_START, start)); | |
| 616 } else if (parameter == kGoogleContextualSearchEnd) { | |
| 617 replacements->push_back( | |
| 618 Replacement(GOOGLE_CONTEXTUAL_SEARCH_END, start)); | |
| 619 } else if (parameter == kGoogleContextualSearchContent) { | |
| 620 replacements->push_back( | |
| 621 Replacement(GOOGLE_CONTEXTUAL_SEARCH_CONTENT, start)); | |
| 622 } else if (parameter == kGoogleContextualSearchBasePageURL) { | |
| 623 replacements->push_back( | |
| 624 Replacement(GOOGLE_CONTEXTUAL_SEARCH_BASE_PAGE_URL, start)); | |
| 625 } else if (parameter == kGoogleContextualSearchEncoding) { | |
| 626 replacements->push_back( | |
| 627 Replacement(GOOGLE_CONTEXTUAL_SEARCH_ENCODING, start)); | |
| 595 } else if (parameter == kGoogleOriginalQueryForSuggestionParameter) { | 628 } else if (parameter == kGoogleOriginalQueryForSuggestionParameter) { |
| 596 replacements->push_back(Replacement(GOOGLE_ORIGINAL_QUERY_FOR_SUGGESTION, | 629 replacements->push_back(Replacement(GOOGLE_ORIGINAL_QUERY_FOR_SUGGESTION, |
| 597 start)); | 630 start)); |
| 598 } else if (parameter == kGooglePageClassificationParameter) { | 631 } else if (parameter == kGooglePageClassificationParameter) { |
| 599 replacements->push_back(Replacement(GOOGLE_PAGE_CLASSIFICATION, start)); | 632 replacements->push_back(Replacement(GOOGLE_PAGE_CLASSIFICATION, start)); |
| 600 } else if (parameter == kGoogleRLZParameter) { | 633 } else if (parameter == kGoogleRLZParameter) { |
| 601 replacements->push_back(Replacement(GOOGLE_RLZ, start)); | 634 replacements->push_back(Replacement(GOOGLE_RLZ, start)); |
| 602 } else if (parameter == kGoogleSearchClient) { | 635 } else if (parameter == kGoogleSearchClient) { |
| 603 replacements->push_back(Replacement(GOOGLE_SEARCH_CLIENT, start)); | 636 replacements->push_back(Replacement(GOOGLE_SEARCH_CLIENT, start)); |
| 604 } else if (parameter == kGoogleSearchFieldtrialParameter) { | 637 } else if (parameter == kGoogleSearchFieldtrialParameter) { |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 921 DCHECK(!i->is_post_param); | 954 DCHECK(!i->is_post_param); |
| 922 if (search_terms_args.omnibox_start_margin >= 0) { | 955 if (search_terms_args.omnibox_start_margin >= 0) { |
| 923 HandleReplacement( | 956 HandleReplacement( |
| 924 "es_sm", | 957 "es_sm", |
| 925 base::IntToString(search_terms_args.omnibox_start_margin), | 958 base::IntToString(search_terms_args.omnibox_start_margin), |
| 926 *i, | 959 *i, |
| 927 &url); | 960 &url); |
| 928 } | 961 } |
| 929 break; | 962 break; |
| 930 | 963 |
| 964 case GOOGLE_CONTEXTUAL_SEARCH_VERSION: | |
| 965 DCHECK(!i->is_post_param); | |
|
Peter Kasting
2014/06/03 21:47:09
Why are you putting this on all these cases? It s
jeremycho
2014/06/04 00:22:11
Done. In fact, we may ultimately send this as a P
Peter Kasting
2014/06/04 00:40:49
Unfortunately, you changed several of these to onl
jeremycho
2014/06/04 03:33:04
Not sure I follow how the single replacement strin
Peter Kasting
2014/06/04 06:56:21
Frankly, I don't know. I didn't write any of the
| |
| 966 if (search_terms_args.contextual_search_version >= 0) { | |
| 967 HandleReplacement( | |
| 968 "ctxs", | |
| 969 base::IntToString(search_terms_args.contextual_search_version), | |
| 970 *i, | |
| 971 &url); | |
| 972 } | |
| 973 break; | |
| 974 | |
| 975 case GOOGLE_CONTEXTUAL_SEARCH_START: | |
| 976 DCHECK(!i->is_post_param); | |
| 977 if (search_terms_args.contextual_search_start >= 0) { | |
| 978 HandleReplacement( | |
| 979 "ctxs_start", | |
| 980 base::IntToString(search_terms_args.contextual_search_start), | |
| 981 *i, | |
| 982 &url); | |
| 983 } | |
| 984 break; | |
| 985 | |
| 986 case GOOGLE_CONTEXTUAL_SEARCH_END: | |
| 987 DCHECK(!i->is_post_param); | |
| 988 if (search_terms_args.contextual_search_end >= 0) { | |
| 989 HandleReplacement( | |
| 990 "ctxs_end", | |
| 991 base::IntToString(search_terms_args.contextual_search_end), | |
| 992 *i, | |
| 993 &url); | |
| 994 } | |
| 995 break; | |
| 996 | |
| 997 case GOOGLE_CONTEXTUAL_SEARCH_CONTENT: { | |
| 998 DCHECK(!i->is_post_param); | |
| 999 const std::string content = search_terms_args.contextual_search_content; | |
| 1000 if (!content.empty()) | |
| 1001 HandleReplacement("ctxs_content", content, *i, &url); | |
| 1002 break; | |
| 1003 } | |
| 1004 | |
| 1005 case GOOGLE_CONTEXTUAL_SEARCH_BASE_PAGE_URL: { | |
| 1006 DCHECK(!i->is_post_param); | |
| 1007 const std::string base_page_url = | |
| 1008 search_terms_args.contextual_search_base_page_url; | |
| 1009 if (!base_page_url.empty()) | |
| 1010 HandleReplacement("ctxs_url", base_page_url, *i, &url); | |
| 1011 break; | |
| 1012 } | |
| 1013 | |
| 1014 case GOOGLE_CONTEXTUAL_SEARCH_ENCODING: { | |
| 1015 DCHECK(!i->is_post_param); | |
| 1016 const std::string encoding = | |
| 1017 search_terms_args.contextual_search_encoding; | |
| 1018 if (!encoding.empty()) | |
| 1019 HandleReplacement("ctxs_encoding", encoding, *i, &url); | |
| 1020 break; | |
| 1021 } | |
| 1022 | |
| 931 case GOOGLE_ORIGINAL_QUERY_FOR_SUGGESTION: | 1023 case GOOGLE_ORIGINAL_QUERY_FOR_SUGGESTION: |
| 932 DCHECK(!i->is_post_param); | 1024 DCHECK(!i->is_post_param); |
| 933 if (search_terms_args.accepted_suggestion >= 0 || | 1025 if (search_terms_args.accepted_suggestion >= 0 || |
| 934 !search_terms_args.assisted_query_stats.empty()) { | 1026 !search_terms_args.assisted_query_stats.empty()) { |
| 935 HandleReplacement( | 1027 HandleReplacement( |
| 936 "oq", base::UTF16ToUTF8(encoded_original_query), *i, &url); | 1028 "oq", base::UTF16ToUTF8(encoded_original_query), *i, &url); |
| 937 } | 1029 } |
| 938 break; | 1030 break; |
| 939 | 1031 |
| 940 case GOOGLE_PAGE_CLASSIFICATION: | 1032 case GOOGLE_PAGE_CLASSIFICATION: |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1092 | 1184 |
| 1093 TemplateURL::TemplateURL(Profile* profile, const TemplateURLData& data) | 1185 TemplateURL::TemplateURL(Profile* profile, const TemplateURLData& data) |
| 1094 : profile_(profile), | 1186 : profile_(profile), |
| 1095 data_(data), | 1187 data_(data), |
| 1096 url_ref_(this, TemplateURLRef::SEARCH), | 1188 url_ref_(this, TemplateURLRef::SEARCH), |
| 1097 suggestions_url_ref_(this, | 1189 suggestions_url_ref_(this, |
| 1098 TemplateURLRef::SUGGEST), | 1190 TemplateURLRef::SUGGEST), |
| 1099 instant_url_ref_(this, | 1191 instant_url_ref_(this, |
| 1100 TemplateURLRef::INSTANT), | 1192 TemplateURLRef::INSTANT), |
| 1101 image_url_ref_(this, TemplateURLRef::IMAGE), | 1193 image_url_ref_(this, TemplateURLRef::IMAGE), |
| 1102 new_tab_url_ref_(this, TemplateURLRef::NEW_TAB) { | 1194 new_tab_url_ref_(this, TemplateURLRef::NEW_TAB), |
| 1195 contextual_search_url_ref_(this, TemplateURLRef::CONTEXTUAL_SEARCH) { | |
| 1103 SetPrepopulateId(data_.prepopulate_id); | 1196 SetPrepopulateId(data_.prepopulate_id); |
| 1104 | 1197 |
| 1105 if (data_.search_terms_replacement_key == | 1198 if (data_.search_terms_replacement_key == |
| 1106 kGoogleInstantExtendedEnabledKeyFull) { | 1199 kGoogleInstantExtendedEnabledKeyFull) { |
| 1107 data_.search_terms_replacement_key = google_util::kInstantExtendedAPIParam; | 1200 data_.search_terms_replacement_key = google_util::kInstantExtendedAPIParam; |
| 1108 } | 1201 } |
| 1109 } | 1202 } |
| 1110 | 1203 |
| 1111 TemplateURL::~TemplateURL() { | 1204 TemplateURL::~TemplateURL() { |
| 1112 } | 1205 } |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1380 // patterns. This means that given patterns | 1473 // patterns. This means that given patterns |
| 1381 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], | 1474 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], |
| 1382 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would | 1475 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would |
| 1383 // return false. This is important for at least Google, where such URLs | 1476 // return false. This is important for at least Google, where such URLs |
| 1384 // are invalid. | 1477 // are invalid. |
| 1385 return !search_terms->empty(); | 1478 return !search_terms->empty(); |
| 1386 } | 1479 } |
| 1387 } | 1480 } |
| 1388 return false; | 1481 return false; |
| 1389 } | 1482 } |
| OLD | NEW |