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

Side by Side Diff: components/omnibox/autocomplete_result.cc

Issue 1098843004: Omnibox - Do Not Allow HTTP/HTTPS Equivalence if User Explicitly Entered A Scheme (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final? API changes Created 5 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
OLDNEW
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/omnibox/autocomplete_result.h" 5 #include "components/omnibox/autocomplete_result.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 // It's probably safe to do this in the initializer list, but there's little 114 // It's probably safe to do this in the initializer list, but there's little
115 // penalty to doing it here and it ensures our object is fully constructed 115 // penalty to doing it here and it ensures our object is fully constructed
116 // before calling member functions. 116 // before calling member functions.
117 default_match_ = end(); 117 default_match_ = end();
118 } 118 }
119 119
120 AutocompleteResult::~AutocompleteResult() {} 120 AutocompleteResult::~AutocompleteResult() {}
121 121
122 void AutocompleteResult::CopyOldMatches( 122 void AutocompleteResult::CopyOldMatches(
123 const AutocompleteInput& input, 123 const AutocompleteInput& input,
124 const std::string& languages,
124 const AutocompleteResult& old_matches, 125 const AutocompleteResult& old_matches,
125 TemplateURLService* template_url_service) { 126 TemplateURLService* template_url_service) {
126 if (old_matches.empty()) 127 if (old_matches.empty())
127 return; 128 return;
128 129
129 if (empty()) { 130 if (empty()) {
130 // If we've got no matches we can copy everything from the last result. 131 // If we've got no matches we can copy everything from the last result.
131 CopyFrom(old_matches); 132 CopyFrom(old_matches);
132 for (ACMatches::iterator i(begin()); i != end(); ++i) 133 for (ACMatches::iterator i(begin()); i != end(); ++i)
133 i->from_previous = true; 134 i->from_previous = true;
(...skipping 17 matching lines...) Expand all
151 // anything permanently. 152 // anything permanently.
152 ProviderToMatches matches_per_provider, old_matches_per_provider; 153 ProviderToMatches matches_per_provider, old_matches_per_provider;
153 BuildProviderToMatches(&matches_per_provider); 154 BuildProviderToMatches(&matches_per_provider);
154 old_matches.BuildProviderToMatches(&old_matches_per_provider); 155 old_matches.BuildProviderToMatches(&old_matches_per_provider);
155 for (ProviderToMatches::const_iterator i(old_matches_per_provider.begin()); 156 for (ProviderToMatches::const_iterator i(old_matches_per_provider.begin());
156 i != old_matches_per_provider.end(); ++i) { 157 i != old_matches_per_provider.end(); ++i) {
157 MergeMatchesByProvider(input.current_page_classification(), 158 MergeMatchesByProvider(input.current_page_classification(),
158 i->second, matches_per_provider[i->first]); 159 i->second, matches_per_provider[i->first]);
159 } 160 }
160 161
161 SortAndCull(input, template_url_service); 162 SortAndCull(input, languages, template_url_service);
162 } 163 }
163 164
164 void AutocompleteResult::AppendMatches(const AutocompleteInput& input, 165 void AutocompleteResult::AppendMatches(const AutocompleteInput& input,
165 const ACMatches& matches) { 166 const ACMatches& matches) {
166 for (const auto& i : matches) { 167 for (const auto& i : matches) {
167 #ifndef NDEBUG 168 #ifndef NDEBUG
168 DCHECK_EQ(AutocompleteMatch::SanitizeString(i.contents), i.contents); 169 DCHECK_EQ(AutocompleteMatch::SanitizeString(i.contents), i.contents);
169 DCHECK_EQ(AutocompleteMatch::SanitizeString(i.description), 170 DCHECK_EQ(AutocompleteMatch::SanitizeString(i.description),
170 i.description); 171 i.description);
171 #endif 172 #endif
172 matches_.push_back(i); 173 matches_.push_back(i);
173 matches_.back().PossiblySwapContentsAndDescriptionForURLSuggestion(input); 174 matches_.back().PossiblySwapContentsAndDescriptionForURLSuggestion(input);
174 } 175 }
175 default_match_ = end(); 176 default_match_ = end();
176 alternate_nav_url_ = GURL(); 177 alternate_nav_url_ = GURL();
177 } 178 }
178 179
179 void AutocompleteResult::SortAndCull( 180 void AutocompleteResult::SortAndCull(
180 const AutocompleteInput& input, 181 const AutocompleteInput& input,
182 const std::string& languages,
181 TemplateURLService* template_url_service) { 183 TemplateURLService* template_url_service) {
182 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) 184 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) {
Peter Kasting 2015/06/30 06:50:30 Nit: No {}
Mark P 2015/06/30 17:29:21 Done.
183 i->ComputeStrippedDestinationURL(template_url_service); 185 i->ComputeStrippedDestinationURL(input, languages, template_url_service);
186 }
184 187
185 DedupMatchesByDestination(input.current_page_classification(), true, 188 DedupMatchesByDestination(input.current_page_classification(), true,
186 &matches_); 189 &matches_);
187 190
188 // Sort and trim to the most relevant kMaxMatches matches. 191 // Sort and trim to the most relevant kMaxMatches matches.
189 size_t max_num_matches = std::min(kMaxMatches, matches_.size()); 192 size_t max_num_matches = std::min(kMaxMatches, matches_.size());
190 CompareWithDemoteByType comparing_object(input.current_page_classification()); 193 CompareWithDemoteByType comparing_object(input.current_page_classification());
191 std::sort(matches_.begin(), matches_.end(), comparing_object); 194 std::sort(matches_.begin(), matches_.end(), comparing_object);
192 if (!matches_.empty() && !matches_.begin()->allowed_to_be_default_match) { 195 if (!matches_.empty() && !matches_.begin()->allowed_to_be_default_match) {
193 // Top match is not allowed to be the default match. Find the most 196 // Top match is not allowed to be the default match. Find the most
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 i != old_matches.rend() && delta > 0; ++i) { 440 i != old_matches.rend() && delta > 0; ++i) {
438 if (!HasMatchByDestination(*i, new_matches)) { 441 if (!HasMatchByDestination(*i, new_matches)) {
439 AutocompleteMatch match = *i; 442 AutocompleteMatch match = *i;
440 match.relevance = std::min(max_relevance, match.relevance); 443 match.relevance = std::min(max_relevance, match.relevance);
441 match.from_previous = true; 444 match.from_previous = true;
442 matches_.push_back(match); 445 matches_.push_back(match);
443 delta--; 446 delta--;
444 } 447 }
445 } 448 }
446 } 449 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698