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

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

Issue 7230053: Modify TemplateURLRef to remove unknown URL parameters, but only when it represents a prepopulate... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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.h" 5 #include "chrome/browser/search_engines/template_url.h"
6 6
7 #include "base/i18n/case_conversion.h" 7 #include "base/i18n/case_conversion.h"
8 #include "base/i18n/icu_string_conversions.h" 8 #include "base/i18n/icu_string_conversions.h"
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } 78 }
79 79
80 TemplateURLRef::TemplateURLRef(const std::string& url, 80 TemplateURLRef::TemplateURLRef(const std::string& url,
81 int index_offset, 81 int index_offset,
82 int page_offset) 82 int page_offset)
83 : url_(url), 83 : url_(url),
84 index_offset_(index_offset), 84 index_offset_(index_offset),
85 page_offset_(page_offset), 85 page_offset_(page_offset),
86 parsed_(false), 86 parsed_(false),
87 valid_(false), 87 valid_(false),
88 supports_replacements_(false) { 88 supports_replacements_(false),
89 prepopulated_(false) {
89 } 90 }
90 91
91 void TemplateURLRef::Set(const std::string& url, 92 void TemplateURLRef::Set(const std::string& url,
92 int index_offset, 93 int index_offset,
93 int page_offset) { 94 int page_offset) {
94 url_ = url; 95 url_ = url;
95 index_offset_ = index_offset; 96 index_offset_ = index_offset;
96 page_offset_ = page_offset; 97 page_offset_ = page_offset;
97 InvalidateCachedValues(); 98 InvalidateCachedValues();
98 } 99 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 } else if (parameter == kGoogleBaseSuggestURLParameter) { 144 } else if (parameter == kGoogleBaseSuggestURLParameter) {
144 replacements->push_back(Replacement(GOOGLE_BASE_SUGGEST_URL, start)); 145 replacements->push_back(Replacement(GOOGLE_BASE_SUGGEST_URL, start));
145 } else if (parameter == kGoogleOriginalQueryForSuggestionParameter) { 146 } else if (parameter == kGoogleOriginalQueryForSuggestionParameter) {
146 replacements->push_back(Replacement(GOOGLE_ORIGINAL_QUERY_FOR_SUGGESTION, 147 replacements->push_back(Replacement(GOOGLE_ORIGINAL_QUERY_FOR_SUGGESTION,
147 start)); 148 start));
148 } else if (parameter == kGoogleRLZParameter) { 149 } else if (parameter == kGoogleRLZParameter) {
149 replacements->push_back(Replacement(GOOGLE_RLZ, start)); 150 replacements->push_back(Replacement(GOOGLE_RLZ, start));
150 } else if (parameter == kGoogleUnescapedSearchTermsParameter) { 151 } else if (parameter == kGoogleUnescapedSearchTermsParameter) {
151 replacements->push_back(Replacement(GOOGLE_UNESCAPED_SEARCH_TERMS, start)); 152 replacements->push_back(Replacement(GOOGLE_UNESCAPED_SEARCH_TERMS, start));
152 } else { 153 } else {
153 // It can be some garbage but can also be a javascript block. Put it back. 154 // If it's a prepopulated URL, we know that it's safe to remove unknown
154 url->insert(start, full_parameter); 155 // parameters. Otherwise it could be some garbage but can also be a
156 // javascript block. Put it back.
157 if (!prepopulated_)
158 url->insert(start, full_parameter);
155 return false; 159 return false;
156 } 160 }
157 return true; 161 return true;
158 } 162 }
159 163
160 std::string TemplateURLRef::ParseURL(const std::string& url, 164 std::string TemplateURLRef::ParseURL(const std::string& url,
161 Replacements* replacements, 165 Replacements* replacements,
162 bool* valid) const { 166 bool* valid) const {
163 *valid = false; 167 *valid = false;
164 std::string parsed_url = url; 168 std::string parsed_url = url;
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 for (std::vector<ImageRef>::const_iterator i = image_refs_.begin(); 682 for (std::vector<ImageRef>::const_iterator i = image_refs_.begin();
679 i != image_refs_.end(); ++i) { 683 i != image_refs_.end(); ++i) {
680 if ((i->type == "image/x-icon" || i->type == "image/vnd.microsoft.icon") 684 if ((i->type == "image/x-icon" || i->type == "image/vnd.microsoft.icon")
681 && i->width == kFaviconSize && i->height == kFaviconSize) { 685 && i->width == kFaviconSize && i->height == kFaviconSize) {
682 return i->url; 686 return i->url;
683 } 687 }
684 } 688 }
685 return GURL(); 689 return GURL();
686 } 690 }
687 691
692 void TemplateURL::SetPrepopulateId(int id) {
693 prepopulate_id_ = id;
694 if (id > 0)
sky 2011/06/28 21:02:26 Convert these to SetTemplateURLRefsPrepopulate(id
695 SetTemplateURLRefsPrepopulated(true);
696 else
697 SetTemplateURLRefsPrepopulated(false);
698 }
699
688 void TemplateURL::InvalidateCachedValues() const { 700 void TemplateURL::InvalidateCachedValues() const {
689 url_.InvalidateCachedValues(); 701 url_.InvalidateCachedValues();
690 suggestions_url_.InvalidateCachedValues(); 702 suggestions_url_.InvalidateCachedValues();
691 if (autogenerate_keyword_) { 703 if (autogenerate_keyword_) {
692 keyword_.clear(); 704 keyword_.clear();
693 keyword_generated_ = false; 705 keyword_generated_ = false;
694 } 706 }
695 } 707 }
696 708
709 void TemplateURL::SetTemplateURLRefsPrepopulated(bool prepopulated) {
710 suggestions_url_.set_prepopulated(prepopulated);
711 url_.set_prepopulated(prepopulated);
712 instant_url_.set_prepopulated(prepopulated);
713 }
714
697 std::string TemplateURL::GetExtensionId() const { 715 std::string TemplateURL::GetExtensionId() const {
698 DCHECK(IsExtensionKeyword()); 716 DCHECK(IsExtensionKeyword());
699 return GURL(url_.url()).host(); 717 return GURL(url_.url()).host();
700 } 718 }
701 719
702 bool TemplateURL::IsExtensionKeyword() const { 720 bool TemplateURL::IsExtensionKeyword() const {
703 return GURL(url_.url()).SchemeIs(chrome::kExtensionScheme); 721 return GURL(url_.url()).SchemeIs(chrome::kExtensionScheme);
704 } 722 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698