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