| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 DCHECK(element->url()->IsValid()); | 311 DCHECK(element->url()->IsValid()); |
| 312 int message_id = element->IsExtensionKeyword() ? | 312 int message_id = element->IsExtensionKeyword() ? |
| 313 IDS_EXTENSION_KEYWORD_COMMAND : IDS_KEYWORD_SEARCH; | 313 IDS_EXTENSION_KEYWORD_COMMAND : IDS_KEYWORD_SEARCH; |
| 314 if (remaining_input.empty()) { | 314 if (remaining_input.empty()) { |
| 315 // Allow extension keyword providers to accept empty string input. This is | 315 // Allow extension keyword providers to accept empty string input. This is |
| 316 // useful to allow extensions to do something in the case where no input is | 316 // useful to allow extensions to do something in the case where no input is |
| 317 // entered. | 317 // entered. |
| 318 if (element->url()->SupportsReplacement() && | 318 if (element->url()->SupportsReplacement() && |
| 319 !element->IsExtensionKeyword()) { | 319 !element->IsExtensionKeyword()) { |
| 320 // No query input; return a generic, no-destination placeholder. | 320 // No query input; return a generic, no-destination placeholder. |
| 321 match->contents.assign(l10n_util::GetStringF(message_id, | 321 match->contents.assign(UTF16ToWideHack( |
| 322 element->AdjustedShortNameForLocaleDirection(), | 322 l10n_util::GetStringFUTF16(message_id, |
| 323 l10n_util::GetString(IDS_EMPTY_KEYWORD_VALUE))); | 323 WideToUTF16Hack(element->AdjustedShortNameForLocaleDirection()), |
| 324 l10n_util::GetStringUTF16(IDS_EMPTY_KEYWORD_VALUE)))); |
| 324 match->contents_class.push_back( | 325 match->contents_class.push_back( |
| 325 ACMatchClassification(0, ACMatchClassification::DIM)); | 326 ACMatchClassification(0, ACMatchClassification::DIM)); |
| 326 } else { | 327 } else { |
| 327 // Keyword that has no replacement text (aka a shorthand for a URL). | 328 // Keyword that has no replacement text (aka a shorthand for a URL). |
| 328 match->destination_url = GURL(element->url()->url()); | 329 match->destination_url = GURL(element->url()->url()); |
| 329 match->contents.assign(element->short_name()); | 330 match->contents.assign(element->short_name()); |
| 330 AutocompleteMatch::ClassifyLocationInString(0, match->contents.length(), | 331 AutocompleteMatch::ClassifyLocationInString(0, match->contents.length(), |
| 331 match->contents.length(), ACMatchClassification::NONE, | 332 match->contents.length(), ACMatchClassification::NONE, |
| 332 &match->contents_class); | 333 &match->contents_class); |
| 333 } | 334 } |
| 334 } else { | 335 } else { |
| 335 // Create destination URL by escaping user input and substituting into | 336 // Create destination URL by escaping user input and substituting into |
| 336 // keyword template URL. The escaping here handles whitespace in user | 337 // keyword template URL. The escaping here handles whitespace in user |
| 337 // input, but we rely on later canonicalization functions to do more | 338 // input, but we rely on later canonicalization functions to do more |
| 338 // fixup to make the URL valid if necessary. | 339 // fixup to make the URL valid if necessary. |
| 339 DCHECK(element->url()->SupportsReplacement()); | 340 DCHECK(element->url()->SupportsReplacement()); |
| 340 match->destination_url = GURL(element->url()->ReplaceSearchTerms( | 341 match->destination_url = GURL(element->url()->ReplaceSearchTerms( |
| 341 *element, remaining_input, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, | 342 *element, remaining_input, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, |
| 342 std::wstring())); | 343 std::wstring())); |
| 343 std::vector<size_t> content_param_offsets; | 344 std::vector<size_t> content_param_offsets; |
| 344 match->contents.assign(l10n_util::GetStringF(message_id, | 345 match->contents.assign(UTF16ToWideHack( |
| 345 element->short_name(), | 346 l10n_util::GetStringFUTF16(message_id, |
| 346 remaining_input, | 347 WideToUTF16Hack(element->short_name()), |
| 347 &content_param_offsets)); | 348 WideToUTF16Hack(remaining_input), |
| 349 &content_param_offsets))); |
| 348 if (content_param_offsets.size() == 2) { | 350 if (content_param_offsets.size() == 2) { |
| 349 AutocompleteMatch::ClassifyLocationInString(content_param_offsets[1], | 351 AutocompleteMatch::ClassifyLocationInString(content_param_offsets[1], |
| 350 remaining_input.length(), match->contents.length(), | 352 remaining_input.length(), match->contents.length(), |
| 351 ACMatchClassification::NONE, &match->contents_class); | 353 ACMatchClassification::NONE, &match->contents_class); |
| 352 } else { | 354 } else { |
| 353 // See comments on an identical NOTREACHED() in search_provider.cc. | 355 // See comments on an identical NOTREACHED() in search_provider.cc. |
| 354 NOTREACHED(); | 356 NOTREACHED(); |
| 355 } | 357 } |
| 356 } | 358 } |
| 357 } | 359 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 // Create destination URL and popup entry content by substituting user input | 415 // Create destination URL and popup entry content by substituting user input |
| 414 // into keyword templates. | 416 // into keyword templates. |
| 415 FillInURLAndContents(remaining_input, element, &result); | 417 FillInURLAndContents(remaining_input, element, &result); |
| 416 | 418 |
| 417 if (supports_replacement) | 419 if (supports_replacement) |
| 418 result.template_url = element; | 420 result.template_url = element; |
| 419 result.transition = PageTransition::KEYWORD; | 421 result.transition = PageTransition::KEYWORD; |
| 420 | 422 |
| 421 // Create popup entry description based on the keyword name. | 423 // Create popup entry description based on the keyword name. |
| 422 if (!element->IsExtensionKeyword()) { | 424 if (!element->IsExtensionKeyword()) { |
| 423 result.description.assign(l10n_util::GetStringF( | 425 result.description.assign(UTF16ToWideHack(l10n_util::GetStringFUTF16( |
| 424 IDS_AUTOCOMPLETE_KEYWORD_DESCRIPTION, keyword)); | 426 IDS_AUTOCOMPLETE_KEYWORD_DESCRIPTION, WideToUTF16Hack(keyword)))); |
| 425 static const std::wstring kKeywordDesc( | 427 string16 keyword_desc( |
| 426 l10n_util::GetString(IDS_AUTOCOMPLETE_KEYWORD_DESCRIPTION)); | 428 l10n_util::GetStringUTF16(IDS_AUTOCOMPLETE_KEYWORD_DESCRIPTION)); |
| 427 AutocompleteMatch::ClassifyLocationInString(kKeywordDesc.find(L"%s"), | 429 AutocompleteMatch::ClassifyLocationInString( |
| 428 prefix_length, | 430 keyword_desc.find(ASCIIToUTF16("%s")), |
| 429 result.description.length(), | 431 prefix_length, |
| 430 ACMatchClassification::DIM, | 432 result.description.length(), |
| 431 &result.description_class); | 433 ACMatchClassification::DIM, |
| 434 &result.description_class); |
| 432 } | 435 } |
| 433 | 436 |
| 434 return result; | 437 return result; |
| 435 } | 438 } |
| 436 | 439 |
| 437 void KeywordProvider::Observe(NotificationType type, | 440 void KeywordProvider::Observe(NotificationType type, |
| 438 const NotificationSource& source, | 441 const NotificationSource& source, |
| 439 const NotificationDetails& details) { | 442 const NotificationDetails& details) { |
| 440 TemplateURLModel* model = profile_ ? profile_->GetTemplateURLModel() : model_; | 443 TemplateURLModel* model = profile_ ? profile_->GetTemplateURLModel() : model_; |
| 441 const AutocompleteInput& input = extension_suggest_last_input_; | 444 const AutocompleteInput& input = extension_suggest_last_input_; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 } | 524 } |
| 522 | 525 |
| 523 void KeywordProvider::MaybeEndExtensionKeywordMode() { | 526 void KeywordProvider::MaybeEndExtensionKeywordMode() { |
| 524 if (!current_keyword_extension_id_.empty()) { | 527 if (!current_keyword_extension_id_.empty()) { |
| 525 ExtensionOmniboxEventRouter::OnInputCancelled( | 528 ExtensionOmniboxEventRouter::OnInputCancelled( |
| 526 profile_, current_keyword_extension_id_); | 529 profile_, current_keyword_extension_id_); |
| 527 | 530 |
| 528 current_keyword_extension_id_.clear(); | 531 current_keyword_extension_id_.clear(); |
| 529 } | 532 } |
| 530 } | 533 } |
| OLD | NEW |