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

Side by Side Diff: chrome/browser/search_engines/template_url_parser.cc

Issue 254763005: Move some content url constants to /url. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Initial patches. Created 6 years, 8 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 (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/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 "chrome/browser/search_engines/search_terms_data.h" 16 #include "chrome/browser/search_engines/search_terms_data.h"
17 #include "chrome/browser/search_engines/template_url.h" 17 #include "chrome/browser/search_engines/template_url.h"
18 #include "chrome/browser/search_engines/template_url_service.h" 18 #include "chrome/browser/search_engines/template_url_service.h"
19 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
20 #include "libxml/parser.h" 20 #include "libxml/parser.h"
21 #include "libxml/xmlwriter.h" 21 #include "libxml/xmlwriter.h"
22 #include "net/base/url_constants.h"
22 #include "ui/gfx/favicon_size.h" 23 #include "ui/gfx/favicon_size.h"
23 #include "url/gurl.h" 24 #include "url/gurl.h"
24 25
25 namespace { 26 namespace {
26 27
27 // NOTE: libxml uses the UTF-8 encoding. As 0-127 of UTF-8 corresponds 28 // NOTE: libxml uses the UTF-8 encoding. As 0-127 of UTF-8 corresponds
28 // to that of char, the following names are all in terms of char. This avoids 29 // to that of char, the following names are all in terms of char. This avoids
29 // having to convert to wide, then do comparisons. 30 // having to convert to wide, then do comparisons.
30 31
31 // Defines for element names of the OSD document: 32 // Defines for element names of the OSD document:
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 query->append("="); 88 query->append("=");
88 } 89 }
89 query->append(value); 90 query->append(value);
90 } 91 }
91 92
92 // Returns true if |url| is empty or is a valid URL with a scheme of HTTP[S]. 93 // Returns true if |url| is empty or is a valid URL with a scheme of HTTP[S].
93 bool IsHTTPRef(const std::string& url) { 94 bool IsHTTPRef(const std::string& url) {
94 if (url.empty()) 95 if (url.empty())
95 return true; 96 return true;
96 GURL gurl(url); 97 GURL gurl(url);
97 return gurl.is_valid() && (gurl.SchemeIs(content::kHttpScheme) || 98 return gurl.is_valid() &&
98 gurl.SchemeIs(content::kHttpsScheme)); 99 (gurl.SchemeIs(net::kHttpScheme) || gurl.SchemeIs(net::kHttpsScheme));
99 } 100 }
100 101
101 } // namespace 102 } // namespace
102 103
103 104
104 // TemplateURLParsingContext -------------------------------------------------- 105 // TemplateURLParsingContext --------------------------------------------------
105 106
106 // To minimize memory overhead while parsing, a SAX style parser is used. 107 // To minimize memory overhead while parsing, a SAX style parser is used.
107 // TemplateURLParsingContext is used to maintain the state we're in the document 108 // TemplateURLParsingContext is used to maintain the state we're in the document
108 // while parsing. 109 // while parsing.
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 context->data_.short_name = context->string_; 246 context->data_.short_name = context->string_;
246 break; 247 break;
247 case TemplateURLParsingContext::IMAGE: { 248 case TemplateURLParsingContext::IMAGE: {
248 GURL image_url(base::UTF16ToUTF8(context->string_)); 249 GURL image_url(base::UTF16ToUTF8(context->string_));
249 if (image_url.SchemeIs(content::kDataScheme)) { 250 if (image_url.SchemeIs(content::kDataScheme)) {
250 // TODO (jcampan): bug 1169256: when dealing with data URL, we need to 251 // TODO (jcampan): bug 1169256: when dealing with data URL, we need to
251 // decode the data URL in the renderer. For now, we'll just point to the 252 // decode the data URL in the renderer. For now, we'll just point to the
252 // favicon from the URL. 253 // favicon from the URL.
253 context->derive_image_from_url_ = true; 254 context->derive_image_from_url_ = true;
254 } else if (context->image_is_valid_for_favicon_ && image_url.is_valid() && 255 } else if (context->image_is_valid_for_favicon_ && image_url.is_valid() &&
255 (image_url.SchemeIs(content::kHttpScheme) || 256 (image_url.SchemeIs(net::kHttpScheme) ||
256 image_url.SchemeIs(content::kHttpsScheme))) { 257 image_url.SchemeIs(net::kHttpsScheme))) {
257 context->data_.favicon_url = image_url; 258 context->data_.favicon_url = image_url;
258 } 259 }
259 context->image_is_valid_for_favicon_ = false; 260 context->image_is_valid_for_favicon_ = false;
260 break; 261 break;
261 } 262 }
262 case TemplateURLParsingContext::INPUT_ENCODING: { 263 case TemplateURLParsingContext::INPUT_ENCODING: {
263 std::string input_encoding = base::UTF16ToASCII(context->string_); 264 std::string input_encoding = base::UTF16ToASCII(context->string_);
264 if (IsValidEncodingString(input_encoding)) 265 if (IsValidEncodingString(input_encoding))
265 context->data_.input_encodings.push_back(input_encoding); 266 context->data_.input_encodings.push_back(input_encoding);
266 break; 267 break;
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 memset(&sax_handler, 0, sizeof(sax_handler)); 488 memset(&sax_handler, 0, sizeof(sax_handler));
488 sax_handler.startElement = &TemplateURLParsingContext::StartElementImpl; 489 sax_handler.startElement = &TemplateURLParsingContext::StartElementImpl;
489 sax_handler.endElement = &TemplateURLParsingContext::EndElementImpl; 490 sax_handler.endElement = &TemplateURLParsingContext::EndElementImpl;
490 sax_handler.characters = &TemplateURLParsingContext::CharactersImpl; 491 sax_handler.characters = &TemplateURLParsingContext::CharactersImpl;
491 int error = xmlSAXUserParseMemory(&sax_handler, &context, data, 492 int error = xmlSAXUserParseMemory(&sax_handler, &context, data,
492 static_cast<int>(length)); 493 static_cast<int>(length));
493 xmlSubstituteEntitiesDefault(last_sub_entities_value); 494 xmlSubstituteEntitiesDefault(last_sub_entities_value);
494 495
495 return error ? NULL : context.GetTemplateURL(profile, show_in_default_list); 496 return error ? NULL : context.GetTemplateURL(profile, show_in_default_list);
496 } 497 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698