diff options
84 files changed, 1212 insertions, 1312 deletions
diff --git a/chrome/browser/autocomplete/autocomplete.cc b/chrome/browser/autocomplete/autocomplete.cc index d624d37..ab47a12 100644 --- a/chrome/browser/autocomplete/autocomplete.cc +++ b/chrome/browser/autocomplete/autocomplete.cc @@ -51,8 +51,8 @@ AutocompleteInput::AutocompleteInput() synchronous_only_(false) { } -AutocompleteInput::AutocompleteInput(const string16& text, - const string16& desired_tld, +AutocompleteInput::AutocompleteInput(const std::wstring& text, + const std::wstring& desired_tld, bool prevent_inline_autocomplete, bool prefer_keyword, bool allow_exact_keyword_match, @@ -88,7 +88,7 @@ AutocompleteInput::~AutocompleteInput() { // static void AutocompleteInput::RemoveForcedQueryStringIfNecessary(Type type, - string16* text) { + std::wstring* text) { if (type == FORCED_QUERY && !text->empty() && (*text)[0] == L'?') text->erase(0, 1); } @@ -111,13 +111,13 @@ std::string AutocompleteInput::TypeToString(Type type) { // static AutocompleteInput::Type AutocompleteInput::Parse( - const string16& text, - const string16& desired_tld, + const std::wstring& text, + const std::wstring& desired_tld, url_parse::Parsed* parts, - string16* scheme, + std::wstring* scheme, GURL* canonicalized_url) { - const size_t first_non_white = text.find_first_not_of(kWhitespaceUTF16, 0); - if (first_non_white == string16::npos) + const size_t first_non_white = text.find_first_not_of(kWhitespaceWide, 0); + if (first_non_white == std::wstring::npos) return INVALID; // All whitespace. if (text.at(first_non_white) == L'?') { @@ -133,15 +133,15 @@ AutocompleteInput::Type AutocompleteInput::Parse( url_parse::Parsed local_parts; if (!parts) parts = &local_parts; - const string16 parsed_scheme(URLFixerUpper::SegmentURL(text, parts)); + const std::wstring parsed_scheme(URLFixerUpper::SegmentURL(text, parts)); if (scheme) *scheme = parsed_scheme; if (canonicalized_url) { - *canonicalized_url = URLFixerUpper::FixupURL(UTF16ToUTF8(text), - UTF16ToUTF8(desired_tld)); + *canonicalized_url = URLFixerUpper::FixupURL(WideToUTF8(text), + WideToUTF8(desired_tld)); } - if (LowerCaseEqualsASCII(parsed_scheme, chrome::kFileScheme)) { + if (parsed_scheme == L"file") { // A user might or might not type a scheme when entering a file URL. In // either case, |parsed_scheme| will tell us that this is a file URL, but // |parts->scheme| might be empty, e.g. if the user typed "C:\foo". @@ -155,10 +155,9 @@ AutocompleteInput::Type AutocompleteInput::Parse( // (e.g. "ftp" or "view-source") but I'll wait to spend the effort on that // until I run into some cases that really need it. if (parts->scheme.is_nonempty() && - !LowerCaseEqualsASCII(parsed_scheme, chrome::kHttpScheme) && - !LowerCaseEqualsASCII(parsed_scheme, chrome::kHttpsScheme)) { + (parsed_scheme != L"http") && (parsed_scheme != L"https")) { // See if we know how to handle the URL internally. - if (net::URLRequest::IsHandledProtocol(UTF16ToASCII(parsed_scheme))) + if (net::URLRequest::IsHandledProtocol(WideToASCII(parsed_scheme))) return URL; // There are also some schemes that we convert to other things before they @@ -176,9 +175,7 @@ AutocompleteInput::Type AutocompleteInput::Parse( // "blocked" by the external protocol handler because we don't want pages to // open them, but users still can. // TODO(viettrungluu): get rid of conversion. - ExternalProtocolHandler::BlockState block_state = - ExternalProtocolHandler::GetBlockState(UTF16ToUTF8(parsed_scheme)); - switch (block_state) { + switch (ExternalProtocolHandler::GetBlockState(WideToUTF8(parsed_scheme))) { case ExternalProtocolHandler::DONT_BLOCK: return URL; @@ -190,16 +187,14 @@ AutocompleteInput::Type AutocompleteInput::Parse( default: { // We don't know about this scheme. It might be that the user typed a // URL of the form "username:password@foo.com". - const string16 http_scheme_prefix = - ASCIIToUTF16(std::string(chrome::kHttpScheme) + - chrome::kStandardSchemeSeparator); + const std::wstring http_scheme_prefix = L"http://"; url_parse::Parsed http_parts; - string16 http_scheme; + std::wstring http_scheme; GURL http_canonicalized_url; Type http_type = Parse(http_scheme_prefix + text, desired_tld, &http_parts, &http_scheme, &http_canonicalized_url); - DCHECK_EQ(std::string(chrome::kHttpScheme), UTF16ToUTF8(http_scheme)); + DCHECK_EQ("http", WideToUTF8(http_scheme)); if ((http_type == URL || http_type == REQUESTED_URL) && http_parts.username.is_nonempty() && @@ -251,19 +246,18 @@ AutocompleteInput::Type AutocompleteInput::Parse( // Likewise, the RCDS can reject certain obviously-invalid hosts. (We also // use the registry length later below.) - const string16 host(text.substr(parts->host.begin, parts->host.len)); + const std::wstring host(text.substr(parts->host.begin, parts->host.len)); const size_t registry_length = - net::RegistryControlledDomainService::GetRegistryLength(UTF16ToUTF8(host), - false); - if (registry_length == std::string::npos) { + net::RegistryControlledDomainService::GetRegistryLength(host, false); + if (registry_length == std::wstring::npos) { // Try to append the desired_tld. if (!desired_tld.empty()) { - string16 host_with_tld(host); + std::wstring host_with_tld(host); if (host[host.length() - 1] != '.') host_with_tld += '.'; host_with_tld += desired_tld; if (net::RegistryControlledDomainService::GetRegistryLength( - UTF16ToUTF8(host_with_tld), false) != std::string::npos) + host_with_tld, false) != std::wstring::npos) return REQUESTED_URL; // Something like "99999999999" that looks like a // bad IP address, but becomes valid on attaching // a TLD. @@ -277,11 +271,10 @@ AutocompleteInput::Type AutocompleteInput::Parse( // unlikely that a user would be trying to type those in for anything other // than a search query. url_canon::CanonHostInfo host_info; - const std::string canonicalized_host(net::CanonicalizeHost(UTF16ToUTF8(host), - &host_info)); + const std::string canonicalized_host(net::CanonicalizeHost(host, &host_info)); if ((host_info.family == url_canon::CanonHostInfo::NEUTRAL) && !net::IsCanonicalizedHostCompliant(canonicalized_host, - UTF16ToUTF8(desired_tld))) { + WideToUTF8(desired_tld))) { // Invalid hostname. There are several possible cases: // * Our checker is too strict and the user pasted in a real-world URL // that's "invalid" but resolves. To catch these, we return UNKNOWN when @@ -301,7 +294,7 @@ AutocompleteInput::Type AutocompleteInput::Parse( // TLD // These are rare, though probably possible in intranets. return (parts->scheme.is_nonempty() || - ((registry_length != 0) && (host.find(' ') == string16::npos))) ? + ((registry_length != 0) && (host.find(' ') == std::wstring::npos))) ? UNKNOWN : QUERY; } @@ -313,8 +306,8 @@ AutocompleteInput::Type AutocompleteInput::Parse( // below. if (parts->port.is_nonempty()) { int port; - if (!base::StringToInt(text.substr(parts->port.begin, parts->port.len), - &port) || + if (!base::StringToInt(WideToUTF8( + text.substr(parts->port.begin, parts->port.len)), &port) || (port < 0) || (port > 65535)) return QUERY; } @@ -363,7 +356,7 @@ AutocompleteInput::Type AutocompleteInput::Parse( // since that's the common case. return ((registry_length == 0) && (text.substr(parts->path.begin, parts->path.len).find(' ') != - string16::npos)) ? UNKNOWN : URL; + std::wstring::npos)) ? UNKNOWN : URL; } // If we reach here with a username, our input looks like "user@host". @@ -399,12 +392,12 @@ AutocompleteInput::Type AutocompleteInput::Parse( // static void AutocompleteInput::ParseForEmphasizeComponents( - const string16& text, - const string16& desired_tld, + const std::wstring& text, + const std::wstring& desired_tld, url_parse::Component* scheme, url_parse::Component* host) { url_parse::Parsed parts; - string16 scheme_str; + std::wstring scheme_str; Parse(text, desired_tld, &parts, &scheme_str, NULL); *scheme = parts.scheme; @@ -416,7 +409,7 @@ void AutocompleteInput::ParseForEmphasizeComponents( if (LowerCaseEqualsASCII(scheme_str, chrome::kViewSourceScheme) && (static_cast<int>(text.length()) > after_scheme_and_colon)) { // Obtain the URL prefixed by view-source and parse it. - string16 real_url(text.substr(after_scheme_and_colon)); + std::wstring real_url(text.substr(after_scheme_and_colon)); url_parse::Parsed real_parts; AutocompleteInput::Parse(real_url, desired_tld, &real_parts, NULL, NULL); if (real_parts.scheme.is_nonempty() || real_parts.host.is_nonempty()) { @@ -439,15 +432,15 @@ void AutocompleteInput::ParseForEmphasizeComponents( } // static -string16 AutocompleteInput::FormattedStringWithEquivalentMeaning( +std::wstring AutocompleteInput::FormattedStringWithEquivalentMeaning( const GURL& url, - const string16& formatted_url) { + const std::wstring& formatted_url) { if (!net::CanStripTrailingSlash(url)) return formatted_url; - const string16 url_with_path(formatted_url + char16('/')); - return (AutocompleteInput::Parse(formatted_url, string16(), NULL, NULL, + const std::wstring url_with_path(formatted_url + L"/"); + return (AutocompleteInput::Parse(formatted_url, std::wstring(), NULL, NULL, NULL) == - AutocompleteInput::Parse(url_with_path, string16(), NULL, NULL, + AutocompleteInput::Parse(url_with_path, std::wstring(), NULL, NULL, NULL)) ? formatted_url : url_with_path; } @@ -508,8 +501,8 @@ AutocompleteProvider::~AutocompleteProvider() { } // static -bool AutocompleteProvider::HasHTTPScheme(const string16& input) { - std::string utf8_input(UTF16ToUTF8(input)); +bool AutocompleteProvider::HasHTTPScheme(const std::wstring& input) { + std::string utf8_input(WideToUTF8(input)); url_parse::Component scheme; if (url_util::FindAndCompareScheme(utf8_input, chrome::kViewSourceScheme, &scheme)) @@ -531,16 +524,16 @@ void AutocompleteProvider::UpdateStarredStateOfMatches() { i->starred = bookmark_model->IsBookmarked(GURL(i->destination_url)); } -string16 AutocompleteProvider::StringForURLDisplay(const GURL& url, - bool check_accept_lang, - bool trim_http) const { +std::wstring AutocompleteProvider::StringForURLDisplay(const GURL& url, + bool check_accept_lang, + bool trim_http) const { std::string languages = (check_accept_lang && profile_) ? profile_->GetPrefs()->GetString(prefs::kAcceptLanguages) : std::string(); - return net::FormatUrl( + return UTF16ToWideHack(net::FormatUrl( url, languages, net::kFormatUrlOmitAll & ~(trim_http ? 0 : net::kFormatUrlOmitHTTP), - UnescapeRule::SPACES, NULL, NULL, NULL); + UnescapeRule::SPACES, NULL, NULL, NULL)); } // AutocompleteResult --------------------------------------------------------- @@ -720,13 +713,13 @@ void AutocompleteController::SetProfile(Profile* profile) { // different profile. } -void AutocompleteController::Start(const string16& text, - const string16& desired_tld, +void AutocompleteController::Start(const std::wstring& text, + const std::wstring& desired_tld, bool prevent_inline_autocomplete, bool prefer_keyword, bool allow_exact_keyword_match, bool synchronous_only) { - const string16 old_input_text(input_.text()); + const std::wstring old_input_text(input_.text()); const bool old_synchronous_only = input_.synchronous_only(); input_ = AutocompleteInput(text, desired_tld, prevent_inline_autocomplete, prefer_keyword, allow_exact_keyword_match, synchronous_only); diff --git a/chrome/browser/autocomplete/autocomplete.h b/chrome/browser/autocomplete/autocomplete.h index 7853f5aa..19a3722 100644 --- a/chrome/browser/autocomplete/autocomplete.h +++ b/chrome/browser/autocomplete/autocomplete.h @@ -11,7 +11,6 @@ #include "base/logging.h" #include "base/ref_counted.h" -#include "base/string16.h" #include "base/timer.h" #include "googleurl/src/gurl.h" #include "googleurl/src/url_parse.h" @@ -181,8 +180,8 @@ class AutocompleteInput { }; AutocompleteInput(); - AutocompleteInput(const string16& text, - const string16& desired_tld, + AutocompleteInput(const std::wstring& text, + const std::wstring& desired_tld, bool prevent_inline_autocomplete, bool prefer_keyword, bool allow_exact_keyword_match, @@ -190,7 +189,7 @@ class AutocompleteInput { ~AutocompleteInput(); // If type is |FORCED_QUERY| and |text| starts with '?', it is removed. - static void RemoveForcedQueryStringIfNecessary(Type type, string16* text); + static void RemoveForcedQueryStringIfNecessary(Type type, std::wstring* text); // Converts |type| to a string representation. Used in logging. static std::string TypeToString(Type type); @@ -200,18 +199,18 @@ class AutocompleteInput { // it is non-NULL. The scheme is stored in |scheme| if it is non-NULL. The // canonicalized URL is stored in |canonicalized_url|; however, this URL is // not guaranteed to be valid, especially if the parsed type is, e.g., QUERY. - static Type Parse(const string16& text, - const string16& desired_tld, + static Type Parse(const std::wstring& text, + const std::wstring& desired_tld, url_parse::Parsed* parts, - string16* scheme, + std::wstring* scheme, GURL* canonicalized_url); // Parses |text| and fill |scheme| and |host| by the positions of them. // The results are almost as same as the result of Parse(), but if the scheme // is view-source, this function returns the positions of scheme and host // in the URL qualified by "view-source:" prefix. - static void ParseForEmphasizeComponents(const string16& text, - const string16& desired_tld, + static void ParseForEmphasizeComponents(const std::wstring& text, + const std::wstring& desired_tld, url_parse::Component* scheme, url_parse::Component* host); @@ -221,23 +220,23 @@ class AutocompleteInput { // function with the URL and its formatted string, and it will return a // formatted string with the same meaning as the original URL (i.e. it will // re-append a slash if necessary). - static string16 FormattedStringWithEquivalentMeaning( + static std::wstring FormattedStringWithEquivalentMeaning( const GURL& url, - const string16& formatted_url); + const std::wstring& formatted_url); // User-provided text to be completed. - const string16& text() const { return text_; } + const std::wstring& text() const { return text_; } // Use of this setter is risky, since no other internal state is updated // besides |text_|. Only callers who know that they're not changing the // type/scheme/etc. should use this. - void set_text(const string16& text) { text_ = text; } + void set_text(const std::wstring& text) { text_ = text; } // User's desired TLD, if one is not already present in the text to // autocomplete. When this is non-empty, it also implies that "www." should // be prepended to the domain where possible. This should not have a leading // '.' (use "com" instead of ".com"). - const string16& desired_tld() const { return desired_tld_; } + const std::wstring& desired_tld() const { return desired_tld_; } // The type of input supplied. Type type() const { return type_; } @@ -247,7 +246,7 @@ class AutocompleteInput { // The scheme parsed from the provided text; only meaningful when type_ is // URL. - const string16& scheme() const { return scheme_; } + const std::wstring& scheme() const { return scheme_; } // The input as an URL to navigate to, if possible. const GURL& canonicalized_url() const { return canonicalized_url_; } @@ -286,11 +285,11 @@ class AutocompleteInput { void Clear(); private: - string16 text_; - string16 desired_tld_; + std::wstring text_; + std::wstring desired_tld_; Type type_; url_parse::Parsed parts_; - string16 scheme_; + std::wstring scheme_; GURL canonicalized_url_; bool initial_prevent_inline_autocomplete_; bool prevent_inline_autocomplete_; @@ -390,7 +389,7 @@ class AutocompleteProvider virtual ~AutocompleteProvider(); // Returns whether |input| begins "http:" or "view-source:http:". - static bool HasHTTPScheme(const string16& input); + static bool HasHTTPScheme(const std::wstring& input); // Updates the starred state of each of the matches in matches_ from the // profile's bookmark bar model. @@ -399,9 +398,9 @@ class AutocompleteProvider // A convenience function to call net::FormatUrl() with the current set of // "Accept Languages" when check_accept_lang is true. Otherwise, it's called // with an empty list. - string16 StringForURLDisplay(const GURL& url, - bool check_accept_lang, - bool trim_http) const; + std::wstring StringForURLDisplay(const GURL& url, + bool check_accept_lang, + bool trim_http) const; // The profile associated with the AutocompleteProvider. Reference is not // owned by us. @@ -586,8 +585,8 @@ class AutocompleteController : public ACProviderListener { // (even if the query completes synchronously). Listeners should use the // result set provided in the accompanying Details object to update // themselves. - void Start(const string16& text, - const string16& desired_tld, + void Start(const std::wstring& text, + const std::wstring& desired_tld, bool prevent_inline_autocomplete, bool prefer_keyword, bool allow_exact_keyword_match, @@ -700,7 +699,7 @@ class AutocompleteController : public ACProviderListener { // The data to log (via the metrics service) when the user selects an item // from the omnibox popup. struct AutocompleteLog { - AutocompleteLog(string16 text, + AutocompleteLog(std::wstring text, AutocompleteInput::Type input_type, size_t selected_index, size_t inline_autocompleted_length, @@ -712,7 +711,7 @@ struct AutocompleteLog { result(result) { } // The user's input text in the omnibox. - string16 text; + std::wstring text; // The detected type of the user's input. AutocompleteInput::Type input_type; // Selected index (if selected) or -1 (AutocompletePopupModel::kNoMatch). diff --git a/chrome/browser/autocomplete/autocomplete_accessibility.cc b/chrome/browser/autocomplete/autocomplete_accessibility.cc index 05cc6c0..bcf087dd 100644 --- a/chrome/browser/autocomplete/autocomplete_accessibility.cc +++ b/chrome/browser/autocomplete/autocomplete_accessibility.cc @@ -120,7 +120,7 @@ STDMETHODIMP AutocompleteAccessibility::get_accValue(VARIANT var_id, return E_INVALIDARG; } - string16 temp_value; + std::wstring temp_value; if (var_id.lVal != CHILDID_SELF) return E_INVALIDARG; diff --git a/chrome/browser/autocomplete/autocomplete_browsertest.cc b/chrome/browser/autocomplete/autocomplete_browsertest.cc index 437e574..1d695d2 100644 --- a/chrome/browser/autocomplete/autocomplete_browsertest.cc +++ b/chrome/browser/autocomplete/autocomplete_browsertest.cc @@ -32,16 +32,16 @@ namespace { -string16 AutocompleteResultAsString(const AutocompleteResult& result) { - std::string output(base::StringPrintf("{%lu} ", result.size())); +std::wstring AutocompleteResultAsString(const AutocompleteResult& result) { + std::wstring output(StringPrintf(L"{%d} ", result.size())); for (size_t i = 0; i < result.size(); ++i) { AutocompleteMatch match = result.match_at(i); - std::string provider_name = match.provider->name(); - output.append(base::StringPrintf("[\"%s\" by \"%s\"] ", - UTF16ToUTF8(match.contents).c_str(), - provider_name.c_str())); + std::wstring provider_name(ASCIIToWide(match.provider->name())); + output.append(StringPrintf(L"[\"%ls\" by \"%ls\"] ", + match.contents.c_str(), + provider_name.c_str())); } - return UTF8ToUTF16(output); + return output; } } // namespace @@ -62,7 +62,7 @@ IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, Basic) { LocationBar* location_bar = GetLocationBar(); EXPECT_TRUE(location_bar->GetInputString().empty()); - EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL), + EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), location_bar->location_entry()->GetText()); // TODO(phajdan.jr): check state of IsSelectAll when it's consistent across // platforms. @@ -70,28 +70,28 @@ IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, Basic) { location_bar->FocusLocation(true); EXPECT_TRUE(location_bar->GetInputString().empty()); - EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL), + EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), location_bar->location_entry()->GetText()); EXPECT_TRUE(location_bar->location_entry()->IsSelectAll()); - location_bar->location_entry()->SetUserText(ASCIIToUTF16("chrome")); + location_bar->location_entry()->SetUserText(L"chrome"); EXPECT_TRUE(location_bar->GetInputString().empty()); - EXPECT_EQ(ASCIIToUTF16("chrome"), location_bar->location_entry()->GetText()); + EXPECT_EQ(L"chrome", location_bar->location_entry()->GetText()); EXPECT_FALSE(location_bar->location_entry()->IsSelectAll()); location_bar->location_entry()->RevertAll(); EXPECT_TRUE(location_bar->GetInputString().empty()); - EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL), + EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), location_bar->location_entry()->GetText()); EXPECT_FALSE(location_bar->location_entry()->IsSelectAll()); - location_bar->location_entry()->SetUserText(ASCIIToUTF16("chrome")); + location_bar->location_entry()->SetUserText(L"chrome"); location_bar->Revert(); EXPECT_TRUE(location_bar->GetInputString().empty()); - EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL), + EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), location_bar->location_entry()->GetText()); EXPECT_FALSE(location_bar->location_entry()->IsSelectAll()); } @@ -105,7 +105,7 @@ IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, MAYBE_Autocomplete) { AutocompleteController* autocomplete_controller = GetAutocompleteController(); { - autocomplete_controller->Start(ASCIIToUTF16("chrome"), string16(), + autocomplete_controller->Start(L"chrome", std::wstring(), true, false, true, true); EXPECT_TRUE(autocomplete_controller->done()); @@ -123,7 +123,7 @@ IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, MAYBE_Autocomplete) { location_bar->Revert(); EXPECT_TRUE(location_bar->GetInputString().empty()); - EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL), + EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), location_bar->location_entry()->GetText()); EXPECT_FALSE(location_bar->location_entry()->IsSelectAll()); const AutocompleteResult& result = autocomplete_controller->result(); @@ -136,17 +136,17 @@ IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, TabAwayRevertSelect) { // Make sure that tabbing away from an empty omnibar causes a revert // and select all. LocationBar* location_bar = GetLocationBar(); - EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL), + EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), location_bar->location_entry()->GetText()); - location_bar->location_entry()->SetUserText(string16()); + location_bar->location_entry()->SetUserText(L""); browser()->AddSelectedTabWithURL(GURL(chrome::kAboutBlankURL), PageTransition::START_PAGE); ui_test_utils::WaitForNavigation( &browser()->GetSelectedTabContents()->controller()); - EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL), + EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), location_bar->location_entry()->GetText()); browser()->CloseTab(); - EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL), + EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), location_bar->location_entry()->GetText()); EXPECT_TRUE(location_bar->location_entry()->IsSelectAll()); } @@ -157,12 +157,12 @@ IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, FocusSearch) { // Focus search when omnibox is blank { EXPECT_TRUE(location_bar->GetInputString().empty()); - EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL), + EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), location_bar->location_entry()->GetText()); location_bar->FocusSearch(); EXPECT_TRUE(location_bar->GetInputString().empty()); - EXPECT_EQ(ASCIIToUTF16("?"), location_bar->location_entry()->GetText()); + EXPECT_EQ(L"?", location_bar->location_entry()->GetText()); size_t selection_start, selection_end; location_bar->location_entry()->GetSelectionBounds(&selection_start, @@ -173,13 +173,13 @@ IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, FocusSearch) { // Focus search when omnibox is _not_ alread in forced query mode. { - location_bar->location_entry()->SetUserText(ASCIIToUTF16("foo")); + location_bar->location_entry()->SetUserText(L"foo"); EXPECT_TRUE(location_bar->GetInputString().empty()); - EXPECT_EQ(ASCIIToUTF16("foo"), location_bar->location_entry()->GetText()); + EXPECT_EQ(L"foo", location_bar->location_entry()->GetText()); location_bar->FocusSearch(); EXPECT_TRUE(location_bar->GetInputString().empty()); - EXPECT_EQ(ASCIIToUTF16("?"), location_bar->location_entry()->GetText()); + EXPECT_EQ(L"?", location_bar->location_entry()->GetText()); size_t selection_start, selection_end; location_bar->location_entry()->GetSelectionBounds(&selection_start, @@ -191,13 +191,13 @@ IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, FocusSearch) { // Focus search when omnibox _is_ already in forced query mode, but no query // has been typed. { - location_bar->location_entry()->SetUserText(ASCIIToUTF16("?")); + location_bar->location_entry()->SetUserText(L"?"); EXPECT_TRUE(location_bar->GetInputString().empty()); - EXPECT_EQ(ASCIIToUTF16("?"), location_bar->location_entry()->GetText()); + EXPECT_EQ(L"?", location_bar->location_entry()->GetText()); location_bar->FocusSearch(); EXPECT_TRUE(location_bar->GetInputString().empty()); - EXPECT_EQ(ASCIIToUTF16("?"), location_bar->location_entry()->GetText()); + EXPECT_EQ(L"?", location_bar->location_entry()->GetText()); size_t selection_start, selection_end; location_bar->location_entry()->GetSelectionBounds(&selection_start, @@ -209,13 +209,13 @@ IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, FocusSearch) { // Focus search when omnibox _is_ already in forced query mode, and some query // has been typed. { - location_bar->location_entry()->SetUserText(ASCIIToUTF16("?foo")); + location_bar->location_entry()->SetUserText(L"?foo"); EXPECT_TRUE(location_bar->GetInputString().empty()); - EXPECT_EQ(ASCIIToUTF16("?foo"), location_bar->location_entry()->GetText()); + EXPECT_EQ(L"?foo", location_bar->location_entry()->GetText()); location_bar->FocusSearch(); EXPECT_TRUE(location_bar->GetInputString().empty()); - EXPECT_EQ(ASCIIToUTF16("?foo"), location_bar->location_entry()->GetText()); + EXPECT_EQ(L"?foo", location_bar->location_entry()->GetText()); size_t selection_start, selection_end; location_bar->location_entry()->GetSelectionBounds(&selection_start, @@ -226,15 +226,13 @@ IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, FocusSearch) { // Focus search when omnibox is in forced query mode with leading whitespace. { - location_bar->location_entry()->SetUserText(ASCIIToUTF16(" ?foo")); + location_bar->location_entry()->SetUserText(L" ?foo"); EXPECT_TRUE(location_bar->GetInputString().empty()); - EXPECT_EQ(ASCIIToUTF16(" ?foo"), - location_bar->location_entry()->GetText()); + EXPECT_EQ(L" ?foo", location_bar->location_entry()->GetText()); location_bar->FocusSearch(); EXPECT_TRUE(location_bar->GetInputString().empty()); - EXPECT_EQ(ASCIIToUTF16(" ?foo"), - location_bar->location_entry()->GetText()); + EXPECT_EQ(L" ?foo", location_bar->location_entry()->GetText()); size_t selection_start, selection_end; location_bar->location_entry()->GetSelectionBounds(&selection_start, diff --git a/chrome/browser/autocomplete/autocomplete_classifier.cc b/chrome/browser/autocomplete/autocomplete_classifier.cc index 45deb87..45635e3 100644 --- a/chrome/browser/autocomplete/autocomplete_classifier.cc +++ b/chrome/browser/autocomplete/autocomplete_classifier.cc @@ -15,8 +15,8 @@ AutocompleteClassifier::AutocompleteClassifier(Profile* profile) AutocompleteClassifier::~AutocompleteClassifier() { } -void AutocompleteClassifier::Classify(const string16& text, - const string16& desired_tld, +void AutocompleteClassifier::Classify(const std::wstring& text, + const std::wstring& desired_tld, bool allow_exact_keyword_match, AutocompleteMatch* match, GURL* alternate_nav_url) { diff --git a/chrome/browser/autocomplete/autocomplete_classifier.h b/chrome/browser/autocomplete/autocomplete_classifier.h index 1d8b473..ed59306 100644 --- a/chrome/browser/autocomplete/autocomplete_classifier.h +++ b/chrome/browser/autocomplete/autocomplete_classifier.h @@ -10,7 +10,6 @@ #include "base/basictypes.h" #include "base/scoped_ptr.h" -#include "base/string16.h" class AutocompleteController; struct AutocompleteMatch; @@ -34,8 +33,8 @@ class AutocompleteClassifier { // non-NULL, will be set to the navigational URL (if any) in case of an // accidental search; see comments on // AutocompleteResult::alternate_nav_url_ in autocomplete.h. - void Classify(const string16& text, - const string16& desired_tld, + void Classify(const std::wstring& text, + const std::wstring& desired_tld, bool allow_exact_keyword_match, AutocompleteMatch* match, GURL* alternate_nav_url); diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc index 7920aa5..1ad993e 100644 --- a/chrome/browser/autocomplete/autocomplete_edit.cc +++ b/chrome/browser/autocomplete/autocomplete_edit.cc @@ -43,8 +43,8 @@ AutocompleteEditController::~AutocompleteEditController() { // AutocompleteEditModel::State AutocompleteEditModel::State::State(bool user_input_in_progress, - const string16& user_text, - const string16& keyword, + const std::wstring& user_text, + const std::wstring& keyword, bool is_keyword_hint) : user_input_in_progress(user_input_in_progress), user_text(user_text), @@ -101,7 +101,7 @@ const AutocompleteEditModel::State // Weird edge case to match other browsers: if the edit is empty, revert to // the permanent text (so the user can get it back easily) but select it (so // on switching back, typing will "just work"). - const string16 user_text(UserTextFromDisplayText(view_->GetText())); + const std::wstring user_text(UserTextFromDisplayText(view_->GetText())); if (user_text.empty()) { view_->RevertAll(); view_->SelectAll(true); @@ -132,7 +132,7 @@ AutocompleteMatch AutocompleteEditModel::CurrentMatch() { } bool AutocompleteEditModel::UpdatePermanentText( - const string16& new_permanent_text) { + const std::wstring& new_permanent_text) { // When there's a new URL, and the user is not editing anything or the edit // doesn't have focus, we want to revert the edit to show the new URL. (The // common case where the edit doesn't have focus is when the user has started @@ -145,7 +145,7 @@ bool AutocompleteEditModel::UpdatePermanentText( return visibly_changed_permanent_text; } -void AutocompleteEditModel::SetUserText(const string16& text) { +void AutocompleteEditModel::SetUserText(const std::wstring& text) { SetInputInProgress(true); InternalSetUserText(text); paste_state_ = NONE; @@ -153,18 +153,18 @@ void AutocompleteEditModel::SetUserText(const string16& text) { } void AutocompleteEditModel::FinalizeInstantQuery( - const string16& input_text, - const string16& suggest_text) { + const std::wstring& input_text, + const std::wstring& suggest_text) { popup_->FinalizeInstantQuery(input_text, suggest_text); } void AutocompleteEditModel::GetDataForURLExport(GURL* url, - string16* title, + std::wstring* title, SkBitmap* favicon) { AutocompleteMatch match; GetInfoForCurrentText(&match, NULL); *url = match.destination_url; - if (*url == URLFixerUpper::FixupURL(UTF16ToUTF8(permanent_text_), + if (*url == URLFixerUpper::FixupURL(WideToUTF8(permanent_text_), std::string())) { *title = controller_->GetTitle(); *favicon = controller_->GetFavIcon(); @@ -191,12 +191,12 @@ bool AutocompleteEditModel::UseVerbatimInstant() { just_deleted_text_) return true; - string16::size_type start, end; + std::wstring::size_type start, end; view_->GetSelectionBounds(&start, &end); return (start != end) || (start != view_->GetText().size()); } -string16 AutocompleteEditModel::GetDesiredTLD() const { +std::wstring AutocompleteEditModel::GetDesiredTLD() const { // Tricky corner case: The user has typed "foo" and currently sees an inline // autocomplete suggestion of "foo.net". He now presses ctrl-a (e.g. to // select all, on Windows). If we treat the ctrl press as potentially for the @@ -211,7 +211,7 @@ string16 AutocompleteEditModel::GetDesiredTLD() const { // * the user is not typing a keyword query. return (control_key_state_ == DOWN_WITHOUT_CHANGE && inline_autocomplete_text_.empty() && !KeywordIsSelected())? - ASCIIToUTF16("com") : string16(); + std::wstring(L"com") : std::wstring(); } bool AutocompleteEditModel::CurrentTextIsURL() const { @@ -235,7 +235,7 @@ AutocompleteMatch::Type AutocompleteEditModel::CurrentTextType() const { void AutocompleteEditModel::AdjustTextForCopy(int sel_min, bool is_all_selected, - string16* text, + std::wstring* text, GURL* url, bool* write_url) { *write_url = false; @@ -253,7 +253,7 @@ void AutocompleteEditModel::AdjustTextForCopy(int sel_min, // The user selected all the text and has not edited it. Use the url as the // text so that if the scheme was stripped it's added back, and the url // is unescaped (we escape parts of the url for display). - *text = UTF8ToUTF16(url->spec()); + *text = UTF8ToWide(url->spec()); *write_url = true; return; } @@ -269,8 +269,8 @@ void AutocompleteEditModel::AdjustTextForCopy(int sel_min, perm_url.host() == url->host()) { *write_url = true; - string16 http = ASCIIToUTF16(chrome::kHttpScheme) + - ASCIIToUTF16(chrome::kStandardSchemeSeparator); + std::wstring http = ASCIIToWide(chrome::kHttpScheme) + + ASCIIToWide(chrome::kStandardSchemeSeparator); if (text->compare(0, http.length(), http) != 0) *text = http + *text; } @@ -287,7 +287,7 @@ void AutocompleteEditModel::SetInputInProgress(bool in_progress) { void AutocompleteEditModel::Revert() { SetInputInProgress(false); paste_state_ = NONE; - InternalSetUserText(string16()); + InternalSetUserText(std::wstring()); keyword_.clear(); is_keyword_hint_ = false; has_temporary_text_ = false; @@ -305,12 +305,12 @@ void AutocompleteEditModel::StartAutocomplete( (paste_state_ != NONE), keyword_is_selected, keyword_is_selected); } -bool AutocompleteEditModel::CanPasteAndGo(const string16& text) const { +bool AutocompleteEditModel::CanPasteAndGo(const std::wstring& text) const { if (!view_->GetCommandUpdater()->IsCommandEnabled(IDC_OPEN_CURRENT_URL)) return false; AutocompleteMatch match; - profile_->GetAutocompleteClassifier()->Classify(text, string16(), false, + profile_->GetAutocompleteClassifier()->Classify(text, std::wstring(), false, &match, &paste_and_go_alternate_nav_url_); paste_and_go_url_ = match.destination_url; paste_and_go_transition_ = match.transition; @@ -324,7 +324,7 @@ void AutocompleteEditModel::PasteAndGo() { view_->RevertAll(); view_->OpenURL(paste_and_go_url_, CURRENT_TAB, paste_and_go_transition_, paste_and_go_alternate_nav_url_, AutocompletePopupModel::kNoMatch, - string16()); + std::wstring()); } void AutocompleteEditModel::AcceptInput(WindowOpenDisposition disposition, @@ -338,7 +338,7 @@ void AutocompleteEditModel::AcceptInput(WindowOpenDisposition disposition, return; if ((match.transition == PageTransition::TYPED) && (match.destination_url == - URLFixerUpper::FixupURL(UTF16ToUTF8(permanent_text_), std::string()))) { + URLFixerUpper::FixupURL(WideToUTF8(permanent_text_), std::string()))) { // When the user hit enter on the existing permanent URL, treat it like a // reload for scoring purposes. We could detect this by just checking // user_input_in_progress_, but it seems better to treat "edits" that end @@ -368,7 +368,7 @@ void AutocompleteEditModel::AcceptInput(WindowOpenDisposition disposition, } view_->OpenURL(match.destination_url, disposition, match.transition, alternate_nav_url, AutocompletePopupModel::kNoMatch, - is_keyword_hint_ ? string16() : keyword_); + is_keyword_hint_ ? std::wstring() : keyword_); } void AutocompleteEditModel::OpenURL(const GURL& url, @@ -376,7 +376,7 @@ void AutocompleteEditModel::OpenURL(const GURL& url, PageTransition::Type transition, const GURL& alternate_nav_url, size_t index, - const string16& keyword) { + const std::wstring& keyword) { // We only care about cases where there is a selection (i.e. the popup is // open). if (popup_->IsOpen()) { @@ -393,7 +393,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(keyword); + template_url_model->GetTemplateURLForKeyword(WideToUTF16Hack(keyword)); // Special case for extension keywords. Don't increment usage count for // these. @@ -409,7 +409,7 @@ void AutocompleteEditModel::OpenURL(const GURL& url, size_t prefix_length = match.template_url->keyword().size() + 1; ExtensionOmniboxEventRouter::OnInputEntered( profile_, match.template_url->GetExtensionId(), - UTF16ToUTF8(match.fill_into_edit.substr(prefix_length))); + WideToUTF8(match.fill_into_edit.substr(prefix_length))); view_->RevertAll(); return; } @@ -435,7 +435,7 @@ bool AutocompleteEditModel::AcceptKeyword() { DCHECK(is_keyword_hint_ && !keyword_.empty()); view_->OnBeforePossibleChange(); - view_->SetWindowTextAndCaretPos(string16(), 0); + view_->SetWindowTextAndCaretPos(std::wstring(), 0); is_keyword_hint_ = false; view_->OnAfterPossibleChange(); just_deleted_text_ = false; // OnAfterPossibleChange() erroneously sets this @@ -446,9 +446,9 @@ bool AutocompleteEditModel::AcceptKeyword() { return true; } -void AutocompleteEditModel::ClearKeyword(const string16& visible_text) { +void AutocompleteEditModel::ClearKeyword(const std::wstring& visible_text) { view_->OnBeforePossibleChange(); - const string16 window_text(keyword_ + visible_text); + const std::wstring window_text(keyword_ + visible_text); view_->SetWindowTextAndCaretPos(window_text.c_str(), keyword_.length()); keyword_.clear(); is_keyword_hint_ = false; @@ -566,9 +566,9 @@ void AutocompleteEditModel::OnUpOrDownKeyPressed(int count) { } void AutocompleteEditModel::OnPopupDataChanged( - const string16& text, + const std::wstring& text, GURL* destination_for_temporary_text_change, - const string16& keyword, + const std::wstring& keyword, bool is_keyword_hint) { // Update keyword/hint-related local state. bool keyword_state_changed = (keyword_ != keyword) || @@ -622,7 +622,7 @@ void AutocompleteEditModel::OnPopupDataChanged( } bool AutocompleteEditModel::OnAfterPossibleChange( - const string16& new_text, + const std::wstring& new_text, bool selection_differs, bool text_differs, bool just_deleted_text, @@ -655,7 +655,7 @@ bool AutocompleteEditModel::OnAfterPossibleChange( // state associated with the text. Otherwise, we can get surprising behavior // where the autocompleted text unexpectedly reappears, e.g. crbug.com/55983 if (user_text_changed) { - const string16 new_user_text = UserTextFromDisplayText(new_text); + const std::wstring new_user_text = UserTextFromDisplayText(new_text); // Try to accept the current keyword if the user only typed a space at the // end of content. Model's state and popup will be updated when the keyword @@ -705,14 +705,14 @@ void AutocompleteEditModel::Observe(NotificationType type, DCHECK_EQ(NotificationType::AUTOCOMPLETE_CONTROLLER_DEFAULT_MATCH_UPDATED, type.value); - string16 inline_autocomplete_text; - string16 keyword; + std::wstring inline_autocomplete_text; + std::wstring keyword; bool is_keyword_hint = false; const AutocompleteResult* result = Details<const AutocompleteResult>(details).ptr(); const AutocompleteResult::const_iterator match(result->default_match()); if (match != result->end()) { - if ((match->inline_autocomplete_offset != string16::npos) && + if ((match->inline_autocomplete_offset != std::wstring::npos) && (match->inline_autocomplete_offset < match->fill_into_edit.length())) { inline_autocomplete_text = match->fill_into_edit.substr(match->inline_autocomplete_offset); @@ -734,7 +734,7 @@ void AutocompleteEditModel::Observe(NotificationType type, OnPopupDataChanged(inline_autocomplete_text, NULL, keyword, is_keyword_hint); } -void AutocompleteEditModel::InternalSetUserText(const string16& text) { +void AutocompleteEditModel::InternalSetUserText(const std::wstring& text) { user_text_ = text; just_deleted_text_ = false; inline_autocomplete_text_.clear(); @@ -744,15 +744,15 @@ bool AutocompleteEditModel::KeywordIsSelected() const { return !is_keyword_hint_ && !keyword_.empty(); } -string16 AutocompleteEditModel::DisplayTextFromUserText( - const string16& text) const { +std::wstring AutocompleteEditModel::DisplayTextFromUserText( + const std::wstring& text) const { return KeywordIsSelected() ? KeywordProvider::SplitReplacementStringFromInput(text, false) : text; } -string16 AutocompleteEditModel::UserTextFromDisplayText( - const string16& text) const { - return KeywordIsSelected() ? (keyword_ + char16(' ') + text) : text; +std::wstring AutocompleteEditModel::UserTextFromDisplayText( + const std::wstring& text) const { + return KeywordIsSelected() ? (keyword_ + L" " + text) : text; } void AutocompleteEditModel::GetInfoForCurrentText( @@ -767,11 +767,11 @@ void AutocompleteEditModel::GetInfoForCurrentText( } } -bool AutocompleteEditModel::GetURLForText(const string16& text, +bool AutocompleteEditModel::GetURLForText(const std::wstring& text, GURL* url) const { GURL parsed_url; const AutocompleteInput::Type type = AutocompleteInput::Parse( - UserTextFromDisplayText(text), string16(), NULL, NULL, &parsed_url); + UserTextFromDisplayText(text), std::wstring(), NULL, NULL, &parsed_url); if (type != AutocompleteInput::URL) return false; @@ -780,7 +780,7 @@ bool AutocompleteEditModel::GetURLForText(const string16& text, } bool AutocompleteEditModel::MaybeAcceptKeywordBySpace( - const string16& new_user_text) { + const std::wstring& new_user_text) { return (paste_state_ == NONE) && is_keyword_hint_ && !keyword_.empty() && inline_autocomplete_text_.empty() && !user_text_.empty() && (new_user_text.length() == user_text_.length() + 1) && diff --git a/chrome/browser/autocomplete/autocomplete_edit.h b/chrome/browser/autocomplete/autocomplete_edit.h index d508eea..6cefc0b 100644 --- a/chrome/browser/autocomplete/autocomplete_edit.h +++ b/chrome/browser/autocomplete/autocomplete_edit.h @@ -50,7 +50,7 @@ class AutocompleteEditController { // Commits the suggested text. |typed_text| is the current text showing in the // autocomplete. Returns true if the text was committed. - virtual bool OnCommitSuggestedText(const string16& typed_text) = 0; + virtual bool OnCommitSuggestedText(const std::wstring& typed_text) = 0; // Accepts the currently showing instant preview, if any, and returns true. // Returns false if there is no instant preview showing. @@ -94,7 +94,7 @@ class AutocompleteEditController { virtual SkBitmap GetFavIcon() const = 0; // Returns the title of the current page. - virtual string16 GetTitle() const = 0; + virtual std::wstring GetTitle() const = 0; protected: virtual ~AutocompleteEditController(); @@ -104,14 +104,14 @@ class AutocompleteEditModel : public NotificationObserver { public: struct State { State(bool user_input_in_progress, - const string16& user_text, - const string16& keyword, + const std::wstring& user_text, + const std::wstring& keyword, bool is_keyword_hint); ~State(); bool user_input_in_progress; - const string16 user_text; - const string16 keyword; + const std::wstring user_text; + const std::wstring keyword; const bool is_keyword_hint; }; @@ -144,7 +144,7 @@ class AutocompleteEditModel : public NotificationObserver { // Called when the user wants to export the entire current text as a URL. // Sets the url, and if known, the title and favicon. - void GetDataForURLExport(GURL* url, string16* title, SkBitmap* favicon); + void GetDataForURLExport(GURL* url, std::wstring* title, SkBitmap* favicon); // Returns true if a verbatim query should be used for instant. A verbatim // query is forced in certain situations, such as pressing delete at the end @@ -155,7 +155,7 @@ class AutocompleteEditModel : public NotificationObserver { // desired TLD is the TLD the user desires to add to the end of the current // input, if any, based on their control key state and any other actions // they've taken. - string16 GetDesiredTLD() const; + std::wstring GetDesiredTLD() const; // Returns true if the current edit contents will be treated as a // URL/navigation, as opposed to a search. @@ -172,7 +172,7 @@ class AutocompleteEditModel : public NotificationObserver { // is set to true and |url| set to the url to write. void AdjustTextForCopy(int sel_min, bool is_all_selected, - string16* text, + std::wstring* text, GURL* url, bool* write_url); @@ -185,14 +185,14 @@ class AutocompleteEditModel : public NotificationObserver { // Updates permanent_text_ to |new_permanent_text|. Returns true if this // change should be immediately user-visible, because either the user is not // editing or the edit does not have focus. - bool UpdatePermanentText(const string16& new_permanent_text); + bool UpdatePermanentText(const std::wstring& new_permanent_text); // Sets the user_text_ to |text|. Only the View should call this. - void SetUserText(const string16& text); + void SetUserText(const std::wstring& text); // Calls through to SearchProvider::FinalizeInstantQuery. - void FinalizeInstantQuery(const string16& input_text, - const string16& suggest_text); + void FinalizeInstantQuery(const std::wstring& input_text, + const std::wstring& suggest_text); // Reverts the edit model back to its unedited state (permanent text showing, // no user input in progress). @@ -206,7 +206,7 @@ class AutocompleteEditModel : public NotificationObserver { // This also updates the internal paste-and-go-related state variables as // appropriate so that the controller doesn't need to be repeatedly queried // for the same text in every clipboard-related function. - bool CanPasteAndGo(const string16& text) const; + bool CanPasteAndGo(const std::wstring& text) const; // Navigates to the destination last supplied to CanPasteAndGo. void PasteAndGo(); @@ -234,13 +234,13 @@ class AutocompleteEditModel : public NotificationObserver { PageTransition::Type transition, const GURL& alternate_nav_url, size_t index, - const string16& keyword); + const std::wstring& keyword); bool has_focus() const { return has_focus_; } // Accessors for keyword-related state (see comments on keyword_ and // is_keyword_hint_). - const string16& keyword() const { return keyword_; } + const std::wstring& keyword() const { return keyword_; } bool is_keyword_hint() const { return is_keyword_hint_; } // Accepts the current keyword hint as a keyword. It always returns true for @@ -249,7 +249,7 @@ class AutocompleteEditModel : public NotificationObserver { // Clears the current keyword. |visible_text| is the (non-keyword) text // currently visible in the edit. - void ClearKeyword(const string16& visible_text); + void ClearKeyword(const std::wstring& visible_text); // Returns true if a query to an autocomplete provider is currently // in progress. This logic should in the future live in @@ -297,9 +297,9 @@ class AutocompleteEditModel : public NotificationObserver { // or the currently selected keyword if |is_keyword_hint| is false (see // comments on keyword_ and is_keyword_hint_). void OnPopupDataChanged( - const string16& text, + const std::wstring& text, GURL* destination_for_temporary_text_change, - const string16& keyword, + const std::wstring& keyword, bool is_keyword_hint); // Called by the AutocompleteEditView after something changes, with details @@ -310,7 +310,7 @@ class AutocompleteEditModel : public NotificationObserver { // may be false when: // 1) The insert caret is not at the end of the edit box // 2) The user is composing a text with an IME - bool OnAfterPossibleChange(const string16& new_text, + bool OnAfterPossibleChange(const std::wstring& new_text, bool selection_differs, bool text_differs, bool just_deleted_text, @@ -351,7 +351,7 @@ class AutocompleteEditModel : public NotificationObserver { const NotificationDetails& details); // Called whenever user_text_ should change. - void InternalSetUserText(const string16& text); + void InternalSetUserText(const std::wstring& text); // Returns true if a keyword is selected. bool KeywordIsSelected() const; @@ -359,8 +359,8 @@ class AutocompleteEditModel : public NotificationObserver { // Conversion between user text and display text. User text is the text the // user has input. Display text is the text being shown in the edit. The // two are different if a keyword is selected. - string16 DisplayTextFromUserText(const string16& text) const; - string16 UserTextFromDisplayText(const string16& text) const; + std::wstring DisplayTextFromUserText(const std::wstring& text) const; + std::wstring UserTextFromDisplayText(const std::wstring& text) const; // Returns the default match for the current text, as well as the alternate // nav URL, if |alternate_nav_url| is non-NULL and there is such a URL. @@ -373,11 +373,11 @@ class AutocompleteEditModel : public NotificationObserver { // and CurrentTextIsURL()). The view needs this because it calls this // function during copy handling, when the control key is down to trigger the // copy. - bool GetURLForText(const string16& text, GURL* url) const; + bool GetURLForText(const std::wstring& text, GURL* url) const; // Accepts current keyword if the user only typed a space at the end of // |new_user_text|. Returns true if the current keyword is accepted. - bool MaybeAcceptKeywordBySpace(const string16& new_user_text); + bool MaybeAcceptKeywordBySpace(const std::wstring& new_user_text); // Checks if a given character is a valid space character for accepting // keyword. @@ -395,7 +395,7 @@ class AutocompleteEditModel : public NotificationObserver { bool has_focus_; // The URL of the currently displayed page. - string16 permanent_text_; + std::wstring permanent_text_; // This flag is true when the user has modified the contents of the edit, but // not yet accepted them. We use this to determine when we need to save @@ -406,7 +406,7 @@ class AutocompleteEditModel : public NotificationObserver { // The text that the user has entered. This does not include inline // autocomplete text that has not yet been accepted. - string16 user_text_; + std::wstring user_text_; // When the user closes the popup, we need to remember the URL for their // desired choice, so that if they hit enter without reopening the popup we @@ -423,7 +423,7 @@ class AutocompleteEditModel : public NotificationObserver { // simply ask the popup for the desired URL directly. As a result, the // contents of this variable only need to be updated when the popup is closed // but user_input_in_progress_ is not being cleared. - string16 url_for_remembered_user_selection_; + std::wstring url_for_remembered_user_selection_; // Inline autocomplete is allowed if the user has not just deleted text, and // no temporary text is showing. In this case, inline_autocomplete_text_ is @@ -433,7 +433,7 @@ class AutocompleteEditModel : public NotificationObserver { // text (actions that close the popup should either accept the text, convert // it to a normal selection, or change the edit entirely). bool just_deleted_text_; - string16 inline_autocomplete_text_; + std::wstring inline_autocomplete_text_; // Used by OnPopupDataChanged to keep track of whether there is currently a // temporary text. @@ -466,7 +466,7 @@ class AutocompleteEditModel : public NotificationObserver { // selected keyword, or just some input text that looks like a keyword (so we // can show a hint to press <tab>). This is the keyword in either case; // is_keyword_hint_ (below) distinguishes the two cases. - string16 keyword_; + std::wstring keyword_; // True if the keyword associated with this match is merely a hint, i.e. the // user hasn't actually selected a keyword yet. When this is true, we can use diff --git a/chrome/browser/autocomplete/autocomplete_edit_unittest.cc b/chrome/browser/autocomplete/autocomplete_edit_unittest.cc index 7643936..f599db3 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_unittest.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_unittest.cc @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/utf_string_conversions.h" #include "chrome/browser/autocomplete/autocomplete_edit.h" #include "chrome/browser/autocomplete/autocomplete_edit_view.h" #include "chrome/test/testing_profile.h" @@ -24,30 +23,30 @@ class TestingAutocompleteEditView : public AutocompleteEditView { PageTransition::Type transition, const GURL& alternate_nav_url, size_t selected_line, - const string16& keyword) {} - virtual string16 GetText() const { return string16(); } + const std::wstring& keyword) {} + virtual std::wstring GetText() const { return std::wstring(); } virtual bool IsEditingOrEmpty() const { return true; } virtual int GetIcon() const { return 0; } - virtual void SetUserText(const string16& text) {} - virtual void SetUserText(const string16& text, - const string16& display_text, + virtual void SetUserText(const std::wstring& text) {} + virtual void SetUserText(const std::wstring& text, + const std::wstring& display_text, bool update_popup) {} - virtual void SetWindowTextAndCaretPos(const string16& text, + virtual void SetWindowTextAndCaretPos(const std::wstring& text, size_t caret_pos) {} virtual void SetForcedQuery() {} virtual bool IsSelectAll() { return false; } virtual bool DeleteAtEndPressed() { return false; } - virtual void GetSelectionBounds(string16::size_type* start, - string16::size_type* end) {} + virtual void GetSelectionBounds(std::wstring::size_type* start, + std::wstring::size_type* end) {} virtual void SelectAll(bool reversed) {} virtual void RevertAll() {} virtual void UpdatePopup() {} virtual void ClosePopup() {} virtual void SetFocus() {} - virtual void OnTemporaryTextMaybeChanged(const string16& display_text, + virtual void OnTemporaryTextMaybeChanged(const std::wstring& display_text, bool save_original_selection) {} virtual bool OnInlineAutocompleteTextMaybeChanged( - const string16& display_text, size_t user_text_length) { + const std::wstring& display_text, size_t user_text_length) { return false; } virtual void OnRevertTemporaryText() {} @@ -62,8 +61,8 @@ class TestingAutocompleteEditView : public AutocompleteEditView { #if defined(TOOLKIT_VIEWS) virtual views::View* AddToView(views::View* parent) { return NULL; } virtual bool CommitInstantSuggestion( - const string16& typed_text, - const string16& suggested_text) { return false; } + const std::wstring& typed_text, + const std::wstring& suggested_text) { return false;} #endif private: @@ -76,7 +75,7 @@ class TestingAutocompleteEditController : public AutocompleteEditController { virtual void OnAutocompleteWillClosePopup() {} virtual void OnAutocompleteLosingFocus(gfx::NativeView view_gaining_focus) {} virtual void OnAutocompleteWillAccept() {} - virtual bool OnCommitSuggestedText(const string16& typed_text) { + virtual bool OnCommitSuggestedText(const std::wstring& typed_text) { return false; } virtual bool AcceptCurrentInstantPreview() { @@ -93,7 +92,7 @@ class TestingAutocompleteEditController : public AutocompleteEditController { virtual void OnKillFocus() {} virtual void OnSetFocus() {} virtual SkBitmap GetFavIcon() const { return SkBitmap(); } - virtual string16 GetTitle() const { return string16(); } + virtual std::wstring GetTitle() const { return std::wstring(); } private: DISALLOW_COPY_AND_ASSIGN(TestingAutocompleteEditController); @@ -106,41 +105,41 @@ typedef testing::Test AutocompleteEditTest; // Tests various permutations of AutocompleteModel::AdjustTextForCopy. TEST(AutocompleteEditTest, AdjustTextForCopy) { struct Data { - const char* perm_text; + const wchar_t* perm_text; const int sel_start; const bool is_all_selected; - const char* input; - const char* expected_output; + const wchar_t* input; + const wchar_t* expected_output; const bool write_url; const char* expected_url; } input[] = { // Test that http:// is inserted if all text is selected. - { "a.b/c", 0, true, "a.b/c", "http://a.b/c", true, "http://a.b/c" }, + { L"a.b/c", 0, true, L"a.b/c", L"http://a.b/c", true, "http://a.b/c" }, // Test that http:// is inserted if the host is selected. - { "a.b/c", 0, false, "a.b/", "http://a.b/", true, "http://a.b/" }, + { L"a.b/c", 0, false, L"a.b/", L"http://a.b/", true, "http://a.b/" }, // Tests that http:// is inserted if the path is modified. - { "a.b/c", 0, false, "a.b/d", "http://a.b/d", true, "http://a.b/d" }, + { L"a.b/c", 0, false, L"a.b/d", L"http://a.b/d", true, "http://a.b/d" }, // Tests that http:// isn't inserted if the host is modified. - { "a.b/c", 0, false, "a.c/", "a.c/", false, "" }, + { L"a.b/c", 0, false, L"a.c/", L"a.c/", false, "" }, // Tests that http:// isn't inserted if the start of the selection is 1. - { "a.b/c", 1, false, "a.b/", "a.b/", false, "" }, + { L"a.b/c", 1, false, L"a.b/", L"a.b/", false, "" }, // Tests that http:// isn't inserted if a portion of the host is selected. - { "a.com/", 0, false, "a.co", "a.co", false, "" }, + { L"a.com/", 0, false, L"a.co", L"a.co", false, "" }, // Tests that http:// isn't inserted for an https url after the user nukes // https. - { "https://a.com/", 0, false, "a.com/", "a.com/", false, "" }, + { L"https://a.com/", 0, false, L"a.com/", L"a.com/", false, "" }, // Tests that http:// isn't inserted if the user adds to the host. - { "a.b/", 0, false, "a.bc/", "a.bc/", false, "" }, + { L"a.b/", 0, false, L"a.bc/", L"a.bc/", false, "" }, // Tests that we don't get double http if the user manually inserts http. - { "a.b/", 0, false, "http://a.b/", "http://a.b/", true, "http://a.b/" }, + { L"a.b/", 0, false, L"http://a.b/", L"http://a.b/", true, "http://a.b/" }, }; TestingAutocompleteEditView view; TestingAutocompleteEditController controller; @@ -148,14 +147,14 @@ TEST(AutocompleteEditTest, AdjustTextForCopy) { AutocompleteEditModel model(&view, &controller, &profile); for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input); ++i) { - model.UpdatePermanentText(ASCIIToUTF16(input[i].perm_text)); + model.UpdatePermanentText(input[i].perm_text); - string16 result = ASCIIToUTF16(input[i].input); + std::wstring result(input[i].input); GURL url; bool write_url; model.AdjustTextForCopy(input[i].sel_start, input[i].is_all_selected, &result, &url, &write_url); - EXPECT_EQ(ASCIIToUTF16(input[i].expected_output), result) << "@: " << i; + EXPECT_EQ(input[i].expected_output, result) << "@: " << i; EXPECT_EQ(input[i].write_url, write_url) << " @" << i; if (write_url) EXPECT_EQ(input[i].expected_url, url.spec()) << " @" << i; diff --git a/chrome/browser/autocomplete/autocomplete_edit_view.h b/chrome/browser/autocomplete/autocomplete_edit_view.h index 73ccb46..4432882 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view.h +++ b/chrome/browser/autocomplete/autocomplete_edit_view.h @@ -60,12 +60,12 @@ class AutocompleteEditView { PageTransition::Type transition, const GURL& alternate_nav_url, size_t selected_line, - const string16& keyword) = 0; + const std::wstring& keyword) = 0; // Returns the current text of the edit control, which could be the // "temporary" text set by the popup, the "permanent" text set by the // browser, or just whatever the user has currently typed. - virtual string16 GetText() const = 0; + virtual std::wstring GetText() const = 0; // |true| if the user is in the process of editing the field, or if // the field is empty. @@ -77,13 +77,13 @@ class AutocompleteEditView { // The user text is the text the user has manually keyed in. When present, // this is shown in preference to the permanent text; hitting escape will // revert to the permanent text. - virtual void SetUserText(const string16& text) = 0; - virtual void SetUserText(const string16& text, - const string16& display_text, + virtual void SetUserText(const std::wstring& text) = 0; + virtual void SetUserText(const std::wstring& text, + const std::wstring& display_text, bool update_popup) = 0; // Sets the window text and the caret position. - virtual void SetWindowTextAndCaretPos(const string16& text, + virtual void SetWindowTextAndCaretPos(const std::wstring& text, size_t caret_pos) = 0; // Sets the edit to forced query mode. Practically speaking, this means that @@ -105,8 +105,8 @@ class AutocompleteEditView { // It is not guaranteed that |*start < *end|, as the selection can be // directed. If there is no selection, |start| and |end| will both be equal // to the current cursor position. - virtual void GetSelectionBounds(string16::size_type* start, - string16::size_type* end) = 0; + virtual void GetSelectionBounds(std::wstring::size_type* start, + std::wstring::size_type* end) = 0; // Selects all the text in the edit. Use this in place of SetSelAll() to // avoid selecting the "phantom newline" at the end of the edit. @@ -130,7 +130,7 @@ class AutocompleteEditView { // |display_text| is the new text to show; |save_original_selection| is true // when there wasn't previously a temporary text and thus we need to save off // the user's existing selection. - virtual void OnTemporaryTextMaybeChanged(const string16& display_text, + virtual void OnTemporaryTextMaybeChanged(const std::wstring& display_text, bool save_original_selection) = 0; // Called when the inline autocomplete text in the model may have changed. @@ -138,7 +138,7 @@ class AutocompleteEditView { // the user input portion of that (so, up to but not including the inline // autocompletion). Returns whether the display text actually changed. virtual bool OnInlineAutocompleteTextMaybeChanged( - const string16& display_text, size_t user_text_length) = 0; + const std::wstring& display_text, size_t user_text_length) = 0; // Called when the temporary text has been reverted by the user. This will // reset the user's original selection. @@ -174,8 +174,8 @@ class AutocompleteEditView { virtual views::View* AddToView(views::View* parent) = 0; // Commits the suggested text. - virtual bool CommitInstantSuggestion(const string16& typed_text, - const string16& suggested_text) = 0; + virtual bool CommitInstantSuggestion(const std::wstring& typed_text, + const std::wstring& suggested_text) = 0; #endif virtual ~AutocompleteEditView() {} diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc b/chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc index 0562064..6e00c93 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc @@ -351,7 +351,7 @@ class AutocompleteEditViewTest : public InProcessBrowserTest, ASSERT_NO_FATAL_FAILURE(WaitForTabOpenOrClose(tab_count)); // Try ctrl-l to focus location bar. - edit_view->SetUserText(ASCIIToUTF16("Hello world")); + edit_view->SetUserText(L"Hello world"); EXPECT_FALSE(edit_view->IsSelectAll()); ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_L, true, false, false)); EXPECT_TRUE(edit_view->IsSelectAll()); @@ -360,13 +360,13 @@ class AutocompleteEditViewTest : public InProcessBrowserTest, ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RIGHT, false, false, false)); EXPECT_FALSE(edit_view->IsSelectAll()); ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_S, false, false, false)); - EXPECT_EQ(ASCIIToUTF16("Hello worlds"), edit_view->GetText()); + EXPECT_EQ(L"Hello worlds", edit_view->GetText()); // Try ctrl-x to cut text. ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, true, true, false)); EXPECT_FALSE(edit_view->IsSelectAll()); ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_X, true, false, false)); - EXPECT_EQ(ASCIIToUTF16("Hello "), edit_view->GetText()); + EXPECT_EQ(L"Hello ", edit_view->GetText()); #if !defined(OS_CHROMEOS) // Try alt-f4 to close the browser. @@ -396,7 +396,7 @@ class AutocompleteEditViewTest : public InProcessBrowserTest, GetAutocompleteEditViewForBrowser(popup, &edit_view)); // Set the edit text to "Hello world". - edit_view->SetUserText(ASCIIToUTF16("Hello world")); + edit_view->SetUserText(L"Hello world"); EXPECT_FALSE(edit_view->IsSelectAll()); popup->FocusLocationBar(); EXPECT_TRUE(edit_view->IsSelectAll()); @@ -407,7 +407,7 @@ class AutocompleteEditViewTest : public InProcessBrowserTest, EXPECT_FALSE(edit_view->IsSelectAll()); ASSERT_NO_FATAL_FAILURE(SendKeyForBrowser(popup, ui::VKEY_S, false, false, false)); - EXPECT_EQ(ASCIIToUTF16("Hello world"), edit_view->GetText()); + EXPECT_EQ(L"Hello world", edit_view->GetText()); // Try ctrl-x to cut text -- should be disallowed. ASSERT_NO_FATAL_FAILURE(SendKeyForBrowser(popup, ui::VKEY_LEFT, true, true, @@ -415,7 +415,7 @@ class AutocompleteEditViewTest : public InProcessBrowserTest, EXPECT_FALSE(edit_view->IsSelectAll()); ASSERT_NO_FATAL_FAILURE(SendKeyForBrowser(popup, ui::VKEY_X, true, false, false)); - EXPECT_EQ(ASCIIToUTF16("Hello world"), edit_view->GetText()); + EXPECT_EQ(L"Hello world", edit_view->GetText()); #if !defined(OS_CHROMEOS) // Try alt-f4 to close the popup. @@ -432,22 +432,22 @@ class AutocompleteEditViewTest : public InProcessBrowserTest, // Trigger keyword hint mode. ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys)); ASSERT_TRUE(edit_view->model()->is_keyword_hint()); - ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(edit_view->model()->keyword())); + ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword())); // Trigger keyword mode. ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, false, false, false)); ASSERT_FALSE(edit_view->model()->is_keyword_hint()); - ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(edit_view->model()->keyword())); + ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword())); // Backspace without search text should bring back keyword hint mode. ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false)); ASSERT_TRUE(edit_view->model()->is_keyword_hint()); - ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(edit_view->model()->keyword())); + ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword())); // Trigger keyword mode again. ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, false, false, false)); ASSERT_FALSE(edit_view->model()->is_keyword_hint()); - ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(edit_view->model()->keyword())); + ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword())); // Input something as search text. ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); @@ -457,7 +457,7 @@ class AutocompleteEditViewTest : public InProcessBrowserTest, for (size_t i = 0; i < arraysize(kSearchText) - 1; ++i) { ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false)); ASSERT_FALSE(edit_view->model()->is_keyword_hint()); - ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(edit_view->model()->keyword())); + ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword())); } // Input something as search text. @@ -469,9 +469,9 @@ class AutocompleteEditViewTest : public InProcessBrowserTest, // the keyword mode. ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false)); ASSERT_FALSE(edit_view->model()->is_keyword_hint()); - ASSERT_EQ(string16(), edit_view->model()->keyword()); + ASSERT_EQ(std::string(), WideToUTF8(edit_view->model()->keyword())); ASSERT_EQ(std::string(kSearchKeyword) + kSearchText, - UTF16ToUTF8(edit_view->GetText())); + WideToUTF8(edit_view->GetText())); } void EscapeTest() { @@ -481,7 +481,7 @@ class AutocompleteEditViewTest : public InProcessBrowserTest, AutocompleteEditView* edit_view = NULL; ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); - string16 old_text = edit_view->GetText(); + std::wstring old_text = edit_view->GetText(); EXPECT_FALSE(old_text.empty()); EXPECT_TRUE(edit_view->IsSelectAll()); @@ -505,8 +505,7 @@ class AutocompleteEditViewTest : public InProcessBrowserTest, ASSERT_NO_FATAL_FAILURE(SendKeySequence(kDesiredTLDKeys)); ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); ASSERT_TRUE(popup_model->IsOpen()); - // ctrl-Enter triggers desired_tld feature, thus www.bar.com shall be - // opened. + // ctrl-Enter triggers desired_tld feature, thus www.bar.com shall be opened. ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN, true, false, false)); GURL url = browser()->GetSelectedTabContents()->GetURL(); @@ -517,7 +516,7 @@ class AutocompleteEditViewTest : public InProcessBrowserTest, AutocompleteEditView* edit_view = NULL; ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); - edit_view->SetUserText(ASCIIToUTF16(chrome::kChromeUIHistoryURL)); + edit_view->SetUserText(ASCIIToWide(chrome::kChromeUIHistoryURL)); int tab_count = browser()->tab_count(); // alt-Enter opens a new tab. ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN, false, false, true)); @@ -550,7 +549,7 @@ class AutocompleteEditViewTest : public InProcessBrowserTest, ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchSingleCharKeys)); ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); ASSERT_TRUE(popup_model->IsOpen()); - EXPECT_EQ(kSearchSingleChar, UTF16ToUTF8(edit_view->GetText())); + EXPECT_EQ(kSearchSingleChar, WideToUTF8(edit_view->GetText())); // Check if the default match result is Search Primary Provider. ASSERT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, @@ -573,7 +572,7 @@ class AutocompleteEditViewTest : public InProcessBrowserTest, ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); ASSERT_TRUE(popup_model->IsOpen()); - string16 old_text = edit_view->GetText(); + std::wstring old_text = edit_view->GetText(); // Make sure inline autocomplete is triggerred. EXPECT_GT(old_text.length(), arraysize(kInlineAutocompleteText) - 1); @@ -605,11 +604,11 @@ class AutocompleteEditViewTest : public InProcessBrowserTest, AutocompleteEditView* edit_view = NULL; ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); - string16 old_text = edit_view->GetText(); - EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL), old_text); + std::wstring old_text = edit_view->GetText(); + EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), old_text); EXPECT_TRUE(edit_view->IsSelectAll()); - string16::size_type start, end; + std::wstring::size_type start, end; edit_view->GetSelectionBounds(&start, &end); EXPECT_EQ(0U, start); EXPECT_EQ(old_text.size(), end); @@ -626,7 +625,7 @@ class AutocompleteEditViewTest : public InProcessBrowserTest, // Insert one character at the end. Make sure we won't insert // anything after the special ZWS mark used in gtk implementation. ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A, false, false, false)); - EXPECT_EQ(old_text + char16('a'), edit_view->GetText()); + EXPECT_EQ(old_text + L"a", edit_view->GetText()); // Delete one character from the end. Make sure we won't delete the special // ZWS mark used in gtk implementation. @@ -660,7 +659,7 @@ class AutocompleteEditViewTest : public InProcessBrowserTest, AutocompleteEditView* edit_view = NULL; ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); - string16 text = UTF8ToUTF16(kSearchKeyword); + std::wstring text = UTF8ToWide(kSearchKeyword); // Trigger keyword hint mode. ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys)); @@ -675,22 +674,21 @@ class AutocompleteEditViewTest : public InProcessBrowserTest, ASSERT_TRUE(edit_view->GetText().empty()); // Revert to keyword hint mode. - edit_view->model()->ClearKeyword(string16()); + edit_view->model()->ClearKeyword(std::wstring()); ASSERT_TRUE(edit_view->model()->is_keyword_hint()); ASSERT_EQ(text, edit_view->model()->keyword()); ASSERT_EQ(text, edit_view->GetText()); // Keyword should also be accepted by typing an ideographic space. edit_view->OnBeforePossibleChange(); - edit_view->SetWindowTextAndCaretPos(text + WideToUTF16(L"\x3000"), - text.length() + 1); + edit_view->SetWindowTextAndCaretPos(text + L"\x3000", text.length() + 1); edit_view->OnAfterPossibleChange(); ASSERT_FALSE(edit_view->model()->is_keyword_hint()); ASSERT_EQ(text, edit_view->model()->keyword()); ASSERT_TRUE(edit_view->GetText().empty()); // Revert to keyword hint mode. - edit_view->model()->ClearKeyword(string16()); + edit_view->model()->ClearKeyword(std::wstring()); ASSERT_TRUE(edit_view->model()->is_keyword_hint()); ASSERT_EQ(text, edit_view->model()->keyword()); ASSERT_EQ(text, edit_view->GetText()); @@ -699,25 +697,25 @@ class AutocompleteEditViewTest : public InProcessBrowserTest, // Simulate pasting a whitespace to the end of content. edit_view->OnBeforePossibleChange(); edit_view->model()->on_paste(); - edit_view->SetWindowTextAndCaretPos(text + char16(' '), text.length() + 1); + edit_view->SetWindowTextAndCaretPos(text + L" ", text.length() + 1); edit_view->OnAfterPossibleChange(); // Should be still in keyword hint mode. ASSERT_TRUE(edit_view->model()->is_keyword_hint()); ASSERT_EQ(text, edit_view->model()->keyword()); - ASSERT_EQ(text + char16(' '), edit_view->GetText()); + ASSERT_EQ(text + L" ", edit_view->GetText()); // Keyword shouldn't be accepted by pressing space with a trailing // whitespace. ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, false, false, false)); ASSERT_TRUE(edit_view->model()->is_keyword_hint()); ASSERT_EQ(text, edit_view->model()->keyword()); - ASSERT_EQ(text + ASCIIToUTF16(" "), edit_view->GetText()); + ASSERT_EQ(text + L" ", edit_view->GetText()); // Keyword shouldn't be accepted by deleting the trailing space. ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false)); ASSERT_TRUE(edit_view->model()->is_keyword_hint()); ASSERT_EQ(text, edit_view->model()->keyword()); - ASSERT_EQ(text + char16(' '), edit_view->GetText()); + ASSERT_EQ(text + L" ", edit_view->GetText()); // Keyword shouldn't be accepted by pressing space in the middle // of content. @@ -725,38 +723,37 @@ class AutocompleteEditViewTest : public InProcessBrowserTest, ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, false, false, false)); ASSERT_TRUE(edit_view->model()->is_keyword_hint()); ASSERT_EQ(text, edit_view->model()->keyword()); - ASSERT_EQ(text + ASCIIToUTF16(" "), edit_view->GetText()); + ASSERT_EQ(text + L" ", edit_view->GetText()); // Keyword shouldn't be accepted by pasting "foo bar". - edit_view->SetUserText(string16()); + edit_view->SetUserText(std::wstring()); ASSERT_FALSE(edit_view->model()->is_keyword_hint()); ASSERT_TRUE(edit_view->model()->keyword().empty()); edit_view->OnBeforePossibleChange(); edit_view->model()->on_paste(); - edit_view->SetWindowTextAndCaretPos(text + ASCIIToUTF16(" bar"), - text.length() + 4); + edit_view->SetWindowTextAndCaretPos(text + L" bar", text.length() + 4); edit_view->OnAfterPossibleChange(); ASSERT_FALSE(edit_view->model()->is_keyword_hint()); ASSERT_TRUE(edit_view->model()->keyword().empty()); - ASSERT_EQ(text + ASCIIToUTF16(" bar"), edit_view->GetText()); + ASSERT_EQ(text + L" bar", edit_view->GetText()); // Keyword shouldn't be accepted by pressing space with a selected range. edit_view->OnBeforePossibleChange(); edit_view->OnInlineAutocompleteTextMaybeChanged( - text + ASCIIToUTF16(" "), text.length()); + text + L" ", text.length()); edit_view->OnAfterPossibleChange(); ASSERT_TRUE(edit_view->model()->is_keyword_hint()); ASSERT_EQ(text, edit_view->model()->keyword()); - ASSERT_EQ(text + ASCIIToUTF16(" "), edit_view->GetText()); + ASSERT_EQ(text + L" ", edit_view->GetText()); - string16::size_type start, end; + std::wstring::size_type start, end; edit_view->GetSelectionBounds(&start, &end); ASSERT_NE(start, end); ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, false, false, false)); ASSERT_TRUE(edit_view->model()->is_keyword_hint()); ASSERT_EQ(text, edit_view->model()->keyword()); - ASSERT_EQ(text + ASCIIToUTF16(" "), edit_view->GetText()); + ASSERT_EQ(text + L" ", edit_view->GetText()); edit_view->GetSelectionBounds(&start, &end); ASSERT_EQ(start, end); @@ -826,8 +823,8 @@ IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, UndoRedoLinux) { AutocompleteEditView* edit_view = NULL; ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); - string16 old_text = edit_view->GetText(); - EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL), old_text); + std::wstring old_text = edit_view->GetText(); + EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), old_text); EXPECT_TRUE(edit_view->IsSelectAll()); // Undo should clear the omnibox. @@ -846,7 +843,7 @@ IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, UndoRedoLinux) { EXPECT_FALSE(edit_view->IsSelectAll()); // The cursor should be at the end. - string16::size_type start, end; + std::wstring::size_type start, end; edit_view->GetSelectionBounds(&start, &end); EXPECT_EQ(old_text.size(), start); EXPECT_EQ(old_text.size(), end); @@ -886,7 +883,7 @@ IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, UndoRedoLinux) { IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, PrimarySelection) { AutocompleteEditView* edit_view = NULL; ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); - edit_view->SetUserText(ASCIIToUTF16("Hello world")); + edit_view->SetUserText(L"Hello world"); EXPECT_FALSE(edit_view->IsSelectAll()); // Move the cursor to the end. @@ -913,14 +910,14 @@ IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, AutocompleteEditView* edit_view = NULL; ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); // Insert text: ダ - edit_view->SetUserText(UTF8ToUTF16("\357\276\200\357\276\236")); + edit_view->SetUserText(UTF8ToWide("\357\276\200\357\276\236")); // Move the cursor to the end. ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END, false, false, false)); // Backspace should delete one character. ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false)); - EXPECT_EQ(UTF8ToUTF16("\357\276\200"), edit_view->GetText()); + EXPECT_EQ(UTF8ToWide("\357\276\200"), edit_view->GetText()); } // http://crbug.com/12316 @@ -938,7 +935,7 @@ IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, PasteReplacingAll) { ASSERT_TRUE(popup_model->IsOpen()); // Inline autocomplete shouldn't be triggered. - ASSERT_EQ(ASCIIToUTF16("abc"), edit_view->GetText()); + ASSERT_EQ(L"abc", edit_view->GetText()); } #endif diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc index 22d25a0..9a6b947 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc @@ -61,8 +61,8 @@ const char kSecurityErrorSchemeColor[] = "#a20000"; const double kStrikethroughStrokeRed = 162.0 / 256.0; const double kStrikethroughStrokeWidth = 2.0; -size_t GetUTF8Offset(const string16& text, size_t text_offset) { - return UTF16ToUTF8(text.substr(0, text_offset)).size(); +size_t GetUTF8Offset(const std::wstring& wide_text, size_t wide_text_offset) { + return WideToUTF8(wide_text.substr(0, wide_text_offset)).size(); } // Stores GTK+-specific state so it can be restored after switching tabs. @@ -456,7 +456,7 @@ void AutocompleteEditViewGtk::SaveStateToTab(TabContents* tab) { void AutocompleteEditViewGtk::Update(const TabContents* contents) { // NOTE: We're getting the URL text here from the ToolbarModel. bool visibly_changed_permanent_text = - model_->UpdatePermanentText(WideToUTF16Hack(toolbar_model_->GetText())); + model_->UpdatePermanentText(toolbar_model_->GetText()); ToolbarModel::SecurityLevel security_level = toolbar_model_->GetSecurityLevel(); @@ -490,7 +490,7 @@ void AutocompleteEditViewGtk::OpenURL(const GURL& url, PageTransition::Type transition, const GURL& alternate_nav_url, size_t selected_line, - const string16& keyword) { + const std::wstring& keyword) { if (!url.is_valid()) return; @@ -498,11 +498,11 @@ void AutocompleteEditViewGtk::OpenURL(const GURL& url, selected_line, keyword); } -string16 AutocompleteEditViewGtk::GetText() const { +std::wstring AutocompleteEditViewGtk::GetText() const { GtkTextIter start, end; GetTextBufferBounds(&start, &end); gchar* utf8 = gtk_text_buffer_get_text(text_buffer_, &start, &end, false); - string16 out(UTF8ToUTF16(utf8)); + std::wstring out(UTF8ToWide(utf8)); g_free(utf8); #if GTK_CHECK_VERSION(2, 20, 0) @@ -528,12 +528,12 @@ int AutocompleteEditViewGtk::GetIcon() const { toolbar_model_->GetIcon(); } -void AutocompleteEditViewGtk::SetUserText(const string16& text) { +void AutocompleteEditViewGtk::SetUserText(const std::wstring& text) { SetUserText(text, text, true); } -void AutocompleteEditViewGtk::SetUserText(const string16& text, - const string16& display_text, +void AutocompleteEditViewGtk::SetUserText(const std::wstring& text, + const std::wstring& display_text, bool update_popup) { model_->SetUserText(text); // TODO(deanm): something about selection / focus change here. @@ -543,17 +543,17 @@ void AutocompleteEditViewGtk::SetUserText(const string16& text, TextChanged(); } -void AutocompleteEditViewGtk::SetWindowTextAndCaretPos(const string16& text, +void AutocompleteEditViewGtk::SetWindowTextAndCaretPos(const std::wstring& text, size_t caret_pos) { CharRange range(static_cast<int>(caret_pos), static_cast<int>(caret_pos)); SetTextAndSelectedRange(text, range); } void AutocompleteEditViewGtk::SetForcedQuery() { - const string16 current_text(GetText()); - const size_t start = current_text.find_first_not_of(kWhitespaceUTF16); - if (start == string16::npos || (current_text[start] != '?')) { - SetUserText(ASCIIToUTF16("?")); + const std::wstring current_text(GetText()); + const size_t start = current_text.find_first_not_of(kWhitespaceWide); + if (start == std::wstring::npos || (current_text[start] != '?')) { + SetUserText(L"?"); } else { StartUpdatingHighlightedText(); SetSelectedRange(CharRange(current_text.size(), start + 1)); @@ -577,8 +577,8 @@ bool AutocompleteEditViewGtk::DeleteAtEndPressed() { return delete_at_end_pressed_; } -void AutocompleteEditViewGtk::GetSelectionBounds(string16::size_type* start, - string16::size_type* end) { +void AutocompleteEditViewGtk::GetSelectionBounds(std::wstring::size_type* start, + std::wstring::size_type* end) { CharRange selection = GetSelection(); *start = static_cast<size_t>(selection.cp_min); *end = static_cast<size_t>(selection.cp_max); @@ -618,7 +618,7 @@ void AutocompleteEditViewGtk::ClosePopup() { } void AutocompleteEditViewGtk::OnTemporaryTextMaybeChanged( - const string16& display_text, + const std::wstring& display_text, bool save_original_selection) { if (save_original_selection) saved_temporary_selection_ = GetSelection(); @@ -630,7 +630,7 @@ void AutocompleteEditViewGtk::OnTemporaryTextMaybeChanged( } bool AutocompleteEditViewGtk::OnInlineAutocompleteTextMaybeChanged( - const string16& display_text, + const std::wstring& display_text, size_t user_text_length) { if (display_text == GetText()) return false; @@ -702,7 +702,7 @@ bool AutocompleteEditViewGtk::OnAfterPossibleChange() { bool at_end_of_edit = (new_sel.cp_min == length && new_sel.cp_max == length); // See if the text or selection have changed since OnBeforePossibleChange(). - string16 new_text(GetText()); + std::wstring new_text(GetText()); text_changed_ = (new_text != text_before_change_); #if GTK_CHECK_VERSION(2, 20, 0) text_changed_ = @@ -836,8 +836,8 @@ views::View* AutocompleteEditViewGtk::AddToView(views::View* parent) { } bool AutocompleteEditViewGtk::CommitInstantSuggestion( - const string16& typed_text, - const string16& suggestion) { + const std::wstring& typed_text, + const std::wstring& suggestion) { return CommitInstantSuggestion(); } @@ -1433,7 +1433,7 @@ void AutocompleteEditViewGtk::HandlePopulatePopup(GtkWidget* sender, // back after shutdown, and similar issues. GtkClipboard* x_clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); gchar* text = gtk_clipboard_wait_for_text(x_clipboard); - string16 text_wstr = UTF8ToUTF16(text); + std::wstring text_wstr = UTF8ToWide(text); g_free(text); // Paste and Go menu item. @@ -1528,7 +1528,7 @@ void AutocompleteEditViewGtk::HandleDragDataReceived( if (!text) return; - string16 possible_url = UTF8ToUTF16(reinterpret_cast<char*>(text)); + std::wstring possible_url = UTF8ToWide(reinterpret_cast<char*>(text)); g_free(text); if (model_->CanPasteAndGo(CollapseWhitespace(possible_url, true))) { model_->PasteAndGo(); @@ -1677,14 +1677,15 @@ void AutocompleteEditViewGtk::HandleCopyOrCutClipboard(bool copy) { CharRange selection = GetSelection(); GURL url; - string16 text(UTF8ToUTF16(GetSelectedText())); + std::wstring text(UTF8ToWide(GetSelectedText())); bool write_url; model_->AdjustTextForCopy(selection.selection_min(), IsSelectAll(), &text, &url, &write_url); if (write_url) { + string16 text16(WideToUTF16(text)); BookmarkNodeData data; - data.ReadFromTuple(url, text); + data.ReadFromTuple(url, text16); data.WriteToClipboard(NULL); // Stop propagating the signal. @@ -1700,7 +1701,7 @@ void AutocompleteEditViewGtk::HandleCopyOrCutClipboard(bool copy) { gtk_text_buffer_delete_selection(text_buffer_, true, true); } - OwnPrimarySelection(UTF16ToUTF8(text)); + OwnPrimarySelection(WideToUTF8(text)); } void AutocompleteEditViewGtk::OwnPrimarySelection(const std::string& text) { @@ -1891,7 +1892,7 @@ void AutocompleteEditViewGtk::EmphasizeURLComponents() { // be treated as a search or a navigation, and is the same method the Paste // And Go system uses. url_parse::Component scheme, host; - string16 text(GetText()); + std::wstring text(GetText()); AutocompleteInput::ParseForEmphasizeComponents( text, model_->GetDesiredTLD(), &scheme, &host); const bool emphasize = model_->CurrentTextIsURL() && (host.len > 0); @@ -1953,7 +1954,7 @@ bool AutocompleteEditViewGtk::CommitInstantSuggestion() { return false; model()->FinalizeInstantQuery(GetText(), - UTF8ToUTF16(suggestion)); + UTF8ToWide(suggestion)); return true; } @@ -1974,10 +1975,10 @@ void AutocompleteEditViewGtk::SavePrimarySelection( clipboard, selected_text.data(), selected_text.size()); } -void AutocompleteEditViewGtk::SetTextAndSelectedRange(const string16& text, +void AutocompleteEditViewGtk::SetTextAndSelectedRange(const std::wstring& text, const CharRange& range) { if (text != GetText()) { - std::string utf8 = UTF16ToUTF8(text); + std::string utf8 = WideToUTF8(text); gtk_text_buffer_set_text(text_buffer_, utf8.data(), utf8.length()); } SetSelectedRange(range); @@ -2143,7 +2144,7 @@ std::string AutocompleteEditViewGtk::GetSelectedText() const { } void AutocompleteEditViewGtk::UpdatePrimarySelectionIfValidURL() { - string16 text = UTF8ToUTF16(GetSelectedText()); + std::wstring text = UTF8ToWide(GetSelectedText()); if (text.empty()) return; @@ -2155,7 +2156,7 @@ void AutocompleteEditViewGtk::UpdatePrimarySelectionIfValidURL() { model_->AdjustTextForCopy(selection.selection_min(), IsSelectAll(), &text, &url, &write_url); if (write_url) { - selected_text_ = UTF16ToUTF8(text); + selected_text_ = WideToUTF8(text); OwnPrimarySelection(selected_text_); } } @@ -2173,7 +2174,7 @@ void AutocompleteEditViewGtk::HandlePreeditChanged(GtkWidget* sender, // delete the selection range here explicitly. See http://crbug.com/18808. if (preedit_.empty()) gtk_text_buffer_delete_selection(text_buffer_, false, true); - preedit_ = UTF8ToUTF16(preedit); + preedit_ = UTF8ToWide(preedit); } else { preedit_.clear(); } diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h index 4508ffa..50426bb 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h +++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h @@ -105,27 +105,27 @@ class AutocompleteEditViewGtk : public AutocompleteEditView, PageTransition::Type transition, const GURL& alternate_nav_url, size_t selected_line, - const string16& keyword); + const std::wstring& keyword); - virtual string16 GetText() const; + virtual std::wstring GetText() const; virtual bool IsEditingOrEmpty() const; virtual int GetIcon() const; - virtual void SetUserText(const string16& text); - virtual void SetUserText(const string16& text, - const string16& display_text, + virtual void SetUserText(const std::wstring& text); + virtual void SetUserText(const std::wstring& text, + const std::wstring& display_text, bool update_popup); - virtual void SetWindowTextAndCaretPos(const string16& text, + virtual void SetWindowTextAndCaretPos(const std::wstring& text, size_t caret_pos); virtual void SetForcedQuery(); virtual bool IsSelectAll(); virtual bool DeleteAtEndPressed(); - virtual void GetSelectionBounds(string16::size_type* start, - string16::size_type* end); + virtual void GetSelectionBounds(std::wstring::size_type* start, + std::wstring::size_type* end); virtual void SelectAll(bool reversed); virtual void RevertAll(); @@ -134,10 +134,10 @@ class AutocompleteEditViewGtk : public AutocompleteEditView, virtual void SetFocus(); - virtual void OnTemporaryTextMaybeChanged(const string16& display_text, + virtual void OnTemporaryTextMaybeChanged(const std::wstring& display_text, bool save_original_selection); virtual bool OnInlineAutocompleteTextMaybeChanged( - const string16& display_text, size_t user_text_length); + const std::wstring& display_text, size_t user_text_length); virtual void OnRevertTemporaryText(); virtual void OnBeforePossibleChange(); virtual bool OnAfterPossibleChange(); @@ -149,8 +149,8 @@ class AutocompleteEditViewGtk : public AutocompleteEditView, #if defined(TOOLKIT_VIEWS) virtual views::View* AddToView(views::View* parent); - virtual bool CommitInstantSuggestion(const string16& typed_text, - const string16& suggested_text); + virtual bool CommitInstantSuggestion(const std::wstring& typed_text, + const std::wstring& suggested_text); // Enables accessibility on AutocompleteEditView. void EnableAccessibility(); @@ -323,7 +323,7 @@ class AutocompleteEditViewGtk : public AutocompleteEditView, void SavePrimarySelection(const std::string& selected_text); // Update the field with |text| and set the selection. - void SetTextAndSelectedRange(const string16& text, + void SetTextAndSelectedRange(const std::wstring& text, const CharRange& range); // Set the selection to |range|. @@ -408,7 +408,7 @@ class AutocompleteEditViewGtk : public AutocompleteEditView, CharRange saved_temporary_selection_; // Tracking state before and after a possible change. - string16 text_before_change_; + std::wstring text_before_change_; CharRange sel_before_change_; // The most-recently-selected text from the entry that was copied to the @@ -511,7 +511,7 @@ class AutocompleteEditViewGtk : public AutocompleteEditView, #if GTK_CHECK_VERSION(2, 20, 0) // Stores the text being composed by the input method. - string16 preedit_; + std::wstring preedit_; // Tracking preedit state before and after a possible change. We don't need to // track preedit_'s content, as it'll be treated as part of text content. diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.h b/chrome/browser/autocomplete/autocomplete_edit_view_mac.h index a671393..0135f1d 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.h +++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.h @@ -46,37 +46,37 @@ class AutocompleteEditViewMac : public AutocompleteEditView, PageTransition::Type transition, const GURL& alternate_nav_url, size_t selected_line, - const string16& keyword); + const std::wstring& keyword); - virtual string16 GetText() const; + virtual std::wstring GetText() const; virtual bool IsEditingOrEmpty() const; virtual int GetIcon() const; - virtual void SetUserText(const string16& text); - virtual void SetUserText(const string16& text, - const string16& display_text, + virtual void SetUserText(const std::wstring& text); + virtual void SetUserText(const std::wstring& text, + const std::wstring& display_text, bool update_popup); - virtual void SetWindowTextAndCaretPos(const string16& text, + virtual void SetWindowTextAndCaretPos(const std::wstring& text, size_t caret_pos); virtual void SetForcedQuery(); virtual bool IsSelectAll(); virtual bool DeleteAtEndPressed(); - virtual void GetSelectionBounds(string16::size_type* start, - string16::size_type* end); + virtual void GetSelectionBounds(std::wstring::size_type* start, + std::wstring::size_type* end); virtual void SelectAll(bool reversed); virtual void RevertAll(); virtual void UpdatePopup(); virtual void ClosePopup(); virtual void SetFocus(); - virtual void OnTemporaryTextMaybeChanged(const string16& display_text, + virtual void OnTemporaryTextMaybeChanged(const std::wstring& display_text, bool save_original_selection); virtual bool OnInlineAutocompleteTextMaybeChanged( - const string16& display_text, size_t user_text_length); + const std::wstring& display_text, size_t user_text_length); virtual void OnStartingIME(); virtual void OnRevertTemporaryText(); virtual void OnBeforePossibleChange(); @@ -111,7 +111,7 @@ class AutocompleteEditViewMac : public AutocompleteEditView, // Helper to get appropriate contents from |clipboard|. Returns // empty string if no appropriate data is found on |clipboard|. - static string16 GetClipboardText(ui::Clipboard* clipboard); + static std::wstring GetClipboardText(ui::Clipboard* clipboard); // Helper to get the font to use in the field, exposed for the // popup. @@ -147,14 +147,14 @@ class AutocompleteEditViewMac : public AutocompleteEditView, // Update the field with |display_text| and highlight the host and scheme (if // it's an URL or URL-fragment). Resets any suggest text that may be present. - void SetText(const string16& display_text); + void SetText(const std::wstring& display_text); // Internal implementation of SetText. Does not reset the suggest text before // setting the display text. Most callers should use |SetText()| instead. - void SetTextInternal(const string16& display_text); + void SetTextInternal(const std::wstring& display_text); // Update the field with |display_text| and set the selection. - void SetTextAndSelectedRange(const string16& display_text, + void SetTextAndSelectedRange(const std::wstring& display_text, const NSRange range); // Returns the non-suggest portion of |field_|'s string value. @@ -167,7 +167,7 @@ class AutocompleteEditViewMac : public AutocompleteEditView, // Calculates text attributes according to |display_text| and applies them // to the given |as| object. - void ApplyTextAttributes(const string16& display_text, + void ApplyTextAttributes(const std::wstring& display_text, NSMutableAttributedString* as); scoped_ptr<AutocompleteEditModel> model_; @@ -189,7 +189,7 @@ class AutocompleteEditViewMac : public AutocompleteEditView, // Tracking state before and after a possible change for reporting // to model_. NSRange selection_before_change_; - string16 text_before_change_; + std::wstring text_before_change_; NSRange marked_range_before_change_; // Length of the suggest text. The suggest text always appears at the end of diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm index a003166..508bfc5 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm +++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm @@ -232,7 +232,7 @@ void AutocompleteEditViewMac::Update( // this is. Maybe this method should be refactored into more // specific cases. const bool user_visible = - model_->UpdatePermanentText(WideToUTF16Hack(toolbar_model_->GetText())); + model_->UpdatePermanentText(toolbar_model_->GetText()); if (tab_for_state_restoring) { RevertAll(); @@ -279,7 +279,7 @@ void AutocompleteEditViewMac::OpenURL(const GURL& url, PageTransition::Type transition, const GURL& alternate_nav_url, size_t selected_line, - const string16& keyword) { + const std::wstring& keyword) { // TODO(shess): Why is the caller passing an invalid url in the // first place? Make sure that case isn't being dropped on the // floor. @@ -291,8 +291,8 @@ void AutocompleteEditViewMac::OpenURL(const GURL& url, selected_line, keyword); } -string16 AutocompleteEditViewMac::GetText() const { - return base::SysNSStringToUTF16(GetNonSuggestTextSubstring()); +std::wstring AutocompleteEditViewMac::GetText() const { + return base::SysNSStringToWide(GetNonSuggestTextSubstring()); } bool AutocompleteEditViewMac::IsEditingOrEmpty() const { @@ -306,12 +306,12 @@ int AutocompleteEditViewMac::GetIcon() const { toolbar_model_->GetIcon(); } -void AutocompleteEditViewMac::SetUserText(const string16& text) { +void AutocompleteEditViewMac::SetUserText(const std::wstring& text) { SetUserText(text, text, true); } -void AutocompleteEditViewMac::SetUserText(const string16& text, - const string16& display_text, +void AutocompleteEditViewMac::SetUserText(const std::wstring& text, + const std::wstring& display_text, bool update_popup) { model_->SetUserText(text); // TODO(shess): TODO below from gtk. @@ -351,7 +351,7 @@ void AutocompleteEditViewMac::SetSelectedRange(const NSRange range) { } } -void AutocompleteEditViewMac::SetWindowTextAndCaretPos(const string16& text, +void AutocompleteEditViewMac::SetWindowTextAndCaretPos(const std::wstring& text, size_t caret_pos) { DCHECK_LE(caret_pos, text.size()); SetTextAndSelectedRange(text, NSMakeRange(caret_pos, caret_pos)); @@ -361,10 +361,10 @@ void AutocompleteEditViewMac::SetForcedQuery() { // We need to do this first, else |SetSelectedRange()| won't work. FocusLocation(true); - const string16 current_text(GetText()); - const size_t start = current_text.find_first_not_of(kWhitespaceUTF16); - if (start == string16::npos || (current_text[start] != '?')) { - SetUserText(ASCIIToUTF16("?")); + const std::wstring current_text(GetText()); + const size_t start = current_text.find_first_not_of(kWhitespaceWide); + if (start == std::wstring::npos || (current_text[start] != '?')) { + SetUserText(L"?"); } else { NSRange range = NSMakeRange(start + 1, current_text.size() - start - 1); [[field_ currentEditor] setSelectedRange:range]; @@ -382,8 +382,8 @@ bool AutocompleteEditViewMac::DeleteAtEndPressed() { return delete_at_end_pressed_; } -void AutocompleteEditViewMac::GetSelectionBounds(string16::size_type* start, - string16::size_type* end) { +void AutocompleteEditViewMac::GetSelectionBounds(std::wstring::size_type* start, + std::wstring::size_type* end) { if (![field_ currentEditor]) { *start = *end = 0; return; @@ -448,24 +448,24 @@ bool AutocompleteEditViewMac::CommitSuggestText() { if (suggest_text_length_ == 0) return false; - string16 input_text(GetText()); + std::wstring input_text(GetText()); suggest_text_length_ = 0; - string16 text(GetText()); + std::wstring text(GetText()); // Call SetText() to force a redraw and move the cursor to the end. SetText(text); model()->FinalizeInstantQuery(input_text, text.substr(input_text.size())); return true; } -void AutocompleteEditViewMac::SetText(const string16& display_text) { +void AutocompleteEditViewMac::SetText(const std::wstring& display_text) { // If we are setting the text directly, there cannot be any suggest text. suggest_text_length_ = 0; SetTextInternal(display_text); } void AutocompleteEditViewMac::SetTextInternal( - const string16& display_text) { - NSString* ss = base::SysUTF16ToNSString(display_text); + const std::wstring& display_text) { + NSString* ss = base::SysWideToNSString(display_text); NSMutableAttributedString* as = [[[NSMutableAttributedString alloc] initWithString:ss] autorelease]; @@ -491,7 +491,7 @@ void AutocompleteEditViewMac::SetTextInternal( } void AutocompleteEditViewMac::SetTextAndSelectedRange( - const string16& display_text, const NSRange range) { + const std::wstring& display_text, const NSRange range) { SetText(display_text); SetSelectedRange(range); } @@ -528,7 +528,7 @@ void AutocompleteEditViewMac::EmphasizeURLComponents() { } void AutocompleteEditViewMac::ApplyTextAttributes( - const string16& display_text, NSMutableAttributedString* as) { + const std::wstring& display_text, NSMutableAttributedString* as) { [as addAttribute:NSFontAttributeName value:GetFieldFont() range:NSMakeRange(0, [as length])]; @@ -588,7 +588,7 @@ void AutocompleteEditViewMac::ApplyTextAttributes( } void AutocompleteEditViewMac::OnTemporaryTextMaybeChanged( - const string16& display_text, bool save_original_selection) { + const std::wstring& display_text, bool save_original_selection) { if (save_original_selection) saved_temporary_selection_ = GetSelectedRange(); @@ -606,7 +606,7 @@ void AutocompleteEditViewMac::OnStartingIME() { } bool AutocompleteEditViewMac::OnInlineAutocompleteTextMaybeChanged( - const string16& display_text, size_t user_text_length) { + const std::wstring& display_text, size_t user_text_length) { // TODO(shess): Make sure that this actually works. The round trip // to native form and back may mean that it's the same but not the // same. @@ -645,7 +645,7 @@ bool AutocompleteEditViewMac::OnAfterPossibleChange() { DCHECK(IsFirstResponder()); const NSRange new_selection(GetSelectedRange()); - const string16 new_text(GetText()); + const std::wstring new_text(GetText()); const size_t length = new_text.length(); const bool selection_differs = @@ -715,7 +715,7 @@ void AutocompleteEditViewMac::SetInstantSuggestion( if (needs_update) { NSRange current_range = GetSelectedRange(); - SetTextInternal(base::SysNSStringToUTF16(text)); + SetTextInternal(base::SysNSStringToWide(text)); if (NSMaxRange(current_range) <= [text length] - suggest_text_length_) SetSelectedRange(current_range); else @@ -901,7 +901,7 @@ void AutocompleteEditViewMac::CopyToPasteboard(NSPasteboard* pb) { DCHECK(CanCopy()); const NSRange selection = GetSelectedRange(); - string16 text = base::SysNSStringToUTF16( + std::wstring text = base::SysNSStringToWide( [[field_ stringValue] substringWithRange:selection]); GURL url; @@ -909,7 +909,7 @@ void AutocompleteEditViewMac::CopyToPasteboard(NSPasteboard* pb) { model_->AdjustTextForCopy(selection.location, IsSelectAll(), &text, &url, &write_url); - NSString* nstext = base::SysUTF16ToNSString(text); + NSString* nstext = base::SysWideToNSString(text); [pb declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil]; [pb setString:nstext forType:NSStringPboardType]; @@ -923,11 +923,11 @@ void AutocompleteEditViewMac::OnPaste() { // This code currently expects |field_| to be focussed. DCHECK([field_ currentEditor]); - string16 text = GetClipboardText(g_browser_process->clipboard()); + std::wstring text = GetClipboardText(g_browser_process->clipboard()); if (text.empty()) { return; } - NSString* s = base::SysUTF16ToNSString(text); + NSString* s = base::SysWideToNSString(text); // -shouldChangeTextInRange:* and -didChangeText are documented in // NSTextView as things you need to do if you write additional @@ -1048,7 +1048,7 @@ void AutocompleteEditViewMac::FocusLocation(bool select_all) { // TODO(shess): Copied from autocomplete_edit_view_win.cc. Could this // be pushed into the model? -string16 AutocompleteEditViewMac::GetClipboardText( +std::wstring AutocompleteEditViewMac::GetClipboardText( ui::Clipboard* clipboard) { // autocomplete_edit_view_win.cc assumes this can never happen, we // will too. @@ -1065,7 +1065,7 @@ string16 AutocompleteEditViewMac::GetClipboardText( // lines in terminals, email programs, etc., and so linebreaks indicate // completely bogus whitespace that would just cause the input to be // invalid. - return CollapseWhitespace(text16, true); + return CollapseWhitespace(UTF16ToWide(text16), true); } // Try bookmark format. @@ -1082,11 +1082,11 @@ string16 AutocompleteEditViewMac::GetClipboardText( // pass resulting url string through GURL to normalize GURL url(url_str); if (url.is_valid()) { - return UTF8ToUTF16(url.spec()); + return UTF8ToWide(url.spec()); } } - return string16(); + return std::wstring(); } // static diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac_unittest.mm b/chrome/browser/autocomplete/autocomplete_edit_view_mac_unittest.mm index 68d07ed..da52d28 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_mac_unittest.mm +++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac_unittest.mm @@ -17,12 +17,12 @@ namespace { TEST(AutocompleteEditViewMacTest, GetClipboardText) { ui::Clipboard clipboard; - string16 text; + std::wstring text; // Does an empty clipboard get empty text? clipboard.WriteObjects(ui::Clipboard::ObjectMap()); text = AutocompleteEditViewMac::GetClipboardText(&clipboard); - EXPECT_EQ(string16(), text); + EXPECT_EQ(std::wstring(), text); const string16 plainText(ASCIIToUTF16("test text")); const std::string url("http://www.example.com/"); @@ -35,7 +35,7 @@ TEST(AutocompleteEditViewMacTest, GetClipboardText) { } text = AutocompleteEditViewMac::GetClipboardText(&clipboard); - EXPECT_EQ(plainText, text); + EXPECT_EQ(UTF16ToWide(plainText), text); // Can we pull a bookmark off the clipboard? { @@ -44,7 +44,7 @@ TEST(AutocompleteEditViewMacTest, GetClipboardText) { } text = AutocompleteEditViewMac::GetClipboardText(&clipboard); - EXPECT_EQ(ASCIIToUTF16(url), text); + EXPECT_EQ(ASCIIToWide(url), text); // Do we pull text in preference to a bookmark? { @@ -54,7 +54,7 @@ TEST(AutocompleteEditViewMacTest, GetClipboardText) { } text = AutocompleteEditViewMac::GetClipboardText(&clipboard); - EXPECT_EQ(plainText, text); + EXPECT_EQ(UTF16ToWide(plainText), text); // Do we get nothing if there is neither text nor a bookmark? { diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_views.cc b/chrome/browser/autocomplete/autocomplete_edit_view_views.cc index fc4d023..e22b1d8 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_views.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_views.cc @@ -288,7 +288,7 @@ void AutocompleteEditViewViews::SaveStateToTab(TabContents* tab) { void AutocompleteEditViewViews::Update(const TabContents* contents) { // NOTE: We're getting the URL text here from the ToolbarModel. bool visibly_changed_permanent_text = - model_->UpdatePermanentText(WideToUTF16Hack(toolbar_model_->GetText())); + model_->UpdatePermanentText(toolbar_model_->GetText()); ToolbarModel::SecurityLevel security_level = toolbar_model_->GetSecurityLevel(); @@ -321,7 +321,7 @@ void AutocompleteEditViewViews::OpenURL(const GURL& url, PageTransition::Type transition, const GURL& alternate_nav_url, size_t selected_line, - const string16& keyword) { + const std::wstring& keyword) { if (!url.is_valid()) return; @@ -329,9 +329,9 @@ void AutocompleteEditViewViews::OpenURL(const GURL& url, selected_line, keyword); } -string16 AutocompleteEditViewViews::GetText() const { +std::wstring AutocompleteEditViewViews::GetText() const { // TODO(oshima): IME support - return textfield_->text(); + return UTF16ToWide(textfield_->text()); } bool AutocompleteEditViewViews::IsEditingOrEmpty() const { @@ -344,12 +344,12 @@ int AutocompleteEditViewViews::GetIcon() const { toolbar_model_->GetIcon(); } -void AutocompleteEditViewViews::SetUserText(const string16& text) { +void AutocompleteEditViewViews::SetUserText(const std::wstring& text) { SetUserText(text, text, true); } -void AutocompleteEditViewViews::SetUserText(const string16& text, - const string16& display_text, +void AutocompleteEditViewViews::SetUserText(const std::wstring& text, + const std::wstring& display_text, bool update_popup) { model_->SetUserText(text); SetWindowTextAndCaretPos(display_text, display_text.length()); @@ -359,17 +359,17 @@ void AutocompleteEditViewViews::SetUserText(const string16& text, } void AutocompleteEditViewViews::SetWindowTextAndCaretPos( - const string16& text, + const std::wstring& text, size_t caret_pos) { const views::TextRange range(caret_pos, caret_pos); SetTextAndSelectedRange(text, range); } void AutocompleteEditViewViews::SetForcedQuery() { - const string16 current_text(GetText()); - const size_t start = current_text.find_first_not_of(kWhitespaceUTF16); - if (start == string16::npos || (current_text[start] != '?')) { - SetUserText(ASCIIToUTF16("?")); + const std::wstring current_text(GetText()); + const size_t start = current_text.find_first_not_of(kWhitespaceWide); + if (start == std::wstring::npos || (current_text[start] != '?')) { + SetUserText(L"?"); } else { SelectRange(current_text.size(), start + 1); } @@ -385,8 +385,8 @@ bool AutocompleteEditViewViews::DeleteAtEndPressed() { } void AutocompleteEditViewViews::GetSelectionBounds( - string16::size_type* start, - string16::size_type* end) { + std::wstring::size_type* start, + std::wstring::size_type* end) { views::TextRange range; textfield_->GetSelectedRange(&range); *start = static_cast<size_t>(range.end()); @@ -435,7 +435,7 @@ void AutocompleteEditViewViews::SetFocus() { } void AutocompleteEditViewViews::OnTemporaryTextMaybeChanged( - const string16& display_text, + const std::wstring& display_text, bool save_original_selection) { if (save_original_selection) textfield_->GetSelectedRange(&saved_temporary_selection_); @@ -445,7 +445,7 @@ void AutocompleteEditViewViews::OnTemporaryTextMaybeChanged( } bool AutocompleteEditViewViews::OnInlineAutocompleteTextMaybeChanged( - const string16& display_text, + const std::wstring& display_text, size_t user_text_length) { if (display_text == GetText()) return false; @@ -482,7 +482,7 @@ bool AutocompleteEditViewViews::OnAfterPossibleChange() { bool at_end_of_edit = (new_sel.start() == length && new_sel.end() == length); // See if the text or selection have changed since OnBeforePossibleChange(). - string16 new_text = GetText(); + std::wstring new_text = GetText(); text_changed_ = (new_text != text_before_change_); bool selection_differs = !((sel_before_change_.is_empty() && new_sel.is_empty()) || @@ -543,8 +543,8 @@ bool AutocompleteEditViewViews::IsImeComposing() const { } bool AutocompleteEditViewViews::CommitInstantSuggestion( - const string16& typed_text, - const string16& suggested_text) { + const std::wstring& typed_text, + const std::wstring& suggested_text) { model_->FinalizeInstantQuery(typed_text, suggested_text); return true; } @@ -619,10 +619,10 @@ void AutocompleteEditViewViews::TextChanged() { } void AutocompleteEditViewViews::SetTextAndSelectedRange( - const string16& text, + const std::wstring& text, const views::TextRange& range) { if (text != GetText()) - textfield_->SetText(text); + textfield_->SetText(WideToUTF16(text)); textfield_->SelectRange(range); } diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_views.h b/chrome/browser/autocomplete/autocomplete_edit_view_views.h index ae2b1a7..9c17ad8 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_views.h +++ b/chrome/browser/autocomplete/autocomplete_edit_view_views.h @@ -81,32 +81,32 @@ class AutocompleteEditViewViews : public views::View, PageTransition::Type transition, const GURL& alternate_nav_url, size_t selected_line, - const string16& keyword); + const std::wstring& keyword); - virtual string16 GetText() const; + virtual std::wstring GetText() const; virtual bool IsEditingOrEmpty() const; virtual int GetIcon() const; - virtual void SetUserText(const string16& text); - virtual void SetUserText(const string16& text, - const string16& display_text, + virtual void SetUserText(const std::wstring& text); + virtual void SetUserText(const std::wstring& text, + const std::wstring& display_text, bool update_popup); - virtual void SetWindowTextAndCaretPos(const string16& text, + virtual void SetWindowTextAndCaretPos(const std::wstring& text, size_t caret_pos); virtual void SetForcedQuery(); virtual bool IsSelectAll(); virtual bool DeleteAtEndPressed(); - virtual void GetSelectionBounds(string16::size_type* start, - string16::size_type* end); + virtual void GetSelectionBounds(std::wstring::size_type* start, + std::wstring::size_type* end); virtual void SelectAll(bool reversed); virtual void RevertAll(); virtual void UpdatePopup(); virtual void ClosePopup(); virtual void SetFocus(); - virtual void OnTemporaryTextMaybeChanged(const string16& display_text, + virtual void OnTemporaryTextMaybeChanged(const std::wstring& display_text, bool save_original_selection); virtual bool OnInlineAutocompleteTextMaybeChanged( - const string16& display_text, size_t user_text_length); + const std::wstring& display_text, size_t user_text_length); virtual void OnRevertTemporaryText(); virtual void OnBeforePossibleChange(); virtual bool OnAfterPossibleChange(); @@ -115,8 +115,8 @@ class AutocompleteEditViewViews : public views::View, virtual views::View* AddToView(views::View* parent); virtual int TextWidth() const; virtual bool IsImeComposing() const; - virtual bool CommitInstantSuggestion(const string16& typed_text, - const string16& suggested_text); + virtual bool CommitInstantSuggestion(const std::wstring& typed_text, + const std::wstring& suggested_text); virtual void SetInstantSuggestion(const string16& input); // Overridden from NotificationObserver: @@ -141,7 +141,7 @@ class AutocompleteEditViewViews : public views::View, void TextChanged(); // Update the field with |text| and set the selection. - void SetTextAndSelectedRange(const string16& text, + void SetTextAndSelectedRange(const std::wstring& text, const views::TextRange& range); // Returns the selected text. @@ -172,7 +172,7 @@ class AutocompleteEditViewViews : public views::View, views::TextRange saved_temporary_selection_; // Tracking state before and after a possible change. - string16 text_before_change_; + std::wstring text_before_change_; views::TextRange sel_before_change_; // TODO(oshima): following flags are copied from gtk implementation. diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc index 89d8f55..3af9ed8 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc @@ -183,7 +183,7 @@ DWORD EditDropTarget::OnDrop(IDataObject* data_object, if (drag_has_url_) { GURL url; - string16 title; + std::wstring title; if (os_data.GetURLAndTitle(&url, &title)) { edit_->SetUserText(UTF8ToWide(url.spec())); edit_->model()->AcceptInput(CURRENT_TAB, true); @@ -191,7 +191,7 @@ DWORD EditDropTarget::OnDrop(IDataObject* data_object, } } else if (drag_has_string_) { int string_drop_position = edit_->drop_highlight_position(); - string16 text; + std::wstring text; if ((string_drop_position != -1 || !edit_->in_drag()) && os_data.GetString(&text)) { DCHECK(string_drop_position == -1 || @@ -597,7 +597,7 @@ void AutocompleteEditViewWin::OpenURL(const GURL& url, PageTransition::Type transition, const GURL& alternate_nav_url, size_t selected_line, - const string16& keyword) { + const std::wstring& keyword) { if (!url.is_valid()) return; @@ -610,9 +610,9 @@ void AutocompleteEditViewWin::OpenURL(const GURL& url, selected_line, keyword); } -string16 AutocompleteEditViewWin::GetText() const { +std::wstring AutocompleteEditViewWin::GetText() const { const int len = GetTextLength() + 1; - string16 str; + std::wstring str; GetWindowText(WriteInto(&str, len), len); return str; } @@ -627,12 +627,12 @@ int AutocompleteEditViewWin::GetIcon() const { toolbar_model_->GetIcon(); } -void AutocompleteEditViewWin::SetUserText(const string16& text) { +void AutocompleteEditViewWin::SetUserText(const std::wstring& text) { SetUserText(text, text, true); } -void AutocompleteEditViewWin::SetUserText(const string16& text, - const string16& display_text, +void AutocompleteEditViewWin::SetUserText(const std::wstring& text, + const std::wstring& display_text, bool update_popup) { ScopedFreeze freeze(this, GetTextObjectModel()); model_->SetUserText(text); @@ -643,16 +643,16 @@ void AutocompleteEditViewWin::SetUserText(const string16& text, TextChanged(); } -void AutocompleteEditViewWin::SetWindowTextAndCaretPos(const string16& text, +void AutocompleteEditViewWin::SetWindowTextAndCaretPos(const std::wstring& text, size_t caret_pos) { SetWindowText(text.c_str()); PlaceCaretAt(caret_pos); } void AutocompleteEditViewWin::SetForcedQuery() { - const string16 current_text(GetText()); + const std::wstring current_text(GetText()); const size_t start = current_text.find_first_not_of(kWhitespaceWide); - if (start == string16::npos || (current_text[start] != '?')) + if (start == std::wstring::npos || (current_text[start] != '?')) SetUserText(L"?"); else SetSelection(current_text.length(), start + 1); @@ -668,8 +668,8 @@ bool AutocompleteEditViewWin::DeleteAtEndPressed() { return delete_at_end_pressed_; } -void AutocompleteEditViewWin::GetSelectionBounds(string16::size_type* start, - string16::size_type* end) { +void AutocompleteEditViewWin::GetSelectionBounds(std::wstring::size_type* start, + std::wstring::size_type* end) { CHARRANGE selection; GetSel(selection); *start = static_cast<size_t>(selection.cpMin); @@ -761,7 +761,7 @@ void AutocompleteEditViewWin::SetDropHighlightPosition(int position) { } void AutocompleteEditViewWin::MoveSelectedText(int new_position) { - const string16 selected_text(GetSelectedText()); + const std::wstring selected_text(GetSelectedText()); CHARRANGE sel; GetSel(sel); DCHECK((sel.cpMax != sel.cpMin) && (new_position >= 0) && @@ -783,7 +783,7 @@ void AutocompleteEditViewWin::MoveSelectedText(int new_position) { } void AutocompleteEditViewWin::InsertText(int position, - const string16& text) { + const std::wstring& text) { DCHECK((position >= 0) && (position <= GetTextLength())); ScopedFreeze freeze(this, GetTextObjectModel()); OnBeforePossibleChange(); @@ -793,7 +793,7 @@ void AutocompleteEditViewWin::InsertText(int position, } void AutocompleteEditViewWin::OnTemporaryTextMaybeChanged( - const string16& display_text, + const std::wstring& display_text, bool save_original_selection) { if (save_original_selection) GetSelection(original_selection_); @@ -811,7 +811,7 @@ void AutocompleteEditViewWin::OnTemporaryTextMaybeChanged( } bool AutocompleteEditViewWin::OnInlineAutocompleteTextMaybeChanged( - const string16& display_text, + const std::wstring& display_text, size_t user_text_length) { // Update the text and selection. Because this can be called repeatedly while // typing, we've careful not to freeze the edit unless we really need to. @@ -870,7 +870,7 @@ bool AutocompleteEditViewWin::OnAfterPossibleChangeInternal( (new_sel.cpMin == length) && (new_sel.cpMax == length); // See if the text or selection have changed since OnBeforePossibleChange(). - const string16 new_text(GetText()); + const std::wstring new_text(GetText()); const bool text_differs = (new_text != text_before_change_) || force_text_changed; @@ -947,13 +947,13 @@ views::View* AutocompleteEditViewWin::AddToView(views::View* parent) { } bool AutocompleteEditViewWin::CommitInstantSuggestion( - const string16& typed_text, - const string16& suggested_text) { + const std::wstring& typed_text, + const std::wstring& suggested_text) { model_->FinalizeInstantQuery(typed_text, suggested_text); return true; } -void AutocompleteEditViewWin::PasteAndGo(const string16& text) { +void AutocompleteEditViewWin::PasteAndGo(const std::wstring& text) { if (CanPasteAndGo(text)) model_->PasteAndGo(); } @@ -1049,7 +1049,7 @@ bool AutocompleteEditViewWin::IsItemForCommandIdDynamic(int command_id) const { return command_id == IDS_PASTE_AND_GO; } -string16 AutocompleteEditViewWin::GetLabelForCommandId( +std::wstring AutocompleteEditViewWin::GetLabelForCommandId( int command_id) const { DCHECK(command_id == IDS_PASTE_AND_GO); return l10n_util::GetStringUTF16(model_->is_paste_and_search() ? @@ -1261,7 +1261,7 @@ void AutocompleteEditViewWin::OnContextMenu(HWND window, const CPoint& point) { } void AutocompleteEditViewWin::OnCopy() { - string16 text(GetSelectedText()); + std::wstring text(GetSelectedText()); if (text.empty()) return; @@ -1369,7 +1369,7 @@ void AutocompleteEditViewWin::OnKeyUp(TCHAR key, ((key == VK_SHIFT) && (GetKeyState(VK_CONTROL) < 0)))) { ScopedFreeze freeze(this, GetTextObjectModel()); - string16 saved_text(GetText()); + std::wstring saved_text(GetText()); CHARRANGE saved_sel; GetSelection(saved_sel); @@ -1691,7 +1691,7 @@ void AutocompleteEditViewWin::OnPaint(HDC bogus_hdc) { void AutocompleteEditViewWin::OnPaste() { // Replace the selection if we have something to paste. - const string16 text(GetClipboardText()); + const std::wstring text(GetClipboardText()); if (!text.empty()) { // Record this paste, so we can do different behavior. model_->on_paste(); @@ -2033,13 +2033,13 @@ void AutocompleteEditViewWin::GetSelection(CHARRANGE& sel) const { std::swap(sel.cpMin, sel.cpMax); } -string16 AutocompleteEditViewWin::GetSelectedText() const { +std::wstring AutocompleteEditViewWin::GetSelectedText() const { // Figure out the length of the selection. CHARRANGE sel; GetSel(sel); // Grab the selected text. - string16 str; + std::wstring str; GetSelText(WriteInto(&str, sel.cpMax - sel.cpMin + 1)); return str; } @@ -2060,7 +2060,7 @@ void AutocompleteEditViewWin::SetSelection(LONG start, LONG end) { selection->SetFlags(tomSelStartActive); } -void AutocompleteEditViewWin::PlaceCaretAt(string16::size_type pos) { +void AutocompleteEditViewWin::PlaceCaretAt(std::wstring::size_type pos) { SetSelection(static_cast<LONG>(pos), static_cast<LONG>(pos)); } @@ -2319,12 +2319,12 @@ void AutocompleteEditViewWin::TextChanged() { controller_->OnChanged(); } -string16 AutocompleteEditViewWin::GetClipboardText() const { +std::wstring AutocompleteEditViewWin::GetClipboardText() const { // Try text format. ui::Clipboard* clipboard = g_browser_process->clipboard(); if (clipboard->IsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(), ui::Clipboard::BUFFER_STANDARD)) { - string16 text; + std::wstring text; clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &text); // Note: Unlike in the find popup and textfield view, here we completely @@ -2353,10 +2353,10 @@ string16 AutocompleteEditViewWin::GetClipboardText() const { return UTF8ToWide(url.spec()); } - return string16(); + return std::wstring(); } -bool AutocompleteEditViewWin::CanPasteAndGo(const string16& text) const { +bool AutocompleteEditViewWin::CanPasteAndGo(const std::wstring& text) const { return !popup_window_mode_ && model_->CanPasteAndGo(text); } @@ -2400,8 +2400,8 @@ void AutocompleteEditViewWin::StartDragIfNecessary(const CPoint& point) { SetSelectionRange(sel); } - const string16 start_text(GetText()); - string16 text_to_write(GetSelectedText()); + const std::wstring start_text(GetText()); + std::wstring text_to_write(GetSelectedText()); GURL url; bool write_url; const bool is_all_selected = IsSelectAllForRange(sel); @@ -2412,7 +2412,7 @@ void AutocompleteEditViewWin::StartDragIfNecessary(const CPoint& point) { &text_to_write, &url, &write_url); if (write_url) { - string16 title; + std::wstring title; SkBitmap favicon; if (is_all_selected) model_->GetDataForURLExport(&url, &title, &favicon); @@ -2561,7 +2561,7 @@ int AutocompleteEditViewWin::GetHorizontalMargin() const { } int AutocompleteEditViewWin::WidthNeededToDisplay( - const string16& text) const { + const std::wstring& text) const { // Use font_.GetStringWidth() instead of // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.h b/chrome/browser/autocomplete/autocomplete_edit_view_win.h index 1b81787..847e62d 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_win.h +++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.h @@ -95,27 +95,27 @@ class AutocompleteEditViewWin PageTransition::Type transition, const GURL& alternate_nav_url, size_t selected_line, - const string16& keyword); + const std::wstring& keyword); - virtual string16 GetText() const; + virtual std::wstring GetText() const; virtual bool IsEditingOrEmpty() const; virtual int GetIcon() const; - virtual void SetUserText(const string16& text); - virtual void SetUserText(const string16& text, - const string16& display_text, + virtual void SetUserText(const std::wstring& text); + virtual void SetUserText(const std::wstring& text, + const std::wstring& display_text, bool update_popup); - virtual void SetWindowTextAndCaretPos(const string16& text, + virtual void SetWindowTextAndCaretPos(const std::wstring& text, size_t caret_pos); virtual void SetForcedQuery(); virtual bool IsSelectAll(); virtual bool DeleteAtEndPressed(); - virtual void GetSelectionBounds(string16::size_type* start, - string16::size_type* end); + virtual void GetSelectionBounds(std::wstring::size_type* start, + std::wstring::size_type* end); virtual void SelectAll(bool reversed); virtual void RevertAll(); @@ -124,10 +124,10 @@ class AutocompleteEditViewWin virtual void SetFocus(); - virtual void OnTemporaryTextMaybeChanged(const string16& display_text, + virtual void OnTemporaryTextMaybeChanged(const std::wstring& display_text, bool save_original_selection); virtual bool OnInlineAutocompleteTextMaybeChanged( - const string16& display_text, size_t user_text_length); + const std::wstring& display_text, size_t user_text_length); virtual void OnRevertTemporaryText(); virtual void OnBeforePossibleChange(); virtual bool OnAfterPossibleChange(); @@ -138,8 +138,8 @@ class AutocompleteEditViewWin virtual bool IsImeComposing() const; virtual views::View* AddToView(views::View* parent); - virtual bool CommitInstantSuggestion(const string16& typed_text, - const string16& suggested_text); + virtual bool CommitInstantSuggestion(const std::wstring& typed_text, + const std::wstring& suggested_text); int GetPopupMaxYCoordinate(); @@ -156,12 +156,12 @@ class AutocompleteEditViewWin void MoveSelectedText(int new_position); // Inserts the text at the specified position. - void InsertText(int position, const string16& text); + void InsertText(int position, const std::wstring& text); // Invokes CanPasteAndGo with the specified text, and if successful navigates // to the appropriate URL. The behavior of this is the same as if the user // typed in the specified text and pressed enter. - void PasteAndGo(const string16& text); + void PasteAndGo(const std::wstring& text); void set_force_hidden(bool force_hidden) { force_hidden_ = force_hidden; } @@ -213,7 +213,7 @@ class AutocompleteEditViewWin virtual bool GetAcceleratorForCommandId(int command_id, ui::Accelerator* accelerator); virtual bool IsItemForCommandIdDynamic(int command_id) const; - virtual string16 GetLabelForCommandId(int command_id) const; + virtual std::wstring GetLabelForCommandId(int command_id) const; virtual void ExecuteCommand(int command_id); private: @@ -312,7 +312,7 @@ class AutocompleteEditViewWin void GetSelection(CHARRANGE& sel) const; // Returns the currently selected text of the edit control. - string16 GetSelectedText() const; + std::wstring GetSelectedText() const; // Like SetSel(), but respects the selection direction implied by |start| and // |end|: if |end| < |start|, the effective cursor will be placed at the @@ -370,10 +370,10 @@ class AutocompleteEditViewWin // Returns the current clipboard contents as a string that can be pasted in. // In addition to just getting CF_UNICODETEXT out, this can also extract URLs // from bookmarks on the clipboard. - string16 GetClipboardText() const; + std::wstring GetClipboardText() const; // Determines whether the user can "paste and go", given the specified text. - bool CanPasteAndGo(const string16& text) const; + bool CanPasteAndGo(const std::wstring& text) const; // Getter for the text_object_model_. Note that the pointer returned here is // only valid as long as the AutocompleteEdit is still alive. Also, if the @@ -403,7 +403,7 @@ class AutocompleteEditViewWin int GetHorizontalMargin() const; // Returns the width in pixels needed to display |text|. - int WidthNeededToDisplay(const string16& text) const; + int WidthNeededToDisplay(const std::wstring& text) const; // Real implementation of OnAfterPossibleChange() method. // If |force_text_changed| is true, then the text_changed code will always be @@ -472,7 +472,7 @@ class AutocompleteEditViewWin bool ignore_ime_messages_; // Variables for tracking state before and after a possible change. - string16 text_before_change_; + std::wstring text_before_change_; CHARRANGE sel_before_change_; // Set at the same time the model's original_* members are set, and valid in diff --git a/chrome/browser/autocomplete/autocomplete_match.cc b/chrome/browser/autocomplete/autocomplete_match.cc index 02ec3f9..353cfad 100644 --- a/chrome/browser/autocomplete/autocomplete_match.cc +++ b/chrome/browser/autocomplete/autocomplete_match.cc @@ -12,7 +12,7 @@ AutocompleteMatch::AutocompleteMatch() : provider(NULL), relevance(0), deletable(false), - inline_autocomplete_offset(string16::npos), + inline_autocomplete_offset(std::wstring::npos), transition(PageTransition::GENERATED), is_history_what_you_typed_match(false), type(SEARCH_WHAT_YOU_TYPED), @@ -27,7 +27,7 @@ AutocompleteMatch::AutocompleteMatch(AutocompleteProvider* provider, : provider(provider), relevance(relevance), deletable(deletable), - inline_autocomplete_offset(string16::npos), + inline_autocomplete_offset(std::wstring::npos), transition(PageTransition::TYPED), is_history_what_you_typed_match(false), type(type), @@ -105,8 +105,8 @@ bool AutocompleteMatch::DestinationsEqual(const AutocompleteMatch& elem1, // static void AutocompleteMatch::ClassifyMatchInString( - const string16& find_text, - const string16& text, + const std::wstring& find_text, + const std::wstring& text, int style, ACMatchClassifications* classification) { ClassifyLocationInString(text.find(find_text), find_text.length(), @@ -132,7 +132,7 @@ void AutocompleteMatch::ClassifyLocationInString( } // Mark matching portion of string. - if (match_location == string16::npos) { + if (match_location == std::wstring::npos) { // No match, above classification will suffice for whole string. return; } @@ -156,7 +156,7 @@ void AutocompleteMatch::Validate() const { } void AutocompleteMatch::ValidateClassifications( - const string16& text, + const std::wstring& text, const ACMatchClassifications& classifications) const { if (text.empty()) { DCHECK(classifications.size() == 0); diff --git a/chrome/browser/autocomplete/autocomplete_match.h b/chrome/browser/autocomplete/autocomplete_match.h index bd7c489..88cbfee 100644 --- a/chrome/browser/autocomplete/autocomplete_match.h +++ b/chrome/browser/autocomplete/autocomplete_match.h @@ -108,8 +108,8 @@ struct AutocompleteMatch { // Fills in the classifications for |text|, using |style| as the base style // and marking the first instance of |find_text| as a match. (This match // will also not be dimmed, if |style| has DIM set.) - static void ClassifyMatchInString(const string16& find_text, - const string16& text, + static void ClassifyMatchInString(const std::wstring& find_text, + const std::wstring& text, int style, ACMatchClassifications* classifications); @@ -143,10 +143,10 @@ struct AutocompleteMatch { // This string is loaded into the location bar when the item is selected // by pressing the arrow keys. This may be different than a URL, for example, // for search suggestions, this would just be the search terms. - string16 fill_into_edit; + std::wstring fill_into_edit; // The position within fill_into_edit from which we'll display the inline - // autocomplete string. This will be string16::npos if this match should + // autocomplete string. This will be std::wstring::npos if this match should // not be inline autocompleted. size_t inline_autocomplete_offset; @@ -156,11 +156,11 @@ struct AutocompleteMatch { GURL destination_url; // The main text displayed in the address bar dropdown. - string16 contents; + std::wstring contents; ACMatchClassifications contents_class; // Additional helper text for each entry, such as a title or description. - string16 description; + std::wstring description; ACMatchClassifications description_class; // The transition type to use when the user opens this match. By default @@ -188,7 +188,7 @@ struct AutocompleteMatch { // Checks one text/classifications pair for valid values. void ValidateClassifications( - const string16& text, + const std::wstring& text, const ACMatchClassifications& classifications) const; #endif }; diff --git a/chrome/browser/autocomplete/autocomplete_popup_model.cc b/chrome/browser/autocomplete/autocomplete_popup_model.cc index 4f72b5f..588683d 100644 --- a/chrome/browser/autocomplete/autocomplete_popup_model.cc +++ b/chrome/browser/autocomplete/autocomplete_popup_model.cc @@ -49,8 +49,8 @@ void AutocompletePopupModel::SetProfile(Profile* profile) { } void AutocompletePopupModel::StartAutocomplete( - const string16& text, - const string16& desired_tld, + const std::wstring& text, + const std::wstring& desired_tld, bool prevent_inline_autocomplete, bool prefer_keyword, bool allow_exact_keyword_match) { @@ -134,11 +134,11 @@ void AutocompletePopupModel::SetSelectedLine(size_t line, // Update the edit with the new data for this match. // TODO(pkasting): If |selected_line_| moves to the controller, this can be // eliminated and just become a call to the observer on the edit. - string16 keyword; + std::wstring keyword; const bool is_keyword_hint = GetKeywordForMatch(match, &keyword); if (reset_to_default) { - string16 inline_autocomplete_text; - if ((match.inline_autocomplete_offset != string16::npos) && + std::wstring inline_autocomplete_text; + if ((match.inline_autocomplete_offset != std::wstring::npos) && (match.inline_autocomplete_offset < match.fill_into_edit.length())) { inline_autocomplete_text = match.fill_into_edit.substr(match.inline_autocomplete_offset); @@ -202,13 +202,13 @@ void AutocompletePopupModel::InfoForCurrentSelection( } bool AutocompletePopupModel::GetKeywordForMatch(const AutocompleteMatch& match, - string16* keyword) const { + std::wstring* keyword) const { // Assume we have no keyword until we find otherwise. keyword->clear(); // If the current match is a keyword, return that as the selected keyword. if (TemplateURL::SupportsReplacement(match.template_url)) { - keyword->assign(match.template_url->keyword()); + keyword->assign(UTF16ToWideHack(match.template_url->keyword())); return false; } @@ -217,7 +217,7 @@ bool AutocompletePopupModel::GetKeywordForMatch(const AutocompleteMatch& match, return false; profile_->GetTemplateURLModel()->Load(); const string16 keyword_hint(TemplateURLModel::CleanUserInputKeyword( - match.fill_into_edit)); + WideToUTF16Hack(match.fill_into_edit))); if (keyword_hint.empty()) return false; @@ -237,13 +237,13 @@ bool AutocompletePopupModel::GetKeywordForMatch(const AutocompleteMatch& match, return false; } - keyword->assign(keyword_hint); + keyword->assign(UTF16ToWideHack(keyword_hint)); return true; } void AutocompletePopupModel::FinalizeInstantQuery( - const string16& input_text, - const string16& suggest_text) { + const std::wstring& input_text, + const std::wstring& suggest_text) { if (IsOpen()) { SearchProvider* search_provider = controller_->search_provider(); search_provider->FinalizeInstantQuery(input_text, suggest_text); diff --git a/chrome/browser/autocomplete/autocomplete_popup_model.h b/chrome/browser/autocomplete/autocomplete_popup_model.h index 32162e9..ee1fef0 100644 --- a/chrome/browser/autocomplete/autocomplete_popup_model.h +++ b/chrome/browser/autocomplete/autocomplete_popup_model.h @@ -30,8 +30,8 @@ class AutocompletePopupModel : public NotificationObserver { // Starts a new query running. These parameters are passed through to the // autocomplete controller; see comments there. - void StartAutocomplete(const string16& text, - const string16& desired_tld, + void StartAutocomplete(const std::wstring& text, + const std::wstring& desired_tld, bool prevent_inline_autocomplete, bool prefer_keyword, bool allow_exact_keyword_match); @@ -98,11 +98,11 @@ class AutocompletePopupModel : public NotificationObserver { // possibly to the empty string], and you cannot have both a selected keyword // and a keyword hint simultaneously.) bool GetKeywordForMatch(const AutocompleteMatch& match, - string16* keyword) const; + std::wstring* keyword) const; // Calls through to SearchProvider::FinalizeInstantQuery. - void FinalizeInstantQuery(const string16& input_text, - const string16& suggest_text); + void FinalizeInstantQuery(const std::wstring& input_text, + const std::wstring& suggest_text); // Returns a pointer to a heap-allocated AutocompleteLog containing the // current input text, selected match, and result set. The caller is diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc index 61d7af6..6a38570 100644 --- a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc +++ b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc @@ -106,8 +106,8 @@ void DrawFullPixbuf(GdkDrawable* drawable, GdkGC* gc, GdkPixbuf* pixbuf, } // TODO(deanm): Find some better home for this, and make it more efficient. -size_t GetUTF8Offset(const string16& text, size_t text_offset) { - return UTF16ToUTF8(text.substr(0, text_offset)).size(); +size_t GetUTF8Offset(const std::wstring& wide_text, size_t wide_text_offset) { + return WideToUTF8(wide_text.substr(0, wide_text_offset)).size(); } // Generates the normal URL color, a green color used in unhighlighted URL @@ -170,7 +170,7 @@ GdkColor SelectedURLColor(GdkColor foreground, GdkColor background) { void AutocompletePopupViewGtk::SetupLayoutForMatch( PangoLayout* layout, - const string16& text, + const std::wstring& text, const AutocompleteMatch::ACMatchClassifications& classifications, const GdkColor* base_color, const GdkColor* dim_color, @@ -180,21 +180,21 @@ void AutocompletePopupViewGtk::SetupLayoutForMatch( // RTL characters inside it, so the ending punctuation displays correctly // and the eliding ellipsis displays correctly. We only mark the text with // LRE. Wrapping it with LRE and PDF by calling AdjustStringForLocaleDirection - // or WrapStringWithLTRFormatting will render the elllipsis at the left of the - // elided pure LTR text. + // will render the elllipsis at the left of the elided pure LTR text. bool marked_with_lre = false; - string16 localized_text = text; + std::wstring localized_text = text; bool is_rtl = base::i18n::IsRTL(); if (is_rtl && !base::i18n::StringContainsStrongRTLChars(localized_text)) { - localized_text.insert(0, 1, base::i18n::kLeftToRightEmbeddingMark); + localized_text.insert(0, 1, + static_cast<wchar_t>(base::i18n::kLeftToRightEmbeddingMark)); marked_with_lre = true; } // We can have a prefix, or insert additional characters while processing the // classifications. We need to take this in to account when we translate the - // UTF-16 offsets in the classification into text_utf8 byte offsets. + // wide offsets in the classification into text_utf8 byte offsets. size_t additional_offset = prefix_text.size(); // Length in utf-8 bytes. - std::string text_utf8 = prefix_text + UTF16ToUTF8(localized_text); + std::string text_utf8 = prefix_text + WideToUTF8(localized_text); PangoAttrList* attrs = pango_attr_list_new(); @@ -473,10 +473,10 @@ void AutocompletePopupViewGtk::AcceptLine(size_t line, // extension, |match| and its contents. So copy the relevant strings out to // make sure they stay alive until the call completes. const GURL url(match.destination_url); - string16 keyword; + std::wstring keyword; const bool is_keyword_hint = model_->GetKeywordForMatch(match, &keyword); edit_view_->OpenURL(url, disposition, match.transition, GURL(), line, - is_keyword_hint ? string16() : keyword); + is_keyword_hint ? std::wstring() : keyword); } GdkPixbuf* AutocompletePopupViewGtk::IconForMatch( diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.h b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.h index 0d97341..0632635 100644 --- a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.h +++ b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.h @@ -53,7 +53,7 @@ class AutocompletePopupViewGtk : public AutocompletePopupView, friend class AutocompletePopupViewGtkTest; static void SetupLayoutForMatch( PangoLayout* layout, - const string16& text, + const std::wstring& text, const AutocompleteMatch::ACMatchClassifications& classifications, const GdkColor* base_color, const GdkColor* dim_color, diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_gtk_unittest.cc b/chrome/browser/autocomplete/autocomplete_popup_view_gtk_unittest.cc index 3be69e5..60f7f2b 100644 --- a/chrome/browser/autocomplete/autocomplete_popup_view_gtk_unittest.cc +++ b/chrome/browser/autocomplete/autocomplete_popup_view_gtk_unittest.cc @@ -6,7 +6,6 @@ #include <gtk/gtk.h> -#include "base/utf_string_conversions.h" #include "chrome/browser/autocomplete/autocomplete.h" #include "chrome/browser/autocomplete/autocomplete_match.h" #include "chrome/browser/ui/gtk/gtk_util.h" @@ -45,7 +44,7 @@ class AutocompletePopupViewGtkTest : public PlatformTest { // friend of the class being tested. This method just proxies the // call through after adding the fixture's layout_. void SetupLayoutForMatch( - const string16& text, + const std::wstring& text, const AutocompleteMatch::ACMatchClassifications& classifications, const GdkColor* base_color, const GdkColor* dim_color, @@ -189,7 +188,7 @@ class AutocompletePopupViewGtkTest : public PlatformTest { // text matches the input string, with the passed-in color, and // nothing bolded. TEST_F(AutocompletePopupViewGtkTest, DecorateMatchedStringNoMatch) { - const string16 kContents = ASCIIToUTF16("This is a test"); + const std::wstring kContents = L"This is a test"; AutocompleteMatch::ACMatchClassifications classifications; @@ -225,7 +224,7 @@ TEST_F(AutocompletePopupViewGtkTest, DecorateMatchedStringNoMatch) { // Identical to DecorateMatchedStringNoMatch, except test that URL // style gets a different color than we passed in. TEST_F(AutocompletePopupViewGtkTest, DecorateMatchedStringURLNoMatch) { - const string16 kContents = ASCIIToUTF16("This is a test"); + const std::wstring kContents = L"This is a test"; AutocompleteMatch::ACMatchClassifications classifications; classifications.push_back( @@ -261,7 +260,7 @@ TEST_F(AutocompletePopupViewGtkTest, DecorateMatchedStringURLNoMatch) { // Test that DIM works as expected. TEST_F(AutocompletePopupViewGtkTest, DecorateMatchedStringDimNoMatch) { - const string16 kContents = ASCIIToUTF16("This is a test"); + const std::wstring kContents = L"This is a test"; // Dim "is". const guint runLength1 = 5, runLength2 = 2, runLength3 = 7; // Make sure nobody messed up the inputs. @@ -323,7 +322,7 @@ TEST_F(AutocompletePopupViewGtkTest, DecorateMatchedStringDimNoMatch) { // Test that the matched run gets bold-faced, but keeps the same // color. TEST_F(AutocompletePopupViewGtkTest, DecorateMatchedStringMatch) { - const string16 kContents = ASCIIToUTF16("This is a test"); + const std::wstring kContents = L"This is a test"; // Match "is". const guint runLength1 = 5, runLength2 = 2, runLength3 = 7; // Make sure nobody messed up the inputs. @@ -381,7 +380,7 @@ TEST_F(AutocompletePopupViewGtkTest, DecorateMatchedStringMatch) { // Just like DecorateMatchedStringURLMatch, this time with URL style. TEST_F(AutocompletePopupViewGtkTest, DecorateMatchedStringURLMatch) { - const string16 kContents = ASCIIToUTF16("http://hello.world/"); + const std::wstring kContents = L"http://hello.world/"; // Match "hello". const guint runLength1 = 7, runLength2 = 5, runLength3 = 7; // Make sure nobody messed up the inputs. diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_mac.h b/chrome/browser/autocomplete/autocomplete_popup_view_mac.h index 5df445a..2fdfaa9 100644 --- a/chrome/browser/autocomplete/autocomplete_popup_view_mac.h +++ b/chrome/browser/autocomplete/autocomplete_popup_view_mac.h @@ -102,7 +102,7 @@ class AutocompletePopupViewMac : public AutocompletePopupView, // and description cases. Returns NSMutableAttributedString as a // convenience for MatchText(). static NSMutableAttributedString* DecorateMatchedString( - const string16 &matchString, + const std::wstring &matchString, const AutocompleteMatch::ACMatchClassifications &classifications, NSColor* textColor, NSColor* dimTextColor, gfx::Font& font); @@ -114,7 +114,7 @@ class AutocompletePopupViewMac : public AutocompletePopupView, // cleaner. static NSMutableAttributedString* ElideString( NSMutableAttributedString* aString, - const string16 originalString, + const std::wstring originalString, const gfx::Font& font, const float cellWidth); diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm b/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm index 02d01b7..893c40b 100644 --- a/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm +++ b/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm @@ -102,14 +102,14 @@ static NSColor* URLTextColor() { // and description cases. Returns NSMutableAttributedString as a // convenience for MatchText(). NSMutableAttributedString* AutocompletePopupViewMac::DecorateMatchedString( - const string16 &matchString, + const std::wstring &matchString, const AutocompleteMatch::ACMatchClassifications &classifications, NSColor* textColor, NSColor* dimTextColor, gfx::Font& font) { // Cache for on-demand computation of the bold version of |font|. NSFont* boldFont = nil; // Start out with a string using the default style info. - NSString* s = base::SysUTF16ToNSString(matchString); + NSString* s = base::SysWideToNSString(matchString); NSDictionary* attributes = [NSDictionary dictionaryWithObjectsAndKeys: font.GetNativeFont(), NSFontAttributeName, textColor, NSForegroundColorAttributeName, @@ -154,7 +154,7 @@ NSMutableAttributedString* AutocompletePopupViewMac::DecorateMatchedString( NSMutableAttributedString* AutocompletePopupViewMac::ElideString( NSMutableAttributedString* aString, - const string16 originalString, + const std::wstring originalString, const gfx::Font& font, const float width) { // If it already fits, nothing to be done. @@ -163,7 +163,8 @@ NSMutableAttributedString* AutocompletePopupViewMac::ElideString( } // If ElideText() decides to do nothing, nothing to be done. - const string16 elided = ui::ElideText(originalString, font, width, false); + const std::wstring elided(UTF16ToWideHack(ui::ElideText( + WideToUTF16Hack(originalString), font, width, false))); if (0 == elided.compare(originalString)) { return aString; } @@ -180,7 +181,7 @@ NSMutableAttributedString* AutocompletePopupViewMac::ElideString( DCHECK(0 != elided.compare(0, i, originalString)); // Replace the end of |aString| with the ellipses from |elided|. - NSString* s = base::SysUTF16ToNSString(elided.substr(i)); + NSString* s = base::SysWideToNSString(elided.substr(i)); [aString replaceCharactersInRange:NSMakeRange(i, [aString length] - i) withString:s]; @@ -547,10 +548,10 @@ void AutocompletePopupViewMac::OpenURLForRow(int row, bool force_background) { // completes. const AutocompleteMatch& match = model_->result().match_at(row); const GURL url(match.destination_url); - string16 keyword; + std::wstring keyword; const bool is_keyword_hint = model_->GetKeywordForMatch(match, &keyword); edit_view_->OpenURL(url, disposition, match.transition, GURL(), row, - is_keyword_hint ? string16() : keyword); + is_keyword_hint ? std::wstring() : keyword); } void AutocompletePopupViewMac::UserPressedOptIn(bool opt_in) { diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_mac_unittest.mm b/chrome/browser/autocomplete/autocomplete_popup_view_mac_unittest.mm index 344694d..3f3a535 100644 --- a/chrome/browser/autocomplete/autocomplete_popup_view_mac_unittest.mm +++ b/chrome/browser/autocomplete/autocomplete_popup_view_mac_unittest.mm @@ -86,8 +86,8 @@ class AutocompletePopupViewMacTest : public PlatformTest { // AutocompleteMatch doesn't really have the right constructor for our // needs. Fake one for us to use. - static AutocompleteMatch MakeMatch(const string16 &contents, - const string16 &description) { + static AutocompleteMatch MakeMatch(const std::wstring &contents, + const std::wstring &description) { AutocompleteMatch m(NULL, 1, true, AutocompleteMatch::URL_WHAT_YOU_TYPED); m.contents = contents; m.description = description; @@ -108,7 +108,7 @@ TEST_F(AutocompletePopupViewMacTest, DecorateMatchedStringNoMatch) { NSAttributedString* decorated = AutocompletePopupViewMac::DecorateMatchedString( - base::SysNSStringToUTF16(string), classifications, + base::SysNSStringToWide(string), classifications, color_, dimColor_, font_); // Result has same characters as the input. @@ -138,7 +138,7 @@ TEST_F(AutocompletePopupViewMacTest, DecorateMatchedStringURLNoMatch) { NSAttributedString* decorated = AutocompletePopupViewMac::DecorateMatchedString( - base::SysNSStringToUTF16(string), classifications, + base::SysNSStringToWide(string), classifications, color_, dimColor_, font_); // Result has same characters as the input. @@ -177,7 +177,7 @@ TEST_F(AutocompletePopupViewMacTest, DecorateMatchedStringDimNoMatch) { NSAttributedString* decorated = AutocompletePopupViewMac::DecorateMatchedString( - base::SysNSStringToUTF16(string), classifications, + base::SysNSStringToWide(string), classifications, color_, dimColor_, font_); // Result has same characters as the input. @@ -227,7 +227,7 @@ TEST_F(AutocompletePopupViewMacTest, DecorateMatchedStringMatch) { NSAttributedString* decorated = AutocompletePopupViewMac::DecorateMatchedString( - base::SysNSStringToUTF16(string), classifications, + base::SysNSStringToWide(string), classifications, color_, dimColor_, font_); // Result has same characters as the input. @@ -275,7 +275,7 @@ TEST_F(AutocompletePopupViewMacTest, DecorateMatchedStringURLMatch) { NSAttributedString* decorated = AutocompletePopupViewMac::DecorateMatchedString( - base::SysNSStringToUTF16(string), classifications, + base::SysNSStringToWide(string), classifications, color_, dimColor_, font_); // Result has same characters as the input. @@ -310,8 +310,8 @@ TEST_F(AutocompletePopupViewMacTest, DecorateMatchedStringURLMatch) { TEST_F(AutocompletePopupViewMacTest, MatchText) { NSString* const contents = @"contents"; NSString* const description = @"description"; - AutocompleteMatch m = MakeMatch(base::SysNSStringToUTF16(contents), - base::SysNSStringToUTF16(description)); + AutocompleteMatch m = MakeMatch(base::SysNSStringToWide(contents), + base::SysNSStringToWide(description)); NSAttributedString* decorated = AutocompletePopupViewMac::MatchText(m, font_, kLargeWidth); @@ -346,8 +346,8 @@ TEST_F(AutocompletePopupViewMacTest, MatchTextContentsMatch) { // Make sure nobody messed up the inputs. EXPECT_EQ(runLength1 + runLength2 + runLength3, [contents length]); - AutocompleteMatch m = MakeMatch(base::SysNSStringToUTF16(contents), - string16()); + AutocompleteMatch m = MakeMatch(base::SysNSStringToWide(contents), + std::wstring()); // Push each run onto contents classifications. m.contents_class.push_back( @@ -394,8 +394,8 @@ TEST_F(AutocompletePopupViewMacTest, MatchTextDescriptionMatch) { // Make sure nobody messed up the inputs. EXPECT_EQ(runLength1 + runLength2, [description length]); - AutocompleteMatch m = MakeMatch(base::SysNSStringToUTF16(contents), - base::SysNSStringToUTF16(description)); + AutocompleteMatch m = MakeMatch(base::SysNSStringToWide(contents), + base::SysNSStringToWide(description)); // Push each run onto contents classifications. m.description_class.push_back( @@ -441,7 +441,7 @@ TEST_F(AutocompletePopupViewMacTest, MatchTextDescriptionMatch) { TEST_F(AutocompletePopupViewMacTest, ElideString) { NSString* const contents = @"This is a test with long contents"; - const string16 contents16(base::SysNSStringToUTF16(contents)); + const std::wstring wideContents(base::SysNSStringToWide(contents)); const float kWide = 1000.0; const float kNarrow = 20.0; @@ -455,23 +455,25 @@ TEST_F(AutocompletePopupViewMacTest, ElideString) { // Nothing happens if the space is really wide. NSMutableAttributedString* ret = - AutocompletePopupViewMac::ElideString(as, contents16, font_, kWide); + AutocompletePopupViewMac::ElideString(as, wideContents, font_, kWide); EXPECT_TRUE(ret == as); EXPECT_TRUE([[as string] isEqualToString:contents]); // When elided, result is the same as ElideText(). - ret = AutocompletePopupViewMac::ElideString(as, contents16, font_, kNarrow); - string16 elided = ui::ElideText(contents16, font_, kNarrow, false); + ret = AutocompletePopupViewMac::ElideString(as, wideContents, font_, kNarrow); + std::wstring elided(UTF16ToWideHack(ui::ElideText(WideToUTF16Hack( + wideContents), font_, kNarrow, false))); EXPECT_TRUE(ret == as); EXPECT_FALSE([[as string] isEqualToString:contents]); - EXPECT_TRUE([[as string] isEqualToString:base::SysUTF16ToNSString(elided)]); + EXPECT_TRUE([[as string] isEqualToString:base::SysWideToNSString(elided)]); // When elided, result is the same as ElideText(). - ret = AutocompletePopupViewMac::ElideString(as, contents16, font_, 0.0); - elided = ui::ElideText(contents16, font_, 0.0, false); + ret = AutocompletePopupViewMac::ElideString(as, wideContents, font_, 0.0); + elided = UTF16ToWideHack(ui::ElideText(WideToUTF16Hack(wideContents), font_, + 0.0, false)); EXPECT_TRUE(ret == as); EXPECT_FALSE([[as string] isEqualToString:contents]); - EXPECT_TRUE([[as string] isEqualToString:base::SysUTF16ToNSString(elided)]); + EXPECT_TRUE([[as string] isEqualToString:base::SysWideToNSString(elided)]); } TEST_F(AutocompletePopupViewMacTest, MatchTextElide) { @@ -482,8 +484,8 @@ TEST_F(AutocompletePopupViewMacTest, MatchTextElide) { // Make sure nobody messed up the inputs. EXPECT_EQ(runLength1 + runLength2 + runLength3, [contents length]); - AutocompleteMatch m = MakeMatch(base::SysNSStringToUTF16(contents), - base::SysNSStringToUTF16(description)); + AutocompleteMatch m = MakeMatch(base::SysNSStringToWide(contents), + base::SysNSStringToWide(description)); // Push each run onto contents classifications. m.contents_class.push_back( diff --git a/chrome/browser/autocomplete/autocomplete_unittest.cc b/chrome/browser/autocomplete/autocomplete_unittest.cc index 332fedf..c63039c 100644 --- a/chrome/browser/autocomplete/autocomplete_unittest.cc +++ b/chrome/browser/autocomplete/autocomplete_unittest.cc @@ -19,6 +19,10 @@ #include "chrome/test/testing_profile.h" #include "testing/gtest/include/gtest/gtest.h" +// identifiers for known autocomplete providers +#define HISTORY_IDENTIFIER L"Chrome:History" +#define SEARCH_IDENTIFIER L"google.com/websearch/en" + static std::ostream& operator<<(std::ostream& os, const AutocompleteResult::const_iterator& it) { return os << static_cast<const AutocompleteMatch*>(&(*it)); @@ -32,7 +36,7 @@ const size_t num_results_per_provider = 3; // refcounted so that it can also be a task on the message loop. class TestProvider : public AutocompleteProvider { public: - TestProvider(int relevance, const string16& prefix) + TestProvider(int relevance, const std::wstring& prefix) : AutocompleteProvider(NULL, NULL, ""), relevance_(relevance), prefix_(prefix) { @@ -53,7 +57,7 @@ class TestProvider : public AutocompleteProvider { void AddResults(int start_at, int num); int relevance_; - const string16 prefix_; + const std::wstring prefix_; }; void TestProvider::Start(const AutocompleteInput& input, @@ -86,8 +90,8 @@ void TestProvider::AddResults(int start_at, int num) { AutocompleteMatch match(this, relevance_ - i, false, AutocompleteMatch::URL_WHAT_YOU_TYPED); - match.fill_into_edit = prefix_ + UTF8ToUTF16(base::IntToString(i)); - match.destination_url = GURL(UTF16ToUTF8(match.fill_into_edit)); + match.fill_into_edit = prefix_ + UTF8ToWide(base::IntToString(i)); + match.destination_url = GURL(WideToUTF8(match.fill_into_edit)); match.contents = match.fill_into_edit; match.contents_class.push_back( @@ -137,12 +141,12 @@ void AutocompleteProviderTest::ResetControllerWithTestProviders( // Construct two new providers, with either the same or different prefixes. TestProvider* providerA = new TestProvider(num_results_per_provider, - ASCIIToUTF16("http://a")); + L"http://a"); providerA->AddRef(); providers_.push_back(providerA); TestProvider* providerB = new TestProvider(num_results_per_provider * 2, - same_destinations ? ASCIIToUTF16("http://a") : ASCIIToUTF16("http://b")); + same_destinations ? L"http://a" : L"http://b"); providerB->AddRef(); providers_.push_back(providerB); @@ -199,7 +203,7 @@ void AutocompleteProviderTest:: void AutocompleteProviderTest::RunTest() { result_.Reset(); - controller_->Start(ASCIIToUTF16("a"), string16(), true, false, true, false); + controller_->Start(L"a", std::wstring(), true, false, true, false); // The message loop will terminate when all autocomplete input has been // collected. @@ -212,7 +216,7 @@ void AutocompleteProviderTest::RunExactKeymatchTest( // created in ResetControllerWithKeywordAndSearchProviders(). The default // match should thus be a keyword match iff |allow_exact_keyword_match| is // true. - controller_->Start(ASCIIToUTF16("k test"), string16(), true, false, + controller_->Start(L"k test", std::wstring(), true, false, allow_exact_keyword_match, true); EXPECT_TRUE(controller_->done()); // ResetControllerWithKeywordAndSearchProviders() adds the keyword provider @@ -263,96 +267,92 @@ TEST_F(AutocompleteProviderTest, AllowExactKeywordMatch) { TEST(AutocompleteTest, InputType) { struct test_data { - const string16 input; + const wchar_t* input; const AutocompleteInput::Type type; } input_cases[] = { - { ASCIIToUTF16(""), AutocompleteInput::INVALID }, - { ASCIIToUTF16("?"), AutocompleteInput::FORCED_QUERY }, - { ASCIIToUTF16("?foo"), AutocompleteInput::FORCED_QUERY }, - { ASCIIToUTF16("?foo bar"), AutocompleteInput::FORCED_QUERY }, - { ASCIIToUTF16("?http://foo.com/bar"), AutocompleteInput::FORCED_QUERY }, - { ASCIIToUTF16("foo"), AutocompleteInput::UNKNOWN }, - { ASCIIToUTF16("foo.c"), AutocompleteInput::UNKNOWN }, - { ASCIIToUTF16("foo.com"), AutocompleteInput::URL }, - { ASCIIToUTF16("-.com"), AutocompleteInput::UNKNOWN }, - { ASCIIToUTF16("foo/bar"), AutocompleteInput::URL }, - { ASCIIToUTF16("foo;bar"), AutocompleteInput::QUERY }, - { ASCIIToUTF16("foo/bar baz"), AutocompleteInput::UNKNOWN }, - { ASCIIToUTF16("foo bar.com"), AutocompleteInput::QUERY }, - { ASCIIToUTF16("foo bar"), AutocompleteInput::QUERY }, - { ASCIIToUTF16("foo+bar"), AutocompleteInput::QUERY }, - { ASCIIToUTF16("foo+bar.com"), AutocompleteInput::UNKNOWN }, - { ASCIIToUTF16("\"foo:bar\""), AutocompleteInput::QUERY }, - { ASCIIToUTF16("link:foo.com"), AutocompleteInput::UNKNOWN }, - { ASCIIToUTF16("foo:81"), AutocompleteInput::URL }, - { ASCIIToUTF16("www.foo.com:81"), AutocompleteInput::URL }, - { ASCIIToUTF16("localhost:8080"), AutocompleteInput::URL }, - { ASCIIToUTF16("foo.com:123456"), AutocompleteInput::QUERY }, - { ASCIIToUTF16("foo.com:abc"), AutocompleteInput::QUERY }, - { ASCIIToUTF16("1.2.3.4:abc"), AutocompleteInput::QUERY }, - { ASCIIToUTF16("user@foo.com"), AutocompleteInput::UNKNOWN }, - { ASCIIToUTF16("user:pass@"), AutocompleteInput::UNKNOWN }, - { ASCIIToUTF16("user:pass@!foo.com"), AutocompleteInput::UNKNOWN }, - { ASCIIToUTF16("user:pass@foo"), AutocompleteInput::URL }, - { ASCIIToUTF16("user:pass@foo.c"), AutocompleteInput::URL }, - { ASCIIToUTF16("user:pass@foo.com"), AutocompleteInput::URL }, - { ASCIIToUTF16("user:pass@foo.com:81"), AutocompleteInput::URL }, - { ASCIIToUTF16("user:pass@foo:81"), AutocompleteInput::URL }, - { ASCIIToUTF16("1.2"), AutocompleteInput::UNKNOWN }, - { ASCIIToUTF16("1.2/45"), AutocompleteInput::UNKNOWN }, - { ASCIIToUTF16("1.2:45"), AutocompleteInput::UNKNOWN }, - { ASCIIToUTF16("user@1.2:45"), AutocompleteInput::UNKNOWN }, - { ASCIIToUTF16("user:pass@1.2:45"), AutocompleteInput::URL }, - { ASCIIToUTF16("ps/2 games"), AutocompleteInput::UNKNOWN }, - { ASCIIToUTF16("en.wikipedia.org/wiki/James Bond"), - AutocompleteInput::URL }, + { L"", AutocompleteInput::INVALID }, + { L"?", AutocompleteInput::FORCED_QUERY }, + { L"?foo", AutocompleteInput::FORCED_QUERY }, + { L"?foo bar", AutocompleteInput::FORCED_QUERY }, + { L"?http://foo.com/bar", AutocompleteInput::FORCED_QUERY }, + { L"foo", AutocompleteInput::UNKNOWN }, + { L"foo.c", AutocompleteInput::UNKNOWN }, + { L"foo.com", AutocompleteInput::URL }, + { L"-.com", AutocompleteInput::UNKNOWN }, + { L"foo/bar", AutocompleteInput::URL }, + { L"foo;bar", AutocompleteInput::QUERY }, + { L"foo/bar baz", AutocompleteInput::UNKNOWN }, + { L"foo bar.com", AutocompleteInput::QUERY }, + { L"foo bar", AutocompleteInput::QUERY }, + { L"foo+bar", AutocompleteInput::QUERY }, + { L"foo+bar.com", AutocompleteInput::UNKNOWN }, + { L"\"foo:bar\"", AutocompleteInput::QUERY }, + { L"link:foo.com", AutocompleteInput::UNKNOWN }, + { L"foo:81", AutocompleteInput::URL }, + { L"www.foo.com:81", AutocompleteInput::URL }, + { L"localhost:8080", AutocompleteInput::URL }, + { L"foo.com:123456", AutocompleteInput::QUERY }, + { L"foo.com:abc", AutocompleteInput::QUERY }, + { L"1.2.3.4:abc", AutocompleteInput::QUERY }, + { L"user@foo.com", AutocompleteInput::UNKNOWN }, + { L"user:pass@", AutocompleteInput::UNKNOWN }, + { L"user:pass@!foo.com", AutocompleteInput::UNKNOWN }, + { L"user:pass@foo", AutocompleteInput::URL }, + { L"user:pass@foo.c", AutocompleteInput::URL }, + { L"user:pass@foo.com", AutocompleteInput::URL }, + { L"user:pass@foo.com:81", AutocompleteInput::URL }, + { L"user:pass@foo:81", AutocompleteInput::URL }, + { L"1.2", AutocompleteInput::UNKNOWN }, + { L"1.2/45", AutocompleteInput::UNKNOWN }, + { L"1.2:45", AutocompleteInput::UNKNOWN }, + { L"user@1.2:45", AutocompleteInput::UNKNOWN }, + { L"user:pass@1.2:45", AutocompleteInput::URL }, + { L"ps/2 games", AutocompleteInput::UNKNOWN }, + { L"en.wikipedia.org/wiki/James Bond", AutocompleteInput::URL }, // In Chrome itself, mailto: will get handled by ShellExecute, but in // unittest mode, we don't have the data loaded in the external protocol // handler to know this. - // { ASCIIToUTF16("mailto:abuse@foo.com"), AutocompleteInput::URL }, - { ASCIIToUTF16("view-source:http://www.foo.com/"), AutocompleteInput::URL }, - { ASCIIToUTF16("javascript:alert(\"Hey there!\");"), - AutocompleteInput::URL }, + // { L"mailto:abuse@foo.com", AutocompleteInput::URL }, + { L"view-source:http://www.foo.com/", AutocompleteInput::URL }, + { L"javascript:alert(\"Hey there!\");", AutocompleteInput::URL }, #if defined(OS_WIN) - { ASCIIToUTF16("C:\\Program Files"), AutocompleteInput::URL }, - { ASCIIToUTF16("\\\\Server\\Folder\\File"), AutocompleteInput::URL }, + { L"C:\\Program Files", AutocompleteInput::URL }, + { L"\\\\Server\\Folder\\File", AutocompleteInput::URL }, #endif // defined(OS_WIN) - { ASCIIToUTF16("http:foo"), AutocompleteInput::URL }, - { ASCIIToUTF16("http://foo"), AutocompleteInput::URL }, - { ASCIIToUTF16("http://foo.c"), AutocompleteInput::URL }, - { ASCIIToUTF16("http://foo.com"), AutocompleteInput::URL }, - { ASCIIToUTF16("http://foo_bar.com"), AutocompleteInput::URL }, - { ASCIIToUTF16("http://foo/bar baz"), AutocompleteInput::URL }, - { ASCIIToUTF16("http://-.com"), AutocompleteInput::UNKNOWN }, - { ASCIIToUTF16("http://_foo_.com"), AutocompleteInput::UNKNOWN }, - { ASCIIToUTF16("http://foo.com:abc"), AutocompleteInput::QUERY }, - { ASCIIToUTF16("http://foo.com:123456"), AutocompleteInput::QUERY }, - { ASCIIToUTF16("http://1.2.3.4:abc"), AutocompleteInput::QUERY }, - { ASCIIToUTF16("http:user@foo.com"), AutocompleteInput::URL }, - { ASCIIToUTF16("http://user@foo.com"), AutocompleteInput::URL }, - { ASCIIToUTF16("http:user:pass@foo.com"), AutocompleteInput::URL }, - { ASCIIToUTF16("http://user:pass@foo.com"), AutocompleteInput::URL }, - { ASCIIToUTF16("http://1.2"), AutocompleteInput::URL }, - { ASCIIToUTF16("http://1.2/45"), AutocompleteInput::URL }, - { ASCIIToUTF16("http:ps/2 games"), AutocompleteInput::URL }, - { ASCIIToUTF16("http://ps/2 games"), AutocompleteInput::URL }, - { ASCIIToUTF16("https://foo.com"), AutocompleteInput::URL }, - { ASCIIToUTF16("127.0.0.1"), AutocompleteInput::URL }, - { ASCIIToUTF16("127.0.1"), AutocompleteInput::UNKNOWN }, - { ASCIIToUTF16("127.0.1/"), AutocompleteInput::UNKNOWN }, - { ASCIIToUTF16("browser.tabs.closeButtons"), AutocompleteInput::UNKNOWN }, - { WideToUTF16(L"\u6d4b\u8bd5"), AutocompleteInput::UNKNOWN }, - { ASCIIToUTF16("[2001:]"), AutocompleteInput::QUERY }, // Not a valid IP - { ASCIIToUTF16("[2001:dB8::1]"), AutocompleteInput::URL }, - { ASCIIToUTF16("192.168.0.256"), - AutocompleteInput::QUERY }, // Invalid IPv4 literal. - { ASCIIToUTF16("[foo.com]"), - AutocompleteInput::QUERY }, // Invalid IPv6 literal. + { L"http:foo", AutocompleteInput::URL }, + { L"http://foo", AutocompleteInput::URL }, + { L"http://foo.c", AutocompleteInput::URL }, + { L"http://foo.com", AutocompleteInput::URL }, + { L"http://foo_bar.com", AutocompleteInput::URL }, + { L"http://foo/bar baz", AutocompleteInput::URL }, + { L"http://-.com", AutocompleteInput::UNKNOWN }, + { L"http://_foo_.com", AutocompleteInput::UNKNOWN }, + { L"http://foo.com:abc", AutocompleteInput::QUERY }, + { L"http://foo.com:123456", AutocompleteInput::QUERY }, + { L"http://1.2.3.4:abc", AutocompleteInput::QUERY }, + { L"http:user@foo.com", AutocompleteInput::URL }, + { L"http://user@foo.com", AutocompleteInput::URL }, + { L"http:user:pass@foo.com", AutocompleteInput::URL }, + { L"http://user:pass@foo.com", AutocompleteInput::URL }, + { L"http://1.2", AutocompleteInput::URL }, + { L"http://1.2/45", AutocompleteInput::URL }, + { L"http:ps/2 games", AutocompleteInput::URL }, + { L"http://ps/2 games", AutocompleteInput::URL }, + { L"https://foo.com", AutocompleteInput::URL }, + { L"127.0.0.1", AutocompleteInput::URL }, + { L"127.0.1", AutocompleteInput::UNKNOWN }, + { L"127.0.1/", AutocompleteInput::UNKNOWN }, + { L"browser.tabs.closeButtons", AutocompleteInput::UNKNOWN }, + { L"\u6d4b\u8bd5", AutocompleteInput::UNKNOWN }, + { L"[2001:]", AutocompleteInput::QUERY }, // Not a valid IP + { L"[2001:dB8::1]", AutocompleteInput::URL }, + { L"192.168.0.256", AutocompleteInput::QUERY }, // Invalid IPv4 literal. + { L"[foo.com]", AutocompleteInput::QUERY }, // Invalid IPv6 literal. }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) { SCOPED_TRACE(input_cases[i].input); - AutocompleteInput input(input_cases[i].input, string16(), true, false, + AutocompleteInput input(input_cases[i].input, std::wstring(), true, false, true, false); EXPECT_EQ(input_cases[i].type, input.type()); } @@ -360,16 +360,16 @@ TEST(AutocompleteTest, InputType) { TEST(AutocompleteTest, InputTypeWithDesiredTLD) { struct test_data { - const string16 input; + const wchar_t* input; const AutocompleteInput::Type type; } input_cases[] = { - { ASCIIToUTF16("401k"), AutocompleteInput::REQUESTED_URL }, - { ASCIIToUTF16("999999999999999"), AutocompleteInput::REQUESTED_URL }, + { L"401k", AutocompleteInput::REQUESTED_URL }, + { L"999999999999999", AutocompleteInput::REQUESTED_URL }, }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) { - AutocompleteInput input(input_cases[i].input, ASCIIToUTF16("com"), true, - false, true, false); + AutocompleteInput input(input_cases[i].input, L"com", true, false, true, + false); EXPECT_EQ(input_cases[i].type, input.type()) << "Input: " << input_cases[i].input; } @@ -378,8 +378,8 @@ TEST(AutocompleteTest, InputTypeWithDesiredTLD) { // This tests for a regression where certain input in the omnibox caused us to // crash. As long as the test completes without crashing, we're fine. TEST(AutocompleteTest, InputCrash) { - AutocompleteInput input(WideToUTF16(L"\uff65@s"), string16(), true, false, - true, false); + AutocompleteInput input(L"\uff65@s", std::wstring(), true, false, true, + false); } // Test comparing matches relevance. @@ -412,41 +412,36 @@ TEST(AutocompleteInput, ParseForEmphasizeComponent) { using url_parse::Component; Component kInvalidComponent(0, -1); struct test_data { - const string16 input; + const wchar_t* input; const Component scheme; const Component host; } input_cases[] = { - { ASCIIToUTF16(""), kInvalidComponent, kInvalidComponent }, - { ASCIIToUTF16("?"), kInvalidComponent, kInvalidComponent }, - { ASCIIToUTF16("?http://foo.com/bar"), kInvalidComponent, - kInvalidComponent }, - { ASCIIToUTF16("foo/bar baz"), kInvalidComponent, Component(0, 3) }, - { ASCIIToUTF16("http://foo/bar baz"), Component(0, 4), Component(7, 3) }, - { ASCIIToUTF16("link:foo.com"), Component(0, 4), kInvalidComponent }, - { ASCIIToUTF16("www.foo.com:81"), kInvalidComponent, Component(0, 11) }, - { WideToUTF16(L"\u6d4b\u8bd5"), kInvalidComponent, Component(0, 2) }, - { ASCIIToUTF16("view-source:http://www.foo.com/"), Component(12, 4), - Component(19, 11) }, - { ASCIIToUTF16("view-source:https://example.com/"), + { L"", kInvalidComponent, kInvalidComponent }, + { L"?", kInvalidComponent, kInvalidComponent }, + { L"?http://foo.com/bar", kInvalidComponent, kInvalidComponent }, + { L"foo/bar baz", kInvalidComponent, Component(0, 3) }, + { L"http://foo/bar baz", Component(0, 4), Component(7, 3) }, + { L"link:foo.com", Component(0, 4), kInvalidComponent }, + { L"www.foo.com:81", kInvalidComponent, Component(0, 11) }, + { L"\u6d4b\u8bd5", kInvalidComponent, Component(0, 2) }, + { L"view-source:http://www.foo.com/", Component(12, 4), Component(19, 11) }, + { L"view-source:https://example.com/", Component(12, 5), Component(20, 11) }, - { ASCIIToUTF16("view-source:www.foo.com"), kInvalidComponent, - Component(12, 11) }, - { ASCIIToUTF16("view-source:"), Component(0, 11), kInvalidComponent }, - { ASCIIToUTF16("view-source:garbage"), kInvalidComponent, - Component(12, 7) }, - { ASCIIToUTF16("view-source:http://http://foo"), Component(12, 4), - Component(19, 4) }, - { ASCIIToUTF16("view-source:view-source:http://example.com/"), - Component(12, 11), kInvalidComponent } + { L"view-source:www.foo.com", kInvalidComponent, Component(12, 11) }, + { L"view-source:", Component(0, 11), kInvalidComponent }, + { L"view-source:garbage", kInvalidComponent, Component(12, 7) }, + { L"view-source:http://http://foo", Component(12, 4), Component(19, 4) }, + { L"view-source:view-source:http://example.com/", + Component(12, 11), kInvalidComponent } }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) { Component scheme, host; AutocompleteInput::ParseForEmphasizeComponents(input_cases[i].input, - string16(), + std::wstring(), &scheme, &host); - AutocompleteInput input(input_cases[i].input, string16(), true, false, + AutocompleteInput input(input_cases[i].input, std::wstring(), true, false, true, false); EXPECT_EQ(input_cases[i].scheme.begin, scheme.begin) << "Input: " << input_cases[i].input; diff --git a/chrome/browser/autocomplete/history_contents_provider.cc b/chrome/browser/autocomplete/history_contents_provider.cc index 44d24e8d..07c9132 100644 --- a/chrome/browser/autocomplete/history_contents_provider.cc +++ b/chrome/browser/autocomplete/history_contents_provider.cc @@ -82,7 +82,7 @@ void HistoryContentsProvider::Start(const AutocompleteInput& input, if ((input.type() == AutocompleteInput::URL) || (((input.type() == AutocompleteInput::REQUESTED_URL) || (input.type() == AutocompleteInput::UNKNOWN)) && - (input.text().find('.') != string16::npos))) { + (input.text().find('.') != std::wstring::npos))) { Stop(); return; } @@ -134,7 +134,7 @@ void HistoryContentsProvider::Start(const AutocompleteInput& input, history::QueryOptions options; options.SetRecentDayRange(kDaysToSearch); options.max_count = kMaxMatches; - history->QueryHistory(input.text(), options, + history->QueryHistory(WideToUTF16(input.text()), options, &request_consumer_, NewCallback(this, &HistoryContentsProvider::QueryComplete)); } @@ -212,7 +212,7 @@ AutocompleteMatch HistoryContentsProvider::ResultToMatch( match.destination_url = result.url(); match.contents_class.push_back( ACMatchClassification(0, ACMatchClassification::URL)); - match.description = result.title(); + match.description = UTF16ToWide(result.title()); match.starred = (profile_->GetBookmarkModel() && profile_->GetBookmarkModel()->IsBookmarked(result.url())); @@ -265,7 +265,7 @@ void HistoryContentsProvider::QueryBookmarks(const AutocompleteInput& input) { TimeTicks start_time = TimeTicks::Now(); std::vector<bookmark_utils::TitleMatch> matches; - bookmark_model->GetBookmarksWithTitlesMatching(input.text(), + bookmark_model->GetBookmarksWithTitlesMatching(WideToUTF16Hack(input.text()), kMaxMatches, &matches); for (size_t i = 0; i < matches.size(); ++i) AddBookmarkTitleMatchToResults(matches[i]); diff --git a/chrome/browser/autocomplete/history_contents_provider.h b/chrome/browser/autocomplete/history_contents_provider.h index 5bee112..504df3f 100644 --- a/chrome/browser/autocomplete/history_contents_provider.h +++ b/chrome/browser/autocomplete/history_contents_provider.h @@ -84,7 +84,7 @@ class HistoryContentsProvider : public HistoryProvider { bool have_results_; // Current query string. - string16 query_; + std::wstring query_; DISALLOW_COPY_AND_ASSIGN(HistoryContentsProvider); }; diff --git a/chrome/browser/autocomplete/history_contents_provider_unittest.cc b/chrome/browser/autocomplete/history_contents_provider_unittest.cc index c9067ea..6404ede 100644 --- a/chrome/browser/autocomplete/history_contents_provider_unittest.cc +++ b/chrome/browser/autocomplete/history_contents_provider_unittest.cc @@ -100,51 +100,51 @@ class HistoryContentsProviderTest : public testing::Test, BrowserThread ui_thread_; BrowserThread file_thread_; + std::wstring history_dir_; + scoped_ptr<TestingProfile> profile_; scoped_refptr<HistoryContentsProvider> provider_; }; TEST_F(HistoryContentsProviderTest, Body) { - AutocompleteInput input(ASCIIToUTF16("FOO"), string16(), true, false, true, - false); + AutocompleteInput input(L"FOO", std::wstring(), true, false, true, false); RunQuery(input, false); // The results should be the first two pages, in decreasing order. const ACMatches& m = matches(); ASSERT_EQ(2U, m.size()); EXPECT_EQ(test_entries[0].url, m[0].destination_url.spec()); - EXPECT_STREQ(test_entries[0].title, UTF16ToUTF8(m[0].description).c_str()); + EXPECT_STREQ(test_entries[0].title, WideToUTF8(m[0].description).c_str()); EXPECT_EQ(test_entries[1].url, m[1].destination_url.spec()); - EXPECT_STREQ(test_entries[1].title, UTF16ToUTF8(m[1].description).c_str()); + EXPECT_STREQ(test_entries[1].title, WideToUTF8(m[1].description).c_str()); } TEST_F(HistoryContentsProviderTest, Title) { - AutocompleteInput input(ASCIIToUTF16("PAGEONE"), string16(), true, false, - true, false); + AutocompleteInput input(L"PAGEONE", std::wstring(), true, false, true, false); RunQuery(input, false); // The results should be the first two pages. const ACMatches& m = matches(); ASSERT_EQ(2U, m.size()); EXPECT_EQ(test_entries[0].url, m[0].destination_url.spec()); - EXPECT_STREQ(test_entries[0].title, UTF16ToUTF8(m[0].description).c_str()); + EXPECT_STREQ(test_entries[0].title, WideToUTF8(m[0].description).c_str()); EXPECT_EQ(test_entries[1].url, m[1].destination_url.spec()); - EXPECT_STREQ(test_entries[1].title, UTF16ToUTF8(m[1].description).c_str()); + EXPECT_STREQ(test_entries[1].title, WideToUTF8(m[1].description).c_str()); } // The "minimal changes" flag should mean that we don't re-query the DB. TEST_F(HistoryContentsProviderTest, MinimalChanges) { // A minimal changes request when there have been no real queries should // give us no results. - AutocompleteInput sync_input(ASCIIToUTF16("PAGEONE"), string16(), true, false, - true, true); + AutocompleteInput sync_input(L"PAGEONE", std::wstring(), true, false, true, + true); RunQuery(sync_input, true); const ACMatches& m1 = matches(); EXPECT_EQ(0U, m1.size()); // Now do a "regular" query to get the results. - AutocompleteInput async_input(ASCIIToUTF16("PAGEONE"), string16(), true, - false, true, false); + AutocompleteInput async_input(L"PAGEONE", std::wstring(), true, false, true, + false); RunQuery(async_input, false); const ACMatches& m2 = matches(); EXPECT_EQ(2U, m2.size()); @@ -167,18 +167,17 @@ TEST_F(HistoryContentsProviderTest, Bookmarks) { ASCIIToUTF16("bar"), true); // Ask for synchronous. This should only get the bookmark. - AutocompleteInput sync_input(ASCIIToUTF16("bar"), string16(), true, false, - true, true); + AutocompleteInput sync_input(L"bar", std::wstring(), true, false, true, true); RunQuery(sync_input, false); const ACMatches& m1 = matches(); ASSERT_EQ(1U, m1.size()); EXPECT_EQ(bookmark_url, m1[0].destination_url); - EXPECT_EQ(ASCIIToUTF16("bar"), m1[0].description); + EXPECT_EQ(L"bar", m1[0].description); EXPECT_TRUE(m1[0].starred); // Ask for async. We should get the bookmark immediately. - AutocompleteInput async_input(ASCIIToUTF16("bar"), string16(), true, false, - true, false); + AutocompleteInput async_input(L"bar", std::wstring(), true, false, true, + false); provider()->Start(async_input, false); const ACMatches& m2 = matches(); ASSERT_EQ(1U, m2.size()); @@ -200,8 +199,7 @@ TEST_F(HistoryContentsProviderTest, Bookmarks) { // Tests that history is deleted properly. TEST_F(HistoryContentsProviderTest, DeleteMatch) { - AutocompleteInput input(ASCIIToUTF16("bar"), string16(), true, false, true, - false); + AutocompleteInput input(L"bar", std::wstring(), true, false, true, false); RunQuery(input, false); // Query; the result should be the third page. @@ -225,8 +223,7 @@ TEST_F(HistoryContentsProviderTest, DeleteStarredMatch) { ASCIIToUTF16("bar"), true); // Get the match to delete its history - AutocompleteInput input(ASCIIToUTF16("bar"), string16(), true, false, true, - false); + AutocompleteInput input(L"bar", std::wstring(), true, false, true, false); RunQuery(input, false); const ACMatches& m = matches(); ASSERT_EQ(1U, m.size()); @@ -236,8 +233,7 @@ TEST_F(HistoryContentsProviderTest, DeleteStarredMatch) { EXPECT_EQ(1U, matches().size()); // Run a query that would only match history (but the history is deleted) - AutocompleteInput you_input(ASCIIToUTF16("you"), string16(), true, false, - true, false); + AutocompleteInput you_input(L"you", std::wstring(), true, false, true, false); RunQuery(you_input, false); EXPECT_EQ(0U, matches().size()); diff --git a/chrome/browser/autocomplete/history_provider.cc b/chrome/browser/autocomplete/history_provider.cc index 4b1d9a3..cbcf691 100644 --- a/chrome/browser/autocomplete/history_provider.cc +++ b/chrome/browser/autocomplete/history_provider.cc @@ -60,10 +60,10 @@ void HistoryProvider::DeleteMatch(const AutocompleteMatch& match) { } // static -string16 HistoryProvider::FixupUserInput(const AutocompleteInput& input) { - const string16& input_text = input.text(); +std::wstring HistoryProvider::FixupUserInput(const AutocompleteInput& input) { + const std::wstring& input_text = input.text(); // Fixup and canonicalize user input. - const GURL canonical_gurl(URLFixerUpper::FixupURL(UTF16ToUTF8(input_text), + const GURL canonical_gurl(URLFixerUpper::FixupURL(WideToUTF8(input_text), std::string())); std::string canonical_gurl_str(canonical_gurl.possibly_invalid_spec()); if (canonical_gurl_str.empty()) { @@ -80,8 +80,8 @@ string16 HistoryProvider::FixupUserInput(const AutocompleteInput& input) { if ((input.type() != AutocompleteInput::URL) && canonical_gurl.HostIsIPAddress()) { std::string original_hostname = - UTF16ToUTF8(input_text.substr(input.parts().host.begin, - input.parts().host.len)); + WideToUTF8(input_text.substr(input.parts().host.begin, + input.parts().host.len)); const url_parse::Parsed& parts = canonical_gurl.parsed_for_possibly_invalid_spec(); // parts.host must not be empty when HostIsIPAddress() is true. @@ -89,11 +89,11 @@ string16 HistoryProvider::FixupUserInput(const AutocompleteInput& input) { canonical_gurl_str.replace(parts.host.begin, parts.host.len, original_hostname); } - string16 output = UTF8ToUTF16(canonical_gurl_str); + std::wstring output = UTF8ToWide(canonical_gurl_str); // Don't prepend a scheme when the user didn't have one. Since the fixer // upper only prepends the "http" scheme, that's all we need to check for. if (canonical_gurl.SchemeIs(chrome::kHttpScheme) && - !url_util::FindAndCompareScheme(UTF16ToUTF8(input_text), + !url_util::FindAndCompareScheme(WideToUTF8(input_text), chrome::kHttpScheme, NULL)) TrimHttpPrefix(&output); @@ -111,14 +111,12 @@ string16 HistoryProvider::FixupUserInput(const AutocompleteInput& input) { // trailing slashes (if the scheme is the only thing in the input). It's not // clear that the result of fixup really matters in this case, but there's no // harm in making sure. - const size_t last_input_nonslash = - input_text.find_last_not_of(ASCIIToUTF16("/\\")); - const size_t num_input_slashes = (last_input_nonslash == string16::npos) ? + const size_t last_input_nonslash = input_text.find_last_not_of(L"/\\"); + const size_t num_input_slashes = (last_input_nonslash == std::wstring::npos) ? input_text.length() : (input_text.length() - 1 - last_input_nonslash); - const size_t last_output_nonslash = - output.find_last_not_of(ASCIIToUTF16("/\\")); + const size_t last_output_nonslash = output.find_last_not_of(L"/\\"); const size_t num_output_slashes = - (last_output_nonslash == string16::npos) ? + (last_output_nonslash == std::wstring::npos) ? output.length() : (output.length() - 1 - last_output_nonslash); if (num_output_slashes < num_input_slashes) output.append(num_input_slashes - num_output_slashes, '/'); @@ -129,18 +127,17 @@ string16 HistoryProvider::FixupUserInput(const AutocompleteInput& input) { } // static -size_t HistoryProvider::TrimHttpPrefix(string16* url) { +size_t HistoryProvider::TrimHttpPrefix(std::wstring* url) { // Find any "http:". if (!HasHTTPScheme(*url)) return 0; - size_t scheme_pos = - url->find(ASCIIToUTF16(chrome::kHttpScheme) + char16(':')); - DCHECK(scheme_pos != string16::npos); + size_t scheme_pos = url->find(ASCIIToWide(chrome::kHttpScheme) + L":"); + DCHECK(scheme_pos != std::wstring::npos); // Erase scheme plus up to two slashes. size_t prefix_end = scheme_pos + strlen(chrome::kHttpScheme) + 1; const size_t after_slashes = std::min(url->length(), prefix_end + 2); - while ((prefix_end < after_slashes) && ((*url)[prefix_end] == '/')) + while ((prefix_end < after_slashes) && ((*url)[prefix_end] == L'/')) ++prefix_end; url->erase(scheme_pos, prefix_end - scheme_pos); return (scheme_pos == 0) ? prefix_end : 0; diff --git a/chrome/browser/autocomplete/history_provider.h b/chrome/browser/autocomplete/history_provider.h index a304742..3cec58e 100644 --- a/chrome/browser/autocomplete/history_provider.h +++ b/chrome/browser/autocomplete/history_provider.h @@ -44,13 +44,13 @@ class HistoryProvider : public AutocompleteProvider { // Note that we don't do this in AutocompleteInput's constructor, because if // e.g. we convert a Unicode hostname to punycode, other providers will show // output that surprises the user ("Search Google for xn--6ca.com"). - static string16 FixupUserInput(const AutocompleteInput& input); + static std::wstring FixupUserInput(const AutocompleteInput& input); // Trims "http:" and up to two subsequent slashes from |url|. Returns the // number of characters that were trimmed. // NOTE: For a view-source: URL, this will trim from after "view-source:" and // return 0. - static size_t TrimHttpPrefix(string16* url); + static size_t TrimHttpPrefix(std::wstring* url); }; #endif // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_PROVIDER_H_ diff --git a/chrome/browser/autocomplete/history_provider_util.cc b/chrome/browser/autocomplete/history_provider_util.cc index 4325b6b..39c26ec 100644 --- a/chrome/browser/autocomplete/history_provider_util.cc +++ b/chrome/browser/autocomplete/history_provider_util.cc @@ -12,7 +12,7 @@ const int kLowQualityMatchAgeLimitInDays = 3; HistoryMatch::HistoryMatch() : url_info(), - input_location(string16::npos), + input_location(std::wstring::npos), match_in_scheme(false), innermost_match(true) { } diff --git a/chrome/browser/autocomplete/history_provider_util.h b/chrome/browser/autocomplete/history_provider_util.h index aa4b444..5f72983 100644 --- a/chrome/browser/autocomplete/history_provider_util.h +++ b/chrome/browser/autocomplete/history_provider_util.h @@ -57,11 +57,11 @@ struct HistoryMatch { typedef std::deque<HistoryMatch> HistoryMatches; struct Prefix { - Prefix(const string16& prefix, int num_components) + Prefix(const std::wstring& prefix, int num_components) : prefix(prefix), num_components(num_components) {} - string16 prefix; + std::wstring prefix; // The number of "components" in the prefix. The scheme is a component, // and the initial "www." or "ftp." is a component. So "http://foo.com" diff --git a/chrome/browser/autocomplete/history_quick_provider.cc b/chrome/browser/autocomplete/history_quick_provider.cc index 9f8fbaa..0392f1e 100644 --- a/chrome/browser/autocomplete/history_quick_provider.cc +++ b/chrome/browser/autocomplete/history_quick_provider.cc @@ -52,7 +52,7 @@ void HistoryQuickProvider::Start(const AutocompleteInput& input, // NOTE: This purposefully doesn't take input.desired_tld() into account; if // it did, then holding "ctrl" would change all the results from the // HistoryQuickProvider provider, not just the What You Typed Result. - const string16 fixed_text(FixupUserInput(input)); + const std::wstring fixed_text(FixupUserInput(input)); if (fixed_text.empty()) { // Conceivably fixup could result in an empty string (although I don't // have cases where this happens offhand). We can't do anything with @@ -76,7 +76,7 @@ void HistoryQuickProvider::DeleteMatch(const AutocompleteMatch& match) {} void HistoryQuickProvider::DoAutocomplete() { // Get the matching URLs from the DB. - string16 term_string = autocomplete_input_.text(); + string16 term_string(WideToUTF16(autocomplete_input_.text())); term_string = UnescapeURLComponent(term_string, UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS); history::InMemoryURLIndex::String16Vector terms( @@ -114,33 +114,34 @@ AutocompleteMatch HistoryQuickProvider::QuickMatchToACMatch( match_type == WHAT_YOU_TYPED ? std::string() : languages_; match.fill_into_edit = AutocompleteInput::FormattedStringWithEquivalentMeaning(info.url(), - net::FormatUrl(info.url(), languages, format_types, - UnescapeRule::SPACES, NULL, NULL, - &inline_autocomplete_offset)); + UTF16ToWide(net::FormatUrl(info.url(), languages, format_types, + UnescapeRule::SPACES, NULL, NULL, + &inline_autocomplete_offset))); if (!autocomplete_input_.prevent_inline_autocomplete()) match.inline_autocomplete_offset = inline_autocomplete_offset; - DCHECK((match.inline_autocomplete_offset == string16::npos) || + DCHECK((match.inline_autocomplete_offset == std::wstring::npos) || (match.inline_autocomplete_offset <= match.fill_into_edit.length())); size_t match_start = history_match.input_location; - match.contents = net::FormatUrl(info.url(), languages, format_types, - UnescapeRule::SPACES, NULL, NULL, - &match_start); - if ((match_start != string16::npos) && - (inline_autocomplete_offset != string16::npos) && + match.contents = + UTF16ToWide(net::FormatUrl(info.url(), languages, format_types, + UnescapeRule::SPACES, NULL, NULL, + &match_start)); + if ((match_start != std::wstring::npos) && + (inline_autocomplete_offset != std::wstring::npos) && (inline_autocomplete_offset != match_start)) { DCHECK(inline_autocomplete_offset > match_start); AutocompleteMatch::ClassifyLocationInString(match_start, inline_autocomplete_offset - match_start, match.contents.length(), ACMatchClassification::URL, &match.contents_class); } else { - AutocompleteMatch::ClassifyLocationInString(string16::npos, 0, + AutocompleteMatch::ClassifyLocationInString(std::wstring::npos, 0, match.contents.length(), ACMatchClassification::URL, &match.contents_class); } - match.description = info.title(); + match.description = UTF16ToWide(info.title()); AutocompleteMatch::ClassifyMatchInString(autocomplete_input_.text(), - info.title(), + UTF16ToWide(info.title()), ACMatchClassification::NONE, &match.description_class); diff --git a/chrome/browser/autocomplete/history_quick_provider_unittest.cc b/chrome/browser/autocomplete/history_quick_provider_unittest.cc index e9f0581..7dab5dc 100644 --- a/chrome/browser/autocomplete/history_quick_provider_unittest.cc +++ b/chrome/browser/autocomplete/history_quick_provider_unittest.cc @@ -96,7 +96,7 @@ class HistoryQuickProviderTest : public testing::Test, // Runs an autocomplete query on |text| and checks to see that the returned // results' destination URLs match those provided. |expected_urls| does not // need to be in sorted order. - void RunTest(const string16 text, + void RunTest(const std::wstring text, std::vector<std::string> expected_urls, std::string expected_top_result); @@ -163,13 +163,13 @@ class SetShouldContain : public std::unary_function<const std::string&, std::set<std::string> matches_; }; -void HistoryQuickProviderTest::RunTest(const string16 text, +void HistoryQuickProviderTest::RunTest(const std::wstring text, std::vector<std::string> expected_urls, std::string expected_top_result) { std::sort(expected_urls.begin(), expected_urls.end()); MessageLoop::current()->RunAllPending(); - AutocompleteInput input(text, string16(), false, false, true, false); + AutocompleteInput input(text, std::wstring(), false, false, true, false); provider_->Start(input, false); EXPECT_TRUE(provider_->done()); @@ -194,7 +194,7 @@ void HistoryQuickProviderTest::RunTest(const string16 text, } TEST_F(HistoryQuickProviderTest, SimpleSingleMatch) { - string16 text(ASCIIToUTF16("slashdot")); + std::wstring text(L"slashdot"); std::string expected_url("http://slashdot.org/favorite_page.html"); std::vector<std::string> expected_urls; expected_urls.push_back(expected_url); @@ -202,7 +202,7 @@ TEST_F(HistoryQuickProviderTest, SimpleSingleMatch) { } TEST_F(HistoryQuickProviderTest, MultiMatch) { - string16 text(ASCIIToUTF16("foo")); + std::wstring text(L"foo"); std::vector<std::string> expected_urls; expected_urls.push_back("http://foo.com/"); expected_urls.push_back("http://foo.com/dir/"); @@ -214,7 +214,7 @@ TEST_F(HistoryQuickProviderTest, MultiMatch) { } TEST_F(HistoryQuickProviderTest, StartRelativeMatch) { - string16 text(ASCIIToUTF16("xyz")); + std::wstring text(L"xyz"); std::vector<std::string> expected_urls; expected_urls.push_back("http://xyzabcdefghijklmnopqrstuvw.com/a"); expected_urls.push_back("http://abcxyzdefghijklmnopqrstuvw.com/a"); @@ -225,7 +225,7 @@ TEST_F(HistoryQuickProviderTest, StartRelativeMatch) { } TEST_F(HistoryQuickProviderTest, RecencyMatch) { - string16 text(ASCIIToUTF16("startest")); + std::wstring text(L"startest"); std::vector<std::string> expected_urls; expected_urls.push_back("http://startest.com/y/a"); expected_urls.push_back("http://startest.com/y/b"); diff --git a/chrome/browser/autocomplete/history_url_provider.cc b/chrome/browser/autocomplete/history_url_provider.cc index 98adf2f..41fb155 100644 --- a/chrome/browser/autocomplete/history_url_provider.cc +++ b/chrome/browser/autocomplete/history_url_provider.cc @@ -78,7 +78,7 @@ bool CompareHistoryMatch(const HistoryMatch& a, const HistoryMatch& b) { // Given the user's |input| and a |match| created from it, reduce the // match's URL to just a host. If this host still matches the user input, // return it. Returns the empty string on failure. -GURL ConvertToHostOnly(const HistoryMatch& match, const string16& input) { +GURL ConvertToHostOnly(const HistoryMatch& match, const std::wstring& input) { // See if we should try to do host-only suggestions for this URL. Nonstandard // schemes means there's no authority section, so suggesting the host name // is useless. File URLs are standard, but host suggestion is not useful for @@ -93,7 +93,7 @@ GURL ConvertToHostOnly(const HistoryMatch& match, const string16& input) { if ((host.spec().length() < (match.input_location + input.length()))) return GURL(); // User typing is longer than this host suggestion. - const string16 spec = UTF8ToUTF16(host.spec()); + const std::wstring spec = UTF8ToWide(host.spec()); if (spec.compare(match.input_location, input.length(), input)) return GURL(); // User typing is no longer a prefix. @@ -188,7 +188,7 @@ void HistoryURLProvider::DoAutocomplete(history::HistoryBackend* backend, (params->input.type() != AutocompleteInput::QUERY) && ((params->input.type() != AutocompleteInput::UNKNOWN) || !params->trim_http || - url_util::FindAndCompareScheme(UTF16ToUTF8(params->input.text()), + url_util::FindAndCompareScheme(WideToUTF8(params->input.text()), chrome::kHttpsScheme, NULL)); AutocompleteMatch what_you_typed_match(SuggestExactInput(params->input, params->trim_http)); @@ -208,11 +208,11 @@ void HistoryURLProvider::DoAutocomplete(history::HistoryBackend* backend, // for more results than we need, of every prefix type, in hopes this will // give us far more than enough to work with. CullRedirects() will then // reduce the list to the best kMaxMatches results. - db->AutocompleteForPrefix(i->prefix + params->input.text(), + db->AutocompleteForPrefix(WideToUTF16(i->prefix + params->input.text()), kMaxMatches * 2, (backend == NULL), &url_matches); for (URLRowVector::const_iterator j(url_matches.begin()); j != url_matches.end(); ++j) { - const Prefix* best_prefix = BestPrefix(j->url(), string16()); + const Prefix* best_prefix = BestPrefix(j->url(), std::wstring()); DCHECK(best_prefix != NULL); history_matches.push_back(HistoryMatch(*j, i->prefix.length(), !i->num_components, @@ -313,7 +313,7 @@ AutocompleteMatch HistoryURLProvider::SuggestExactInput( // |match_location| below. StringForURLDisplay() and TrimHttpPrefix() have // slightly different behavior as well (the latter will strip even without // two slashes after the scheme). - string16 display_string(StringForURLDisplay(url, false, false)); + std::wstring display_string(StringForURLDisplay(url, false, false)); const size_t offset = trim_http ? TrimHttpPrefix(&display_string) : 0; match.fill_into_edit = AutocompleteInput::FormattedStringWithEquivalentMeaning(url, @@ -331,7 +331,7 @@ AutocompleteMatch HistoryURLProvider::SuggestExactInput( // to not contain the user's input at all. In this case don't mark anything // as a match. const size_t match_location = (best_prefix == NULL) ? - string16::npos : best_prefix->prefix.length() - offset; + std::wstring::npos : best_prefix->prefix.length() - offset; AutocompleteMatch::ClassifyLocationInString(match_location, input.text().length(), match.contents.length(), @@ -371,7 +371,7 @@ bool HistoryURLProvider::FixupExactSuggestion(history::URLDatabase* db, if (!db->GetRowForURL(match->destination_url, &info)) { if (input.desired_tld().empty()) return false; - GURL destination_url(URLFixerUpper::FixupURL(UTF16ToUTF8(input.text()), + GURL destination_url(URLFixerUpper::FixupURL(WideToUTF8(input.text()), std::string())); if (!db->GetRowForURL(destination_url, NULL)) return false; @@ -382,9 +382,9 @@ bool HistoryURLProvider::FixupExactSuggestion(history::URLDatabase* db, } else { // We have data for this match, use it. match->deletable = true; - match->description = info.title(); + match->description = UTF16ToWide(info.title()); AutocompleteMatch::ClassifyMatchInString(input.text(), - info.title(), + UTF16ToWide(info.title()), ACMatchClassification::NONE, &match->description_class); if (!info.typed_count()) { // If we reach here, we must be in the second pass, and we must not have @@ -402,7 +402,7 @@ bool HistoryURLProvider::FixupExactSuggestion(history::URLDatabase* db, match->relevance = CalculateRelevance(input.type(), type, 0); // Put it on the front of the HistoryMatches for redirect culling. - EnsureMatchPresent(info, string16::npos, false, matches, true); + EnsureMatchPresent(info, std::wstring::npos, false, matches, true); return true; } @@ -430,15 +430,14 @@ history::Prefixes HistoryURLProvider::GetPrefixes() { // We'll complete text following these prefixes. // NOTE: There's no requirement that these be in any particular order. Prefixes prefixes; - prefixes.push_back(Prefix(ASCIIToUTF16("https://www."), 2)); - prefixes.push_back(Prefix(ASCIIToUTF16("http://www."), 2)); - prefixes.push_back(Prefix(ASCIIToUTF16("ftp://ftp."), 2)); - prefixes.push_back(Prefix(ASCIIToUTF16("ftp://www."), 2)); - prefixes.push_back(Prefix(ASCIIToUTF16("https://"), 1)); - prefixes.push_back(Prefix(ASCIIToUTF16("http://"), 1)); - prefixes.push_back(Prefix(ASCIIToUTF16("ftp://"), 1)); - // Empty string catches within-scheme matches as well. - prefixes.push_back(Prefix(string16(), 0)); + prefixes.push_back(Prefix(L"https://www.", 2)); + prefixes.push_back(Prefix(L"http://www.", 2)); + prefixes.push_back(Prefix(L"ftp://ftp.", 2)); + prefixes.push_back(Prefix(L"ftp://www.", 2)); + prefixes.push_back(Prefix(L"https://", 1)); + prefixes.push_back(Prefix(L"http://", 1)); + prefixes.push_back(Prefix(L"ftp://", 1)); + prefixes.push_back(Prefix(L"", 0)); // Catches within-scheme matches as well return prefixes; } @@ -530,7 +529,7 @@ void HistoryURLProvider::PromoteOrCreateShorterSuggestion( // static void HistoryURLProvider::EnsureMatchPresent( const history::URLRow& info, - string16::size_type input_location, + std::wstring::size_type input_location, bool match_in_scheme, HistoryMatches* matches, bool promote) { @@ -595,7 +594,7 @@ void HistoryURLProvider::RunAutocompletePasses( // NOTE: This purposefully doesn't take input.desired_tld() into account; if // it did, then holding "ctrl" would change all the results from the // HistoryURLProvider provider, not just the What You Typed Result. - const string16 fixed_text(FixupUserInput(input)); + const std::wstring fixed_text(FixupUserInput(input)); if (fixed_text.empty()) { // Conceivably fixup could result in an empty string (although I don't // have cases where this happens offhand). We can't do anything with @@ -636,14 +635,14 @@ void HistoryURLProvider::RunAutocompletePasses( const history::Prefix* HistoryURLProvider::BestPrefix( const GURL& url, - const string16& prefix_suffix) const { + const std::wstring& prefix_suffix) const { const Prefix* best_prefix = NULL; - const string16 text(UTF8ToUTF16(url.spec())); + const std::wstring text(UTF8ToWide(url.spec())); for (Prefixes::const_iterator i(prefixes_.begin()); i != prefixes_.end(); ++i) { if ((best_prefix == NULL) || (i->num_components > best_prefix->num_components)) { - string16 prefix_with_suffix(i->prefix + prefix_suffix); + std::wstring prefix_with_suffix(i->prefix + prefix_suffix); if ((text.length() >= prefix_with_suffix.length()) && !text.compare(0, prefix_with_suffix.length(), prefix_with_suffix)) best_prefix = &(*i); @@ -779,32 +778,32 @@ AutocompleteMatch HistoryURLProvider::HistoryMatchToACMatch( 0 : net::kFormatUrlOmitHTTP); match.fill_into_edit = AutocompleteInput::FormattedStringWithEquivalentMeaning(info.url(), - net::FormatUrl(info.url(), languages, format_types, - UnescapeRule::SPACES, NULL, NULL, - &inline_autocomplete_offset)); + UTF16ToWideHack(net::FormatUrl(info.url(), languages, format_types, + UnescapeRule::SPACES, NULL, NULL, + &inline_autocomplete_offset))); if (!params->input.prevent_inline_autocomplete()) match.inline_autocomplete_offset = inline_autocomplete_offset; - DCHECK((match.inline_autocomplete_offset == string16::npos) || + DCHECK((match.inline_autocomplete_offset == std::wstring::npos) || (match.inline_autocomplete_offset <= match.fill_into_edit.length())); size_t match_start = history_match.input_location; - match.contents = net::FormatUrl(info.url(), languages, - format_types, UnescapeRule::SPACES, NULL, NULL, &match_start); - if ((match_start != string16::npos) && - (inline_autocomplete_offset != string16::npos) && + match.contents = UTF16ToWideHack(net::FormatUrl(info.url(), languages, + format_types, UnescapeRule::SPACES, NULL, NULL, &match_start)); + if ((match_start != std::wstring::npos) && + (inline_autocomplete_offset != std::wstring::npos) && (inline_autocomplete_offset != match_start)) { DCHECK(inline_autocomplete_offset > match_start); AutocompleteMatch::ClassifyLocationInString(match_start, inline_autocomplete_offset - match_start, match.contents.length(), ACMatchClassification::URL, &match.contents_class); } else { - AutocompleteMatch::ClassifyLocationInString(string16::npos, 0, + AutocompleteMatch::ClassifyLocationInString(std::wstring::npos, 0, match.contents.length(), ACMatchClassification::URL, &match.contents_class); } - match.description = info.title(); + match.description = UTF16ToWide(info.title()); AutocompleteMatch::ClassifyMatchInString(params->input.text(), - info.title(), + UTF16ToWide(info.title()), ACMatchClassification::NONE, &match.description_class); diff --git a/chrome/browser/autocomplete/history_url_provider.h b/chrome/browser/autocomplete/history_url_provider.h index 9b72cb1..0e4e5ff 100644 --- a/chrome/browser/autocomplete/history_url_provider.h +++ b/chrome/browser/autocomplete/history_url_provider.h @@ -192,7 +192,7 @@ class HistoryURLProvider : public HistoryProvider { // match's URL to just a host. If this host still matches the user input, // return it. Returns the empty string on failure. static GURL ConvertToHostOnly(const history::HistoryMatch& match, - const string16& input); + const std::wstring& input); // See if a shorter version of the best match should be created, and if so // place it at the front of |matches|. This can suggest history URLs that @@ -216,7 +216,7 @@ class HistoryURLProvider : public HistoryProvider { // |promote| is false, existing matches are left in place, and newly added // matches are placed at the back. static void EnsureMatchPresent(const history::URLRow& info, - string16::size_type input_location, + std::wstring::size_type input_location, bool match_in_scheme, history::HistoryMatches* matches, bool promote); @@ -232,7 +232,7 @@ class HistoryURLProvider : public HistoryProvider { // prefix. This is useful when you need to figure out the innermost match // for some user input in a URL. const history::Prefix* BestPrefix(const GURL& text, - const string16& prefix_suffix) const; + const std::wstring& prefix_suffix) const; // Returns a match corresponding to exactly what the user has typed. AutocompleteMatch SuggestExactInput(const AutocompleteInput& input, diff --git a/chrome/browser/autocomplete/history_url_provider_unittest.cc b/chrome/browser/autocomplete/history_url_provider_unittest.cc index 116cab6..b0f3cbd 100644 --- a/chrome/browser/autocomplete/history_url_provider_unittest.cc +++ b/chrome/browser/autocomplete/history_url_provider_unittest.cc @@ -115,13 +115,13 @@ class HistoryURLProviderTest : public testing::Test, // Runs an autocomplete query on |text| and checks to see that the returned // results' destination URLs match those provided. - void RunTest(const string16 text, - const string16& desired_tld, + void RunTest(const std::wstring text, + const std::wstring& desired_tld, bool prevent_inline_autocomplete, const std::string* expected_urls, size_t num_results); - void RunAdjustOffsetTest(const string16 text, size_t expected_offset); + void RunAdjustOffsetTest(const std::wstring text, size_t expected_offset); MessageLoopForUI message_loop_; BrowserThread ui_thread_; @@ -180,8 +180,8 @@ void HistoryURLProviderTest::FillData() { } } -void HistoryURLProviderTest::RunTest(const string16 text, - const string16& desired_tld, +void HistoryURLProviderTest::RunTest(const std::wstring text, + const std::wstring& desired_tld, bool prevent_inline_autocomplete, const std::string* expected_urls, size_t num_results) { @@ -198,9 +198,9 @@ void HistoryURLProviderTest::RunTest(const string16 text, EXPECT_EQ(expected_urls[i], matches_[i].destination_url.spec()); } -void HistoryURLProviderTest::RunAdjustOffsetTest(const string16 text, +void HistoryURLProviderTest::RunAdjustOffsetTest(const std::wstring text, size_t expected_offset) { - AutocompleteInput input(text, string16(), false, false, true, false); + AutocompleteInput input(text, std::wstring(), false, false, true, false); autocomplete_->Start(input, false); if (!autocomplete_->done()) MessageLoop::current()->Run(); @@ -216,7 +216,7 @@ TEST_F(HistoryURLProviderTest, PromoteShorterURLs) { "http://slashdot.org/favorite_page.html", "http://slashdot.org/", }; - RunTest(ASCIIToUTF16("slash"), string16(), true, expected_nonsynth, + RunTest(L"slash", std::wstring(), true, expected_nonsynth, arraysize(expected_nonsynth)); // Test that hosts get synthesized above less popular pages. @@ -224,11 +224,11 @@ TEST_F(HistoryURLProviderTest, PromoteShorterURLs) { "http://kerneltrap.org/", "http://kerneltrap.org/not_very_popular.html", }; - RunTest(ASCIIToUTF16("kernel"), string16(), true, expected_synth, + RunTest(L"kernel", std::wstring(), true, expected_synth, arraysize(expected_synth)); // Test that unpopular pages are ignored completely. - RunTest(ASCIIToUTF16("fresh"), string16(), true, NULL, 0); + RunTest(L"fresh", std::wstring(), true, NULL, 0); // Test that if we have a synthesized host that matches a suggestion, they // get combined into one. @@ -236,11 +236,11 @@ TEST_F(HistoryURLProviderTest, PromoteShorterURLs) { "http://news.google.com/", "http://news.google.com/?ned=us&topic=n", }; - ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16("news"), string16(), true, + ASSERT_NO_FATAL_FAILURE(RunTest(L"news", std::wstring(), true, expected_combine, arraysize(expected_combine))); // The title should also have gotten set properly on the host for the // synthesized one, since it was also in the results. - EXPECT_EQ(ASCIIToUTF16("Google News"), matches_.front().description); + EXPECT_EQ(std::wstring(L"Google News"), matches_.front().description); // Test that short URL matching works correctly as the user types more // (several tests): @@ -250,7 +250,7 @@ TEST_F(HistoryURLProviderTest, PromoteShorterURLs) { "http://foo.com/dir/another/again/myfile.html", "http://foo.com/dir/", }; - RunTest(ASCIIToUTF16("foo"), string16(), true, short_1, arraysize(short_1)); + RunTest(L"foo", std::wstring(), true, short_1, arraysize(short_1)); // When the user types the whole host, make sure we don't get two results for // it. @@ -260,10 +260,8 @@ TEST_F(HistoryURLProviderTest, PromoteShorterURLs) { "http://foo.com/dir/", "http://foo.com/dir/another/", }; - RunTest(ASCIIToUTF16("foo.com"), string16(), true, short_2, - arraysize(short_2)); - RunTest(ASCIIToUTF16("foo.com/"), string16(), true, short_2, - arraysize(short_2)); + RunTest(L"foo.com", std::wstring(), true, short_2, arraysize(short_2)); + RunTest(L"foo.com/", std::wstring(), true, short_2, arraysize(short_2)); // The filename is the second best of the foo.com* entries, but there is a // shorter URL that's "good enough". The host doesn't match the user input @@ -274,8 +272,7 @@ TEST_F(HistoryURLProviderTest, PromoteShorterURLs) { "http://foo.com/dir/another/again/myfile.html", "http://foo.com/dir/", }; - RunTest(ASCIIToUTF16("foo.com/d"), string16(), true, short_3, - arraysize(short_3)); + RunTest(L"foo.com/d", std::wstring(), true, short_3, arraysize(short_3)); // We shouldn't promote shorter URLs than the best if they're not good // enough. @@ -284,7 +281,7 @@ TEST_F(HistoryURLProviderTest, PromoteShorterURLs) { "http://foo.com/dir/another/again/myfile.html", "http://foo.com/dir/another/again/", }; - RunTest(ASCIIToUTF16("foo.com/dir/another/a"), string16(), true, short_4, + RunTest(L"foo.com/dir/another/a", std::wstring(), true, short_4, arraysize(short_4)); // Exact matches should always be best no matter how much more another match @@ -298,8 +295,8 @@ TEST_F(HistoryURLProviderTest, PromoteShorterURLs) { "http://gooey/", "http://www.google.com/", }; - RunTest(ASCIIToUTF16("g"), string16(), false, short_5a, arraysize(short_5a)); - RunTest(ASCIIToUTF16("go"), string16(), false, short_5b, arraysize(short_5b)); + RunTest(L"g", std::wstring(), false, short_5a, arraysize(short_5a)); + RunTest(L"go", std::wstring(), false, short_5b, arraysize(short_5b)); } TEST_F(HistoryURLProviderTest, CullRedirects) { @@ -339,32 +336,31 @@ TEST_F(HistoryURLProviderTest, CullRedirects) { // Because all the results are part of a redirect chain with other results, // all but the first one (A) should be culled. We should get the default // "what you typed" result, plus this one. - const string16 typing(ASCIIToUTF16("http://redirects/")); + const std::wstring typing(L"http://redirects/"); const std::string expected_results[] = { - UTF16ToUTF8(typing), + WideToUTF8(typing), redirect[0].url}; - RunTest(typing, string16(), true, expected_results, + RunTest(typing, std::wstring(), true, expected_results, arraysize(expected_results)); } TEST_F(HistoryURLProviderTest, WhatYouTyped) { // Make sure we suggest a What You Typed match at the right times. - RunTest(ASCIIToUTF16("wytmatch"), string16(), false, NULL, 0); - RunTest(ASCIIToUTF16("wytmatch foo bar"), string16(), false, NULL, 0); - RunTest(ASCIIToUTF16("wytmatch+foo+bar"), string16(), false, NULL, 0); - RunTest(ASCIIToUTF16("wytmatch+foo+bar.com"), string16(), false, NULL, 0); + RunTest(L"wytmatch", std::wstring(), false, NULL, 0); + RunTest(L"wytmatch foo bar", std::wstring(), false, NULL, 0); + RunTest(L"wytmatch+foo+bar", std::wstring(), false, NULL, 0); + RunTest(L"wytmatch+foo+bar.com", std::wstring(), false, NULL, 0); const std::string results_1[] = {"http://www.wytmatch.com/"}; - RunTest(ASCIIToUTF16("wytmatch"), ASCIIToUTF16("com"), false, results_1, - arraysize(results_1)); + RunTest(L"wytmatch", L"com", false, results_1, arraysize(results_1)); const std::string results_2[] = {"http://wytmatch%20foo%20bar/"}; - RunTest(ASCIIToUTF16("http://wytmatch foo bar"), string16(), false, results_2, + RunTest(L"http://wytmatch foo bar", std::wstring(), false, results_2, arraysize(results_2)); const std::string results_3[] = {"https://wytmatch%20foo%20bar/"}; - RunTest(ASCIIToUTF16("https://wytmatch foo bar"), string16(), false, - results_3, arraysize(results_3)); + RunTest(L"https://wytmatch foo bar", std::wstring(), false, results_3, + arraysize(results_3)); // Test the corner case where a user has fully typed a previously visited // intranet address and is now hitting ctrl-enter, which completes to a @@ -374,9 +370,9 @@ TEST_F(HistoryURLProviderTest, WhatYouTyped) { "http://www.binky.com/", "http://binky/", }; - RunTest(ASCIIToUTF16("binky"), string16(), false, binky_results, + RunTest(L"binky", std::wstring(), false, binky_results, arraysize(binky_results)); - RunTest(ASCIIToUTF16("binky"), ASCIIToUTF16("com"), false, binky_com_results, + RunTest(L"binky", L"com", false, binky_com_results, arraysize(binky_com_results)); // Test the related case where a user has fully typed a previously visited @@ -390,74 +386,71 @@ TEST_F(HistoryURLProviderTest, WhatYouTyped) { "http://www.winky.com/", "http://winky/", }; - RunTest(ASCIIToUTF16("winky"), string16(), false, winky_results, + RunTest(L"winky", std::wstring(), false, winky_results, arraysize(winky_results)); - RunTest(ASCIIToUTF16("winky"), ASCIIToUTF16("com"), false, winky_com_results, + RunTest(L"winky", L"com", false, winky_com_results, arraysize(winky_com_results)); } TEST_F(HistoryURLProviderTest, Fixup) { // Test for various past crashes we've had. - RunTest(ASCIIToUTF16("\\"), string16(), false, NULL, 0); - RunTest(ASCIIToUTF16("#"), string16(), false, NULL, 0); - RunTest(ASCIIToUTF16("%20"), string16(), false, NULL, 0); - RunTest(WideToUTF16(L"\uff65@s"), string16(), false, NULL, 0); - RunTest(WideToUTF16(L"\u2015\u2015@ \uff7c"), string16(), false, NULL, 0); + RunTest(L"\\", std::wstring(), false, NULL, 0); + RunTest(L"#", std::wstring(), false, NULL, 0); + RunTest(L"%20", std::wstring(), false, NULL, 0); + RunTest(L"\uff65@s", std::wstring(), false, NULL, 0); + RunTest(L"\u2015\u2015@ \uff7c", std::wstring(), false, NULL, 0); // Fixing up "file:" should result in an inline autocomplete offset of just // after "file:", not just after "file://". - const string16 input_1(ASCIIToUTF16("file:")); + const std::wstring input_1(L"file:"); const std::string fixup_1[] = {"file:///C:/foo.txt"}; - ASSERT_NO_FATAL_FAILURE(RunTest(input_1, string16(), false, fixup_1, + ASSERT_NO_FATAL_FAILURE(RunTest(input_1, std::wstring(), false, fixup_1, arraysize(fixup_1))); EXPECT_EQ(input_1.length(), matches_.front().inline_autocomplete_offset); // Fixing up "http:/" should result in an inline autocomplete offset of just // after "http:/", not just after "http:". - const string16 input_2(ASCIIToUTF16("http:/")); + const std::wstring input_2(L"http:/"); const std::string fixup_2[] = { "http://bogussite.com/a", "http://bogussite.com/b", "http://bogussite.com/c", }; - ASSERT_NO_FATAL_FAILURE(RunTest(input_2, string16(), false, fixup_2, + ASSERT_NO_FATAL_FAILURE(RunTest(input_2, std::wstring(), false, fixup_2, arraysize(fixup_2))); EXPECT_EQ(input_2.length(), matches_.front().inline_autocomplete_offset); // Adding a TLD to a small number like "56" should result in "www.56.com" // rather than "0.0.0.56.com". const std::string fixup_3[] = {"http://www.56.com/"}; - RunTest(ASCIIToUTF16("56"), ASCIIToUTF16("com"), true, fixup_3, - arraysize(fixup_3)); + RunTest(L"56", L"com", true, fixup_3, arraysize(fixup_3)); // An input looks like a IP address like "127.0.0.1" should result in // "http://127.0.0.1/". const std::string fixup_4[] = {"http://127.0.0.1/"}; - RunTest(ASCIIToUTF16("127.0.0.1"), string16(), false, fixup_4, - arraysize(fixup_4)); + RunTest(L"127.0.0.1", std::wstring(), false, fixup_4, arraysize(fixup_4)); // An number "17173" should result in "http://www.17173.com/" in db. const std::string fixup_5[] = {"http://www.17173.com/"}; - RunTest(ASCIIToUTF16("17173"), string16(), false, fixup_5, - arraysize(fixup_5)); + RunTest(L"17173", std::wstring(), false, fixup_5, arraysize(fixup_5)); } TEST_F(HistoryURLProviderTest, AdjustOffset) { - RunAdjustOffsetTest(WideToUTF16(L"http://www.\uAD50\uC721"), 13); - RunAdjustOffsetTest(ASCIIToUTF16("http://spaces.com/path%20with%20spa"), 31); - RunAdjustOffsetTest(ASCIIToUTF16("http://ms/c++ s"), 15); + RunAdjustOffsetTest(L"http://www.\uAD50\uC721", 13); + RunAdjustOffsetTest(L"http://spaces.com/path%20with%20spa", 31); + RunAdjustOffsetTest(L"http://ms/c++ s", 15); } TEST_F(HistoryURLProviderTestNoDB, NavigateWithoutDB) { // Ensure that we will still produce matches for navigation when there is no // database. std::string navigation_1[] = {"http://test.com/"}; - RunTest(ASCIIToUTF16("test.com"), string16(), false, navigation_1, + RunTest(L"test.com", std::wstring(), false, navigation_1, arraysize(navigation_1)); std::string navigation_2[] = {"http://slash/"}; - RunTest(ASCIIToUTF16("slash"), string16(), false, navigation_2, + RunTest(L"slash", std::wstring(), false, navigation_2, arraysize(navigation_2)); - RunTest(ASCIIToUTF16("this is a query"), string16(), false, NULL, 0); + RunTest(L"this is a query", std::wstring(), false, NULL, 0); } diff --git a/chrome/browser/autocomplete/keyword_provider.cc b/chrome/browser/autocomplete/keyword_provider.cc index 10cf328..b690363 100644 --- a/chrome/browser/autocomplete/keyword_provider.cc +++ b/chrome/browser/autocomplete/keyword_provider.cc @@ -41,15 +41,15 @@ class KeywordProvider::ScopedEndExtensionKeywordMode { }; // static -string16 KeywordProvider::SplitReplacementStringFromInput( - const string16& input, +std::wstring KeywordProvider::SplitReplacementStringFromInput( + const std::wstring& input, bool trim_leading_whitespace) { // The input may contain leading whitespace, strip it. - string16 trimmed_input; + std::wstring trimmed_input; TrimWhitespace(input, TRIM_LEADING, &trimmed_input); // And extract the replacement string. - string16 remaining_input; + std::wstring remaining_input; SplitKeywordFromInput(trimmed_input, trim_leading_whitespace, &remaining_input); return remaining_input; @@ -107,11 +107,11 @@ static int global_input_uid_; const TemplateURL* KeywordProvider::GetSubstitutingTemplateURLForInput( Profile* profile, const AutocompleteInput& input, - string16* remaining_input) { + std::wstring* remaining_input) { if (!input.allow_exact_keyword_match()) return NULL; - string16 keyword; + std::wstring keyword; if (!ExtractKeywordFromInput(input, &keyword, remaining_input)) return NULL; @@ -121,7 +121,8 @@ const TemplateURL* KeywordProvider::GetSubstitutingTemplateURLForInput( DCHECK(model); model->Load(); - const TemplateURL* template_url = model->GetTemplateURLForKeyword(keyword); + const TemplateURL* template_url = + model->GetTemplateURLForKeyword(WideToUTF16Hack(keyword)); return TemplateURL::SupportsReplacement(template_url) ? template_url : NULL; } @@ -154,7 +155,7 @@ void KeywordProvider::Start(const AutocompleteInput& input, // keywords, we might suggest keywords that haven't even been partially typed, // if the user uses them enough and isn't obviously typing something else. In // this case we'd consider all input here to be query input. - string16 keyword, remaining_input; + std::wstring keyword, remaining_input; if (!ExtractKeywordFromInput(input, &keyword, &remaining_input)) return; @@ -175,7 +176,7 @@ void KeywordProvider::Start(const AutocompleteInput& input, // search query both from the autocomplete popup and from web pages // themselves. std::vector<string16> keyword_matches; - model->FindMatchingKeywords(keyword, + model->FindMatchingKeywords(WideToUTF16Hack(keyword), !remaining_input.empty(), &keyword_matches); @@ -206,8 +207,9 @@ 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() == keyword) { - const TemplateURL* template_url(model->GetTemplateURLForKeyword(keyword)); + if (keyword_matches.front() == WideToUTF16Hack(keyword)) { + const TemplateURL* template_url( + model->GetTemplateURLForKeyword(WideToUTF16Hack(keyword))); // TODO(pkasting): We should probably check that if the user explicitly // typed a scheme, that scheme matches the one in |template_url|. matches_.push_back(CreateAutocompleteMatch(model, keyword, input, @@ -223,7 +225,7 @@ void KeywordProvider::Start(const AutocompleteInput& input, keyword_mode_toggle.StayInKeywordMode(); ApplyDefaultSuggestionForExtensionKeyword(profile_, template_url, - remaining_input, + WideToUTF16(remaining_input), &matches_[0]); if (minimal_changes) { @@ -240,7 +242,7 @@ void KeywordProvider::Start(const AutocompleteInput& input, bool have_listeners = ExtensionOmniboxEventRouter::OnInputChanged( profile_, template_url->GetExtensionId(), - UTF16ToUTF8(remaining_input), current_input_id_); + WideToUTF8(remaining_input), current_input_id_); // We only have to wait for suggest results if there are actually // extensions listening for input changes. @@ -255,7 +257,7 @@ void KeywordProvider::Start(const AutocompleteInput& input, } for (std::vector<string16>::const_iterator i(keyword_matches.begin()); i != keyword_matches.end(); ++i) { - matches_.push_back(CreateAutocompleteMatch(model, *i, + matches_.push_back(CreateAutocompleteMatch(model, UTF16ToWideHack(*i), input, keyword.length(), remaining_input, -1)); } @@ -271,33 +273,34 @@ KeywordProvider::~KeywordProvider() {} // static bool KeywordProvider::ExtractKeywordFromInput(const AutocompleteInput& input, - string16* keyword, - string16* remaining_input) { + std::wstring* keyword, + std::wstring* remaining_input) { if ((input.type() == AutocompleteInput::INVALID) || (input.type() == AutocompleteInput::FORCED_QUERY)) return false; - *keyword = TemplateURLModel::CleanUserInputKeyword( - SplitKeywordFromInput(input.text(), true, remaining_input)); + *keyword = + UTF16ToWideHack(TemplateURLModel::CleanUserInputKeyword(WideToUTF16Hack( + SplitKeywordFromInput(input.text(), true, remaining_input)))); return !keyword->empty(); } // static -string16 KeywordProvider::SplitKeywordFromInput( - const string16& input, +std::wstring KeywordProvider::SplitKeywordFromInput( + const std::wstring& input, bool trim_leading_whitespace, - string16* remaining_input) { + std::wstring* remaining_input) { // Find end of first token. The AutocompleteController has trimmed leading // whitespace, so we need not skip over that. - const size_t first_white(input.find_first_of(kWhitespaceUTF16)); + const size_t first_white(input.find_first_of(kWhitespaceWide)); DCHECK_NE(0U, first_white); - if (first_white == string16::npos) + if (first_white == std::wstring::npos) return input; // Only one token provided. // Set |remaining_input| to everything after the first token. DCHECK(remaining_input != NULL); const size_t remaining_start = trim_leading_whitespace ? - input.find_first_not_of(kWhitespaceUTF16, first_white) : first_white + 1; + input.find_first_not_of(kWhitespaceWide, first_white) : first_white + 1; if (remaining_start < input.length()) remaining_input->assign(input.begin() + remaining_start, input.end()); @@ -308,7 +311,7 @@ string16 KeywordProvider::SplitKeywordFromInput( // static void KeywordProvider::FillInURLAndContents( - const string16& remaining_input, + const std::wstring& remaining_input, const TemplateURL* element, AutocompleteMatch* match) { DCHECK(!element->short_name().empty()); @@ -323,16 +326,16 @@ void KeywordProvider::FillInURLAndContents( if (element->url()->SupportsReplacement() && !element->IsExtensionKeyword()) { // No query input; return a generic, no-destination placeholder. - match->contents.assign( + match->contents.assign(UTF16ToWideHack( l10n_util::GetStringFUTF16(message_id, element->AdjustedShortNameForLocaleDirection(), - l10n_util::GetStringUTF16(IDS_EMPTY_KEYWORD_VALUE))); + l10n_util::GetStringUTF16(IDS_EMPTY_KEYWORD_VALUE)))); match->contents_class.push_back( ACMatchClassification(0, ACMatchClassification::DIM)); } else { // Keyword that has no replacement text (aka a shorthand for a URL). match->destination_url = GURL(element->url()->url()); - match->contents.assign(element->short_name()); + match->contents.assign(UTF16ToWideHack(element->short_name())); AutocompleteMatch::ClassifyLocationInString(0, match->contents.length(), match->contents.length(), ACMatchClassification::NONE, &match->contents_class); @@ -344,13 +347,14 @@ void KeywordProvider::FillInURLAndContents( // fixup to make the URL valid if necessary. DCHECK(element->url()->SupportsReplacement()); match->destination_url = GURL(element->url()->ReplaceSearchTerms( - *element, remaining_input, - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); + *element, WideToUTF16Hack(remaining_input), + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); std::vector<size_t> content_param_offsets; - match->contents.assign(l10n_util::GetStringFUTF16(message_id, - element->short_name(), - remaining_input, - &content_param_offsets)); + match->contents.assign(UTF16ToWideHack( + l10n_util::GetStringFUTF16(message_id, + element->short_name(), + WideToUTF16Hack(remaining_input), + &content_param_offsets))); if (content_param_offsets.size() == 2) { AutocompleteMatch::ClassifyLocationInString(content_param_offsets[1], remaining_input.length(), match->contents.length(), @@ -378,15 +382,15 @@ int KeywordProvider::CalculateRelevance(AutocompleteInput::Type type, AutocompleteMatch KeywordProvider::CreateAutocompleteMatch( TemplateURLModel* model, - const string16& keyword, + const std::wstring& keyword, const AutocompleteInput& input, size_t prefix_length, - const string16& remaining_input, + const std::wstring& remaining_input, int relevance) { DCHECK(model); // Get keyword data from data store. const TemplateURL* element( - model->GetTemplateURLForKeyword(keyword)); + model->GetTemplateURLForKeyword(WideToUTF16Hack(keyword))); DCHECK(element && element->url()); const bool supports_replacement = element->url()->SupportsReplacement(); @@ -415,7 +419,7 @@ AutocompleteMatch KeywordProvider::CreateAutocompleteMatch( // to the user's input. Because right now inexact keyword matches can't score // more highly than a "what you typed" match from one of the other providers, // we just don't bother to do this, and leave inline autocompletion off. - result.inline_autocomplete_offset = string16::npos; + result.inline_autocomplete_offset = std::wstring::npos; // Create destination URL and popup entry content by substituting user input // into keyword templates. @@ -427,8 +431,8 @@ AutocompleteMatch KeywordProvider::CreateAutocompleteMatch( // Create popup entry description based on the keyword name. if (!element->IsExtensionKeyword()) { - result.description.assign(l10n_util::GetStringFUTF16( - IDS_AUTOCOMPLETE_KEYWORD_DESCRIPTION, keyword)); + result.description.assign(UTF16ToWideHack(l10n_util::GetStringFUTF16( + IDS_AUTOCOMPLETE_KEYWORD_DESCRIPTION, WideToUTF16Hack(keyword)))); string16 keyword_desc( l10n_util::GetStringUTF16(IDS_AUTOCOMPLETE_KEYWORD_DESCRIPTION)); AutocompleteMatch::ClassifyLocationInString( @@ -458,15 +462,15 @@ void KeywordProvider::Observe(NotificationType type, case NotificationType::EXTENSION_OMNIBOX_DEFAULT_SUGGESTION_CHANGED: { // It's possible to change the default suggestion while not in an editing // session. - string16 keyword, remaining_input; + std::wstring keyword, remaining_input; if (matches_.empty() || current_keyword_extension_id_.empty() || !ExtractKeywordFromInput(input, &keyword, &remaining_input)) return; const TemplateURL* template_url( - model->GetTemplateURLForKeyword(keyword)); + model->GetTemplateURLForKeyword(WideToUTF16Hack(keyword))); ApplyDefaultSuggestionForExtensionKeyword(profile_, template_url, - remaining_input, + WideToUTF16(remaining_input), &matches_[0]); listener_->OnProviderUpdate(true); return; @@ -478,7 +482,7 @@ void KeywordProvider::Observe(NotificationType type, if (suggestions.request_id != current_input_id_) return; // This is an old result. Just ignore. - string16 keyword, remaining_input; + std::wstring keyword, remaining_input; if (!ExtractKeywordFromInput(input, &keyword, &remaining_input)) { NOTREACHED(); return; @@ -498,10 +502,10 @@ void KeywordProvider::Observe(NotificationType type, input.prefer_keyword(), input.allow_exact_keyword_match()); extension_suggest_matches_.push_back(CreateAutocompleteMatch( model, keyword, input, keyword.length(), - suggestion.content, first_relevance - (i + 1))); + UTF16ToWide(suggestion.content), first_relevance - (i + 1))); AutocompleteMatch* match = &extension_suggest_matches_.back(); - match->contents.assign(suggestion.description); + match->contents.assign(UTF16ToWide(suggestion.description)); match->contents_class = suggestion.description_styles; match->description.clear(); match->description_class.clear(); diff --git a/chrome/browser/autocomplete/keyword_provider.h b/chrome/browser/autocomplete/keyword_provider.h index bd5cb9e..7adb9b5 100644 --- a/chrome/browser/autocomplete/keyword_provider.h +++ b/chrome/browser/autocomplete/keyword_provider.h @@ -60,8 +60,8 @@ class KeywordProvider : public AutocompleteProvider, // For example, the replacement string for "b blah" is blah. // If |trim_leading_whitespace| is true then leading whitespace in // replacement string will be trimmed. - static string16 SplitReplacementStringFromInput( - const string16& input, + static std::wstring SplitReplacementStringFromInput( + const std::wstring& input, bool trim_leading_whitespace); // Returns the matching substituting keyword for |input|, or NULL if there @@ -69,7 +69,7 @@ class KeywordProvider : public AutocompleteProvider, static const TemplateURL* GetSubstitutingTemplateURLForInput( Profile* profile, const AutocompleteInput& input, - string16* remaining_input); + std::wstring* remaining_input); // AutocompleteProvider virtual void Start(const AutocompleteInput& input, bool minimal_changes); @@ -89,22 +89,22 @@ class KeywordProvider : public AutocompleteProvider, // In general use this instead of SplitKeywordFromInput. // Leading whitespace in |*remaining_input| will be trimmed. static bool ExtractKeywordFromInput(const AutocompleteInput& input, - string16* keyword, - string16* remaining_input); + std::wstring* keyword, + std::wstring* remaining_input); // Extracts the next whitespace-delimited token from input and returns it. // Sets |remaining_input| to everything after the first token (skipping over // the first intervening whitespace). // If |trim_leading_whitespace| is true then leading whitespace in // |*remaining_input| will be trimmed. - static string16 SplitKeywordFromInput(const string16& input, - bool trim_leading_whitespace, - string16* remaining_input); + static std::wstring SplitKeywordFromInput(const std::wstring& input, + bool trim_leading_whitespace, + std::wstring* remaining_input); // Fills in the "destination_url" and "contents" fields of |match| with the // provided user input and keyword data. static void FillInURLAndContents( - const string16& remaining_input, + const std::wstring& remaining_input, const TemplateURL* element, AutocompleteMatch* match); @@ -123,10 +123,10 @@ class KeywordProvider : public AutocompleteProvider, // If |relevance| is negative, calculate a relevance based on heuristics. AutocompleteMatch CreateAutocompleteMatch( TemplateURLModel* model, - const string16& keyword, + const std::wstring& keyword, const AutocompleteInput& input, size_t prefix_length, - const string16& remaining_input, + const std::wstring& remaining_input, int relevance); void EnterExtensionKeywordMode(const std::string& extension_id); diff --git a/chrome/browser/autocomplete/keyword_provider_unittest.cc b/chrome/browser/autocomplete/keyword_provider_unittest.cc index 5874cca..9feee61 100644 --- a/chrome/browser/autocomplete/keyword_provider_unittest.cc +++ b/chrome/browser/autocomplete/keyword_provider_unittest.cc @@ -15,7 +15,7 @@ class KeywordProviderTest : public testing::Test { protected: template<class ResultType> struct test_data { - const string16 input; + const std::wstring input; const size_t num_results; const ResultType output[3]; }; @@ -64,13 +64,13 @@ void KeywordProviderTest::RunTest( ResultType AutocompleteMatch::* member) { ACMatches matches; for (int i = 0; i < num_cases; ++i) { - AutocompleteInput input(keyword_cases[i].input, string16(), true, + AutocompleteInput input(keyword_cases[i].input, std::wstring(), true, false, true, false); kw_provider_->Start(input, false); EXPECT_TRUE(kw_provider_->done()); matches = kw_provider_->matches(); EXPECT_EQ(keyword_cases[i].num_results, matches.size()) << - ASCIIToUTF16("Input was: ") + keyword_cases[i].input; + L"Input was: " + keyword_cases[i].input; if (matches.size() == keyword_cases[i].num_results) { for (size_t j = 0; j < keyword_cases[i].num_results; ++j) { EXPECT_EQ(keyword_cases[i].output[j], matches[j].*member); @@ -80,69 +80,61 @@ void KeywordProviderTest::RunTest( } TEST_F(KeywordProviderTest, Edit) { - test_data<string16> edit_cases[] = { + test_data<std::wstring> edit_cases[] = { // Searching for a nonexistent prefix should give nothing. - {ASCIIToUTF16("Not Found"), 0, {}}, - {ASCIIToUTF16("aaaaaNot Found"), 0, {}}, + {L"Not Found", 0, {}}, + {L"aaaaaNot Found", 0, {}}, // Check that tokenization only collapses whitespace between first tokens, // no-query-input cases have a space appended, and action is not escaped. - {ASCIIToUTF16("z foo"), 1, {ASCIIToUTF16("z foo")}}, - {ASCIIToUTF16("z"), 1, {ASCIIToUTF16("z ")}}, - {ASCIIToUTF16("z \t"), 1, {ASCIIToUTF16("z ")}}, - {ASCIIToUTF16("z a b c++"), 1, {ASCIIToUTF16("z a b c++")}}, + {L"z foo", 1, {L"z foo"}}, + {L"z", 1, {L"z "}}, + {L"z \t", 1, {L"z "}}, + {L"z a b c++", 1, {L"z a b c++"}}, // Matches should be limited to three, and sorted in quality order, not // alphabetical. - {ASCIIToUTF16("aaa"), 2, {ASCIIToUTF16("aaaa "), - ASCIIToUTF16("aaaaa ")}}, - {ASCIIToUTF16("a 1 2 3"), 3, {ASCIIToUTF16("aa 1 2 3"), - ASCIIToUTF16("ab 1 2 3"), - ASCIIToUTF16("aaaa 1 2 3")}}, - {ASCIIToUTF16("www.a"), 3, {ASCIIToUTF16("aa "), - ASCIIToUTF16("ab "), - ASCIIToUTF16("aaaa ")}}, + {L"aaa", 2, {L"aaaa ", L"aaaaa "}}, + {L"a 1 2 3", 3, {L"aa 1 2 3", L"ab 1 2 3", L"aaaa 1 2 3"}}, + {L"www.a", 3, {L"aa ", L"ab ", L"aaaa "}}, // Exact matches should prevent returning inexact matches. - {ASCIIToUTF16("aaaa foo"), 1, {ASCIIToUTF16("aaaa foo")}}, - {ASCIIToUTF16("www.aaaa foo"), 1, {ASCIIToUTF16("aaaa foo")}}, + {L"aaaa foo", 1, {L"aaaa foo"}}, + {L"www.aaaa foo", 1, {L"aaaa foo"}}, // Clean up keyword input properly. "http" and "https" are the only // allowed schemes. - {ASCIIToUTF16("www"), 1, {ASCIIToUTF16("www ")}}, - {ASCIIToUTF16("www."), 0, {}}, - {ASCIIToUTF16("www.w w"), 2, {ASCIIToUTF16("www w"), - ASCIIToUTF16("weasel w")}}, - {ASCIIToUTF16("http://www"), 1, {ASCIIToUTF16("www ")}}, - {ASCIIToUTF16("http://www."), 0, {}}, - {ASCIIToUTF16("ftp: blah"), 0, {}}, - {ASCIIToUTF16("mailto:z"), 0, {}}, - {ASCIIToUTF16("ftp://z"), 0, {}}, - {ASCIIToUTF16("https://z"), 1, {ASCIIToUTF16("z ")}}, + {L"www", 1, {L"www "}}, + {L"www.", 0, {}}, + {L"www.w w", 2, {L"www w", L"weasel w"}}, + {L"http://www", 1, {L"www "}}, + {L"http://www.", 0, {}}, + {L"ftp: blah", 0, {}}, + {L"mailto:z", 0, {}}, + {L"ftp://z", 0, {}}, + {L"https://z", 1, {L"z "}}, }; - RunTest<string16>(edit_cases, arraysize(edit_cases), - &AutocompleteMatch::fill_into_edit); + RunTest<std::wstring>(edit_cases, arraysize(edit_cases), + &AutocompleteMatch::fill_into_edit); } TEST_F(KeywordProviderTest, URL) { test_data<GURL> url_cases[] = { // No query input -> empty destination URL. - {ASCIIToUTF16("z"), 1, {GURL()}}, - {ASCIIToUTF16("z \t"), 1, {GURL()}}, + {L"z", 1, {GURL()}}, + {L"z \t", 1, {GURL()}}, // Check that tokenization only collapses whitespace between first tokens // and query input, but not rest of URL, is escaped. - {ASCIIToUTF16("z a b c++"), 1, {GURL("a+++b+++c%2B%2B=z")}}, - {ASCIIToUTF16("www.www www"), 1, {GURL(" +%2B?=wwwfoo ")}}, + {L"z a b c++", 1, {GURL("a+++b+++c%2B%2B=z")}}, + {L"www.www www", 1, {GURL(" +%2B?=wwwfoo ")}}, // Substitution should work with various locations of the "%s". - {ASCIIToUTF16("aaa 1a2b"), 2, {GURL("http://aaaa/?aaaa=1&b=1a2b&c"), - GURL("1a2b")}}, - {ASCIIToUTF16("a 1 2 3"), 3, {GURL("aa.com?foo=1+2+3"), - GURL("bogus URL 1+2+3"), - GURL("http://aaaa/?aaaa=1&b=1+2+3&c")}}, - {ASCIIToUTF16("www.w w"), 2, {GURL(" +%2B?=wfoo "), - GURL("weaselwweasel")}}, + {L"aaa 1a2b", 2, {GURL("http://aaaa/?aaaa=1&b=1a2b&c"), + GURL("1a2b")}}, + {L"a 1 2 3", 3, {GURL("aa.com?foo=1+2+3"), GURL("bogus URL 1+2+3"), + GURL("http://aaaa/?aaaa=1&b=1+2+3&c")}}, + {L"www.w w", 2, {GURL(" +%2B?=wfoo "), GURL("weaselwweasel")}}, }; RunTest<GURL>(url_cases, arraysize(url_cases), @@ -150,51 +142,44 @@ TEST_F(KeywordProviderTest, URL) { } TEST_F(KeywordProviderTest, Contents) { - test_data<string16> contents_cases[] = { + test_data<std::wstring> contents_cases[] = { // No query input -> substitute "<enter query>" into contents. - {ASCIIToUTF16("z"), 1, - {ASCIIToUTF16("Search z for <enter query>")}}, - {ASCIIToUTF16("z \t"), 1, - {ASCIIToUTF16("Search z for <enter query>")}}, + {L"z", 1, {L"Search z for <enter query>"}}, + {L"z \t", 1, {L"Search z for <enter query>"}}, // Check that tokenization only collapses whitespace between first tokens // and contents are not escaped or unescaped. - {ASCIIToUTF16("z a b c++"), 1, - {ASCIIToUTF16("Search z for a b c++")}}, - {ASCIIToUTF16("www.www www"), 1, {ASCIIToUTF16("Search www for www")}}, + {L"z a b c++", 1, {L"Search z for a b c++"}}, + {L"www.www www", 1, {L"Search www for www"}}, // Substitution should work with various locations of the "%s". - {ASCIIToUTF16("aaa"), 2, - {ASCIIToUTF16("Search aaaa for <enter query>"), - ASCIIToUTF16("Search aaaaa for <enter query>")}}, - {ASCIIToUTF16("a 1 2 3"), 3, {ASCIIToUTF16("Search aa for 1 2 3"), - ASCIIToUTF16("Search ab for 1 2 3"), - ASCIIToUTF16("Search aaaa for 1 2 3")}}, - {ASCIIToUTF16("www.w w"), 2, {ASCIIToUTF16("Search www for w"), - ASCIIToUTF16("Search weasel for w")}}, + {L"aaa", 2, {L"Search aaaa for <enter query>", + L"Search aaaaa for <enter query>"}}, + {L"a 1 2 3", 3, {L"Search aa for 1 2 3", L"Search ab for 1 2 3", + L"Search aaaa for 1 2 3"}}, + {L"www.w w", 2, {L"Search www for w", L"Search weasel for w"}}, }; - RunTest<string16>(contents_cases, arraysize(contents_cases), + RunTest<std::wstring>(contents_cases, arraysize(contents_cases), &AutocompleteMatch::contents); } TEST_F(KeywordProviderTest, Description) { - test_data<string16> description_cases[] = { + test_data<std::wstring> description_cases[] = { // Whole keyword should be returned for both exact and inexact matches. - {ASCIIToUTF16("z foo"), 1, {ASCIIToUTF16("(Keyword: z)")}}, - {ASCIIToUTF16("a foo"), 3, {ASCIIToUTF16("(Keyword: aa)"), - ASCIIToUTF16("(Keyword: ab)"), - ASCIIToUTF16("(Keyword: aaaa)")}}, - {ASCIIToUTF16("ftp://www.www w"), 0, {}}, - {ASCIIToUTF16("http://www.ab w"), 1, {ASCIIToUTF16("(Keyword: ab)")}}, + {L"z foo", 1, {L"(Keyword: z)"}}, + {L"a foo", 3, {L"(Keyword: aa)", L"(Keyword: ab)", + L"(Keyword: aaaa)"}}, + {L"ftp://www.www w", 0, {}}, + {L"http://www.ab w", 1, {L"(Keyword: ab)"}}, // Keyword should be returned regardless of query input. - {ASCIIToUTF16("z"), 1, {ASCIIToUTF16("(Keyword: z)")}}, - {ASCIIToUTF16("z \t"), 1, {ASCIIToUTF16("(Keyword: z)")}}, - {ASCIIToUTF16("z a b c++"), 1, {ASCIIToUTF16("(Keyword: z)")}}, + {L"z", 1, {L"(Keyword: z)"}}, + {L"z \t", 1, {L"(Keyword: z)"}}, + {L"z a b c++", 1, {L"(Keyword: z)"}}, }; - RunTest<string16>(description_cases, arraysize(description_cases), + RunTest<std::wstring>(description_cases, arraysize(description_cases), &AutocompleteMatch::description); } diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc index de6313a..32f58e5 100644 --- a/chrome/browser/autocomplete/search_provider.cc +++ b/chrome/browser/autocomplete/search_provider.cc @@ -63,8 +63,8 @@ SearchProvider::SearchProvider(ACProviderListener* listener, Profile* profile) instant_finalized_(false) { } -void SearchProvider::FinalizeInstantQuery(const string16& input_text, - const string16& suggest_text) { +void SearchProvider::FinalizeInstantQuery(const std::wstring& input_text, + const std::wstring& suggest_text) { if (done_ || instant_finalized_) return; @@ -80,11 +80,11 @@ void SearchProvider::FinalizeInstantQuery(const string16& input_text, default_provider_suggest_text_ = suggest_text; - string16 adjusted_input_text(input_text); + std::wstring adjusted_input_text(input_text); AutocompleteInput::RemoveForcedQueryStringIfNecessary(input_.type(), &adjusted_input_text); - const string16 text = adjusted_input_text + suggest_text; + const std::wstring text = adjusted_input_text + suggest_text; // Remove any matches that are identical to |text|. We don't use the // destination_url for comparison as it varies depending upon the index passed // to TemplateURL::ReplaceSearchTerms. @@ -180,7 +180,8 @@ void SearchProvider::Start(const AutocompleteInput& input, if (default_provider) { AutocompleteMatch match; match.provider = this; - match.contents.assign(l10n_util::GetStringUTF16(IDS_EMPTY_KEYWORD_VALUE)); + match.contents.assign(UTF16ToWideHack( + l10n_util::GetStringUTF16(IDS_EMPTY_KEYWORD_VALUE))); match.contents_class.push_back( ACMatchClassification(0, ACMatchClassification::NONE)); matches_.push_back(match); @@ -243,12 +244,12 @@ void SearchProvider::OnURLFetchComplete(const URLFetcher* source, if (response_headers) { std::string charset; if (response_headers->GetCharset(&charset)) { - string16 data_16; + std::wstring wide_data; // TODO(jungshik): Switch to CodePageToUTF8 after it's added. - if (base::CodepageToUTF16(data, charset.c_str(), - base::OnStringConversionError::FAIL, - &data_16)) - json_data = UTF16ToUTF8(data_16); + if (base::CodepageToWide(data, charset.c_str(), + base::OnStringConversionError::FAIL, + &wide_data)) + json_data = WideToUTF8(wide_data); } } @@ -260,7 +261,7 @@ void SearchProvider::OnURLFetchComplete(const URLFetcher* source, JSONStringValueSerializer deserializer(json_data); deserializer.set_allow_trailing_comma(true); scoped_ptr<Value> root_val(deserializer.Deserialize(NULL, NULL)); - const string16& input_text = + const std::wstring& input_text = is_keyword_results ? keyword_input_text_ : input_.text(); have_suggest_results_ = root_val.get() && @@ -295,14 +296,14 @@ void SearchProvider::DoHistoryQuery(bool minimal_changes) { if (providers_.valid_keyword_provider()) { url_db->GetMostRecentKeywordSearchTerms( providers_.keyword_provider().id(), - keyword_input_text_, + WideToUTF16(keyword_input_text_), static_cast<int>(kMaxMatches), &keyword_history_results_); } if (providers_.valid_default_provider()) { url_db->GetMostRecentKeywordSearchTerms( providers_.default_provider().id(), - input_.text(), + WideToUTF16(input_.text()), static_cast<int>(kMaxMatches), &default_history_results_); } @@ -372,9 +373,8 @@ bool SearchProvider::IsQuerySuitableForSuggest() const { // probably a URL that's being entered and happens to currently be invalid -- // in which case we again want to run our checks below. Other QUERY cases are // less likely to be URLs and thus we assume we're OK. - if (!LowerCaseEqualsASCII(input_.scheme(), chrome::kHttpScheme) && - !LowerCaseEqualsASCII(input_.scheme(), chrome::kHttpsScheme) && - !LowerCaseEqualsASCII(input_.scheme(), chrome::kFtpScheme)) + if ((input_.scheme() != L"http") && (input_.scheme() != L"https") && + (input_.scheme() != L"ftp")) return (input_.type() == AutocompleteInput::QUERY); // Don't send URLs with usernames, queries or refs. Some of these are @@ -391,8 +391,7 @@ bool SearchProvider::IsQuerySuitableForSuggest() const { // Don't send anything for https except the hostname. Hostnames are OK // because they are visible when the TCP connection is established, but the // specific path may reveal private information. - if (LowerCaseEqualsASCII(input_.scheme(), chrome::kHttpsScheme) && - parts.path.is_nonempty()) + if ((input_.scheme() == L"https") && parts.path.is_nonempty()) return false; return true; @@ -413,12 +412,12 @@ void SearchProvider::StopSuggest() { URLFetcher* SearchProvider::CreateSuggestFetcher(int id, const TemplateURL& provider, - const string16& text) { + const std::wstring& text) { const TemplateURLRef* const suggestions_url = provider.suggestions_url(); DCHECK(suggestions_url->SupportsReplacement()); URLFetcher* fetcher = URLFetcher::Create(id, GURL(suggestions_url->ReplaceSearchTerms( - provider, text, + provider, WideToUTF16Hack(text), TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())), URLFetcher::GET, this); fetcher->set_request_context(profile_->GetRequestContext()); @@ -428,7 +427,7 @@ URLFetcher* SearchProvider::CreateSuggestFetcher(int id, bool SearchProvider::ParseSuggestResults(Value* root_val, bool is_keyword, - const string16& input_text, + const std::wstring& input_text, SuggestResults* suggest_results) { if (!root_val->IsType(Value::TYPE_LIST)) return false; @@ -439,7 +438,7 @@ bool SearchProvider::ParseSuggestResults(Value* root_val, Value* result_val; if ((root_list->GetSize() < 2) || !root_list->Get(0, &query_val) || !query_val->GetAsString(&query_str) || - (query_str != input_text) || + (query_str != WideToUTF16Hack(input_text)) || !root_list->Get(1, &result_val) || !result_val->IsType(Value::TYPE_LIST)) return false; @@ -504,14 +503,15 @@ bool SearchProvider::ParseSuggestResults(Value* root_val, GURL result_url(URLFixerUpper::FixupURL(UTF16ToUTF8(suggestion_str), std::string())); if (result_url.is_valid()) { - navigation_results.push_back(NavigationResult(result_url, site_name)); + navigation_results.push_back(NavigationResult(result_url, + UTF16ToWideHack(site_name))); } } } else { // TODO(kochi): Currently we treat a calculator result as a query, but it // is better to have better presentation for caluculator results. if (suggest_results->size() < kMaxMatches) - suggest_results->push_back(suggestion_str); + suggest_results->push_back(UTF16ToWideHack(suggestion_str)); } } @@ -612,7 +612,7 @@ void SearchProvider::AddHistoryResultsToMap(const HistoryResults& results, if (i != results.begin() && relevance >= last_relevance) relevance = last_relevance - 1; last_relevance = relevance; - AddMatchToMap(i->term, + AddMatchToMap(UTF16ToWide(i->term), is_keyword ? keyword_input_text_ : input_.text(), relevance, AutocompleteMatch::SEARCH_HISTORY, did_not_accept_suggestion, @@ -717,8 +717,8 @@ int SearchProvider::CalculateRelevanceForNavigation(size_t num_results, static_cast<int>(num_results - 1 - result_number); } -void SearchProvider::AddMatchToMap(const string16& query_string, - const string16& input_text, +void SearchProvider::AddMatchToMap(const std::wstring& query_string, + const std::wstring& input_text, int relevance, AutocompleteMatch::Type type, int accepted_suggestion, @@ -735,7 +735,7 @@ void SearchProvider::AddMatchToMap(const string16& query_string, // "youtube", so we'll bold the "tube" section: you*tube*. if (input_text != query_string) { size_t input_position = match.contents.find(input_text); - if (input_position == string16::npos) { + if (input_position == std::wstring::npos) { // The input text is not a substring of the query string, e.g. input // text is "slasdot" and the query string is "slashdot", so we bold the // whole thing. @@ -774,12 +774,12 @@ void SearchProvider::AddMatchToMap(const string16& query_string, // suggestion, non-Search results will suddenly appear. size_t search_start = 0; if (input_.type() == AutocompleteInput::FORCED_QUERY) { - match.fill_into_edit.assign(ASCIIToUTF16("?")); + match.fill_into_edit.assign(L"?"); ++search_start; } if (is_keyword) { - match.fill_into_edit.append( - providers_.keyword_provider().keyword() + char16(' ')); + match.fill_into_edit.append(UTF16ToWideHack( + providers_.keyword_provider().keyword() + char16(' '))); match.template_url = &providers_.keyword_provider(); } match.fill_into_edit.append(query_string); @@ -793,9 +793,9 @@ void SearchProvider::AddMatchToMap(const string16& query_string, DCHECK(search_url->SupportsReplacement()); match.destination_url = GURL(search_url->ReplaceSearchTerms(provider, - query_string, + WideToUTF16Hack(query_string), accepted_suggestion, - input_text)); + WideToUTF16Hack(input_text))); // Search results don't look like URLs. match.transition = @@ -805,8 +805,8 @@ void SearchProvider::AddMatchToMap(const string16& query_string, // |map|, replace it if |match| is more relevant. // NOTE: Keep this ToLower() call in sync with url_database.cc. const std::pair<MatchMap::iterator, bool> i = map->insert( - std::pair<string16, AutocompleteMatch>( - l10n_util::ToLower(query_string), match)); + std::pair<std::wstring, AutocompleteMatch>( + UTF16ToWide(l10n_util::ToLower(WideToUTF16(query_string))), match)); // NOTE: We purposefully do a direct relevance comparison here instead of // using AutocompleteMatch::MoreRelevant(), so that we'll prefer "items added // first" rather than "items alphabetically first" when the scores are equal. @@ -823,7 +823,7 @@ AutocompleteMatch SearchProvider::NavigationToMatch( const NavigationResult& navigation, int relevance, bool is_keyword) { - const string16& input_text = + const std::wstring& input_text = is_keyword ? keyword_input_text_ : input_.text(); AutocompleteMatch match(this, relevance, false, AutocompleteMatch::NAVSUGGEST); @@ -843,7 +843,7 @@ AutocompleteMatch SearchProvider::NavigationToMatch( // values preserve that property. Otherwise, if the user starts editing a // suggestion, non-Search results will suddenly appear. if (input_.type() == AutocompleteInput::FORCED_QUERY) - match.fill_into_edit.assign(ASCIIToUTF16("?")); + match.fill_into_edit.assign(L"?"); match.fill_into_edit.append( AutocompleteInput::FormattedStringWithEquivalentMeaning(navigation.url, match.contents)); @@ -870,10 +870,11 @@ void SearchProvider::UpdateFirstSearchMatchDescription() { case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED: case AutocompleteMatch::SEARCH_HISTORY: case AutocompleteMatch::SEARCH_SUGGEST: - match.description.assign(l10n_util::GetStringFUTF16( - IDS_AUTOCOMPLETE_SEARCH_DESCRIPTION, - providers_.default_provider(). - AdjustedShortNameForLocaleDirection())); + match.description.assign( + UTF16ToWideHack(l10n_util::GetStringFUTF16( + IDS_AUTOCOMPLETE_SEARCH_DESCRIPTION, + 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.h b/chrome/browser/autocomplete/search_provider.h index f25e9c8..6f1d462 100644 --- a/chrome/browser/autocomplete/search_provider.h +++ b/chrome/browser/autocomplete/search_provider.h @@ -59,8 +59,8 @@ class SearchProvider : public AutocompleteProvider, // // This method also marks the search provider as no longer needing to wait for // the instant result. - void FinalizeInstantQuery(const string16& input_text, - const string16& suggest_text); + void FinalizeInstantQuery(const std::wstring& input_text, + const std::wstring& suggest_text); // AutocompleteProvider virtual void Start(const AutocompleteInput& input, @@ -152,7 +152,7 @@ class SearchProvider : public AutocompleteProvider, }; struct NavigationResult { - NavigationResult(const GURL& url, const string16& site_name) + NavigationResult(const GURL& url, const std::wstring& site_name) : url(url), site_name(site_name) { } @@ -161,13 +161,13 @@ class SearchProvider : public AutocompleteProvider, GURL url; // Name for the site. - string16 site_name; + std::wstring site_name; }; - typedef std::vector<string16> SuggestResults; + typedef std::vector<std::wstring> SuggestResults; typedef std::vector<NavigationResult> NavigationResults; typedef std::vector<history::KeywordSearchTermVisit> HistoryResults; - typedef std::map<string16, AutocompleteMatch> MatchMap; + typedef std::map<std::wstring, AutocompleteMatch> MatchMap; // Called when timer_ expires. void Run(); @@ -194,13 +194,13 @@ class SearchProvider : public AutocompleteProvider, // TemplateURL. Ownership of the returned URLFetchet passes to the caller. URLFetcher* CreateSuggestFetcher(int id, const TemplateURL& provider, - const string16& text); + const std::wstring& text); // Parses the results from the Suggest server and stores up to kMaxMatches of // them in server_results_. Returns whether parsing succeeded. bool ParseSuggestResults(Value* root_val, bool is_keyword, - const string16& input_text, + const std::wstring& input_text, SuggestResults* suggest_results); // Converts the parsed server results in server_results_ to a set of @@ -251,8 +251,8 @@ class SearchProvider : public AutocompleteProvider, // Creates an AutocompleteMatch for "Search <engine> for |query_string|" with // the supplied relevance. Adds this match to |map|; if such a match already // exists, whichever one has lower relevance is eliminated. - void AddMatchToMap(const string16& query_string, - const string16& input_text, + void AddMatchToMap(const std::wstring& query_string, + const std::wstring& input_text, int relevance, AutocompleteMatch::Type type, int accepted_suggestion, @@ -282,7 +282,7 @@ class SearchProvider : public AutocompleteProvider, AutocompleteInput input_; // Input text when searching against the keyword provider. - string16 keyword_input_text_; + std::wstring keyword_input_text_; // Searches in the user's history that begin with the input text. HistoryResults keyword_history_results_; @@ -318,7 +318,7 @@ class SearchProvider : public AutocompleteProvider, bool instant_finalized_; // The |suggest_text| parameter passed to FinalizeInstantQuery. - string16 default_provider_suggest_text_; + std::wstring default_provider_suggest_text_; DISALLOW_COPY_AND_ASSIGN(SearchProvider); }; diff --git a/chrome/browser/autocomplete/search_provider_unittest.cc b/chrome/browser/autocomplete/search_provider_unittest.cc index 264dbcf..0e7ac57 100644 --- a/chrome/browser/autocomplete/search_provider_unittest.cc +++ b/chrome/browser/autocomplete/search_provider_unittest.cc @@ -173,8 +173,8 @@ void SearchProviderTest::RunTillProviderDone() { void SearchProviderTest::QueryForInput(const string16& text, bool prevent_inline_autocomplete) { // Start a query. - AutocompleteInput input(text, string16(), prevent_inline_autocomplete, - false, true, false); + AutocompleteInput input(UTF16ToWide(text), std::wstring(), + prevent_inline_autocomplete, false, true, false); provider_->Start(input, false); // RunAllPending so that the task scheduled by SearchProvider to create the @@ -312,7 +312,8 @@ TEST_F(SearchProviderTest, QueryKeywordProvider) { EXPECT_TRUE(match.template_url); // The fill into edit should contain the keyword. - EXPECT_EQ(keyword_t_url_->keyword() + char16(' ') + keyword_term_, + EXPECT_EQ(UTF16ToWideHack(keyword_t_url_->keyword()) + + L" " + UTF16ToWide(keyword_term_), match.fill_into_edit); } @@ -359,7 +360,7 @@ TEST_F(SearchProviderTest, FinalizeInstantQuery) { EXPECT_FALSE(provider_->done()); // Tell the provider instant is done. - provider_->FinalizeInstantQuery(ASCIIToUTF16("foo"), ASCIIToUTF16("bar")); + provider_->FinalizeInstantQuery(L"foo", L"bar"); // The provider should now be done. EXPECT_TRUE(provider_->done()); @@ -396,7 +397,7 @@ TEST_F(SearchProviderTest, RememberInstantQuery) { QueryForInput(ASCIIToUTF16("foo"), false); // Finalize the instant query immediately. - provider_->FinalizeInstantQuery(ASCIIToUTF16("foo"), ASCIIToUTF16("bar")); + provider_->FinalizeInstantQuery(L"foo", L"bar"); // There should be two matches, one for what you typed, the other for // 'foobar'. diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index 987eee2..2a32d3b 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -1019,7 +1019,7 @@ void TestingAutomationProvider::GetFullscreenBubbleVisibility(int handle, void TestingAutomationProvider::GetAutocompleteEditText( int autocomplete_edit_handle, bool* success, - string16* text) { + std::wstring* text) { *success = false; if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) { *text = autocomplete_edit_tracker_->GetResource(autocomplete_edit_handle)-> @@ -1030,7 +1030,7 @@ void TestingAutomationProvider::GetAutocompleteEditText( void TestingAutomationProvider::SetAutocompleteEditText( int autocomplete_edit_handle, - const string16& text, + const std::wstring& text, bool* success) { *success = false; if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) { @@ -1125,16 +1125,16 @@ void TestingAutomationProvider::ExecuteJavascript( // This routing id needs to be remembered for the reverse // communication while sending back the response of // this javascript execution. - std::string set_automation_id; + std::wstring set_automation_id; base::SStringPrintf(&set_automation_id, - "window.domAutomationController.setAutomationId(%d);", + L"window.domAutomationController.setAutomationId(%d);", reply_message->routing_id()); DCHECK(reply_message_ == NULL); reply_message_ = reply_message; tab_contents->render_view_host()->ExecuteJavascriptInWebFrame( - frame_xpath, UTF8ToWide(set_automation_id)); + frame_xpath, set_automation_id); tab_contents->render_view_host()->ExecuteJavascriptInWebFrame( frame_xpath, script); } @@ -2852,8 +2852,8 @@ void TestingAutomationProvider::GetOmniboxInfo(Browser* browser, item->SetString("type", AutocompleteMatch::TypeToString(match.type)); item->SetBoolean("starred", match.starred); item->SetString("destination_url", match.destination_url.spec()); - item->SetString("contents", match.contents); - item->SetString("description", match.description); + item->SetString("contents", WideToUTF16Hack(match.contents)); + item->SetString("description", WideToUTF16Hack(match.description)); matches->Append(item); } return_value->Set("matches", matches); @@ -2862,8 +2862,8 @@ void TestingAutomationProvider::GetOmniboxInfo(Browser* browser, DictionaryValue* properties = new DictionaryValue; // owned by return_value properties->SetBoolean("has_focus", model->has_focus()); properties->SetBoolean("query_in_progress", model->query_in_progress()); - properties->SetString("keyword", model->keyword()); - properties->SetString("text", edit_view->GetText()); + properties->SetString("keyword", WideToUTF16Hack(model->keyword())); + properties->SetString("text", WideToUTF16Hack(edit_view->GetText())); return_value->Set("properties", properties); AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); @@ -2884,7 +2884,7 @@ void TestingAutomationProvider::SetOmniboxText(Browser* browser, LocationBar* loc_bar = browser->window()->GetLocationBar(); AutocompleteEditView* edit_view = loc_bar->location_entry(); edit_view->model()->OnSetFocus(false); - edit_view->SetUserText(text); + edit_view->SetUserText(UTF16ToWideHack(text)); reply.SendSuccess(NULL); } @@ -4045,7 +4045,7 @@ ListValue* TestingAutomationProvider::GetListFromAutoFillProfiles( const std::vector<AutoFillProfile*>& autofill_profiles) { ListValue* profiles = new ListValue; - std::map<AutoFillFieldType, std::string> autofill_type_to_string + std::map<AutoFillFieldType, std::wstring> autofill_type_to_string = GetAutoFillFieldToStringMap(); // For each AutoFillProfile, transform it to a dictionary object to return. @@ -4055,12 +4055,12 @@ ListValue* TestingAutomationProvider::GetListFromAutoFillProfiles( AutoFillProfile* profile = *it; DictionaryValue* profile_info = new DictionaryValue; // For each of the types, if it has a value, add it to the dictionary. - for (std::map<AutoFillFieldType, std::string>::iterator + for (std::map<AutoFillFieldType, std::wstring>::iterator type_it = autofill_type_to_string.begin(); type_it != autofill_type_to_string.end(); ++type_it) { string16 value = profile->GetFieldText(AutoFillType(type_it->first)); if (value.length()) { // If there was something stored for that value. - profile_info->SetString(type_it->second, value); + profile_info->SetString(WideToUTF8(type_it->second), value); } } profiles->Append(profile_info); @@ -4073,7 +4073,7 @@ ListValue* TestingAutomationProvider::GetListFromCreditCards( const std::vector<CreditCard*>& credit_cards) { ListValue* cards = new ListValue; - std::map<AutoFillFieldType, std::string> credit_card_type_to_string = + std::map<AutoFillFieldType, std::wstring> credit_card_type_to_string = GetCreditCardFieldToStringMap(); // For each AutoFillProfile, transform it to a dictionary object to return. @@ -4083,13 +4083,13 @@ ListValue* TestingAutomationProvider::GetListFromCreditCards( CreditCard* card = *it; DictionaryValue* card_info = new DictionaryValue; // For each of the types, if it has a value, add it to the dictionary. - for (std::map<AutoFillFieldType, std::string>::iterator type_it = + for (std::map<AutoFillFieldType, std::wstring>::iterator type_it = credit_card_type_to_string.begin(); type_it != credit_card_type_to_string.end(); ++type_it) { string16 value = card->GetFieldText(AutoFillType(type_it->first)); // If there was something stored for that value. if (value.length()) { - card_info->SetString(type_it->second, value); + card_info->SetString(WideToUTF8(type_it->second), value); } } cards->Append(card_info); @@ -4105,7 +4105,7 @@ TestingAutomationProvider::GetAutoFillProfilesFromList( DictionaryValue* profile_info = NULL; string16 current_value; - std::map<AutoFillFieldType, std::string> autofill_type_to_string = + std::map<AutoFillFieldType, std::wstring> autofill_type_to_string = GetAutoFillFieldToStringMap(); int num_profiles = profiles.GetSize(); @@ -4113,11 +4113,11 @@ TestingAutomationProvider::GetAutoFillProfilesFromList( profiles.GetDictionary(i, &profile_info); AutoFillProfile profile; // Loop through the possible profile types and add those provided. - for (std::map<AutoFillFieldType, std::string>::iterator type_it = + for (std::map<AutoFillFieldType, std::wstring>::iterator type_it = autofill_type_to_string.begin(); type_it != autofill_type_to_string.end(); ++type_it) { - if (profile_info->HasKey(type_it->second)) { - if (profile_info->GetString(type_it->second, + if (profile_info->HasKey(WideToUTF8(type_it->second))) { + if (profile_info->GetString(WideToUTF8(type_it->second), ¤t_value)) { profile.SetInfo(AutoFillType(type_it->first), current_value); } else { @@ -4138,7 +4138,7 @@ std::vector<CreditCard> TestingAutomationProvider::GetCreditCardsFromList( DictionaryValue* card_info = NULL; string16 current_value; - std::map<AutoFillFieldType, std::string> credit_card_type_to_string = + std::map<AutoFillFieldType, std::wstring> credit_card_type_to_string = GetCreditCardFieldToStringMap(); int num_credit_cards = cards.GetSize(); @@ -4146,11 +4146,11 @@ std::vector<CreditCard> TestingAutomationProvider::GetCreditCardsFromList( cards.GetDictionary(i, &card_info); CreditCard card; // Loop through the possible credit card fields and add those provided. - for (std::map<AutoFillFieldType, std::string>::iterator type_it = + for (std::map<AutoFillFieldType, std::wstring>::iterator type_it = credit_card_type_to_string.begin(); type_it != credit_card_type_to_string.end(); ++type_it) { - if (card_info->HasKey(type_it->second)) { - if (card_info->GetString(type_it->second, ¤t_value)) { + if (card_info->HasKey(WideToUTF8(type_it->second))) { + if (card_info->GetString(WideToUTF8(type_it->second), ¤t_value)) { card.SetInfo(AutoFillType(type_it->first), current_value); } else { *error_message= "All values must be strings"; @@ -4164,36 +4164,36 @@ std::vector<CreditCard> TestingAutomationProvider::GetCreditCardsFromList( } /* static */ -std::map<AutoFillFieldType, std::string> +std::map<AutoFillFieldType, std::wstring> TestingAutomationProvider::GetAutoFillFieldToStringMap() { - std::map<AutoFillFieldType, std::string> autofill_type_to_string; - autofill_type_to_string[NAME_FIRST] = "NAME_FIRST"; - autofill_type_to_string[NAME_MIDDLE] = "NAME_MIDDLE"; - autofill_type_to_string[NAME_LAST] = "NAME_LAST"; - autofill_type_to_string[COMPANY_NAME] = "COMPANY_NAME"; - autofill_type_to_string[EMAIL_ADDRESS] = "EMAIL_ADDRESS"; - autofill_type_to_string[ADDRESS_HOME_LINE1] = "ADDRESS_HOME_LINE1"; - autofill_type_to_string[ADDRESS_HOME_LINE2] = "ADDRESS_HOME_LINE2"; - autofill_type_to_string[ADDRESS_HOME_CITY] = "ADDRESS_HOME_CITY"; - autofill_type_to_string[ADDRESS_HOME_STATE] = "ADDRESS_HOME_STATE"; - autofill_type_to_string[ADDRESS_HOME_ZIP] = "ADDRESS_HOME_ZIP"; - autofill_type_to_string[ADDRESS_HOME_COUNTRY] = "ADDRESS_HOME_COUNTRY"; + std::map<AutoFillFieldType, std::wstring> autofill_type_to_string; + autofill_type_to_string[NAME_FIRST] = L"NAME_FIRST"; + autofill_type_to_string[NAME_MIDDLE] = L"NAME_MIDDLE"; + autofill_type_to_string[NAME_LAST] = L"NAME_LAST"; + autofill_type_to_string[COMPANY_NAME] = L"COMPANY_NAME"; + autofill_type_to_string[EMAIL_ADDRESS] = L"EMAIL_ADDRESS"; + autofill_type_to_string[ADDRESS_HOME_LINE1] = L"ADDRESS_HOME_LINE1"; + autofill_type_to_string[ADDRESS_HOME_LINE2] = L"ADDRESS_HOME_LINE2"; + autofill_type_to_string[ADDRESS_HOME_CITY] = L"ADDRESS_HOME_CITY"; + autofill_type_to_string[ADDRESS_HOME_STATE] = L"ADDRESS_HOME_STATE"; + autofill_type_to_string[ADDRESS_HOME_ZIP] = L"ADDRESS_HOME_ZIP"; + autofill_type_to_string[ADDRESS_HOME_COUNTRY] = L"ADDRESS_HOME_COUNTRY"; autofill_type_to_string[PHONE_HOME_WHOLE_NUMBER] = - "PHONE_HOME_WHOLE_NUMBER"; - autofill_type_to_string[PHONE_FAX_WHOLE_NUMBER] = "PHONE_FAX_WHOLE_NUMBER"; - autofill_type_to_string[NAME_FIRST] = "NAME_FIRST"; + L"PHONE_HOME_WHOLE_NUMBER"; + autofill_type_to_string[PHONE_FAX_WHOLE_NUMBER] = L"PHONE_FAX_WHOLE_NUMBER"; + autofill_type_to_string[NAME_FIRST] = L"NAME_FIRST"; return autofill_type_to_string; } /* static */ -std::map<AutoFillFieldType, std::string> +std::map<AutoFillFieldType, std::wstring> TestingAutomationProvider::GetCreditCardFieldToStringMap() { - std::map<AutoFillFieldType, std::string> credit_card_type_to_string; - credit_card_type_to_string[CREDIT_CARD_NAME] = "CREDIT_CARD_NAME"; - credit_card_type_to_string[CREDIT_CARD_NUMBER] = "CREDIT_CARD_NUMBER"; - credit_card_type_to_string[CREDIT_CARD_EXP_MONTH] = "CREDIT_CARD_EXP_MONTH"; + std::map<AutoFillFieldType, std::wstring> credit_card_type_to_string; + credit_card_type_to_string[CREDIT_CARD_NAME] = L"CREDIT_CARD_NAME"; + credit_card_type_to_string[CREDIT_CARD_NUMBER] = L"CREDIT_CARD_NUMBER"; + credit_card_type_to_string[CREDIT_CARD_EXP_MONTH] = L"CREDIT_CARD_EXP_MONTH"; credit_card_type_to_string[CREDIT_CARD_EXP_4_DIGIT_YEAR] = - "CREDIT_CARD_EXP_4_DIGIT_YEAR"; + L"CREDIT_CARD_EXP_4_DIGIT_YEAR"; return credit_card_type_to_string; } diff --git a/chrome/browser/automation/testing_automation_provider.h b/chrome/browser/automation/testing_automation_provider.h index 9c8d471c..941c0b4 100644 --- a/chrome/browser/automation/testing_automation_provider.h +++ b/chrome/browser/automation/testing_automation_provider.h @@ -138,11 +138,11 @@ class TestingAutomationProvider : public AutomationProvider, // Retrieves the visible text from the autocomplete edit. void GetAutocompleteEditText(int autocomplete_edit_handle, - bool* success, string16* text); + bool* success, std::wstring* text); // Sets the visible text from the autocomplete edit. void SetAutocompleteEditText(int autocomplete_edit_handle, - const string16& text, + const std::wstring& text, bool* success); // Retrieves if a query to an autocomplete provider is in progress. @@ -689,9 +689,9 @@ class TestingAutomationProvider : public AutomationProvider, // Return the map from the internal data representation to the string value // of auto fill fields and credit card fields. - static std::map<AutoFillFieldType, std::string> + static std::map<AutoFillFieldType, std::wstring> GetAutoFillFieldToStringMap(); - static std::map<AutoFillFieldType, std::string> + static std::map<AutoFillFieldType, std::wstring> GetCreditCardFieldToStringMap(); // Get a list of active HTML5 notifications. diff --git a/chrome/browser/extensions/extension_omnibox_api.cc b/chrome/browser/extensions/extension_omnibox_api.cc index 408fa1f..4981c98 100644 --- a/chrome/browser/extensions/extension_omnibox_api.cc +++ b/chrome/browser/extensions/extension_omnibox_api.cc @@ -261,5 +261,5 @@ void ApplyDefaultSuggestionForExtensionKeyword( } } - match->contents.assign(description); + match->contents.assign(UTF16ToWide(description)); } diff --git a/chrome/browser/extensions/extension_omnibox_apitest.cc b/chrome/browser/extensions/extension_omnibox_apitest.cc index b10f0b6..f2a4ce2 100644 --- a/chrome/browser/extensions/extension_omnibox_apitest.cc +++ b/chrome/browser/extensions/extension_omnibox_apitest.cc @@ -31,16 +31,16 @@ namespace { -string16 AutocompleteResultAsString(const AutocompleteResult& result) { - std::string output(base::StringPrintf("{%lu} ", result.size())); +std::wstring AutocompleteResultAsString(const AutocompleteResult& result) { + std::wstring output(base::StringPrintf(L"{%d} ", result.size())); for (size_t i = 0; i < result.size(); ++i) { AutocompleteMatch match = result.match_at(i); - std::string provider_name = match.provider->name(); - output.append(base::StringPrintf("[\"%s\" by \"%s\"] ", - UTF16ToUTF8(match.contents).c_str(), + std::wstring provider_name(ASCIIToWide(match.provider->name())); + output.append(base::StringPrintf(L"[\"%ls\" by \"%ls\"] ", + match.contents.c_str(), provider_name.c_str())); } - return UTF8ToUTF16(output); + return output; } } // namespace @@ -88,13 +88,13 @@ IN_PROC_BROWSER_TEST_F(OmniboxApiTest, MAYBE_Basic) { // Test that our extension's keyword is suggested to us when we partially type // it. { - autocomplete_controller->Start(ASCIIToUTF16("keywor"), string16(), + autocomplete_controller->Start(L"keywor", std::wstring(), true, false, true, false); WaitForAutocompleteDone(autocomplete_controller); EXPECT_TRUE(autocomplete_controller->done()); EXPECT_EQ(std::wstring(), location_bar->GetInputString()); - EXPECT_EQ(string16(), location_bar->location_entry()->GetText()); + EXPECT_EQ(std::wstring(), location_bar->location_entry()->GetText()); EXPECT_TRUE(location_bar->location_entry()->IsSelectAll()); // First result should be to search for what was typed, second should be to @@ -113,8 +113,8 @@ IN_PROC_BROWSER_TEST_F(OmniboxApiTest, MAYBE_Basic) { // Test that our extension can send suggestions back to us. { - autocomplete_controller->Start(ASCIIToUTF16("keyword suggestio"), - string16(), true, false, true, false); + autocomplete_controller->Start(L"keyword suggestio", std::wstring(), + true, false, true, false); WaitForAutocompleteDone(autocomplete_controller); EXPECT_TRUE(autocomplete_controller->done()); @@ -126,17 +126,13 @@ IN_PROC_BROWSER_TEST_F(OmniboxApiTest, MAYBE_Basic) { ASSERT_EQ(5U, result.size()) << AutocompleteResultAsString(result); ASSERT_TRUE(result.match_at(0).template_url); - EXPECT_EQ(ASCIIToUTF16("keyword suggestio"), - result.match_at(0).fill_into_edit); - EXPECT_EQ(ASCIIToUTF16("keyword suggestion1"), - result.match_at(1).fill_into_edit); - EXPECT_EQ(ASCIIToUTF16("keyword suggestion2"), - result.match_at(2).fill_into_edit); - EXPECT_EQ(ASCIIToUTF16("keyword suggestion3"), - result.match_at(3).fill_into_edit); - - string16 description = - ASCIIToUTF16("Description with style: <match>, [dim], (url till end)"); + EXPECT_EQ(L"keyword suggestio", result.match_at(0).fill_into_edit); + EXPECT_EQ(L"keyword suggestion1", result.match_at(1).fill_into_edit); + EXPECT_EQ(L"keyword suggestion2", result.match_at(2).fill_into_edit); + EXPECT_EQ(L"keyword suggestion3", result.match_at(3).fill_into_edit); + + std::wstring description = + L"Description with style: <match>, [dim], (url till end)"; EXPECT_EQ(description, result.match_at(1).contents); ASSERT_EQ(6u, result.match_at(1).contents_class.size()); @@ -177,7 +173,7 @@ IN_PROC_BROWSER_TEST_F(OmniboxApiTest, MAYBE_Basic) { { ResultCatcher catcher; - autocomplete_controller->Start(ASCIIToUTF16("keyword command"), string16(), + autocomplete_controller->Start(L"keyword command", std::wstring(), true, false, true, false); location_bar->AcceptInput(); EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); diff --git a/chrome/browser/instant/instant_browsertest.cc b/chrome/browser/instant/instant_browsertest.cc index 99f58a9..0f296c5 100644 --- a/chrome/browser/instant/instant_browsertest.cc +++ b/chrome/browser/instant/instant_browsertest.cc @@ -79,7 +79,7 @@ class InstantTest : public InProcessBrowserTest { // Type a character to get instant to trigger. void SetupLocationBar() { FindLocationBar(); - location_bar_->location_entry()->SetUserText(ASCIIToUTF16("a")); + location_bar_->location_entry()->SetUserText(L"a"); } // Waits for preview to be shown. @@ -111,7 +111,7 @@ class InstantTest : public InProcessBrowserTest { void SetLocationBarText(const std::wstring& text) { ASSERT_NO_FATAL_FAILURE(FindLocationBar()); - location_bar_->location_entry()->SetUserText(WideToUTF16Hack(text)); + location_bar_->location_entry()->SetUserText(text); ui_test_utils::WaitForNotification( NotificationType::INSTANT_CONTROLLER_SHOWN); } @@ -413,7 +413,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, NonSearchToSearch) { // Now type in some search text. ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); - location_bar_->location_entry()->SetUserText(ASCIIToUTF16("abc")); + location_bar_->location_entry()->SetUserText(L"abc"); // Wait for the preview to navigate. ASSERT_NO_FATAL_FAILURE(WaitForPreviewToNavigate(false)); @@ -445,7 +445,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, NonSearchToSearch) { // Reset the user text so that the page is told the text changed. We should be // able to nuke this once 66104 is fixed. - location_bar_->location_entry()->SetUserText(ASCIIToUTF16("abcd")); + location_bar_->location_entry()->SetUserText(L"abcd"); // Wait for the renderer to process it. ASSERT_NO_FATAL_FAILURE( @@ -472,7 +472,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, SearchServerDoesntSupportInstant) { ASSERT_TRUE(test_server()->Start()); ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("empty.html")); ASSERT_NO_FATAL_FAILURE(FindLocationBar()); - location_bar_->location_entry()->SetUserText(ASCIIToUTF16("a")); + location_bar_->location_entry()->SetUserText(L"a"); ASSERT_TRUE(browser()->instant()); // Because we typed in a search string we should think we're showing instant // results. @@ -511,7 +511,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, NonSearchToSearchDoesntSupportInstant) { ASSERT_TRUE(rwhv->IsShowing()); // Now type in some search text. - location_bar_->location_entry()->SetUserText(ASCIIToUTF16("a")); + location_bar_->location_entry()->SetUserText(L"a"); // Instant should still be live. ASSERT_TRUE(browser()->instant()->is_displayable()); @@ -561,7 +561,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, HideOn403) { ASSERT_TRUE(test_server()->Start()); GURL url(test_server()->GetURL("files/instant/403.html")); ASSERT_NO_FATAL_FAILURE(FindLocationBar()); - location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec())); + location_bar_->location_entry()->SetUserText(UTF8ToWide(url.spec())); // The preview shouldn't be showing, but it should be loading. ASSERT_TRUE(browser()->instant()->GetPreviewContents()); ASSERT_TRUE(browser()->instant()->is_active()); @@ -576,7 +576,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, HideOn403) { // Try loading another url on the server. Instant shouldn't create a new tab // as the server returned 403. GURL url2(test_server()->GetURL("files/instant/empty.html")); - location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url2.spec())); + location_bar_->location_entry()->SetUserText(UTF8ToWide(url2.spec())); ASSERT_FALSE(browser()->instant()->GetPreviewContents()); ASSERT_TRUE(browser()->instant()->is_active()); ASSERT_FALSE(browser()->instant()->is_displayable()); @@ -648,7 +648,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_TabKey) { // Pressing tab to convert instant suggest into inline autocomplete. ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB)); - ASSERT_EQ(ASCIIToUTF16("abcdef"), location_bar_->location_entry()->GetText()); + ASSERT_EQ(L"abcdef", location_bar_->location_entry()->GetText()); EXPECT_EQ("true 0 0 2 2 a false abcdef false 6 6", GetSearchStateAsString(preview_)); diff --git a/chrome/browser/net/url_fixer_upper.cc b/chrome/browser/net/url_fixer_upper.cc index 07881a4..4c36368 100644 --- a/chrome/browser/net/url_fixer_upper.cc +++ b/chrome/browser/net/url_fixer_upper.cc @@ -72,50 +72,6 @@ void UTF8PartsToWideParts(const std::string& text_utf8, parts->ref = UTF8ComponentToWideComponent(text_utf8, parts_utf8.ref); } -#if defined(WCHAR_T_IS_UTF32) -url_parse::Component UTF8ComponentToUTF16Component( - const std::string& text_utf8, - const url_parse::Component& component_utf8) { - if (component_utf8.len == -1) - return url_parse::Component(); - - std::string before_component_string = - text_utf8.substr(0, component_utf8.begin); - std::string component_string = text_utf8.substr(component_utf8.begin, - component_utf8.len); - string16 before_component_string_16 = UTF8ToUTF16(before_component_string); - string16 component_string_16 = UTF8ToUTF16(component_string); - url_parse::Component component_16(before_component_string_16.length(), - component_string_16.length()); - return component_16; -} - -void UTF8PartsToUTF16Parts(const std::string& text_utf8, - const url_parse::Parsed& parts_utf8, - url_parse::Parsed* parts) { - if (IsStringASCII(text_utf8)) { - *parts = parts_utf8; - return; - } - - parts->scheme = - UTF8ComponentToUTF16Component(text_utf8, parts_utf8.scheme); - parts ->username = - UTF8ComponentToUTF16Component(text_utf8, parts_utf8.username); - parts->password = - UTF8ComponentToUTF16Component(text_utf8, parts_utf8.password); - parts->host = - UTF8ComponentToUTF16Component(text_utf8, parts_utf8.host); - parts->port = - UTF8ComponentToUTF16Component(text_utf8, parts_utf8.port); - parts->path = - UTF8ComponentToUTF16Component(text_utf8, parts_utf8.path); - parts->query = - UTF8ComponentToUTF16Component(text_utf8, parts_utf8.query); - parts->ref = - UTF8ComponentToUTF16Component(text_utf8, parts_utf8.ref); -} -#endif TrimPositions TrimWhitespaceUTF8(const std::string& input, TrimPositions positions, @@ -625,16 +581,6 @@ std::wstring URLFixerUpper::SegmentURL(const std::wstring& text, UTF8PartsToWideParts(text_utf8, parts_utf8, parts); return UTF8ToWide(scheme_utf8); } -#if defined(WCHAR_T_IS_UTF32) -string16 URLFixerUpper::SegmentURL(const string16& text, - url_parse::Parsed* parts) { - std::string text_utf8 = UTF16ToUTF8(text); - url_parse::Parsed parts_utf8; - std::string scheme_utf8 = SegmentURL(text_utf8, &parts_utf8); - UTF8PartsToUTF16Parts(text_utf8, parts_utf8, parts); - return UTF8ToUTF16(scheme_utf8); -} -#endif GURL URLFixerUpper::FixupRelativeFile(const std::wstring& base_dir, const std::wstring& text) { return FixupRelativeFile(FilePath::FromWStringHack(base_dir), diff --git a/chrome/browser/net/url_fixer_upper.h b/chrome/browser/net/url_fixer_upper.h index fa5ba1b..9f5beb5 100644 --- a/chrome/browser/net/url_fixer_upper.h +++ b/chrome/browser/net/url_fixer_upper.h @@ -8,7 +8,6 @@ #include <string> -#include "base/string16.h" #include "googleurl/src/gurl.h" namespace url_parse { @@ -30,11 +29,8 @@ namespace URLFixerUpper { // Returns the canonicalized scheme, or the empty string when |text| is only // whitespace. std::string SegmentURL(const std::string& text, url_parse::Parsed* parts); - // Deprecated temporary compatibility functions. + // Deprecated temporary compatibility function. std::wstring SegmentURL(const std::wstring& text, url_parse::Parsed* parts); -#if defined(WCHAR_T_IS_UTF32) - string16 SegmentURL(const string16& text, url_parse::Parsed* parts); -#endif // Converts |text| to a fixed-up URL and returns it. Attempts to make // some "smart" adjustments to obviously-invalid input where possible. diff --git a/chrome/browser/omnibox_search_hint.cc b/chrome/browser/omnibox_search_hint.cc index 7b19d10..dcd5224 100644 --- a/chrome/browser/omnibox_search_hint.cc +++ b/chrome/browser/omnibox_search_hint.cc @@ -208,8 +208,8 @@ void OmniboxSearchHint::ShowEnteringQuery() { GetLocationBar(); AutocompleteEditView* edit_view = location_bar->location_entry(); location_bar->FocusLocation(true); - edit_view->SetUserText( - l10n_util::GetStringUTF16(IDS_OMNIBOX_SEARCH_HINT_OMNIBOX_TEXT)); + edit_view->SetUserText(UTF16ToWideHack( + l10n_util::GetStringUTF16(IDS_OMNIBOX_SEARCH_HINT_OMNIBOX_TEXT))); edit_view->SelectAll(false); // Entering text in the autocomplete edit view triggers the suggestion popup // that we don't want to show in this case. diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc index 3a343c5..1095f58 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.cc +++ b/chrome/browser/tab_contents/render_view_context_menu.cc @@ -592,7 +592,8 @@ void RenderViewContextMenu::AppendSearchProvider() { AutocompleteMatch match; profile_->GetAutocompleteClassifier()->Classify( - params_.selection_text, string16(), false, &match, NULL); + UTF16ToWideHack(params_.selection_text), + std::wstring(), false, &match, NULL); selection_navigation_url_ = match.destination_url; if (!selection_navigation_url_.is_valid()) return; diff --git a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell_unittest.mm b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell_unittest.mm index 1bc2eee..0b8d2cc 100644 --- a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell_unittest.mm +++ b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell_unittest.mm @@ -102,7 +102,7 @@ TEST_F(AutocompleteTextFieldCellTest, DISABLED_FocusedDisplay) { SelectedKeywordDecoration selected_keyword_decoration([view_ font]); selected_keyword_decoration.SetVisible(true); - selected_keyword_decoration.SetKeyword(ASCIIToUTF16("Google"), false); + selected_keyword_decoration.SetKeyword(std::wstring(L"Google"), false); [cell addLeftDecoration:&selected_keyword_decoration]; EXPECT_NE(selected_keyword_decoration.GetWidthForSpace(kVeryWide), LocationBarDecoration::kOmittedWidth); diff --git a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h index 0f87f44..201b645 100644 --- a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h +++ b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h @@ -132,7 +132,7 @@ class LocationBarViewMac : public AutocompleteEditController, virtual void OnAutocompleteWillClosePopup(); virtual void OnAutocompleteLosingFocus(gfx::NativeView unused); virtual void OnAutocompleteWillAccept(); - virtual bool OnCommitSuggestedText(const string16& typed_text); + virtual bool OnCommitSuggestedText(const std::wstring& typed_text); virtual bool AcceptCurrentInstantPreview(); virtual void OnPopupBoundsChanged(const gfx::Rect& bounds); virtual void OnAutocompleteAccept(const GURL& url, @@ -145,9 +145,9 @@ class LocationBarViewMac : public AutocompleteEditController, virtual void OnKillFocus(); virtual void OnSetFocus(); virtual SkBitmap GetFavIcon() const; - virtual string16 GetTitle() const; + virtual std::wstring GetTitle() const; - NSImage* GetKeywordImage(const string16& keyword); + NSImage* GetKeywordImage(const std::wstring& keyword); AutocompleteTextField* GetAutocompleteTextField() { return field_; } 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 213cc53..f9071ab 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 @@ -248,7 +248,7 @@ void LocationBarViewMac::OnAutocompleteWillAccept() { update_instant_ = false; } -bool LocationBarViewMac::OnCommitSuggestedText(const string16& typed_text) { +bool LocationBarViewMac::OnCommitSuggestedText(const std::wstring& typed_text) { return edit_view_->CommitSuggestText(); } @@ -317,17 +317,17 @@ void LocationBarViewMac::OnChanged() { instant->Update (browser_->GetSelectedTabContentsWrapper(), edit_view_->model()->CurrentMatch(), - edit_view_->GetText(), + WideToUTF16(edit_view_->GetText()), edit_view_->model()->UseVerbatimInstant(), &suggested_text); if (!instant->MightSupportInstant()) { - edit_view_->model()->FinalizeInstantQuery(string16(), - string16()); + edit_view_->model()->FinalizeInstantQuery(std::wstring(), + std::wstring()); } } else { instant->DestroyPreviewContents(); - edit_view_->model()->FinalizeInstantQuery(string16(), - string16()); + edit_view_->model()->FinalizeInstantQuery(std::wstring(), + std::wstring()); } } @@ -357,9 +357,9 @@ SkBitmap LocationBarViewMac::GetFavIcon() const { return SkBitmap(); } -string16 LocationBarViewMac::GetTitle() const { +std::wstring LocationBarViewMac::GetTitle() const { NOTIMPLEMENTED(); - return string16(); + return std::wstring(); } void LocationBarViewMac::Revert() { @@ -520,9 +520,10 @@ NSPoint LocationBarViewMac::GetPageInfoBubblePoint() const { } } -NSImage* LocationBarViewMac::GetKeywordImage(const string16& keyword) { +NSImage* LocationBarViewMac::GetKeywordImage(const std::wstring& keyword) { const TemplateURL* template_url = - profile_->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword); + profile_->GetTemplateURLModel()->GetTemplateURLForKeyword( + WideToUTF16Hack(keyword)); if (template_url && template_url->IsExtensionKeyword()) { const SkBitmap& bitmap = profile_->GetExtensionService()-> GetOmniboxIcon(template_url->GetExtensionId()); @@ -650,12 +651,12 @@ void LocationBarViewMac::Layout() { keyword_hint_decoration_->SetVisible(false); // Get the keyword to use for keyword-search and hinting. - const string16 keyword = edit_view_->model()->keyword(); + const std::wstring keyword(edit_view_->model()->keyword()); string16 short_name; bool is_extension_keyword = false; if (!keyword.empty()) { short_name = profile_->GetTemplateURLModel()-> - GetKeywordShortName(keyword, &is_extension_keyword); + GetKeywordShortName(WideToUTF16Hack(keyword), &is_extension_keyword); } const bool is_keyword_hint = edit_view_->model()->is_keyword_hint(); @@ -664,7 +665,8 @@ void LocationBarViewMac::Layout() { // Switch from location icon to keyword mode. location_icon_decoration_->SetVisible(false); selected_keyword_decoration_->SetVisible(true); - selected_keyword_decoration_->SetKeyword(short_name, is_extension_keyword); + selected_keyword_decoration_->SetKeyword(UTF16ToWideHack(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. diff --git a/chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h b/chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h index f64f354..3c9cf309 100644 --- a/chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h +++ b/chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h @@ -10,7 +10,6 @@ #import <Cocoa/Cocoa.h> -#include "base/string16.h" #include "chrome/browser/ui/cocoa/location_bar/bubble_decoration.h" class SelectedKeywordDecoration : public BubbleDecoration { @@ -19,7 +18,7 @@ class SelectedKeywordDecoration : public BubbleDecoration { // Calculates appropriate full and partial label strings based on // inputs. - void SetKeyword(const string16& keyword, bool is_extension_keyword); + void SetKeyword(const std::wstring& keyword, bool is_extension_keyword); // Determines what combination of labels and image will best fit // within |width|, makes those current for |BubbleDecoration|, and diff --git a/chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.mm b/chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.mm index 7d90eeb..fae0cc4 100644 --- a/chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.mm +++ b/chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.mm @@ -46,23 +46,23 @@ CGFloat SelectedKeywordDecoration::GetWidthForSpace(CGFloat width) { return GetWidthForImageAndLabel(nil, partial_string_); } -void SelectedKeywordDecoration::SetKeyword(const string16& short_name, +void SelectedKeywordDecoration::SetKeyword(const std::wstring& short_name, bool is_extension_keyword) { - const string16 min_name(WideToUTF16Hack( - location_bar_util::CalculateMinString(UTF16ToWideHack(short_name)))); + const std::wstring min_name( + location_bar_util::CalculateMinString(short_name)); const int message_id = is_extension_keyword ? IDS_OMNIBOX_EXTENSION_KEYWORD_TEXT : IDS_OMNIBOX_KEYWORD_TEXT; // The text will be like "Search <name>:". "<name>" is a parameter // derived from |short_name|. full_string_.reset( - [l10n_util::GetNSStringF(message_id, short_name) copy]); + [l10n_util::GetNSStringF(message_id, WideToUTF16(short_name)) copy]); if (min_name.empty()) { partial_string_.reset(); } else { partial_string_.reset( - [l10n_util::GetNSStringF(message_id, min_name) copy]); + [l10n_util::GetNSStringF(message_id, WideToUTF16(min_name)) copy]); } } diff --git a/chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration_unittest.mm b/chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration_unittest.mm index 9112272..5536fda 100644 --- a/chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration_unittest.mm +++ b/chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration_unittest.mm @@ -4,7 +4,6 @@ #import <Cocoa/Cocoa.h> -#include "base/utf_string_conversions.h" #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" #include "testing/gtest/include/gtest/gtest.h" @@ -33,7 +32,7 @@ class SelectedKeywordDecorationTest : public CocoaTest { // not enough room. TEST_F(SelectedKeywordDecorationTest, UsesPartialKeywordIfNarrow) { - const string16 kKeyword = ASCIIToUTF16("Engine"); + const std::wstring kKeyword(L"Engine"); NSString* const kFullString = @"Search Engine:"; NSString* const kPartialString = @"Search En\u2026:"; // ellipses diff --git a/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm b/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm index 3c0775c..e141939 100644 --- a/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm +++ b/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm @@ -1753,7 +1753,8 @@ private: // If the input is plain text, classify the input and make the URL. AutocompleteMatch match; browser_->profile()->GetAutocompleteClassifier()->Classify( - base::SysNSStringToUTF16(text), string16(), false, &match, NULL); + base::SysNSStringToWide(text), + std::wstring(), false, &match, NULL); GURL url(match.destination_url); [self openURL:&url inView:view at:point]; diff --git a/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm b/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm index 3f8f710..7a25aca 100644 --- a/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm +++ b/chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm @@ -787,7 +787,8 @@ class NotificationBridge : public NotificationObserver { // If the input is plain text, classify the input and make the URL. AutocompleteMatch match; browser_->profile()->GetAutocompleteClassifier()->Classify( - base::SysNSStringToUTF16(text), string16(), false, &match, NULL); + base::SysNSStringToWide(text), + std::wstring(), false, &match, NULL); GURL url(match.destination_url); browser_->GetSelectedTabContents()->OpenURL(url, GURL(), CURRENT_TAB, diff --git a/chrome/browser/ui/gtk/gtk_util.cc b/chrome/browser/ui/gtk/gtk_util.cc index 9ba091b..dc86954 100644 --- a/chrome/browser/ui/gtk/gtk_util.cc +++ b/chrome/browser/ui/gtk/gtk_util.cc @@ -965,8 +965,8 @@ bool URLFromPrimarySelection(Profile* profile, GURL* url) { // Use autocomplete to clean up the text, going so far as to turn it into // a search query if necessary. AutocompleteMatch match; - profile->GetAutocompleteClassifier()->Classify(UTF8ToUTF16(selection_text), - string16(), false, &match, NULL); + profile->GetAutocompleteClassifier()->Classify(UTF8ToWide(selection_text), + std::wstring(), false, &match, NULL); g_free(selection_text); if (!match.destination_url.is_valid()) return false; diff --git a/chrome/browser/ui/gtk/location_bar_view_gtk.cc b/chrome/browser/ui/gtk/location_bar_view_gtk.cc index 076b67e..177d422 100644 --- a/chrome/browser/ui/gtk/location_bar_view_gtk.cc +++ b/chrome/browser/ui/gtk/location_bar_view_gtk.cc @@ -459,7 +459,7 @@ void LocationBarViewGtk::OnAutocompleteWillAccept() { } bool LocationBarViewGtk::OnCommitSuggestedText( - const string16& typed_text) { + const std::wstring& typed_text) { return browser_->instant() && location_entry_->CommitInstantSuggestion(); } @@ -513,7 +513,7 @@ void LocationBarViewGtk::OnAutocompleteAccept(const GURL& url, void LocationBarViewGtk::OnChanged() { UpdateSiteTypeArea(); - const string16 keyword(location_entry_->model()->keyword()); + const std::wstring keyword(location_entry_->model()->keyword()); const bool is_keyword_hint = location_entry_->model()->is_keyword_hint(); show_selected_keyword_ = !keyword.empty() && !is_keyword_hint; show_keyword_hint_ = !keyword.empty() && is_keyword_hint; @@ -534,17 +534,17 @@ void LocationBarViewGtk::OnChanged() { instant->Update( browser_->GetSelectedTabContentsWrapper(), location_entry_->model()->CurrentMatch(), - location_entry_->GetText(), + WideToUTF16(location_entry_->GetText()), location_entry_->model()->UseVerbatimInstant(), &suggested_text); if (!instant->MightSupportInstant()) { - location_entry_->model()->FinalizeInstantQuery(string16(), - string16()); + location_entry_->model()->FinalizeInstantQuery(std::wstring(), + std::wstring()); } } else { instant->DestroyPreviewContents(); - location_entry_->model()->FinalizeInstantQuery(string16(), - string16()); + location_entry_->model()->FinalizeInstantQuery(std::wstring(), + std::wstring()); } } @@ -606,8 +606,8 @@ SkBitmap LocationBarViewGtk::GetFavIcon() const { return GetTabContents()->GetFavIcon(); } -string16 LocationBarViewGtk::GetTitle() const { - return GetTabContents()->GetTitle(); +std::wstring LocationBarViewGtk::GetTitle() const { + return UTF16ToWideHack(GetTabContents()->GetTitle()); } void LocationBarViewGtk::ShowFirstRunBubble(FirstRun::BubbleType bubble_type) { @@ -627,7 +627,8 @@ void LocationBarViewGtk::SetSuggestedText(const string16& text) { // text. if (!text.empty()) { location_entry_->model()->FinalizeInstantQuery( - location_entry_->GetText(), text); + location_entry_->GetText(), + UTF16ToWide(text)); } } else { location_entry_->SetInstantSuggestion(text); @@ -970,7 +971,7 @@ void LocationBarViewGtk::UpdateEVCertificateLabelSize() { pango_font_metrics_unref(metrics); } -void LocationBarViewGtk::SetKeywordLabel(const string16& keyword) { +void LocationBarViewGtk::SetKeywordLabel(const std::wstring& keyword) { if (keyword.empty()) return; @@ -980,7 +981,7 @@ void LocationBarViewGtk::SetKeywordLabel(const string16& keyword) { bool is_extension_keyword; const string16 short_name = profile_->GetTemplateURLModel()-> - GetKeywordShortName(keyword, &is_extension_keyword); + GetKeywordShortName(WideToUTF16Hack(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, @@ -999,7 +1000,8 @@ void LocationBarViewGtk::SetKeywordLabel(const string16& keyword) { if (is_extension_keyword) { const TemplateURL* template_url = - profile_->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword); + profile_->GetTemplateURLModel()->GetTemplateURLForKeyword( + WideToUTF16Hack(keyword)); const SkBitmap& bitmap = profile_->GetExtensionService()-> GetOmniboxIcon(template_url->GetExtensionId()); GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&bitmap); @@ -1013,7 +1015,7 @@ void LocationBarViewGtk::SetKeywordLabel(const string16& keyword) { } } -void LocationBarViewGtk::SetKeywordHintLabel(const string16& keyword) { +void LocationBarViewGtk::SetKeywordHintLabel(const std::wstring& keyword) { if (keyword.empty()) return; @@ -1023,7 +1025,7 @@ void LocationBarViewGtk::SetKeywordHintLabel(const string16& keyword) { bool is_extension_keyword; const string16 short_name = profile_->GetTemplateURLModel()-> - GetKeywordShortName(keyword, &is_extension_keyword); + GetKeywordShortName(WideToUTF16Hack(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; @@ -1127,7 +1129,7 @@ void LocationBarViewGtk::OnIconDragBegin(GtkWidget* sender, if (!pixbuf) return; drag_icon_ = bookmark_utils::GetDragRepresentation(pixbuf, - GetTitle(), theme_provider_); + WideToUTF16(GetTitle()), theme_provider_); g_object_unref(pixbuf); gtk_drag_set_icon_widget(context, drag_icon_, 0, 0); } diff --git a/chrome/browser/ui/gtk/location_bar_view_gtk.h b/chrome/browser/ui/gtk/location_bar_view_gtk.h index 374d8fc..0298495 100644 --- a/chrome/browser/ui/gtk/location_bar_view_gtk.h +++ b/chrome/browser/ui/gtk/location_bar_view_gtk.h @@ -95,7 +95,7 @@ class LocationBarViewGtk : public AutocompleteEditController, virtual void OnAutocompleteLosingFocus(gfx::NativeView view_gaining_focus); virtual void OnAutocompleteWillAccept(); // For this implementation, the parameter is ignored. - virtual bool OnCommitSuggestedText(const string16& typed_text); + virtual bool OnCommitSuggestedText(const std::wstring& typed_text); virtual bool AcceptCurrentInstantPreview(); virtual void OnPopupBoundsChanged(const gfx::Rect& bounds); virtual void OnAutocompleteAccept(const GURL& url, @@ -108,7 +108,7 @@ class LocationBarViewGtk : public AutocompleteEditController, virtual void OnSetFocus(); virtual void OnInputInProgress(bool in_progress); virtual SkBitmap GetFavIcon() const; - virtual string16 GetTitle() const; + virtual std::wstring GetTitle() const; // Implement the LocationBar interface. virtual void ShowFirstRunBubble(FirstRun::BubbleType bubble_type); @@ -313,10 +313,10 @@ class LocationBarViewGtk : public AutocompleteEditController, void SetInfoText(); // Set the keyword text for the Search BLAH: keyword box. - void SetKeywordLabel(const string16& keyword); + void SetKeywordLabel(const std::wstring& keyword); // Set the keyword text for the "Press tab to search BLAH" hint box. - void SetKeywordHintLabel(const string16& keyword); + void SetKeywordHintLabel(const std::wstring& keyword); void ShowFirstRunBubbleInternal(FirstRun::BubbleType bubble_type); @@ -423,7 +423,7 @@ class LocationBarViewGtk : public AutocompleteEditController, bool show_keyword_hint_; // The last search keyword that was shown via the |tab_to_search_box_|. - string16 last_keyword_; + std::wstring last_keyword_; // True if we should update the instant controller when the edit text changes. bool update_instant_; diff --git a/chrome/browser/ui/gtk/tabs/tab_strip_gtk.cc b/chrome/browser/ui/gtk/tabs/tab_strip_gtk.cc index cf6d3d4..c79e8c1 100644 --- a/chrome/browser/ui/gtk/tabs/tab_strip_gtk.cc +++ b/chrome/browser/ui/gtk/tabs/tab_strip_gtk.cc @@ -1631,7 +1631,7 @@ bool TabStripGtk::CompleteDrop(guchar* data, bool is_plain_text) { if (is_plain_text) { AutocompleteMatch match; model_->profile()->GetAutocompleteClassifier()->Classify( - UTF8ToUTF16(reinterpret_cast<char*>(data)), string16(), false, + UTF8ToWide(reinterpret_cast<char*>(data)), std::wstring(), false, &match, NULL); url = match.destination_url; } else { diff --git a/chrome/browser/ui/toolbar/toolbar_model.cc b/chrome/browser/ui/toolbar/toolbar_model.cc index b8091a3..98c392a 100644 --- a/chrome/browser/ui/toolbar/toolbar_model.cc +++ b/chrome/browser/ui/toolbar/toolbar_model.cc @@ -53,11 +53,9 @@ std::wstring ToolbarModel::GetText() const { // Note that we can't unescape spaces here, because if the user copies this // and pastes it into another program, that program may think the URL ends at // the space. - return UTF16ToWideHack( - AutocompleteInput::FormattedStringWithEquivalentMeaning( - url, - net::FormatUrl(url, languages, net::kFormatUrlOmitAll, - UnescapeRule::NORMAL, NULL, NULL, NULL))); + return AutocompleteInput::FormattedStringWithEquivalentMeaning(url, + UTF16ToWideHack(net::FormatUrl(url, languages, net::kFormatUrlOmitAll, + UnescapeRule::NORMAL, NULL, NULL, NULL))); } ToolbarModel::SecurityLevel ToolbarModel::GetSecurityLevel() const { diff --git a/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc b/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc index 9068ace..1900df2 100644 --- a/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc +++ b/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc @@ -108,7 +108,7 @@ SkColor GetColor(ResultViewState state, ColorKind kind) { return colors[state][kind]; } -const char16 kEllipsis[] = { 0x2026 }; +const wchar_t kEllipsis[] = L"\x2026"; const SkAlpha kGlassPopupAlpha = 240; const SkAlpha kOpaquePopupAlpha = 255; @@ -293,7 +293,7 @@ class AutocompleteResultView : public views::View { // Precalculated data used to draw the portion of a match classification that // fits entirely within one run. struct ClassificationData { - string16 text; + std::wstring text; const gfx::Font* font; SkColor color; int pixel_width; @@ -327,7 +327,7 @@ class AutocompleteResultView : public views::View { // added to all of the classifications. Returns the x position to the right // of the string. int DrawString(gfx::Canvas* canvas, - const string16& text, + const std::wstring& text, const ACMatchClassifications& classifications, bool force_dim, int x, @@ -422,7 +422,7 @@ AutocompleteResultView::AutocompleteResultView( model_index_(model_index), normal_font_(font), bold_font_(bold_font), - ellipsis_width_(font.GetStringWidth(string16(kEllipsis))), + ellipsis_width_(font.GetStringWidth(WideToUTF16(kEllipsis))), mirroring_context_(new MirroringContext()), match_(NULL, 0, false, AutocompleteMatch::URL_WHAT_YOU_TYPED) { CHECK(model_index >= 0); @@ -458,8 +458,8 @@ void AutocompleteResultView::Paint(gfx::Canvas* canvas) { // would also let us use a more properly-localizable string than we get with // just the IDS_AUTOCOMPLETE_MATCH_DESCRIPTION_SEPARATOR. if (!match_.description.empty()) { - string16 separator = - l10n_util::GetStringUTF16(IDS_AUTOCOMPLETE_MATCH_DESCRIPTION_SEPARATOR); + std::wstring separator = UTF16ToWide(l10n_util::GetStringUTF16( + IDS_AUTOCOMPLETE_MATCH_DESCRIPTION_SEPARATOR)); ACMatchClassifications classifications; classifications.push_back( ACMatchClassification(0, ACMatchClassification::NONE)); @@ -534,7 +534,7 @@ const SkBitmap* AutocompleteResultView::GetIcon() const { int AutocompleteResultView::DrawString( gfx::Canvas* canvas, - const string16& text, + const std::wstring& text, const ACMatchClassifications& classifications, bool force_dim, int x, @@ -558,7 +558,7 @@ int AutocompleteResultView::DrawString( // unintended ways, e.g. by removing directional markings or by adding an // ellipsis that's not enclosed in appropriate markings. base::i18n::BiDiLineIterator bidi_line; - if (!bidi_line.Open(text, base::i18n::IsRTL(), is_url)) + if (!bidi_line.Open(WideToUTF16Hack(text), base::i18n::IsRTL(), is_url)) return x; const int num_runs = bidi_line.CountRuns(); Runs runs; @@ -613,7 +613,8 @@ int AutocompleteResultView::DrawString( else current_data->color = GetColor(state, force_dim ? DIMMED_TEXT : TEXT); current_data->pixel_width = - current_data->font->GetStringWidth(current_data->text); + current_data->font->GetStringWidth( + WideToUTF16Hack(current_data->text)); current_run->pixel_width += current_data->pixel_width; } DCHECK(!current_run->classifications.empty()); @@ -669,7 +670,7 @@ int AutocompleteResultView::DrawString( for (Classifications::const_iterator j(i->classifications.begin()); j != i->classifications.end(); ++j) { int left = mirroring_context_->mirrored_left_coord(x, x + j->pixel_width); - canvas->DrawStringInt(j->text, *j->font, j->color, left, + canvas->DrawStringInt(WideToUTF16Hack(j->text), *j->font, j->color, left, y, j->pixel_width, j->font->GetHeight(), flags); x += j->pixel_width; } @@ -708,8 +709,9 @@ void AutocompleteResultView::Elide(Runs* runs, int remaining_width) const { first_classification = false; // Can we fit at least an ellipsis? - string16 elided_text = - ui::ElideText(j->text, *j->font, remaining_width, false); + std::wstring elided_text(UTF16ToWideHack( + ui::ElideText(WideToUTF16Hack(j->text), *j->font, remaining_width, + false))); Classifications::reverse_iterator prior_classification(j); ++prior_classification; const bool on_first_classification = @@ -738,7 +740,7 @@ void AutocompleteResultView::Elide(Runs* runs, int remaining_width) const { (prior_classification->font == &normal_font_))) j->font = &normal_font_; - j->pixel_width = j->font->GetStringWidth(elided_text); + j->pixel_width = j->font->GetStringWidth(WideToUTF16Hack(elided_text)); // Erase any other classifications that come after the elided one. i->classifications.erase(j.base(), i->classifications.end()); @@ -1150,10 +1152,10 @@ void AutocompletePopupContentsView::OpenIndex( // extension, |match| and its contents. So copy the relevant strings out to // make sure they stay alive until the call completes. const GURL url(match.destination_url); - string16 keyword; + std::wstring keyword; const bool is_keyword_hint = model_->GetKeywordForMatch(match, &keyword); edit_view_->OpenURL(url, disposition, match.transition, GURL(), index, - is_keyword_hint ? string16() : keyword); + is_keyword_hint ? std::wstring() : keyword); } size_t AutocompletePopupContentsView::GetIndexForPoint( diff --git a/chrome/browser/ui/views/frame/browser_root_view.cc b/chrome/browser/ui/views/frame/browser_root_view.cc index 0eb38e3..0350f19 100644 --- a/chrome/browser/ui/views/frame/browser_root_view.cc +++ b/chrome/browser/ui/views/frame/browser_root_view.cc @@ -147,7 +147,7 @@ bool BrowserRootView::GetPasteAndGoURL(const ui::OSExchangeData& data, AutocompleteMatch match; browser_view_->browser()->profile()->GetAutocompleteClassifier()->Classify( - WideToUTF16Hack(text), string16(), false, &match, NULL); + text, std::wstring(), false, &match, NULL); if (!match.destination_url.is_valid()) return false; 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 07ca935..7e4ba37 100644 --- a/chrome/browser/ui/views/location_bar/keyword_hint_view.cc +++ b/chrome/browser/ui/views/location_bar/keyword_hint_view.cc @@ -48,7 +48,7 @@ void KeywordHintView::SetColor(const SkColor& color) { trailing_label_->SetColor(color); } -void KeywordHintView::SetKeyword(const string16& keyword) { +void KeywordHintView::SetKeyword(const std::wstring& keyword) { keyword_ = keyword; if (keyword_.empty()) return; @@ -59,7 +59,7 @@ void KeywordHintView::SetKeyword(const string16& keyword) { std::vector<size_t> content_param_offsets; bool is_extension_keyword; string16 short_name = profile_->GetTemplateURLModel()-> - GetKeywordShortName(keyword, &is_extension_keyword); + GetKeywordShortName(WideToUTF16Hack(keyword), &is_extension_keyword); int message_id = is_extension_keyword ? IDS_OMNIBOX_EXTENSION_KEYWORD_HINT : IDS_OMNIBOX_KEYWORD_HINT; const std::wstring keyword_hint = diff --git a/chrome/browser/ui/views/location_bar/keyword_hint_view.h b/chrome/browser/ui/views/location_bar/keyword_hint_view.h index 0281231..d7b23ec 100644 --- a/chrome/browser/ui/views/location_bar/keyword_hint_view.h +++ b/chrome/browser/ui/views/location_bar/keyword_hint_view.h @@ -36,8 +36,8 @@ class KeywordHintView : public views::View { void SetColor(const SkColor& color); - void SetKeyword(const string16& keyword); - string16 keyword() const { return keyword_; } + void SetKeyword(const std::wstring& keyword); + std::wstring keyword() const { return keyword_; } virtual void Paint(gfx::Canvas* canvas); virtual gfx::Size GetPreferredSize(); @@ -52,7 +52,7 @@ class KeywordHintView : public views::View { views::Label* trailing_label_; // The keyword. - string16 keyword_; + std::wstring keyword_; Profile* profile_; 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 d66b51a..fa6a63f 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.cc +++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc @@ -447,7 +447,7 @@ void LocationBarView::Layout() { int ev_bubble_width = 0; location_icon_view_->SetVisible(false); ev_bubble_view_->SetVisible(false); - const string16 keyword(location_entry_->model()->keyword()); + const std::wstring keyword(location_entry_->model()->keyword()); const bool is_keyword_hint(location_entry_->model()->is_keyword_hint()); const bool show_selected_keyword = !keyword.empty() && !is_keyword_hint; if (show_selected_keyword) { @@ -516,7 +516,8 @@ void LocationBarView::Layout() { if (selected_keyword_view_->keyword() != keyword) { selected_keyword_view_->SetKeyword(keyword); const TemplateURL* template_url = - profile_->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword); + profile_->GetTemplateURLModel()->GetTemplateURLForKeyword( + WideToUTF16Hack(keyword)); if (template_url && template_url->IsExtensionKeyword()) { const SkBitmap& bitmap = profile_->GetExtensionService()-> GetOmniboxIcon(template_url->GetExtensionId()); @@ -768,11 +769,11 @@ void LocationBarView::OnAutocompleteWillAccept() { update_instant_ = false; } -bool LocationBarView::OnCommitSuggestedText(const string16& typed_text) { +bool LocationBarView::OnCommitSuggestedText(const std::wstring& typed_text) { InstantController* instant = delegate_->GetInstant(); if (!instant) return false; - string16 suggestion; + std::wstring suggestion; #if defined(OS_WIN) if (!HasValidSuggestText()) return false; @@ -848,17 +849,17 @@ void LocationBarView::OnChanged() { location_entry_->model()->popup_model()->IsOpen()) { instant->Update(GetTabContentsWrapper(), location_entry_->model()->CurrentMatch(), - location_entry_->GetText(), + WideToUTF16(location_entry_->GetText()), location_entry_->model()->UseVerbatimInstant(), &suggested_text); if (!instant->MightSupportInstant()) { - location_entry_->model()->FinalizeInstantQuery(string16(), - string16()); + location_entry_->model()->FinalizeInstantQuery(std::wstring(), + std::wstring()); } } else { instant->DestroyPreviewContents(); - location_entry_->model()->FinalizeInstantQuery(string16(), - string16()); + location_entry_->model()->FinalizeInstantQuery(std::wstring(), + std::wstring()); } } @@ -894,8 +895,8 @@ SkBitmap LocationBarView::GetFavIcon() const { return GetTabContentsFromDelegate(delegate_)->GetFavIcon(); } -string16 LocationBarView::GetTitle() const { - return GetTabContentsFromDelegate(delegate_)->GetTitle(); +std::wstring LocationBarView::GetTitle() const { + return UTF16ToWideHack(GetTabContentsFromDelegate(delegate_)->GetTitle()); } int LocationBarView::AvailableWidth(int location_bar_width) { @@ -1129,7 +1130,7 @@ void LocationBarView::SetSuggestedText(const string16& input) { // text. if (!input.empty()) { location_entry_->model()->FinalizeInstantQuery(location_entry_->GetText(), - input); + UTF16ToWide(input)); } return; } diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.h b/chrome/browser/ui/views/location_bar/location_bar_view.h index f96e463..f36c5c8 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.h +++ b/chrome/browser/ui/views/location_bar/location_bar_view.h @@ -195,7 +195,7 @@ class LocationBarView : public LocationBar, virtual void OnAutocompleteWillClosePopup(); virtual void OnAutocompleteLosingFocus(gfx::NativeView view_gaining_focus); virtual void OnAutocompleteWillAccept(); - virtual bool OnCommitSuggestedText(const string16& typed_text); + virtual bool OnCommitSuggestedText(const std::wstring& typed_text); virtual bool AcceptCurrentInstantPreview(); virtual void OnPopupBoundsChanged(const gfx::Rect& bounds); virtual void OnAutocompleteAccept(const GURL& url, @@ -208,7 +208,7 @@ class LocationBarView : public LocationBar, virtual void OnKillFocus(); virtual void OnSetFocus(); virtual SkBitmap GetFavIcon() const; - virtual string16 GetTitle() const; + virtual std::wstring GetTitle() const; // Overridden from views::View: virtual std::string GetClassName() const; 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 6af5000..6f4b637 100644 --- a/chrome/browser/ui/views/location_bar/selected_keyword_view.cc +++ b/chrome/browser/ui/views/location_bar/selected_keyword_view.cc @@ -50,7 +50,7 @@ void SelectedKeywordView::Layout() { IconLabelBubbleView::Layout(); } -void SelectedKeywordView::SetKeyword(const string16& keyword) { +void SelectedKeywordView::SetKeyword(const std::wstring& keyword) { keyword_ = keyword; if (keyword.empty()) return; @@ -60,7 +60,7 @@ void SelectedKeywordView::SetKeyword(const string16& keyword) { bool is_extension_keyword; const string16 short_name = profile_->GetTemplateURLModel()-> - GetKeywordShortName(keyword, &is_extension_keyword); + GetKeywordShortName(WideToUTF16Hack(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/ui/views/location_bar/selected_keyword_view.h b/chrome/browser/ui/views/location_bar/selected_keyword_view.h index 2e0c530..a3f8266 100644 --- a/chrome/browser/ui/views/location_bar/selected_keyword_view.h +++ b/chrome/browser/ui/views/location_bar/selected_keyword_view.h @@ -33,8 +33,8 @@ class SelectedKeywordView : public IconLabelBubbleView { virtual void Layout(); // The current keyword, or an empty string if no keyword is displayed. - void SetKeyword(const string16& keyword); - string16 keyword() const { return keyword_; } + void SetKeyword(const std::wstring& keyword); + std::wstring keyword() const { return keyword_; } void set_profile(Profile* profile) { profile_ = profile; } @@ -42,7 +42,7 @@ class SelectedKeywordView : public IconLabelBubbleView { // The keyword we're showing. If empty, no keyword is selected. // NOTE: we don't cache the TemplateURL as it is possible for it to get // deleted out from under us. - string16 keyword_; + std::wstring keyword_; // These labels are never visible. They are used to size the view. One // label contains the complete description of the keyword, the second diff --git a/chrome/common/automation_messages_internal.h b/chrome/common/automation_messages_internal.h index 87359f5..2b2765b 100644 --- a/chrome/common/automation_messages_internal.h +++ b/chrome/common/automation_messages_internal.h @@ -653,7 +653,7 @@ IPC_SYNC_MESSAGE_CONTROL4_1(AutomationMsg_SavePage, IPC_SYNC_MESSAGE_CONTROL1_2(AutomationMsg_AutocompleteEditGetText, int /* autocomplete edit handle */, bool /* the requested autocomplete edit exists */, - string16 /* omnibox text */) + std::wstring /* omnibox text */) // This message sets the text being displayed in the AutocompleteEdit. The // first parameter is the handle to the omnibox and the second parameter is @@ -662,7 +662,7 @@ IPC_SYNC_MESSAGE_CONTROL1_2(AutomationMsg_AutocompleteEditGetText, // completed. IPC_SYNC_MESSAGE_CONTROL2_1(AutomationMsg_AutocompleteEditSetText, int /* autocomplete edit handle */, - string16 /* text to set */, + std::wstring /* text to set */, bool /* the requested autocomplete edit exists */) // This message requests if a query to a autocomplete provider is still in diff --git a/chrome/test/automation/autocomplete_edit_proxy.cc b/chrome/test/automation/autocomplete_edit_proxy.cc index fc5871a..fd8061b 100644 --- a/chrome/test/automation/autocomplete_edit_proxy.cc +++ b/chrome/test/automation/autocomplete_edit_proxy.cc @@ -14,7 +14,7 @@ using base::TimeDelta; using base::TimeTicks; -bool AutocompleteEditProxy::GetText(string16* text) const { +bool AutocompleteEditProxy::GetText(std::wstring* text) const { if (!is_valid()) return false; if (!text) { @@ -36,7 +36,7 @@ bool AutocompleteEditProxy::WaitForFocus() const { return edit_exists; } -bool AutocompleteEditProxy::SetText(const string16& text) { +bool AutocompleteEditProxy::SetText(const std::wstring& text) { if (!is_valid()) return false; bool result = false; diff --git a/chrome/test/automation/autocomplete_edit_proxy.h b/chrome/test/automation/autocomplete_edit_proxy.h index 73dc673..e33824a 100644 --- a/chrome/test/automation/autocomplete_edit_proxy.h +++ b/chrome/test/automation/autocomplete_edit_proxy.h @@ -48,11 +48,11 @@ struct AutocompleteMatchData { std::string provider_name; int relevance; bool deletable; - string16 fill_into_edit; + std::wstring fill_into_edit; size_t inline_autocomplete_offset; GURL destination_url; - string16 contents; - string16 description; + std::wstring contents; + std::wstring description; bool is_history_what_you_typed_match; std::string type; bool starred; @@ -68,11 +68,11 @@ struct ParamTraits<AutocompleteMatchData> { m->WriteString(p.provider_name); m->WriteInt(p.relevance); m->WriteBool(p.deletable); - m->WriteString16(p.fill_into_edit); + m->WriteWString(p.fill_into_edit); m->WriteSize(p.inline_autocomplete_offset); m->WriteString(p.destination_url.possibly_invalid_spec()); - m->WriteString16(p.contents); - m->WriteString16(p.description); + m->WriteWString(p.contents); + m->WriteWString(p.description); m->WriteBool(p.is_history_what_you_typed_match); m->WriteString(p.type); m->WriteBool(p.starred); @@ -83,11 +83,11 @@ struct ParamTraits<AutocompleteMatchData> { if (!m->ReadString(iter, &r->provider_name) || !m->ReadInt(iter, &r->relevance) || !m->ReadBool(iter, &r->deletable) || - !m->ReadString16(iter, &r->fill_into_edit) || + !m->ReadWString(iter, &r->fill_into_edit) || !m->ReadSize(iter, &r->inline_autocomplete_offset) || !m->ReadString(iter, &destination_url) || - !m->ReadString16(iter, &r->contents) || - !m->ReadString16(iter, &r->description) || + !m->ReadWString(iter, &r->contents) || + !m->ReadWString(iter, &r->description) || !m->ReadBool(iter, &r->is_history_what_you_typed_match) || !m->ReadString(iter, &r->type) || !m->ReadBool(iter, &r->starred)) @@ -136,10 +136,10 @@ class AutocompleteEditProxy : public AutomationResourceProxy { // there are no IPC errors. // Gets the text visible in the omnibox. - bool GetText(string16* text) const; + bool GetText(std::wstring* text) const; // Sets the text visible in the omnibox. - bool SetText(const string16& text); + bool SetText(const std::wstring& text); // Determines if a query to an autocomplete provider is still in progress. // NOTE: No autocomplete queries will be made if the omnibox doesn't have diff --git a/chrome/test/automation/automation_proxy_uitest.cc b/chrome/test/automation/automation_proxy_uitest.cc index b465b07..bd9cef0 100644 --- a/chrome/test/automation/automation_proxy_uitest.cc +++ b/chrome/test/automation/automation_proxy_uitest.cc @@ -1384,8 +1384,8 @@ TEST_F(AutomationProxyTest, AutocompleteGetSetText) { browser->GetAutocompleteEdit()); ASSERT_TRUE(edit.get()); EXPECT_TRUE(edit->is_valid()); - const string16 text_to_set = ASCIIToUTF16("Lollerskates"); - string16 actual_text; + const std::wstring text_to_set = L"Lollerskates"; + std::wstring actual_text; EXPECT_TRUE(edit->SetText(text_to_set)); EXPECT_TRUE(edit->GetText(&actual_text)); EXPECT_EQ(text_to_set, actual_text); @@ -1409,9 +1409,9 @@ TEST_F(AutomationProxyTest, AutocompleteParallelProxy) { ASSERT_TRUE(edit2.get()); EXPECT_TRUE(browser2->GetTab(0)->WaitForTabToBeRestored( TestTimeouts::action_max_timeout_ms())); - const string16 text_to_set1 = ASCIIToUTF16("Lollerskates"); - const string16 text_to_set2 = ASCIIToUTF16("Roflcopter"); - string16 actual_text1, actual_text2; + const std::wstring text_to_set1 = L"Lollerskates"; + const std::wstring text_to_set2 = L"Roflcopter"; + std::wstring actual_text1, actual_text2; EXPECT_TRUE(edit1->SetText(text_to_set1)); EXPECT_TRUE(edit2->SetText(text_to_set2)); EXPECT_TRUE(edit1->GetText(&actual_text1)); @@ -1438,7 +1438,7 @@ TEST_F(AutomationProxyVisibleTest, AutocompleteMatchesTest) { EXPECT_TRUE(edit->is_valid()); EXPECT_TRUE(browser->ApplyAccelerator(IDC_FOCUS_LOCATION)); ASSERT_TRUE(edit->WaitForFocus()); - EXPECT_TRUE(edit->SetText(ASCIIToUTF16("Roflcopter"))); + EXPECT_TRUE(edit->SetText(L"Roflcopter")); EXPECT_TRUE(edit->WaitForQuery(TestTimeouts::action_max_timeout_ms())); bool query_in_progress; EXPECT_TRUE(edit->IsQueryInProgress(&query_in_progress)); @@ -1513,8 +1513,7 @@ TEST_F(AutomationProxyTest, FLAKY_AppModalDialogTest) { EXPECT_FALSE(modal_dialog_showing); int result = -1; EXPECT_TRUE(tab->ExecuteAndExtractInt( - std::wstring(), - L"window.domAutomationController.send(result);", &result)); + L"", L"window.domAutomationController.send(result);", &result)); EXPECT_EQ(0, result); // Try again. @@ -1534,8 +1533,7 @@ TEST_F(AutomationProxyTest, FLAKY_AppModalDialogTest) { &button)); EXPECT_FALSE(modal_dialog_showing); EXPECT_TRUE(tab->ExecuteAndExtractInt( - std::wstring(), - L"window.domAutomationController.send(result);", &result)); + L"", L"window.domAutomationController.send(result);", &result)); EXPECT_EQ(1, result); } diff --git a/chrome/test/ui/omnibox_uitest.cc b/chrome/test/ui/omnibox_uitest.cc index f4f24fa..b30f91d 100644 --- a/chrome/test/ui/omnibox_uitest.cc +++ b/chrome/test/ui/omnibox_uitest.cc @@ -52,22 +52,20 @@ class OmniboxTest : public UITest { // http://www.google.com/ is suggested that should be considered a match. // This could probably be accomplished with regex as well. Note that this // method is called even when suggestion isn't a URL. - bool IsMatch(const string16& input_test, const string16& suggestion); + bool IsMatch(const std::wstring& input_test, const std::wstring& suggestion); // Runs a query chain. This sends each proper prefix of the input to the // omnibox and scores the autocompelte results returned. - void RunQueryChain(const string16& input_text); + void RunQueryChain(const std::wstring& input_text); }; -bool OmniboxTest::IsMatch(const string16& input_text, - const string16& suggestion) { +bool OmniboxTest::IsMatch(const std::wstring& input_text, + const std::wstring& suggestion) { // This prefix list comes from the list used in history_url_provider.cc // with the exception of "ftp." and "www.". - string16 prefixes[] = {ASCIIToUTF16(""), ASCIIToUTF16("ftp://"), - ASCIIToUTF16("http://"), ASCIIToUTF16("https://"), ASCIIToUTF16("ftp."), - ASCIIToUTF16("www."), ASCIIToUTF16("ftp://www."), - ASCIIToUTF16("ftp://ftp."), ASCIIToUTF16("http://www."), - ASCIIToUTF16("https://www.")}; - string16 postfixes[] = {ASCIIToUTF16(""), ASCIIToUTF16("/")}; + std::wstring prefixes[] = {L"", L"ftp://", L"http://", L"https://", + L"ftp.", L"www.", L"ftp://www.", L"ftp://ftp.", + L"http://www.", L"https://www."}; + std::wstring postfixes[] = {L"", L"/"}; for (size_t i = 0; i < arraysize(prefixes); ++i) { for (size_t j = 0; j < arraysize(postfixes); ++j) { if (prefixes[i] + input_text + postfixes[j] == suggestion) @@ -77,7 +75,7 @@ bool OmniboxTest::IsMatch(const string16& input_text, return false; } -void OmniboxTest::RunQueryChain(const string16& input_text) { +void OmniboxTest::RunQueryChain(const std::wstring& input_text) { // Get a handle on the omnibox and give it focus. scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); ASSERT_TRUE(browser.get()); @@ -165,7 +163,7 @@ TEST_F(OmniboxTest, Measure) { expected_providers.push_back(provider); reader.Read(); } - RunQueryChain(ASCIIToUTF16(query)); + RunQueryChain(ASCIIToWide(query)); reader.Read(); } reader.Read(); |