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 <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <map> | 10 #include <map> |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 const xmlChar* ch, | 296 const xmlChar* ch, |
297 int len) { | 297 int len) { |
298 reinterpret_cast<TemplateURLParsingContext*>(ctx)->string_ += | 298 reinterpret_cast<TemplateURLParsingContext*>(ctx)->string_ += |
299 base::UTF8ToUTF16( | 299 base::UTF8ToUTF16( |
300 base::StringPiece(reinterpret_cast<const char*>(ch), len)); | 300 base::StringPiece(reinterpret_cast<const char*>(ch), len)); |
301 } | 301 } |
302 | 302 |
303 std::unique_ptr<TemplateURL> TemplateURLParsingContext::GetTemplateURL( | 303 std::unique_ptr<TemplateURL> TemplateURLParsingContext::GetTemplateURL( |
304 const SearchTermsData& search_terms_data) { | 304 const SearchTermsData& search_terms_data) { |
305 // TODO(jcampan): Support engines that use POST; see http://crbug.com/18107 | 305 // TODO(jcampan): Support engines that use POST; see http://crbug.com/18107 |
306 if (method_ == TemplateURLParsingContext::POST || | 306 if (method_ == TemplateURLParsingContext::POST || !IsHTTPRef(data_.url()) || |
307 data_.short_name().empty() || !IsHTTPRef(data_.url()) || | |
308 !IsHTTPRef(data_.suggestions_url)) | 307 !IsHTTPRef(data_.suggestions_url)) |
309 return nullptr; | 308 return nullptr; |
310 if (suggestion_method_ == TemplateURLParsingContext::POST) | 309 if (suggestion_method_ == TemplateURLParsingContext::POST) |
311 data_.suggestions_url.clear(); | 310 data_.suggestions_url.clear(); |
312 | 311 |
313 // If the image was a data URL, use the favicon from the search URL instead. | 312 // If the image was a data URL, use the favicon from the search URL instead. |
314 // (see the TODO in EndElementImpl()). | 313 // (see the TODO in EndElementImpl()). |
315 GURL search_url(data_.url()); | 314 GURL search_url(data_.url()); |
316 if (derive_image_from_url_ && data_.favicon_url.is_empty()) | 315 if (derive_image_from_url_ && data_.favicon_url.is_empty()) |
317 data_.favicon_url = TemplateURL::GenerateFaviconURL(search_url); | 316 data_.favicon_url = TemplateURL::GenerateFaviconURL(search_url); |
318 | 317 |
319 // Generate a keyword for this search engine if a custom one was not present | 318 // Generate a keyword for this search engine if a custom one was not present |
320 // in the imported data. | 319 // in the imported data. |
321 if (!has_custom_keyword_) | 320 if (!has_custom_keyword_) |
322 data_.SetKeyword(TemplateURL::GenerateKeyword(search_url)); | 321 data_.SetKeyword(TemplateURL::GenerateKeyword(search_url)); |
323 | 322 |
| 323 // If the OSDD omits or has an empty short name, use the keyword. |
| 324 if (data_.short_name().empty()) |
| 325 data_.SetShortName(data_.keyword()); |
| 326 |
324 // Bail if the search URL is empty or if either TemplateURLRef is invalid. | 327 // Bail if the search URL is empty or if either TemplateURLRef is invalid. |
325 std::unique_ptr<TemplateURL> template_url = | 328 std::unique_ptr<TemplateURL> template_url = |
326 base::MakeUnique<TemplateURL>(data_); | 329 base::MakeUnique<TemplateURL>(data_); |
327 if (template_url->url().empty() || | 330 if (template_url->url().empty() || |
328 !template_url->url_ref().IsValid(search_terms_data) || | 331 !template_url->url_ref().IsValid(search_terms_data) || |
329 (!template_url->suggestions_url().empty() && | 332 (!template_url->suggestions_url().empty() && |
330 !template_url->suggestions_url_ref().IsValid(search_terms_data))) { | 333 !template_url->suggestions_url_ref().IsValid(search_terms_data))) { |
331 return nullptr; | 334 return nullptr; |
332 } | 335 } |
333 | 336 |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 memset(&sax_handler, 0, sizeof(sax_handler)); | 507 memset(&sax_handler, 0, sizeof(sax_handler)); |
505 sax_handler.startElement = &TemplateURLParsingContext::StartElementImpl; | 508 sax_handler.startElement = &TemplateURLParsingContext::StartElementImpl; |
506 sax_handler.endElement = &TemplateURLParsingContext::EndElementImpl; | 509 sax_handler.endElement = &TemplateURLParsingContext::EndElementImpl; |
507 sax_handler.characters = &TemplateURLParsingContext::CharactersImpl; | 510 sax_handler.characters = &TemplateURLParsingContext::CharactersImpl; |
508 int error = xmlSAXUserParseMemory(&sax_handler, &context, data, | 511 int error = xmlSAXUserParseMemory(&sax_handler, &context, data, |
509 static_cast<int>(length)); | 512 static_cast<int>(length)); |
510 xmlSubstituteEntitiesDefault(last_sub_entities_value); | 513 xmlSubstituteEntitiesDefault(last_sub_entities_value); |
511 | 514 |
512 return error ? nullptr : context.GetTemplateURL(search_terms_data); | 515 return error ? nullptr : context.GetTemplateURL(search_terms_data); |
513 } | 516 } |
OLD | NEW |