| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/search_engines/template_url_parser.h" | 5 #include "components/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 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "components/search_engines/search_terms_data.h" |
| 16 #include "components/search_engines/template_url.h" | 17 #include "components/search_engines/template_url.h" |
| 17 #include "libxml/parser.h" | 18 #include "libxml/parser.h" |
| 18 #include "libxml/xmlwriter.h" | 19 #include "libxml/xmlwriter.h" |
| 19 #include "ui/gfx/favicon_size.h" | 20 #include "ui/gfx/favicon_size.h" |
| 20 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 21 #include "url/url_constants.h" | 22 #include "url/url_constants.h" |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 // NOTE: libxml uses the UTF-8 encoding. As 0-127 of UTF-8 corresponds | 26 // NOTE: libxml uses the UTF-8 encoding. As 0-127 of UTF-8 corresponds |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 | 309 |
| 309 // If the image was a data URL, use the favicon from the search URL instead. | 310 // If the image was a data URL, use the favicon from the search URL instead. |
| 310 // (see the TODO in EndElementImpl()). | 311 // (see the TODO in EndElementImpl()). |
| 311 GURL search_url(data_.url()); | 312 GURL search_url(data_.url()); |
| 312 if (derive_image_from_url_ && data_.favicon_url.is_empty()) | 313 if (derive_image_from_url_ && data_.favicon_url.is_empty()) |
| 313 data_.favicon_url = TemplateURL::GenerateFaviconURL(search_url); | 314 data_.favicon_url = TemplateURL::GenerateFaviconURL(search_url); |
| 314 | 315 |
| 315 // Generate a keyword for this search engine if a custom one was not present | 316 // Generate a keyword for this search engine if a custom one was not present |
| 316 // in the imported data. | 317 // in the imported data. |
| 317 if (!has_custom_keyword_) | 318 if (!has_custom_keyword_) |
| 318 data_.SetKeyword(TemplateURL::GenerateKeyword(search_url)); | 319 data_.SetKeyword(TemplateURL::GenerateKeyword( |
| 320 search_url, search_terms_data.GetAcceptLanguages())); |
| 319 | 321 |
| 320 data_.show_in_default_list = show_in_default_list; | 322 data_.show_in_default_list = show_in_default_list; |
| 321 | 323 |
| 322 // Bail if the search URL is empty or if either TemplateURLRef is invalid. | 324 // Bail if the search URL is empty or if either TemplateURLRef is invalid. |
| 323 scoped_ptr<TemplateURL> template_url(new TemplateURL(data_)); | 325 scoped_ptr<TemplateURL> template_url(new TemplateURL(data_)); |
| 324 if (template_url->url().empty() || | 326 if (template_url->url().empty() || |
| 325 !template_url->url_ref().IsValid(search_terms_data) || | 327 !template_url->url_ref().IsValid(search_terms_data) || |
| 326 (!template_url->suggestions_url().empty() && | 328 (!template_url->suggestions_url().empty() && |
| 327 !template_url->suggestions_url_ref().IsValid(search_terms_data))) { | 329 !template_url->suggestions_url_ref().IsValid(search_terms_data))) { |
| 328 return NULL; | 330 return NULL; |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 sax_handler.startElement = &TemplateURLParsingContext::StartElementImpl; | 505 sax_handler.startElement = &TemplateURLParsingContext::StartElementImpl; |
| 504 sax_handler.endElement = &TemplateURLParsingContext::EndElementImpl; | 506 sax_handler.endElement = &TemplateURLParsingContext::EndElementImpl; |
| 505 sax_handler.characters = &TemplateURLParsingContext::CharactersImpl; | 507 sax_handler.characters = &TemplateURLParsingContext::CharactersImpl; |
| 506 int error = xmlSAXUserParseMemory(&sax_handler, &context, data, | 508 int error = xmlSAXUserParseMemory(&sax_handler, &context, data, |
| 507 static_cast<int>(length)); | 509 static_cast<int>(length)); |
| 508 xmlSubstituteEntitiesDefault(last_sub_entities_value); | 510 xmlSubstituteEntitiesDefault(last_sub_entities_value); |
| 509 | 511 |
| 510 return error ? | 512 return error ? |
| 511 NULL : context.GetTemplateURL(search_terms_data, show_in_default_list); | 513 NULL : context.GetTemplateURL(search_terms_data, show_in_default_list); |
| 512 } | 514 } |
| OLD | NEW |