Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(338)

Side by Side Diff: chrome/browser/search_engines/template_url.h

Issue 12623029: Upstreaming mechanism to add query refinement to omnibox searches. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed ChromeOS. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #ifndef CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_ 5 #ifndef CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_
6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_ 6 #define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 135
136 // Converts the specified term in our owner's encoding to a string16. 136 // Converts the specified term in our owner's encoding to a string16.
137 string16 SearchTermToString16(const std::string& term) const; 137 string16 SearchTermToString16(const std::string& term) const;
138 138
139 // Returns true if this TemplateURLRef has a replacement term of 139 // Returns true if this TemplateURLRef has a replacement term of
140 // {google:baseURL} or {google:baseSuggestURL}. 140 // {google:baseURL} or {google:baseSuggestURL}.
141 bool HasGoogleBaseURLs() const; 141 bool HasGoogleBaseURLs() const;
142 142
143 // Use the pattern referred to by this TemplateURLRef to match the provided 143 // Use the pattern referred to by this TemplateURLRef to match the provided
144 // |url| and extract |search_terms| from it. Returns true if the pattern 144 // |url| and extract |search_terms| from it. Returns true if the pattern
145 // matches, even if |search_terms| is empty. Returns false and an empty 145 // matches, even if |search_terms| is empty. In this case
146 // |search_terms| if the pattern does not match. 146 // |search_term_location|, if not NULL, indicates whether the search terms
147 // were found in the query or the ref parameters; and |search_terms_position|,
148 // if not NULL, contains the position of the search terms in the query or the
149 // ref parameters. Returns false and an empty |search_terms| if the pattern
150 // does not match.
147 bool ExtractSearchTermsFromURL( 151 bool ExtractSearchTermsFromURL(
148 const GURL& url, 152 const GURL& url,
149 string16* search_terms, 153 string16* search_terms,
150 const SearchTermsData& search_terms_data) const; 154 const SearchTermsData& search_terms_data,
155 url_parse::Parsed::ComponentType* search_term_location,
Peter Kasting 2013/03/22 20:20:06 Nit: I suggest |search_term_component| here and in
beaudoin 2013/03/22 23:10:43 Done.
beaudoin 2013/03/22 23:10:43 Done.
156 url_parse::Component* search_terms_position) const;
151 157
152 private: 158 private:
153 friend class TemplateURL; 159 friend class TemplateURL;
154 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, SetPrepopulatedAndParse); 160 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, SetPrepopulatedAndParse);
155 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseParameterKnown); 161 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseParameterKnown);
156 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseParameterUnknown); 162 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseParameterUnknown);
157 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLEmpty); 163 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLEmpty);
158 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNoTemplateEnd); 164 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNoTemplateEnd);
159 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNoKnownParameters); 165 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLNoKnownParameters);
160 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLTwoParameters); 166 FRIEND_TEST_ALL_PREFIXES(TemplateURLTest, ParseURLTwoParameters);
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 const SearchTermsData& search_terms_data); 513 const SearchTermsData& search_terms_data);
508 514
509 // Returns true if the specified |url| contains the search terms replacement 515 // Returns true if the specified |url| contains the search terms replacement
510 // key in either the query or the ref. This method does not verify anything 516 // key in either the query or the ref. This method does not verify anything
511 // else about the URL. In particular, it does not check that the domain 517 // else about the URL. In particular, it does not check that the domain
512 // matches that of this TemplateURL. 518 // matches that of this TemplateURL.
513 // TODO(beaudoin): Rename this to reflect that it really checks for an 519 // TODO(beaudoin): Rename this to reflect that it really checks for an
514 // InstantExtended capable URL. 520 // InstantExtended capable URL.
515 bool HasSearchTermsReplacementKey(const GURL& url) const; 521 bool HasSearchTermsReplacementKey(const GURL& url) const;
516 522
523 // Given a |url| corresponding to this TemplateURL, identifies the search
524 // terms and replace them with the ones in |search_terms_args|, leaving the
Peter Kasting 2013/03/22 20:20:06 Nit: replace -> replaces
beaudoin 2013/03/22 23:10:43 Done.
525 // other parameters untouched. If the replacement fails, returns false and
526 // leaves |result| untouched.
527 bool ReplaceSearchTermsInURL(
Peter Kasting 2013/03/22 20:20:06 As with autocomplete_input.h, I'd specifically not
beaudoin 2013/03/22 23:10:43 I hope to upstream the call to this too, and make
528 const GURL& url,
529 const TemplateURLRef::SearchTermsArgs& search_terms_args,
530 GURL* result);
531
532 // Encode the search terms from |search_terms_args| so that we know the
Peter Kasting 2013/03/22 20:20:06 Nit: Encode -> Encodes
beaudoin 2013/03/22 23:10:43 Done.
533 // |input_encoding|. Returns the |encoded_terms| and the
534 // |encoded_original_query|. |encoded_terms| may be escaped as path or query
535 // depending on |is_in_query|; |encoded_original_query| is always escaped as
536 // query.
537 void EncodeSearchTerms(
538 const TemplateURLRef::SearchTermsArgs& search_terms_args,
539 bool is_in_query,
540 std::string* input_encoding,
541 string16* encoded_terms,
542 string16* encoded_original_query) const;
543
517 private: 544 private:
518 friend class TemplateURLService; 545 friend class TemplateURLService;
519 546
520 void CopyFrom(const TemplateURL& other); 547 void CopyFrom(const TemplateURL& other);
521 548
522 void SetURL(const std::string& url); 549 void SetURL(const std::string& url);
523 void SetPrepopulateId(int id); 550 void SetPrepopulateId(int id);
524 551
525 // Resets the keyword if IsGoogleSearchURLWithReplaceableKeyword() or |force|. 552 // Resets the keyword if IsGoogleSearchURLWithReplaceableKeyword() or |force|.
526 // The |force| parameter is useful when the existing keyword is known to be 553 // The |force| parameter is useful when the existing keyword is known to be
527 // a placeholder. The resulting keyword is generated using 554 // a placeholder. The resulting keyword is generated using
528 // TemplateURLService::GenerateSearchURL() and 555 // TemplateURLService::GenerateSearchURL() and
529 // TemplateURLService::GenerateKeyword(). 556 // TemplateURLService::GenerateKeyword().
530 void ResetKeywordIfNecessary(bool force); 557 void ResetKeywordIfNecessary(bool force);
531 558
559 // Use the alternate URLs and the search URL to match the provided |url|
Peter Kasting 2013/03/22 20:20:06 Nit: Use -> Uses
beaudoin 2013/03/22 23:10:43 Done.
560 // and extract |search_terms| from it as well as the |search_terms_location|
561 // (either REF or QUERY) and |search_terms_location| at which the
562 // |search_terms| are found in |url|. See also ExtractSearchTermsFromURL().
563 bool FindSearchTermsInURL(
564 const GURL& url,
565 const SearchTermsData& search_terms_data,
566 string16* search_terms,
567 url_parse::Parsed::ComponentType* search_terms_location,
568 url_parse::Component* search_terms_position);
569
532 Profile* profile_; 570 Profile* profile_;
533 TemplateURLData data_; 571 TemplateURLData data_;
534 TemplateURLRef url_ref_; 572 TemplateURLRef url_ref_;
535 TemplateURLRef suggestions_url_ref_; 573 TemplateURLRef suggestions_url_ref_;
536 TemplateURLRef instant_url_ref_; 574 TemplateURLRef instant_url_ref_;
537 575
538 // TODO(sky): Add date last parsed OSD file. 576 // TODO(sky): Add date last parsed OSD file.
539 577
540 DISALLOW_COPY_AND_ASSIGN(TemplateURL); 578 DISALLOW_COPY_AND_ASSIGN(TemplateURL);
541 }; 579 };
542 580
543 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_ 581 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698