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 // Do not use a UIThreadSearchTermsData if a profile wasn't provided as it |
314 // results in the same thing (relevant UIThreadSearchTermsData methods default | |
315 // to SearchTermsData methods when the profile is NULL), but prevents | |
316 // validity checks on non-UI threads. | |
Peter Kasting
2013/04/17 22:50:06
This comment is extremely confusing. I would remo
gab
2013/04/18 15:00:27
Done.
| |
317 scoped_ptr<SearchTermsData> search_terms_data(profile ? | |
318 new UIThreadSearchTermsData(profile) : new SearchTermsData()); | |
319 if (template_url->url().empty() || | |
320 !template_url->url_ref().IsValidUsingTermsData(*search_terms_data) || | |
313 (!template_url->suggestions_url().empty() && | 321 (!template_url->suggestions_url().empty() && |
314 !template_url->suggestions_url_ref().IsValid())) | 322 !template_url->suggestions_url_ref(). |
323 IsValidUsingTermsData(*search_terms_data))) { | |
315 return NULL; | 324 return NULL; |
325 } | |
316 | 326 |
317 return template_url.release(); | 327 return template_url.release(); |
318 } | 328 } |
319 | 329 |
320 // static | 330 // static |
321 void TemplateURLParsingContext::InitMapping() { | 331 void TemplateURLParsingContext::InitMapping() { |
322 kElementNameToElementTypeMap = new std::map<std::string, ElementType>; | 332 kElementNameToElementTypeMap = new std::map<std::string, ElementType>; |
323 (*kElementNameToElementTypeMap)[kURLElement] = URL; | 333 (*kElementNameToElementTypeMap)[kURLElement] = URL; |
324 (*kElementNameToElementTypeMap)[kParamElement] = PARAM; | 334 (*kElementNameToElementTypeMap)[kParamElement] = PARAM; |
325 (*kElementNameToElementTypeMap)[kShortNameElement] = SHORT_NAME; | 335 (*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)); | 497 memset(&sax_handler, 0, sizeof(sax_handler)); |
488 sax_handler.startElement = &TemplateURLParsingContext::StartElementImpl; | 498 sax_handler.startElement = &TemplateURLParsingContext::StartElementImpl; |
489 sax_handler.endElement = &TemplateURLParsingContext::EndElementImpl; | 499 sax_handler.endElement = &TemplateURLParsingContext::EndElementImpl; |
490 sax_handler.characters = &TemplateURLParsingContext::CharactersImpl; | 500 sax_handler.characters = &TemplateURLParsingContext::CharactersImpl; |
491 int error = xmlSAXUserParseMemory(&sax_handler, &context, data, | 501 int error = xmlSAXUserParseMemory(&sax_handler, &context, data, |
492 static_cast<int>(length)); | 502 static_cast<int>(length)); |
493 xmlSubstituteEntitiesDefault(last_sub_entities_value); | 503 xmlSubstituteEntitiesDefault(last_sub_entities_value); |
494 | 504 |
495 return error ? NULL : context.GetTemplateURL(profile, show_in_default_list); | 505 return error ? NULL : context.GetTemplateURL(profile, show_in_default_list); |
496 } | 506 } |
OLD | NEW |