Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/autocomplete/keyword_provider.h" | 5 #include "chrome/browser/autocomplete/keyword_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/string16.h" | 10 #include "base/string16.h" |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 } | 278 } |
| 279 if (keyword_matches.empty()) | 279 if (keyword_matches.empty()) |
| 280 return; | 280 return; |
| 281 std::sort(keyword_matches.begin(), keyword_matches.end(), CompareQuality()); | 281 std::sort(keyword_matches.begin(), keyword_matches.end(), CompareQuality()); |
| 282 | 282 |
| 283 // Limit to one exact or three inexact matches, and mark them up for display | 283 // Limit to one exact or three inexact matches, and mark them up for display |
| 284 // in the autocomplete popup. | 284 // in the autocomplete popup. |
| 285 // Any exact match is going to be the highest quality match, and thus at the | 285 // Any exact match is going to be the highest quality match, and thus at the |
| 286 // front of our vector. | 286 // front of our vector. |
| 287 if (keyword_matches.front() == keyword) { | 287 if (keyword_matches.front() == keyword) { |
| 288 const TemplateURL* template_url(model->GetTemplateURLForKeyword(keyword)); | 288 const TemplateURL* template_url = model->GetTemplateURLForKeyword(keyword); |
| 289 const bool is_extension_keyword = template_url->IsExtensionKeyword(); | |
| 290 | |
| 291 // Only create an exact match if |remaining_input| is empty or if | |
| 292 // this is an extension keyword. If |remaining_input| is a | |
| 293 // non-empty non-extension keyword (i.e., a regular keyword that | |
| 294 // supports replacement and that has extra text following it), | |
| 295 // then SearchProvider creates the exact (a.k.a. verbatim) match. | |
| 296 if (!remaining_input.empty() && !is_extension_keyword) | |
| 297 return; | |
| 298 | |
| 289 // TODO(pkasting): We should probably check that if the user explicitly | 299 // TODO(pkasting): We should probably check that if the user explicitly |
| 290 // typed a scheme, that scheme matches the one in |template_url|. | 300 // typed a scheme, that scheme matches the one in |template_url|. |
| 291 matches_.push_back(CreateAutocompleteMatch(model, keyword, input, | 301 matches_.push_back(CreateAutocompleteMatch(model, keyword, input, |
| 292 keyword.length(), | 302 keyword.length(), |
| 293 remaining_input, -1)); | 303 remaining_input, -1)); |
| 294 | 304 |
| 295 if (profile_ && template_url->IsExtensionKeyword()) { | 305 if (profile_ && is_extension_keyword) { |
| 296 if (input.matches_requested() == AutocompleteInput::ALL_MATCHES) { | 306 if (input.matches_requested() == AutocompleteInput::ALL_MATCHES) { |
| 297 if (template_url->GetExtensionId() != current_keyword_extension_id_) | 307 if (template_url->GetExtensionId() != current_keyword_extension_id_) |
| 298 MaybeEndExtensionKeywordMode(); | 308 MaybeEndExtensionKeywordMode(); |
| 299 if (current_keyword_extension_id_.empty()) | 309 if (current_keyword_extension_id_.empty()) |
| 300 EnterExtensionKeywordMode(template_url->GetExtensionId()); | 310 EnterExtensionKeywordMode(template_url->GetExtensionId()); |
| 301 keyword_mode_toggle.StayInKeywordMode(); | 311 keyword_mode_toggle.StayInKeywordMode(); |
| 302 } | 312 } |
| 303 | 313 |
| 304 extensions::ApplyDefaultSuggestionForExtensionKeyword( | 314 extensions::ApplyDefaultSuggestionForExtensionKeyword( |
| 305 profile_, template_url, | 315 profile_, template_url, |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 414 remaining_input.length(), match->contents.length(), | 424 remaining_input.length(), match->contents.length(), |
| 415 ACMatchClassification::NONE, &match->contents_class); | 425 ACMatchClassification::NONE, &match->contents_class); |
| 416 } else { | 426 } else { |
| 417 // See comments on an identical NOTREACHED() in search_provider.cc. | 427 // See comments on an identical NOTREACHED() in search_provider.cc. |
| 418 NOTREACHED(); | 428 NOTREACHED(); |
| 419 } | 429 } |
| 420 } | 430 } |
| 421 } | 431 } |
| 422 | 432 |
| 423 // static | 433 // static |
| 434 // Perhaps this should be kept similar to | |
|
msw
2013/02/02 02:27:52
nit: comment inside the function or at the declara
Mark P
2013/02/04 19:46:09
Done.
| |
| 435 // SearchProvider::CalculateRelevanceForKeywordVerbatim(). That | |
| 436 // function calculates the verbatim query score for search keywords | |
| 437 // but only non-extension ones. It would be a bit odd if the score | |
| 438 // for a verbatim query for non-extension keyword and for an extension | |
| 439 // keyword differed dramatically (though no immediate harm would come | |
| 440 // from it). | |
| 424 int KeywordProvider::CalculateRelevance(AutocompleteInput::Type type, | 441 int KeywordProvider::CalculateRelevance(AutocompleteInput::Type type, |
| 425 bool complete, | 442 bool complete, |
| 426 bool supports_replacement, | 443 bool supports_replacement, |
| 427 bool prefer_keyword, | 444 bool prefer_keyword, |
| 428 bool allow_exact_keyword_match) { | 445 bool allow_exact_keyword_match) { |
| 429 if (!complete) | 446 if (!complete) |
| 430 return (type == AutocompleteInput::URL) ? 700 : 450; | 447 return (type == AutocompleteInput::URL) ? 700 : 450; |
| 431 if (!supports_replacement || (allow_exact_keyword_match && prefer_keyword)) | 448 if (!supports_replacement || (allow_exact_keyword_match && prefer_keyword)) |
| 432 return 1500; | 449 return 1500; |
| 433 return (allow_exact_keyword_match && (type == AutocompleteInput::QUERY)) ? | 450 return (allow_exact_keyword_match && (type == AutocompleteInput::QUERY)) ? |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 586 } | 603 } |
| 587 | 604 |
| 588 void KeywordProvider::MaybeEndExtensionKeywordMode() { | 605 void KeywordProvider::MaybeEndExtensionKeywordMode() { |
| 589 if (!current_keyword_extension_id_.empty()) { | 606 if (!current_keyword_extension_id_.empty()) { |
| 590 extensions::ExtensionOmniboxEventRouter::OnInputCancelled( | 607 extensions::ExtensionOmniboxEventRouter::OnInputCancelled( |
| 591 profile_, current_keyword_extension_id_); | 608 profile_, current_keyword_extension_id_); |
| 592 | 609 |
| 593 current_keyword_extension_id_.clear(); | 610 current_keyword_extension_id_.clear(); |
| 594 } | 611 } |
| 595 } | 612 } |
| OLD | NEW |