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/strings/string16.h" | 10 #include "base/strings/string16.h" |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 matches_.push_back(extension_suggest_matches_[i]); | 355 matches_.push_back(extension_suggest_matches_[i]); |
356 matches_.back().relevance = matches_[0].relevance - (i + 1); | 356 matches_.back().relevance = matches_[0].relevance - (i + 1); |
357 } | 357 } |
358 } else if (input.matches_requested() == AutocompleteInput::ALL_MATCHES) { | 358 } else if (input.matches_requested() == AutocompleteInput::ALL_MATCHES) { |
359 extension_suggest_last_input_ = input; | 359 extension_suggest_last_input_ = input; |
360 extension_suggest_matches_.clear(); | 360 extension_suggest_matches_.clear(); |
361 | 361 |
362 bool have_listeners = | 362 bool have_listeners = |
363 extensions::ExtensionOmniboxEventRouter::OnInputChanged( | 363 extensions::ExtensionOmniboxEventRouter::OnInputChanged( |
364 profile_, template_url->GetExtensionId(), | 364 profile_, template_url->GetExtensionId(), |
365 UTF16ToUTF8(remaining_input), current_input_id_); | 365 base::UTF16ToUTF8(remaining_input), current_input_id_); |
366 | 366 |
367 // We only have to wait for suggest results if there are actually | 367 // We only have to wait for suggest results if there are actually |
368 // extensions listening for input changes. | 368 // extensions listening for input changes. |
369 if (have_listeners) | 369 if (have_listeners) |
370 done_ = false; | 370 done_ = false; |
371 } | 371 } |
372 } | 372 } |
373 } else { | 373 } else { |
374 if (matches.size() > kMaxMatches) | 374 if (matches.size() > kMaxMatches) |
375 matches.erase(matches.begin() + kMaxMatches, matches.end()); | 375 matches.erase(matches.begin() + kMaxMatches, matches.end()); |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 // We recompute the first match's relevance; we know that |complete| | 583 // We recompute the first match's relevance; we know that |complete| |
584 // is true, because we wouldn't get results from the extension unless | 584 // is true, because we wouldn't get results from the extension unless |
585 // the full keyword had been typed. | 585 // the full keyword had been typed. |
586 int first_relevance = CalculateRelevance(input.type(), true, true, | 586 int first_relevance = CalculateRelevance(input.type(), true, true, |
587 input.prefer_keyword(), input.allow_exact_keyword_match()); | 587 input.prefer_keyword(), input.allow_exact_keyword_match()); |
588 // Because these matches are async, we should never let them become the | 588 // Because these matches are async, we should never let them become the |
589 // default match, lest we introduce race conditions in the omnibox user | 589 // default match, lest we introduce race conditions in the omnibox user |
590 // interaction. | 590 // interaction. |
591 extension_suggest_matches_.push_back(CreateAutocompleteMatch( | 591 extension_suggest_matches_.push_back(CreateAutocompleteMatch( |
592 template_url, input, keyword.length(), | 592 template_url, input, keyword.length(), |
593 UTF8ToUTF16(suggestion.content), false, first_relevance - (i + 1))); | 593 base::UTF8ToUTF16(suggestion.content), false, |
| 594 first_relevance - (i + 1))); |
594 | 595 |
595 AutocompleteMatch* match = &extension_suggest_matches_.back(); | 596 AutocompleteMatch* match = &extension_suggest_matches_.back(); |
596 match->contents.assign(UTF8ToUTF16(suggestion.description)); | 597 match->contents.assign(base::UTF8ToUTF16(suggestion.description)); |
597 match->contents_class = | 598 match->contents_class = |
598 extensions::StyleTypesToACMatchClassifications(suggestion); | 599 extensions::StyleTypesToACMatchClassifications(suggestion); |
599 match->description.clear(); | 600 match->description.clear(); |
600 match->description_class.clear(); | 601 match->description_class.clear(); |
601 } | 602 } |
602 | 603 |
603 done_ = true; | 604 done_ = true; |
604 matches_.insert(matches_.end(), extension_suggest_matches_.begin(), | 605 matches_.insert(matches_.end(), extension_suggest_matches_.begin(), |
605 extension_suggest_matches_.end()); | 606 extension_suggest_matches_.end()); |
606 listener_->OnProviderUpdate(!extension_suggest_matches_.empty()); | 607 listener_->OnProviderUpdate(!extension_suggest_matches_.empty()); |
(...skipping 26 matching lines...) Expand all Loading... |
633 } | 634 } |
634 | 635 |
635 void KeywordProvider::MaybeEndExtensionKeywordMode() { | 636 void KeywordProvider::MaybeEndExtensionKeywordMode() { |
636 if (!current_keyword_extension_id_.empty()) { | 637 if (!current_keyword_extension_id_.empty()) { |
637 extensions::ExtensionOmniboxEventRouter::OnInputCancelled( | 638 extensions::ExtensionOmniboxEventRouter::OnInputCancelled( |
638 profile_, current_keyword_extension_id_); | 639 profile_, current_keyword_extension_id_); |
639 | 640 |
640 current_keyword_extension_id_.clear(); | 641 current_keyword_extension_id_.clear(); |
641 } | 642 } |
642 } | 643 } |
OLD | NEW |