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