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 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 query->append("="); | 93 query->append("="); |
94 } | 94 } |
95 query->append(value); | 95 query->append(value); |
96 } | 96 } |
97 | 97 |
98 // Returns true if |url| is empty or is a valid URL with a scheme of HTTP[S]. | 98 // Returns true if |url| is empty or is a valid URL with a scheme of HTTP[S]. |
99 bool IsHTTPRef(const std::string& url) { | 99 bool IsHTTPRef(const std::string& url) { |
100 if (url.empty()) | 100 if (url.empty()) |
101 return true; | 101 return true; |
102 GURL gurl(url); | 102 GURL gurl(url); |
103 return gurl.is_valid() && (gurl.SchemeIs(chrome::kHttpScheme) || | 103 return gurl.is_valid() && (gurl.SchemeIs(content::kHttpScheme) || |
104 gurl.SchemeIs(content::kHttpsScheme)); | 104 gurl.SchemeIs(content::kHttpsScheme)); |
105 } | 105 } |
106 | 106 |
107 } // namespace | 107 } // namespace |
108 | 108 |
109 | 109 |
110 // TemplateURLParsingContext -------------------------------------------------- | 110 // TemplateURLParsingContext -------------------------------------------------- |
111 | 111 |
112 // To minimize memory overhead while parsing, a SAX style parser is used. | 112 // To minimize memory overhead while parsing, a SAX style parser is used. |
113 // TemplateURLParsingContext is used to maintain the state we're in the document | 113 // TemplateURLParsingContext is used to maintain the state we're in the document |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 context->data_.short_name = context->string_; | 251 context->data_.short_name = context->string_; |
252 break; | 252 break; |
253 case TemplateURLParsingContext::IMAGE: { | 253 case TemplateURLParsingContext::IMAGE: { |
254 GURL image_url(UTF16ToUTF8(context->string_)); | 254 GURL image_url(UTF16ToUTF8(context->string_)); |
255 if (image_url.SchemeIs(chrome::kDataScheme)) { | 255 if (image_url.SchemeIs(chrome::kDataScheme)) { |
256 // TODO (jcampan): bug 1169256: when dealing with data URL, we need to | 256 // TODO (jcampan): bug 1169256: when dealing with data URL, we need to |
257 // decode the data URL in the renderer. For now, we'll just point to the | 257 // decode the data URL in the renderer. For now, we'll just point to the |
258 // favicon from the URL. | 258 // favicon from the URL. |
259 context->derive_image_from_url_ = true; | 259 context->derive_image_from_url_ = true; |
260 } else if (context->image_is_valid_for_favicon_ && image_url.is_valid() && | 260 } else if (context->image_is_valid_for_favicon_ && image_url.is_valid() && |
261 (image_url.SchemeIs(chrome::kHttpScheme) || | 261 (image_url.SchemeIs(content::kHttpScheme) || |
262 image_url.SchemeIs(content::kHttpsScheme))) { | 262 image_url.SchemeIs(content::kHttpsScheme))) { |
263 context->data_.favicon_url = image_url; | 263 context->data_.favicon_url = image_url; |
264 } | 264 } |
265 context->image_is_valid_for_favicon_ = false; | 265 context->image_is_valid_for_favicon_ = false; |
266 break; | 266 break; |
267 } | 267 } |
268 case TemplateURLParsingContext::INPUT_ENCODING: { | 268 case TemplateURLParsingContext::INPUT_ENCODING: { |
269 std::string input_encoding = UTF16ToASCII(context->string_); | 269 std::string input_encoding = UTF16ToASCII(context->string_); |
270 if (IsValidEncodingString(input_encoding)) | 270 if (IsValidEncodingString(input_encoding)) |
271 context->data_.input_encodings.push_back(input_encoding); | 271 context->data_.input_encodings.push_back(input_encoding); |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 memset(&sax_handler, 0, sizeof(sax_handler)); | 493 memset(&sax_handler, 0, sizeof(sax_handler)); |
494 sax_handler.startElement = &TemplateURLParsingContext::StartElementImpl; | 494 sax_handler.startElement = &TemplateURLParsingContext::StartElementImpl; |
495 sax_handler.endElement = &TemplateURLParsingContext::EndElementImpl; | 495 sax_handler.endElement = &TemplateURLParsingContext::EndElementImpl; |
496 sax_handler.characters = &TemplateURLParsingContext::CharactersImpl; | 496 sax_handler.characters = &TemplateURLParsingContext::CharactersImpl; |
497 int error = xmlSAXUserParseMemory(&sax_handler, &context, data, | 497 int error = xmlSAXUserParseMemory(&sax_handler, &context, data, |
498 static_cast<int>(length)); | 498 static_cast<int>(length)); |
499 xmlSubstituteEntitiesDefault(last_sub_entities_value); | 499 xmlSubstituteEntitiesDefault(last_sub_entities_value); |
500 | 500 |
501 return error ? NULL : context.GetTemplateURL(profile, show_in_default_list); | 501 return error ? NULL : context.GetTemplateURL(profile, show_in_default_list); |
502 } | 502 } |
OLD | NEW |