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

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 comments plus more tests. 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();
291
292 // We only create an exact match if remaining_input is empty or
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() ==
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.
329 if (have_listeners) 341 if (have_listeners)
330 done_ = false; 342 done_ = false;
331 } 343 }
332 } 344 }
333 } else { 345 return;
334 if (keyword_matches.size() > kMaxMatches) { 346 }
Bart N. 2013/01/30 21:36:21 I think "else" here was probably better than now (
Mark P 2013/01/30 22:19:45 Done.
335 keyword_matches.erase(keyword_matches.begin() + kMaxMatches, 347
336 keyword_matches.end()); 348 // If we reached here, we have no exact keyword match.
337 } 349 if (keyword_matches.size() > kMaxMatches) {
338 for (std::vector<string16>::const_iterator i(keyword_matches.begin()); 350 keyword_matches.erase(keyword_matches.begin() + kMaxMatches,
339 i != keyword_matches.end(); ++i) { 351 keyword_matches.end());
340 matches_.push_back(CreateAutocompleteMatch(model, *i, 352 }
341 input, keyword.length(), 353 for (std::vector<string16>::const_iterator i(keyword_matches.begin());
342 remaining_input, -1)); 354 i != keyword_matches.end(); ++i) {
343 } 355 matches_.push_back(CreateAutocompleteMatch(model, *i,
356 input, keyword.length(),
357 remaining_input, -1));
344 } 358 }
345 } 359 }
346 360
347 void KeywordProvider::Stop(bool clear_cached_results) { 361 void KeywordProvider::Stop(bool clear_cached_results) {
348 done_ = true; 362 done_ = true;
349 MaybeEndExtensionKeywordMode(); 363 MaybeEndExtensionKeywordMode();
350 } 364 }
351 365
352 KeywordProvider::~KeywordProvider() {} 366 KeywordProvider::~KeywordProvider() {}
353 367
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 } 600 }
587 601
588 void KeywordProvider::MaybeEndExtensionKeywordMode() { 602 void KeywordProvider::MaybeEndExtensionKeywordMode() {
589 if (!current_keyword_extension_id_.empty()) { 603 if (!current_keyword_extension_id_.empty()) {
590 extensions::ExtensionOmniboxEventRouter::OnInputCancelled( 604 extensions::ExtensionOmniboxEventRouter::OnInputCancelled(
591 profile_, current_keyword_extension_id_); 605 profile_, current_keyword_extension_id_);
592 606
593 current_keyword_extension_id_.clear(); 607 current_keyword_extension_id_.clear();
594 } 608 }
595 } 609 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698