Upload upstream chromium 114.0.5735.31
[platform/framework/web/chromium-efl.git] / components / search_engines / template_url.h
index 4fa09c5..fb94b7c 100644 (file)
@@ -1,4 +1,4 @@
-// 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/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;
 
 
@@ -55,11 +57,14 @@ class TemplateURLRef {
     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
@@ -71,7 +76,8 @@ class TemplateURLRef {
   // TemplateURLRef::ReplaceSearchTerms methods.  By default, only search_terms
   // is required and is passed in the constructor.
   struct SearchTermsArgs {
-    explicit SearchTermsArgs(const base::string16& search_terms);
+    SearchTermsArgs();
+    explicit SearchTermsArgs(const std::u16string& search_terms);
     SearchTermsArgs(const SearchTermsArgs& other);
     ~SearchTermsArgs();
 
@@ -79,12 +85,53 @@ class TemplateURLRef {
       ContextualSearchParams();
       // Modern constructor, used when the content is sent in the HTTP header
       // instead of as CGI parameters.
+      // The |version| tell the server which version of the client is making
+      // this request.
+      // The |contextual_cards_version| tells the server which version of
+      // contextual cards integration is being used by the client.
       // The |home_country| is an ISO country code for the country that the user
       // considers their permanent home (which may be different from the country
       // they are currently visiting).  Pass an empty string if none available.
+      // The |previous_event_id| is an identifier previously returned by the
+      // server to identify that user interaction.
+      // The |previous_event_results| are the results of the user-interaction of
+      // that previous request.
+      // The "previous_xyz" parameters are documented in go/cs-sanitized.
+      // The |is_exact_search| allows the search request to be narrowed down to
+      // an "exact" search only, meaning just search for X rather than X +
+      // whatever else is in the context.  The returned search term should not
+      // be expanded, and the server will honor this along with creating a
+      // narrow Search Term.
+      // The |source_lang| specifies a source language hint to apply for
+      // translation or to indicate that translation might be appropriate.
+      // This comes from CLD evaluating the selection and/or page content.
+      // The |target_lang| specifies the best language to translate into for
+      // the user, which also indicates when translation is appropriate or
+      // helpful.  This comes from the Chrome Language Model.
+      // The |fluent_languages| string specifies the languages the user
+      // is fluent in reading.  This acts as an alternate set of languages
+      // to consider translating into.  The languages are ordered by
+      // fluency, and encoded as a comma-separated list of BCP 47 languages.
+      // The |related_searches_stamp| string contains an information that
+      // 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,
-                             const std::string& home_country);
+                             std::string home_country,
+                             int64_t previous_event_id,
+                             int previous_event_results,
+                             bool is_exact_search,
+                             std::string source_lang,
+                             std::string target_lang,
+                             std::string fluent_languages,
+                             std::string related_searches_stamp,
+                             bool apply_lang_hint);
       ContextualSearchParams(const ContextualSearchParams& other);
       ~ContextualSearchParams();
 
@@ -93,16 +140,46 @@ class TemplateURLRef {
       size_t EstimateMemoryUsage() const;
 
       // The version of contextual search.
-      int version;
+      int version = -1;
 
       // The version of Contextual Cards data to request.
       // A value of 0 indicates no data needed.
-      int contextual_cards_version;
+      int contextual_cards_version = 0;
 
       // The locale of the user's home country in an ISO country code format,
       // or an empty string if not available.  This indicates where the user
       // resides, not where they currently are.
       std::string home_country;
+
+      // An EventID from a previous interaction (sent by server, recorded by
+      // client).
+      int64_t previous_event_id = 0l;
+
+      // An encoded set of booleans that represent the interaction results from
+      // the previous event.
+      int previous_event_results = 0;
+
+      // A flag that restricts the search to exactly match the selection rather
+      // than expanding the Search Term to include other words in the context.
+      bool is_exact_search = false;
+
+      // Source language string to translate from.
+      std::string source_lang;
+
+      // Target language string to be translated into.
+      std::string target_lang;
+
+      // Alternate target languages that the user is fluent in, encoded in a
+      // single string.
+      std::string fluent_languages;
+
+      // Experiment arm and processing information for the Related Searches
+      // 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.
@@ -110,35 +187,48 @@ class TemplateURLRef {
     size_t EstimateMemoryUsage() const;
 
     // The search terms (query).
-    base::string16 search_terms;
+    std::u16string search_terms;
 
     // The original (input) query.
-    base::string16 original_query;
+    std::u16string original_query;
 
     // The type the original input query was identified as.
-    metrics::OmniboxInputType input_type;
+    metrics::OmniboxInputType input_type = metrics::OmniboxInputType::EMPTY;
+
+    // Specifies how the user last interacted with the searchbox UI element.
+    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;
+    int accepted_suggestion = NO_SUGGESTIONS_AVAILABLE;
 
     // The 0-based position of the cursor within the query string at the time
-    // the request was issued.  Set to base::string16::npos if not used.
-    size_t cursor_position;
+    // the request was issued.  Set to std::u16string::npos if not used.
+    size_t cursor_position = std::u16string::npos;
 
     // The URL of the current webpage to be used for experimental zero-prefix
     // suggestions.
     std::string current_page_url;
 
     // Which omnibox the user used to type the prefix.
-    metrics::OmniboxEventProto::PageClassification page_classification;
+    metrics::OmniboxEventProto::PageClassification page_classification =
+        metrics::OmniboxEventProto::INVALID_SPEC;
 
     // Optional session token.
     std::string session_token;
@@ -147,8 +237,8 @@ class TemplateURLRef {
     std::string prefetch_query;
     std::string prefetch_query_type;
 
-    // Additional query params provided by the suggest server.
-    std::string suggest_query_params;
+    // Additional query params to append to the request.
+    std::string additional_query_params;
 
     // If set, ReplaceSearchTerms() will automatically append any extra query
     // params specified via the --extra-search-query-params command-line
@@ -157,12 +247,18 @@ class TemplateURLRef {
     // about the query portion of the URL.  Since neither TemplateURLRef nor
     // indeed TemplateURL know whether a TemplateURL is the default search
     // engine, callers instead must set this manually.
-    bool append_extra_query_params;
+    bool append_extra_query_params_from_command_line = false;
 
     // The raw content of an image thumbnail that will be used as a query for
     // 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;
@@ -170,11 +266,28 @@ class TemplateURLRef {
     // When searching for an image, the original size of the image.
     gfx::Size image_original_size;
 
-    // True if the search was made using the app list search box. Otherwise, the
-    // search was made using the omnibox.
-    bool from_app_list;
+    // Source of the search or suggest request.
+    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);
@@ -221,16 +334,16 @@ class TemplateURLRef {
 
   // Returns a string representation of this TemplateURLRef suitable for
   // display. The display format is the same as the format used by Firefox.
-  base::string16 DisplayURL(const SearchTermsData& search_terms_data) const;
+  std::u16string DisplayURL(const SearchTermsData& search_terms_data) const;
 
   // Converts a string as returned by DisplayURL back into a string as
   // understood by TemplateURLRef.
-  static std::string DisplayURLToURLRef(const base::string16& display_url);
+  static std::string DisplayURLToURLRef(const std::u16string& display_url);
 
   // If this TemplateURLRef is valid and contains one search term, this returns
   // the host/path of the URL, otherwise this returns an empty string.
   const std::string& GetHost(const SearchTermsData& search_terms_data) const;
-  const std::string& GetPath(const SearchTermsData& search_terms_data) const;
+  std::string GetPath(const SearchTermsData& search_terms_data) const;
 
   // If this TemplateURLRef is valid and contains one search term
   // in its query or ref, this returns the key of the search term,
@@ -256,8 +369,8 @@ class TemplateURLRef {
   const std::string& GetSearchTermValueSuffix(
       const SearchTermsData& search_terms_data) const;
 
-  // Converts the specified term in our owner's encoding to a base::string16.
-  base::string16 SearchTermToString16(const base::StringPiece& term) const;
+  // Converts the specified term in our owner's encoding to a std::u16string.
+  std::u16string SearchTermToString16(const base::StringPiece& term) const;
 
   // Returns true if this TemplateURLRef has a replacement term of
   // {google:baseURL} or {google:baseSuggestURL}.
@@ -273,7 +386,7 @@ class TemplateURLRef {
   // does not match.
   bool ExtractSearchTermsFromURL(
       const GURL& url,
-      base::string16* search_terms,
+      std::u16string* search_terms,
       const SearchTermsData& search_terms_data,
       url::Parsed::ComponentType* search_term_component,
       url::Component* search_terms_position) const;
@@ -288,6 +401,8 @@ class TemplateURLRef {
  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);
@@ -302,23 +417,29 @@ class TemplateURLRef {
   enum ReplacementType {
     ENCODING,
     GOOGLE_ASSISTED_QUERY_STATS,
-    GOOGLE_BASE_URL,
+    GOOGLE_BASE_SEARCH_BY_IMAGE_URL,
     GOOGLE_BASE_SUGGEST_URL,
+    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_BASE64,
     GOOGLE_IMAGE_THUMBNAIL,
     GOOGLE_IMAGE_URL,
     GOOGLE_INPUT_TYPE,
     GOOGLE_IOS_SEARCH_LANGUAGE,
     GOOGLE_NTP_IS_THEMED,
-    GOOGLE_CONTEXTUAL_SEARCH_VERSION,
-    GOOGLE_CONTEXTUAL_SEARCH_CONTEXT_DATA,
+    GOOGLE_OMNIBOX_FOCUS_TYPE,
     GOOGLE_ORIGINAL_QUERY_FOR_SUGGESTION,
     GOOGLE_PAGE_CLASSIFICATION,
     GOOGLE_PREFETCH_QUERY,
+    GOOGLE_PREFETCH_SOURCE,
+    GOOGLE_PROCESSED_IMAGE_DIMENSIONS,
     GOOGLE_RLZ,
     GOOGLE_SEARCH_CLIENT,
     GOOGLE_SEARCH_FIELDTRIAL_GROUP,
@@ -331,6 +452,8 @@ class TemplateURLRef {
     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.
@@ -396,6 +519,18 @@ class TemplateURLRef {
   // search_offset_.
   void ParseIfNecessary(const SearchTermsData& search_terms_data) const;
 
+  // Parses a wildcard out of |path|, putting the parsed path in |path_prefix_|
+  // and |path_suffix_| and setting |path_wildcard_present_| to true.
+  // In the absence of a wildcard, the full path will be contained in
+  // |path_prefix_| and |path_wildcard_present_| will be false.
+  void ParsePath(const std::string& path) const;
+
+  // Returns whether the path portion of this template URL is equal to the path
+  // in |url|, checking that URL is prefixed/suffixed by
+  // |path_prefix_|/|path_suffix_| if |path_wildcard_present_| is true, or equal
+  // to |path_prefix_| otherwise.
+  bool PathIsEqual(const GURL& url) const;
+
   // Extracts the query key and host from the url.
   void ParseHostAndSearchTermKey(
       const SearchTermsData& search_terms_data) const;
@@ -410,6 +545,7 @@ class TemplateURLRef {
   // 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,
@@ -424,46 +560,51 @@ class TemplateURLRef {
       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_;
 
   // If |type_| is |INDEXED|, this |index_in_owner_| is used instead to refer to
   // a url within our owner.
-  size_t index_in_owner_;
+  size_t index_in_owner_ = 0;
 
   // Whether the URL has been parsed.
-  mutable bool parsed_;
+  mutable bool parsed_ = false;
 
   // Whether the url was successfully parsed.
-  mutable bool valid_;
+  mutable bool valid_ = false;
 
   // The parsed URL. All terms have been stripped out of this with
   // replacements_ giving the index of the terms to replace.
   mutable std::string parsed_url_;
 
   // Do we support search term replacement?
-  mutable bool supports_replacements_;
+  mutable bool supports_replacements_ = false;
 
   // The replaceable parts of url (parsed_url_). These are ordered by index
   // into the string, and may be empty.
   mutable Replacements replacements_;
 
+  // Whether the path contains a wildcard.
+  mutable bool path_wildcard_present_ = false;
+
   // Host, port, path, key and location of the search term. These are only set
   // if the url contains one search term.
   mutable std::string host_;
   mutable std::string port_;
-  mutable std::string path_;
+  mutable std::string path_prefix_;
+  mutable std::string path_suffix_;
   mutable std::string search_term_key_;
-  mutable url::Parsed::ComponentType search_term_key_location_;
+  mutable url::Parsed::ComponentType search_term_key_location_ =
+      url::Parsed::QUERY;
   mutable std::string search_term_value_prefix_;
   mutable std::string search_term_value_suffix_;
 
   mutable PostParams post_params_;
 
   // Whether the contained URL is a pre-populated URL.
-  bool prepopulated_;
+  bool prepopulated_ = false;
 };
 
 
@@ -481,15 +622,23 @@ class TemplateURLRef {
 // is made a friend so that it can be the exception to this pattern.
 class TemplateURL {
  public:
+  using TemplateURLVector = std::vector<TemplateURL*>;
+  using OwnedTemplateURLVector = std::vector<std::unique_ptr<TemplateURL>>;
+
+  // These values are not persisted and can be freely changed.
+  // Their integer values are used for choosing the best engine during keyword
+  // conflicts, so their relative ordering should not be changed without careful
+  // thought about what happens during version skew.
   enum Type {
-    // Regular search engine.
-    NORMAL,
-    // Installed by extension through Override Settings API.
-    NORMAL_CONTROLLED_BY_EXTENSION,
+    // Installed only on this device. Should not be synced. This is not common.
+    LOCAL = 0,
+    // Regular search engine. This is the most common, and the ONLY type synced.
+    NORMAL = 1,
+    // Installed by extension through Override Settings API. Not synced.
+    NORMAL_CONTROLLED_BY_EXTENSION = 2,
     // The keyword associated with an extension that uses the Omnibox API.
-    OMNIBOX_API_EXTENSION,
-    // Installed only on this device. Should not be synced.
-    LOCAL,
+    // Not synced.
+    OMNIBOX_API_EXTENSION = 3,
   };
 
   // An AssociatedExtensionInfo represents information about the extension that
@@ -524,12 +673,34 @@ class TemplateURL {
               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|,
+  // returns true if |this| is strictly better than |other|.
+  //
+  // While normal engines must all have distinct keywords, policy-created,
+  // extension-controlled and omnibox API engines may have the same keywords as
+  // each other or as normal engines.  In these cases, policy-create engines
+  // override omnibox API engines, which override extension-controlled engines,
+  // which override normal engines.
+  //
+  // If there is still a conflict after this, compare by safe-for-autoreplace,
+  // then last modified date, then use the sync guid as a tiebreaker.
+  //
+  // TODO(tommycli): I'd like to use this to resolve Sync conflicts in the
+  // future, but we need a total ordering of TemplateURLs. That's not the case
+  // today, because the sync GUIDs are not actually globally unique, so there
+  // can be a genuine tie, which is not good, because then two different clients
+  // could choose to resolve the conflict in two different ways.
+  bool IsBetterThanEngineWithConflictingKeyword(const TemplateURL* other) const;
+
   // Generates a suitable keyword for the specified url, which must be valid.
   // This is guaranteed not to return an empty string, since TemplateURLs should
   // never have an empty keyword.
-  static base::string16 GenerateKeyword(const GURL& url);
+  static std::u16string GenerateKeyword(const GURL& url);
 
   // Generates a favicon URL from the specified url.
   static GURL GenerateFaviconURL(const GURL& url);
@@ -542,16 +713,19 @@ class TemplateURL {
 
   const TemplateURLData& data() const { return data_; }
 
-  const base::string16& short_name() const { return data_.short_name(); }
+  const std::u16string& short_name() const { return data_.short_name(); }
   // An accessor for the short_name, but adjusted so it can be appropriately
   // displayed even if it is LTR and the UI is RTL.
-  base::string16 AdjustedShortNameForLocaleDirection() const;
+  std::u16string AdjustedShortNameForLocaleDirection() const;
 
-  const base::string16& keyword() const { return data_.keyword(); }
+  const std::u16string& keyword() const { return data_.keyword(); }
 
   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;
@@ -565,6 +739,26 @@ class TemplateURL {
   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;
   }
@@ -589,6 +783,8 @@ class TemplateURL {
   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; }
 
@@ -596,6 +792,10 @@ class TemplateURL {
 
   const std::string& sync_guid() const { return data_.sync_guid; }
 
+  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.
@@ -606,6 +806,9 @@ class TemplateURL {
     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_;
@@ -645,13 +848,17 @@ class TemplateURL {
   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
   // the order listed in |url_refs_| (see comment there).
   bool ExtractSearchTermsFromURL(const GURL& url,
                                  const SearchTermsData& search_terms_data,
-                                 base::string16* search_terms) const;
+                                 std::u16string* search_terms) const;
 
   // Returns true if non-empty search terms could be extracted from |url| using
   // ExtractSearchTermsFromURL(). In other words, this returns whether |url|
@@ -659,6 +866,20 @@ class TemplateURL {
   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
@@ -679,12 +900,46 @@ class TemplateURL {
       const TemplateURLRef::SearchTermsArgs& search_terms_args,
       bool is_in_query,
       std::string* input_encoding,
-      base::string16* encoded_terms,
-      base::string16* encoded_original_query) const;
+      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
@@ -695,6 +950,12 @@ class TemplateURL {
   // 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;
 
@@ -720,7 +981,7 @@ class TemplateURL {
   // |search_terms| are found in |url|. See also ExtractSearchTermsFromURL().
   bool FindSearchTermsInURL(const GURL& url,
                             const SearchTermsData& search_terms_data,
-                            base::string16* search_terms,
+                            std::u16string* search_terms,
                             url::Parsed::ComponentType* search_terms_component,
                             url::Component* search_terms_position) const;
 
@@ -738,6 +999,7 @@ class TemplateURL {
 
   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_;
@@ -748,8 +1010,6 @@ class TemplateURL {
   mutable SearchEngineType engine_type_;
 
   // TODO(sky): Add date last parsed OSD file.
-
-  DISALLOW_COPY_AND_ASSIGN(TemplateURL);
 };
 
 #endif  // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_H_