OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_TEMPLATE_URL_PARSER_H_ | 5 #ifndef CHROME_BROWSER_TEMPLATE_URL_PARSER_H__ |
6 #define CHROME_BROWSER_TEMPLATE_URL_PARSER_H_ | 6 #define CHROME_BROWSER_TEMPLATE_URL_PARSER_H__ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 | 11 |
12 class TemplateURL; | 12 class TemplateURL; |
13 | 13 |
14 // TemplateURLParser, as the name implies, handling reading of TemplateURLs | 14 // TemplateURLParser, as the name implies, handling reading of TemplateURLs |
15 // from OpenSearch description documents. | 15 // from OpenSearch description documents. |
16 class TemplateURLParser { | 16 class TemplateURLParser { |
17 public: | 17 public: |
18 class ParameterFilter { | 18 class ParameterFilter { |
19 public: | 19 public: |
20 // Invoked for each parameter of the template URL while parsing. If this | 20 // Invoked for each parameter of the template URL while parsing. If this |
21 // methods returns false, the parameter is not included. | 21 // methods returns false, the parameter is not included. |
22 virtual bool KeepParameter(const std::string& key, | 22 virtual bool KeepParameter(const std::string& key, |
23 const std::string& value) = 0; | 23 const std::string& value) = 0; |
24 protected: | |
25 ~ParameterFilter() {} | |
26 }; | 24 }; |
27 // Decodes the chunk of data representing a TemplateURL. If data does | 25 // Decodes the chunk of data representing a TemplateURL. If data does |
28 // not describe a valid TemplateURL false is returned. Additionally, if the | 26 // not describe a valid TemplateURL false is returned. Additionally, if the |
29 // URLs referenced do not point to valid http/https resources, false is | 27 // URLs referenced do not point to valid http/https resources, false is |
30 // returned. |parameter_filter| can be used if you want to filter out some | 28 // returned. |parameter_filter| can be used if you want to filter out some |
31 // parameters out of the URL. For example when importing from another browser | 29 // parameters out of the URL. For example when importing from another browser |
32 // we remove any parameter identifying that browser. If set to NULL, the URL | 30 // we remove any parameter identifying that browser. If set to NULL, the URL |
33 // is not modified. | 31 // is not modified. |
34 // | 32 // |
35 // NOTE: This does not clear all values of the supplied TemplateURL; it's | 33 // NOTE: This does not clear all values of the supplied TemplateURL; it's |
36 // expected callers will supply a new TemplateURL to this method. | 34 // expected callers will supply a new TemplateURL to this method. |
37 static bool Parse(const unsigned char* data, | 35 static bool Parse(const unsigned char* data, |
38 size_t length, | 36 size_t length, |
39 ParameterFilter* parameter_filter, | 37 ParameterFilter* parameter_filter, |
40 TemplateURL* url); | 38 TemplateURL* url); |
41 | 39 |
42 private: | 40 private: |
43 // No one should create one of these. | 41 // No one should create one of these. |
44 TemplateURLParser(); | 42 TemplateURLParser(); |
45 | 43 |
46 DISALLOW_EVIL_CONSTRUCTORS(TemplateURLParser); | 44 DISALLOW_EVIL_CONSTRUCTORS(TemplateURLParser); |
47 }; | 45 }; |
48 | 46 |
49 #endif // CHROME_BROWSER_TEMPLATE_URL_PARSER_H_ | 47 #endif // CHROME_BROWSER_TEMPLATE_URL_PARSER_H__ |
OLD | NEW |