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

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

Issue 9965143: Revert 130431 - Move the URL string from TemplateURLRef onto the owning TemplateURL. This will mak… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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 | Annotate | Revision Log
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
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 std::string* query) { 87 std::string* query) {
88 if (!query->empty()) 88 if (!query->empty())
89 query->append("&"); 89 query->append("&");
90 if (!key.empty()) { 90 if (!key.empty()) {
91 query->append(key); 91 query->append(key);
92 query->append("="); 92 query->append("=");
93 } 93 }
94 query->append(value); 94 query->append(value);
95 } 95 }
96 96
97 // Returns true if |url| is empty or is a valid URL with a scheme of HTTP[S]. 97 // Returns true if the ref is null, or the url wrapped by ref is
98 bool IsHTTPRef(const std::string& url) { 98 // valid with a spec of http/https.
99 if (url.empty()) 99 bool IsHTTPRef(const TemplateURLRef* ref) {
100 if (ref == NULL)
100 return true; 101 return true;
101 GURL gurl(url); 102 GURL url(ref->url());
102 return (gurl.is_valid() && (gurl.SchemeIs(chrome::kHttpScheme) || 103 return (url.is_valid() && (url.SchemeIs(chrome::kHttpScheme) ||
103 gurl.SchemeIs(chrome::kHttpsScheme))); 104 url.SchemeIs(chrome::kHttpsScheme)));
104 } 105 }
105 106
106 } // namespace 107 } // namespace
107 108
108 109
109 // TemplateURLParsingContext -------------------------------------------------- 110 // TemplateURLParsingContext --------------------------------------------------
110 111
111 // 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.
112 // 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
113 // while parsing. 114 // while parsing.
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 } 292 }
292 293
293 TemplateURL* TemplateURLParsingContext::GetTemplateURL(Profile* profile) { 294 TemplateURL* TemplateURLParsingContext::GetTemplateURL(Profile* profile) {
294 // Basic legality checks. 295 // Basic legality checks.
295 if (url_->short_name_.empty() || !IsHTTPRef(url_->url()) || 296 if (url_->short_name_.empty() || !IsHTTPRef(url_->url()) ||
296 !IsHTTPRef(url_->suggestions_url())) 297 !IsHTTPRef(url_->suggestions_url()))
297 return NULL; 298 return NULL;
298 299
299 // If the image was a data URL, use the favicon from the search URL instead. 300 // If the image was a data URL, use the favicon from the search URL instead.
300 // (see TODO inEndElementImpl()). 301 // (see TODO inEndElementImpl()).
301 GURL url(url_->url()); 302 GURL url(url_->url()->url());
302 if (derive_image_from_url_ && url_->favicon_url().is_empty()) 303 if (derive_image_from_url_ && url_->favicon_url().is_empty())
303 url_->set_favicon_url(TemplateURL::GenerateFaviconURL(url)); 304 url_->set_favicon_url(TemplateURL::GenerateFaviconURL(url));
304 305
305 // TODO(jcampan): http://b/issue?id=1196285 we do not support search engines 306 // TODO(jcampan): http://b/issue?id=1196285 we do not support search engines
306 // that use POST yet. 307 // that use POST yet.
307 if (method_ == TemplateURLParsingContext::POST) 308 if (method_ == TemplateURLParsingContext::POST)
308 return NULL; 309 return NULL;
309 if (suggestion_method_ == TemplateURLParsingContext::POST) 310 if (suggestion_method_ == TemplateURLParsingContext::POST)
310 url_->SetSuggestionsURL(std::string()); 311 url_->SetSuggestionsURL(std::string());
311 312
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 407
407 if (!key.empty() && 408 if (!key.empty() &&
408 (!parameter_filter_ || parameter_filter_->KeepParameter(key, value))) 409 (!parameter_filter_ || parameter_filter_->KeepParameter(key, value)))
409 extra_params_.push_back(Param(key, value)); 410 extra_params_.push_back(Param(key, value));
410 } 411 }
411 412
412 void TemplateURLParsingContext::ProcessURLParams() { 413 void TemplateURLParsingContext::ProcessURLParams() {
413 if (!parameter_filter_ && extra_params_.empty()) 414 if (!parameter_filter_ && extra_params_.empty())
414 return; 415 return;
415 416
416 GURL url(is_suggest_url_ ? url_->suggestions_url() : url_->url()); 417 const TemplateURLRef* t_url_ref =
417 if (url.is_empty()) 418 is_suggest_url_ ? url_->suggestions_url() : url_->url();
419 if (!t_url_ref)
418 return; 420 return;
419 421 GURL url(t_url_ref->url());
420 // If there is a parameter filter, parse the existing URL and remove any 422 // If there is a parameter filter, parse the existing URL and remove any
421 // unwanted parameter. 423 // unwanted parameter.
422 std::string new_query; 424 std::string new_query;
423 bool modified = false; 425 bool modified = false;
424 if (parameter_filter_) { 426 if (parameter_filter_) {
425 url_parse::Component query = url.parsed_for_possibly_invalid_spec().query; 427 url_parse::Component query = url.parsed_for_possibly_invalid_spec().query;
426 url_parse::Component key, value; 428 url_parse::Component key, value;
427 const char* url_spec = url.spec().c_str(); 429 const char* url_spec = url.spec().c_str();
428 while (url_parse::ExtractQueryKeyValue(url_spec, &query, &key, &value)) { 430 while (url_parse::ExtractQueryKeyValue(url_spec, &query, &key, &value)) {
429 std::string key_str(url_spec, key.begin, key.len); 431 std::string key_str(url_spec, key.begin, key.len);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 xmlSAXHandler sax_handler; 486 xmlSAXHandler sax_handler;
485 memset(&sax_handler, 0, sizeof(sax_handler)); 487 memset(&sax_handler, 0, sizeof(sax_handler));
486 sax_handler.startElement = &TemplateURLParsingContext::StartElementImpl; 488 sax_handler.startElement = &TemplateURLParsingContext::StartElementImpl;
487 sax_handler.endElement = &TemplateURLParsingContext::EndElementImpl; 489 sax_handler.endElement = &TemplateURLParsingContext::EndElementImpl;
488 sax_handler.characters = &TemplateURLParsingContext::CharactersImpl; 490 sax_handler.characters = &TemplateURLParsingContext::CharactersImpl;
489 xmlSAXUserParseMemory(&sax_handler, &context, data, static_cast<int>(length)); 491 xmlSAXUserParseMemory(&sax_handler, &context, data, static_cast<int>(length));
490 xmlSubstituteEntitiesDefault(last_sub_entities_value); 492 xmlSubstituteEntitiesDefault(last_sub_entities_value);
491 493
492 return context.GetTemplateURL(profile); 494 return context.GetTemplateURL(profile);
493 } 495 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698