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

Side by Side Diff: chrome/browser/autocomplete/keyword_provider.cc

Issue 12090006: Omnibox: Create Keyword Verbatim Result in Search Provider (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: roperly resolved (variable rename) Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 } 299 }
300 if (keyword_matches.empty()) 300 if (keyword_matches.empty())
301 return; 301 return;
302 std::sort(keyword_matches.begin(), keyword_matches.end(), CompareQuality()); 302 std::sort(keyword_matches.begin(), keyword_matches.end(), CompareQuality());
303 303
304 // Limit to one exact or three inexact matches, and mark them up for display 304 // Limit to one exact or three inexact matches, and mark them up for display
305 // in the autocomplete popup. 305 // in the autocomplete popup.
306 // Any exact match is going to be the highest quality match, and thus at the 306 // Any exact match is going to be the highest quality match, and thus at the
307 // front of our vector. 307 // front of our vector.
308 if (keyword_matches.front() == keyword) { 308 if (keyword_matches.front() == keyword) {
309 const TemplateURL* template_url(model->GetTemplateURLForKeyword(keyword)); 309 const TemplateURL* template_url = model->GetTemplateURLForKeyword(keyword);
310 const bool is_extension_keyword = template_url->IsExtensionKeyword();
311
312 // Only create an exact match if |remaining_input| is empty or if
313 // this is an extension keyword. If |remaining_input| is a
314 // non-empty non-extension keyword (i.e., a regular keyword that
315 // supports replacement and that has extra text following it),
316 // then SearchProvider creates the exact (a.k.a. verbatim) match.
317 if (!remaining_input.empty() && !is_extension_keyword)
318 return;
319
310 // TODO(pkasting): We should probably check that if the user explicitly 320 // TODO(pkasting): We should probably check that if the user explicitly
311 // typed a scheme, that scheme matches the one in |template_url|. 321 // typed a scheme, that scheme matches the one in |template_url|.
312 matches_.push_back(CreateAutocompleteMatch(model, keyword, input, 322 matches_.push_back(CreateAutocompleteMatch(model, keyword, input,
313 keyword.length(), 323 keyword.length(),
314 remaining_input, -1)); 324 remaining_input, -1));
315 325
316 if (profile_ && template_url->IsExtensionKeyword()) { 326 if (profile_ && is_extension_keyword) {
317 if (input.matches_requested() == AutocompleteInput::ALL_MATCHES) { 327 if (input.matches_requested() == AutocompleteInput::ALL_MATCHES) {
318 if (template_url->GetExtensionId() != current_keyword_extension_id_) 328 if (template_url->GetExtensionId() != current_keyword_extension_id_)
319 MaybeEndExtensionKeywordMode(); 329 MaybeEndExtensionKeywordMode();
320 if (current_keyword_extension_id_.empty()) 330 if (current_keyword_extension_id_.empty())
321 EnterExtensionKeywordMode(template_url->GetExtensionId()); 331 EnterExtensionKeywordMode(template_url->GetExtensionId());
322 keyword_mode_toggle.StayInKeywordMode(); 332 keyword_mode_toggle.StayInKeywordMode();
323 } 333 }
324 334
325 extensions::ApplyDefaultSuggestionForExtensionKeyword( 335 extensions::ApplyDefaultSuggestionForExtensionKeyword(
326 profile_, template_url, 336 profile_, template_url,
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 } 450 }
441 } 451 }
442 } 452 }
443 453
444 // static 454 // static
445 int KeywordProvider::CalculateRelevance(AutocompleteInput::Type type, 455 int KeywordProvider::CalculateRelevance(AutocompleteInput::Type type,
446 bool complete, 456 bool complete,
447 bool supports_replacement, 457 bool supports_replacement,
448 bool prefer_keyword, 458 bool prefer_keyword,
449 bool allow_exact_keyword_match) { 459 bool allow_exact_keyword_match) {
460 // This function is responsible for scoring suggestions of keywords
461 // themselves and the suggestion of the verbatim query on an
462 // extension keyword. SearchProvider::CalculateRelevanceForKeywordVerbatim()
463 // scores verbatim query suggestions for non-extension keywords.
464 // These two functions are currently in sync, but there's no reason
465 // we couldn't decide in the future to score verbatim matches
466 // differently for extension and non-extension keywords. If you
467 // make such a change, however, you should update this comment to
468 // describe it, so it's clear why the functions diverge.
450 if (!complete) 469 if (!complete)
451 return (type == AutocompleteInput::URL) ? 700 : 450; 470 return (type == AutocompleteInput::URL) ? 700 : 450;
452 if (!supports_replacement || (allow_exact_keyword_match && prefer_keyword)) 471 if (!supports_replacement || (allow_exact_keyword_match && prefer_keyword))
453 return 1500; 472 return 1500;
454 return (allow_exact_keyword_match && (type == AutocompleteInput::QUERY)) ? 473 return (allow_exact_keyword_match && (type == AutocompleteInput::QUERY)) ?
455 1450 : 1100; 474 1450 : 1100;
456 } 475 }
457 476
458 AutocompleteMatch KeywordProvider::CreateAutocompleteMatch( 477 AutocompleteMatch KeywordProvider::CreateAutocompleteMatch(
459 TemplateURLService* model, 478 TemplateURLService* model,
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 } 626 }
608 627
609 void KeywordProvider::MaybeEndExtensionKeywordMode() { 628 void KeywordProvider::MaybeEndExtensionKeywordMode() {
610 if (!current_keyword_extension_id_.empty()) { 629 if (!current_keyword_extension_id_.empty()) {
611 extensions::ExtensionOmniboxEventRouter::OnInputCancelled( 630 extensions::ExtensionOmniboxEventRouter::OnInputCancelled(
612 profile_, current_keyword_extension_id_); 631 profile_, current_keyword_extension_id_);
613 632
614 current_keyword_extension_id_.clear(); 633 current_keyword_extension_id_.clear();
615 } 634 }
616 } 635 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698