Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: components/search_engines/template_url_parser.cc

Issue 1238683003: Unpunycode search keywords and short names. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Rebased to origin/master. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/template_url.h" 16 #include "components/search_engines/template_url.h"
17 #include "libxml/parser.h" 17 #include "libxml/parser.h"
18 #include "libxml/xmlwriter.h" 18 #include "libxml/xmlwriter.h"
19 #include "net/base/net_util.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
26 // to that of char, the following names are all in terms of char. This avoids 27 // to that of char, the following names are all in terms of char. This avoids
27 // having to convert to wide, then do comparisons. 28 // having to convert to wide, then do comparisons.
28 29
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 245
245 // static 246 // static
246 void TemplateURLParsingContext::EndElementImpl(void* ctx, const xmlChar* name) { 247 void TemplateURLParsingContext::EndElementImpl(void* ctx, const xmlChar* name) {
247 TemplateURLParsingContext* context = 248 TemplateURLParsingContext* context =
248 reinterpret_cast<TemplateURLParsingContext*>(ctx); 249 reinterpret_cast<TemplateURLParsingContext*>(ctx);
249 switch (context->GetKnownType()) { 250 switch (context->GetKnownType()) {
250 case TemplateURLParsingContext::URL: 251 case TemplateURLParsingContext::URL:
251 context->ProcessURLParams(); 252 context->ProcessURLParams();
252 break; 253 break;
253 case TemplateURLParsingContext::SHORT_NAME: 254 case TemplateURLParsingContext::SHORT_NAME:
254 context->data_.SetShortName(context->string_); 255 // If someone gives us ShortName in punycode, decode it.
256 context->data_.SetShortName(
257 base::IsStringASCII(context->string_)
Peter Kasting 2015/07/14 18:05:33 Why do an ASCII check here? Why not just uncondit
alshabalin 2015/07/15 14:18:01 IDNToUnicode requires ASCII because it calls ASCII
Peter Kasting 2015/07/15 21:19:12 At the least you need a comment in all these place
258 ? net::IDNToUnicode(base::UTF16ToASCII(context->string_), "")
259 : context->string_);
255 break; 260 break;
256 case TemplateURLParsingContext::IMAGE: { 261 case TemplateURLParsingContext::IMAGE: {
257 GURL image_url(base::UTF16ToUTF8(context->string_)); 262 GURL image_url(base::UTF16ToUTF8(context->string_));
258 if (image_url.SchemeIs(url::kDataScheme)) { 263 if (image_url.SchemeIs(url::kDataScheme)) {
259 // TODO (jcampan): bug 1169256: when dealing with data URL, we need to 264 // 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 265 // decode the data URL in the renderer. For now, we'll just point to the
261 // favicon from the URL. 266 // favicon from the URL.
262 context->derive_image_from_url_ = true; 267 context->derive_image_from_url_ = true;
263 } else if (context->image_is_valid_for_favicon_ && image_url.is_valid() && 268 } else if (context->image_is_valid_for_favicon_ && image_url.is_valid() &&
264 (image_url.SchemeIs(url::kHttpScheme) || 269 (image_url.SchemeIs(url::kHttpScheme) ||
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 sax_handler.startElement = &TemplateURLParsingContext::StartElementImpl; 508 sax_handler.startElement = &TemplateURLParsingContext::StartElementImpl;
504 sax_handler.endElement = &TemplateURLParsingContext::EndElementImpl; 509 sax_handler.endElement = &TemplateURLParsingContext::EndElementImpl;
505 sax_handler.characters = &TemplateURLParsingContext::CharactersImpl; 510 sax_handler.characters = &TemplateURLParsingContext::CharactersImpl;
506 int error = xmlSAXUserParseMemory(&sax_handler, &context, data, 511 int error = xmlSAXUserParseMemory(&sax_handler, &context, data,
507 static_cast<int>(length)); 512 static_cast<int>(length));
508 xmlSubstituteEntitiesDefault(last_sub_entities_value); 513 xmlSubstituteEntitiesDefault(last_sub_entities_value);
509 514
510 return error ? 515 return error ?
511 NULL : context.GetTemplateURL(search_terms_data, show_in_default_list); 516 NULL : context.GetTemplateURL(search_terms_data, show_in_default_list);
512 } 517 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698