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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: components/omnibox/browser/autocomplete_result.cc
diff --git a/components/omnibox/browser/autocomplete_result.cc b/components/omnibox/browser/autocomplete_result.cc
index 14f084337e980300abdaf7d6df4ba3b249b8374d..b942fffdfc940ca2a56f2c3a7116b51c23373206 100644
--- a/components/omnibox/browser/autocomplete_result.cc
+++ b/components/omnibox/browser/autocomplete_result.cc
@@ -166,24 +166,35 @@ void AutocompleteResult::SortAndCull(
: base::string16()) +
base::ASCIIToUTF16(", input=") +
input.text();
- DCHECK(default_match_->allowed_to_be_default_match) << debug_info;
- // If the default match is valid (i.e., not a prompt/placeholder), make
- // sure the type of destination is what the user would expect given the
- // input.
- if (default_match_->destination_url.is_valid()) {
- if (AutocompleteMatch::IsSearchType(default_match_->type)) {
- // We shouldn't get query matches for URL inputs.
- DCHECK_NE(metrics::OmniboxInputType::URL, input.type()) << debug_info;
- } else {
- // If the user explicitly typed a scheme, the default match should
- // have the same scheme.
- if ((input.type() == metrics::OmniboxInputType::URL) &&
- input.parts().scheme.is_nonempty()) {
- const std::string& in_scheme = base::UTF16ToUTF8(input.scheme());
- const std::string& dest_scheme =
- default_match_->destination_url.scheme();
- DCHECK(url_formatter::IsEquivalentScheme(in_scheme, dest_scheme))
- << debug_info;
+
+ // Ensure there is a default match if (and only if) the omnibox is not
+ // empty. Typically, the omnibox will never be empty because it is filled
+ // with the current page URL when the omnibox is focused. The zero-suggest
+ // default match, if any, should navigate to this URL. However, on some
+ // WebUI pages (eg: chrome://newtab) the URL is not auto-filled. In this
+ // case, there should be no default match.
+ 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.
+ DCHECK(!default_match_->allowed_to_be_default_match) << debug_info;
+ } else {
+ DCHECK(default_match_->allowed_to_be_default_match) << debug_info;
+ // If the default match is valid (i.e., not a prompt/placeholder), make
+ // sure the type of destination is what the user would expect given the
+ // input.
+ if (default_match_->destination_url.is_valid()) {
+ if (AutocompleteMatch::IsSearchType(default_match_->type)) {
+ // We shouldn't get query matches for URL inputs.
+ DCHECK_NE(metrics::OmniboxInputType::URL, input.type()) << debug_info;
+ } else {
+ // If the user explicitly typed a scheme, the default match should
+ // have the same scheme.
+ if ((input.type() == metrics::OmniboxInputType::URL) &&
+ input.parts().scheme.is_nonempty()) {
+ const std::string& in_scheme = base::UTF16ToUTF8(input.scheme());
+ const std::string& dest_scheme =
+ default_match_->destination_url.scheme();
+ DCHECK(url_formatter::IsEquivalentScheme(in_scheme, dest_scheme))
+ << debug_info;
+ }
}
}
}

Powered by Google App Engine
This is Rietveld 408576698