OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 65 |
66 // Returns a string that is the result of replacing the search terms in | 66 // Returns a string that is the result of replacing the search terms in |
67 // the url with the specified value. | 67 // the url with the specified value. |
68 // | 68 // |
69 // If this TemplateURLRef does not support replacement (SupportsReplacement | 69 // If this TemplateURLRef does not support replacement (SupportsReplacement |
70 // returns false), an empty string is returned. | 70 // returns false), an empty string is returned. |
71 // | 71 // |
72 // The TemplateURL is used to determine the input encoding for the term. | 72 // The TemplateURL is used to determine the input encoding for the term. |
73 std::string ReplaceSearchTerms( | 73 std::string ReplaceSearchTerms( |
74 const TemplateURL& host, | 74 const TemplateURL& host, |
75 const std::wstring& terms, | 75 const string16& terms, |
76 int accepted_suggestion, | 76 int accepted_suggestion, |
77 const std::wstring& original_query_for_suggestion) const; | 77 const string16& original_query_for_suggestion) const; |
78 | 78 |
79 // Just like ReplaceSearchTerms except that it takes SearchTermsData to supply | 79 // Just like ReplaceSearchTerms except that it takes SearchTermsData to supply |
80 // the data for some search terms. Most of the time ReplaceSearchTerms should | 80 // the data for some search terms. Most of the time ReplaceSearchTerms should |
81 // be called. | 81 // be called. |
82 std::string ReplaceSearchTermsUsingTermsData( | 82 std::string ReplaceSearchTermsUsingTermsData( |
83 const TemplateURL& host, | 83 const TemplateURL& host, |
84 const std::wstring& terms, | 84 const string16& terms, |
85 int accepted_suggestion, | 85 int accepted_suggestion, |
86 const std::wstring& original_query_for_suggestion, | 86 const string16& original_query_for_suggestion, |
87 const SearchTermsData& search_terms_data) const; | 87 const SearchTermsData& search_terms_data) const; |
88 | 88 |
89 // Returns the raw URL. None of the parameters will have been replaced. | 89 // Returns the raw URL. None of the parameters will have been replaced. |
90 const std::string& url() const { return url_; } | 90 const std::string& url() const { return url_; } |
91 | 91 |
92 // Returns the index number of the first search result. | 92 // Returns the index number of the first search result. |
93 int index_offset() const { return index_offset_; } | 93 int index_offset() const { return index_offset_; } |
94 | 94 |
95 // Returns the page number of the first search results. | 95 // Returns the page number of the first search results. |
96 int page_offset() const { return page_offset_; } | 96 int page_offset() const { return page_offset_; } |
97 | 97 |
98 // Returns true if the TemplateURLRef is valid. An invalid TemplateURLRef is | 98 // Returns true if the TemplateURLRef is valid. An invalid TemplateURLRef is |
99 // one that contains unknown terms, or invalid characters. | 99 // one that contains unknown terms, or invalid characters. |
100 bool IsValid() const; | 100 bool IsValid() const; |
101 | 101 |
102 // Like IsValid but usable on threads other than the UI thread. | 102 // Like IsValid but usable on threads other than the UI thread. |
103 bool IsValidUsingTermsData(const SearchTermsData& search_terms_data) const; | 103 bool IsValidUsingTermsData(const SearchTermsData& search_terms_data) const; |
104 | 104 |
105 // Returns a string representation of this TemplateURLRef suitable for | 105 // Returns a string representation of this TemplateURLRef suitable for |
106 // display. The display format is the same as the format used by Firefox. | 106 // display. The display format is the same as the format used by Firefox. |
107 std::wstring DisplayURL() const; | 107 string16 DisplayURL() const; |
108 | 108 |
109 // Converts a string as returned by DisplayURL back into a string as | 109 // Converts a string as returned by DisplayURL back into a string as |
110 // understood by TemplateURLRef. | 110 // understood by TemplateURLRef. |
111 static std::string DisplayURLToURLRef(const std::wstring& display_url); | 111 static std::string DisplayURLToURLRef(const string16& display_url); |
112 | 112 |
113 // If this TemplateURLRef is valid and contains one search term, this returns | 113 // If this TemplateURLRef is valid and contains one search term, this returns |
114 // the host/path of the URL, otherwise this returns an empty string. | 114 // the host/path of the URL, otherwise this returns an empty string. |
115 const std::string& GetHost() const; | 115 const std::string& GetHost() const; |
116 const std::string& GetPath() const; | 116 const std::string& GetPath() const; |
117 | 117 |
118 // If this TemplateURLRef is valid and contains one search term, this returns | 118 // If this TemplateURLRef is valid and contains one search term, this returns |
119 // the key of the search term, otherwise this returns an empty string. | 119 // the key of the search term, otherwise this returns an empty string. |
120 const std::string& GetSearchTermKey() const; | 120 const std::string& GetSearchTermKey() const; |
121 | 121 |
122 // Converts the specified term in the encoding of the host TemplateURL to a | 122 // Converts the specified term in the encoding of the host TemplateURL to a |
123 // wide string. | 123 // string16. |
124 std::wstring SearchTermToWide(const TemplateURL& host, | 124 string16 SearchTermToString16(const TemplateURL& host, |
125 const std::string& term) const; | 125 const std::string& term) const; |
126 | 126 |
127 // Returns true if this TemplateURLRef has a replacement term of | 127 // Returns true if this TemplateURLRef has a replacement term of |
128 // {google:baseURL} or {google:baseSuggestURL}. | 128 // {google:baseURL} or {google:baseSuggestURL}. |
129 bool HasGoogleBaseURLs() const; | 129 bool HasGoogleBaseURLs() const; |
130 | 130 |
131 // Returns true if both refs are NULL or have the same values. | 131 // Returns true if both refs are NULL or have the same values. |
132 static bool SameUrlRefs(const TemplateURLRef* ref1, | 132 static bool SameUrlRefs(const TemplateURLRef* ref1, |
133 const TemplateURLRef* ref2); | 133 const TemplateURLRef* ref2); |
134 | 134 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 | 252 |
253 // Describes the relevant portions of a single OSD document. | 253 // Describes the relevant portions of a single OSD document. |
254 class TemplateURL { | 254 class TemplateURL { |
255 public: | 255 public: |
256 // Describes a single image reference. Each TemplateURL may have | 256 // Describes a single image reference. Each TemplateURL may have |
257 // any number (including 0) of ImageRefs. | 257 // any number (including 0) of ImageRefs. |
258 // | 258 // |
259 // If a TemplateURL has no images, the favicon for the generated URL | 259 // If a TemplateURL has no images, the favicon for the generated URL |
260 // should be used. | 260 // should be used. |
261 struct ImageRef { | 261 struct ImageRef { |
262 ImageRef(const std::wstring& type, int width, int height) | 262 ImageRef(const std::string& type, int width, int height) |
263 : type(type), width(width), height(height) { | 263 : type(type), width(width), height(height) { |
264 } | 264 } |
265 | 265 |
266 ImageRef(const std::wstring& type, int width, int height, const GURL& url) | 266 ImageRef(const std::string& type, int width, int height, const GURL& url) |
267 : type(type), width(width), height(height), url(url) { | 267 : type(type), width(width), height(height), url(url) { |
268 } | 268 } |
269 | 269 |
270 // Mime type for the image. | 270 // Mime type for the image. |
271 // ICO image will have the format: image/x-icon or image/vnd.microsoft.icon | 271 // ICO image will have the format: image/x-icon or image/vnd.microsoft.icon |
272 std::wstring type; | 272 std::string type; |
273 | 273 |
274 // Size of the image | 274 // Size of the image |
275 int width; | 275 int width; |
276 int height; | 276 int height; |
277 | 277 |
278 // URL of the image. | 278 // URL of the image. |
279 GURL url; | 279 GURL url; |
280 }; | 280 }; |
281 | 281 |
282 // Generates a favicon URL from the specified url. | 282 // Generates a favicon URL from the specified url. |
283 static GURL GenerateFaviconURL(const GURL& url); | 283 static GURL GenerateFaviconURL(const GURL& url); |
284 | 284 |
285 // Returns true if |turl| is non-null and has a search URL that supports | 285 // Returns true if |turl| is non-null and has a search URL that supports |
286 // replacement. | 286 // replacement. |
287 static bool SupportsReplacement(const TemplateURL* turl); | 287 static bool SupportsReplacement(const TemplateURL* turl); |
288 | 288 |
289 // Like SupportsReplacement but usable on threads other than the UI thread. | 289 // Like SupportsReplacement but usable on threads other than the UI thread. |
290 static bool SupportsReplacementUsingTermsData( | 290 static bool SupportsReplacementUsingTermsData( |
291 const TemplateURL* turl, | 291 const TemplateURL* turl, |
292 const SearchTermsData& search_terms_data); | 292 const SearchTermsData& search_terms_data); |
293 | 293 |
294 TemplateURL(); | 294 TemplateURL(); |
295 ~TemplateURL(); | 295 ~TemplateURL(); |
296 | 296 |
297 // A short description of the template. This is the name we show to the user | 297 // A short description of the template. This is the name we show to the user |
298 // in various places that use keywords. For example, the location bar shows | 298 // in various places that use keywords. For example, the location bar shows |
299 // this when the user selects the keyword. | 299 // this when the user selects the keyword. |
300 void set_short_name(const std::wstring& short_name) { | 300 void set_short_name(const string16& short_name) { |
301 short_name_ = short_name; | 301 short_name_ = short_name; |
302 } | 302 } |
303 const std::wstring& short_name() const { return short_name_; } | 303 string16 short_name() const { return short_name_; } |
304 | 304 |
305 // An accessor for the short_name, but adjusted so it can be appropriately | 305 // An accessor for the short_name, but adjusted so it can be appropriately |
306 // displayed even if it is LTR and the UI is RTL. | 306 // displayed even if it is LTR and the UI is RTL. |
307 std::wstring AdjustedShortNameForLocaleDirection() const; | 307 string16 AdjustedShortNameForLocaleDirection() const; |
308 | 308 |
309 // A description of the template; this may be empty. | 309 // A description of the template; this may be empty. |
310 void set_description(const std::wstring& description) { | 310 void set_description(const string16& description) { |
311 description_ = description; | 311 description_ = description; |
312 } | 312 } |
313 const std::wstring& description() const { return description_; } | 313 string16 description() const { return description_; } |
314 | 314 |
315 // URL providing JSON results. This is typically used to provide suggestions | 315 // URL providing JSON results. This is typically used to provide suggestions |
316 // as your type. If NULL, this url does not support suggestions. | 316 // as your type. If NULL, this url does not support suggestions. |
317 // Be sure and check the resulting TemplateURLRef for SupportsReplacement | 317 // Be sure and check the resulting TemplateURLRef for SupportsReplacement |
318 // before using. | 318 // before using. |
319 void SetSuggestionsURL(const std::string& suggestions_url, | 319 void SetSuggestionsURL(const std::string& suggestions_url, |
320 int index_offset, | 320 int index_offset, |
321 int page_offset); | 321 int page_offset); |
322 const TemplateURLRef* suggestions_url() const { | 322 const TemplateURLRef* suggestions_url() const { |
323 return suggestions_url_.url().empty() ? NULL : &suggestions_url_; | 323 return suggestions_url_.url().empty() ? NULL : &suggestions_url_; |
(...skipping 19 matching lines...) Expand all Loading... |
343 return instant_url_.url().empty() ? NULL : &instant_url_; | 343 return instant_url_.url().empty() ? NULL : &instant_url_; |
344 } | 344 } |
345 | 345 |
346 // URL to the OSD file this came from. May be empty. | 346 // URL to the OSD file this came from. May be empty. |
347 void set_originating_url(const GURL& url) { | 347 void set_originating_url(const GURL& url) { |
348 originating_url_ = url; | 348 originating_url_ = url; |
349 } | 349 } |
350 const GURL& originating_url() const { return originating_url_; } | 350 const GURL& originating_url() const { return originating_url_; } |
351 | 351 |
352 // The shortcut for this template url. May be empty. | 352 // The shortcut for this template url. May be empty. |
353 void set_keyword(const std::wstring& keyword); | 353 void set_keyword(const string16& keyword); |
354 const std::wstring& keyword() const; | 354 string16 keyword() const; |
355 | 355 |
356 // Whether to autogenerate a keyword from the url() in GetKeyword(). Most | 356 // Whether to autogenerate a keyword from the url() in GetKeyword(). Most |
357 // consumers should not need this. | 357 // consumers should not need this. |
358 // NOTE: Calling set_keyword() turns this back off. Manual and automatic | 358 // NOTE: Calling set_keyword() turns this back off. Manual and automatic |
359 // keywords are mutually exclusive. | 359 // keywords are mutually exclusive. |
360 void set_autogenerate_keyword(bool autogenerate_keyword) { | 360 void set_autogenerate_keyword(bool autogenerate_keyword) { |
361 autogenerate_keyword_ = autogenerate_keyword; | 361 autogenerate_keyword_ = autogenerate_keyword; |
362 if (autogenerate_keyword_) { | 362 if (autogenerate_keyword_) { |
363 keyword_.clear(); | 363 keyword_.clear(); |
364 keyword_generated_ = false; | 364 keyword_generated_ = false; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 | 403 |
404 // Convenience methods for getting/setting an ImageRef that points to a | 404 // Convenience methods for getting/setting an ImageRef that points to a |
405 // favicon. A TemplateURL need not have an ImageRef for a favicon. In such | 405 // favicon. A TemplateURL need not have an ImageRef for a favicon. In such |
406 // a situation GetFavIconURL returns an invalid url. | 406 // a situation GetFavIconURL returns an invalid url. |
407 // | 407 // |
408 // If url is empty and there is an image ref for a favicon, it is removed. | 408 // If url is empty and there is an image ref for a favicon, it is removed. |
409 void SetFavIconURL(const GURL& url); | 409 void SetFavIconURL(const GURL& url); |
410 GURL GetFavIconURL() const; | 410 GURL GetFavIconURL() const; |
411 | 411 |
412 // Set of languages supported. This may be empty. | 412 // Set of languages supported. This may be empty. |
413 void add_language(const std::wstring& language) { | 413 void add_language(const string16& language) { |
414 languages_.push_back(language); | 414 languages_.push_back(language); |
415 } | 415 } |
416 const std::vector<std::wstring>& languages() const { return languages_; } | 416 std::vector<string16> languages() const { return languages_; } |
417 | 417 |
418 // Date this keyword was created. | 418 // Date this keyword was created. |
419 // | 419 // |
420 // NOTE: this may be 0, which indicates the keyword was created before we | 420 // NOTE: this may be 0, which indicates the keyword was created before we |
421 // started tracking creation time. | 421 // started tracking creation time. |
422 void set_date_created(base::Time time) { date_created_ = time; } | 422 void set_date_created(base::Time time) { date_created_ = time; } |
423 base::Time date_created() const { return date_created_; } | 423 base::Time date_created() const { return date_created_; } |
424 | 424 |
425 // True if this TemplateURL was automatically created by the administrator via | 425 // True if this TemplateURL was automatically created by the administrator via |
426 // group policy. | 426 // group policy. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 friend class TemplateURLModel; | 480 friend class TemplateURLModel; |
481 friend class WebDatabaseTest; | 481 friend class WebDatabaseTest; |
482 friend class WebDatabase; | 482 friend class WebDatabase; |
483 | 483 |
484 // Invalidates cached values on this object and its child TemplateURLRefs. | 484 // Invalidates cached values on this object and its child TemplateURLRefs. |
485 void InvalidateCachedValues() const; | 485 void InvalidateCachedValues() const; |
486 | 486 |
487 // Unique identifier, used when archived to the database. | 487 // Unique identifier, used when archived to the database. |
488 void set_id(TemplateURLID id) { id_ = id;} | 488 void set_id(TemplateURLID id) { id_ = id;} |
489 | 489 |
490 std::wstring short_name_; | 490 string16 short_name_; |
491 std::wstring description_; | 491 string16 description_; |
492 TemplateURLRef suggestions_url_; | 492 TemplateURLRef suggestions_url_; |
493 TemplateURLRef url_; | 493 TemplateURLRef url_; |
494 TemplateURLRef instant_url_; | 494 TemplateURLRef instant_url_; |
495 GURL originating_url_; | 495 GURL originating_url_; |
496 mutable std::wstring keyword_; | 496 mutable string16 keyword_; |
497 bool autogenerate_keyword_; // If this is set, |keyword_| holds the cached | 497 bool autogenerate_keyword_; // If this is set, |keyword_| holds the cached |
498 // generated keyword if available. | 498 // generated keyword if available. |
499 mutable bool keyword_generated_; // True if the keyword was generated. This | 499 mutable bool keyword_generated_; // True if the keyword was generated. This |
500 // is used to avoid multiple attempts if | 500 // is used to avoid multiple attempts if |
501 // generating a keyword failed. | 501 // generating a keyword failed. |
502 bool show_in_default_list_; | 502 bool show_in_default_list_; |
503 bool safe_for_autoreplace_; | 503 bool safe_for_autoreplace_; |
504 std::vector<ImageRef> image_refs_; | 504 std::vector<ImageRef> image_refs_; |
505 std::vector<std::wstring> languages_; | 505 std::vector<string16> languages_; |
506 // List of supported input encodings. | 506 // List of supported input encodings. |
507 std::vector<std::string> input_encodings_; | 507 std::vector<std::string> input_encodings_; |
508 TemplateURLID id_; | 508 TemplateURLID id_; |
509 base::Time date_created_; | 509 base::Time date_created_; |
510 bool created_by_policy_; | 510 bool created_by_policy_; |
511 int usage_count_; | 511 int usage_count_; |
512 SearchEngineType search_engine_type_; | 512 SearchEngineType search_engine_type_; |
513 int logo_id_; | 513 int logo_id_; |
514 int prepopulate_id_; | 514 int prepopulate_id_; |
515 | 515 |
516 // TODO(sky): Add date last parsed OSD file. | 516 // TODO(sky): Add date last parsed OSD file. |
517 }; | 517 }; |
518 | 518 |
519 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_ | 519 #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_H_ |
OLD | NEW |