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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 return !keyword->empty(); | 357 return !keyword->empty(); |
358 } | 358 } |
359 | 359 |
360 // static | 360 // static |
361 void KeywordProvider::FillInURLAndContents( | 361 void KeywordProvider::FillInURLAndContents( |
362 Profile* profile, | 362 Profile* profile, |
363 const string16& remaining_input, | 363 const string16& remaining_input, |
364 const TemplateURL* element, | 364 const TemplateURL* element, |
365 AutocompleteMatch* match) { | 365 AutocompleteMatch* match) { |
366 DCHECK(!element->short_name().empty()); | 366 DCHECK(!element->short_name().empty()); |
367 const TemplateURLRef& element_ref = element->url_ref(); | 367 const TemplateURLRef* element_ref = element->url(); |
368 DCHECK(element_ref.IsValid()); | 368 DCHECK(element_ref); |
| 369 DCHECK(element_ref->IsValid()); |
369 int message_id = element->IsExtensionKeyword() ? | 370 int message_id = element->IsExtensionKeyword() ? |
370 IDS_EXTENSION_KEYWORD_COMMAND : IDS_KEYWORD_SEARCH; | 371 IDS_EXTENSION_KEYWORD_COMMAND : IDS_KEYWORD_SEARCH; |
371 if (remaining_input.empty()) { | 372 if (remaining_input.empty()) { |
372 // Allow extension keyword providers to accept empty string input. This is | 373 // Allow extension keyword providers to accept empty string input. This is |
373 // useful to allow extensions to do something in the case where no input is | 374 // useful to allow extensions to do something in the case where no input is |
374 // entered. | 375 // entered. |
375 if (element_ref.SupportsReplacement() && !element->IsExtensionKeyword()) { | 376 if (element_ref->SupportsReplacement() && !element->IsExtensionKeyword()) { |
376 // No query input; return a generic, no-destination placeholder. | 377 // No query input; return a generic, no-destination placeholder. |
377 match->contents.assign( | 378 match->contents.assign( |
378 l10n_util::GetStringFUTF16(message_id, | 379 l10n_util::GetStringFUTF16(message_id, |
379 element->AdjustedShortNameForLocaleDirection(), | 380 element->AdjustedShortNameForLocaleDirection(), |
380 l10n_util::GetStringUTF16(IDS_EMPTY_KEYWORD_VALUE))); | 381 l10n_util::GetStringUTF16(IDS_EMPTY_KEYWORD_VALUE))); |
381 match->contents_class.push_back( | 382 match->contents_class.push_back( |
382 ACMatchClassification(0, ACMatchClassification::DIM)); | 383 ACMatchClassification(0, ACMatchClassification::DIM)); |
383 } else { | 384 } else { |
384 // Keyword that has no replacement text (aka a shorthand for a URL). | 385 // Keyword that has no replacement text (aka a shorthand for a URL). |
385 match->destination_url = GURL(element->url()); | 386 match->destination_url = GURL(element_ref->url()); |
386 match->contents.assign(element->short_name()); | 387 match->contents.assign(element->short_name()); |
387 AutocompleteMatch::ClassifyLocationInString(0, match->contents.length(), | 388 AutocompleteMatch::ClassifyLocationInString(0, match->contents.length(), |
388 match->contents.length(), ACMatchClassification::NONE, | 389 match->contents.length(), ACMatchClassification::NONE, |
389 &match->contents_class); | 390 &match->contents_class); |
390 } | 391 } |
391 } else { | 392 } else { |
392 // Create destination URL by escaping user input and substituting into | 393 // Create destination URL by escaping user input and substituting into |
393 // keyword template URL. The escaping here handles whitespace in user | 394 // keyword template URL. The escaping here handles whitespace in user |
394 // input, but we rely on later canonicalization functions to do more | 395 // input, but we rely on later canonicalization functions to do more |
395 // fixup to make the URL valid if necessary. | 396 // fixup to make the URL valid if necessary. |
396 DCHECK(element_ref.SupportsReplacement()); | 397 DCHECK(element_ref->SupportsReplacement()); |
397 match->destination_url = GURL(element_ref.ReplaceSearchTermsUsingProfile( | 398 match->destination_url = GURL(element_ref-> |
398 profile, remaining_input, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, | 399 ReplaceSearchTermsUsingProfile(profile, remaining_input, |
399 string16())); | 400 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); |
400 std::vector<size_t> content_param_offsets; | 401 std::vector<size_t> content_param_offsets; |
401 match->contents.assign(l10n_util::GetStringFUTF16(message_id, | 402 match->contents.assign(l10n_util::GetStringFUTF16(message_id, |
402 element->short_name(), | 403 element->short_name(), |
403 remaining_input, | 404 remaining_input, |
404 &content_param_offsets)); | 405 &content_param_offsets)); |
405 if (content_param_offsets.size() == 2) { | 406 if (content_param_offsets.size() == 2) { |
406 AutocompleteMatch::ClassifyLocationInString(content_param_offsets[1], | 407 AutocompleteMatch::ClassifyLocationInString(content_param_offsets[1], |
407 remaining_input.length(), match->contents.length(), | 408 remaining_input.length(), match->contents.length(), |
408 ACMatchClassification::NONE, &match->contents_class); | 409 ACMatchClassification::NONE, &match->contents_class); |
409 } else { | 410 } else { |
(...skipping 21 matching lines...) Expand all Loading... |
431 TemplateURLService* model, | 432 TemplateURLService* model, |
432 const string16& keyword, | 433 const string16& keyword, |
433 const AutocompleteInput& input, | 434 const AutocompleteInput& input, |
434 size_t prefix_length, | 435 size_t prefix_length, |
435 const string16& remaining_input, | 436 const string16& remaining_input, |
436 int relevance) { | 437 int relevance) { |
437 DCHECK(model); | 438 DCHECK(model); |
438 // Get keyword data from data store. | 439 // Get keyword data from data store. |
439 const TemplateURL* element( | 440 const TemplateURL* element( |
440 model->GetTemplateURLForKeyword(keyword)); | 441 model->GetTemplateURLForKeyword(keyword)); |
441 DCHECK(element && !element->url().empty()); | 442 DCHECK(element && element->url()); |
442 const bool supports_replacement = element->url_ref().SupportsReplacement(); | 443 const bool supports_replacement = element->url()->SupportsReplacement(); |
443 | 444 |
444 // Create an edit entry of "[keyword] [remaining input]". This is helpful | 445 // Create an edit entry of "[keyword] [remaining input]". This is helpful |
445 // even when [remaining input] is empty, as the user can select the popup | 446 // even when [remaining input] is empty, as the user can select the popup |
446 // choice and immediately begin typing in query input. | 447 // choice and immediately begin typing in query input. |
447 const bool keyword_complete = (prefix_length == keyword.length()); | 448 const bool keyword_complete = (prefix_length == keyword.length()); |
448 if (relevance < 0) { | 449 if (relevance < 0) { |
449 relevance = | 450 relevance = |
450 CalculateRelevance(input.type(), keyword_complete, | 451 CalculateRelevance(input.type(), keyword_complete, |
451 // When the user wants keyword matches to take | 452 // When the user wants keyword matches to take |
452 // preference, score them highly regardless of | 453 // preference, score them highly regardless of |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 } | 582 } |
582 | 583 |
583 void KeywordProvider::MaybeEndExtensionKeywordMode() { | 584 void KeywordProvider::MaybeEndExtensionKeywordMode() { |
584 if (!current_keyword_extension_id_.empty()) { | 585 if (!current_keyword_extension_id_.empty()) { |
585 ExtensionOmniboxEventRouter::OnInputCancelled( | 586 ExtensionOmniboxEventRouter::OnInputCancelled( |
586 profile_, current_keyword_extension_id_); | 587 profile_, current_keyword_extension_id_); |
587 | 588 |
588 current_keyword_extension_id_.clear(); | 589 current_keyword_extension_id_.clear(); |
589 } | 590 } |
590 } | 591 } |
OLD | NEW |