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

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: Bart's final comments. 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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 =
290 profile_ && template_url->IsExtensionKeyword();
msw 2013/01/31 00:38:16 Is |profile_| actually required for extension keyw
Mark P 2013/01/31 23:09:27 That was a condition in the original if test so I
msw 2013/02/01 20:52:37 I see that, but I asked if that was a separate con
Mark P 2013/02/02 00:24:35 It's unrelated. Moved as you suggested.
291
292 // We only create an exact match if remaining_input is empty or
msw 2013/01/31 00:38:16 optional nits: |remaining_input| here and below an
Mark P 2013/01/31 23:09:27 Done.
293 // if this is an extension keyword; if remaining_input is a non-empty
294 // non-extension keyword (i.e., we have a regular keyword that
295 // supports replacement and has extra text following it), then we
296 // let SearchProvider create the exact (a.k.a. verbatim) match.
297 if (!remaining_input.empty() && !is_extension_keyword)
298 return;
299
289 // TODO(pkasting): We should probably check that if the user explicitly 300 // TODO(pkasting): We should probably check that if the user explicitly
290 // typed a scheme, that scheme matches the one in |template_url|. 301 // typed a scheme, that scheme matches the one in |template_url|.
291 matches_.push_back(CreateAutocompleteMatch(model, keyword, input, 302 matches_.push_back(CreateAutocompleteMatch(model, keyword, input,
292 keyword.length(), 303 keyword.length(),
293 remaining_input, -1)); 304 remaining_input, -1));
294 305
295 if (profile_ && template_url->IsExtensionKeyword()) { 306 if (is_extension_keyword) {
296 if (input.matches_requested() == AutocompleteInput::ALL_MATCHES) { 307 if (input.matches_requested() == AutocompleteInput::ALL_MATCHES) {
297 if (template_url->GetExtensionId() != current_keyword_extension_id_) 308 if (template_url->GetExtensionId() != current_keyword_extension_id_)
298 MaybeEndExtensionKeywordMode(); 309 MaybeEndExtensionKeywordMode();
299 if (current_keyword_extension_id_.empty()) 310 if (current_keyword_extension_id_.empty())
300 EnterExtensionKeywordMode(template_url->GetExtensionId()); 311 EnterExtensionKeywordMode(template_url->GetExtensionId());
301 keyword_mode_toggle.StayInKeywordMode(); 312 keyword_mode_toggle.StayInKeywordMode();
302 } 313 }
303 314
304 extensions::ApplyDefaultSuggestionForExtensionKeyword( 315 extensions::ApplyDefaultSuggestionForExtensionKeyword(
305 profile_, template_url, 316 profile_, template_url,
306 remaining_input, 317 remaining_input,
307 &matches_[0]); 318 &matches_[0]);
308 319
309 if (minimal_changes && 320 if (minimal_changes &&
310 (input.matches_requested() != AutocompleteInput::BEST_MATCH)) { 321 (input.matches_requested() != AutocompleteInput::BEST_MATCH)) {
311 // If the input hasn't significantly changed, we can just use the 322 // If the input hasn't significantly changed, we can just use the
312 // suggestions from last time. We need to readjust the relevance to 323 // suggestions from last time. We need to readjust the relevance to
313 // ensure it is less than the main match's relevance. 324 // ensure it is less than the main match's relevance.
314 for (size_t i = 0; i < extension_suggest_matches_.size(); ++i) { 325 for (size_t i = 0; i < extension_suggest_matches_.size(); ++i) {
315 matches_.push_back(extension_suggest_matches_[i]); 326 matches_.push_back(extension_suggest_matches_[i]);
316 matches_.back().relevance = matches_[0].relevance - (i + 1); 327 matches_.back().relevance = matches_[0].relevance - (i + 1);
317 } 328 }
318 } else if (input.matches_requested() == AutocompleteInput::ALL_MATCHES) { 329 } else if (input.matches_requested() ==
msw 2013/01/31 00:38:16 optional nit: don't split this line
Mark P 2013/01/31 23:09:27 Done.
330 AutocompleteInput::ALL_MATCHES) {
319 extension_suggest_last_input_ = input; 331 extension_suggest_last_input_ = input;
320 extension_suggest_matches_.clear(); 332 extension_suggest_matches_.clear();
321 333
322 bool have_listeners = 334 bool have_listeners =
323 extensions::ExtensionOmniboxEventRouter::OnInputChanged( 335 extensions::ExtensionOmniboxEventRouter::OnInputChanged(
324 profile_, template_url->GetExtensionId(), 336 profile_, template_url->GetExtensionId(),
325 UTF16ToUTF8(remaining_input), current_input_id_); 337 UTF16ToUTF8(remaining_input), current_input_id_);
326 338
327 // We only have to wait for suggest results if there are actually 339 // We only have to wait for suggest results if there are actually
328 // extensions listening for input changes. 340 // extensions listening for input changes.
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 remaining_input.length(), match->contents.length(), 426 remaining_input.length(), match->contents.length(),
415 ACMatchClassification::NONE, &match->contents_class); 427 ACMatchClassification::NONE, &match->contents_class);
416 } else { 428 } else {
417 // See comments on an identical NOTREACHED() in search_provider.cc. 429 // See comments on an identical NOTREACHED() in search_provider.cc.
418 NOTREACHED(); 430 NOTREACHED();
419 } 431 }
420 } 432 }
421 } 433 }
422 434
423 // static 435 // static
424 int KeywordProvider::CalculateRelevance(AutocompleteInput::Type type, 436 int KeywordProvider::CalculateRelevance(AutocompleteInput::Type type,
msw 2013/01/31 00:38:16 optional nit: add a decl comment that these scores
Mark P 2013/01/31 23:09:27 It doesn't have to stay in sync. See the last par
msw 2013/02/01 20:52:37 It still seems odd if they diverged, but I don't r
Mark P 2013/02/02 00:24:35 Done.
425 bool complete, 437 bool complete,
426 bool supports_replacement, 438 bool supports_replacement,
427 bool prefer_keyword, 439 bool prefer_keyword,
428 bool allow_exact_keyword_match) { 440 bool allow_exact_keyword_match) {
429 if (!complete) 441 if (!complete)
430 return (type == AutocompleteInput::URL) ? 700 : 450; 442 return (type == AutocompleteInput::URL) ? 700 : 450;
431 if (!supports_replacement || (allow_exact_keyword_match && prefer_keyword)) 443 if (!supports_replacement || (allow_exact_keyword_match && prefer_keyword))
432 return 1500; 444 return 1500;
433 return (allow_exact_keyword_match && (type == AutocompleteInput::QUERY)) ? 445 return (allow_exact_keyword_match && (type == AutocompleteInput::QUERY)) ?
434 1450 : 1100; 446 1450 : 1100;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 } 598 }
587 599
588 void KeywordProvider::MaybeEndExtensionKeywordMode() { 600 void KeywordProvider::MaybeEndExtensionKeywordMode() {
589 if (!current_keyword_extension_id_.empty()) { 601 if (!current_keyword_extension_id_.empty()) {
590 extensions::ExtensionOmniboxEventRouter::OnInputCancelled( 602 extensions::ExtensionOmniboxEventRouter::OnInputCancelled(
591 profile_, current_keyword_extension_id_); 603 profile_, current_keyword_extension_id_);
592 604
593 current_keyword_extension_id_.clear(); 605 current_keyword_extension_id_.clear();
594 } 606 }
595 } 607 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698