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 <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 | 244 |
245 // static | 245 // static |
246 void TemplateURLParsingContext::EndElementImpl(void* ctx, const xmlChar* name) { | 246 void TemplateURLParsingContext::EndElementImpl(void* ctx, const xmlChar* name) { |
247 TemplateURLParsingContext* context = | 247 TemplateURLParsingContext* context = |
248 reinterpret_cast<TemplateURLParsingContext*>(ctx); | 248 reinterpret_cast<TemplateURLParsingContext*>(ctx); |
249 switch (context->GetKnownType()) { | 249 switch (context->GetKnownType()) { |
250 case TemplateURLParsingContext::URL: | 250 case TemplateURLParsingContext::URL: |
251 context->ProcessURLParams(); | 251 context->ProcessURLParams(); |
252 break; | 252 break; |
253 case TemplateURLParsingContext::SHORT_NAME: | 253 case TemplateURLParsingContext::SHORT_NAME: |
254 context->data_.short_name = context->string_; | 254 context->data_.SetShortName(context->string_); |
255 break; | 255 break; |
256 case TemplateURLParsingContext::IMAGE: { | 256 case TemplateURLParsingContext::IMAGE: { |
257 GURL image_url(base::UTF16ToUTF8(context->string_)); | 257 GURL image_url(base::UTF16ToUTF8(context->string_)); |
258 if (image_url.SchemeIs(url::kDataScheme)) { | 258 if (image_url.SchemeIs(url::kDataScheme)) { |
259 // TODO (jcampan): bug 1169256: when dealing with data URL, we need to | 259 // 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 | 260 // decode the data URL in the renderer. For now, we'll just point to the |
261 // favicon from the URL. | 261 // favicon from the URL. |
262 context->derive_image_from_url_ = true; | 262 context->derive_image_from_url_ = true; |
263 } else if (context->image_is_valid_for_favicon_ && image_url.is_valid() && | 263 } else if (context->image_is_valid_for_favicon_ && image_url.is_valid() && |
264 (image_url.SchemeIs(url::kHttpScheme) || | 264 (image_url.SchemeIs(url::kHttpScheme) || |
(...skipping 27 matching lines...) Expand all Loading... |
292 int len) { | 292 int len) { |
293 reinterpret_cast<TemplateURLParsingContext*>(ctx)->string_ += | 293 reinterpret_cast<TemplateURLParsingContext*>(ctx)->string_ += |
294 base::UTF8ToUTF16( | 294 base::UTF8ToUTF16( |
295 base::StringPiece(reinterpret_cast<const char*>(ch), len)); | 295 base::StringPiece(reinterpret_cast<const char*>(ch), len)); |
296 } | 296 } |
297 | 297 |
298 TemplateURL* TemplateURLParsingContext::GetTemplateURL( | 298 TemplateURL* TemplateURLParsingContext::GetTemplateURL( |
299 const SearchTermsData& search_terms_data, | 299 const SearchTermsData& search_terms_data, |
300 bool show_in_default_list) { | 300 bool show_in_default_list) { |
301 // TODO(jcampan): Support engines that use POST; see http://crbug.com/18107 | 301 // TODO(jcampan): Support engines that use POST; see http://crbug.com/18107 |
302 if (method_ == TemplateURLParsingContext::POST || data_.short_name.empty() || | 302 if (method_ == TemplateURLParsingContext::POST || |
303 !IsHTTPRef(data_.url()) || !IsHTTPRef(data_.suggestions_url)) | 303 data_.short_name().empty() || !IsHTTPRef(data_.url()) || |
| 304 !IsHTTPRef(data_.suggestions_url)) |
304 return NULL; | 305 return NULL; |
305 if (suggestion_method_ == TemplateURLParsingContext::POST) | 306 if (suggestion_method_ == TemplateURLParsingContext::POST) |
306 data_.suggestions_url.clear(); | 307 data_.suggestions_url.clear(); |
307 | 308 |
308 // If the image was a data URL, use the favicon from the search URL instead. | 309 // If the image was a data URL, use the favicon from the search URL instead. |
309 // (see the TODO in EndElementImpl()). | 310 // (see the TODO in EndElementImpl()). |
310 GURL search_url(data_.url()); | 311 GURL search_url(data_.url()); |
311 if (derive_image_from_url_ && data_.favicon_url.is_empty()) | 312 if (derive_image_from_url_ && data_.favicon_url.is_empty()) |
312 data_.favicon_url = TemplateURL::GenerateFaviconURL(search_url); | 313 data_.favicon_url = TemplateURL::GenerateFaviconURL(search_url); |
313 | 314 |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 sax_handler.startElement = &TemplateURLParsingContext::StartElementImpl; | 503 sax_handler.startElement = &TemplateURLParsingContext::StartElementImpl; |
503 sax_handler.endElement = &TemplateURLParsingContext::EndElementImpl; | 504 sax_handler.endElement = &TemplateURLParsingContext::EndElementImpl; |
504 sax_handler.characters = &TemplateURLParsingContext::CharactersImpl; | 505 sax_handler.characters = &TemplateURLParsingContext::CharactersImpl; |
505 int error = xmlSAXUserParseMemory(&sax_handler, &context, data, | 506 int error = xmlSAXUserParseMemory(&sax_handler, &context, data, |
506 static_cast<int>(length)); | 507 static_cast<int>(length)); |
507 xmlSubstituteEntitiesDefault(last_sub_entities_value); | 508 xmlSubstituteEntitiesDefault(last_sub_entities_value); |
508 | 509 |
509 return error ? | 510 return error ? |
510 NULL : context.GetTemplateURL(search_terms_data, show_in_default_list); | 511 NULL : context.GetTemplateURL(search_terms_data, show_in_default_list); |
511 } | 512 } |
OLD | NEW |