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 #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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "base/time.h" | 13 #include "base/time.h" |
14 #include "chrome/browser/search_engines/template_url_id.h" | 14 #include "chrome/browser/search_engines/template_url_id.h" |
15 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
16 | 16 |
17 class Profile; | 17 class Profile; |
18 class SearchTermsData; | 18 class SearchTermsData; |
19 class TemplateURL; | 19 class TemplateURL; |
20 | 20 |
21 | 21 |
22 // TemplateURLRef ------------------------------------------------------------- | 22 // TemplateURLRef ------------------------------------------------------------- |
23 | 23 |
24 // A TemplateURLRef represents a single URL within the larger TemplateURL class | 24 // A TemplateURLRef represents a single URL within the larger TemplateURL class |
25 // (which represents an entire "search engine", see below). If | 25 // (which represents an entire "search engine", see below). If |
26 // SupportsReplacement() is true, this URL has placeholders in it, for which | 26 // SupportsReplacement() is true, this URL has placeholders in it, for which |
27 // callers can substitute values to get a "real" URL using ReplaceSearchTerms(). | 27 // callers can substitute values to get a "real" URL using ReplaceSearchTerms(). |
28 // | 28 // |
29 // TemplateURLRefs always have a non-NULL |owner_| TemplateURL, which they | 29 // TemplateURLRefs always have a non-NULL |owner_| TemplateURL, which they |
30 // access in order to get at important data like the underlying URL string. | 30 // access in order to get at important data like the underlying URL string or |
| 31 // the associated Profile. |
31 class TemplateURLRef { | 32 class TemplateURLRef { |
32 public: | 33 public: |
33 // Magic numbers to pass to ReplaceSearchTerms() for the |accepted_suggestion| | 34 // Magic numbers to pass to ReplaceSearchTerms() for the |accepted_suggestion| |
34 // parameter. Most callers aren't using Suggest capabilities and should just | 35 // parameter. Most callers aren't using Suggest capabilities and should just |
35 // pass NO_SUGGESTIONS_AVAILABLE. | 36 // pass NO_SUGGESTIONS_AVAILABLE. |
36 // NOTE: Because positive values are meaningful, make sure these are negative! | 37 // NOTE: Because positive values are meaningful, make sure these are negative! |
37 enum AcceptedSuggestion { | 38 enum AcceptedSuggestion { |
38 NO_SUGGESTION_CHOSEN = -1, | 39 NO_SUGGESTION_CHOSEN = -1, |
39 NO_SUGGESTIONS_AVAILABLE = -2, | 40 NO_SUGGESTIONS_AVAILABLE = -2, |
40 }; | 41 }; |
(...skipping 22 matching lines...) Expand all Loading... |
63 // Returns a string that is the result of replacing the search terms in | 64 // Returns a string that is the result of replacing the search terms in |
64 // the url with the specified value. We use our owner's input encoding. | 65 // the url with the specified value. We use our owner's input encoding. |
65 // | 66 // |
66 // If this TemplateURLRef does not support replacement (SupportsReplacement | 67 // If this TemplateURLRef does not support replacement (SupportsReplacement |
67 // returns false), an empty string is returned. | 68 // returns false), an empty string is returned. |
68 std::string ReplaceSearchTerms( | 69 std::string ReplaceSearchTerms( |
69 const string16& terms, | 70 const string16& terms, |
70 int accepted_suggestion, | 71 int accepted_suggestion, |
71 const string16& original_query_for_suggestion) const; | 72 const string16& original_query_for_suggestion) const; |
72 | 73 |
73 // Just like ReplaceSearchTerms except that it takes a Profile that's used to | |
74 // retrieve Instant field trial params. Most callers don't care about those | |
75 // params, and so can use ReplaceSearchTerms instead. | |
76 std::string ReplaceSearchTermsUsingProfile( | |
77 Profile* profile, | |
78 const string16& terms, | |
79 int accepted_suggestion, | |
80 const string16& original_query_for_suggestion) const; | |
81 | |
82 // Just like ReplaceSearchTerms except that it takes SearchTermsData to supply | 74 // Just like ReplaceSearchTerms except that it takes SearchTermsData to supply |
83 // the data for some search terms. Most of the time ReplaceSearchTerms should | 75 // the data for some search terms. Most of the time ReplaceSearchTerms should |
84 // be called. | 76 // be called. |
85 std::string ReplaceSearchTermsUsingTermsData( | 77 std::string ReplaceSearchTermsUsingTermsData( |
86 const string16& terms, | 78 const string16& terms, |
87 int accepted_suggestion, | 79 int accepted_suggestion, |
88 const string16& original_query_for_suggestion, | 80 const string16& original_query_for_suggestion, |
89 const SearchTermsData& search_terms_data) const; | 81 const SearchTermsData& search_terms_data) const; |
90 | 82 |
91 // Returns true if the TemplateURLRef is valid. An invalid TemplateURLRef is | 83 // Returns true if the TemplateURLRef is valid. An invalid TemplateURLRef is |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 // One TemplateURL contains several TemplateURLRefs, which correspond to various | 349 // One TemplateURL contains several TemplateURLRefs, which correspond to various |
358 // different capabilities (e.g. doing searches or getting suggestions), as well | 350 // different capabilities (e.g. doing searches or getting suggestions), as well |
359 // as a TemplateURLData containing other details like the name, keyword, etc. | 351 // as a TemplateURLData containing other details like the name, keyword, etc. |
360 // | 352 // |
361 // TemplateURLs are intended to be read-only for most users; the only public | 353 // TemplateURLs are intended to be read-only for most users; the only public |
362 // non-const method is the Profile getter, which returns a non-const Profile*. | 354 // non-const method is the Profile getter, which returns a non-const Profile*. |
363 // The TemplateURLService, which handles storing and manipulating TemplateURLs, | 355 // The TemplateURLService, which handles storing and manipulating TemplateURLs, |
364 // is made a friend so that it can be the exception to this pattern. | 356 // is made a friend so that it can be the exception to this pattern. |
365 class TemplateURL { | 357 class TemplateURL { |
366 public: | 358 public: |
367 explicit TemplateURL(const TemplateURLData& data); | 359 // |profile| may be NULL. This will affect the results of e.g. calling |
| 360 // ReplaceSearchTerms() on the member TemplateURLRefs. |
| 361 TemplateURL(Profile* profile, const TemplateURLData& data); |
368 | 362 |
369 TemplateURL(const TemplateURL& other); | 363 TemplateURL(const TemplateURL& other); |
370 TemplateURL& operator=(const TemplateURL& other); | 364 TemplateURL& operator=(const TemplateURL& other); |
371 | 365 |
372 ~TemplateURL(); | 366 ~TemplateURL(); |
373 | 367 |
374 // Generates a favicon URL from the specified url. | 368 // Generates a favicon URL from the specified url. |
375 static GURL GenerateFaviconURL(const GURL& url); | 369 static GURL GenerateFaviconURL(const GURL& url); |
376 | 370 |
| 371 Profile* profile() { return profile_; } |
377 const TemplateURLData& data() const { return data_; } | 372 const TemplateURLData& data() const { return data_; } |
378 | 373 |
379 const string16& short_name() const { return data_.short_name; } | 374 const string16& short_name() const { return data_.short_name; } |
380 // An accessor for the short_name, but adjusted so it can be appropriately | 375 // An accessor for the short_name, but adjusted so it can be appropriately |
381 // displayed even if it is LTR and the UI is RTL. | 376 // displayed even if it is LTR and the UI is RTL. |
382 string16 AdjustedShortNameForLocaleDirection() const; | 377 string16 AdjustedShortNameForLocaleDirection() const; |
383 | 378 |
384 const string16& keyword() const { return data_.keyword(this); } | 379 const string16& keyword() const { return data_.keyword(this); } |
385 bool autogenerate_keyword() const { | 380 bool autogenerate_keyword() const { |
386 return data_.autogenerate_keyword(); | 381 return data_.autogenerate_keyword(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 | 431 |
437 private: | 432 private: |
438 friend class TemplateURLService; | 433 friend class TemplateURLService; |
439 | 434 |
440 void SetURL(const std::string& url); | 435 void SetURL(const std::string& url); |
441 void SetPrepopulateId(int id); | 436 void SetPrepopulateId(int id); |
442 | 437 |
443 // Invalidates cached values on this object and its child TemplateURLRefs. | 438 // Invalidates cached values on this object and its child TemplateURLRefs. |
444 void InvalidateCachedValues(); | 439 void InvalidateCachedValues(); |
445 | 440 |
| 441 Profile* profile_; |
446 TemplateURLData data_; | 442 TemplateURLData data_; |
447 TemplateURLRef url_ref_; | 443 TemplateURLRef url_ref_; |
448 TemplateURLRef suggestions_url_ref_; | 444 TemplateURLRef suggestions_url_ref_; |
449 TemplateURLRef instant_url_ref_; | 445 TemplateURLRef instant_url_ref_; |
450 | 446 |
451 // TODO(sky): Add date last parsed OSD file. | 447 // TODO(sky): Add date last parsed OSD file. |
452 }; | 448 }; |
453 | 449 |
454 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_ | 450 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_ |
OLD | NEW |