-// Copyright 2014 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <vector>
#include "base/gtest_prod_util.h"
-#include "base/macros.h"
+#include "base/memory/raw_ptr.h"
#include "base/time/time.h"
-#include "components/search_engines/omnibox_focus_type.h"
#include "components/search_engines/search_engine_type.h"
+#include "components/search_engines/search_terms_data.h"
#include "components/search_engines/template_url_data.h"
#include "components/search_engines/template_url_id.h"
#include "third_party/metrics_proto/omnibox_event.pb.h"
+#include "third_party/metrics_proto/omnibox_focus_type.pb.h"
#include "third_party/metrics_proto/omnibox_input_type.pb.h"
+#include "third_party/omnibox_proto/chrome_searchbox_stats.pb.h"
#include "ui/gfx/geometry/size.h"
#include "url/gurl.h"
#include "url/third_party/mozilla/url_parse.h"
-class SearchTermsData;
class TemplateURL;
SEARCH,
SUGGEST,
IMAGE,
+ IMAGE_TRANSLATE,
NEW_TAB,
CONTEXTUAL_SEARCH,
INDEXED
};
+ using RequestSource = SearchTermsData::RequestSource;
+
// Type to store <content_type, post_data> pair for POST URLs.
// The |content_type|(first part of the pair) is the content-type of
// the |post_data|(second part of the pair) which is encoded in
// the |post_data|. See http://tools.ietf.org/html/rfc2046 for the details.
typedef std::pair<std::string, std::string> PostContent;
- // Enumeration of the known search or suggest request sources. These values
- // are not persisted or used in histograms; thus can be freely changed.
- enum RequestSource {
- SEARCHBOX, // Omnibox or the NTP realbox. The default.
- CROS_APP_LIST, // Chrome OS app list search box.
- };
-
// This struct encapsulates arguments passed to
// TemplateURLRef::ReplaceSearchTerms methods. By default, only search_terms
// is required and is passed in the constructor.
// indicates experiment status and server processing results so that
// can be logged in GWS Sawmill logs for offline analysis for the
// Related Searches MVP experiment.
+ // The |apply_lang_hint| specifies whether or not the |source_lang| should
+ // be used as a hint for backend language detection. Otherwise, backend
+ // translation is forced using |source_lang|. Note that this only supports
+ // Partial Translate and so may only be enabled for select clients on the
+ // server.
ContextualSearchParams(int version,
int contextual_cards_version,
std::string home_country,
std::string source_lang,
std::string target_lang,
std::string fluent_languages,
- std::string related_searches_stamp);
+ std::string related_searches_stamp,
+ bool apply_lang_hint);
ContextualSearchParams(const ContextualSearchParams& other);
~ContextualSearchParams();
// experiment. The value is an arbitrary string that starts with a
// schema version number.
std::string related_searches_stamp;
+
+ // Whether hinted language detection should be used on the backend.
+ bool apply_lang_hint = false;
};
// Estimates dynamic memory usage.
metrics::OmniboxInputType input_type = metrics::OmniboxInputType::EMPTY;
// Specifies how the user last interacted with the searchbox UI element.
- OmniboxFocusType focus_type = OmniboxFocusType::DEFAULT;
+ metrics::OmniboxFocusType focus_type =
+ metrics::OmniboxFocusType::INTERACTION_DEFAULT;
// The optional assisted query stats, aka AQS, used for logging purposes.
// This string contains impressions of all autocomplete matches shown
// at the query submission time. For privacy reasons, we require the
// search provider to support HTTPS protocol in order to receive the AQS
// param.
- // For more details, see http://goto.google.com/binary-clients-logging .
+ // For more details, see go/chrome-suggest-logging.
std::string assisted_query_stats;
+ // The optional searchbox stats, reported as gs_lcrp for logging purposes.
+ // This proto message contains information such as impressions of all
+ // autocomplete matches shown at the query submission time.
+ // For privacy reasons, we require the search provider to support HTTPS
+ // protocol in order to receive the gs_lcrp param.
+ // For more details, see go/chrome-suggest-logging-improvement.
+ omnibox::metrics::ChromeSearchboxStats searchbox_stats;
+
// TODO: Remove along with "aq" CGI param.
int accepted_suggestion = NO_SUGGESTIONS_AVAILABLE;
// search-by-image frontend.
std::string image_thumbnail_content;
+ // The content type string for `image_thumbnail_content`.
+ std::string image_thumbnail_content_type;
+
+ // The image dimension data for a Google search-by-image query.
+ std::string processed_image_dimensions;
+
// When searching for an image, the URL of the original image. Callers
// should leave this empty for images specified via data: URLs.
GURL image_url;
gfx::Size image_original_size;
// Source of the search or suggest request.
- RequestSource request_source = SEARCHBOX;
+ RequestSource request_source = RequestSource::SEARCHBOX;
// Whether the query is being fetched as a prefetch request before the user
// actually searches for the search terms.
bool is_prefetch = false;
ContextualSearchParams contextual_search_params;
+
+ // The cache duration to be sent as a query string parameter in the zero
+ // suggest requests, if non-zero.
+ uint32_t zero_suggest_cache_duration_sec = 0;
+
+ // Whether the request should bypass the HTTP cache, i.e., a "shift-reload".
+ // If true, the net::LOAD_BYPASS_CACHE load flag will be set on the request.
+ bool bypass_cache = false;
+
+ // The source locale used for image translations.
+ std::string image_translate_source_locale;
+
+ // The target locale used for image translations.
+ std::string image_translate_target_locale;
};
TemplateURLRef(const TemplateURL* owner, Type type);
private:
friend class TemplateURL;
friend class TemplateURLTest;
+ FRIEND_TEST_ALL_PREFIXES(TemplateURLTest,
+ ImageThumbnailContentTypePostParams);
FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, SetPrepopulatedAndParse);
FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseParameterKnown);
FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseParameterUnknown);
enum ReplacementType {
ENCODING,
GOOGLE_ASSISTED_QUERY_STATS,
- GOOGLE_BASE_URL,
GOOGLE_BASE_SEARCH_BY_IMAGE_URL,
GOOGLE_BASE_SUGGEST_URL,
- GOOGLE_CONTEXTUAL_SEARCH_VERSION,
+ GOOGLE_BASE_URL,
+ GOOGLE_CLIENT_CACHE_TIME_TO_LIVE,
GOOGLE_CONTEXTUAL_SEARCH_CONTEXT_DATA,
+ GOOGLE_CONTEXTUAL_SEARCH_VERSION,
GOOGLE_CURRENT_PAGE_URL,
GOOGLE_CURSOR_POSITION,
GOOGLE_IMAGE_ORIGINAL_HEIGHT,
GOOGLE_IMAGE_ORIGINAL_WIDTH,
GOOGLE_IMAGE_SEARCH_SOURCE,
- GOOGLE_IMAGE_THUMBNAIL,
GOOGLE_IMAGE_THUMBNAIL_BASE64,
+ GOOGLE_IMAGE_THUMBNAIL,
GOOGLE_IMAGE_URL,
GOOGLE_INPUT_TYPE,
GOOGLE_IOS_SEARCH_LANGUAGE,
GOOGLE_PAGE_CLASSIFICATION,
GOOGLE_PREFETCH_QUERY,
GOOGLE_PREFETCH_SOURCE,
+ GOOGLE_PROCESSED_IMAGE_DIMENSIONS,
GOOGLE_RLZ,
GOOGLE_SEARCH_CLIENT,
GOOGLE_SEARCH_FIELDTRIAL_GROUP,
MAIL_RU_REFERRAL_ID,
SEARCH_TERMS,
YANDEX_REFERRAL_ID,
+ IMAGE_TRANSLATE_SOURCE_LOCALE,
+ IMAGE_TRANSLATE_TARGET_LOCALE,
};
// Used to identify an element of the raw url that can be replaced.
// belongs to a PostParam, the PostParam will be replaced by the term data.
// Otherwise, the term data will be inserted at the place that the
// replacement points to.
+ // Can be called repeatedly with the same replacement.
void HandleReplacement(const std::string& name,
const std::string& value,
const Replacement& replacement,
PostContent* post_content) const;
// The TemplateURL that contains us. This should outlive us.
- const TemplateURL* owner_;
+ raw_ptr<const TemplateURL> owner_;
// What kind of URL we are.
Type type_;
base::Time install_time,
bool wants_to_be_default_engine);
+ TemplateURL(const TemplateURL&) = delete;
+ TemplateURL& operator=(const TemplateURL&) = delete;
+
~TemplateURL();
// For two engines with the same keyword, |this| and |other|,
const std::string& url() const { return data_.url(); }
const std::string& suggestions_url() const { return data_.suggestions_url; }
const std::string& image_url() const { return data_.image_url; }
+ const std::string& image_translate_url() const {
+ return data_.image_translate_url;
+ }
const std::string& new_tab_url() const { return data_.new_tab_url; }
const std::string& contextual_search_url() const {
return data_.contextual_search_url;
const std::string& image_url_post_params() const {
return data_.image_url_post_params;
}
+ const std::string& side_search_param() const {
+ return data_.side_search_param;
+ }
+ const std::string& side_image_search_param() const {
+ return data_.side_image_search_param;
+ }
+ const std::string& image_translate_source_language_param_key() const {
+ return data_.image_translate_source_language_param_key;
+ }
+ const std::string& image_translate_target_language_param_key() const {
+ return data_.image_translate_target_language_param_key;
+ }
+ const std::u16string& image_search_branding_label() const {
+ return !data_.image_search_branding_label.empty()
+ ? data_.image_search_branding_label
+ : short_name();
+ }
+ const std::vector<std::string>& search_intent_params() const {
+ return data_.search_intent_params;
+ }
const std::vector<std::string>& alternate_urls() const {
return data_.alternate_urls;
}
base::Time last_visited() const { return data_.last_visited; }
bool created_by_policy() const { return data_.created_by_policy; }
+ bool enforced_by_policy() const { return data_.enforced_by_policy; }
bool created_from_play_api() const { return data_.created_from_play_api; }
int usage_count() const { return data_.usage_count; }
TemplateURLData::ActiveStatus is_active() const { return data_.is_active; }
+ int starter_pack_id() const { return data_.starter_pack_id; }
+
const std::vector<TemplateURLRef>& url_refs() const { return url_refs_; }
const TemplateURLRef& url_ref() const {
// Sanity check for https://crbug.com/781703.
return suggestions_url_ref_;
}
const TemplateURLRef& image_url_ref() const { return image_url_ref_; }
+ const TemplateURLRef& image_translate_url_ref() const {
+ return image_translate_url_ref_;
+ }
const TemplateURLRef& new_tab_url_ref() const { return new_tab_url_ref_; }
const TemplateURLRef& contextual_search_url_ref() const {
return contextual_search_url_ref_;
SearchEngineType GetEngineType(
const SearchTermsData& search_terms_data) const;
+ // Returns the type of this search engine, i.e. whether the engine is a
+ // prepopulated engine, starter pack engine, or not built-in.
+ BuiltinEngineType GetBuiltinEngineType() const;
+
// Use the alternate URLs and the search URL to match the provided |url|
// and extract |search_terms| from it. Returns false and an empty
// |search_terms| if no search terms can be matched. The URLs are matched in
bool IsSearchURL(const GURL& url,
const SearchTermsData& search_terms_data) const;
+ // Given a `url` corresponding to this TemplateURL, keeps the search terms and
+ // optionally the search intent params and removes the other params. If
+ // `normalize_search_terms` is true, the search terms in the final URL
+ // will be converted to lowercase with extra whitespace characters collapsed.
+ // If `url` is not a search URL or replacement fails, leaves `out_url` and
+ // `out_search_terms` untouched and returns false. Used to compare
+ // normalized (aka canonical) search URLs.
+ bool KeepSearchTermsInURL(const GURL& url,
+ const SearchTermsData& search_terms_data,
+ const bool keep_search_intent_params,
+ const bool normalize_search_terms,
+ GURL* out_url,
+ std::u16string* out_search_terms = nullptr) const;
+
// Given a |url| corresponding to this TemplateURL, identifies the search
// terms and replaces them with the ones in |search_terms_args|, leaving the
// other parameters untouched. If the replacement fails, returns false and
std::u16string* encoded_terms,
std::u16string* encoded_original_query) const;
- // Returns the search url for this template URL.
+ // Returns the search url for this template URL and the optional search terms.
+ // Uses something obscure as the default value for the search terms argument
+ // so that in the rare case the term replaces the URL it's unlikely another
+ // keyword would have the same url.
// Returns an empty GURL if this template URL has no url().
- GURL GenerateSearchURL(const SearchTermsData& search_terms_data) const;
+ GURL GenerateSearchURL(
+ const SearchTermsData& search_terms_data,
+ const std::u16string& search_terms = u"blah.blah.blah.blah.blah") const;
+
+ // Returns the suggest endpoint URL for this template URL.
+ // Returns an empty GURL if this template URL has no suggestions_url().
+ GURL GenerateSuggestionURL(const SearchTermsData& search_terms_data) const;
+
+ // Returns true if this search engine supports the side search feature.
+ bool IsSideSearchSupported() const;
+
+ // Returns true if this search engine supports the side image search feature.
+ bool IsSideImageSearchSupported() const;
+
+ // Takes a search URL belonging to this search engine and generates the URL
+ // appropriate for the side search side panel.
+ GURL GenerateSideSearchURL(const GURL& search_url,
+ const std::string& version,
+ const SearchTermsData& search_terms_data) const;
+
+ // Takes a search URL that belongs to this side search in the side panel and
+ // removes the side search param from the URL.
+ GURL RemoveSideSearchParamFromURL(const GURL& side_search_url) const;
+
+ // Takes a search URL belonging to this image search engine and generates the
+ // URL appropriate for the image search in the side panel.
+ GURL GenerateSideImageSearchURL(const GURL& image_search_url,
+ const std::string& version) const;
+
+ // Takes a search URL that belongs to this image search in the side panel and
+ // removes the side image search param from the URL.
+ GURL RemoveSideImageSearchParamFromURL(const GURL& image_search_url) const;
// TemplateURL internally caches values derived from a passed SearchTermsData
// to make its functions quick. This method invalidates any cached values and
// See base/trace_event/memory_usage_estimator.h for more info.
size_t EstimateMemoryUsage() const;
+ // Returns whether |url| query contains a side search param.
+ bool ContainsSideSearchParam(const GURL& url) const;
+
+ // Returns whether |url| query contains a side image search param.
+ bool ContainsSideImageSearchParam(const GURL& url) const;
+
private:
friend class TemplateURLService;
TemplateURLRef suggestions_url_ref_;
TemplateURLRef image_url_ref_;
+ TemplateURLRef image_translate_url_ref_;
TemplateURLRef new_tab_url_ref_;
TemplateURLRef contextual_search_url_ref_;
std::unique_ptr<AssociatedExtensionInfo> extension_info_;
mutable SearchEngineType engine_type_;
// TODO(sky): Add date last parsed OSD file.
-
- DISALLOW_COPY_AND_ASSIGN(TemplateURL);
};
#endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_H_