diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-14 22:18:25 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-14 22:18:25 +0000 |
commit | 6235541680600aecf07e7e85a63dc0843f1b7084 (patch) | |
tree | 76304d95b2638e9aa3eebfd5db6b2f2198e4da5d | |
parent | fd4aafc80ad6b4fc7dcbbe36dfec3b7e1bcbd707 (diff) | |
download | chromium_src-6235541680600aecf07e7e85a63dc0843f1b7084.zip chromium_src-6235541680600aecf07e7e85a63dc0843f1b7084.tar.gz chromium_src-6235541680600aecf07e7e85a63dc0843f1b7084.tar.bz2 |
Revert 71485 - Remove wstring from TemplateURL and friends.
BUG=23581
TEST=no visible changes; all tests pass
Review URL: http://codereview.chromium.org/6322001
TBR=avi@chromium.org
Review URL: http://codereview.chromium.org/6291003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71500 0039d316-1c4b-4281-b951-d872f2087c98
68 files changed, 649 insertions, 688 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc index 9b03855..5bf0c21 100644 --- a/chrome/browser/autocomplete/autocomplete_edit.cc +++ b/chrome/browser/autocomplete/autocomplete_edit.cc @@ -400,7 +400,7 @@ void AutocompleteEditModel::OpenURL(const GURL& url, TemplateURLModel* template_url_model = profile_->GetTemplateURLModel(); if (template_url_model && !keyword.empty()) { const TemplateURL* const template_url = - template_url_model->GetTemplateURLForKeyword(WideToUTF16Hack(keyword)); + template_url_model->GetTemplateURLForKeyword(keyword); // Special case for extension keywords. Don't increment usage count for // these. diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc b/chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc index ec5afc21..0b8dfcc 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -224,8 +224,8 @@ class AutocompleteEditViewTest : public InProcessBrowserTest, TemplateURL* template_url = new TemplateURL(); template_url->SetURL(kSearchURL, 0, 0); - template_url->set_keyword(UTF8ToUTF16(kSearchKeyword)); - template_url->set_short_name(UTF8ToUTF16(kSearchShortName)); + template_url->set_keyword(UTF8ToWide(kSearchKeyword)); + template_url->set_short_name(UTF8ToWide(kSearchShortName)); model->Add(template_url); model->SetDefaultSearchProvider(template_url); diff --git a/chrome/browser/autocomplete/autocomplete_popup_model.cc b/chrome/browser/autocomplete/autocomplete_popup_model.cc index beb80c3..8af3572 100644 --- a/chrome/browser/autocomplete/autocomplete_popup_model.cc +++ b/chrome/browser/autocomplete/autocomplete_popup_model.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -9,7 +9,6 @@ #include "unicode/ubidi.h" #include "base/string_util.h" -#include "base/utf_string_conversions.h" #include "chrome/browser/autocomplete/autocomplete_edit.h" #include "chrome/browser/autocomplete/autocomplete_match.h" #include "chrome/browser/autocomplete/autocomplete_popup_view.h" @@ -208,7 +207,7 @@ bool AutocompletePopupModel::GetKeywordForMatch(const AutocompleteMatch& match, // If the current match is a keyword, return that as the selected keyword. if (TemplateURL::SupportsReplacement(match.template_url)) { - keyword->assign(UTF16ToWideHack(match.template_url->keyword())); + keyword->assign(match.template_url->keyword()); return false; } @@ -216,8 +215,8 @@ bool AutocompletePopupModel::GetKeywordForMatch(const AutocompleteMatch& match, if (!profile_->GetTemplateURLModel()) return false; profile_->GetTemplateURLModel()->Load(); - const string16 keyword_hint(TemplateURLModel::CleanUserInputKeyword( - WideToUTF16Hack(match.fill_into_edit))); + const std::wstring keyword_hint( + TemplateURLModel::CleanUserInputKeyword(match.fill_into_edit)); if (keyword_hint.empty()) return false; @@ -237,7 +236,7 @@ bool AutocompletePopupModel::GetKeywordForMatch(const AutocompleteMatch& match, return false; } - keyword->assign(UTF16ToWideHack(keyword_hint)); + keyword->assign(keyword_hint); return true; } diff --git a/chrome/browser/autocomplete/autocomplete_unittest.cc b/chrome/browser/autocomplete/autocomplete_unittest.cc index f40fb4d..fc6c402 100644 --- a/chrome/browser/autocomplete/autocomplete_unittest.cc +++ b/chrome/browser/autocomplete/autocomplete_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -177,8 +177,8 @@ void AutocompleteProviderTest:: // Create another TemplateURL for KeywordProvider. TemplateURL* keyword_t_url = new TemplateURL(); - keyword_t_url->set_short_name(ASCIIToUTF16("k")); - keyword_t_url->set_keyword(ASCIIToUTF16("k")); + keyword_t_url->set_short_name(L"k"); + keyword_t_url->set_keyword(L"k"); keyword_t_url->SetURL("http://keyword/{searchTerms}", 0, 0); profile_.GetTemplateURLModel()->Add(keyword_t_url); ASSERT_NE(0, keyword_t_url->id()); diff --git a/chrome/browser/autocomplete/keyword_provider.cc b/chrome/browser/autocomplete/keyword_provider.cc index 2225456..a1be35a 100644 --- a/chrome/browser/autocomplete/keyword_provider.cc +++ b/chrome/browser/autocomplete/keyword_provider.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -91,8 +91,8 @@ class CompareQuality { // probably better rankings than the fraction of the keyword typed. We should // always put any exact matches first no matter what, since the code in // Start() assumes this (and it makes sense). - bool operator()(const string16& keyword1, - const string16& keyword2) const { + bool operator()(const std::wstring& keyword1, + const std::wstring& keyword2) const { return keyword1.length() < keyword2.length(); } }; @@ -121,8 +121,7 @@ const TemplateURL* KeywordProvider::GetSubstitutingTemplateURLForInput( DCHECK(model); model->Load(); - const TemplateURL* template_url = - model->GetTemplateURLForKeyword(WideToUTF16Hack(keyword)); + const TemplateURL* template_url = model->GetTemplateURLForKeyword(keyword); return TemplateURL::SupportsReplacement(template_url) ? template_url : NULL; } @@ -175,14 +174,13 @@ void KeywordProvider::Start(const AutocompleteInput& input, // TODO(pkasting): http://b/893701 We should remember the user's use of a // search query both from the autocomplete popup and from web pages // themselves. - std::vector<string16> keyword_matches; - model->FindMatchingKeywords(WideToUTF16Hack(keyword), - !remaining_input.empty(), + std::vector<std::wstring> keyword_matches; + model->FindMatchingKeywords(keyword, !remaining_input.empty(), &keyword_matches); // Prune any extension keywords that are disallowed in incognito mode (if // we're incognito), or disabled. - for (std::vector<string16>::iterator i(keyword_matches.begin()); + for (std::vector<std::wstring>::iterator i(keyword_matches.begin()); i != keyword_matches.end(); ) { const TemplateURL* template_url(model->GetTemplateURLForKeyword(*i)); if (profile_ && @@ -207,9 +205,8 @@ void KeywordProvider::Start(const AutocompleteInput& input, // 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() == WideToUTF16Hack(keyword)) { - const TemplateURL* template_url( - model->GetTemplateURLForKeyword(WideToUTF16Hack(keyword))); + if (keyword_matches.front() == keyword) { + const TemplateURL* template_url(model->GetTemplateURLForKeyword(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, @@ -255,10 +252,10 @@ void KeywordProvider::Start(const AutocompleteInput& input, keyword_matches.erase(keyword_matches.begin() + kMaxMatches, keyword_matches.end()); } - for (std::vector<string16>::const_iterator i(keyword_matches.begin()); + for (std::vector<std::wstring>::const_iterator i(keyword_matches.begin()); i != keyword_matches.end(); ++i) { - matches_.push_back(CreateAutocompleteMatch(model, UTF16ToWideHack(*i), - input, keyword.length(), + matches_.push_back(CreateAutocompleteMatch(model, *i, input, + keyword.length(), remaining_input, -1)); } } @@ -279,9 +276,8 @@ bool KeywordProvider::ExtractKeywordFromInput(const AutocompleteInput& input, (input.type() == AutocompleteInput::FORCED_QUERY)) return false; - *keyword = - UTF16ToWideHack(TemplateURLModel::CleanUserInputKeyword(WideToUTF16Hack( - SplitKeywordFromInput(input.text(), true, remaining_input)))); + *keyword = TemplateURLModel::CleanUserInputKeyword( + SplitKeywordFromInput(input.text(), true, remaining_input)); return !keyword->empty(); } @@ -328,14 +324,14 @@ void KeywordProvider::FillInURLAndContents( // No query input; return a generic, no-destination placeholder. match->contents.assign(UTF16ToWideHack( l10n_util::GetStringFUTF16(message_id, - element->AdjustedShortNameForLocaleDirection(), + WideToUTF16Hack(element->AdjustedShortNameForLocaleDirection()), 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(UTF16ToWideHack(element->short_name())); + match->contents.assign(element->short_name()); AutocompleteMatch::ClassifyLocationInString(0, match->contents.length(), match->contents.length(), ACMatchClassification::NONE, &match->contents_class); @@ -347,12 +343,12 @@ void KeywordProvider::FillInURLAndContents( // fixup to make the URL valid if necessary. DCHECK(element->url()->SupportsReplacement()); match->destination_url = GURL(element->url()->ReplaceSearchTerms( - *element, WideToUTF16Hack(remaining_input), - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); + *element, remaining_input, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, + std::wstring())); std::vector<size_t> content_param_offsets; match->contents.assign(UTF16ToWideHack( l10n_util::GetStringFUTF16(message_id, - element->short_name(), + WideToUTF16Hack(element->short_name()), WideToUTF16Hack(remaining_input), &content_param_offsets))); if (content_param_offsets.size() == 2) { @@ -389,8 +385,7 @@ AutocompleteMatch KeywordProvider::CreateAutocompleteMatch( int relevance) { DCHECK(model); // Get keyword data from data store. - const TemplateURL* element( - model->GetTemplateURLForKeyword(WideToUTF16Hack(keyword))); + const TemplateURL* element(model->GetTemplateURLForKeyword(keyword)); DCHECK(element && element->url()); const bool supports_replacement = element->url()->SupportsReplacement(); @@ -467,8 +462,7 @@ void KeywordProvider::Observe(NotificationType type, !ExtractKeywordFromInput(input, &keyword, &remaining_input)) return; - const TemplateURL* template_url( - model->GetTemplateURLForKeyword(WideToUTF16Hack(keyword))); + const TemplateURL* template_url(model->GetTemplateURLForKeyword(keyword)); ApplyDefaultSuggestionForExtensionKeyword(profile_, template_url, WideToUTF16(remaining_input), &matches_[0]); diff --git a/chrome/browser/autocomplete/keyword_provider_unittest.cc b/chrome/browser/autocomplete/keyword_provider_unittest.cc index 9feee61..165662e 100644 --- a/chrome/browser/autocomplete/keyword_provider_unittest.cc +++ b/chrome/browser/autocomplete/keyword_provider_unittest.cc @@ -1,9 +1,8 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "base/message_loop.h" -#include "base/utf_string_conversions.h" #include "chrome/browser/autocomplete/autocomplete_match.h" #include "chrome/browser/autocomplete/keyword_provider.h" #include "chrome/browser/search_engines/template_url.h" @@ -38,13 +37,13 @@ class KeywordProviderTest : public testing::Test { void KeywordProviderTest::SetUp() { static const TemplateURLModel::Initializer kTestKeywordData[] = { - { "aa", "aa.com?foo=%s", "aa" }, - { "aaaa", "http://aaaa/?aaaa=1&b=%s&c", "aaaa" }, - { "aaaaa", "%s", "aaaaa" }, - { "ab", "bogus URL %s", "ab" }, - { "weasel", "weasel%sweasel", "weasel" }, - { "www", " +%2B?=%sfoo ", "www" }, - { "z", "%s=z", "z" }, + { L"aa", "aa.com?foo=%s", L"aa" }, + { L"aaaa", "http://aaaa/?aaaa=1&b=%s&c", L"aaaa" }, + { L"aaaaa", "%s", L"aaaaa" }, + { L"ab", "bogus URL %s", L"ab" }, + { L"weasel", "weasel%sweasel", L"weasel" }, + { L"www", " +%2B?=%sfoo ", L"www" }, + { L"z", "%s=z", L"z" }, }; model_.reset(new TemplateURLModel(kTestKeywordData, @@ -185,17 +184,17 @@ TEST_F(KeywordProviderTest, Description) { TEST_F(KeywordProviderTest, AddKeyword) { TemplateURL* template_url = new TemplateURL(); - string16 keyword(ASCIIToUTF16("foo")); + std::wstring keyword(L"foo"); std::string url("http://www.google.com/foo?q={searchTerms}"); template_url->SetURL(url, 0, 0); template_url->set_keyword(keyword); - template_url->set_short_name(ASCIIToUTF16("Test")); + template_url->set_short_name(L"Test"); model_->Add(template_url); ASSERT_TRUE(template_url == model_->GetTemplateURLForKeyword(keyword)); } TEST_F(KeywordProviderTest, RemoveKeyword) { - string16 url(ASCIIToUTF16("http://aaaa/?aaaa=1&b={searchTerms}&c")); - model_->Remove(model_->GetTemplateURLForKeyword(ASCIIToUTF16("aaaa"))); - ASSERT_TRUE(model_->GetTemplateURLForKeyword(ASCIIToUTF16("aaaa")) == NULL); + std::wstring url(L"http://aaaa/?aaaa=1&b={searchTerms}&c"); + model_->Remove(model_->GetTemplateURLForKeyword(L"aaaa")); + ASSERT_TRUE(model_->GetTemplateURLForKeyword(L"aaaa") == NULL); } diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc index fa162d3..2b308a3 100644 --- a/chrome/browser/autocomplete/search_provider.cc +++ b/chrome/browser/autocomplete/search_provider.cc @@ -417,8 +417,8 @@ URLFetcher* SearchProvider::CreateSuggestFetcher(int id, DCHECK(suggestions_url->SupportsReplacement()); URLFetcher* fetcher = URLFetcher::Create(id, GURL(suggestions_url->ReplaceSearchTerms( - provider, WideToUTF16Hack(text), - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())), + provider, text, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, + std::wstring())), URLFetcher::GET, this); fetcher->set_request_context(profile_->GetRequestContext()); fetcher->Start(); @@ -778,8 +778,7 @@ void SearchProvider::AddMatchToMap(const std::wstring& query_string, ++search_start; } if (is_keyword) { - match.fill_into_edit.append(UTF16ToWideHack( - providers_.keyword_provider().keyword() + char16(' '))); + match.fill_into_edit.append(providers_.keyword_provider().keyword() + L" "); match.template_url = &providers_.keyword_provider(); } match.fill_into_edit.append(query_string); @@ -793,9 +792,9 @@ void SearchProvider::AddMatchToMap(const std::wstring& query_string, DCHECK(search_url->SupportsReplacement()); match.destination_url = GURL(search_url->ReplaceSearchTerms(provider, - WideToUTF16Hack(query_string), + query_string, accepted_suggestion, - WideToUTF16Hack(input_text))); + input_text)); // Search results don't look like URLs. match.transition = @@ -873,8 +872,8 @@ void SearchProvider::UpdateFirstSearchMatchDescription() { match.description.assign( UTF16ToWideHack(l10n_util::GetStringFUTF16( IDS_AUTOCOMPLETE_SEARCH_DESCRIPTION, - providers_.default_provider(). - AdjustedShortNameForLocaleDirection()))); + WideToUTF16Hack(providers_.default_provider(). + AdjustedShortNameForLocaleDirection())))); match.description_class.push_back( ACMatchClassification(0, ACMatchClassification::DIM)); // Only the first search match gets a description. diff --git a/chrome/browser/autocomplete/search_provider_unittest.cc b/chrome/browser/autocomplete/search_provider_unittest.cc index 0e7ac57..bf74e5f 100644 --- a/chrome/browser/autocomplete/search_provider_unittest.cc +++ b/chrome/browser/autocomplete/search_provider_unittest.cc @@ -116,7 +116,7 @@ void SearchProviderTest::SetUp() { HistoryService* history = profile_.GetHistoryService(Profile::EXPLICIT_ACCESS); term1_url_ = GURL(default_t_url_->url()->ReplaceSearchTerms( - *default_t_url_, term1_, 0, string16())); + *default_t_url_, UTF16ToWide(term1_), 0, std::wstring())); history->AddPageWithDetails(term1_url_, string16(), 1, 1, base::Time::Now(), false, history::SOURCE_BROWSED); @@ -125,7 +125,7 @@ void SearchProviderTest::SetUp() { // Create another TemplateURL. keyword_t_url_ = new TemplateURL(); - keyword_t_url_->set_keyword(ASCIIToUTF16("k")); + keyword_t_url_->set_keyword(L"k"); keyword_t_url_->SetURL("http://keyword/{searchTerms}", 0, 0); keyword_t_url_->SetSuggestionsURL("http://suggest_keyword/{searchTerms}", 0, 0); @@ -134,7 +134,7 @@ void SearchProviderTest::SetUp() { // Add a page and search term for keyword_t_url_. keyword_url_ = GURL(keyword_t_url_->url()->ReplaceSearchTerms( - *keyword_t_url_, keyword_term_, 0, string16())); + *keyword_t_url_, UTF16ToWide(keyword_term_), 0, std::wstring())); history->AddPageWithDetails(keyword_url_, string16(), 1, 1, base::Time::Now(), false, history::SOURCE_BROWSED); @@ -227,7 +227,8 @@ TEST_F(SearchProviderTest, QueryDefaultProvider) { // And the URL matches what we expected. GURL expected_url = GURL(default_t_url_->suggestions_url()-> - ReplaceSearchTerms(*default_t_url_, term, 0, string16())); + ReplaceSearchTerms(*default_t_url_, UTF16ToWide(term), + 0, std::wstring())); ASSERT_TRUE(fetcher->original_url() == expected_url); // Tell the SearchProvider the suggest query is done. @@ -247,7 +248,7 @@ TEST_F(SearchProviderTest, QueryDefaultProvider) { EXPECT_FALSE(term1_match.description.empty()); GURL what_you_typed_url = GURL(default_t_url_->url()->ReplaceSearchTerms( - *default_t_url_, term, 0, string16())); + *default_t_url_, UTF16ToWide(term), 0, std::wstring())); AutocompleteMatch what_you_typed_match = FindMatchWithDestination(what_you_typed_url); EXPECT_TRUE(!what_you_typed_match.destination_url.is_empty()); @@ -270,7 +271,7 @@ TEST_F(SearchProviderTest, HonorPreventInlineAutocomplete) { // is queried as well as URLFetchers getting created. TEST_F(SearchProviderTest, QueryKeywordProvider) { string16 term = keyword_term_.substr(0, keyword_term_.size() - 1); - QueryForInput(keyword_t_url_->keyword() + + QueryForInput(WideToUTF16(keyword_t_url_->keyword()) + UTF8ToUTF16(" ") + term, false); // Make sure the default providers suggest service was queried. @@ -291,7 +292,8 @@ TEST_F(SearchProviderTest, QueryKeywordProvider) { // And the URL matches what we expected. GURL expected_url = GURL(keyword_t_url_->suggestions_url()-> - ReplaceSearchTerms(*keyword_t_url_, term, 0, string16())); + ReplaceSearchTerms(*keyword_t_url_, UTF16ToWide(term), 0, + std::wstring())); ASSERT_TRUE(keyword_fetcher->original_url() == expected_url); // Tell the SearchProvider the keyword suggest query is done. @@ -312,8 +314,7 @@ TEST_F(SearchProviderTest, QueryKeywordProvider) { EXPECT_TRUE(match.template_url); // The fill into edit should contain the keyword. - EXPECT_EQ(UTF16ToWideHack(keyword_t_url_->keyword()) + - L" " + UTF16ToWide(keyword_term_), + EXPECT_EQ(keyword_t_url_->keyword() + L" " + UTF16ToWide(keyword_term_), match.fill_into_edit); } @@ -369,7 +370,7 @@ TEST_F(SearchProviderTest, FinalizeInstantQuery) { // 'foobar'. EXPECT_EQ(2u, provider_->matches().size()); GURL instant_url = GURL(default_t_url_->url()->ReplaceSearchTerms( - *default_t_url_, ASCIIToUTF16("foobar"), 0, string16())); + *default_t_url_, L"foobar", 0, std::wstring())); AutocompleteMatch instant_match = FindMatchWithDestination(instant_url); EXPECT_TRUE(!instant_match.destination_url.is_empty()); @@ -378,7 +379,7 @@ TEST_F(SearchProviderTest, FinalizeInstantQuery) { // Make sure the what you typed match has no description. GURL what_you_typed_url = GURL(default_t_url_->url()->ReplaceSearchTerms( - *default_t_url_, ASCIIToUTF16("foo"), 0, string16())); + *default_t_url_, L"foo", 0, std::wstring())); AutocompleteMatch what_you_typed_match = FindMatchWithDestination(what_you_typed_url); EXPECT_TRUE(!what_you_typed_match.destination_url.is_empty()); @@ -403,7 +404,7 @@ TEST_F(SearchProviderTest, RememberInstantQuery) { // 'foobar'. EXPECT_EQ(2u, provider_->matches().size()); GURL instant_url = GURL(default_t_url_->url()->ReplaceSearchTerms( - *default_t_url_, ASCIIToUTF16("foobar"), 0, string16())); + *default_t_url_, L"foobar", 0, std::wstring())); AutocompleteMatch instant_match = FindMatchWithDestination(instant_url); EXPECT_FALSE(instant_match.destination_url.is_empty()); diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index 1cd9079..9012d3c 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -2687,9 +2687,9 @@ void TestingAutomationProvider::GetSearchEngineInfo( for (std::vector<const TemplateURL*>::const_iterator it = template_urls.begin(); it != template_urls.end(); ++it) { DictionaryValue* search_engine = new DictionaryValue; - search_engine->SetString("short_name", UTF16ToUTF8((*it)->short_name())); - search_engine->SetString("description", UTF16ToUTF8((*it)->description())); - search_engine->SetString("keyword", UTF16ToUTF8((*it)->keyword())); + search_engine->SetString("short_name", WideToUTF8((*it)->short_name())); + search_engine->SetString("description", WideToUTF8((*it)->description())); + search_engine->SetString("keyword", WideToUTF8((*it)->keyword())); search_engine->SetBoolean("in_default_list", (*it)->ShowInDefaultList()); search_engine->SetBoolean("is_default", (*it) == url_model->GetDefaultSearchProvider()); @@ -2700,7 +2700,7 @@ void TestingAutomationProvider::GetSearchEngineInfo( search_engine->SetString("host", (*it)->url()->GetHost()); search_engine->SetString("path", (*it)->url()->GetPath()); search_engine->SetString("display_url", - UTF16ToUTF8((*it)->url()->DisplayURL())); + WideToUTF8((*it)->url()->DisplayURL())); search_engines->Append(search_engine); } return_value->Set("search_engines", search_engines); @@ -2726,11 +2726,11 @@ void TestingAutomationProvider::AddOrEditSearchEngine( return; } std::string new_ref_url = TemplateURLRef::DisplayURLToURLRef( - UTF8ToUTF16(new_url)); + UTF8ToWide(new_url)); scoped_ptr<KeywordEditorController> controller( new KeywordEditorController(profile_)); if (args->GetString("keyword", &keyword)) { - template_url = url_model->GetTemplateURLForKeyword(UTF8ToUTF16(keyword)); + template_url = url_model->GetTemplateURLForKeyword(UTF8ToWide(keyword)); if (template_url == NULL) { AutomationJSONReply(this, reply_message).SendError( StringPrintf("No match for keyword: %s", keyword.c_str())); @@ -2763,7 +2763,7 @@ void TestingAutomationProvider::PerformActionOnSearchEngine( return; } const TemplateURL* template_url( - url_model->GetTemplateURLForKeyword(UTF8ToUTF16(keyword))); + url_model->GetTemplateURLForKeyword(UTF8ToWide(keyword))); if (template_url == NULL) { AutomationJSONReply(this, reply_message).SendError( StringPrintf("No match for keyword: %s", keyword.c_str())); diff --git a/chrome/browser/dom_ui/options/browser_options_handler.cc b/chrome/browser/dom_ui/options/browser_options_handler.cc index 1f227ff..e83b408 100644 --- a/chrome/browser/dom_ui/options/browser_options_handler.cc +++ b/chrome/browser/dom_ui/options/browser_options_handler.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -229,7 +229,7 @@ void BrowserOptionsHandler::OnTemplateURLModelChanged() { continue; DictionaryValue* entry = new DictionaryValue(); - entry->SetString("name", model_urls[i]->short_name()); + entry->SetString("name", WideToUTF16Hack(model_urls[i]->short_name())); entry->SetInteger("index", i); search_engines.Append(entry); if (model_urls[i] == default_url) diff --git a/chrome/browser/dom_ui/options/search_engine_manager_handler.cc b/chrome/browser/dom_ui/options/search_engine_manager_handler.cc index de4856c..5291c37 100644 --- a/chrome/browser/dom_ui/options/search_engine_manager_handler.cc +++ b/chrome/browser/dom_ui/options/search_engine_manager_handler.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -158,7 +158,7 @@ DictionaryValue* SearchEngineManagerHandler::CreateDictionaryForEngine( dict->SetString("keyword", table_model->GetText( index, IDS_SEARCH_ENGINES_EDITOR_KEYWORD_COLUMN)); const TemplateURL* template_url = list_controller_->GetTemplateURL(index); - dict->SetString("url", template_url->url()->DisplayURL()); + dict->SetString("url", WideToUTF16Hack(template_url->url()->DisplayURL())); dict->SetBoolean("urlLocked", template_url->prepopulate_id() > 0); GURL icon_url = template_url->GetFavIconURL(); if (icon_url.is_valid()) diff --git a/chrome/browser/extensions/extension_omnibox_apitest.cc b/chrome/browser/extensions/extension_omnibox_apitest.cc index f2a4ce2..7778a8c 100644 --- a/chrome/browser/extensions/extension_omnibox_apitest.cc +++ b/chrome/browser/extensions/extension_omnibox_apitest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -108,7 +108,7 @@ IN_PROC_BROWSER_TEST_F(OmniboxApiTest, MAYBE_Basic) { match = result.match_at(1); ASSERT_TRUE(match.template_url); EXPECT_TRUE(match.template_url->IsExtensionKeyword()); - EXPECT_EQ(ASCIIToUTF16("keyword"), match.template_url->keyword()); + EXPECT_EQ(L"keyword", match.template_url->keyword()); } // Test that our extension can send suggestions back to us. diff --git a/chrome/browser/importer/firefox2_importer.cc b/chrome/browser/importer/firefox2_importer.cc index 59f9ff2..7783a7c 100644 --- a/chrome/browser/importer/firefox2_importer.cc +++ b/chrome/browser/importer/firefox2_importer.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -140,9 +140,9 @@ TemplateURL* Firefox2Importer::CreateTemplateURL(const std::wstring& title, TemplateURL* t_url = new TemplateURL(); // We set short name by using the title if it exists. // Otherwise, we use the shortcut. - t_url->set_short_name(WideToUTF16Hack(!title.empty() ? title : keyword)); - t_url->set_keyword(WideToUTF16Hack(keyword)); - t_url->SetURL(TemplateURLRef::DisplayURLToURLRef(UTF8ToUTF16(url.spec())), + t_url->set_short_name(!title.empty() ? title : keyword); + t_url->set_keyword(keyword); + t_url->SetURL(TemplateURLRef::DisplayURLToURLRef(UTF8ToWide(url.spec())), 0, 0); return t_url; } diff --git a/chrome/browser/importer/firefox_importer_utils.cc b/chrome/browser/importer/firefox_importer_utils.cc index 3ff88f2..be606ff 100644 --- a/chrome/browser/importer/firefox_importer_utils.cc +++ b/chrome/browser/importer/firefox_importer_utils.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -312,7 +312,7 @@ int GetFirefoxDefaultSearchEngineIndex( int default_se_index = -1; for (std::vector<TemplateURL*>::const_iterator iter = search_engines.begin(); iter != search_engines.end(); ++iter) { - if (default_se_name == UTF16ToUTF8((*iter)->short_name())) { + if (default_se_name == WideToUTF8((*iter)->short_name())) { default_se_index = static_cast<int>(iter - search_engines.begin()); break; } diff --git a/chrome/browser/importer/importer_messages.h b/chrome/browser/importer/importer_messages.h index ac63526..e05aac8 100644 --- a/chrome/browser/importer/importer_messages.h +++ b/chrome/browser/importer/importer_messages.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -222,7 +222,7 @@ struct ParamTraits<TemplateURL::ImageRef> { WriteParam(m, p.url); } static bool Read(const Message* m, void** iter, param_type* p) { - std::string type; + std::wstring type; int width; int height; GURL url; @@ -275,17 +275,17 @@ struct ParamTraits<TemplateURL> { WriteParam(m, p.prepopulate_id()); } static bool Read(const Message* m, void** iter, param_type* p) { - string16 short_name; - string16 description; + std::wstring short_name; + std::wstring description; bool includes_suggestions_url; TemplateURLRef suggestions_url; TemplateURLRef url; GURL originating_url; - string16 keyword; + std::wstring keyword; bool autogenerate_keyword; bool show_in_default_list; bool safe_for_autoreplace; - std::vector<string16> languages; + std::vector<std::wstring> languages; std::vector<std::string> input_encodings; base::Time date_created; int usage_count; @@ -314,7 +314,7 @@ struct ParamTraits<TemplateURL> { *p = TemplateURL(); for (size_t i = 0; i < image_refs_size; ++i) { - std::string type; + std::wstring type; int width; int height; GURL url; @@ -344,7 +344,7 @@ struct ParamTraits<TemplateURL> { p->set_show_in_default_list(show_in_default_list); p->set_safe_for_autoreplace(safe_for_autoreplace); - std::vector<string16>::const_iterator lang_iter; + std::vector<std::wstring>::const_iterator lang_iter; for (lang_iter = languages.begin(); lang_iter != languages.end(); ++lang_iter) { diff --git a/chrome/browser/importer/importer_unittest.cc b/chrome/browser/importer/importer_unittest.cc index 2117619..595a3d7 100644 --- a/chrome/browser/importer/importer_unittest.cc +++ b/chrome/browser/importer/importer_unittest.cc @@ -637,10 +637,9 @@ class FirefoxObserver : public ProfileWriter, // The order might not be deterministic, look in the expected list for // that template URL. bool found = false; - string16 keyword = template_urls[i]->keyword(); + std::wstring keyword = template_urls[i]->keyword(); for (size_t j = 0; j < arraysize(kFirefox2Keywords); ++j) { - if (template_urls[i]->keyword() == - WideToUTF16Hack(kFirefox2Keywords[j].keyword)) { + if (template_urls[i]->keyword() == kFirefox2Keywords[j].keyword) { EXPECT_EQ(kFirefox2Keywords[j].url, template_urls[i]->url()->url()); found = true; break; @@ -653,7 +652,7 @@ class FirefoxObserver : public ProfileWriter, if (default_keyword_index != -1) { EXPECT_LT(default_keyword_index, static_cast<int>(template_urls.size())); TemplateURL* default_turl = template_urls[default_keyword_index]; - default_keyword_ = UTF16ToWideHack(default_turl->keyword()); + default_keyword_ = default_turl->keyword(); default_keyword_url_ = default_turl->url()->url(); } @@ -845,10 +844,9 @@ class Firefox3Observer : public ProfileWriter, // The order might not be deterministic, look in the expected list for // that template URL. bool found = false; - string16 keyword = template_urls[i]->keyword(); + std::wstring keyword = template_urls[i]->keyword(); for (size_t j = 0; j < arraysize(kFirefox3Keywords); ++j) { - if (template_urls[i]->keyword() == - WideToUTF16Hack(kFirefox3Keywords[j].keyword)) { + if (template_urls[i]->keyword() == kFirefox3Keywords[j].keyword) { EXPECT_EQ(kFirefox3Keywords[j].url, template_urls[i]->url()->url()); found = true; break; @@ -861,7 +859,7 @@ class Firefox3Observer : public ProfileWriter, if (default_keyword_index != -1) { EXPECT_LT(default_keyword_index, static_cast<int>(template_urls.size())); TemplateURL* default_turl = template_urls[default_keyword_index]; - default_keyword_ = UTF16ToWideHack(default_turl->keyword()); + default_keyword_ = default_turl->keyword(); default_keyword_url_ = default_turl->url()->url(); } diff --git a/chrome/browser/importer/profile_writer.cc b/chrome/browser/importer/profile_writer.cc index e6eefdf..00e8dcf 100644 --- a/chrome/browser/importer/profile_writer.cc +++ b/chrome/browser/importer/profile_writer.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -181,8 +181,8 @@ static std::string BuildHostPathKey(const TemplateURL* t_url, if (t_url->url()->SupportsReplacement()) { return HostPathKeyForURL(GURL( t_url->url()->ReplaceSearchTerms( - *t_url, ASCIIToUTF16("random string"), - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()))); + *t_url, L"random string", + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()))); } } return std::string(); diff --git a/chrome/browser/instant/instant_browsertest.cc b/chrome/browser/instant/instant_browsertest.cc index 0e32467..2409068 100644 --- a/chrome/browser/instant/instant_browsertest.cc +++ b/chrome/browser/instant/instant_browsertest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -58,8 +58,8 @@ class InstantTest : public InProcessBrowserTest { page.c_str()); template_url->SetURL(url, 0, 0); template_url->SetInstantURL(url, 0, 0); - template_url->set_keyword(ASCIIToUTF16("foo")); - template_url->set_short_name(ASCIIToUTF16("foo")); + template_url->set_keyword(UTF8ToWide("foo")); + template_url->set_short_name(UTF8ToWide("foo")); model->Add(template_url); model->SetDefaultSearchProvider(template_url); diff --git a/chrome/browser/instant/instant_loader.cc b/chrome/browser/instant/instant_loader.cc index bc472ea..9f73025 100644 --- a/chrome/browser/instant/instant_loader.cc +++ b/chrome/browser/instant/instant_loader.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -504,7 +504,7 @@ void InstantLoader::Update(TabContentsWrapper* tab_contents, // TODO(sky): having to use a replaceable url is a bit of a hack here. GURL instant_url( template_url->instant_url()->ReplaceSearchTerms( - *template_url, string16(), -1, string16())); + *template_url, std::wstring(), -1, std::wstring())); CommandLine* cl = CommandLine::ForCurrentProcess(); if (cl->HasSwitch(switches::kInstantURL)) instant_url = GURL(cl->GetSwitchValueASCII(switches::kInstantURL)); diff --git a/chrome/browser/policy/configuration_policy_pref_store.cc b/chrome/browser/policy/configuration_policy_pref_store.cc index 1ff956c..58b5cac 100644 --- a/chrome/browser/policy/configuration_policy_pref_store.cc +++ b/chrome/browser/policy/configuration_policy_pref_store.cc @@ -424,8 +424,8 @@ class SearchTermsDataForValidation : public SearchTermsData { return "en"; } #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) - virtual string16 GetRlzParameterValue() const { - return string16(); + virtual std::wstring GetRlzParameterValue() const { + return std::wstring(); } #endif private: diff --git a/chrome/browser/search_engines/edit_search_engine_controller.cc b/chrome/browser/search_engines/edit_search_engine_controller.cc index 10c02ef..b2b6a6d 100644 --- a/chrome/browser/search_engines/edit_search_engine_controller.cc +++ b/chrome/browser/search_engines/edit_search_engine_controller.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -51,8 +51,8 @@ bool EditSearchEngineController::IsURLValid( // If the url has a search term, replace it with a random string and make // sure the resulting URL is valid. We don't check the validity of the url // with the search term as that is not necessarily valid. - return GURL(template_ref.ReplaceSearchTerms(TemplateURL(), ASCIIToUTF16("a"), - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())).is_valid(); + return GURL(template_ref.ReplaceSearchTerms(TemplateURL(), L"a", + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())).is_valid(); } bool EditSearchEngineController::IsKeywordValid( @@ -62,7 +62,7 @@ bool EditSearchEngineController::IsKeywordValid( return false; // Do not allow empty keyword. const TemplateURL* turl_with_keyword = profile_->GetTemplateURLModel()->GetTemplateURLForKeyword( - keyword_input_trimmed); + UTF16ToWideHack(keyword_input_trimmed)); return (turl_with_keyword == NULL || turl_with_keyword == template_url_); } @@ -75,7 +75,7 @@ void EditSearchEngineController::AcceptAddOrEdit( const TemplateURL* existing = profile_->GetTemplateURLModel()->GetTemplateURLForKeyword( - keyword_input); + UTF16ToWideHack(keyword_input)); if (existing && (!edit_keyword_delegate_ || existing != template_url_)) { // An entry may have been added with the same keyword string while the @@ -96,8 +96,8 @@ void EditSearchEngineController::AcceptAddOrEdit( // does in a similar situation (updating an existing TemplateURL with // data from a new one). TemplateURL* modifiable_url = const_cast<TemplateURL*>(template_url_); - modifiable_url->set_short_name(title_input); - modifiable_url->set_keyword(keyword_input); + modifiable_url->set_short_name(UTF16ToWideHack(title_input)); + modifiable_url->set_keyword(UTF16ToWideHack(keyword_input)); modifiable_url->SetURL(url_string, 0, 0); // TemplateURLModel takes ownership of template_url_. profile_->GetTemplateURLModel()->Add(modifiable_url); @@ -124,7 +124,7 @@ void EditSearchEngineController::CleanUpCancelledAdd() { std::string EditSearchEngineController::GetFixedUpURL( const std::string& url_input) const { std::string url; - TrimWhitespace(TemplateURLRef::DisplayURLToURLRef(UTF8ToUTF16(url_input)), + TrimWhitespace(TemplateURLRef::DisplayURLToURLRef(UTF8ToWide(url_input)), TRIM_ALL, &url); if (url.empty()) return url; @@ -135,7 +135,7 @@ std::string EditSearchEngineController::GetFixedUpURL( TemplateURL t_url; t_url.SetURL(url, 0, 0); std::string expanded_url = - t_url.url()->ReplaceSearchTerms(t_url, ASCIIToUTF16("x"), 0, string16()); + t_url.url()->ReplaceSearchTerms(t_url, L"x", 0, std::wstring()); url_parse::Parsed parts; std::string scheme( URLFixerUpper::SegmentURL(expanded_url, &parts)); diff --git a/chrome/browser/search_engines/keyword_editor_controller.cc b/chrome/browser/search_engines/keyword_editor_controller.cc index 349d469..b7d2c5e 100644 --- a/chrome/browser/search_engines/keyword_editor_controller.cc +++ b/chrome/browser/search_engines/keyword_editor_controller.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -37,8 +37,8 @@ int KeywordEditorController::AddTemplateURL(const string16& title, profile_); TemplateURL* template_url = new TemplateURL(); - template_url->set_short_name(title); - template_url->set_keyword(keyword); + template_url->set_short_name(UTF16ToWideHack(title)); + template_url->set_keyword(UTF16ToWideHack(keyword)); template_url->SetURL(url, 0, 0); // There's a bug (1090726) in TableView with groups enabled such that newly @@ -64,8 +64,8 @@ void KeywordEditorController::ModifyTemplateURL(const TemplateURL* template_url, } // Don't do anything if the entry didn't change. - if (template_url->short_name() == title && - template_url->keyword() == keyword && + if (template_url->short_name() == UTF16ToWideHack(title) && + template_url->keyword() == UTF16ToWideHack(keyword) && ((url.empty() && !template_url->url()) || (!url.empty() && template_url->url() && template_url->url()->url() == url))) { diff --git a/chrome/browser/search_engines/keyword_editor_controller_unittest.cc b/chrome/browser/search_engines/keyword_editor_controller_unittest.cc index 9ea48ac..e59af22 100644 --- a/chrome/browser/search_engines/keyword_editor_controller_unittest.cc +++ b/chrome/browser/search_engines/keyword_editor_controller_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -137,8 +137,8 @@ TEST_F(KeywordEditorControllerTest, Add) { // Verify the entry is what we added. const TemplateURL* turl = model_->GetTemplateURLs()[0]; - EXPECT_EQ(ASCIIToUTF16("a"), turl->short_name()); - EXPECT_EQ(ASCIIToUTF16("b"), turl->keyword()); + EXPECT_EQ(L"a", turl->short_name()); + EXPECT_EQ(L"b", turl->keyword()); ASSERT_TRUE(turl->url() != NULL); EXPECT_EQ("http://c", turl->url()->url()); } @@ -154,8 +154,8 @@ TEST_F(KeywordEditorControllerTest, Modify) { // Make sure it was updated appropriately. VerifyChangeCount(0, 1, 0, 0); - EXPECT_EQ(ASCIIToUTF16("a1"), turl->short_name()); - EXPECT_EQ(ASCIIToUTF16("b1"), turl->keyword()); + EXPECT_EQ(L"a1", turl->short_name()); + EXPECT_EQ(L"b1", turl->keyword()); ASSERT_TRUE(turl->url() != NULL); EXPECT_EQ("http://c1", turl->url()->url()); } @@ -186,11 +186,9 @@ TEST_F(KeywordEditorControllerTest, CannotSetDefaultWhileManaged) { controller_->AddTemplateURL(kA1, kB1, "http://d{searchTerms}"); ClearChangeCount(); - const TemplateURL* turl1 = - model_->GetTemplateURLForKeyword(ASCIIToUTF16("b")); + const TemplateURL* turl1 = model_->GetTemplateURLForKeyword(L"b"); ASSERT_TRUE(turl1 != NULL); - const TemplateURL* turl2 = - model_->GetTemplateURLForKeyword(ASCIIToUTF16("b1")); + const TemplateURL* turl2 = model_->GetTemplateURLForKeyword(L"b1"); ASSERT_TRUE(turl2 != NULL); EXPECT_TRUE(controller_->CanMakeDefault(turl1)); @@ -210,11 +208,9 @@ TEST_F(KeywordEditorControllerTest, EditManagedDefault) { controller_->AddTemplateURL(kA1, kB1, "http://d{searchTerms}"); ClearChangeCount(); - const TemplateURL* turl1 = - model_->GetTemplateURLForKeyword(ASCIIToUTF16("b")); + const TemplateURL* turl1 = model_->GetTemplateURLForKeyword(L"b"); ASSERT_TRUE(turl1 != NULL); - const TemplateURL* turl2 = - model_->GetTemplateURLForKeyword(ASCIIToUTF16("b1")); + const TemplateURL* turl2 = model_->GetTemplateURLForKeyword(L"b1"); ASSERT_TRUE(turl2 != NULL); EXPECT_TRUE(controller_->CanEdit(turl1)); @@ -245,8 +241,8 @@ TEST_F(KeywordEditorControllerTest, MakeDefaultNoWebData) { // appropriately. TEST_F(KeywordEditorControllerTest, MutateTemplateURLModel) { TemplateURL* turl = new TemplateURL(); - turl->set_keyword(ASCIIToUTF16("a")); - turl->set_short_name(ASCIIToUTF16("b")); + turl->set_keyword(L"a"); + turl->set_short_name(L"b"); model_->Add(turl); // Table model should have updated. diff --git a/chrome/browser/search_engines/search_provider_install_data.cc b/chrome/browser/search_engines/search_provider_install_data.cc index f0ef037..2a32c92 100644 --- a/chrome/browser/search_engines/search_provider_install_data.cc +++ b/chrome/browser/search_engines/search_provider_install_data.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -36,9 +36,9 @@ class IOThreadSearchTermsData : public SearchTermsData { virtual std::string GoogleBaseURLValue() const; virtual std::string GetApplicationLocale() const; #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) - virtual string16 GetRlzParameterValue() const { + virtual std::wstring GetRlzParameterValue() const { // This value doesn't matter for our purposes. - return string16(); + return std::wstring(); } #endif diff --git a/chrome/browser/search_engines/search_provider_install_data_unittest.cc b/chrome/browser/search_engines/search_provider_install_data_unittest.cc index f132032..28bcd47 100644 --- a/chrome/browser/search_engines/search_provider_install_data_unittest.cc +++ b/chrome/browser/search_engines/search_provider_install_data_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -8,7 +8,6 @@ #include "base/message_loop.h" #include "base/ref_counted.h" #include "base/task.h" -#include "base/utf_string_conversions.h" #include "chrome/browser/browser_thread.h" #include "chrome/browser/search_engines/search_provider_install_data.h" #include "chrome/browser/search_engines/template_url.h" @@ -24,11 +23,11 @@ // Create a TemplateURL. The caller owns the returned TemplateURL*. static TemplateURL* CreateTemplateURL(const std::string& url, - const std::string& keyword) { + const std::wstring& keyword) { TemplateURL* t_url = new TemplateURL(); t_url->SetURL(url, 0, 0); - t_url->set_keyword(UTF8ToUTF16(keyword)); - t_url->set_short_name(UTF8ToUTF16(keyword)); + t_url->set_keyword(keyword); + t_url->set_short_name(keyword); return t_url; } @@ -226,7 +225,7 @@ TEST_F(SearchProviderInstallDataTest, GetInstallState) { util_.ChangeModelToLoadState(); std::string host = "www.unittest.com"; TemplateURL* t_url = CreateTemplateURL("http://" + host + "/path", - "unittest"); + L"unittest"); util_.model()->Add(t_url); // Wait for the changes to be saved. @@ -241,7 +240,7 @@ TEST_F(SearchProviderInstallDataTest, GetInstallState) { // Set-up a default and try it all one more time. std::string default_host = "www.mmm.com"; TemplateURL* default_url = CreateTemplateURL("http://" + default_host + "/", - "mmm"); + L"mmm"); util_.model()->Add(default_url); util_.model()->SetDefaultSearchProvider(default_url); test_get_install_state->set_default_search_provider_host(default_host); @@ -254,7 +253,7 @@ TEST_F(SearchProviderInstallDataTest, ManagedDefaultSearch) { util_.ChangeModelToLoadState(); std::string host = "www.unittest.com"; TemplateURL* t_url = CreateTemplateURL("http://" + host + "/path", - "unittest"); + L"unittest"); util_.model()->Add(t_url); // Set a managed preference that establishes a default search provider. @@ -288,10 +287,10 @@ TEST_F(SearchProviderInstallDataTest, GoogleBaseUrlChange) { TemplateURLModelTestUtil::BlockTillIOThreadProcessesRequests(); TemplateURL* t_url = CreateTemplateURL("{google:baseURL}?q={searchTerms}", - "t"); + L"t"); util_.model()->Add(t_url); TemplateURL* default_url = CreateTemplateURL("http://d.com/", - "d"); + L"d"); util_.model()->Add(default_url); util_.model()->SetDefaultSearchProvider(default_url); diff --git a/chrome/browser/search_engines/search_terms_data.cc b/chrome/browser/search_engines/search_terms_data.cc index 7b09df2..7e5b9ff 100644 --- a/chrome/browser/search_engines/search_terms_data.cc +++ b/chrome/browser/search_engines/search_terms_data.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -73,14 +73,14 @@ std::string UIThreadSearchTermsData::GetApplicationLocale() const { } #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) -string16 UIThreadSearchTermsData::GetRlzParameterValue() const { +std::wstring UIThreadSearchTermsData::GetRlzParameterValue() const { DCHECK(!BrowserThread::IsWellKnownThread(BrowserThread::UI) || BrowserThread::CurrentlyOn(BrowserThread::UI)); - string16 rlz_string; + std::wstring rlz_string; // For organic brandcodes do not use rlz at all. Empty brandcode usually // means a chromium install. This is ok. - string16 brand; - // See http://crbug.com/62337 . + std::wstring brand; + // See http://crbug.com/62337. base::ThreadRestrictions::ScopedAllowIO allow_io; if (GoogleUpdateSettings::GetBrand(&brand) && !brand.empty() && !GoogleUpdateSettings::IsOrganic(brand)) diff --git a/chrome/browser/search_engines/search_terms_data.h b/chrome/browser/search_engines/search_terms_data.h index c830ade..41807c3 100644 --- a/chrome/browser/search_engines/search_terms_data.h +++ b/chrome/browser/search_engines/search_terms_data.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -28,7 +28,7 @@ class SearchTermsData { #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) // Returns the value for the Chrome Omnibox rlz. - virtual string16 GetRlzParameterValue() const = 0; + virtual std::wstring GetRlzParameterValue() const = 0; #endif private: @@ -44,7 +44,7 @@ class UIThreadSearchTermsData : public SearchTermsData { virtual std::string GoogleBaseURLValue() const; virtual std::string GetApplicationLocale() const; #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) - virtual string16 GetRlzParameterValue() const; + virtual std::wstring GetRlzParameterValue() const; #endif // Used by tests to set the value for the Google base url. This takes diff --git a/chrome/browser/search_engines/template_url.cc b/chrome/browser/search_engines/template_url.cc index b9cbac8..c1ebf517 100644 --- a/chrome/browser/search_engines/template_url.cc +++ b/chrome/browser/search_engines/template_url.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -262,9 +262,9 @@ void TemplateURLRef::SetGoogleBaseURL(std::string* google_base_url) { std::string TemplateURLRef::ReplaceSearchTerms( const TemplateURL& host, - const string16& terms, + const std::wstring& terms, int accepted_suggestion, - const string16& original_query_for_suggestion) const { + const std::wstring& original_query_for_suggestion) const { UIThreadSearchTermsData search_terms_data; return ReplaceSearchTermsUsingTermsData(host, terms, @@ -275,9 +275,9 @@ std::string TemplateURLRef::ReplaceSearchTerms( std::string TemplateURLRef::ReplaceSearchTermsUsingTermsData( const TemplateURL& host, - const string16& terms, + const std::wstring& terms, int accepted_suggestion, - const string16& original_query_for_suggestion, + const std::wstring& original_query_for_suggestion, const SearchTermsData& search_terms_data) const { ParseIfNecessaryUsingTermsData(search_terms_data); if (!valid_) @@ -292,9 +292,9 @@ std::string TemplateURLRef::ReplaceSearchTermsUsingTermsData( for (Replacements::iterator i = replacements_.begin(); i != replacements_.end(); ++i) { if (i->type == SEARCH_TERMS) { - string16::size_type query_start = parsed_url_.find('?'); - is_in_query = query_start != string16::npos && - (static_cast<string16::size_type>(i->index) > query_start); + std::wstring::size_type query_start = parsed_url_.find('?'); + is_in_query = query_start != std::wstring::npos && + (static_cast<std::wstring::size_type>(i->index) > query_start); break; } } @@ -307,11 +307,11 @@ std::string TemplateURLRef::ReplaceSearchTermsUsingTermsData( // Encode the search terms so that we know the encoding. const std::vector<std::string>& encodings = host.input_encodings(); for (size_t i = 0; i < encodings.size(); ++i) { - if (EscapeQueryParamValue(terms, + if (EscapeQueryParamValue(WideToUTF16Hack(terms), encodings[i].c_str(), true, &encoded_terms)) { if (!original_query_for_suggestion.empty()) { - EscapeQueryParamValue(original_query_for_suggestion, + EscapeQueryParamValue(WideToUTF16Hack(original_query_for_suggestion), encodings[i].c_str(), true, &encoded_original_query); @@ -321,15 +321,17 @@ std::string TemplateURLRef::ReplaceSearchTermsUsingTermsData( } } if (input_encoding.empty()) { - encoded_terms = EscapeQueryParamValueUTF8(terms, true); + encoded_terms = WideToUTF16Hack( + EscapeQueryParamValueUTF8(terms, true)); if (!original_query_for_suggestion.empty()) { encoded_original_query = - EscapeQueryParamValueUTF8(original_query_for_suggestion, true); + WideToUTF16Hack(EscapeQueryParamValueUTF8( + original_query_for_suggestion, true)); } input_encoding = "UTF-8"; } } else { - encoded_terms = UTF8ToUTF16(EscapePath(UTF16ToUTF8(terms))); + encoded_terms = WideToUTF16Hack(UTF8ToWide(EscapePath(WideToUTF8(terms)))); input_encoding = "UTF-8"; } @@ -371,10 +373,10 @@ std::string TemplateURLRef::ReplaceSearchTermsUsingTermsData( // empty string. (If we don't handle this case, we hit a // NOTREACHED below.) #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) - string16 rlz_string = search_terms_data.GetRlzParameterValue(); + std::wstring rlz_string = search_terms_data.GetRlzParameterValue(); if (!rlz_string.empty()) { rlz_string = L"rlz=" + rlz_string + L"&"; - url.insert(i->index, UTF16ToUTF8(rlz_string)); + url.insert(i->index, WideToUTF8(rlz_string)); } #endif break; @@ -382,9 +384,9 @@ std::string TemplateURLRef::ReplaceSearchTermsUsingTermsData( case GOOGLE_UNESCAPED_SEARCH_TERMS: { std::string unescaped_terms; - base::UTF16ToCodepage(terms, input_encoding.c_str(), - base::OnStringConversionError::SKIP, - &unescaped_terms); + base::WideToCodepage(terms, input_encoding.c_str(), + base::OnStringConversionError::SKIP, + &unescaped_terms); url.insert(i->index, std::string(unescaped_terms.begin(), unescaped_terms.end())); break; @@ -429,10 +431,10 @@ bool TemplateURLRef::IsValidUsingTermsData( return valid_; } -string16 TemplateURLRef::DisplayURL() const { +std::wstring TemplateURLRef::DisplayURL() const { ParseIfNecessary(); if (!valid_ || replacements_.empty()) - return UTF8ToUTF16(url_); + return UTF8ToWide(url_); string16 result = UTF8ToUTF16(url_); ReplaceSubstringsAfterOffset(&result, 0, @@ -444,13 +446,13 @@ string16 TemplateURLRef::DisplayURL() const { ASCIIToUTF16(kGoogleUnescapedSearchTermsParameterFull), ASCIIToUTF16(kDisplayUnescapedSearchTerms)); - return result; + return UTF16ToWideHack(result); } // static std::string TemplateURLRef::DisplayURLToURLRef( - const string16& display_url) { - string16 result = display_url; + const std::wstring& display_url) { + string16 result = WideToUTF16Hack(display_url); ReplaceSubstringsAfterOffset(&result, 0, ASCIIToUTF16(kDisplaySearchTerms), ASCIIToUTF16(kSearchTermsParameterFull)); ReplaceSubstringsAfterOffset( @@ -475,29 +477,29 @@ const std::string& TemplateURLRef::GetSearchTermKey() const { return search_term_key_; } -string16 TemplateURLRef::SearchTermToString16(const TemplateURL& host, +std::wstring TemplateURLRef::SearchTermToWide(const TemplateURL& host, const std::string& term) const { const std::vector<std::string>& encodings = host.input_encodings(); - string16 result; + std::wstring result; std::string unescaped = UnescapeURLComponent(term, UnescapeRule::REPLACE_PLUS_WITH_SPACE | UnescapeRule::URL_SPECIAL_CHARS); for (size_t i = 0; i < encodings.size(); ++i) { - if (base::CodepageToUTF16(unescaped, encodings[i].c_str(), - base::OnStringConversionError::FAIL, &result)) + if (base::CodepageToWide(unescaped, encodings[i].c_str(), + base::OnStringConversionError::FAIL, &result)) return result; } // Always fall back on UTF-8 if it works. - if (base::CodepageToUTF16(unescaped, base::kCodepageUTF8, - base::OnStringConversionError::FAIL, &result)) + if (base::CodepageToWide(unescaped, base::kCodepageUTF8, + base::OnStringConversionError::FAIL, &result)) return result; // When nothing worked, just use the escaped text. We have no idea what the // encoding is. We need to substitute spaces for pluses ourselves since we're // not sending it through an unescaper. - result = UTF8ToUTF16(term); + result = UTF8ToWide(term); std::replace(result.begin(), result.end(), '+', ' '); return result; } @@ -575,8 +577,8 @@ TemplateURL::TemplateURL() TemplateURL::~TemplateURL() { } -string16 TemplateURL::AdjustedShortNameForLocaleDirection() const { - string16 bidi_safe_short_name = short_name_; +std::wstring TemplateURL::AdjustedShortNameForLocaleDirection() const { + std::wstring bidi_safe_short_name = short_name_; base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name); return bidi_safe_short_name; } @@ -599,14 +601,14 @@ void TemplateURL::SetInstantURL(const std::string& url, instant_url_.Set(url, index_offset, page_offset); } -void TemplateURL::set_keyword(const string16& keyword) { +void TemplateURL::set_keyword(const std::wstring& keyword) { // Case sensitive keyword matching is confusing. As such, we force all // keywords to be lower case. - keyword_ = l10n_util::ToLower(keyword); + keyword_ = UTF16ToWide(l10n_util::ToLower(WideToUTF16(keyword))); autogenerate_keyword_ = false; } -string16 TemplateURL::keyword() const { +const std::wstring& TemplateURL::keyword() const { EnsureKeyword(); return keyword_; } @@ -627,7 +629,7 @@ bool TemplateURL::ShowInDefaultList() const { void TemplateURL::SetFavIconURL(const GURL& url) { for (std::vector<ImageRef>::iterator i = image_refs_.begin(); i != image_refs_.end(); ++i) { - if (i->type == "image/x-icon" && + if (i->type == L"image/x-icon" && i->width == kFavIconSize && i->height == kFavIconSize) { if (!url.is_valid()) image_refs_.erase(i); @@ -639,15 +641,15 @@ void TemplateURL::SetFavIconURL(const GURL& url) { // Don't have one yet, add it. if (url.is_valid()) { add_image_ref( - TemplateURL::ImageRef("image/x-icon", kFavIconSize, - kFavIconSize, url)); + TemplateURL::ImageRef(L"image/x-icon", kFavIconSize, kFavIconSize, + url)); } } GURL TemplateURL::GetFavIconURL() const { for (std::vector<ImageRef>::const_iterator i = image_refs_.begin(); i != image_refs_.end(); ++i) { - if ((i->type == "image/x-icon" || i->type == "image/vnd.microsoft.icon") + if ((i->type == L"image/x-icon" || i->type == L"image/vnd.microsoft.icon") && i->width == kFavIconSize && i->height == kFavIconSize) { return i->url; } diff --git a/chrome/browser/search_engines/template_url.h b/chrome/browser/search_engines/template_url.h index 44cdeec..ba2a96e 100644 --- a/chrome/browser/search_engines/template_url.h +++ b/chrome/browser/search_engines/template_url.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -72,18 +72,18 @@ class TemplateURLRef { // The TemplateURL is used to determine the input encoding for the term. std::string ReplaceSearchTerms( const TemplateURL& host, - const string16& terms, + const std::wstring& terms, int accepted_suggestion, - const string16& original_query_for_suggestion) const; + const std::wstring& original_query_for_suggestion) const; // Just like ReplaceSearchTerms except that it takes SearchTermsData to supply // the data for some search terms. Most of the time ReplaceSearchTerms should // be called. std::string ReplaceSearchTermsUsingTermsData( const TemplateURL& host, - const string16& terms, + const std::wstring& terms, int accepted_suggestion, - const string16& original_query_for_suggestion, + const std::wstring& original_query_for_suggestion, const SearchTermsData& search_terms_data) const; // Returns the raw URL. None of the parameters will have been replaced. @@ -104,11 +104,11 @@ class TemplateURLRef { // Returns a string representation of this TemplateURLRef suitable for // display. The display format is the same as the format used by Firefox. - string16 DisplayURL() const; + std::wstring DisplayURL() const; // Converts a string as returned by DisplayURL back into a string as // understood by TemplateURLRef. - static std::string DisplayURLToURLRef(const string16& display_url); + static std::string DisplayURLToURLRef(const std::wstring& display_url); // If this TemplateURLRef is valid and contains one search term, this returns // the host/path of the URL, otherwise this returns an empty string. @@ -120,8 +120,8 @@ class TemplateURLRef { const std::string& GetSearchTermKey() const; // Converts the specified term in the encoding of the host TemplateURL to a - // string16. - string16 SearchTermToString16(const TemplateURL& host, + // wide string. + std::wstring SearchTermToWide(const TemplateURL& host, const std::string& term) const; // Returns true if this TemplateURLRef has a replacement term of @@ -259,17 +259,17 @@ class TemplateURL { // If a TemplateURL has no images, the favicon for the generated URL // should be used. struct ImageRef { - ImageRef(const std::string& type, int width, int height) + ImageRef(const std::wstring& type, int width, int height) : type(type), width(width), height(height) { } - ImageRef(const std::string& type, int width, int height, const GURL& url) + ImageRef(const std::wstring& type, int width, int height, const GURL& url) : type(type), width(width), height(height), url(url) { } // Mime type for the image. // ICO image will have the format: image/x-icon or image/vnd.microsoft.icon - std::string type; + std::wstring type; // Size of the image int width; @@ -297,20 +297,20 @@ class TemplateURL { // A short description of the template. This is the name we show to the user // in various places that use keywords. For example, the location bar shows // this when the user selects the keyword. - void set_short_name(const string16& short_name) { + void set_short_name(const std::wstring& short_name) { short_name_ = short_name; } - string16 short_name() const { return short_name_; } + const std::wstring& short_name() const { return short_name_; } // An accessor for the short_name, but adjusted so it can be appropriately // displayed even if it is LTR and the UI is RTL. - string16 AdjustedShortNameForLocaleDirection() const; + std::wstring AdjustedShortNameForLocaleDirection() const; // A description of the template; this may be empty. - void set_description(const string16& description) { + void set_description(const std::wstring& description) { description_ = description; } - string16 description() const { return description_; } + const std::wstring& description() const { return description_; } // URL providing JSON results. This is typically used to provide suggestions // as your type. If NULL, this url does not support suggestions. @@ -350,8 +350,8 @@ class TemplateURL { const GURL& originating_url() const { return originating_url_; } // The shortcut for this template url. May be empty. - void set_keyword(const string16& keyword); - string16 keyword() const; + void set_keyword(const std::wstring& keyword); + const std::wstring& keyword() const; // Whether to autogenerate a keyword from the url() in GetKeyword(). Most // consumers should not need this. @@ -410,10 +410,10 @@ class TemplateURL { GURL GetFavIconURL() const; // Set of languages supported. This may be empty. - void add_language(const string16& language) { + void add_language(const std::wstring& language) { languages_.push_back(language); } - std::vector<string16> languages() const { return languages_; } + const std::vector<std::wstring>& languages() const { return languages_; } // Date this keyword was created. // @@ -487,13 +487,13 @@ class TemplateURL { // Unique identifier, used when archived to the database. void set_id(TemplateURLID id) { id_ = id;} - string16 short_name_; - string16 description_; + std::wstring short_name_; + std::wstring description_; TemplateURLRef suggestions_url_; TemplateURLRef url_; TemplateURLRef instant_url_; GURL originating_url_; - mutable string16 keyword_; + mutable std::wstring keyword_; bool autogenerate_keyword_; // If this is set, |keyword_| holds the cached // generated keyword if available. mutable bool keyword_generated_; // True if the keyword was generated. This @@ -502,7 +502,7 @@ class TemplateURL { bool show_in_default_list_; bool safe_for_autoreplace_; std::vector<ImageRef> image_refs_; - std::vector<string16> languages_; + std::vector<std::wstring> languages_; // List of supported input encodings. std::vector<std::string> input_encodings_; TemplateURLID id_; diff --git a/chrome/browser/search_engines/template_url_fetcher.cc b/chrome/browser/search_engines/template_url_fetcher.cc index a86c5c1..293f59b 100644 --- a/chrome/browser/search_engines/template_url_fetcher.cc +++ b/chrome/browser/search_engines/template_url_fetcher.cc @@ -26,7 +26,7 @@ class TemplateURLFetcher::RequestDelegate : public URLFetcher::Delegate, public: // Takes ownership of |callbacks|. RequestDelegate(TemplateURLFetcher* fetcher, - const string16& keyword, + const std::wstring& keyword, const GURL& osdd_url, const GURL& favicon_url, TemplateURLFetcherCallbacks* callbacks, @@ -48,10 +48,10 @@ class TemplateURLFetcher::RequestDelegate : public URLFetcher::Delegate, const std::string& data); // URL of the OSDD. - GURL url() const { return osdd_url_; } + const GURL& url() const { return osdd_url_; } // Keyword to use. - string16 keyword() const { return keyword_; } + const std::wstring keyword() const { return keyword_; } // The type of search provider being fetched. ProviderType provider_type() const { return provider_type_; } @@ -62,7 +62,7 @@ class TemplateURLFetcher::RequestDelegate : public URLFetcher::Delegate, URLFetcher url_fetcher_; TemplateURLFetcher* fetcher_; scoped_ptr<TemplateURL> template_url_; - string16 keyword_; + std::wstring keyword_; const GURL osdd_url_; const GURL favicon_url_; const ProviderType provider_type_; @@ -76,7 +76,7 @@ class TemplateURLFetcher::RequestDelegate : public URLFetcher::Delegate, TemplateURLFetcher::RequestDelegate::RequestDelegate( TemplateURLFetcher* fetcher, - const string16& keyword, + const std::wstring& keyword, const GURL& osdd_url, const GURL& favicon_url, TemplateURLFetcherCallbacks* callbacks, @@ -160,7 +160,7 @@ void TemplateURLFetcher::RequestDelegate::AddSearchProvider() { // it gives wrong result when OSDD is located on third party site that // has nothing in common with search engine in OSDD. GURL keyword_url(template_url_->url()->url()); - string16 new_keyword = TemplateURLModel::GenerateKeyword( + std::wstring new_keyword = TemplateURLModel::GenerateKeyword( keyword_url, false); if (!new_keyword.empty()) keyword_ = new_keyword; @@ -183,13 +183,13 @@ void TemplateURLFetcher::RequestDelegate::AddSearchProvider() { // provider. The keyword isn't as important in this case. if (provider_type_ == EXPLICIT_DEFAULT_PROVIDER) { // The loop numbers are arbitrary and are simply a strong effort. - string16 new_keyword; + std::wstring new_keyword; for (int i = 0; i < 100; ++i) { // Concatenate a number at end of the keyword and try that. new_keyword = keyword_; // Try the keyword alone the first time if (i > 0) - new_keyword.append(base::IntToString16(i)); + new_keyword.append(UTF16ToWide(base::IntToString16(i))); if (!model->GetTemplateURLForKeyword(new_keyword) || model->CanReplaceKeyword(new_keyword, GURL(template_url_->url()->url()), @@ -268,7 +268,7 @@ TemplateURLFetcher::~TemplateURLFetcher() { } void TemplateURLFetcher::ScheduleDownload( - const string16& keyword, + const std::wstring& keyword, const GURL& osdd_url, const GURL& favicon_url, TemplateURLFetcherCallbacks* callbacks, diff --git a/chrome/browser/search_engines/template_url_fetcher.h b/chrome/browser/search_engines/template_url_fetcher.h index 444f396..b1e15cc 100644 --- a/chrome/browser/search_engines/template_url_fetcher.h +++ b/chrome/browser/search_engines/template_url_fetcher.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -7,7 +7,6 @@ #pragma once #include "base/scoped_vector.h" -#include "base/string16.h" #include "gfx/native_widget_types.h" class GURL; @@ -34,7 +33,7 @@ class TemplateURLFetcher { // If TemplateURLFetcher is not already downloading the OSDD for osdd_url, // it is downloaded. If successful and the result can be parsed, a TemplateURL // is added to the TemplateURLModel. Takes ownership of |callbacks|. - void ScheduleDownload(const string16& keyword, + void ScheduleDownload(const std::wstring& keyword, const GURL& osdd_url, const GURL& favicon_url, TemplateURLFetcherCallbacks* callbacks, diff --git a/chrome/browser/search_engines/template_url_fetcher_unittest.cc b/chrome/browser/search_engines/template_url_fetcher_unittest.cc index ec20c66..737a349 100644 --- a/chrome/browser/search_engines/template_url_fetcher_unittest.cc +++ b/chrome/browser/search_engines/template_url_fetcher_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,7 +6,6 @@ #include "base/message_loop.h" #include "base/path_service.h" #include "base/scoped_ptr.h" -#include "base/utf_string_conversions.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_fetcher.h" #include "chrome/browser/search_engines/template_url_fetcher_callbacks.h" @@ -77,7 +76,7 @@ class TemplateURLFetcherTest : public testing::Test { protected: // Schedules the download of the url. - void StartDownload(const string16& keyword, + void StartDownload(const std::wstring& keyword, const std::string& osdd_file_name, TemplateURLFetcher::ProviderType provider_type, bool check_that_file_exists); @@ -155,7 +154,7 @@ void TemplateURLFetcherTest::ConfirmAddSearchProvider( } void TemplateURLFetcherTest::StartDownload( - const string16& keyword, + const std::wstring& keyword, const std::string& osdd_file_name, TemplateURLFetcher::ProviderType provider_type, bool check_that_file_exists) { @@ -184,7 +183,7 @@ void TemplateURLFetcherTest::WaitForDownloadToFinish() { } TEST_F(TemplateURLFetcherTest, BasicAutodetectedTest) { - string16 keyword(ASCIIToUTF16("test")); + std::wstring keyword(L"test"); test_util_.ChangeModelToLoadState(); ASSERT_FALSE(test_util_.model()->GetTemplateURLForKeyword(keyword)); @@ -204,13 +203,13 @@ TEST_F(TemplateURLFetcherTest, BasicAutodetectedTest) { const TemplateURL* t_url = test_util_.model()->GetTemplateURLForKeyword( keyword); ASSERT_TRUE(t_url); - EXPECT_EQ(ASCIIToUTF16("http://example.com/%s/other_stuff"), - t_url->url()->DisplayURL()); + EXPECT_STREQ(L"http://example.com/%s/other_stuff", + t_url->url()->DisplayURL().c_str()); EXPECT_TRUE(t_url->safe_for_autoreplace()); } TEST_F(TemplateURLFetcherTest, DuplicatesThrownAway) { - string16 keyword(ASCIIToUTF16("test")); + std::wstring keyword(L"test"); test_util_.ChangeModelToLoadState(); ASSERT_FALSE(test_util_.model()->GetTemplateURLForKeyword(keyword)); @@ -225,7 +224,7 @@ TEST_F(TemplateURLFetcherTest, DuplicatesThrownAway) { struct { std::string description; std::string osdd_file_name; - string16 keyword; + std::wstring keyword; TemplateURLFetcher::ProviderType provider_type; } test_cases[] = { { "Duplicate keyword and osdd url with autodetected provider.", @@ -233,8 +232,7 @@ TEST_F(TemplateURLFetcherTest, DuplicatesThrownAway) { { "Duplicate keyword and osdd url with explicit provider.", osdd_file_name, keyword, TemplateURLFetcher::EXPLICIT_PROVIDER }, { "Duplicate osdd url with explicit provider.", - osdd_file_name, keyword + ASCIIToUTF16("1"), - TemplateURLFetcher::EXPLICIT_PROVIDER }, + osdd_file_name, keyword + L"1", TemplateURLFetcher::EXPLICIT_PROVIDER }, { "Duplicate keyword with explicit provider.", osdd_file_name + "1", keyword, TemplateURLFetcher::EXPLICIT_PROVIDER } }; @@ -257,7 +255,7 @@ TEST_F(TemplateURLFetcherTest, DuplicatesThrownAway) { } TEST_F(TemplateURLFetcherTest, BasicExplicitTest) { - string16 keyword(ASCIIToUTF16("test")); + std::wstring keyword(L"test"); test_util_.ChangeModelToLoadState(); ASSERT_FALSE(test_util_.model()->GetTemplateURLForKeyword(keyword)); @@ -275,13 +273,13 @@ TEST_F(TemplateURLFetcherTest, BasicExplicitTest) { ASSERT_EQ(1, callbacks_destroyed_); ASSERT_TRUE(last_callback_template_url_.get()); - EXPECT_EQ(ASCIIToUTF16("http://example.com/%s/other_stuff"), - last_callback_template_url_->url()->DisplayURL()); + EXPECT_STREQ(L"http://example.com/%s/other_stuff", + last_callback_template_url_->url()->DisplayURL().c_str()); EXPECT_FALSE(last_callback_template_url_->safe_for_autoreplace()); } TEST_F(TemplateURLFetcherTest, BasicExplicitDefaultTest) { - string16 keyword(ASCIIToUTF16("test")); + std::wstring keyword(L"test"); test_util_.ChangeModelToLoadState(); ASSERT_FALSE(test_util_.model()->GetTemplateURLForKeyword(keyword)); @@ -299,13 +297,13 @@ TEST_F(TemplateURLFetcherTest, BasicExplicitDefaultTest) { ASSERT_EQ(1, callbacks_destroyed_); ASSERT_TRUE(last_callback_template_url_.get()); - EXPECT_EQ(ASCIIToUTF16("http://example.com/%s/other_stuff"), - last_callback_template_url_->url()->DisplayURL()); + EXPECT_STREQ(L"http://example.com/%s/other_stuff", + last_callback_template_url_->url()->DisplayURL().c_str()); EXPECT_FALSE(last_callback_template_url_->safe_for_autoreplace()); } TEST_F(TemplateURLFetcherTest, AutodetectedBeforeLoadTest) { - string16 keyword(ASCIIToUTF16("test")); + std::wstring keyword(L"test"); ASSERT_FALSE(test_util_.model()->GetTemplateURLForKeyword(keyword)); std::string osdd_file_name("simple_open_search.xml"); @@ -317,7 +315,7 @@ TEST_F(TemplateURLFetcherTest, AutodetectedBeforeLoadTest) { } TEST_F(TemplateURLFetcherTest, ExplicitBeforeLoadTest) { - string16 keyword(ASCIIToUTF16("test")); + std::wstring keyword(L"test"); ASSERT_FALSE(test_util_.model()->GetTemplateURLForKeyword(keyword)); std::string osdd_file_name("simple_open_search.xml"); @@ -329,7 +327,7 @@ TEST_F(TemplateURLFetcherTest, ExplicitBeforeLoadTest) { } TEST_F(TemplateURLFetcherTest, ExplicitDefaultBeforeLoadTest) { - string16 keyword(ASCIIToUTF16("test")); + std::wstring keyword(L"test"); ASSERT_FALSE(test_util_.model()->GetTemplateURLForKeyword(keyword)); std::string osdd_file_name("simple_open_search.xml"); @@ -345,13 +343,13 @@ TEST_F(TemplateURLFetcherTest, ExplicitDefaultBeforeLoadTest) { ASSERT_EQ(1, callbacks_destroyed_); ASSERT_TRUE(last_callback_template_url_.get()); - EXPECT_EQ(ASCIIToUTF16("http://example.com/%s/other_stuff"), - last_callback_template_url_->url()->DisplayURL()); + EXPECT_STREQ(L"http://example.com/%s/other_stuff", + last_callback_template_url_->url()->DisplayURL().c_str()); EXPECT_FALSE(last_callback_template_url_->safe_for_autoreplace()); } TEST_F(TemplateURLFetcherTest, DuplicateKeywordsTest) { - string16 keyword(ASCIIToUTF16("test")); + std::wstring keyword(L"test"); TemplateURL* t_url = new TemplateURL(); t_url->SetURL("http://example.com/", 0, 0); @@ -386,5 +384,5 @@ TEST_F(TemplateURLFetcherTest, DuplicateKeywordsTest) { ASSERT_EQ(0, add_provider_called_); ASSERT_EQ(3, callbacks_destroyed_); ASSERT_TRUE(last_callback_template_url_.get()); - ASSERT_NE(keyword, last_callback_template_url_->keyword()); + ASSERT_STRNE(keyword.c_str(), last_callback_template_url_->keyword().c_str()); } diff --git a/chrome/browser/search_engines/template_url_model.cc b/chrome/browser/search_engines/template_url_model.cc index 5894932..7372262 100644 --- a/chrome/browser/search_engines/template_url_model.cc +++ b/chrome/browser/search_engines/template_url_model.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -46,7 +46,7 @@ static const char kTemplateParameter[] = "%s"; // Term used when generating a search url. Use something obscure so that on // the rare case the term replaces the URL it's unlikely another keyword would // have the same url. -static const char kReplacementTerm[] = "blah.blah.blah.blah.blah"; +static const wchar_t kReplacementTerm[] = L"blah.blah.blah.blah.blah"; // Removes from the vector any template URL that was created because of @@ -129,8 +129,8 @@ TemplateURLModel::~TemplateURLModel() { } // static -string16 TemplateURLModel::GenerateKeyword(const GURL& url, - bool autodetected) { +std::wstring TemplateURLModel::GenerateKeyword(const GURL& url, + bool autodetected) { // Don't autogenerate keywords for referrers that are the result of a form // submission (TODO: right now we approximate this by checking for the URL // having a query, but we should replace this with a call to WebCore to see if @@ -143,43 +143,44 @@ string16 TemplateURLModel::GenerateKeyword(const GURL& url, if (!url.is_valid() || (autodetected && (url.has_query() || !url.SchemeIs(chrome::kHttpScheme) || ((url.path() != "") && (url.path() != "/"))))) - return string16(); + return std::wstring(); // Strip "www." off the front of the keyword; otherwise the keyword won't work // properly. See http://code.google.com/p/chromium/issues/detail?id=6984 . - return net::StripWWW(UTF8ToUTF16(url.host())); + return UTF16ToWideHack(net::StripWWW(UTF8ToUTF16(url.host()))); } // static -string16 TemplateURLModel::CleanUserInputKeyword(const string16& keyword) { +std::wstring TemplateURLModel::CleanUserInputKeyword( + const std::wstring& keyword) { // Remove the scheme. - string16 result(l10n_util::ToLower(keyword)); + std::wstring result(UTF16ToWide(l10n_util::ToLower(WideToUTF16(keyword)))); url_parse::Component scheme_component; - if (url_parse::ExtractScheme(UTF16ToUTF8(keyword).c_str(), + if (url_parse::ExtractScheme(WideToUTF8(keyword).c_str(), static_cast<int>(keyword.length()), &scheme_component)) { // If the scheme isn't "http" or "https", bail. The user isn't trying to // type a web address, but rather an FTP, file:, or other scheme URL, or a // search query with some sort of initial operator (e.g. "site:"). if (result.compare(0, scheme_component.end(), - ASCIIToUTF16(chrome::kHttpScheme)) && + ASCIIToWide(chrome::kHttpScheme)) && result.compare(0, scheme_component.end(), - ASCIIToUTF16(chrome::kHttpsScheme))) - return string16(); + ASCIIToWide(chrome::kHttpsScheme))) + return std::wstring(); // Include trailing ':'. result.erase(0, scheme_component.end() + 1); // Many schemes usually have "//" after them, so strip it too. - const string16 after_scheme(ASCIIToUTF16("//")); + const std::wstring after_scheme(L"//"); if (result.compare(0, after_scheme.length(), after_scheme) == 0) result.erase(0, after_scheme.length()); } // Remove leading "www.". - result = net::StripWWW(result); + result = UTF16ToWideHack(net::StripWWW(WideToUTF16(result))); // Remove trailing "/". - return (result.length() > 0 && result[result.length() - 1] == '/') ? + return (result.length() > 0 && result[result.length() - 1] == L'/') ? result.substr(0, result.length() - 1) : result; } @@ -205,13 +206,12 @@ GURL TemplateURLModel::GenerateSearchURLUsingTermsData( return GURL(search_ref->url()); return GURL(search_ref->ReplaceSearchTermsUsingTermsData( - *t_url, ASCIIToUTF16(kReplacementTerm), - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, - string16(), search_terms_data)); + *t_url, kReplacementTerm, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, + std::wstring(), search_terms_data)); } bool TemplateURLModel::CanReplaceKeyword( - const string16& keyword, + const std::wstring& keyword, const GURL& url, const TemplateURL** template_url_to_replace) { DCHECK(!keyword.empty()); // This should only be called for non-empty @@ -237,9 +237,9 @@ bool TemplateURLModel::CanReplaceKeyword( } void TemplateURLModel::FindMatchingKeywords( - const string16& prefix, + const std::wstring& prefix, bool support_replacement_only, - std::vector<string16>* matches) const { + std::vector<std::wstring>* matches) const { // Sanity check args. if (prefix.empty()) return; @@ -265,7 +265,7 @@ void TemplateURLModel::FindMatchingKeywords( } const TemplateURL* TemplateURLModel::GetTemplateURLForKeyword( - const string16& keyword) const { + const std::wstring& keyword) const { KeywordToTemplateMap::const_iterator elem( keyword_to_template_map_.find(keyword)); return (elem == keyword_to_template_map_.end()) ? NULL : elem->second; @@ -320,10 +320,10 @@ void TemplateURLModel::RegisterExtensionKeyword(const Extension* extension) { } const TemplateURL* existing_url = GetTemplateURLForExtension(extension); - string16 keyword = UTF8ToUTF16(extension->omnibox_keyword()); + std::wstring keyword = UTF8ToWide(extension->omnibox_keyword()); scoped_ptr<TemplateURL> template_url(new TemplateURL); - template_url->set_short_name(UTF8ToUTF16(extension->name())); + template_url->set_short_name(UTF8ToWide(extension->name())); template_url->set_keyword(keyword); // This URL is not actually used for navigation. It holds the extension's // ID, as well as forcing the TemplateURL to be treated as a search keyword. @@ -372,8 +372,8 @@ void TemplateURLModel::IncrementUsageCount(const TemplateURL* url) { } void TemplateURLModel::ResetTemplateURL(const TemplateURL* url, - const string16& title, - const string16& keyword, + const std::wstring& title, + const std::wstring& keyword, const std::string& search_url) { TemplateURL new_url(*url); new_url.set_short_name(title); @@ -538,8 +538,8 @@ void TemplateURLModel::OnWebDataServiceRequestDone( NotifyLoaded(); } -string16 TemplateURLModel::GetKeywordShortName(const string16& keyword, - bool* is_extension_keyword) { +std::wstring TemplateURLModel::GetKeywordShortName(const std::wstring& keyword, + bool* is_extension_keyword) { const TemplateURL* template_url = GetTemplateURLForKeyword(keyword); // TODO(sky): Once LocationBarView adds a listener to the TemplateURLModel @@ -549,7 +549,7 @@ string16 TemplateURLModel::GetKeywordShortName(const string16& keyword, return template_url->AdjustedShortNameForLocaleDirection(); } *is_extension_keyword = false; - return string16(); + return std::wstring(); } void TemplateURLModel::Observe(NotificationType type, @@ -602,12 +602,12 @@ void TemplateURLModel::RegisterUserPrefs(PrefService* prefs) { void TemplateURLModel::SetKeywordSearchTermsForURL(const TemplateURL* t_url, const GURL& url, - const string16& term) { + const std::wstring& term) { HistoryService* history = profile_ ? profile_->GetHistoryService(Profile::EXPLICIT_ACCESS) : NULL; if (!history) return; - history->SetKeywordSearchTermsForURL(url, t_url->id(), term); + history->SetKeywordSearchTermsForURL(url, t_url->id(), WideToUTF16Hack(term)); } void TemplateURLModel::Init(const Initializer* initializers, @@ -640,15 +640,15 @@ void TemplateURLModel::Init(const Initializer* initializers, size_t template_position = std::string(initializers[i].url).find(kTemplateParameter); - DCHECK(template_position != std::string::npos); + DCHECK(template_position != std::wstring::npos); std::string osd_url(initializers[i].url); osd_url.replace(template_position, arraysize(kTemplateParameter) - 1, kSearchTermParameter); // TemplateURLModel ends up owning the TemplateURL, don't try and free it. TemplateURL* template_url = new TemplateURL(); - template_url->set_keyword(UTF8ToUTF16(initializers[i].keyword)); - template_url->set_short_name(UTF8ToUTF16(initializers[i].content)); + template_url->set_keyword(initializers[i].keyword); + template_url->set_short_name(initializers[i].content); template_url->SetURL(osd_url, 0, 0); AddNoNotify(template_url); } @@ -777,8 +777,8 @@ void TemplateURLModel::SaveDefaultSearchProviderToPrefs( if (!icon_gurl.is_empty()) icon_url = icon_gurl.spec(); encodings = JoinString(t_url->input_encodings(), ';'); - short_name = UTF16ToUTF8(t_url->short_name()); - keyword = UTF16ToUTF8(t_url->keyword()); + short_name = WideToUTF8(t_url->short_name()); + keyword = WideToUTF8(t_url->keyword()); id_string = base::Int64ToString(t_url->id()); prepopulate_id = base::Int64ToString(t_url->prepopulate_id()); } @@ -822,10 +822,10 @@ bool TemplateURLModel::LoadDefaultSearchProviderFromPrefs( return true; } - string16 name = - UTF8ToUTF16(prefs->GetString(prefs::kDefaultSearchProviderName)); - string16 keyword = - UTF8ToUTF16(prefs->GetString(prefs::kDefaultSearchProviderKeyword)); + std::wstring name = + UTF8ToWide(prefs->GetString(prefs::kDefaultSearchProviderName)); + std::wstring keyword = + UTF8ToWide(prefs->GetString(prefs::kDefaultSearchProviderKeyword)); std::string icon_url = prefs->GetString(prefs::kDefaultSearchProviderIconURL); std::string encodings = @@ -983,7 +983,7 @@ void TemplateURLModel::UpdateKeywordSearchTermsForURL( if (terms_iterator != query_terms.end() && !terms_iterator->second.empty()) { SetKeywordSearchTermsForURL( - *i, row.url(), search_ref->SearchTermToString16(*(*i), + *i, row.url(), search_ref->SearchTermToWide(*(*i), terms_iterator->second)); } } @@ -1006,8 +1006,7 @@ void TemplateURLModel::AddTabToSearchVisit(const TemplateURL& t_url) { if (!history) return; - GURL url(URLFixerUpper::FixupURL(UTF16ToUTF8(t_url.keyword()), - std::string())); + GURL url(URLFixerUpper::FixupURL(WideToUTF8(t_url.keyword()), std::string())); if (!url.is_valid()) return; diff --git a/chrome/browser/search_engines/template_url_model.h b/chrome/browser/search_engines/template_url_model.h index 504e79f..a16bad7 100644 --- a/chrome/browser/search_engines/template_url_model.h +++ b/chrome/browser/search_engines/template_url_model.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -45,7 +45,7 @@ struct URLVisitedDetails; // // There is a TemplateURLModel per Profile. // -// TemplateURLModel does not load the vector of TemplateURLs in its +// TemplateURLModel does not load the vector of TemplateURLs in it's // constructor (except for testing). Use the Load method to trigger a load. // When TemplateURLModel has completed loading, observers are notified via // OnTemplateURLModelChanged as well as the TEMPLATE_URL_MODEL_LOADED @@ -63,9 +63,9 @@ class TemplateURLModel : public WebDataServiceConsumer, // Struct used for initializing the data store with fake data. // Each initializer is mapped to a TemplateURL. struct Initializer { - const char* const keyword; + const wchar_t* const keyword; const char* const url; - const char* const content; + const wchar_t* const content; }; explicit TemplateURLModel(Profile* profile); @@ -78,11 +78,11 @@ class TemplateURLModel : public WebDataServiceConsumer, // don't generate keywords for a variety of situations where we would probably // not want to auto-add keywords, such as keywords for searches on pages that // themselves come from form submissions. - static string16 GenerateKeyword(const GURL& url, bool autodetected); + static std::wstring GenerateKeyword(const GURL& url, bool autodetected); // Removes any unnecessary characters from a user input keyword. // This removes the leading scheme, "www." and any trailing slash. - static string16 CleanUserInputKeyword(const string16& keyword); + static std::wstring CleanUserInputKeyword(const std::wstring& keyword); // Returns the search url for t_url. Returns an empty GURL if t_url has no // url(). @@ -102,22 +102,23 @@ class TemplateURLModel : public WebDataServiceConsumer, // // url gives the url of the search query. The url is used to avoid generating // a TemplateURL for an existing TemplateURL that shares the same host. - bool CanReplaceKeyword(const string16& keyword, + bool CanReplaceKeyword(const std::wstring& keyword, const GURL& url, const TemplateURL** template_url_to_replace); // Returns (in |matches|) all keywords beginning with |prefix|, sorted // shortest-first. If support_replacement_only is true, only keywords that // support replacement are returned. - void FindMatchingKeywords(const string16& prefix, + void FindMatchingKeywords(const std::wstring& prefix, bool support_replacement_only, - std::vector<string16>* matches) const; + std::vector<std::wstring>* matches) const; // Looks up |keyword| and returns the element it maps to. Returns NULL if // the keyword was not found. // The caller should not try to delete the returned pointer; the data store // retains ownership of it. - const TemplateURL* GetTemplateURLForKeyword(const string16& keyword) const; + const TemplateURL* GetTemplateURLForKeyword( + const std::wstring& keyword) const; // Returns the first TemplateURL found with a URL using the specified |host|, // or NULL if there are no such TemplateURLs @@ -166,8 +167,8 @@ class TemplateURLModel : public WebDataServiceConsumer, // Resets the title, keyword and search url of the specified TemplateURL. // The TemplateURL is marked as not replaceable. void ResetTemplateURL(const TemplateURL* url, - const string16& title, - const string16& keyword, + const std::wstring& title, + const std::wstring& keyword, const std::string& search_url); // Return true if the given |url| can be made the default. @@ -210,8 +211,8 @@ class TemplateURLModel : public WebDataServiceConsumer, // Returns the locale-direction-adjusted short name for the given keyword. // Also sets the out param to indicate whether the keyword belongs to an // extension. - string16 GetKeywordShortName(const string16& keyword, - bool* is_extension_keyword); + std::wstring GetKeywordShortName(const std::wstring& keyword, + bool* is_extension_keyword); // NotificationObserver method. TemplateURLModel listens for three // notification types: @@ -244,7 +245,7 @@ class TemplateURLModel : public WebDataServiceConsumer, // This exists and is virtual for testing. virtual void SetKeywordSearchTermsForURL(const TemplateURL* t_url, const GURL& url, - const string16& term); + const std::wstring& term); private: FRIEND_TEST_ALL_PREFIXES(TemplateURLModelTest, BuildQueryTerms); @@ -257,7 +258,7 @@ class TemplateURLModel : public WebDataServiceConsumer, FRIEND_TEST_ALL_PREFIXES(TemplateURLModelTest, MergeDeletesUnusedProviders); friend class TemplateURLModelTestUtil; - typedef std::map<string16, const TemplateURL*> KeywordToTemplateMap; + typedef std::map<std::wstring, const TemplateURL*> KeywordToTemplateMap; typedef std::vector<const TemplateURL*> TemplateURLVector; // Helper functor for FindMatchingKeywords(), for finding the range of diff --git a/chrome/browser/search_engines/template_url_model_test_util.cc b/chrome/browser/search_engines/template_url_model_test_util.cc index 477999c..7803b12 100644 --- a/chrome/browser/search_engines/template_url_model_test_util.cc +++ b/chrome/browser/search_engines/template_url_model_test_util.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -85,8 +85,8 @@ class TestingTemplateURLModel : public TemplateURLModel { : TemplateURLModel(profile) { } - string16 GetAndClearSearchTerm() { - string16 search_term; + std::wstring GetAndClearSearchTerm() { + std::wstring search_term; search_term.swap(search_term_); return search_term; } @@ -94,12 +94,12 @@ class TestingTemplateURLModel : public TemplateURLModel { protected: virtual void SetKeywordSearchTermsForURL(const TemplateURL* t_url, const GURL& url, - const string16& term) { + const std::wstring& term) { search_term_ = term; } private: - string16 search_term_; + std::wstring search_term_; DISALLOW_COPY_AND_ASSIGN(TestingTemplateURLModel); }; @@ -210,7 +210,7 @@ void TemplateURLModelTestUtil::ResetModel(bool verify_load) { VerifyLoad(); } -string16 TemplateURLModelTestUtil::GetAndClearSearchTerm() { +std::wstring TemplateURLModelTestUtil::GetAndClearSearchTerm() { return static_cast<TestingTemplateURLModel*>(model())->GetAndClearSearchTerm(); } diff --git a/chrome/browser/search_engines/template_url_model_test_util.h b/chrome/browser/search_engines/template_url_model_test_util.h index 18cfb58..058b64b 100644 --- a/chrome/browser/search_engines/template_url_model_test_util.h +++ b/chrome/browser/search_engines/template_url_model_test_util.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -12,7 +12,6 @@ #include "base/message_loop.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" -#include "base/string16.h" #include "chrome/browser/browser_thread.h" #include "chrome/browser/search_engines/template_url_model_observer.h" @@ -71,7 +70,7 @@ class TemplateURLModelTestUtil : public TemplateURLModelObserver { // Returns the search term from the last invocation of // TemplateURLModel::SetKeywordSearchTermsForURL and clears the search term. - string16 GetAndClearSearchTerm(); + std::wstring GetAndClearSearchTerm(); // Set the google base url. void SetGoogleBaseURL(const std::string& base_url) const; diff --git a/chrome/browser/search_engines/template_url_model_unittest.cc b/chrome/browser/search_engines/template_url_model_unittest.cc index ab64c2a..9e5477c 100644 --- a/chrome/browser/search_engines/template_url_model_unittest.cc +++ b/chrome/browser/search_engines/template_url_model_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -8,7 +8,6 @@ #include "base/string_util.h" #include "base/ref_counted.h" #include "base/threading/thread.h" -#include "base/utf_string_conversions.h" #include "chrome/browser/browser_thread.h" #include "chrome/browser/history/history.h" #include "chrome/browser/history/history_notifications.h" @@ -78,8 +77,8 @@ class TestSearchTermsData : public SearchTermsData { #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) // Returns the value for the Chrome Omnibox rlz. - virtual string16 GetRlzParameterValue() const { - return string16(); + virtual std::wstring GetRlzParameterValue() const { + return std::wstring(); } #endif @@ -94,8 +93,8 @@ class TestSearchTermsData : public SearchTermsData { static TemplateURL* CreatePreloadedTemplateURL() { TemplateURL* t_url = new TemplateURL(); t_url->SetURL("http://www.unittest.com/", 0, 0); - t_url->set_keyword(ASCIIToUTF16("unittest")); - t_url->set_short_name(ASCIIToUTF16("unittest")); + t_url->set_keyword(L"unittest"); + t_url->set_short_name(L"unittest"); t_url->set_safe_for_autoreplace(true); GURL favicon_url("http://favicon.url"); t_url->SetFavIconURL(favicon_url); @@ -116,22 +115,22 @@ class TemplateURLModelTest : public testing::Test { test_util_.TearDown(); } - TemplateURL* AddKeywordWithDate(const std::string& keyword, + TemplateURL* AddKeywordWithDate(const std::wstring& keyword, bool autogenerate_keyword, const std::string& url, const std::string& suggest_url, const std::string& fav_icon_url, const std::string& encodings, - const std::string& short_name, + const std::wstring& short_name, bool safe_for_autoreplace, Time created_date) { TemplateURL* template_url = new TemplateURL(); template_url->SetURL(url, 0, 0); template_url->SetSuggestionsURL(suggest_url, 0, 0); template_url->SetFavIconURL(GURL(fav_icon_url)); - template_url->set_keyword(UTF8ToUTF16(keyword)); + template_url->set_keyword(keyword); template_url->set_autogenerate_keyword(autogenerate_keyword); - template_url->set_short_name(UTF8ToUTF16(short_name)); + template_url->set_short_name(short_name); std::vector<std::string> encodings_vector; base::SplitString(encodings, ';', &encodings_vector); template_url->set_input_encodings(encodings_vector); @@ -241,12 +240,12 @@ class TemplateURLModelTest : public testing::Test { prefs::kDefaultSearchProviderPrepopulateID); } - // Creates a TemplateURL with the same prepopulated id as a real prepopulated + // Creates a TemplateURL with the same prepopluated id as a real prepopulated // item. The input number determines which prepopulated item. The caller is // responsible for owning the returned TemplateURL*. TemplateURL* CreateReplaceablePreloadedTemplateURL( size_t index_offset_from_default, - string16* prepopulated_display_url); + std::wstring* prepopulated_display_url); // Verifies the behavior of when a preloaded url later gets changed. // Since the input is the offset from the default, when one passes in @@ -270,7 +269,7 @@ class TemplateURLModelTest : public testing::Test { void VerifyLoad() { test_util_.VerifyLoad(); } void ChangeModelToLoadState() { test_util_.ChangeModelToLoadState(); } void ResetModel(bool verify_load) { test_util_.ResetModel(verify_load); } - string16 GetAndClearSearchTerm() { + std::wstring GetAndClearSearchTerm() { return test_util_.GetAndClearSearchTerm(); } void SetGoogleBaseURL(const std::string& base_url) const { @@ -324,7 +323,7 @@ void TestGenerateSearchURL::RunTest() { TemplateURL* TemplateURLModelTest::CreateReplaceablePreloadedTemplateURL( size_t index_offset_from_default, - string16* prepopulated_display_url) { + std::wstring* prepopulated_display_url) { TemplateURL* t_url = CreatePreloadedTemplateURL(); ScopedVector<TemplateURL> prepopulated_urls; size_t default_search_provider_index = 0; @@ -345,37 +344,39 @@ TemplateURL* TemplateURLModelTest::CreateReplaceablePreloadedTemplateURL( void TemplateURLModelTest::TestLoadUpdatingPreloadedURL( size_t index_offset_from_default) { - string16 prepopulated_url; + std::wstring prepopulated_url; TemplateURL* t_url = CreateReplaceablePreloadedTemplateURL( index_offset_from_default, &prepopulated_url); t_url->set_safe_for_autoreplace(false); - string16 original_url = t_url->url()->DisplayURL(); - ASSERT_NE(prepopulated_url, original_url); + std::wstring original_url = t_url->url()->DisplayURL(); + ASSERT_STRNE(prepopulated_url.c_str(), original_url.c_str()); // Then add it to the model and save it all. ChangeModelToLoadState(); model()->Add(t_url); const TemplateURL* keyword_url = - model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); + model()->GetTemplateURLForKeyword(L"unittest"); ASSERT_EQ(t_url, keyword_url); - ASSERT_EQ(original_url, keyword_url->url()->DisplayURL()); + ASSERT_STREQ(original_url.c_str(), keyword_url->url()->DisplayURL().c_str()); BlockTillServiceProcessesRequests(); // Now reload the model and verify that the merge updates the url. ResetModel(true); - keyword_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); + keyword_url = model()->GetTemplateURLForKeyword(L"unittest"); ASSERT_TRUE(keyword_url != NULL); - ASSERT_EQ(prepopulated_url, keyword_url->url()->DisplayURL()); + ASSERT_STREQ(prepopulated_url.c_str(), + keyword_url->url()->DisplayURL().c_str()); // Wait for any saves to finish. BlockTillServiceProcessesRequests(); // Reload the model to verify that change was saved correctly. ResetModel(true); - keyword_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); + keyword_url = model()->GetTemplateURLForKeyword(L"unittest"); ASSERT_TRUE(keyword_url != NULL); - ASSERT_EQ(prepopulated_url, keyword_url->url()->DisplayURL()); + ASSERT_STREQ(prepopulated_url.c_str(), + keyword_url->url()->DisplayURL().c_str()); } TEST_F(TemplateURLModelTest, MAYBE_Load) { @@ -389,15 +390,14 @@ TEST_F(TemplateURLModelTest, AddUpdateRemove) { TemplateURL* t_url = new TemplateURL(); t_url->SetURL("http://www.google.com/foo/bar", 0, 0); - t_url->set_keyword(ASCIIToUTF16("keyword")); - t_url->set_short_name(ASCIIToUTF16("google")); + t_url->set_keyword(L"keyword"); + t_url->set_short_name(L"google"); GURL favicon_url("http://favicon.url"); t_url->SetFavIconURL(favicon_url); t_url->set_date_created(Time::FromTimeT(100)); t_url->set_safe_for_autoreplace(true); model()->Add(t_url); - ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), - GURL(), NULL)); + ASSERT_TRUE(model()->CanReplaceKeyword(L"keyword", GURL(), NULL)); VerifyObserverCount(1); BlockTillServiceProcessesRequests(); // We need to clone as model takes ownership of TemplateURL and will @@ -410,28 +410,24 @@ TEST_F(TemplateURLModelTest, AddUpdateRemove) { // Reload the model to verify it was actually saved to the database. ResetModel(true); ASSERT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); - const TemplateURL* loaded_url = - model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); + const TemplateURL* loaded_url = model()->GetTemplateURLForKeyword(L"keyword"); ASSERT_TRUE(loaded_url != NULL); AssertEquals(cloned_url, *loaded_url); - ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), - GURL(), NULL)); + ASSERT_TRUE(model()->CanReplaceKeyword(L"keyword", GURL(), NULL)); // Mutate an element and verify it succeeded. - model()->ResetTemplateURL(loaded_url, ASCIIToUTF16("a"), - ASCIIToUTF16("b"), "c"); - ASSERT_EQ(ASCIIToUTF16("a"), loaded_url->short_name()); - ASSERT_EQ(ASCIIToUTF16("b"), loaded_url->keyword()); + model()->ResetTemplateURL(loaded_url, L"a", L"b", "c"); + ASSERT_EQ(L"a", loaded_url->short_name()); + ASSERT_EQ(L"b", loaded_url->keyword()); ASSERT_EQ("c", loaded_url->url()->url()); ASSERT_FALSE(loaded_url->safe_for_autoreplace()); - ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), - GURL(), NULL)); - ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("b"), GURL(), NULL)); + ASSERT_TRUE(model()->CanReplaceKeyword(L"keyword", GURL(), NULL)); + ASSERT_FALSE(model()->CanReplaceKeyword(L"b", GURL(), NULL)); cloned_url = *loaded_url; BlockTillServiceProcessesRequests(); ResetModel(true); ASSERT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); - loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("b")); + loaded_url = model()->GetTemplateURLForKeyword(L"b"); ASSERT_TRUE(loaded_url != NULL); AssertEquals(cloned_url, *loaded_url); @@ -440,30 +436,28 @@ TEST_F(TemplateURLModelTest, AddUpdateRemove) { VerifyObserverCount(1); ResetModel(true); ASSERT_EQ(initial_count, model()->GetTemplateURLs().size()); - EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("b")) == NULL); + EXPECT_TRUE(model()->GetTemplateURLForKeyword(L"b") == NULL); } TEST_F(TemplateURLModelTest, GenerateKeyword) { - ASSERT_EQ(string16(), TemplateURLModel::GenerateKeyword(GURL(), true)); + ASSERT_EQ(L"", TemplateURLModel::GenerateKeyword(GURL(), true)); // Shouldn't generate keywords for https. - ASSERT_EQ(string16(), - TemplateURLModel::GenerateKeyword(GURL("https://blah"), true)); - ASSERT_EQ(ASCIIToUTF16("foo"), - TemplateURLModel::GenerateKeyword(GURL("http://foo"), true)); + ASSERT_EQ(L"", TemplateURLModel::GenerateKeyword(GURL("https://blah"), true)); + ASSERT_EQ(L"foo", TemplateURLModel::GenerateKeyword(GURL("http://foo"), + true)); // www. should be stripped. - ASSERT_EQ(ASCIIToUTF16("foo"), - TemplateURLModel::GenerateKeyword(GURL("http://www.foo"), true)); + ASSERT_EQ(L"foo", TemplateURLModel::GenerateKeyword(GURL("http://www.foo"), + true)); // Shouldn't generate keywords with paths, if autodetected. - ASSERT_EQ(string16(), - TemplateURLModel::GenerateKeyword(GURL("http://blah/foo"), true)); - ASSERT_EQ(ASCIIToUTF16("blah"), - TemplateURLModel::GenerateKeyword(GURL("http://blah/foo"), false)); + ASSERT_EQ(L"", TemplateURLModel::GenerateKeyword(GURL("http://blah/foo"), + true)); + ASSERT_EQ(L"blah", TemplateURLModel::GenerateKeyword(GURL("http://blah/foo"), + false)); // FTP shouldn't generate a keyword. - ASSERT_EQ(string16(), - TemplateURLModel::GenerateKeyword(GURL("ftp://blah/"), true)); + ASSERT_EQ(L"", TemplateURLModel::GenerateKeyword(GURL("ftp://blah/"), true)); // Make sure we don't get a trailing / - ASSERT_EQ(ASCIIToUTF16("blah"), - TemplateURLModel::GenerateKeyword(GURL("http://blah/"), true)); + ASSERT_EQ(L"blah", TemplateURLModel::GenerateKeyword(GURL("http://blah/"), + true)); } TEST_F(TemplateURLModelTest, GenerateSearchURL) { @@ -498,21 +492,21 @@ TEST_F(TemplateURLModelTest, ClearBrowsingData_Keywords) { EXPECT_EQ(0U, model()->GetTemplateURLs().size()); // Create one with a 0 time. - AddKeywordWithDate("key1", false, "http://foo1", "http://suggest1", - "http://icon1", "UTF-8;UTF-16", "name1", true, Time()); + AddKeywordWithDate(L"key1", false, "http://foo1", "http://suggest1", + "http://icon1", "UTF-8;UTF-16", L"name1", true, Time()); // Create one for now and +/- 1 day. - AddKeywordWithDate("key2", false, "http://foo2", "http://suggest2", - "http://icon2", "UTF-8;UTF-16", "name2", true, + AddKeywordWithDate(L"key2", false, "http://foo2", "http://suggest2", + "http://icon2", "UTF-8;UTF-16", L"name2", true, now - one_day); - AddKeywordWithDate("key3", false, "http://foo3", "", "", "", "name3", + AddKeywordWithDate(L"key3", false, "http://foo3", "", "", "", L"name3", true, now); - AddKeywordWithDate("key4", false, "http://foo4", "", "", "", "name4", + AddKeywordWithDate(L"key4", false, "http://foo4", "", "", "", L"name4", true, now + one_day); // Try the other three states. - AddKeywordWithDate("key5", false, "http://foo5", "http://suggest5", - "http://icon5", "UTF-8;UTF-16", "name5", false, now); - AddKeywordWithDate("key6", false, "http://foo6", "http://suggest6", - "http://icon6", "UTF-8;UTF-16", "name6", false, + AddKeywordWithDate(L"key5", false, "http://foo5", "http://suggest5", + "http://icon5", "UTF-8;UTF-16", L"name5", false, now); + AddKeywordWithDate(L"key6", false, "http://foo6", "http://suggest6", + "http://icon6", "UTF-8;UTF-16", L"name6", false, month_ago); // We just added a few items, validate them. @@ -529,17 +523,17 @@ TEST_F(TemplateURLModelTest, ClearBrowsingData_Keywords) { EXPECT_EQ(3U, model()->GetTemplateURLs().size()); // Make sure the right values remain. - EXPECT_EQ(ASCIIToUTF16("key1"), model()->GetTemplateURLs()[0]->keyword()); + EXPECT_EQ(L"key1", model()->GetTemplateURLs()[0]->keyword()); EXPECT_TRUE(model()->GetTemplateURLs()[0]->safe_for_autoreplace()); EXPECT_EQ(0U, model()->GetTemplateURLs()[0]->date_created().ToInternalValue()); - EXPECT_EQ(ASCIIToUTF16("key5"), model()->GetTemplateURLs()[1]->keyword()); + EXPECT_EQ(L"key5", model()->GetTemplateURLs()[1]->keyword()); EXPECT_FALSE(model()->GetTemplateURLs()[1]->safe_for_autoreplace()); EXPECT_EQ(now.ToInternalValue(), model()->GetTemplateURLs()[1]->date_created().ToInternalValue()); - EXPECT_EQ(ASCIIToUTF16("key6"), model()->GetTemplateURLs()[2]->keyword()); + EXPECT_EQ(L"key6", model()->GetTemplateURLs()[2]->keyword()); EXPECT_FALSE(model()->GetTemplateURLs()[2]->safe_for_autoreplace()); EXPECT_EQ(month_ago.ToInternalValue(), model()->GetTemplateURLs()[2]->date_created().ToInternalValue()); @@ -555,8 +549,8 @@ TEST_F(TemplateURLModelTest, Reset) { const size_t initial_count = model()->GetTemplateURLs().size(); TemplateURL* t_url = new TemplateURL(); t_url->SetURL("http://www.google.com/foo/bar", 0, 0); - t_url->set_keyword(ASCIIToUTF16("keyword")); - t_url->set_short_name(ASCIIToUTF16("google")); + t_url->set_keyword(L"keyword"); + t_url->set_short_name(L"google"); GURL favicon_url("http://favicon.url"); t_url->SetFavIconURL(favicon_url); t_url->set_date_created(Time::FromTimeT(100)); @@ -566,8 +560,8 @@ TEST_F(TemplateURLModelTest, Reset) { BlockTillServiceProcessesRequests(); // Reset the short name, keyword, url and make sure it takes. - const string16 new_short_name(ASCIIToUTF16("a")); - const string16 new_keyword(ASCIIToUTF16("b")); + const std::wstring new_short_name(L"a"); + const std::wstring new_keyword(L"b"); const std::string new_url("c"); model()->ResetTemplateURL(t_url, new_short_name, new_keyword, new_url); ASSERT_EQ(new_short_name, t_url->short_name()); @@ -576,8 +570,7 @@ TEST_F(TemplateURLModelTest, Reset) { // Make sure the mappings in the model were updated. ASSERT_TRUE(model()->GetTemplateURLForKeyword(new_keyword) == t_url); - ASSERT_TRUE( - model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")) == NULL); + ASSERT_TRUE(model()->GetTemplateURLForKeyword(L"keyword") == NULL); TemplateURL last_url = *t_url; @@ -594,8 +587,8 @@ TEST_F(TemplateURLModelTest, DefaultSearchProvider) { // Add a new TemplateURL. VerifyLoad(); const size_t initial_count = model()->GetTemplateURLs().size(); - TemplateURL* t_url = AddKeywordWithDate("key1", false, "http://foo1", - "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", true, Time()); + TemplateURL* t_url = AddKeywordWithDate(L"key1", false, "http://foo1", + "http://sugg1", "http://icon1", "UTF-8;UTF-16", L"name1", true, Time()); test_util_.ResetObserverCount(); model()->SetDefaultSearchProvider(t_url); @@ -626,8 +619,8 @@ TEST_F(TemplateURLModelTest, TemplateURLWithNoKeyword) { const size_t initial_count = model()->GetTemplateURLs().size(); - AddKeywordWithDate("", false, "http://foo1", "http://sugg1", - "http://icon1", "UTF-8;UTF-16", "name1", true, Time()); + AddKeywordWithDate(std::wstring(), false, "http://foo1", "http://sugg1", + "http://icon1", "UTF-8;UTF-16", L"name1", true, Time()); // We just added a few items, validate them. ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); @@ -649,40 +642,36 @@ TEST_F(TemplateURLModelTest, TemplateURLWithNoKeyword) { TEST_F(TemplateURLModelTest, CantReplaceWithSameKeyword) { ChangeModelToLoadState(); - ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"), GURL(), NULL)); - TemplateURL* t_url = AddKeywordWithDate("foo", false, "http://foo1", - "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", true, Time()); + ASSERT_TRUE(model()->CanReplaceKeyword(L"foo", GURL(), NULL)); + TemplateURL* t_url = AddKeywordWithDate(L"foo", false, "http://foo1", + "http://sugg1", "http://icon1", "UTF-8;UTF-16", L"name1", true, Time()); // Can still replace, newly added template url is marked safe to replace. - ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"), - GURL("http://foo2"), NULL)); + ASSERT_TRUE(model()->CanReplaceKeyword(L"foo", GURL("http://foo2"), NULL)); // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should // no longer be replaceable. model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(), t_url->url()->url()); - ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"), - GURL("http://foo2"), NULL)); + ASSERT_FALSE(model()->CanReplaceKeyword(L"foo", GURL("http://foo2"), NULL)); } TEST_F(TemplateURLModelTest, CantReplaceWithSameHosts) { ChangeModelToLoadState(); - ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"), - GURL("http://foo.com"), NULL)); - TemplateURL* t_url = AddKeywordWithDate("foo", false, "http://foo.com", - "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", true, Time()); + ASSERT_TRUE(model()->CanReplaceKeyword(L"foo", GURL("http://foo.com"), NULL)); + TemplateURL* t_url = AddKeywordWithDate(L"foo", false, "http://foo.com", + "http://sugg1", "http://icon1", "UTF-8;UTF-16", L"name1", true, Time()); // Can still replace, newly added template url is marked safe to replace. - ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("bar"), - GURL("http://foo.com"), NULL)); + ASSERT_TRUE(model()->CanReplaceKeyword(L"bar", GURL("http://foo.com"), NULL)); // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should // no longer be replaceable. model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(), t_url->url()->url()); - ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("bar"), + ASSERT_FALSE(model()->CanReplaceKeyword(L"bar", GURL("http://foo.com"), NULL)); } @@ -703,7 +692,7 @@ TEST_F(TemplateURLModelTest, DefaultSearchProviderLoadedFromPrefs) { template_url->SetURL("http://url", 0, 0); template_url->SetSuggestionsURL("http://url2", 0, 0); template_url->SetInstantURL("http://instant", 0, 0); - template_url->set_short_name(ASCIIToUTF16("a")); + template_url->set_short_name(L"a"); template_url->set_safe_for_autoreplace(true); template_url->set_date_created(Time::FromTimeT(100)); @@ -733,7 +722,7 @@ TEST_F(TemplateURLModelTest, DefaultSearchProviderLoadedFromPrefs) { ASSERT_EQ("http://url2", default_turl->suggestions_url()->url()); ASSERT_TRUE(default_turl->instant_url()); EXPECT_EQ("http://instant", default_turl->instant_url()->url()); - ASSERT_EQ(ASCIIToUTF16("a"), default_turl->short_name()); + ASSERT_EQ(L"a", default_turl->short_name()); ASSERT_EQ(id, default_turl->id()); // Now do a load and make sure the default search provider really takes. @@ -793,20 +782,20 @@ TEST_F(TemplateURLModelTest, BuildQueryTerms) { TEST_F(TemplateURLModelTest, UpdateKeywordSearchTermsForURL) { struct TestData { const std::string url; - const string16 term; + const std::wstring term; } data[] = { - { "http://foo/", string16() }, - { "http://foo/foo?q=xx", string16() }, - { "http://x/bar?q=xx", string16() }, - { "http://x/foo?y=xx", string16() }, - { "http://x/foo?q=xx", ASCIIToUTF16("xx") }, - { "http://x/foo?a=b&q=xx", ASCIIToUTF16("xx") }, - { "http://x/foo?q=b&q=xx", string16() }, + { "http://foo/", L"" }, + { "http://foo/foo?q=xx", L"" }, + { "http://x/bar?q=xx", L"" }, + { "http://x/foo?y=xx", L"" }, + { "http://x/foo?q=xx", L"xx" }, + { "http://x/foo?a=b&q=xx", L"xx" }, + { "http://x/foo?q=b&q=xx", L"" }, }; ChangeModelToLoadState(); - AddKeywordWithDate("x", false, "http://x/foo?q={searchTerms}", - "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name", false, Time()); + AddKeywordWithDate(L"x", false, "http://x/foo?q={searchTerms}", + "http://sugg1", "http://icon1", "UTF-8;UTF-16", L"name", false, Time()); for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { history::URLVisitedDetails details; @@ -827,15 +816,15 @@ TEST_F(TemplateURLModelTest, DontUpdateKeywordSearchForNonReplaceable) { }; ChangeModelToLoadState(); - AddKeywordWithDate("x", false, "http://x/foo", "http://sugg1", - "http://icon1", "UTF-8;UTF-16", "name", false, Time()); + AddKeywordWithDate(L"x", false, "http://x/foo", "http://sugg1", + "http://icon1", "UTF-8;UTF-16", L"name", false, Time()); for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { history::URLVisitedDetails details; details.row = history::URLRow(GURL(data[i].url)); details.transition = 0; model()->UpdateKeywordSearchTermsForURL(details); - ASSERT_EQ(string16(), GetAndClearSearchTerm()); + ASSERT_EQ(std::wstring(), GetAndClearSearchTerm()); } } @@ -845,12 +834,12 @@ TEST_F(TemplateURLModelTest, ChangeGoogleBaseValue) { // test. ChangeModelToLoadState(); SetGoogleBaseURL("http://google.com/"); - const TemplateURL* t_url = AddKeywordWithDate("", true, + const TemplateURL* t_url = AddKeywordWithDate(std::wstring(), true, "{google:baseURL}?q={searchTerms}", "http://sugg1", "http://icon1", - "UTF-8;UTF-16", "name", false, Time()); + "UTF-8;UTF-16", L"name", false, Time()); ASSERT_EQ(t_url, model()->GetTemplateURLForHost("google.com")); EXPECT_EQ("google.com", t_url->url()->GetHost()); - EXPECT_EQ(ASCIIToUTF16("google.com"), t_url->keyword()); + EXPECT_EQ(L"google.com", t_url->keyword()); // Change the Google base url. test_util_.ResetObserverCount(); @@ -861,9 +850,9 @@ TEST_F(TemplateURLModelTest, ChangeGoogleBaseValue) { ASSERT_EQ(t_url, model()->GetTemplateURLForHost("foo.com")); EXPECT_TRUE(model()->GetTemplateURLForHost("google.com") == NULL); EXPECT_EQ("foo.com", t_url->url()->GetHost()); - EXPECT_EQ(ASCIIToUTF16("foo.com"), t_url->keyword()); + EXPECT_EQ(L"foo.com", t_url->keyword()); EXPECT_EQ("http://foo.com/?q=x", t_url->url()->ReplaceSearchTerms(*t_url, - ASCIIToUTF16("x"), TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); + L"x", TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); } struct QueryHistoryCallbackImpl { @@ -892,16 +881,16 @@ TEST_F(TemplateURLModelTest, GenerateVisitOnKeyword) { // Create a keyword. TemplateURL* t_url = AddKeywordWithDate( - "keyword", false, "http://foo.com/foo?query={searchTerms}", - "http://sugg1", "http://icon1", "UTF-8;UTF-16", "keyword", - true, base::Time::Now()); + L"keyword", false, "http://foo.com/foo?query={searchTerms}", + "http://sugg1", "http://icon1", "UTF-8;UTF-16", L"keyword", true, + base::Time::Now()); // Add a visit that matches the url of the keyword. HistoryService* history = profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); history->AddPage( - GURL(t_url->url()->ReplaceSearchTerms(*t_url, ASCIIToUTF16("blah"), 0, - string16())), + GURL(t_url->url()->ReplaceSearchTerms(*t_url, L"blah", 0, + std::wstring())), NULL, 0, GURL(), PageTransition::KEYWORD, history::RedirectList(), history::SOURCE_BROWSED, false); @@ -933,14 +922,12 @@ TEST_F(TemplateURLModelTest, LoadDeletesUnusedProvider) { TemplateURL* t_url = CreatePreloadedTemplateURL(); ChangeModelToLoadState(); model()->Add(t_url); - ASSERT_TRUE( - model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) != NULL); + ASSERT_TRUE(model()->GetTemplateURLForKeyword(L"unittest") != NULL); BlockTillServiceProcessesRequests(); // Ensure that merging clears this engine. ResetModel(true); - ASSERT_TRUE( - model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) == NULL); + ASSERT_TRUE(model()->GetTemplateURLForKeyword(L"unittest") == NULL); // Wait for any saves to finish. BlockTillServiceProcessesRequests(); @@ -948,8 +935,7 @@ TEST_F(TemplateURLModelTest, LoadDeletesUnusedProvider) { // Reload the model to verify that the database was updated as a result of the // merge. ResetModel(true); - ASSERT_TRUE( - model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) == NULL); + ASSERT_TRUE(model()->GetTemplateURLForKeyword(L"unittest") == NULL); } // Make sure that load routine doesn't delete prepopulated engines that no @@ -963,7 +949,7 @@ TEST_F(TemplateURLModelTest, LoadRetainsModifiedProvider) { // Do the copy after t_url is added so that the id is set. TemplateURL copy_t_url = *t_url; - ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest"))); + ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(L"unittest")); // Wait for any saves to finish. BlockTillServiceProcessesRequests(); @@ -971,7 +957,7 @@ TEST_F(TemplateURLModelTest, LoadRetainsModifiedProvider) { // Ensure that merging won't clear it if the user has edited it. ResetModel(true); const TemplateURL* url_for_unittest = - model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); + model()->GetTemplateURLForKeyword(L"unittest"); ASSERT_TRUE(url_for_unittest != NULL); AssertEquals(copy_t_url, *url_for_unittest); @@ -980,8 +966,7 @@ TEST_F(TemplateURLModelTest, LoadRetainsModifiedProvider) { // Reload the model to verify that save/reload retains the item. ResetModel(true); - ASSERT_TRUE( - model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) != NULL); + ASSERT_TRUE(model()->GetTemplateURLForKeyword(L"unittest") != NULL); } // Make sure that load routine doesn't delete @@ -1018,7 +1003,7 @@ TEST_F(TemplateURLModelTest, LoadRetainsDefaultProvider) { // internal state is correct. TemplateURL copy_t_url = *t_url; - ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest"))); + ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(L"unittest")); ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); BlockTillServiceProcessesRequests(); @@ -1027,7 +1012,7 @@ TEST_F(TemplateURLModelTest, LoadRetainsDefaultProvider) { ResetModel(true); { const TemplateURL* keyword_url = - model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); + model()->GetTemplateURLForKeyword(L"unittest"); ASSERT_TRUE(keyword_url != NULL); AssertEquals(copy_t_url, *keyword_url); ASSERT_EQ(keyword_url, model()->GetDefaultSearchProvider()); @@ -1040,7 +1025,7 @@ TEST_F(TemplateURLModelTest, LoadRetainsDefaultProvider) { ResetModel(true); { const TemplateURL* keyword_url = - model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); + model()->GetTemplateURLForKeyword(L"unittest"); ASSERT_TRUE(keyword_url != NULL); AssertEquals(copy_t_url, *keyword_url); ASSERT_EQ(keyword_url, model()->GetDefaultSearchProvider()); @@ -1063,7 +1048,7 @@ TEST_F(TemplateURLModelTest, LoadUpdatesSearchURL) { // This test basically verifies that no asserts or crashes occur // during this operation. TEST_F(TemplateURLModelTest, LoadDoesAutoKeywordUpdate) { - string16 prepopulated_url; + std::wstring prepopulated_url; TemplateURL* t_url = CreateReplaceablePreloadedTemplateURL( 0, &prepopulated_url); t_url->set_safe_for_autoreplace(false); @@ -1107,8 +1092,8 @@ TEST_F(TemplateURLModelTest, TestManagedDefaultSearch) { test_util_.ResetObserverCount(); // Set a regular default search provider. - TemplateURL* regular_default = AddKeywordWithDate("key1", false, - "http://foo1", "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", + TemplateURL* regular_default = AddKeywordWithDate(L"key1", false, + "http://foo1", "http://sugg1", "http://icon1", "UTF-8;UTF-16", L"name1", true, Time()); VerifyObserverCount(1); model()->SetDefaultSearchProvider(regular_default); @@ -1133,7 +1118,7 @@ TEST_F(TemplateURLModelTest, TestManagedDefaultSearch) { scoped_ptr<TemplateURL> expected_managed_default1(new TemplateURL()); expected_managed_default1->SetURL(kSearchURL, 0, 0); expected_managed_default1->SetFavIconURL(GURL(kIconURL)); - expected_managed_default1->set_short_name(ASCIIToUTF16("test1")); + expected_managed_default1->set_short_name(L"test1"); std::vector<std::string> encodings_vector; base::SplitString(kEncodings, ';', &encodings_vector); expected_managed_default1->set_input_encodings(encodings_vector); @@ -1157,7 +1142,7 @@ TEST_F(TemplateURLModelTest, TestManagedDefaultSearch) { scoped_ptr<TemplateURL> expected_managed_default2(new TemplateURL()); expected_managed_default2->SetURL(kNewSearchURL, 0, 0); expected_managed_default2->SetSuggestionsURL(kNewSuggestURL, 0, 0); - expected_managed_default2->set_short_name(ASCIIToUTF16("test2")); + expected_managed_default2->set_short_name(L"test2"); expected_managed_default2->set_show_in_default_list(true); actual_managed_default = model()->GetDefaultSearchProvider(); ExpectSimilar(actual_managed_default, expected_managed_default2.get()); diff --git a/chrome/browser/search_engines/template_url_parser.cc b/chrome/browser/search_engines/template_url_parser.cc index e671d63..245ca3f 100644 --- a/chrome/browser/search_engines/template_url_parser.cc +++ b/chrome/browser/search_engines/template_url_parser.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -138,7 +138,7 @@ class ParsingContext { TemplateURL* template_url() { return url_; } - void AddImageRef(const std::string& type, int width, int height) { + void AddImageRef(const std::wstring& type, int width, int height) { if (width > 0 && height > 0) current_image_.reset(new TemplateURL::ImageRef(type, width, height)); } @@ -147,9 +147,9 @@ class ParsingContext { current_image_.reset(); } - void SetImageURL(const GURL& url) { + void SetImageURL(const std::wstring& url) { if (current_image_.get()) { - current_image_->url = url; + current_image_->url = GURL(WideToUTF8(url)); url_->add_image_ref(*current_image_); current_image_.reset(); } @@ -159,11 +159,11 @@ class ParsingContext { string_.clear(); } - void AppendString(const string16& string) { + void AppendString(const std::wstring& string) { string_ += string; } - const string16& GetString() { + const std::wstring& GetString() { return string_; } @@ -233,7 +233,7 @@ class ParsingContext { scoped_ptr<TemplateURL::ImageRef> current_image_; // Character content for the current element. - string16 string_; + std::wstring string_; TemplateURLParser::ParameterFilter* parameter_filter_; @@ -259,8 +259,12 @@ class ParsingContext { std::map<std::string, ParsingContext::ElementType>* ParsingContext::kElementNameToElementTypeMap = NULL; -string16 XMLCharToUTF16(const xmlChar* value, int length) { - return UTF8ToUTF16(std::string((const char*)value, length)); +std::wstring XMLCharToWide(const xmlChar* value) { + return UTF8ToWide(std::string((const char*)value)); +} + +std::wstring XMLCharToWide(const xmlChar* value, int length) { + return UTF8ToWide(std::string((const char*)value, length)); } std::string XMLCharToString(const xmlChar* value) { @@ -340,12 +344,12 @@ void ParseImage(const xmlChar** atts, ParsingContext* context) { const xmlChar** attributes = atts; int width = 0; int height = 0; - std::string type; + std::wstring type; while (*attributes) { std::string name(XMLCharToString(*attributes)); const xmlChar* value = attributes[1]; if (name == kImageTypeAttribute) { - type = XMLCharToString(value); + type = XMLCharToWide(value); } else if (name == kImageWidthAttribute) { base::StringToInt(XMLCharToString(value), &width); } else if (name == kImageHeightAttribute) { @@ -364,6 +368,7 @@ void ParseParam(const xmlChar** atts, ParsingContext* context) { return; const xmlChar** attributes = atts; + std::wstring type; std::string key, value; while (*attributes) { std::string name(XMLCharToString(*attributes)); @@ -482,14 +487,14 @@ void EndElementImpl(void *ctx, const xmlChar *name) { context->template_url()->set_description(context->GetString()); break; case ParsingContext::IMAGE: { - GURL image_url(UTF16ToUTF8(context->GetString())); + GURL image_url(WideToUTF8(context->GetString())); if (image_url.SchemeIs(chrome::kDataScheme)) { // TODO (jcampan): bug 1169256: when dealing with data URL, we need to // decode the data URL in the renderer. For now, we'll just point to the // fav icon from the URL. context->set_derive_image_from_url(true); } else { - context->SetImageURL(image_url); + context->SetImageURL(context->GetString()); } context->EndImage(); break; @@ -498,7 +503,7 @@ void EndElementImpl(void *ctx, const xmlChar *name) { context->template_url()->add_language(context->GetString()); break; case ParsingContext::INPUT_ENCODING: { - std::string input_encoding = UTF16ToASCII(context->GetString()); + std::string input_encoding = WideToASCII(context->GetString()); if (IsValidEncodingString(input_encoding)) context->template_url()->add_input_encoding(input_encoding); break; @@ -515,7 +520,7 @@ void EndElementImpl(void *ctx, const xmlChar *name) { void CharactersImpl(void *ctx, const xmlChar *ch, int len) { ParsingContext* context = reinterpret_cast<ParsingContext*>(ctx); - context->AppendString(XMLCharToUTF16(ch, len)); + context->AppendString(XMLCharToWide(ch, len)); } // Returns true if the ref is null, or the url wrapped by ref is diff --git a/chrome/browser/search_engines/template_url_parser_unittest.cc b/chrome/browser/search_engines/template_url_parser_unittest.cc index c339092..14d6203 100644 --- a/chrome/browser/search_engines/template_url_parser_unittest.cc +++ b/chrome/browser/search_engines/template_url_parser_unittest.cc @@ -1,11 +1,10 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "base/file_util.h" #include "base/logging.h" #include "base/path_service.h" -#include "base/utf_string_conversions.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_parser.h" #include "chrome/common/chrome_paths.h" @@ -85,7 +84,7 @@ TEST_F(TemplateURLParserTest, TestDictionary) { return; ParseFile("dictionary.xml", NULL); ASSERT_TRUE(parse_result_); - EXPECT_EQ(ASCIIToUTF16("Dictionary.com"), template_url_.short_name()); + EXPECT_EQ(L"Dictionary.com", template_url_.short_name()); EXPECT_TRUE(template_url_.GetFavIconURL() == GURL("http://cache.lexico.com/g/d/favicon.ico")); EXPECT_TRUE(template_url_.url() != NULL); @@ -99,7 +98,7 @@ TEST_F(TemplateURLParserTest, TestMSDN) { return; ParseFile("msdn.xml", NULL); ASSERT_TRUE(parse_result_); - EXPECT_EQ(ASCIIToUTF16("Search \" MSDN"), template_url_.short_name()); + EXPECT_EQ(L"Search \" MSDN", template_url_.short_name()); EXPECT_TRUE(template_url_.GetFavIconURL() == GURL("http://search.msdn.microsoft.com/search/favicon.ico")); EXPECT_TRUE(template_url_.url() != NULL); @@ -113,7 +112,7 @@ TEST_F(TemplateURLParserTest, TestWikipedia) { return; ParseFile("wikipedia.xml", NULL); ASSERT_TRUE(parse_result_); - EXPECT_EQ(ASCIIToUTF16("Wikipedia (English)"), template_url_.short_name()); + EXPECT_EQ(L"Wikipedia (English)", template_url_.short_name()); EXPECT_TRUE(template_url_.GetFavIconURL() == GURL("http://en.wikipedia.org/favicon.ico")); EXPECT_TRUE(template_url_.url() != NULL); @@ -164,7 +163,7 @@ TEST_F(TemplateURLParserTest, TestFirefoxEbay) { ParamFilterImpl filter("ebay", "ebay"); ParseFile("firefox_ebay.xml", &filter); ASSERT_TRUE(parse_result_); - EXPECT_EQ(ASCIIToUTF16("eBay"), template_url_.short_name()); + EXPECT_EQ(L"eBay", template_url_.short_name()); EXPECT_TRUE(template_url_.url() != NULL); EXPECT_TRUE(template_url_.url()->SupportsReplacement()); std::string exp_url = @@ -185,7 +184,7 @@ TEST_F(TemplateURLParserTest, TestFirefoxWebster) { ParamFilterImpl filter("", "Mozilla"); ParseFile("firefox_webster.xml", &filter); ASSERT_TRUE(parse_result_); - EXPECT_EQ(ASCIIToUTF16("Webster"), template_url_.short_name()); + EXPECT_EQ(L"Webster", template_url_.short_name()); EXPECT_TRUE(template_url_.url() != NULL); EXPECT_TRUE(template_url_.url()->SupportsReplacement()); EXPECT_EQ("http://www.webster.com/cgi-bin/dictionary?va={searchTerms}", @@ -203,7 +202,7 @@ TEST_F(TemplateURLParserTest, TestFirefoxYahoo) { ParamFilterImpl filter("", "Mozilla"); ParseFile("firefox_yahoo.xml", &filter); ASSERT_TRUE(parse_result_); - EXPECT_EQ(ASCIIToUTF16("Yahoo"), template_url_.short_name()); + EXPECT_EQ(L"Yahoo", template_url_.short_name()); EXPECT_TRUE(template_url_.url() != NULL); EXPECT_TRUE(template_url_.url()->SupportsReplacement()); EXPECT_EQ("http://ff.search.yahoo.com/gossip?" @@ -226,7 +225,7 @@ TEST_F(TemplateURLParserTest, TestPostSuggestion) { ParamFilterImpl filter("", "Mozilla"); ParseFile("post_suggestion.xml", &filter); ASSERT_TRUE(parse_result_); - EXPECT_EQ(ASCIIToUTF16("Yahoo"), template_url_.short_name()); + EXPECT_EQ(L"Yahoo", template_url_.short_name()); EXPECT_TRUE(template_url_.url() != NULL); EXPECT_TRUE(template_url_.url()->SupportsReplacement()); EXPECT_TRUE(template_url_.suggestions_url() == NULL); diff --git a/chrome/browser/search_engines/template_url_prepopulate_data.cc b/chrome/browser/search_engines/template_url_prepopulate_data.cc index 6cb64bd..fbd89b4 100644 --- a/chrome/browser/search_engines/template_url_prepopulate_data.cc +++ b/chrome/browser/search_engines/template_url_prepopulate_data.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -3379,11 +3379,11 @@ TemplateURL* MakePrepopulatedTemplateURL(const wchar_t* name, new_turl->SetSuggestionsURL(WideToUTF8(suggest_url), 0, 0); if (instant_url) new_turl->SetInstantURL(WideToUTF8(instant_url), 0, 0); - new_turl->set_short_name(WideToUTF16Hack(name)); + new_turl->set_short_name(name); if (keyword == NULL) new_turl->set_autogenerate_keyword(true); else - new_turl->set_keyword(WideToUTF16Hack(keyword)); + new_turl->set_keyword(keyword); new_turl->set_show_in_default_list(true); new_turl->set_safe_for_autoreplace(true); new_turl->set_date_created(Time()); diff --git a/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc b/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc index 1261915..f79f6b6 100644 --- a/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc +++ b/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc @@ -1,11 +1,10 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "base/file_util.h" #include "base/scoped_temp_dir.h" #include "base/scoped_vector.h" -#include "base/utf_string_conversions.h" #include "chrome/browser/search_engines/search_engine_type.h" #include "chrome/browser/search_engines/search_terms_data.h" #include "chrome/browser/search_engines/template_url.h" @@ -120,8 +119,8 @@ TEST_F(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) { &prefs, &(t_urls.get()), &default_index); ASSERT_EQ(1u, t_urls.size()); - EXPECT_EQ(ASCIIToUTF16("foo"), t_urls[0]->short_name()); - EXPECT_EQ(ASCIIToUTF16("fook"), t_urls[0]->keyword()); + EXPECT_EQ(L"foo", t_urls[0]->short_name()); + EXPECT_EQ(L"fook", t_urls[0]->keyword()); EXPECT_EQ("foo.com", t_urls[0]->url()->GetHost()); EXPECT_EQ("foi.com", t_urls[0]->GetFavIconURL().host()); EXPECT_EQ(1u, t_urls[0]->input_encodings().size()); diff --git a/chrome/browser/search_engines/template_url_table_model.cc b/chrome/browser/search_engines/template_url_table_model.cc index 18c239d..453b98d 100644 --- a/chrome/browser/search_engines/template_url_table_model.cc +++ b/chrome/browser/search_engines/template_url_table_model.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -180,7 +180,7 @@ string16 TemplateURLTableModel::GetText(int row, int col_id) { switch (col_id) { case IDS_SEARCH_ENGINES_EDITOR_DESCRIPTION_COLUMN: { - string16 url_short_name = url.short_name(); + string16 url_short_name = WideToUTF16Hack(url.short_name()); // TODO(xji): Consider adding a special case if the short name is a URL, // since those should always be displayed LTR. Please refer to // http://crbug.com/6726 for more information. @@ -195,7 +195,7 @@ string16 TemplateURLTableModel::GetText(int row, int col_id) { case IDS_SEARCH_ENGINES_EDITOR_KEYWORD_COLUMN: { // Keyword should be domain name. Force it to have LTR directionality. - string16 keyword = url.keyword(); + string16 keyword = WideToUTF16(url.keyword()); keyword = base::i18n::GetDisplayStringInLTRDirectionality(keyword); return keyword; } @@ -279,7 +279,8 @@ void TemplateURLTableModel::ModifyTemplateURL(int index, DCHECK(index >= 0 && index <= RowCount()); const TemplateURL* template_url = &GetTemplateURL(index); template_url_model_->RemoveObserver(this); - template_url_model_->ResetTemplateURL(template_url, title, keyword, url); + template_url_model_->ResetTemplateURL(template_url, UTF16ToWideHack(title), + UTF16ToWideHack(keyword), url); if (template_url_model_->GetDefaultSearchProvider() == template_url && !TemplateURL::SupportsReplacement(template_url)) { // The entry was the default search provider, but the url has been modified diff --git a/chrome/browser/search_engines/template_url_unittest.cc b/chrome/browser/search_engines/template_url_unittest.cc index 819164c..3faa2aa 100644 --- a/chrome/browser/search_engines/template_url_unittest.cc +++ b/chrome/browser/search_engines/template_url_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -28,8 +28,8 @@ class TestSearchTermsData : public SearchTermsData { #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) // Returns the value for the Chrome Omnibox rlz. - virtual string16 GetRlzParameterValue() const { - return string16(); + virtual std::wstring GetRlzParameterValue() const { + return L""; } #endif @@ -68,16 +68,15 @@ TEST_F(TemplateURLTest, TestValidWithComplete) { TEST_F(TemplateURLTest, URLRefTestSearchTerms) { struct SearchTermsCase { const char* url; - const string16 terms; + const wchar_t* terms; const char* output; } search_term_cases[] = { - { "http://foo{searchTerms}", ASCIIToUTF16("sea rch/bar"), - "http://foosea%20rch/bar" }, - { "http://foo{searchTerms}?boo=abc", ASCIIToUTF16("sea rch/bar"), + { "http://foo{searchTerms}", L"sea rch/bar", "http://foosea%20rch/bar" }, + { "http://foo{searchTerms}?boo=abc", L"sea rch/bar", "http://foosea%20rch/bar?boo=abc" }, - { "http://foo/?boo={searchTerms}", ASCIIToUTF16("sea rch/bar"), + { "http://foo/?boo={searchTerms}", L"sea rch/bar", "http://foo/?boo=sea+rch%2Fbar" }, - { "http://en.wikipedia.org/{searchTerms}", ASCIIToUTF16("wiki/?"), + { "http://en.wikipedia.org/{searchTerms}", L"wiki/?", "http://en.wikipedia.org/wiki/%3F" } }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(search_term_cases); ++i) { @@ -88,7 +87,7 @@ TEST_F(TemplateURLTest, URLRefTestSearchTerms) { ASSERT_TRUE(ref.SupportsReplacement()); GURL result = GURL(ref.ReplaceSearchTerms(t_url, value.terms, - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); ASSERT_TRUE(result.is_valid()); ASSERT_EQ(value.output, result.spec()); } @@ -99,8 +98,8 @@ TEST_F(TemplateURLTest, URLRefTestCount) { TemplateURLRef ref("http://foo{searchTerms}{count?}", 0, 0); ASSERT_TRUE(ref.IsValid()); ASSERT_TRUE(ref.SupportsReplacement()); - GURL result = GURL(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"), - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); + GURL result = GURL(ref.ReplaceSearchTerms(t_url, L"X", + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); ASSERT_TRUE(result.is_valid()); ASSERT_EQ("http://foox/", result.spec()); } @@ -110,8 +109,8 @@ TEST_F(TemplateURLTest, URLRefTestCount2) { TemplateURLRef ref("http://foo{searchTerms}{count}", 0, 0); ASSERT_TRUE(ref.IsValid()); ASSERT_TRUE(ref.SupportsReplacement()); - GURL result = GURL(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"), - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); + GURL result = GURL(ref.ReplaceSearchTerms(t_url, L"X", + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); ASSERT_TRUE(result.is_valid()); ASSERT_EQ("http://foox10/", result.spec()); } @@ -122,8 +121,8 @@ TEST_F(TemplateURLTest, URLRefTestIndices) { 1, 2); ASSERT_TRUE(ref.IsValid()); ASSERT_TRUE(ref.SupportsReplacement()); - GURL result = GURL(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"), - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); + GURL result = GURL(ref.ReplaceSearchTerms(t_url, L"X", + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); ASSERT_TRUE(result.is_valid()); ASSERT_EQ("http://fooxxy/", result.spec()); } @@ -133,8 +132,8 @@ TEST_F(TemplateURLTest, URLRefTestIndices2) { TemplateURLRef ref("http://foo{searchTerms}x{startIndex}y{startPage}", 1, 2); ASSERT_TRUE(ref.IsValid()); ASSERT_TRUE(ref.SupportsReplacement()); - GURL result = GURL(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"), - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); + GURL result = GURL(ref.ReplaceSearchTerms(t_url, L"X", + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); ASSERT_TRUE(result.is_valid()); ASSERT_EQ("http://fooxx1y2/", result.spec()); } @@ -145,8 +144,8 @@ TEST_F(TemplateURLTest, URLRefTestEncoding) { "http://foo{searchTerms}x{inputEncoding?}y{outputEncoding?}a", 1, 2); ASSERT_TRUE(ref.IsValid()); ASSERT_TRUE(ref.SupportsReplacement()); - GURL result = GURL(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"), - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); + GURL result = GURL(ref.ReplaceSearchTerms(t_url, L"X", + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); ASSERT_TRUE(result.is_valid()); ASSERT_EQ("http://fooxxutf-8ya/", result.spec()); } @@ -157,8 +156,8 @@ TEST_F(TemplateURLTest, InputEncodingBeforeSearchTerm) { "http://foox{inputEncoding?}a{searchTerms}y{outputEncoding?}b", 1, 2); ASSERT_TRUE(ref.IsValid()); ASSERT_TRUE(ref.SupportsReplacement()); - GURL result = GURL(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"), - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); + GURL result = GURL(ref.ReplaceSearchTerms(t_url, L"X", + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); ASSERT_TRUE(result.is_valid()); ASSERT_EQ("http://fooxutf-8axyb/", result.spec()); } @@ -169,8 +168,8 @@ TEST_F(TemplateURLTest, URLRefTestEncoding2) { "http://foo{searchTerms}x{inputEncoding}y{outputEncoding}a", 1, 2); ASSERT_TRUE(ref.IsValid()); ASSERT_TRUE(ref.SupportsReplacement()); - GURL result = GURL(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"), - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); + GURL result = GURL(ref.ReplaceSearchTerms(t_url, L"X", + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); ASSERT_TRUE(result.is_valid()); ASSERT_EQ("http://fooxxutf-8yutf-8a/", result.spec()); } @@ -178,12 +177,12 @@ TEST_F(TemplateURLTest, URLRefTestEncoding2) { TEST_F(TemplateURLTest, URLRefTestSearchTermsUsingTermsData) { struct SearchTermsCase { const char* url; - const string16 terms; + const wchar_t* terms; const char* output; } search_term_cases[] = { - { "{google:baseURL}{language}{searchTerms}", string16(), + { "{google:baseURL}{language}{searchTerms}", L"", "http://example.com/e/yy" }, - { "{google:baseSuggestURL}{searchTerms}", string16(), + { "{google:baseSuggestURL}{searchTerms}", L"", "http://clients1.example.com/complete/" } }; @@ -197,7 +196,7 @@ TEST_F(TemplateURLTest, URLRefTestSearchTermsUsingTermsData) { ASSERT_TRUE(ref.SupportsReplacement()); GURL result = GURL(ref.ReplaceSearchTermsUsingTermsData( t_url, value.terms, - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16(), + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring(), search_terms_data)); ASSERT_TRUE(result.is_valid()); ASSERT_EQ(value.output, result.spec()); @@ -207,21 +206,21 @@ TEST_F(TemplateURLTest, URLRefTestSearchTermsUsingTermsData) { TEST_F(TemplateURLTest, URLRefTermToWide) { struct ToWideCase { const char* encoded_search_term; - const string16 expected_decoded_term; + const wchar_t* expected_decoded_term; } to_wide_cases[] = { - {"hello+world", ASCIIToUTF16("hello world")}, + {"hello+world", L"hello world"}, // Test some big-5 input. - {"%a7A%A6%6e+to+you", WideToUTF16(L"\x4f60\x597d to you")}, + {"%a7A%A6%6e+to+you", L"\x4f60\x597d to you"}, // Test some UTF-8 input. We should fall back to this when the encoding // doesn't look like big-5. We have a '5' in the middle, which is an invalid // Big-5 trailing byte. - {"%e4%bd%a05%e5%a5%bd+to+you", WideToUTF16(L"\x4f60\x35\x597d to you")}, + {"%e4%bd%a05%e5%a5%bd+to+you", L"\x4f60\x35\x597d to you"}, // Undecodable input should stay escaped. - {"%91%01+abcd", WideToUTF16(L"%91%01 abcd")}, + {"%91%01+abcd", L"%91%01 abcd"}, // Make sure we convert %2B to +. - {"C%2B%2B", ASCIIToUTF16("C++")}, + {"C%2B%2B", L"C++"}, // C%2B is escaped as C%252B, make sure we unescape it properly. - {"C%252B", ASCIIToUTF16("C%2B")}, + {"C%252B", L"C%2B"}, }; TemplateURL t_url; @@ -236,10 +235,10 @@ TEST_F(TemplateURLTest, URLRefTermToWide) { ASSERT_TRUE(ref.SupportsReplacement()); for (size_t i = 0; i < ARRAYSIZE_UNSAFE(to_wide_cases); i++) { - string16 result = ref.SearchTermToString16(t_url, + std::wstring result = ref.SearchTermToWide(t_url, to_wide_cases[i].encoded_search_term); - EXPECT_EQ(to_wide_cases[i].expected_decoded_term, result); + EXPECT_EQ(std::wstring(to_wide_cases[i].expected_decoded_term), result); } } @@ -259,16 +258,16 @@ TEST_F(TemplateURLTest, SetFavIcon) { TEST_F(TemplateURLTest, DisplayURLToURLRef) { struct TestData { const std::string url; - const string16 expected_result; + const std::wstring expected_result; } data[] = { { "http://foo{searchTerms}x{inputEncoding}y{outputEncoding}a", - ASCIIToUTF16("http://foo%sx{inputEncoding}y{outputEncoding}a") }, + L"http://foo%sx{inputEncoding}y{outputEncoding}a" }, { "http://X", - ASCIIToUTF16("http://X") }, + L"http://X" }, { "http://foo{searchTerms", - ASCIIToUTF16("http://foo{searchTerms") }, + L"http://foo{searchTerms" }, { "http://foo{searchTerms}{language}", - ASCIIToUTF16("http://foo%s{language}") }, + L"http://foo%s{language}" }, }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { TemplateURLRef ref(data[i].url, 1, 2); @@ -317,8 +316,8 @@ TEST_F(TemplateURLTest, ReplaceSearchTerms) { std::string expected_result = data[i].expected_result; ReplaceSubstringsAfterOffset(&expected_result, 0, "{language}", g_browser_process->GetApplicationLocale()); - GURL result = GURL(ref.ReplaceSearchTerms(turl, ASCIIToUTF16("X"), - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); + GURL result = GURL(ref.ReplaceSearchTerms(turl, L"X", + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); EXPECT_TRUE(result.is_valid()); EXPECT_EQ(expected_result, result.spec()); } @@ -330,15 +329,13 @@ TEST_F(TemplateURLTest, ReplaceSearchTerms) { TEST_F(TemplateURLTest, ReplaceArbitrarySearchTerms) { struct TestData { const std::string encoding; - const string16 search_term; + const std::wstring search_term; const std::string url; const std::string expected_result; } data[] = { - { "BIG5", WideToUTF16(L"\x60BD"), - "http://foo/?{searchTerms}{inputEncoding}", + { "BIG5", L"\x60BD", "http://foo/?{searchTerms}{inputEncoding}", "http://foo/?%B1~BIG5" }, - { "UTF-8", ASCIIToUTF16("blah"), - "http://foo/?{searchTerms}{inputEncoding}", + { "UTF-8", L"blah", "http://foo/?{searchTerms}{inputEncoding}", "http://foo/?blahUTF-8" }, }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { @@ -347,7 +344,7 @@ TEST_F(TemplateURLTest, ReplaceArbitrarySearchTerms) { TemplateURLRef ref(data[i].url, 1, 2); GURL result = GURL(ref.ReplaceSearchTerms(turl, data[i].search_term, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, - string16())); + std::wstring())); EXPECT_TRUE(result.is_valid()); EXPECT_EQ(data[i].expected_result, result.spec()); } @@ -356,19 +353,19 @@ TEST_F(TemplateURLTest, ReplaceArbitrarySearchTerms) { TEST_F(TemplateURLTest, Suggestions) { struct TestData { const int accepted_suggestion; - const string16 original_query_for_suggestion; + const std::wstring original_query_for_suggestion; const std::string expected_result; } data[] = { - { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16(), + { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring(), "http://bar/foo?q=foobar" }, - { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, ASCIIToUTF16("foo"), + { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, L"foo", "http://bar/foo?q=foobar" }, - { TemplateURLRef::NO_SUGGESTION_CHOSEN, string16(), + { TemplateURLRef::NO_SUGGESTION_CHOSEN, std::wstring(), "http://bar/foo?aq=f&q=foobar" }, - { TemplateURLRef::NO_SUGGESTION_CHOSEN, ASCIIToUTF16("foo"), + { TemplateURLRef::NO_SUGGESTION_CHOSEN, L"foo", "http://bar/foo?aq=f&q=foobar" }, - { 0, string16(), "http://bar/foo?aq=0&oq=&q=foobar" }, - { 1, ASCIIToUTF16("foo"), "http://bar/foo?aq=1&oq=foo&q=foobar" }, + { 0, std::wstring(), "http://bar/foo?aq=0&oq=&q=foobar" }, + { 1, L"foo", "http://bar/foo?aq=1&oq=foo&q=foobar" }, }; TemplateURL turl; turl.add_input_encoding("UTF-8"); @@ -377,7 +374,7 @@ TEST_F(TemplateURLTest, Suggestions) { ASSERT_TRUE(ref.IsValid()); ASSERT_TRUE(ref.SupportsReplacement()); for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { - GURL result = GURL(ref.ReplaceSearchTerms(turl, ASCIIToUTF16("foobar"), + GURL result = GURL(ref.ReplaceSearchTerms(turl, L"foobar", data[i].accepted_suggestion, data[i].original_query_for_suggestion)); EXPECT_TRUE(result.is_valid()); EXPECT_EQ(data[i].expected_result, result.spec()); @@ -386,7 +383,7 @@ TEST_F(TemplateURLTest, Suggestions) { #if defined(OS_WIN) TEST_F(TemplateURLTest, RLZ) { - string16 rlz_string; + std::wstring rlz_string; #if defined(GOOGLE_CHROME_BUILD) RLZTracker::GetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, &rlz_string); #endif @@ -396,7 +393,7 @@ TEST_F(TemplateURLTest, RLZ) { ASSERT_TRUE(ref.IsValid()); ASSERT_TRUE(ref.SupportsReplacement()); GURL result(ref.ReplaceSearchTerms(t_url, L"x", - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); ASSERT_TRUE(result.is_valid()); std::string expected_url = "http://bar/?"; if (!rlz_string.empty()) { @@ -464,14 +461,14 @@ TEST_F(TemplateURLTest, Keyword) { TemplateURL t_url; t_url.SetURL("http://www.google.com/search", 0, 0); EXPECT_FALSE(t_url.autogenerate_keyword()); - t_url.set_keyword(ASCIIToUTF16("foo")); - EXPECT_EQ(ASCIIToUTF16("foo"), t_url.keyword()); + t_url.set_keyword(L"foo"); + EXPECT_EQ(L"foo", t_url.keyword()); t_url.set_autogenerate_keyword(true); EXPECT_TRUE(t_url.autogenerate_keyword()); - EXPECT_EQ(ASCIIToUTF16("google.com"), t_url.keyword()); - t_url.set_keyword(ASCIIToUTF16("foo")); + EXPECT_EQ(L"google.com", t_url.keyword()); + t_url.set_keyword(L"foo"); EXPECT_FALSE(t_url.autogenerate_keyword()); - EXPECT_EQ(ASCIIToUTF16("foo"), t_url.keyword()); + EXPECT_EQ(L"foo", t_url.keyword()); } TEST_F(TemplateURLTest, ParseParameterKnown) { diff --git a/chrome/browser/search_engines/util.cc b/chrome/browser/search_engines/util.cc index 203042d..94b46d6 100644 --- a/chrome/browser/search_engines/util.cc +++ b/chrome/browser/search_engines/util.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -8,6 +8,7 @@ #include <vector> #include "base/logging.h" +#include "base/utf_string_conversions.h" #include "chrome/browser/browser_thread.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_model.h" @@ -28,7 +29,7 @@ string16 GetDefaultSearchEngineName(Profile* profile) { // http://code.google.com/p/chromium/issues/detail?id=2573 return string16(); } - return default_provider->short_name(); + return WideToUTF16(default_provider->short_name()); } // Removes (and deletes) TemplateURLs from |urls| that have duplicate diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc index 8edf95a..cf826bd 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.cc +++ b/chrome/browser/tab_contents/render_view_context_menu.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -607,7 +607,7 @@ void RenderViewContextMenu::AppendSearchProvider() { menu_model_.AddItem( IDC_CONTENT_CONTEXT_SEARCHWEBFOR, l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_SEARCHWEBFOR, - default_provider->short_name(), + WideToUTF16(default_provider->short_name()), printable_selection_text)); } } diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 0c940c5..b73ef97 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -2175,7 +2175,7 @@ void TabContents::GenerateKeywordIfNecessary( GURL keyword_url = previous_entry->user_typed_url().is_valid() ? previous_entry->user_typed_url() : previous_entry->url(); - string16 keyword = + std::wstring keyword = TemplateURLModel::GenerateKeyword(keyword_url, true); // autodetected if (keyword.empty()) return; @@ -3003,7 +3003,7 @@ void TabContents::PageHasOSDD( if (!keyword_url.is_valid()) return; - string16 keyword = TemplateURLModel::GenerateKeyword( + std::wstring keyword = TemplateURLModel::GenerateKeyword( keyword_url, provider_type == TemplateURLFetcher::AUTODETECTED_PROVIDER); diff --git a/chrome/browser/ui/browser_init.cc b/chrome/browser/ui/browser_init.cc index cc3ba35..6977552 100644 --- a/chrome/browser/ui/browser_init.cc +++ b/chrome/browser/ui/browser_init.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -886,8 +886,8 @@ std::vector<GURL> BrowserInit::LaunchWithProfile::GetURLsFromCommandLine( DCHECK(search_url->SupportsReplacement()); std::wstring search_term = param.ToWStringHack().substr(2); urls.push_back(GURL(search_url->ReplaceSearchTerms( - *default_provider, WideToUTF16Hack(search_term), - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()))); + *default_provider, search_term, + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()))); } else { // This will create a file URL or a regular URL. // This call can (in rare circumstances) block the UI thread. diff --git a/chrome/browser/ui/cocoa/edit_search_engine_cocoa_controller.mm b/chrome/browser/ui/cocoa/edit_search_engine_cocoa_controller.mm index 01fa580..7d83c74 100644 --- a/chrome/browser/ui/cocoa/edit_search_engine_cocoa_controller.mm +++ b/chrome/browser/ui/cocoa/edit_search_engine_cocoa_controller.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -87,11 +87,11 @@ void ShiftOriginY(NSView* view, CGFloat amount) { [window setTitle:l10n_util::GetNSString( IDS_SEARCH_ENGINES_EDITOR_EDIT_WINDOW_TITLE)]; [nameField_ setStringValue: - base::SysUTF16ToNSString(templateURL_->short_name())]; + base::SysWideToNSString(templateURL_->short_name())]; [keywordField_ setStringValue: - base::SysUTF16ToNSString(templateURL_->keyword())]; + base::SysWideToNSString(templateURL_->keyword())]; [urlField_ setStringValue: - base::SysUTF16ToNSString(templateURL_->url()->DisplayURL())]; + base::SysWideToNSString(templateURL_->url()->DisplayURL())]; [urlField_ setEnabled:(templateURL_->prepopulate_id() == 0)]; } // When creating a new keyword, this will mark the fields as "invalid" and diff --git a/chrome/browser/ui/cocoa/edit_search_engine_cocoa_controller_unittest.mm b/chrome/browser/ui/cocoa/edit_search_engine_cocoa_controller_unittest.mm index 4e5402a..f4b74a5 100644 --- a/chrome/browser/ui/cocoa/edit_search_engine_cocoa_controller_unittest.mm +++ b/chrome/browser/ui/cocoa/edit_search_engine_cocoa_controller_unittest.mm @@ -1,10 +1,9 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "app/l10n_util_mac.h" #include "base/scoped_nsobject.h" -#include "base/utf_string_conversions.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/ui/cocoa/browser_test_helper.h" #include "chrome/browser/ui/cocoa/cocoa_test_helper.h" @@ -206,10 +205,10 @@ TEST_F(EditSearchEngineControllerTest, ValidateFields) { // Tests editing an existing TemplateURL. TEST_F(EditSearchEngineControllerTest, EditTemplateURL) { TemplateURL url; - url.set_short_name(ASCIIToUTF16("Foobar")); - url.set_keyword(ASCIIToUTF16("keyword")); + url.set_short_name(L"Foobar"); + url.set_keyword(L"keyword"); std::string urlString = TemplateURLRef::DisplayURLToURLRef( - ASCIIToUTF16("http://foo-bar.com")); + L"http://foo-bar.com"); url.SetURL(urlString, 0, 1); TestingProfile* profile = browser_helper_.profile(); FakeEditSearchEngineController *controller = diff --git a/chrome/browser/ui/cocoa/keyword_editor_cocoa_controller_unittest.mm b/chrome/browser/ui/cocoa/keyword_editor_cocoa_controller_unittest.mm index 383532c..27ffabe 100644 --- a/chrome/browser/ui/cocoa/keyword_editor_cocoa_controller_unittest.mm +++ b/chrome/browser/ui/cocoa/keyword_editor_cocoa_controller_unittest.mm @@ -1,10 +1,9 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "base/mac/scoped_nsautorelease_pool.h" #include "base/scoped_nsobject.h" -#include "base/utf_string_conversions.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_model.h" #include "chrome/browser/ui/cocoa/browser_test_helper.h" @@ -151,16 +150,16 @@ TEST_F(KeywordEditorCocoaControllerTest, IndexInModelForRowMixed) { // Add a default engine. TemplateURL* t_url = new TemplateURL(); t_url->SetURL("http://test1/{searchTerms}", 0, 0); - t_url->set_keyword(ASCIIToUTF16("test1")); - t_url->set_short_name(ASCIIToUTF16("Test1")); + t_url->set_keyword(L"test1"); + t_url->set_short_name(L"Test1"); t_url->set_show_in_default_list(true); template_model->Add(t_url); // Add a non-default engine. t_url = new TemplateURL(); t_url->SetURL("http://test2/{searchTerms}", 0, 0); - t_url->set_keyword(ASCIIToUTF16("test2")); - t_url->set_short_name(ASCIIToUTF16("Test2")); + t_url->set_keyword(L"test2"); + t_url->set_short_name(L"Test2"); t_url->set_show_in_default_list(false); template_model->Add(t_url); @@ -194,15 +193,15 @@ TEST_F(KeywordEditorCocoaControllerTest, IndexInModelForDefault) { // Add 2 default engines. TemplateURL* t_url = new TemplateURL(); t_url->SetURL("http://test1/{searchTerms}", 0, 0); - t_url->set_keyword(ASCIIToUTF16("test1")); - t_url->set_short_name(ASCIIToUTF16("Test1")); + t_url->set_keyword(L"test1"); + t_url->set_short_name(L"Test1"); t_url->set_show_in_default_list(true); template_model->Add(t_url); t_url = new TemplateURL(); t_url->SetURL("http://test2/{searchTerms}", 0, 0); - t_url->set_keyword(ASCIIToUTF16("test2")); - t_url->set_short_name(ASCIIToUTF16("Test2")); + t_url->set_keyword(L"test2"); + t_url->set_short_name(L"Test2"); t_url->set_show_in_default_list(true); template_model->Add(t_url); diff --git a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm index f69951f..84b3518 100644 --- a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm +++ b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -527,8 +527,7 @@ NSPoint LocationBarViewMac::GetPageInfoBubblePoint() const { NSImage* LocationBarViewMac::GetKeywordImage(const std::wstring& keyword) { const TemplateURL* template_url = - profile_->GetTemplateURLModel()->GetTemplateURLForKeyword( - WideToUTF16Hack(keyword)); + profile_->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword); if (template_url && template_url->IsExtensionKeyword()) { const SkBitmap& bitmap = profile_->GetExtensionService()-> GetOmniboxIcon(template_url->GetExtensionId()); @@ -657,11 +656,11 @@ void LocationBarViewMac::Layout() { // Get the keyword to use for keyword-search and hinting. const std::wstring keyword(edit_view_->model()->keyword()); - string16 short_name; + std::wstring short_name; bool is_extension_keyword = false; if (!keyword.empty()) { short_name = profile_->GetTemplateURLModel()-> - GetKeywordShortName(WideToUTF16Hack(keyword), &is_extension_keyword); + GetKeywordShortName(keyword, &is_extension_keyword); } const bool is_keyword_hint = edit_view_->model()->is_keyword_hint(); @@ -670,8 +669,7 @@ void LocationBarViewMac::Layout() { // Switch from location icon to keyword mode. location_icon_decoration_->SetVisible(false); selected_keyword_decoration_->SetVisible(true); - selected_keyword_decoration_->SetKeyword(UTF16ToWideHack(short_name), - is_extension_keyword); + selected_keyword_decoration_->SetKeyword(short_name, is_extension_keyword); selected_keyword_decoration_->SetImage(GetKeywordImage(keyword)); } else if (toolbar_model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) { // Switch from location icon to show the EV bubble instead. @@ -681,7 +679,7 @@ void LocationBarViewMac::Layout() { std::wstring label(toolbar_model_->GetEVCertName()); ev_bubble_decoration_->SetFullLabel(base::SysWideToNSString(label)); } else if (!keyword.empty() && is_keyword_hint) { - keyword_hint_decoration_->SetKeyword(short_name, + keyword_hint_decoration_->SetKeyword(WideToUTF16Hack(short_name), is_extension_keyword); keyword_hint_decoration_->SetVisible(true); } diff --git a/chrome/browser/ui/cocoa/search_engine_dialog_controller.mm b/chrome/browser/ui/cocoa/search_engine_dialog_controller.mm index 699f342..fa53295 100644 --- a/chrome/browser/ui/cocoa/search_engine_dialog_controller.mm +++ b/chrome/browser/ui/cocoa/search_engine_dialog_controller.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -205,7 +205,7 @@ void SearchEngineDialogControllerBridge::OnTemplateURLModelChanged() { [logoView setEditable:NO]; // Tooltip text provides accessibility. - [logoView setToolTip:base::SysUTF16ToNSString(engine->short_name())]; + [logoView setToolTip:base::SysWideToNSString(engine->short_name())]; engineIdentifier = logoView; } else { // No logo -- we must show a text label. @@ -224,7 +224,7 @@ void SearchEngineDialogControllerBridge::OnTemplateURLModelChanged() { paragraphStyle.get(), NSParagraphStyleAttributeName, nil]; - NSString* value = base::SysUTF16ToNSString(engine->short_name()); + NSString* value = base::SysWideToNSString(engine->short_name()); scoped_nsobject<NSAttributedString> attrValue( [[NSAttributedString alloc] initWithString:value attributes:attrs]); diff --git a/chrome/browser/ui/cocoa/search_engine_list_model.mm b/chrome/browser/ui/cocoa/search_engine_list_model.mm index 8f80ce6..b79c882 100644 --- a/chrome/browser/ui/cocoa/search_engine_list_model.mm +++ b/chrome/browser/ui/cocoa/search_engine_list_model.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -79,7 +79,7 @@ class SearchEngineObserver : public TemplateURLModelObserver { TemplateURLs modelURLs = model_->GetTemplateURLs(); for (size_t i = 0; i < modelURLs.size(); ++i) { if (modelURLs[i]->ShowInDefaultList()) - [engines addObject:base::SysUTF16ToNSString(modelURLs[i]->short_name())]; + [engines addObject:base::SysWideToNSString(modelURLs[i]->short_name())]; } [self setSearchEngines:engines.get()]; diff --git a/chrome/browser/ui/cocoa/search_engine_list_model_unittest.mm b/chrome/browser/ui/cocoa/search_engine_list_model_unittest.mm index 64c173b..a59bcec 100644 --- a/chrome/browser/ui/cocoa/search_engine_list_model_unittest.mm +++ b/chrome/browser/ui/cocoa/search_engine_list_model_unittest.mm @@ -1,9 +1,8 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "base/scoped_nsobject.h" -#include "base/utf_string_conversions.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_model.h" @@ -33,14 +32,14 @@ class SearchEngineListModelTest : public PlatformTest { template_model_.reset(new TemplateURLModel(helper_.profile())); TemplateURL* t_url = new TemplateURL(); t_url->SetURL("http://www.google.com/?q={searchTerms}", 0, 0); - t_url->set_keyword(ASCIIToUTF16("keyword")); - t_url->set_short_name(ASCIIToUTF16("google")); + t_url->set_keyword(L"keyword"); + t_url->set_short_name(L"google"); t_url->set_show_in_default_list(true); template_model_->Add(t_url); t_url = new TemplateURL(); t_url->SetURL("http://www.google2.com/?q={searchTerms}", 0, 0); - t_url->set_keyword(ASCIIToUTF16("keyword2")); - t_url->set_short_name(ASCIIToUTF16("google2")); + t_url->set_keyword(L"keyword2"); + t_url->set_short_name(L"google2"); t_url->set_show_in_default_list(true); template_model_->Add(t_url); EXPECT_EQ(template_model_->GetTemplateURLs().size(), 2U); @@ -84,14 +83,14 @@ TEST_F(SearchEngineListModelTest, Default) { // Add two more URLs, neither of which are shown in the default list. TemplateURL* t_url = new TemplateURL(); t_url->SetURL("http://www.google3.com/?q={searchTerms}", 0, 0); - t_url->set_keyword(ASCIIToUTF16("keyword3")); - t_url->set_short_name(ASCIIToUTF16("google3 not eligible")); + t_url->set_keyword(L"keyword3"); + t_url->set_short_name(L"google3 not eligible"); t_url->set_show_in_default_list(false); template_model_->Add(t_url); t_url = new TemplateURL(); t_url->SetURL("http://www.google4.com/?q={searchTerms}", 0, 0); - t_url->set_keyword(ASCIIToUTF16("keyword4")); - t_url->set_short_name(ASCIIToUTF16("google4")); + t_url->set_keyword(L"keyword4"); + t_url->set_short_name(L"google4"); t_url->set_show_in_default_list(false); template_model_->Add(t_url); @@ -117,14 +116,14 @@ TEST_F(SearchEngineListModelTest, DefaultChosenFromUI) { // Add two more URLs, the first one not shown in the default list. TemplateURL* t_url = new TemplateURL(); t_url->SetURL("http://www.google3.com/?q={searchTerms}", 0, 0); - t_url->set_keyword(ASCIIToUTF16("keyword3")); - t_url->set_short_name(ASCIIToUTF16("google3 not eligible")); + t_url->set_keyword(L"keyword3"); + t_url->set_short_name(L"google3 not eligible"); t_url->set_show_in_default_list(false); template_model_->Add(t_url); t_url = new TemplateURL(); t_url->SetURL("http://www.google4.com/?q={searchTerms}", 0, 0); - t_url->set_keyword(ASCIIToUTF16("keyword4")); - t_url->set_short_name(ASCIIToUTF16("google4")); + t_url->set_keyword(L"keyword4"); + t_url->set_short_name(L"google4"); t_url->set_show_in_default_list(true); template_model_->Add(t_url); @@ -144,8 +143,8 @@ TEST_F(SearchEngineListModelTest, Notification) { // Add one more item to force a notification. TemplateURL* t_url = new TemplateURL(); t_url->SetURL("http://www.google3.com/foo/bar", 0, 0); - t_url->set_keyword(ASCIIToUTF16("keyword3")); - t_url->set_short_name(ASCIIToUTF16("google3")); + t_url->set_keyword(L"keyword3"); + t_url->set_short_name(L"google3"); t_url->set_show_in_default_list(true); template_model_->Add(t_url); diff --git a/chrome/browser/ui/gtk/edit_search_engine_dialog.cc b/chrome/browser/ui/gtk/edit_search_engine_dialog.cc index f2fd6e9..0903040 100644 --- a/chrome/browser/ui/gtk/edit_search_engine_dialog.cc +++ b/chrome/browser/ui/gtk/edit_search_engine_dialog.cc @@ -26,7 +26,7 @@ namespace { std::string GetDisplayURL(const TemplateURL& turl) { - return turl.url() ? UTF16ToUTF8(turl.url()->DisplayURL()) : std::string(); + return turl.url() ? WideToUTF8(turl.url()->DisplayURL()) : std::string(); } // Forces text to lowercase when connected to an editable's "insert-text" @@ -158,10 +158,10 @@ void EditSearchEngineDialog::Init(GtkWindow* parent_window, Profile* profile) { if (controller_->template_url()) { gtk_entry_set_text( GTK_ENTRY(title_entry_), - UTF16ToUTF8(controller_->template_url()->short_name()).c_str()); + WideToUTF8(controller_->template_url()->short_name()).c_str()); gtk_entry_set_text( GTK_ENTRY(keyword_entry_), - UTF16ToUTF8(controller_->template_url()->keyword()).c_str()); + WideToUTF8(controller_->template_url()->keyword()).c_str()); gtk_entry_set_text( GTK_ENTRY(url_entry_), GetDisplayURL(*controller_->template_url()).c_str()); diff --git a/chrome/browser/ui/gtk/first_run_dialog.cc b/chrome/browser/ui/gtk/first_run_dialog.cc index eee9a13..5994a84 100644 --- a/chrome/browser/ui/gtk/first_run_dialog.cc +++ b/chrome/browser/ui/gtk/first_run_dialog.cc @@ -342,7 +342,7 @@ void FirstRunDialog::OnTemplateURLModelChanged() { GtkWidget* logo_label = gtk_label_new(NULL); char* markup = g_markup_printf_escaped( "<span weight='bold' size='x-large' color='black'>%s</span>", - UTF16ToUTF8((*search_engine_iter)->short_name()).c_str()); + WideToUTF8((*search_engine_iter)->short_name()).c_str()); gtk_label_set_markup(GTK_LABEL(logo_label), markup); g_free(markup); gtk_widget_set_size_request(logo_label, -1, diff --git a/chrome/browser/ui/gtk/keyword_editor_view_unittest.cc b/chrome/browser/ui/gtk/keyword_editor_view_unittest.cc index acc4e07..5f4043a 100644 --- a/chrome/browser/ui/gtk/keyword_editor_view_unittest.cc +++ b/chrome/browser/ui/gtk/keyword_editor_view_unittest.cc @@ -30,8 +30,8 @@ class KeywordEditorViewTest : public testing::Test { const std::string& keyword, bool make_default) { TemplateURL* template_url = new TemplateURL(); - template_url->set_short_name(UTF8ToUTF16(name)); - template_url->set_keyword(UTF8ToUTF16(keyword)); + template_url->set_short_name(UTF8ToWide(name)); + template_url->set_keyword(UTF8ToWide(keyword)); template_url->SetURL("http://example.com/{searchTerms}", 0, 0); profile_->GetTemplateURLModel()->Add(template_url); if (make_default) diff --git a/chrome/browser/ui/gtk/location_bar_view_gtk.cc b/chrome/browser/ui/gtk/location_bar_view_gtk.cc index 337036d..982af73 100644 --- a/chrome/browser/ui/gtk/location_bar_view_gtk.cc +++ b/chrome/browser/ui/gtk/location_bar_view_gtk.cc @@ -983,16 +983,15 @@ void LocationBarViewGtk::SetKeywordLabel(const std::wstring& keyword) { return; bool is_extension_keyword; - const string16 short_name = profile_->GetTemplateURLModel()-> - GetKeywordShortName(WideToUTF16Hack(keyword), &is_extension_keyword); + const std::wstring short_name = profile_->GetTemplateURLModel()-> + GetKeywordShortName(keyword, &is_extension_keyword); int message_id = is_extension_keyword ? IDS_OMNIBOX_EXTENSION_KEYWORD_TEXT : IDS_OMNIBOX_KEYWORD_TEXT; string16 full_name = l10n_util::GetStringFUTF16(message_id, - short_name); + WideToUTF16Hack(short_name)); string16 partial_name = l10n_util::GetStringFUTF16( message_id, - WideToUTF16Hack( - location_bar_util::CalculateMinString(UTF16ToWideHack(short_name)))); + WideToUTF16Hack(location_bar_util::CalculateMinString(short_name))); gtk_label_set_text(GTK_LABEL(tab_to_search_full_label_), UTF16ToUTF8(full_name).c_str()); gtk_label_set_text(GTK_LABEL(tab_to_search_partial_label_), @@ -1003,8 +1002,7 @@ void LocationBarViewGtk::SetKeywordLabel(const std::wstring& keyword) { if (is_extension_keyword) { const TemplateURL* template_url = - profile_->GetTemplateURLModel()->GetTemplateURLForKeyword( - WideToUTF16Hack(keyword)); + profile_->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword); const SkBitmap& bitmap = profile_->GetExtensionService()-> GetOmniboxIcon(template_url->GetExtensionId()); GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&bitmap); @@ -1027,15 +1025,15 @@ void LocationBarViewGtk::SetKeywordHintLabel(const std::wstring& keyword) { return; bool is_extension_keyword; - const string16 short_name = profile_->GetTemplateURLModel()-> - GetKeywordShortName(WideToUTF16Hack(keyword), &is_extension_keyword); + const std::wstring short_name = profile_->GetTemplateURLModel()-> + GetKeywordShortName(keyword, &is_extension_keyword); int message_id = is_extension_keyword ? IDS_OMNIBOX_EXTENSION_KEYWORD_HINT : IDS_OMNIBOX_KEYWORD_HINT; std::vector<size_t> content_param_offsets; const string16 keyword_hint = l10n_util::GetStringFUTF16( message_id, string16(), - short_name, + WideToUTF16Hack(short_name), &content_param_offsets); if (content_param_offsets.size() != 2) { // See comments on an identical NOTREACHED() in search_provider.cc. diff --git a/chrome/browser/ui/gtk/options/general_page_gtk.cc b/chrome/browser/ui/gtk/options/general_page_gtk.cc index 84e35db..c541eab 100644 --- a/chrome/browser/ui/gtk/options/general_page_gtk.cc +++ b/chrome/browser/ui/gtk/options/general_page_gtk.cc @@ -686,7 +686,7 @@ void GeneralPageGtk::OnTemplateURLModelChanged() { default_search_engines_model_, &iter, SEARCH_ENGINES_COL_INDEX, i, SEARCH_ENGINES_COL_TITLE, - UTF16ToUTF8(model_urls[i]->short_name()).c_str(), + WideToUTF8(model_urls[i]->short_name()).c_str(), -1); if (model_urls[i] == default_search_provider) { gtk_combo_box_set_active_iter( diff --git a/chrome/browser/ui/omnibox/location_bar_util.cc b/chrome/browser/ui/omnibox/location_bar_util.cc index efb9a3c..a5e9404 100644 --- a/chrome/browser/ui/omnibox/location_bar_util.cc +++ b/chrome/browser/ui/omnibox/location_bar_util.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -18,10 +18,9 @@ std::wstring GetKeywordName(Profile* profile, const std::wstring& keyword) { // TODO(sky): Once LocationBarView adds a listener to the TemplateURLModel // to track changes to the model, this should become a DCHECK. const TemplateURL* template_url = - profile->GetTemplateURLModel()->GetTemplateURLForKeyword( - WideToUTF16Hack(keyword)); + profile->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword); if (template_url) - return UTF16ToWideHack(template_url->AdjustedShortNameForLocaleDirection()); + return template_url->AdjustedShortNameForLocaleDirection(); return std::wstring(); } diff --git a/chrome/browser/ui/views/location_bar/keyword_hint_view.cc b/chrome/browser/ui/views/location_bar/keyword_hint_view.cc index 4b1d1496..305279c 100644 --- a/chrome/browser/ui/views/location_bar/keyword_hint_view.cc +++ b/chrome/browser/ui/views/location_bar/keyword_hint_view.cc @@ -58,15 +58,15 @@ void KeywordHintView::SetKeyword(const std::wstring& keyword) { std::vector<size_t> content_param_offsets; bool is_extension_keyword; - string16 short_name = profile_->GetTemplateURLModel()-> - GetKeywordShortName(WideToUTF16Hack(keyword), &is_extension_keyword); + std::wstring short_name = profile_->GetTemplateURLModel()-> + GetKeywordShortName(keyword, &is_extension_keyword); int message_id = is_extension_keyword ? IDS_OMNIBOX_EXTENSION_KEYWORD_HINT : IDS_OMNIBOX_KEYWORD_HINT; const std::wstring keyword_hint = UTF16ToWide(l10n_util::GetStringFUTF16( message_id, string16(), - short_name, + WideToUTF16(short_name), &content_param_offsets)); if (content_param_offsets.size() == 2) { leading_label_->SetText( diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc index 4d2723b..8a40202 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.cc +++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc @@ -516,8 +516,7 @@ void LocationBarView::Layout() { if (selected_keyword_view_->keyword() != keyword) { selected_keyword_view_->SetKeyword(keyword); const TemplateURL* template_url = - profile_->GetTemplateURLModel()->GetTemplateURLForKeyword( - WideToUTF16Hack(keyword)); + profile_->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword); if (template_url && template_url->IsExtensionKeyword()) { const SkBitmap& bitmap = profile_->GetExtensionService()-> GetOmniboxIcon(template_url->GetExtensionId()); diff --git a/chrome/browser/ui/views/location_bar/selected_keyword_view.cc b/chrome/browser/ui/views/location_bar/selected_keyword_view.cc index 408c436..7ca3b03c 100644 --- a/chrome/browser/ui/views/location_bar/selected_keyword_view.cc +++ b/chrome/browser/ui/views/location_bar/selected_keyword_view.cc @@ -59,8 +59,8 @@ void SelectedKeywordView::SetKeyword(const std::wstring& keyword) { return; bool is_extension_keyword; - const string16 short_name = profile_->GetTemplateURLModel()-> - GetKeywordShortName(WideToUTF16Hack(keyword), &is_extension_keyword); + const string16 short_name = WideToUTF16(profile_->GetTemplateURLModel()-> + GetKeywordShortName(keyword, &is_extension_keyword)); int message_id = is_extension_keyword ? IDS_OMNIBOX_EXTENSION_KEYWORD_TEXT : IDS_OMNIBOX_KEYWORD_TEXT; full_label_.SetText(UTF16ToWide( diff --git a/chrome/browser/webdata/web_database.cc b/chrome/browser/webdata/web_database.cc index 6e4a3fb..2400c04 100644 --- a/chrome/browser/webdata/web_database.cc +++ b/chrome/browser/webdata/web_database.cc @@ -179,8 +179,8 @@ const char* kBuiltinKeywordVersion = "Builtin Keyword Version"; const size_t kMaxDataLength = 1024; void BindURLToStatement(const TemplateURL& url, sql::Statement* s) { - s->BindString(0, UTF16ToUTF8(url.short_name())); - s->BindString(1, UTF16ToUTF8(url.keyword())); + s->BindString(0, WideToUTF8(url.short_name())); + s->BindString(1, WideToUTF8(url.keyword())); GURL favicon_url = url.GetFavIconURL(); if (!favicon_url.is_valid()) { s->BindString(2, std::string()); @@ -866,9 +866,9 @@ bool WebDatabase::GetKeywords(std::vector<TemplateURL*>* urls) { std::string tmp; tmp = s.ColumnString(1); DCHECK(!tmp.empty()); - template_url->set_short_name(UTF8ToUTF16(tmp)); + template_url->set_short_name(UTF8ToWide(tmp)); - template_url->set_keyword(UTF8ToUTF16(s.ColumnString(2))); + template_url->set_keyword(UTF8ToWide(s.ColumnString(2))); tmp = s.ColumnString(3); if (!tmp.empty()) @@ -2203,8 +2203,8 @@ sql::InitStatus WebDatabase::MigrateOldVersionsAsNeeded(){ "INSERT INTO credit_cards_temp " "SELECT label,unique_id,name_on_card,type,card_number," "expiration_month,expiration_year,verification_code,0," - "shipping_address,card_number_encrypted," - "verification_code_encrypted FROM credit_cards")) { + "shipping_address,card_number_encrypted,verification_code_encrypted " + "FROM credit_cards")) { LOG(WARNING) << "Unable to update web database to version 27."; NOTREACHED(); return sql::INIT_FAILURE; @@ -2509,8 +2509,8 @@ sql::InitStatus WebDatabase::MigrateOldVersionsAsNeeded(){ if (!db_.Execute( "INSERT INTO autofill_profiles_temp " "SELECT guid, label, first_name, middle_name, last_name, email, " - "company_name, address_line_1, address_line_2, city, state, " - "zipcode, country, phone, fax, date_modified " + "company_name, address_line_1, address_line_2, city, state, zipcode, " + "country, phone, fax, date_modified " "FROM autofill_profiles")) { LOG(WARNING) << "Unable to update web database to version 32."; NOTREACHED(); diff --git a/chrome/browser/webdata/web_database_unittest.cc b/chrome/browser/webdata/web_database_unittest.cc index 41489e9..dc38100 100644 --- a/chrome/browser/webdata/web_database_unittest.cc +++ b/chrome/browser/webdata/web_database_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -305,8 +305,8 @@ TEST_F(WebDatabaseTest, Keywords) { ASSERT_EQ(sql::INIT_OK, db.Init(file_)); TemplateURL template_url; - template_url.set_short_name(ASCIIToUTF16("short_name")); - template_url.set_keyword(ASCIIToUTF16("keyword")); + template_url.set_short_name(L"short_name"); + template_url.set_keyword(L"keyword"); GURL favicon_url("http://favicon.url/"); GURL originating_url("http://google.com/"); template_url.SetFavIconURL(favicon_url); @@ -398,8 +398,8 @@ TEST_F(WebDatabaseTest, UpdateKeyword) { ASSERT_EQ(sql::INIT_OK, db.Init(file_)); TemplateURL template_url; - template_url.set_short_name(ASCIIToUTF16("short_name")); - template_url.set_keyword(ASCIIToUTF16("keyword")); + template_url.set_short_name(L"short_name"); + template_url.set_keyword(L"keyword"); GURL favicon_url("http://favicon.url/"); GURL originating_url("http://originating.url/"); template_url.SetFavIconURL(favicon_url); @@ -414,7 +414,7 @@ TEST_F(WebDatabaseTest, UpdateKeyword) { GURL originating_url2("http://originating.url/"); template_url.set_originating_url(originating_url2); template_url.set_autogenerate_keyword(true); - EXPECT_EQ(ASCIIToUTF16("url"), template_url.keyword()); + EXPECT_EQ(L"url", template_url.keyword()); template_url.add_input_encoding("Shift_JIS"); set_prepopulate_id(&template_url, 5); set_logo_id(&template_url, 2000); @@ -468,8 +468,8 @@ TEST_F(WebDatabaseTest, KeywordWithNoFavicon) { ASSERT_EQ(sql::INIT_OK, db.Init(file_)); TemplateURL template_url; - template_url.set_short_name(ASCIIToUTF16("short_name")); - template_url.set_keyword(ASCIIToUTF16("keyword")); + template_url.set_short_name(L"short_name"); + template_url.set_keyword(L"keyword"); template_url.SetURL("http://url/", 0, 0); template_url.set_safe_for_autoreplace(true); SetID(-100, &template_url); diff --git a/net/base/escape.cc b/net/base/escape.cc index ae8411b..5479b82 100644 --- a/net/base/escape.cc +++ b/net/base/escape.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -192,9 +192,9 @@ std::string EscapeQueryParamValue(const std::string& text, bool use_plus) { // Convert the string to a sequence of bytes and then % escape anything // except alphanumerics and !'()*-._~ -string16 EscapeQueryParamValueUTF8(const string16& text, - bool use_plus) { - return UTF8ToUTF16(Escape(UTF16ToUTF8(text), kQueryCharmap, use_plus)); +std::wstring EscapeQueryParamValueUTF8(const std::wstring& text, + bool use_plus) { + return UTF8ToWide(Escape(WideToUTF8(text), kQueryCharmap, use_plus)); } // non-printable, non-7bit, and (including space) "#%:<>?[\]^`{|} diff --git a/net/base/escape.h b/net/base/escape.h index faa7bd3..39447a5 100644 --- a/net/base/escape.h +++ b/net/base/escape.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -125,8 +125,8 @@ std::string EscapeQueryParamValue(const std::string& text, bool use_plus); bool EscapeQueryParamValue(const string16& text, const char* codepage, bool use_plus, string16* escaped); -// A specialized version of EscapeQueryParamValue for string16s that +// A specialized version of EscapeQueryParamValue for wide strings that // assumes the codepage is UTF8. This is provided as a convenience. -string16 EscapeQueryParamValueUTF8(const string16& text, bool use_plus); +std::wstring EscapeQueryParamValueUTF8(const std::wstring& text, bool use_plus); #endif // NET_BASE_ESCAPE_H_ diff --git a/net/base/escape_unittest.cc b/net/base/escape_unittest.cc index 60d4ae3..04a040e 100644 --- a/net/base/escape_unittest.cc +++ b/net/base/escape_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -66,8 +66,7 @@ TEST(EscapeTest, EscapeTextForFormSubmission) { }; for (size_t i = 0; i < arraysize(escape_cases); ++i) { EscapeCase value = escape_cases[i]; - EXPECT_EQ(WideToUTF16Hack(value.output), - EscapeQueryParamValueUTF8(WideToUTF16Hack(value.input), true)); + EXPECT_EQ(value.output, EscapeQueryParamValueUTF8(value.input, true)); } const EscapeCase escape_cases_no_plus[] = { @@ -77,8 +76,7 @@ TEST(EscapeTest, EscapeTextForFormSubmission) { }; for (size_t i = 0; i < arraysize(escape_cases_no_plus); ++i) { EscapeCase value = escape_cases_no_plus[i]; - EXPECT_EQ(WideToUTF16Hack(value.output), - EscapeQueryParamValueUTF8(WideToUTF16Hack(value.input), false)); + EXPECT_EQ(value.output, EscapeQueryParamValueUTF8(value.input, false)); } // Test all the values in we're supposed to be escaping. @@ -116,10 +114,12 @@ TEST(EscapeTest, EscapeTextForFormSubmission) { string16 wide; EXPECT_TRUE(EscapeQueryParamValue(test_str, base::kCodepageUTF8, true, &wide)); - EXPECT_EQ(wide, EscapeQueryParamValueUTF8(test_str, true)); + EXPECT_EQ(UTF16ToWideHack(wide), + EscapeQueryParamValueUTF8(UTF16ToWideHack(test_str), true)); EXPECT_TRUE(EscapeQueryParamValue(test_str, base::kCodepageUTF8, false, &wide)); - EXPECT_EQ(wide, EscapeQueryParamValueUTF8(test_str, false)); + EXPECT_EQ(UTF16ToWideHack(wide), + EscapeQueryParamValueUTF8(UTF16ToWideHack(test_str), false)); } TEST(EscapeTest, EscapePath) { |