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 |
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/string_util.h" | 13 #include "base/string_util.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "chrome/browser/search_engines/search_terms_data.h" |
16 #include "chrome/browser/search_engines/template_url.h" | 17 #include "chrome/browser/search_engines/template_url.h" |
17 #include "chrome/browser/search_engines/template_url_service.h" | 18 #include "chrome/browser/search_engines/template_url_service.h" |
18 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
19 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
20 #include "libxml/parser.h" | 21 #include "libxml/parser.h" |
21 #include "libxml/xmlwriter.h" | 22 #include "libxml/xmlwriter.h" |
22 #include "ui/gfx/favicon_size.h" | 23 #include "ui/gfx/favicon_size.h" |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 // (see the TODO in EndElementImpl()). | 303 // (see the TODO in EndElementImpl()). |
303 GURL search_url(data_.url()); | 304 GURL search_url(data_.url()); |
304 if (derive_image_from_url_ && data_.favicon_url.is_empty()) | 305 if (derive_image_from_url_ && data_.favicon_url.is_empty()) |
305 data_.favicon_url = TemplateURL::GenerateFaviconURL(search_url); | 306 data_.favicon_url = TemplateURL::GenerateFaviconURL(search_url); |
306 | 307 |
307 data_.SetKeyword(TemplateURLService::GenerateKeyword(search_url)); | 308 data_.SetKeyword(TemplateURLService::GenerateKeyword(search_url)); |
308 data_.show_in_default_list = show_in_default_list; | 309 data_.show_in_default_list = show_in_default_list; |
309 | 310 |
310 // Bail if the search URL is empty or if either TemplateURLRef is invalid. | 311 // Bail if the search URL is empty or if either TemplateURLRef is invalid. |
311 scoped_ptr<TemplateURL> template_url(new TemplateURL(profile, data_)); | 312 scoped_ptr<TemplateURL> template_url(new TemplateURL(profile, data_)); |
312 if (template_url->url().empty() || !template_url->url_ref().IsValid() || | 313 scoped_ptr<SearchTermsData> search_terms_data(profile ? |
| 314 new UIThreadSearchTermsData(profile) : new SearchTermsData()); |
| 315 if (template_url->url().empty() || |
| 316 !template_url->url_ref().IsValidUsingTermsData(*search_terms_data) || |
313 (!template_url->suggestions_url().empty() && | 317 (!template_url->suggestions_url().empty() && |
314 !template_url->suggestions_url_ref().IsValid())) | 318 !template_url->suggestions_url_ref(). |
| 319 IsValidUsingTermsData(*search_terms_data))) { |
315 return NULL; | 320 return NULL; |
| 321 } |
316 | 322 |
317 return template_url.release(); | 323 return template_url.release(); |
318 } | 324 } |
319 | 325 |
320 // static | 326 // static |
321 void TemplateURLParsingContext::InitMapping() { | 327 void TemplateURLParsingContext::InitMapping() { |
322 kElementNameToElementTypeMap = new std::map<std::string, ElementType>; | 328 kElementNameToElementTypeMap = new std::map<std::string, ElementType>; |
323 (*kElementNameToElementTypeMap)[kURLElement] = URL; | 329 (*kElementNameToElementTypeMap)[kURLElement] = URL; |
324 (*kElementNameToElementTypeMap)[kParamElement] = PARAM; | 330 (*kElementNameToElementTypeMap)[kParamElement] = PARAM; |
325 (*kElementNameToElementTypeMap)[kShortNameElement] = SHORT_NAME; | 331 (*kElementNameToElementTypeMap)[kShortNameElement] = SHORT_NAME; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 memset(&sax_handler, 0, sizeof(sax_handler)); | 493 memset(&sax_handler, 0, sizeof(sax_handler)); |
488 sax_handler.startElement = &TemplateURLParsingContext::StartElementImpl; | 494 sax_handler.startElement = &TemplateURLParsingContext::StartElementImpl; |
489 sax_handler.endElement = &TemplateURLParsingContext::EndElementImpl; | 495 sax_handler.endElement = &TemplateURLParsingContext::EndElementImpl; |
490 sax_handler.characters = &TemplateURLParsingContext::CharactersImpl; | 496 sax_handler.characters = &TemplateURLParsingContext::CharactersImpl; |
491 int error = xmlSAXUserParseMemory(&sax_handler, &context, data, | 497 int error = xmlSAXUserParseMemory(&sax_handler, &context, data, |
492 static_cast<int>(length)); | 498 static_cast<int>(length)); |
493 xmlSubstituteEntitiesDefault(last_sub_entities_value); | 499 xmlSubstituteEntitiesDefault(last_sub_entities_value); |
494 | 500 |
495 return error ? NULL : context.GetTemplateURL(profile, show_in_default_list); | 501 return error ? NULL : context.GetTemplateURL(profile, show_in_default_list); |
496 } | 502 } |
OLD | NEW |