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/string16.h" | 10 #include "base/string16.h" |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 AutocompleteMatch::ClassifyLocationInString(0, match->contents.length(), | 387 AutocompleteMatch::ClassifyLocationInString(0, match->contents.length(), |
388 match->contents.length(), ACMatchClassification::NONE, | 388 match->contents.length(), ACMatchClassification::NONE, |
389 &match->contents_class); | 389 &match->contents_class); |
390 } | 390 } |
391 } else { | 391 } else { |
392 // Create destination URL by escaping user input and substituting into | 392 // Create destination URL by escaping user input and substituting into |
393 // keyword template URL. The escaping here handles whitespace in user | 393 // keyword template URL. The escaping here handles whitespace in user |
394 // input, but we rely on later canonicalization functions to do more | 394 // input, but we rely on later canonicalization functions to do more |
395 // fixup to make the URL valid if necessary. | 395 // fixup to make the URL valid if necessary. |
396 DCHECK(element_ref.SupportsReplacement()); | 396 DCHECK(element_ref.SupportsReplacement()); |
397 match->destination_url = GURL(element_ref.ReplaceSearchTermsUsingProfile( | 397 match->destination_url = GURL(element_ref.ReplaceSearchTerms( |
398 profile, remaining_input, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, | 398 remaining_input, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); |
399 string16())); | |
400 std::vector<size_t> content_param_offsets; | 399 std::vector<size_t> content_param_offsets; |
401 match->contents.assign(l10n_util::GetStringFUTF16(message_id, | 400 match->contents.assign(l10n_util::GetStringFUTF16(message_id, |
402 element->short_name(), | 401 element->short_name(), |
403 remaining_input, | 402 remaining_input, |
404 &content_param_offsets)); | 403 &content_param_offsets)); |
405 if (content_param_offsets.size() == 2) { | 404 if (content_param_offsets.size() == 2) { |
406 AutocompleteMatch::ClassifyLocationInString(content_param_offsets[1], | 405 AutocompleteMatch::ClassifyLocationInString(content_param_offsets[1], |
407 remaining_input.length(), match->contents.length(), | 406 remaining_input.length(), match->contents.length(), |
408 ACMatchClassification::NONE, &match->contents_class); | 407 ACMatchClassification::NONE, &match->contents_class); |
409 } else { | 408 } else { |
(...skipping 20 matching lines...) Expand all Loading... |
430 AutocompleteMatch KeywordProvider::CreateAutocompleteMatch( | 429 AutocompleteMatch KeywordProvider::CreateAutocompleteMatch( |
431 TemplateURLService* model, | 430 TemplateURLService* model, |
432 const string16& keyword, | 431 const string16& keyword, |
433 const AutocompleteInput& input, | 432 const AutocompleteInput& input, |
434 size_t prefix_length, | 433 size_t prefix_length, |
435 const string16& remaining_input, | 434 const string16& remaining_input, |
436 int relevance) { | 435 int relevance) { |
437 DCHECK(model); | 436 DCHECK(model); |
438 // Get keyword data from data store. | 437 // Get keyword data from data store. |
439 const TemplateURL* element = model->GetTemplateURLForKeyword(keyword); | 438 const TemplateURL* element = model->GetTemplateURLForKeyword(keyword); |
440 DCHECK(element && !element->url().empty()); | 439 DCHECK(element); |
441 const bool supports_replacement = element->url_ref().SupportsReplacement(); | 440 const bool supports_replacement = element->url_ref().SupportsReplacement(); |
442 | 441 |
443 // Create an edit entry of "[keyword] [remaining input]". This is helpful | 442 // Create an edit entry of "[keyword] [remaining input]". This is helpful |
444 // even when [remaining input] is empty, as the user can select the popup | 443 // even when [remaining input] is empty, as the user can select the popup |
445 // choice and immediately begin typing in query input. | 444 // choice and immediately begin typing in query input. |
446 const bool keyword_complete = (prefix_length == keyword.length()); | 445 const bool keyword_complete = (prefix_length == keyword.length()); |
447 if (relevance < 0) { | 446 if (relevance < 0) { |
448 relevance = | 447 relevance = |
449 CalculateRelevance(input.type(), keyword_complete, | 448 CalculateRelevance(input.type(), keyword_complete, |
450 // When the user wants keyword matches to take | 449 // When the user wants keyword matches to take |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 } | 579 } |
581 | 580 |
582 void KeywordProvider::MaybeEndExtensionKeywordMode() { | 581 void KeywordProvider::MaybeEndExtensionKeywordMode() { |
583 if (!current_keyword_extension_id_.empty()) { | 582 if (!current_keyword_extension_id_.empty()) { |
584 ExtensionOmniboxEventRouter::OnInputCancelled( | 583 ExtensionOmniboxEventRouter::OnInputCancelled( |
585 profile_, current_keyword_extension_id_); | 584 profile_, current_keyword_extension_id_); |
586 | 585 |
587 current_keyword_extension_id_.clear(); | 586 current_keyword_extension_id_.clear(); |
588 } | 587 } |
589 } | 588 } |
OLD | NEW |