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 <string> | |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.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" |
20 #include "net/base/net_util.h" | |
19 #include "ui/gfx/favicon_size.h" | 21 #include "ui/gfx/favicon_size.h" |
20 #include "url/gurl.h" | 22 #include "url/gurl.h" |
21 #include "url/url_constants.h" | 23 #include "url/url_constants.h" |
22 | 24 |
23 namespace { | 25 namespace { |
24 | 26 |
25 // NOTE: libxml uses the UTF-8 encoding. As 0-127 of UTF-8 corresponds | 27 // NOTE: libxml uses the UTF-8 encoding. As 0-127 of UTF-8 corresponds |
26 // to that of char, the following names are all in terms of char. This avoids | 28 // to that of char, the following names are all in terms of char. This avoids |
27 // having to convert to wide, then do comparisons. | 29 // having to convert to wide, then do comparisons. |
28 | 30 |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
244 | 246 |
245 // static | 247 // static |
246 void TemplateURLParsingContext::EndElementImpl(void* ctx, const xmlChar* name) { | 248 void TemplateURLParsingContext::EndElementImpl(void* ctx, const xmlChar* name) { |
247 TemplateURLParsingContext* context = | 249 TemplateURLParsingContext* context = |
248 reinterpret_cast<TemplateURLParsingContext*>(ctx); | 250 reinterpret_cast<TemplateURLParsingContext*>(ctx); |
249 switch (context->GetKnownType()) { | 251 switch (context->GetKnownType()) { |
250 case TemplateURLParsingContext::URL: | 252 case TemplateURLParsingContext::URL: |
251 context->ProcessURLParams(); | 253 context->ProcessURLParams(); |
252 break; | 254 break; |
253 case TemplateURLParsingContext::SHORT_NAME: | 255 case TemplateURLParsingContext::SHORT_NAME: |
254 context->data_.SetShortName(context->string_); | 256 // If someone gives us ShortName in punycode, decode it. |
257 context->data_.SetShortName( | |
258 base::IsStringASCII(context->string_) | |
Matt Giuca
2015/07/17 04:13:11
This should not be unpunycoded. The ShortName fiel
alshabalin
2015/07/20 14:06:38
Done.
| |
259 ? net::IDNToUnicode(base::UTF16ToASCII(context->string_), | |
260 std::string()) | |
261 : context->string_); | |
255 break; | 262 break; |
256 case TemplateURLParsingContext::IMAGE: { | 263 case TemplateURLParsingContext::IMAGE: { |
257 GURL image_url(base::UTF16ToUTF8(context->string_)); | 264 GURL image_url(base::UTF16ToUTF8(context->string_)); |
258 if (image_url.SchemeIs(url::kDataScheme)) { | 265 if (image_url.SchemeIs(url::kDataScheme)) { |
259 // TODO (jcampan): bug 1169256: when dealing with data URL, we need to | 266 // TODO (jcampan): bug 1169256: when dealing with data URL, we need to |
260 // decode the data URL in the renderer. For now, we'll just point to the | 267 // decode the data URL in the renderer. For now, we'll just point to the |
261 // favicon from the URL. | 268 // favicon from the URL. |
262 context->derive_image_from_url_ = true; | 269 context->derive_image_from_url_ = true; |
263 } else if (context->image_is_valid_for_favicon_ && image_url.is_valid() && | 270 } else if (context->image_is_valid_for_favicon_ && image_url.is_valid() && |
264 (image_url.SchemeIs(url::kHttpScheme) || | 271 (image_url.SchemeIs(url::kHttpScheme) || |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
503 sax_handler.startElement = &TemplateURLParsingContext::StartElementImpl; | 510 sax_handler.startElement = &TemplateURLParsingContext::StartElementImpl; |
504 sax_handler.endElement = &TemplateURLParsingContext::EndElementImpl; | 511 sax_handler.endElement = &TemplateURLParsingContext::EndElementImpl; |
505 sax_handler.characters = &TemplateURLParsingContext::CharactersImpl; | 512 sax_handler.characters = &TemplateURLParsingContext::CharactersImpl; |
506 int error = xmlSAXUserParseMemory(&sax_handler, &context, data, | 513 int error = xmlSAXUserParseMemory(&sax_handler, &context, data, |
507 static_cast<int>(length)); | 514 static_cast<int>(length)); |
508 xmlSubstituteEntitiesDefault(last_sub_entities_value); | 515 xmlSubstituteEntitiesDefault(last_sub_entities_value); |
509 | 516 |
510 return error ? | 517 return error ? |
511 NULL : context.GetTemplateURL(search_terms_data, show_in_default_list); | 518 NULL : context.GetTemplateURL(search_terms_data, show_in_default_list); |
512 } | 519 } |
OLD | NEW |