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

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

Issue 1784233003: Omnibox - Keyword Provider Shouldn't Bold What-You-Typed Queries (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update test Created 4 years, 9 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
« no previous file with comments | « no previous file | components/omnibox/browser/keyword_provider_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/keyword_provider.h" 5 #include "components/omnibox/browser/keyword_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 return match; 442 return match;
443 } 443 }
444 444
445 void KeywordProvider::FillInURLAndContents( 445 void KeywordProvider::FillInURLAndContents(
446 const base::string16& remaining_input, 446 const base::string16& remaining_input,
447 const TemplateURL* element, 447 const TemplateURL* element,
448 AutocompleteMatch* match) const { 448 AutocompleteMatch* match) const {
449 DCHECK(!element->short_name().empty()); 449 DCHECK(!element->short_name().empty());
450 const TemplateURLRef& element_ref = element->url_ref(); 450 const TemplateURLRef& element_ref = element->url_ref();
451 DCHECK(element_ref.IsValid(GetTemplateURLService()->search_terms_data())); 451 DCHECK(element_ref.IsValid(GetTemplateURLService()->search_terms_data()));
452 int message_id = (element->GetType() == TemplateURL::OMNIBOX_API_EXTENSION) ?
453 IDS_EXTENSION_KEYWORD_COMMAND : IDS_KEYWORD_SEARCH;
454 if (remaining_input.empty()) { 452 if (remaining_input.empty()) {
455 // Allow extension keyword providers to accept empty string input. This is 453 // Allow extension keyword providers to accept empty string input. This is
456 // useful to allow extensions to do something in the case where no input is 454 // useful to allow extensions to do something in the case where no input is
457 // entered. 455 // entered.
458 if (element_ref.SupportsReplacement( 456 if (element_ref.SupportsReplacement(
459 GetTemplateURLService()->search_terms_data()) && 457 GetTemplateURLService()->search_terms_data()) &&
460 (element->GetType() != TemplateURL::OMNIBOX_API_EXTENSION)) { 458 (element->GetType() != TemplateURL::OMNIBOX_API_EXTENSION)) {
461 // No query input; return a generic, no-destination placeholder. 459 // No query input; return a generic, no-destination placeholder.
462 match->contents.assign( 460 match->contents.assign(
463 l10n_util::GetStringFUTF16(message_id, 461 l10n_util::GetStringFUTF16(
462 IDS_KEYWORD_SEARCH,
464 element->AdjustedShortNameForLocaleDirection(), 463 element->AdjustedShortNameForLocaleDirection(),
465 l10n_util::GetStringUTF16(IDS_EMPTY_KEYWORD_VALUE))); 464 l10n_util::GetStringUTF16(IDS_EMPTY_KEYWORD_VALUE)));
Peter Kasting 2016/03/17 06:08:11 Should we change this to just "<enter query> - Ama
Mark P 2016/04/01 21:48:39 Changed text per the bug.
466 match->contents_class.push_back( 465 match->contents_class.push_back(
467 ACMatchClassification(0, ACMatchClassification::DIM)); 466 ACMatchClassification(0, ACMatchClassification::DIM));
468 } else { 467 } else {
469 // Keyword that has no replacement text (aka a shorthand for a URL). 468 // Keyword or extension that has no replacement text (aka a shorthand for
469 // a URL).
470 match->destination_url = GURL(element->url()); 470 match->destination_url = GURL(element->url());
471 match->contents.assign(element->short_name()); 471 match->contents.assign(element->short_name());
472 AutocompleteMatch::ClassifyLocationInString(0, match->contents.length(), 472 AutocompleteMatch::ClassifyLocationInString(0, match->contents.length(),
473 match->contents.length(), ACMatchClassification::NONE, 473 match->contents.length(), ACMatchClassification::NONE,
474 &match->contents_class); 474 &match->contents_class);
475 } 475 }
476 } else { 476 } else {
477 // Create destination URL by escaping user input and substituting into 477 // Create destination URL by escaping user input and substituting into
478 // keyword template URL. The escaping here handles whitespace in user 478 // keyword template URL. The escaping here handles whitespace in user
479 // input, but we rely on later canonicalization functions to do more 479 // input, but we rely on later canonicalization functions to do more
480 // fixup to make the URL valid if necessary. 480 // fixup to make the URL valid if necessary.
481 DCHECK(element_ref.SupportsReplacement( 481 DCHECK(element_ref.SupportsReplacement(
482 GetTemplateURLService()->search_terms_data())); 482 GetTemplateURLService()->search_terms_data()));
483 TemplateURLRef::SearchTermsArgs search_terms_args(remaining_input); 483 TemplateURLRef::SearchTermsArgs search_terms_args(remaining_input);
484 search_terms_args.append_extra_query_params = 484 search_terms_args.append_extra_query_params =
485 element == GetTemplateURLService()->GetDefaultSearchProvider(); 485 element == GetTemplateURLService()->GetDefaultSearchProvider();
486 match->destination_url = GURL(element_ref.ReplaceSearchTerms( 486 match->destination_url = GURL(element_ref.ReplaceSearchTerms(
487 search_terms_args, GetTemplateURLService()->search_terms_data())); 487 search_terms_args, GetTemplateURLService()->search_terms_data()));
488 std::vector<size_t> content_param_offsets; 488 match->contents = remaining_input;
489 match->contents.assign(l10n_util::GetStringFUTF16(message_id, 489 match->contents_class.push_back(
490 element->short_name(), 490 ACMatchClassification(0, ACMatchClassification::NONE));
491 remaining_input,
492 &content_param_offsets));
493 DCHECK_EQ(2U, content_param_offsets.size());
494 AutocompleteMatch::ClassifyLocationInString(content_param_offsets[1],
495 remaining_input.length(), match->contents.length(),
496 ACMatchClassification::NONE, &match->contents_class);
497 } 491 }
498 } 492 }
499 493
500 TemplateURLService* KeywordProvider::GetTemplateURLService() const { 494 TemplateURLService* KeywordProvider::GetTemplateURLService() const {
501 // Make sure the model is loaded. This is cheap and quickly bails out if 495 // Make sure the model is loaded. This is cheap and quickly bails out if
502 // the model is already loaded. 496 // the model is already loaded.
503 model_->Load(); 497 model_->Load();
504 return model_; 498 return model_;
505 } 499 }
OLDNEW
« no previous file with comments | « no previous file | components/omnibox/browser/keyword_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698