| Index: chrome/browser/autocomplete/keyword_provider.cc
|
| ===================================================================
|
| --- chrome/browser/autocomplete/keyword_provider.cc (revision 72382)
|
| +++ chrome/browser/autocomplete/keyword_provider.cc (working copy)
|
| @@ -41,15 +41,15 @@
|
| };
|
|
|
| // static
|
| -string16 KeywordProvider::SplitReplacementStringFromInput(
|
| - const string16& input,
|
| +std::wstring KeywordProvider::SplitReplacementStringFromInput(
|
| + const std::wstring& input,
|
| bool trim_leading_whitespace) {
|
| // The input may contain leading whitespace, strip it.
|
| - string16 trimmed_input;
|
| + std::wstring trimmed_input;
|
| TrimWhitespace(input, TRIM_LEADING, &trimmed_input);
|
|
|
| // And extract the replacement string.
|
| - string16 remaining_input;
|
| + std::wstring remaining_input;
|
| SplitKeywordFromInput(trimmed_input, trim_leading_whitespace,
|
| &remaining_input);
|
| return remaining_input;
|
| @@ -107,11 +107,11 @@
|
| const TemplateURL* KeywordProvider::GetSubstitutingTemplateURLForInput(
|
| Profile* profile,
|
| const AutocompleteInput& input,
|
| - string16* remaining_input) {
|
| + std::wstring* remaining_input) {
|
| if (!input.allow_exact_keyword_match())
|
| return NULL;
|
|
|
| - string16 keyword;
|
| + std::wstring keyword;
|
| if (!ExtractKeywordFromInput(input, &keyword, remaining_input))
|
| return NULL;
|
|
|
| @@ -121,7 +121,8 @@
|
| DCHECK(model);
|
| model->Load();
|
|
|
| - const TemplateURL* template_url = model->GetTemplateURLForKeyword(keyword);
|
| + const TemplateURL* template_url =
|
| + model->GetTemplateURLForKeyword(WideToUTF16Hack(keyword));
|
| return TemplateURL::SupportsReplacement(template_url) ? template_url : NULL;
|
| }
|
|
|
| @@ -154,7 +155,7 @@
|
| // keywords, we might suggest keywords that haven't even been partially typed,
|
| // if the user uses them enough and isn't obviously typing something else. In
|
| // this case we'd consider all input here to be query input.
|
| - string16 keyword, remaining_input;
|
| + std::wstring keyword, remaining_input;
|
| if (!ExtractKeywordFromInput(input, &keyword, &remaining_input))
|
| return;
|
|
|
| @@ -175,7 +176,7 @@
|
| // search query both from the autocomplete popup and from web pages
|
| // themselves.
|
| std::vector<string16> keyword_matches;
|
| - model->FindMatchingKeywords(keyword,
|
| + model->FindMatchingKeywords(WideToUTF16Hack(keyword),
|
| !remaining_input.empty(),
|
| &keyword_matches);
|
|
|
| @@ -206,8 +207,9 @@
|
| // in the autocomplete popup.
|
| // Any exact match is going to be the highest quality match, and thus at the
|
| // front of our vector.
|
| - if (keyword_matches.front() == keyword) {
|
| - const TemplateURL* template_url(model->GetTemplateURLForKeyword(keyword));
|
| + if (keyword_matches.front() == WideToUTF16Hack(keyword)) {
|
| + const TemplateURL* template_url(
|
| + model->GetTemplateURLForKeyword(WideToUTF16Hack(keyword)));
|
| // TODO(pkasting): We should probably check that if the user explicitly
|
| // typed a scheme, that scheme matches the one in |template_url|.
|
| matches_.push_back(CreateAutocompleteMatch(model, keyword, input,
|
| @@ -223,7 +225,7 @@
|
| keyword_mode_toggle.StayInKeywordMode();
|
|
|
| ApplyDefaultSuggestionForExtensionKeyword(profile_, template_url,
|
| - remaining_input,
|
| + WideToUTF16(remaining_input),
|
| &matches_[0]);
|
|
|
| if (minimal_changes) {
|
| @@ -240,7 +242,7 @@
|
|
|
| bool have_listeners = ExtensionOmniboxEventRouter::OnInputChanged(
|
| profile_, template_url->GetExtensionId(),
|
| - UTF16ToUTF8(remaining_input), current_input_id_);
|
| + WideToUTF8(remaining_input), current_input_id_);
|
|
|
| // We only have to wait for suggest results if there are actually
|
| // extensions listening for input changes.
|
| @@ -255,7 +257,7 @@
|
| }
|
| for (std::vector<string16>::const_iterator i(keyword_matches.begin());
|
| i != keyword_matches.end(); ++i) {
|
| - matches_.push_back(CreateAutocompleteMatch(model, *i,
|
| + matches_.push_back(CreateAutocompleteMatch(model, UTF16ToWideHack(*i),
|
| input, keyword.length(),
|
| remaining_input, -1));
|
| }
|
| @@ -271,33 +273,34 @@
|
|
|
| // static
|
| bool KeywordProvider::ExtractKeywordFromInput(const AutocompleteInput& input,
|
| - string16* keyword,
|
| - string16* remaining_input) {
|
| + std::wstring* keyword,
|
| + std::wstring* remaining_input) {
|
| if ((input.type() == AutocompleteInput::INVALID) ||
|
| (input.type() == AutocompleteInput::FORCED_QUERY))
|
| return false;
|
|
|
| - *keyword = TemplateURLModel::CleanUserInputKeyword(
|
| - SplitKeywordFromInput(input.text(), true, remaining_input));
|
| + *keyword =
|
| + UTF16ToWideHack(TemplateURLModel::CleanUserInputKeyword(WideToUTF16Hack(
|
| + SplitKeywordFromInput(input.text(), true, remaining_input))));
|
| return !keyword->empty();
|
| }
|
|
|
| // static
|
| -string16 KeywordProvider::SplitKeywordFromInput(
|
| - const string16& input,
|
| +std::wstring KeywordProvider::SplitKeywordFromInput(
|
| + const std::wstring& input,
|
| bool trim_leading_whitespace,
|
| - string16* remaining_input) {
|
| + std::wstring* remaining_input) {
|
| // Find end of first token. The AutocompleteController has trimmed leading
|
| // whitespace, so we need not skip over that.
|
| - const size_t first_white(input.find_first_of(kWhitespaceUTF16));
|
| + const size_t first_white(input.find_first_of(kWhitespaceWide));
|
| DCHECK_NE(0U, first_white);
|
| - if (first_white == string16::npos)
|
| + if (first_white == std::wstring::npos)
|
| return input; // Only one token provided.
|
|
|
| // Set |remaining_input| to everything after the first token.
|
| DCHECK(remaining_input != NULL);
|
| const size_t remaining_start = trim_leading_whitespace ?
|
| - input.find_first_not_of(kWhitespaceUTF16, first_white) : first_white + 1;
|
| + input.find_first_not_of(kWhitespaceWide, first_white) : first_white + 1;
|
|
|
| if (remaining_start < input.length())
|
| remaining_input->assign(input.begin() + remaining_start, input.end());
|
| @@ -308,7 +311,7 @@
|
|
|
| // static
|
| void KeywordProvider::FillInURLAndContents(
|
| - const string16& remaining_input,
|
| + const std::wstring& remaining_input,
|
| const TemplateURL* element,
|
| AutocompleteMatch* match) {
|
| DCHECK(!element->short_name().empty());
|
| @@ -323,16 +326,16 @@
|
| if (element->url()->SupportsReplacement() &&
|
| !element->IsExtensionKeyword()) {
|
| // No query input; return a generic, no-destination placeholder.
|
| - match->contents.assign(
|
| + match->contents.assign(UTF16ToWideHack(
|
| l10n_util::GetStringFUTF16(message_id,
|
| element->AdjustedShortNameForLocaleDirection(),
|
| - l10n_util::GetStringUTF16(IDS_EMPTY_KEYWORD_VALUE)));
|
| + l10n_util::GetStringUTF16(IDS_EMPTY_KEYWORD_VALUE))));
|
| match->contents_class.push_back(
|
| ACMatchClassification(0, ACMatchClassification::DIM));
|
| } else {
|
| // Keyword that has no replacement text (aka a shorthand for a URL).
|
| match->destination_url = GURL(element->url()->url());
|
| - match->contents.assign(element->short_name());
|
| + match->contents.assign(UTF16ToWideHack(element->short_name()));
|
| AutocompleteMatch::ClassifyLocationInString(0, match->contents.length(),
|
| match->contents.length(), ACMatchClassification::NONE,
|
| &match->contents_class);
|
| @@ -344,13 +347,14 @@
|
| // fixup to make the URL valid if necessary.
|
| DCHECK(element->url()->SupportsReplacement());
|
| match->destination_url = GURL(element->url()->ReplaceSearchTerms(
|
| - *element, remaining_input,
|
| - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
|
| + *element, WideToUTF16Hack(remaining_input),
|
| + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()));
|
| std::vector<size_t> content_param_offsets;
|
| - match->contents.assign(l10n_util::GetStringFUTF16(message_id,
|
| - element->short_name(),
|
| - remaining_input,
|
| - &content_param_offsets));
|
| + match->contents.assign(UTF16ToWideHack(
|
| + l10n_util::GetStringFUTF16(message_id,
|
| + element->short_name(),
|
| + WideToUTF16Hack(remaining_input),
|
| + &content_param_offsets)));
|
| if (content_param_offsets.size() == 2) {
|
| AutocompleteMatch::ClassifyLocationInString(content_param_offsets[1],
|
| remaining_input.length(), match->contents.length(),
|
| @@ -378,15 +382,15 @@
|
|
|
| AutocompleteMatch KeywordProvider::CreateAutocompleteMatch(
|
| TemplateURLModel* model,
|
| - const string16& keyword,
|
| + const std::wstring& keyword,
|
| const AutocompleteInput& input,
|
| size_t prefix_length,
|
| - const string16& remaining_input,
|
| + const std::wstring& remaining_input,
|
| int relevance) {
|
| DCHECK(model);
|
| // Get keyword data from data store.
|
| const TemplateURL* element(
|
| - model->GetTemplateURLForKeyword(keyword));
|
| + model->GetTemplateURLForKeyword(WideToUTF16Hack(keyword)));
|
| DCHECK(element && element->url());
|
| const bool supports_replacement = element->url()->SupportsReplacement();
|
|
|
| @@ -415,7 +419,7 @@
|
| // to the user's input. Because right now inexact keyword matches can't score
|
| // more highly than a "what you typed" match from one of the other providers,
|
| // we just don't bother to do this, and leave inline autocompletion off.
|
| - result.inline_autocomplete_offset = string16::npos;
|
| + result.inline_autocomplete_offset = std::wstring::npos;
|
|
|
| // Create destination URL and popup entry content by substituting user input
|
| // into keyword templates.
|
| @@ -427,8 +431,8 @@
|
|
|
| // Create popup entry description based on the keyword name.
|
| if (!element->IsExtensionKeyword()) {
|
| - result.description.assign(l10n_util::GetStringFUTF16(
|
| - IDS_AUTOCOMPLETE_KEYWORD_DESCRIPTION, keyword));
|
| + result.description.assign(UTF16ToWideHack(l10n_util::GetStringFUTF16(
|
| + IDS_AUTOCOMPLETE_KEYWORD_DESCRIPTION, WideToUTF16Hack(keyword))));
|
| string16 keyword_desc(
|
| l10n_util::GetStringUTF16(IDS_AUTOCOMPLETE_KEYWORD_DESCRIPTION));
|
| AutocompleteMatch::ClassifyLocationInString(
|
| @@ -458,15 +462,15 @@
|
| case NotificationType::EXTENSION_OMNIBOX_DEFAULT_SUGGESTION_CHANGED: {
|
| // It's possible to change the default suggestion while not in an editing
|
| // session.
|
| - string16 keyword, remaining_input;
|
| + std::wstring keyword, remaining_input;
|
| if (matches_.empty() || current_keyword_extension_id_.empty() ||
|
| !ExtractKeywordFromInput(input, &keyword, &remaining_input))
|
| return;
|
|
|
| const TemplateURL* template_url(
|
| - model->GetTemplateURLForKeyword(keyword));
|
| + model->GetTemplateURLForKeyword(WideToUTF16Hack(keyword)));
|
| ApplyDefaultSuggestionForExtensionKeyword(profile_, template_url,
|
| - remaining_input,
|
| + WideToUTF16(remaining_input),
|
| &matches_[0]);
|
| listener_->OnProviderUpdate(true);
|
| return;
|
| @@ -478,7 +482,7 @@
|
| if (suggestions.request_id != current_input_id_)
|
| return; // This is an old result. Just ignore.
|
|
|
| - string16 keyword, remaining_input;
|
| + std::wstring keyword, remaining_input;
|
| if (!ExtractKeywordFromInput(input, &keyword, &remaining_input)) {
|
| NOTREACHED();
|
| return;
|
| @@ -498,10 +502,10 @@
|
| input.prefer_keyword(), input.allow_exact_keyword_match());
|
| extension_suggest_matches_.push_back(CreateAutocompleteMatch(
|
| model, keyword, input, keyword.length(),
|
| - suggestion.content, first_relevance - (i + 1)));
|
| + UTF16ToWide(suggestion.content), first_relevance - (i + 1)));
|
|
|
| AutocompleteMatch* match = &extension_suggest_matches_.back();
|
| - match->contents.assign(suggestion.description);
|
| + match->contents.assign(UTF16ToWide(suggestion.description));
|
| match->contents_class = suggestion.description_styles;
|
| match->description.clear();
|
| match->description_class.clear();
|
|
|