| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/search_engines/template_url.h" | 5 #include "components/search_engines/template_url.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 | 141 |
| 142 | 142 |
| 143 // TemplateURLRef::SearchTermsArgs -------------------------------------------- | 143 // TemplateURLRef::SearchTermsArgs -------------------------------------------- |
| 144 | 144 |
| 145 TemplateURLRef::SearchTermsArgs::SearchTermsArgs( | 145 TemplateURLRef::SearchTermsArgs::SearchTermsArgs( |
| 146 const base::string16& search_terms) | 146 const base::string16& search_terms) |
| 147 : search_terms(search_terms), | 147 : search_terms(search_terms), |
| 148 input_type(metrics::OmniboxInputType::INVALID), | 148 input_type(metrics::OmniboxInputType::INVALID), |
| 149 accepted_suggestion(NO_SUGGESTIONS_AVAILABLE), | 149 accepted_suggestion(NO_SUGGESTIONS_AVAILABLE), |
| 150 cursor_position(base::string16::npos), | 150 cursor_position(base::string16::npos), |
| 151 enable_omnibox_start_margin(false), | |
| 152 page_classification(metrics::OmniboxEventProto::INVALID_SPEC), | 151 page_classification(metrics::OmniboxEventProto::INVALID_SPEC), |
| 153 bookmark_bar_pinned(false), | |
| 154 append_extra_query_params(false), | 152 append_extra_query_params(false), |
| 155 force_instant_results(false), | 153 force_instant_results(false), |
| 156 from_app_list(false), | 154 from_app_list(false), |
| 157 contextual_search_params(ContextualSearchParams()) { | 155 contextual_search_params(ContextualSearchParams()) { |
| 158 } | 156 } |
| 159 | 157 |
| 160 TemplateURLRef::SearchTermsArgs::~SearchTermsArgs() { | 158 TemplateURLRef::SearchTermsArgs::~SearchTermsArgs() { |
| 161 } | 159 } |
| 162 | 160 |
| 163 TemplateURLRef::SearchTermsArgs::ContextualSearchParams:: | 161 TemplateURLRef::SearchTermsArgs::ContextualSearchParams:: |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 replacements->push_back(Replacement(SEARCH_TERMS, start)); | 562 replacements->push_back(Replacement(SEARCH_TERMS, start)); |
| 565 } else if (parameter == "count") { | 563 } else if (parameter == "count") { |
| 566 if (!optional) | 564 if (!optional) |
| 567 url->insert(start, kDefaultCount); | 565 url->insert(start, kDefaultCount); |
| 568 } else if (parameter == "google:assistedQueryStats") { | 566 } else if (parameter == "google:assistedQueryStats") { |
| 569 replacements->push_back(Replacement(GOOGLE_ASSISTED_QUERY_STATS, start)); | 567 replacements->push_back(Replacement(GOOGLE_ASSISTED_QUERY_STATS, start)); |
| 570 } else if (parameter == "google:baseURL") { | 568 } else if (parameter == "google:baseURL") { |
| 571 replacements->push_back(Replacement(GOOGLE_BASE_URL, start)); | 569 replacements->push_back(Replacement(GOOGLE_BASE_URL, start)); |
| 572 } else if (parameter == "google:baseSuggestURL") { | 570 } else if (parameter == "google:baseSuggestURL") { |
| 573 replacements->push_back(Replacement(GOOGLE_BASE_SUGGEST_URL, start)); | 571 replacements->push_back(Replacement(GOOGLE_BASE_SUGGEST_URL, start)); |
| 574 } else if (parameter == "google:bookmarkBarPinned") { | |
| 575 replacements->push_back(Replacement(GOOGLE_BOOKMARK_BAR_PINNED, start)); | |
| 576 } else if (parameter == "google:currentPageUrl") { | 572 } else if (parameter == "google:currentPageUrl") { |
| 577 replacements->push_back(Replacement(GOOGLE_CURRENT_PAGE_URL, start)); | 573 replacements->push_back(Replacement(GOOGLE_CURRENT_PAGE_URL, start)); |
| 578 } else if (parameter == "google:cursorPosition") { | 574 } else if (parameter == "google:cursorPosition") { |
| 579 replacements->push_back(Replacement(GOOGLE_CURSOR_POSITION, start)); | 575 replacements->push_back(Replacement(GOOGLE_CURSOR_POSITION, start)); |
| 580 } else if (parameter == "google:forceInstantResults") { | 576 } else if (parameter == "google:forceInstantResults") { |
| 581 replacements->push_back(Replacement(GOOGLE_FORCE_INSTANT_RESULTS, start)); | 577 replacements->push_back(Replacement(GOOGLE_FORCE_INSTANT_RESULTS, start)); |
| 582 } else if (parameter == "google:imageOriginalHeight") { | 578 } else if (parameter == "google:imageOriginalHeight") { |
| 583 replacements->push_back( | 579 replacements->push_back( |
| 584 Replacement(TemplateURLRef::GOOGLE_IMAGE_ORIGINAL_HEIGHT, start)); | 580 Replacement(TemplateURLRef::GOOGLE_IMAGE_ORIGINAL_HEIGHT, start)); |
| 585 } else if (parameter == "google:imageOriginalWidth") { | 581 } else if (parameter == "google:imageOriginalWidth") { |
| 586 replacements->push_back( | 582 replacements->push_back( |
| 587 Replacement(TemplateURLRef::GOOGLE_IMAGE_ORIGINAL_WIDTH, start)); | 583 Replacement(TemplateURLRef::GOOGLE_IMAGE_ORIGINAL_WIDTH, start)); |
| 588 } else if (parameter == "google:imageSearchSource") { | 584 } else if (parameter == "google:imageSearchSource") { |
| 589 replacements->push_back( | 585 replacements->push_back( |
| 590 Replacement(TemplateURLRef::GOOGLE_IMAGE_SEARCH_SOURCE, start)); | 586 Replacement(TemplateURLRef::GOOGLE_IMAGE_SEARCH_SOURCE, start)); |
| 591 } else if (parameter == "google:imageThumbnail") { | 587 } else if (parameter == "google:imageThumbnail") { |
| 592 replacements->push_back( | 588 replacements->push_back( |
| 593 Replacement(TemplateURLRef::GOOGLE_IMAGE_THUMBNAIL, start)); | 589 Replacement(TemplateURLRef::GOOGLE_IMAGE_THUMBNAIL, start)); |
| 594 } else if (parameter == "google:imageURL") { | 590 } else if (parameter == "google:imageURL") { |
| 595 replacements->push_back(Replacement(TemplateURLRef::GOOGLE_IMAGE_URL, | 591 replacements->push_back(Replacement(TemplateURLRef::GOOGLE_IMAGE_URL, |
| 596 start)); | 592 start)); |
| 597 } else if (parameter == "google:inputType") { | 593 } else if (parameter == "google:inputType") { |
| 598 replacements->push_back(Replacement(TemplateURLRef::GOOGLE_INPUT_TYPE, | 594 replacements->push_back(Replacement(TemplateURLRef::GOOGLE_INPUT_TYPE, |
| 599 start)); | 595 start)); |
| 600 } else if (parameter == "google:instantExtendedEnabledParameter") { | 596 } else if (parameter == "google:instantExtendedEnabledParameter") { |
| 601 replacements->push_back(Replacement(GOOGLE_INSTANT_EXTENDED_ENABLED, | 597 replacements->push_back(Replacement(GOOGLE_INSTANT_EXTENDED_ENABLED, |
| 602 start)); | 598 start)); |
| 603 } else if (parameter == "google:instantExtendedEnabledKey") { | 599 } else if (parameter == "google:instantExtendedEnabledKey") { |
| 604 url->insert(start, google_util::kInstantExtendedAPIParam); | 600 url->insert(start, google_util::kInstantExtendedAPIParam); |
| 605 } else if (parameter == "google:ntpIsThemedParameter") { | |
| 606 replacements->push_back(Replacement(GOOGLE_NTP_IS_THEMED, start)); | |
| 607 } else if (parameter == "google:omniboxStartMarginParameter") { | |
| 608 replacements->push_back(Replacement(GOOGLE_OMNIBOX_START_MARGIN, start)); | |
| 609 } else if (parameter == "google:contextualSearchVersion") { | 601 } else if (parameter == "google:contextualSearchVersion") { |
| 610 replacements->push_back( | 602 replacements->push_back( |
| 611 Replacement(GOOGLE_CONTEXTUAL_SEARCH_VERSION, start)); | 603 Replacement(GOOGLE_CONTEXTUAL_SEARCH_VERSION, start)); |
| 612 } else if (parameter == "google:contextualSearchContextData") { | 604 } else if (parameter == "google:contextualSearchContextData") { |
| 613 replacements->push_back( | 605 replacements->push_back( |
| 614 Replacement(GOOGLE_CONTEXTUAL_SEARCH_CONTEXT_DATA, start)); | 606 Replacement(GOOGLE_CONTEXTUAL_SEARCH_CONTEXT_DATA, start)); |
| 615 } else if (parameter == "google:originalQueryForSuggestion") { | 607 } else if (parameter == "google:originalQueryForSuggestion") { |
| 616 replacements->push_back(Replacement(GOOGLE_ORIGINAL_QUERY_FOR_SUGGESTION, | 608 replacements->push_back(Replacement(GOOGLE_ORIGINAL_QUERY_FOR_SUGGESTION, |
| 617 start)); | 609 start)); |
| 618 } else if (parameter == "google:pageClassification") { | 610 } else if (parameter == "google:pageClassification") { |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 std::string(), search_terms_data.GoogleBaseURLValue(), *i, &url); | 889 std::string(), search_terms_data.GoogleBaseURLValue(), *i, &url); |
| 898 break; | 890 break; |
| 899 | 891 |
| 900 case GOOGLE_BASE_SUGGEST_URL: | 892 case GOOGLE_BASE_SUGGEST_URL: |
| 901 DCHECK(!i->is_post_param); | 893 DCHECK(!i->is_post_param); |
| 902 HandleReplacement( | 894 HandleReplacement( |
| 903 std::string(), search_terms_data.GoogleBaseSuggestURLValue(), *i, | 895 std::string(), search_terms_data.GoogleBaseSuggestURLValue(), *i, |
| 904 &url); | 896 &url); |
| 905 break; | 897 break; |
| 906 | 898 |
| 907 case GOOGLE_BOOKMARK_BAR_PINNED: | |
| 908 if (search_terms_data.IsShowingSearchTermsOnSearchResultsPages()) { | |
| 909 // Log whether the bookmark bar is pinned when the user is seeing | |
| 910 // InstantExtended on the SRP. | |
| 911 DCHECK(!i->is_post_param); | |
| 912 HandleReplacement( | |
| 913 "bmbp", search_terms_args.bookmark_bar_pinned ? "1" : "0", *i, | |
| 914 &url); | |
| 915 } | |
| 916 break; | |
| 917 | |
| 918 case GOOGLE_CURRENT_PAGE_URL: | 899 case GOOGLE_CURRENT_PAGE_URL: |
| 919 DCHECK(!i->is_post_param); | 900 DCHECK(!i->is_post_param); |
| 920 if (!search_terms_args.current_page_url.empty()) { | 901 if (!search_terms_args.current_page_url.empty()) { |
| 921 const std::string& escaped_current_page_url = | 902 const std::string& escaped_current_page_url = |
| 922 net::EscapeQueryParamValue(search_terms_args.current_page_url, | 903 net::EscapeQueryParamValue(search_terms_args.current_page_url, |
| 923 true); | 904 true); |
| 924 HandleReplacement("url", escaped_current_page_url, *i, &url); | 905 HandleReplacement("url", escaped_current_page_url, *i, &url); |
| 925 } | 906 } |
| 926 break; | 907 break; |
| 927 | 908 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 952 | 933 |
| 953 case GOOGLE_INSTANT_EXTENDED_ENABLED: | 934 case GOOGLE_INSTANT_EXTENDED_ENABLED: |
| 954 DCHECK(!i->is_post_param); | 935 DCHECK(!i->is_post_param); |
| 955 HandleReplacement(std::string(), | 936 HandleReplacement(std::string(), |
| 956 search_terms_data.InstantExtendedEnabledParam( | 937 search_terms_data.InstantExtendedEnabledParam( |
| 957 type_ == SEARCH), | 938 type_ == SEARCH), |
| 958 *i, | 939 *i, |
| 959 &url); | 940 &url); |
| 960 break; | 941 break; |
| 961 | 942 |
| 962 case GOOGLE_NTP_IS_THEMED: | |
| 963 DCHECK(!i->is_post_param); | |
| 964 HandleReplacement( | |
| 965 std::string(), search_terms_data.NTPIsThemedParam(), *i, &url); | |
| 966 break; | |
| 967 | |
| 968 case GOOGLE_OMNIBOX_START_MARGIN: | |
| 969 DCHECK(!i->is_post_param); | |
| 970 if (search_terms_args.enable_omnibox_start_margin) { | |
| 971 int omnibox_start_margin = search_terms_data.OmniboxStartMargin(); | |
| 972 if (omnibox_start_margin >= 0) { | |
| 973 HandleReplacement("es_sm", base::IntToString(omnibox_start_margin), | |
| 974 *i, &url); | |
| 975 } | |
| 976 } | |
| 977 break; | |
| 978 | |
| 979 case GOOGLE_CONTEXTUAL_SEARCH_VERSION: | 943 case GOOGLE_CONTEXTUAL_SEARCH_VERSION: |
| 980 if (search_terms_args.contextual_search_params.version >= 0) { | 944 if (search_terms_args.contextual_search_params.version >= 0) { |
| 981 HandleReplacement( | 945 HandleReplacement( |
| 982 "ctxs", | 946 "ctxs", |
| 983 base::IntToString( | 947 base::IntToString( |
| 984 search_terms_args.contextual_search_params.version), | 948 search_terms_args.contextual_search_params.version), |
| 985 *i, | 949 *i, |
| 986 &url); | 950 &url); |
| 987 } | 951 } |
| 988 break; | 952 break; |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1514 // patterns. This means that given patterns | 1478 // patterns. This means that given patterns |
| 1515 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], | 1479 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], |
| 1516 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would | 1480 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would |
| 1517 // return false. This is important for at least Google, where such URLs | 1481 // return false. This is important for at least Google, where such URLs |
| 1518 // are invalid. | 1482 // are invalid. |
| 1519 return !search_terms->empty(); | 1483 return !search_terms->empty(); |
| 1520 } | 1484 } |
| 1521 } | 1485 } |
| 1522 return false; | 1486 return false; |
| 1523 } | 1487 } |
| OLD | NEW |