| OLD | NEW |
| 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 Loading... |
| 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 // We should only get here with an empty omnibox for automatic suggestions |
| 171 // sure the type of destination is what the user would expect given the | 171 // on focus on the NTP; in these cases hitting enter should do nothing, so |
| 172 // input. | 172 // there should be no default match. Otherwise, we're doing automatic |
| 173 if (default_match_->destination_url.is_valid()) { | 173 // suggestions for the currently visible URL (and hitting enter should |
| 174 // reload it), or the user is typing; in either of these cases, there should |
| 175 // be a default match. |
| 176 DCHECK_NE(input.text().empty(), default_match_->allowed_to_be_default_match) |
| 177 << debug_info; |
| 178 |
| 179 // For navigable default matches, make sure the destination type is what the |
| 180 // user would expect given the input. |
| 181 if (default_match_->allowed_to_be_default_match && |
| 182 default_match_->destination_url.is_valid()) { |
| 174 if (AutocompleteMatch::IsSearchType(default_match_->type)) { | 183 if (AutocompleteMatch::IsSearchType(default_match_->type)) { |
| 175 // We shouldn't get query matches for URL inputs. | 184 // We shouldn't get query matches for URL inputs. |
| 176 DCHECK_NE(metrics::OmniboxInputType::URL, input.type()) << debug_info; | 185 DCHECK_NE(metrics::OmniboxInputType::URL, input.type()) << debug_info; |
| 177 } else { | 186 } else { |
| 178 // If the user explicitly typed a scheme, the default match should | 187 // If the user explicitly typed a scheme, the default match should |
| 179 // have the same scheme. | 188 // have the same scheme. |
| 180 if ((input.type() == metrics::OmniboxInputType::URL) && | 189 if ((input.type() == metrics::OmniboxInputType::URL) && |
| 181 input.parts().scheme.is_nonempty()) { | 190 input.parts().scheme.is_nonempty()) { |
| 182 const std::string& in_scheme = base::UTF16ToUTF8(input.scheme()); | 191 const std::string& in_scheme = base::UTF16ToUTF8(input.scheme()); |
| 183 const std::string& dest_scheme = | 192 const std::string& dest_scheme = |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 i != old_matches.rend() && delta > 0; ++i) { | 388 i != old_matches.rend() && delta > 0; ++i) { |
| 380 if (!HasMatchByDestination(*i, new_matches)) { | 389 if (!HasMatchByDestination(*i, new_matches)) { |
| 381 AutocompleteMatch match = *i; | 390 AutocompleteMatch match = *i; |
| 382 match.relevance = std::min(max_relevance, match.relevance); | 391 match.relevance = std::min(max_relevance, match.relevance); |
| 383 match.from_previous = true; | 392 match.from_previous = true; |
| 384 matches_.push_back(match); | 393 matches_.push_back(match); |
| 385 delta--; | 394 delta--; |
| 386 } | 395 } |
| 387 } | 396 } |
| 388 } | 397 } |
| OLD | NEW |