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

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

Issue 2266083002: Avoid DCHECK failure for chrome:// URLs in autocomplete suggestions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix OmniboxViewViewsTest.CloseOmniboxPopupOnTextDrag Created 4 years, 3 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/browser/autocomplete_result.h" 5 #include "components/omnibox/browser/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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 if (default_match_ != matches_.end()) { 159 if (default_match_ != matches_.end()) {
160 const base::string16 debug_info = 160 const base::string16 debug_info =
161 base::ASCIIToUTF16("fill_into_edit=") + 161 base::ASCIIToUTF16("fill_into_edit=") +
162 default_match_->fill_into_edit + 162 default_match_->fill_into_edit +
163 base::ASCIIToUTF16(", provider=") + 163 base::ASCIIToUTF16(", provider=") +
164 ((default_match_->provider != NULL) 164 ((default_match_->provider != NULL)
165 ? base::ASCIIToUTF16(default_match_->provider->GetName()) 165 ? base::ASCIIToUTF16(default_match_->provider->GetName())
166 : base::string16()) + 166 : base::string16()) +
167 base::ASCIIToUTF16(", input=") + 167 base::ASCIIToUTF16(", input=") +
168 input.text(); 168 input.text();
169 DCHECK(default_match_->allowed_to_be_default_match) << debug_info; 169
170 // If the default match is valid (i.e., not a prompt/placeholder), make 170 // Ensure there is a default match if (and only if) the omnibox is not
171 // sure the type of destination is what the user would expect given the 171 // empty. Typically, the omnibox will never be empty because it is filled
172 // input. 172 // with the current page URL when the omnibox is focused. The zero-suggest
173 if (default_match_->destination_url.is_valid()) { 173 // default match, if any, should navigate to this URL. However, on some
174 if (AutocompleteMatch::IsSearchType(default_match_->type)) { 174 // WebUI pages (eg: chrome://newtab) the URL is not auto-filled. In this
175 // We shouldn't get query matches for URL inputs. 175 // case, there should be no default match.
176 DCHECK_NE(metrics::OmniboxInputType::URL, input.type()) << debug_info; 176 if (input.text().empty()) {
Peter Kasting 2016/09/01 22:06:35 Nit: Less nesting and code duplication. (I rewrot
mattreynolds 2016/09/02 00:29:08 Done.
177 } else { 177 DCHECK(!default_match_->allowed_to_be_default_match) << debug_info;
178 // If the user explicitly typed a scheme, the default match should 178 } else {
179 // have the same scheme. 179 DCHECK(default_match_->allowed_to_be_default_match) << debug_info;
180 if ((input.type() == metrics::OmniboxInputType::URL) && 180 // If the default match is valid (i.e., not a prompt/placeholder), make
181 input.parts().scheme.is_nonempty()) { 181 // sure the type of destination is what the user would expect given the
182 const std::string& in_scheme = base::UTF16ToUTF8(input.scheme()); 182 // input.
183 const std::string& dest_scheme = 183 if (default_match_->destination_url.is_valid()) {
184 default_match_->destination_url.scheme(); 184 if (AutocompleteMatch::IsSearchType(default_match_->type)) {
185 DCHECK(url_formatter::IsEquivalentScheme(in_scheme, dest_scheme)) 185 // We shouldn't get query matches for URL inputs.
186 << debug_info; 186 DCHECK_NE(metrics::OmniboxInputType::URL, input.type()) << debug_info;
187 } else {
188 // If the user explicitly typed a scheme, the default match should
189 // have the same scheme.
190 if ((input.type() == metrics::OmniboxInputType::URL) &&
191 input.parts().scheme.is_nonempty()) {
192 const std::string& in_scheme = base::UTF16ToUTF8(input.scheme());
193 const std::string& dest_scheme =
194 default_match_->destination_url.scheme();
195 DCHECK(url_formatter::IsEquivalentScheme(in_scheme, dest_scheme))
196 << debug_info;
197 }
187 } 198 }
188 } 199 }
189 } 200 }
190 } 201 }
191 202
192 // Set the alternate nav URL. 203 // Set the alternate nav URL.
193 alternate_nav_url_ = (default_match_ == matches_.end()) ? 204 alternate_nav_url_ = (default_match_ == matches_.end()) ?
194 GURL() : ComputeAlternateNavUrl(input, *default_match_); 205 GURL() : ComputeAlternateNavUrl(input, *default_match_);
195 } 206 }
196 207
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 i != old_matches.rend() && delta > 0; ++i) { 390 i != old_matches.rend() && delta > 0; ++i) {
380 if (!HasMatchByDestination(*i, new_matches)) { 391 if (!HasMatchByDestination(*i, new_matches)) {
381 AutocompleteMatch match = *i; 392 AutocompleteMatch match = *i;
382 match.relevance = std::min(max_relevance, match.relevance); 393 match.relevance = std::min(max_relevance, match.relevance);
383 match.from_previous = true; 394 match.from_previous = true;
384 matches_.push_back(match); 395 matches_.push_back(match);
385 delta--; 396 delta--;
386 } 397 }
387 } 398 }
388 } 399 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698