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 #include "chrome/browser/search_engines/template_url_parser.h" | 5 #include "chrome/browser/search_engines/template_url_parser.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 query->append("="); | 92 query->append("="); |
93 } | 93 } |
94 query->append(value); | 94 query->append(value); |
95 } | 95 } |
96 | 96 |
97 // Returns true if |url| is empty or is a valid URL with a scheme of HTTP[S]. | 97 // Returns true if |url| is empty or is a valid URL with a scheme of HTTP[S]. |
98 bool IsHTTPRef(const std::string& url) { | 98 bool IsHTTPRef(const std::string& url) { |
99 if (url.empty()) | 99 if (url.empty()) |
100 return true; | 100 return true; |
101 GURL gurl(url); | 101 GURL gurl(url); |
102 return (gurl.is_valid() && (gurl.SchemeIs(chrome::kHttpScheme) || | 102 return gurl.is_valid() && (gurl.SchemeIs(chrome::kHttpScheme) || |
103 gurl.SchemeIs(chrome::kHttpsScheme))); | 103 gurl.SchemeIs(chrome::kHttpsScheme)); |
104 } | 104 } |
105 | 105 |
106 } // namespace | 106 } // namespace |
107 | 107 |
108 | 108 |
109 // TemplateURLParsingContext -------------------------------------------------- | 109 // TemplateURLParsingContext -------------------------------------------------- |
110 | 110 |
111 // To minimize memory overhead while parsing, a SAX style parser is used. | 111 // To minimize memory overhead while parsing, a SAX style parser is used. |
112 // TemplateURLParsingContext is used to maintain the state we're in the document | 112 // TemplateURLParsingContext is used to maintain the state we're in the document |
113 // while parsing. | 113 // while parsing. |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 if (derive_image_from_url_ && data_.favicon_url.is_empty()) | 305 if (derive_image_from_url_ && data_.favicon_url.is_empty()) |
306 data_.favicon_url = TemplateURL::GenerateFaviconURL(url); | 306 data_.favicon_url = TemplateURL::GenerateFaviconURL(url); |
307 | 307 |
308 // TODO(jcampan): http://b/issue?id=1196285 we do not support search engines | 308 // TODO(jcampan): http://b/issue?id=1196285 we do not support search engines |
309 // that use POST yet. | 309 // that use POST yet. |
310 if (method_ == TemplateURLParsingContext::POST) | 310 if (method_ == TemplateURLParsingContext::POST) |
311 return NULL; | 311 return NULL; |
312 if (suggestion_method_ == TemplateURLParsingContext::POST) | 312 if (suggestion_method_ == TemplateURLParsingContext::POST) |
313 data_.suggestions_url.clear(); | 313 data_.suggestions_url.clear(); |
314 | 314 |
315 // Give this a keyword to facilitate tab-to-search. | |
316 string16 keyword(TemplateURLService::GenerateKeyword(url, false)); | 315 string16 keyword(TemplateURLService::GenerateKeyword(url, false)); |
317 DCHECK(!keyword.empty()); | 316 DCHECK(!keyword.empty()); |
318 data_.SetKeyword(keyword); | 317 data_.SetKeyword(keyword); |
319 data_.show_in_default_list = show_in_default_list; | 318 data_.show_in_default_list = show_in_default_list; |
320 return new TemplateURL(data_); | 319 return new TemplateURL(data_); |
321 } | 320 } |
322 | 321 |
323 // static | 322 // static |
324 void TemplateURLParsingContext::InitMapping() { | 323 void TemplateURLParsingContext::InitMapping() { |
325 kElementNameToElementTypeMap = new std::map<std::string, ElementType>; | 324 kElementNameToElementTypeMap = new std::map<std::string, ElementType>; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 xmlSAXHandler sax_handler; | 488 xmlSAXHandler sax_handler; |
490 memset(&sax_handler, 0, sizeof(sax_handler)); | 489 memset(&sax_handler, 0, sizeof(sax_handler)); |
491 sax_handler.startElement = &TemplateURLParsingContext::StartElementImpl; | 490 sax_handler.startElement = &TemplateURLParsingContext::StartElementImpl; |
492 sax_handler.endElement = &TemplateURLParsingContext::EndElementImpl; | 491 sax_handler.endElement = &TemplateURLParsingContext::EndElementImpl; |
493 sax_handler.characters = &TemplateURLParsingContext::CharactersImpl; | 492 sax_handler.characters = &TemplateURLParsingContext::CharactersImpl; |
494 xmlSAXUserParseMemory(&sax_handler, &context, data, static_cast<int>(length)); | 493 xmlSAXUserParseMemory(&sax_handler, &context, data, static_cast<int>(length)); |
495 xmlSubstituteEntitiesDefault(last_sub_entities_value); | 494 xmlSubstituteEntitiesDefault(last_sub_entities_value); |
496 | 495 |
497 return context.GetTemplateURL(profile, show_in_default_list); | 496 return context.GetTemplateURL(profile, show_in_default_list); |
498 } | 497 } |
OLD | NEW |