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

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: fix browsertests compile error (sigh) 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/command_line.h" 10 #include "base/command_line.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 // It's probably safe to do this in the initializer list, but there's little 116 // It's probably safe to do this in the initializer list, but there's little
117 // penalty to doing it here and it ensures our object is fully constructed 117 // penalty to doing it here and it ensures our object is fully constructed
118 // before calling member functions. 118 // before calling member functions.
119 default_match_ = end(); 119 default_match_ = end();
120 } 120 }
121 121
122 AutocompleteResult::~AutocompleteResult() {} 122 AutocompleteResult::~AutocompleteResult() {}
123 123
124 void AutocompleteResult::CopyOldMatches( 124 void AutocompleteResult::CopyOldMatches(
125 const AutocompleteInput& input, 125 const AutocompleteInput& input,
126 const std::string& languages,
126 const AutocompleteResult& old_matches, 127 const AutocompleteResult& old_matches,
127 TemplateURLService* template_url_service) { 128 TemplateURLService* template_url_service) {
128 if (old_matches.empty()) 129 if (old_matches.empty())
129 return; 130 return;
130 131
131 if (empty()) { 132 if (empty()) {
132 // If we've got no matches we can copy everything from the last result. 133 // If we've got no matches we can copy everything from the last result.
133 CopyFrom(old_matches); 134 CopyFrom(old_matches);
134 for (ACMatches::iterator i(begin()); i != end(); ++i) 135 for (ACMatches::iterator i(begin()); i != end(); ++i)
135 i->from_previous = true; 136 i->from_previous = true;
(...skipping 17 matching lines...) Expand all
153 // anything permanently. 154 // anything permanently.
154 ProviderToMatches matches_per_provider, old_matches_per_provider; 155 ProviderToMatches matches_per_provider, old_matches_per_provider;
155 BuildProviderToMatches(&matches_per_provider); 156 BuildProviderToMatches(&matches_per_provider);
156 old_matches.BuildProviderToMatches(&old_matches_per_provider); 157 old_matches.BuildProviderToMatches(&old_matches_per_provider);
157 for (ProviderToMatches::const_iterator i(old_matches_per_provider.begin()); 158 for (ProviderToMatches::const_iterator i(old_matches_per_provider.begin());
158 i != old_matches_per_provider.end(); ++i) { 159 i != old_matches_per_provider.end(); ++i) {
159 MergeMatchesByProvider(input.current_page_classification(), 160 MergeMatchesByProvider(input.current_page_classification(),
160 i->second, matches_per_provider[i->first]); 161 i->second, matches_per_provider[i->first]);
161 } 162 }
162 163
163 SortAndCull(input, template_url_service); 164 SortAndCull(input, languages, template_url_service);
164 } 165 }
165 166
166 void AutocompleteResult::AppendMatches(const AutocompleteInput& input, 167 void AutocompleteResult::AppendMatches(const AutocompleteInput& input,
167 const ACMatches& matches) { 168 const ACMatches& matches) {
168 for (const auto& i : matches) { 169 for (const auto& i : matches) {
169 #ifndef NDEBUG 170 #ifndef NDEBUG
170 DCHECK_EQ(AutocompleteMatch::SanitizeString(i.contents), i.contents); 171 DCHECK_EQ(AutocompleteMatch::SanitizeString(i.contents), i.contents);
171 DCHECK_EQ(AutocompleteMatch::SanitizeString(i.description), 172 DCHECK_EQ(AutocompleteMatch::SanitizeString(i.description),
172 i.description); 173 i.description);
173 #endif 174 #endif
174 matches_.push_back(i); 175 matches_.push_back(i);
175 if (!AutocompleteMatch::IsSearchType(i.type) && !i.description.empty() && 176 if (!AutocompleteMatch::IsSearchType(i.type) && !i.description.empty() &&
176 base::CommandLine::ForCurrentProcess()-> 177 base::CommandLine::ForCurrentProcess()->
177 HasSwitch(switches::kEmphasizeTitlesInOmniboxDropdown) && 178 HasSwitch(switches::kEmphasizeTitlesInOmniboxDropdown) &&
178 ((input.type() == metrics::OmniboxInputType::QUERY) || 179 ((input.type() == metrics::OmniboxInputType::QUERY) ||
179 (input.type() == metrics::OmniboxInputType::FORCED_QUERY)) && 180 (input.type() == metrics::OmniboxInputType::FORCED_QUERY)) &&
180 AutocompleteMatch::HasMatchStyle(i.description_class)) { 181 AutocompleteMatch::HasMatchStyle(i.description_class)) {
181 matches_.back().swap_contents_and_description = true; 182 matches_.back().swap_contents_and_description = true;
182 } 183 }
183 } 184 }
184 default_match_ = end(); 185 default_match_ = end();
185 alternate_nav_url_ = GURL(); 186 alternate_nav_url_ = GURL();
186 } 187 }
187 188
188 void AutocompleteResult::SortAndCull( 189 void AutocompleteResult::SortAndCull(
189 const AutocompleteInput& input, 190 const AutocompleteInput& input,
191 const std::string& languages,
190 TemplateURLService* template_url_service) { 192 TemplateURLService* template_url_service) {
191 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i) 193 for (ACMatches::iterator i(matches_.begin()); i != matches_.end(); ++i)
192 i->ComputeStrippedDestinationURL(template_url_service); 194 i->ComputeStrippedDestinationURL(input, languages, template_url_service);
193 195
194 DedupMatchesByDestination(input.current_page_classification(), true, 196 DedupMatchesByDestination(input.current_page_classification(), true,
195 &matches_); 197 &matches_);
196 198
197 // Sort and trim to the most relevant kMaxMatches matches. 199 // Sort and trim to the most relevant kMaxMatches matches.
198 size_t max_num_matches = std::min(kMaxMatches, matches_.size()); 200 size_t max_num_matches = std::min(kMaxMatches, matches_.size());
199 CompareWithDemoteByType comparing_object(input.current_page_classification()); 201 CompareWithDemoteByType comparing_object(input.current_page_classification());
200 std::sort(matches_.begin(), matches_.end(), comparing_object); 202 std::sort(matches_.begin(), matches_.end(), comparing_object);
201 if (!matches_.empty() && !matches_.begin()->allowed_to_be_default_match) { 203 if (!matches_.empty() && !matches_.begin()->allowed_to_be_default_match) {
202 // Top match is not allowed to be the default match. Find the most 204 // 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
446 i != old_matches.rend() && delta > 0; ++i) { 448 i != old_matches.rend() && delta > 0; ++i) {
447 if (!HasMatchByDestination(*i, new_matches)) { 449 if (!HasMatchByDestination(*i, new_matches)) {
448 AutocompleteMatch match = *i; 450 AutocompleteMatch match = *i;
449 match.relevance = std::min(max_relevance, match.relevance); 451 match.relevance = std::min(max_relevance, match.relevance);
450 match.from_previous = true; 452 match.from_previous = true;
451 matches_.push_back(match); 453 matches_.push_back(match);
452 delta--; 454 delta--;
453 } 455 }
454 } 456 }
455 } 457 }
OLDNEW
« no previous file with comments | « components/omnibox/autocomplete_result.h ('k') | components/omnibox/autocomplete_result_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698