Replace std:;wstring with std::string and string16 in locale-name related APIs.
1. Change the locale param to be std::string because they're always ASCII and change call-sites accordingly. 2. Add GetStringFUTF16 to l10n_util. On Windows, they're inline helpers calling the correspondingGetStringF returning wstring while on Mac/Linux, they just return the result of |string16 GetStringF|without converting to wstring. This is part 1 of the fix for issue 8647. Some of newly introduced conversions are temporary and will be removed later (e.g. ASCIIToWide applied to the result of GetApplicationLocale in a few places). Note : this CL will be landed after http://codereview.chromium.org/147038 is landed. BUG=8647 (http://crbug.com/8647) TEST=Pass l10n_util_unittest and other unit tests Review URL: http://codereview.chromium.org/126223 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19183 0039d316-1c4b-4281-b951-d872f2087c98
Esse commit está contido em:
+82
-67
@@ -51,10 +51,10 @@ void GetLanguageAndRegionFromOS(std::string* lang, std::string* region) {
|
||||
}
|
||||
|
||||
// Convert Chrome locale name to ICU locale name
|
||||
std::string ICULocaleName(const std::wstring& locale_string) {
|
||||
std::string ICULocaleName(const std::string& locale_string) {
|
||||
// If not Spanish, just return it.
|
||||
if (locale_string.substr(0, 2) != L"es")
|
||||
return WideToASCII(locale_string);
|
||||
if (locale_string.substr(0, 2) != "es")
|
||||
return locale_string;
|
||||
// Expand es to es-ES.
|
||||
if (LowerCaseEqualsASCII(locale_string, "es"))
|
||||
return "es-ES";
|
||||
@@ -74,7 +74,7 @@ std::string ICULocaleName(const std::wstring& locale_string) {
|
||||
}
|
||||
// Currently, Chrome has only "es" and "es-419", but later we may have
|
||||
// more specific "es-RR".
|
||||
return WideToASCII(locale_string);
|
||||
return locale_string;
|
||||
}
|
||||
|
||||
// Sets the default locale of ICU.
|
||||
@@ -85,7 +85,7 @@ std::string ICULocaleName(const std::wstring& locale_string) {
|
||||
// This is handy in that we don't have to call GetApplicationLocale()
|
||||
// everytime we call locale-dependent ICU APIs as long as we make sure
|
||||
// that this is called before any locale-dependent API is called.
|
||||
UBool SetICUDefaultLocale(const std::wstring& locale_string) {
|
||||
UBool SetICUDefaultLocale(const std::string& locale_string) {
|
||||
Locale locale(ICULocaleName(locale_string).c_str());
|
||||
UErrorCode error_code = U_ZERO_ERROR;
|
||||
Locale::setDefault(locale, error_code);
|
||||
@@ -118,27 +118,24 @@ bool IsDuplicateName(const std::string& locale_name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IsLocaleAvailable(const std::wstring& locale,
|
||||
const std::wstring& locale_path) {
|
||||
std::wstring test_locale = locale;
|
||||
bool IsLocaleAvailable(const std::string& locale,
|
||||
const FilePath& locale_path) {
|
||||
// If locale has any illegal characters in it, we don't want to try to
|
||||
// load it because it may be pointing outside the locale data file directory.
|
||||
file_util::ReplaceIllegalCharacters(&test_locale, ' ');
|
||||
if (test_locale != locale)
|
||||
if (!file_util::IsFilenameLegal(ASCIIToUTF16(locale)))
|
||||
return false;
|
||||
|
||||
if (!l10n_util::IsLocaleSupportedByOS(locale))
|
||||
return false;
|
||||
|
||||
FilePath test_path = FilePath::FromWStringHack(locale_path)
|
||||
.Append(FilePath::FromWStringHack(locale))
|
||||
.ReplaceExtension(kLocaleFileExtension);
|
||||
FilePath test_path = locale_path;
|
||||
test_path.AppendASCII(locale).ReplaceExtension(kLocaleFileExtension);
|
||||
return file_util::PathExists(test_path) && SetICUDefaultLocale(locale);
|
||||
}
|
||||
|
||||
bool CheckAndResolveLocale(const std::wstring& locale,
|
||||
const std::wstring& locale_path,
|
||||
std::wstring* resolved_locale) {
|
||||
bool CheckAndResolveLocale(const std::string& locale,
|
||||
const FilePath& locale_path,
|
||||
std::string* resolved_locale) {
|
||||
if (IsLocaleAvailable(locale, locale_path)) {
|
||||
*resolved_locale = locale;
|
||||
return true;
|
||||
@@ -148,22 +145,22 @@ bool CheckAndResolveLocale(const std::wstring& locale,
|
||||
// does not support but available on Windows. We fall
|
||||
// back to en-US in GetApplicationLocale so that it's a not critical,
|
||||
// but we can do better.
|
||||
std::wstring::size_type hyphen_pos = locale.find(L'-');
|
||||
if (hyphen_pos != std::wstring::npos && hyphen_pos > 0) {
|
||||
std::wstring lang(locale, 0, hyphen_pos);
|
||||
std::wstring region(locale, hyphen_pos + 1);
|
||||
std::wstring tmp_locale(lang);
|
||||
std::string::size_type hyphen_pos = locale.find(L'-');
|
||||
if (hyphen_pos != std::string::npos && hyphen_pos > 0) {
|
||||
std::string lang(locale, 0, hyphen_pos);
|
||||
std::string region(locale, hyphen_pos + 1);
|
||||
std::string tmp_locale(lang);
|
||||
// Map es-RR other than es-ES to es-419 (Chrome's Latin American
|
||||
// Spanish locale).
|
||||
if (LowerCaseEqualsASCII(lang, "es") && !LowerCaseEqualsASCII(region, "es"))
|
||||
tmp_locale.append(L"-419");
|
||||
tmp_locale.append("-419");
|
||||
else if (LowerCaseEqualsASCII(lang, "zh")) {
|
||||
// Map zh-HK and zh-MK to zh-TW. Otherwise, zh-FOO is mapped to zh-CN.
|
||||
if (LowerCaseEqualsASCII(region, "hk") ||
|
||||
LowerCaseEqualsASCII(region, "mk")) {
|
||||
tmp_locale.append(L"-TW");
|
||||
tmp_locale.append("-TW");
|
||||
} else {
|
||||
tmp_locale.append(L"-CN");
|
||||
tmp_locale.append("-CN");
|
||||
}
|
||||
}
|
||||
if (IsLocaleAvailable(tmp_locale, locale_path)) {
|
||||
@@ -176,16 +173,16 @@ bool CheckAndResolveLocale(const std::wstring& locale,
|
||||
// We need to map them to our codes.
|
||||
struct {
|
||||
const char* source;
|
||||
const wchar_t* dest;} alias_map[] = {
|
||||
{"no", L"nb"},
|
||||
{"tl", L"fil"},
|
||||
{"iw", L"he"},
|
||||
{"en", L"en-US"},
|
||||
const char* dest;} alias_map[] = {
|
||||
{"no", "nb"},
|
||||
{"tl", "fil"},
|
||||
{"iw", "he"},
|
||||
{"en", "en-US"},
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(alias_map); ++i) {
|
||||
if (LowerCaseEqualsASCII(locale, alias_map[i].source)) {
|
||||
std::wstring tmp_locale(alias_map[i].dest);
|
||||
std::string tmp_locale(alias_map[i].dest);
|
||||
if (IsLocaleAvailable(tmp_locale, locale_path)) {
|
||||
resolved_locale->swap(tmp_locale);
|
||||
return true;
|
||||
@@ -199,7 +196,7 @@ bool CheckAndResolveLocale(const std::wstring& locale,
|
||||
// Get the locale of the operating system. The return value is of the form
|
||||
// language[-country] (e.g., en-US) where the language is the 2 letter code from
|
||||
// ISO-639.
|
||||
std::wstring GetSystemLocale() {
|
||||
std::string GetSystemLocale() {
|
||||
std::string language, region;
|
||||
GetLanguageAndRegionFromOS(&language, ®ion);
|
||||
std::string ret;
|
||||
@@ -209,7 +206,7 @@ std::wstring GetSystemLocale() {
|
||||
ret.append("-");
|
||||
ret.append(region);
|
||||
}
|
||||
return ASCIIToWide(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -219,79 +216,69 @@ namespace l10n_util {
|
||||
// Represents the locale-specific text direction.
|
||||
static TextDirection g_text_direction = UNKNOWN_DIRECTION;
|
||||
|
||||
std::wstring GetApplicationLocale(const std::wstring& pref_locale) {
|
||||
std::string GetApplicationLocale(const std::wstring& pref_locale) {
|
||||
#if defined(OS_MACOSX)
|
||||
// On the mac, we don't want to test preferences or ICU for the language,
|
||||
// we want to use whatever Cocoa is using when it loaded the main nib file.
|
||||
// It handles all the mapping and fallbacks for us, we just need to ask
|
||||
// Cocoa.
|
||||
// TODO(pinkerton): break this out into a .mm and ask Cocoa.
|
||||
return L"en";
|
||||
return "en";
|
||||
#else
|
||||
FilePath locale_path;
|
||||
PathService::Get(app::DIR_LOCALES, &locale_path);
|
||||
std::wstring resolved_locale;
|
||||
std::string resolved_locale;
|
||||
|
||||
// First, check to see if there's a --lang flag.
|
||||
const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
|
||||
const std::wstring& lang_arg =
|
||||
parsed_command_line.GetSwitchValue(switches::kLang);
|
||||
const std::string& lang_arg = WideToASCII(
|
||||
parsed_command_line.GetSwitchValue(switches::kLang));
|
||||
if (!lang_arg.empty()) {
|
||||
if (CheckAndResolveLocale(lang_arg, locale_path.ToWStringHack(),
|
||||
&resolved_locale))
|
||||
if (CheckAndResolveLocale(lang_arg, locale_path, &resolved_locale))
|
||||
return resolved_locale;
|
||||
}
|
||||
|
||||
// Second, try user prefs.
|
||||
if (!pref_locale.empty()) {
|
||||
if (CheckAndResolveLocale(pref_locale, locale_path.ToWStringHack(),
|
||||
&resolved_locale))
|
||||
if (CheckAndResolveLocale(WideToASCII(pref_locale),
|
||||
locale_path, &resolved_locale))
|
||||
return resolved_locale;
|
||||
}
|
||||
|
||||
// Next, try the system locale.
|
||||
const std::wstring system_locale = GetSystemLocale();
|
||||
if (CheckAndResolveLocale(system_locale, locale_path.ToWStringHack(),
|
||||
&resolved_locale))
|
||||
const std::string system_locale = GetSystemLocale();
|
||||
if (CheckAndResolveLocale(system_locale, locale_path, &resolved_locale))
|
||||
return resolved_locale;
|
||||
|
||||
// Fallback on en-US.
|
||||
const std::wstring fallback_locale(L"en-US");
|
||||
if (IsLocaleAvailable(fallback_locale, locale_path.ToWStringHack()))
|
||||
const std::string fallback_locale("en-US");
|
||||
if (IsLocaleAvailable(fallback_locale, locale_path))
|
||||
return fallback_locale;
|
||||
|
||||
// No locale data file was found; we shouldn't get here.
|
||||
NOTREACHED();
|
||||
|
||||
return std::wstring();
|
||||
return std::string();
|
||||
#endif
|
||||
}
|
||||
|
||||
std::wstring GetLocalName(const std::string& locale_code_str,
|
||||
const std::wstring& app_locale_wstr,
|
||||
bool is_for_ui) {
|
||||
const std::string app_locale = WideToASCII(app_locale_wstr);
|
||||
const char* locale_code = locale_code_str.c_str();
|
||||
string16 GetDisplayNameForLocale(const std::string& locale_code,
|
||||
const std::string& display_locale,
|
||||
bool is_for_ui) {
|
||||
UErrorCode error = U_ZERO_ERROR;
|
||||
const int buffer_size = 1024;
|
||||
|
||||
#if defined(WCHAR_T_IS_UTF32)
|
||||
string16 name_local_utf16;
|
||||
int actual_size = uloc_getDisplayName(locale_code, app_locale.c_str(),
|
||||
WriteInto(&name_local_utf16, buffer_size + 1), buffer_size, &error);
|
||||
std::wstring name_local = UTF16ToWide(name_local_utf16);
|
||||
#else
|
||||
std::wstring name_local;
|
||||
int actual_size = uloc_getDisplayName(locale_code, app_locale.c_str(),
|
||||
WriteInto(&name_local, buffer_size + 1), buffer_size, &error);
|
||||
#endif
|
||||
string16 display_name;
|
||||
int actual_size = uloc_getDisplayName(locale_code.c_str(),
|
||||
display_locale.c_str(),
|
||||
WriteInto(&display_name, buffer_size + 1), buffer_size, &error);
|
||||
DCHECK(U_SUCCESS(error));
|
||||
name_local.resize(actual_size);
|
||||
display_name.resize(actual_size);
|
||||
// Add an RTL mark so parentheses are properly placed.
|
||||
if (is_for_ui && GetTextDirection() == RIGHT_TO_LEFT) {
|
||||
name_local.push_back(static_cast<wchar_t>(kRightToLeftMark));
|
||||
display_name.push_back(static_cast<char16>(kRightToLeftMark));
|
||||
}
|
||||
return name_local;
|
||||
return display_name;
|
||||
}
|
||||
|
||||
std::wstring GetString(int message_id) {
|
||||
@@ -327,6 +314,7 @@ static string16 GetStringF(int message_id,
|
||||
return formatted;
|
||||
}
|
||||
|
||||
#if !defined(WCHAR_T_IS_UTF16)
|
||||
std::wstring GetStringF(int message_id, const std::wstring& a) {
|
||||
return UTF16ToWide(GetStringF(message_id, WideToUTF16(a), string16(),
|
||||
string16(), string16(), NULL));
|
||||
@@ -355,6 +343,7 @@ std::wstring GetStringF(int message_id,
|
||||
return UTF16ToWide(GetStringF(message_id, WideToUTF16(a), WideToUTF16(b),
|
||||
WideToUTF16(c), WideToUTF16(d), NULL));
|
||||
}
|
||||
#endif
|
||||
|
||||
std::string GetStringFUTF8(int message_id,
|
||||
const string16& a) {
|
||||
@@ -384,6 +373,32 @@ std::string GetStringFUTF8(int message_id,
|
||||
return UTF16ToUTF8(GetStringF(message_id, a, b, c, d, NULL));
|
||||
}
|
||||
|
||||
string16 GetStringFUTF16(int message_id,
|
||||
const string16& a) {
|
||||
return GetStringF(message_id, a, string16(), string16(), string16(), NULL);
|
||||
}
|
||||
|
||||
string16 GetStringFUTF16(int message_id,
|
||||
const string16& a,
|
||||
const string16& b) {
|
||||
return GetStringF(message_id, a, b, string16(), string16(), NULL);
|
||||
}
|
||||
|
||||
string16 GetStringFUTF16(int message_id,
|
||||
const string16& a,
|
||||
const string16& b,
|
||||
const string16& c) {
|
||||
return GetStringF(message_id, a, b, c, string16(), NULL);
|
||||
}
|
||||
|
||||
string16 GetStringFUTF16(int message_id,
|
||||
const string16& a,
|
||||
const string16& b,
|
||||
const string16& c,
|
||||
const string16& d) {
|
||||
return GetStringF(message_id, a, b, c, d, NULL);
|
||||
}
|
||||
|
||||
std::wstring GetStringF(int message_id, const std::wstring& a, size_t* offset) {
|
||||
DCHECK(offset);
|
||||
std::vector<size_t> offsets;
|
||||
@@ -678,7 +693,7 @@ bool StringComparator<std::wstring>::operator()(const std::wstring& lhs,
|
||||
return CompareStringWithCollator(collator_, lhs, rhs) == UCOL_LESS;
|
||||
};
|
||||
|
||||
void SortStrings(const std::wstring& locale,
|
||||
void SortStrings(const std::string& locale,
|
||||
std::vector<std::wstring>* strings) {
|
||||
SortVectorWithStringKey(locale, strings, false);
|
||||
}
|
||||
@@ -692,7 +707,7 @@ const std::vector<std::string>& GetAvailableLocales() {
|
||||
// Filter out the names that have aliases.
|
||||
if (IsDuplicateName(locale_name))
|
||||
continue;
|
||||
if (!IsLocaleSupportedByOS(ASCIIToWide(locale_name)))
|
||||
if (!IsLocaleSupportedByOS(locale_name))
|
||||
continue;
|
||||
// Normalize underscores to hyphens because that's what our locale files
|
||||
// use.
|
||||
|
||||
+55
-14
@@ -46,23 +46,25 @@ const char16 kPopDirectionalFormatting = 0x202C;
|
||||
// as |pref_locale|), finally, we fall back on the system locale. We only return
|
||||
// a value if there's a corresponding resource DLL for the locale. Otherwise,
|
||||
// we fall back to en-us.
|
||||
std::wstring GetApplicationLocale(const std::wstring& pref_locale);
|
||||
std::string GetApplicationLocale(const std::wstring& pref_locale);
|
||||
|
||||
// Given a locale code, return true if the OS is capable of supporting it.
|
||||
// For instance, Oriya is not well supported on Windows XP and we return
|
||||
// false for "or".
|
||||
bool IsLocaleSupportedByOS(const std::wstring& locale);
|
||||
bool IsLocaleSupportedByOS(const std::string& locale);
|
||||
|
||||
// This method returns the Local Name of the Locale Code. For example, for
|
||||
// |local_code_wstr| = "en-US", it returns "English (United States)".
|
||||
// |app_locale_wstr| can be obtained in the UI thread - for example:
|
||||
// const std::wstring app_locale_wstr = g_browser_process->
|
||||
// GetApplicationLocale();
|
||||
// This method returns the display name of the locale code in |display_locale|.
|
||||
|
||||
// For example, for |locale_code| = "en-US" and |display_locale| = "en",
|
||||
// it returns "English (United States)". To get the display name of
|
||||
// |locale_code| in the UI language of Chrome, |display_locale| can be
|
||||
// set to the return value of g_browser_process->GetApplicationLocale()
|
||||
// in the UI thread.
|
||||
// If |is_for_ui| is true, U+200F is appended so that it can be
|
||||
// rendered properly in a RTL Chrome.
|
||||
std::wstring GetLocalName(const std::string& locale_code_str,
|
||||
const std::wstring& app_locale_wstr,
|
||||
bool is_for_ui);
|
||||
string16 GetDisplayNameForLocale(const std::string& locale_code,
|
||||
const std::string& display_locale,
|
||||
bool is_for_ui);
|
||||
|
||||
// Pulls resource string from the string bundle and returns it.
|
||||
std::wstring GetString(int message_id);
|
||||
@@ -71,6 +73,44 @@ string16 GetStringUTF16(int message_id);
|
||||
|
||||
// Get a resource string and replace $1-$2-$3 with |a| and |b|
|
||||
// respectively. Additionally, $$ is replaced by $.
|
||||
string16 GetStringFUTF16(int message_id,
|
||||
const string16& a);
|
||||
string16 GetStringFUTF16(int message_id,
|
||||
const string16& a,
|
||||
const string16& b);
|
||||
string16 GetStringFUTF16(int message_id,
|
||||
const string16& a,
|
||||
const string16& b,
|
||||
const string16& c);
|
||||
string16 GetStringFUTF16(int message_id,
|
||||
const string16& a,
|
||||
const string16& b,
|
||||
const string16& c,
|
||||
const string16& d);
|
||||
#if defined(WCHAR_T_IS_UTF16)
|
||||
inline std::wstring GetStringF(int message_id,
|
||||
const std::wstring& a) {
|
||||
return GetStringFUTF16(message_id, a);
|
||||
}
|
||||
inline std::wstring GetStringF(int message_id,
|
||||
const std::wstring& a,
|
||||
const std::wstring& b) {
|
||||
return GetStringFUTF16(message_id, a, b);
|
||||
}
|
||||
inline std::wstring GetStringF(int message_id,
|
||||
const std::wstring& a,
|
||||
const std::wstring& b,
|
||||
const std::wstring& c) {
|
||||
return GetStringFUTF16(message_id, a, b, c);
|
||||
}
|
||||
inline std::wstring GetStringF(int message_id,
|
||||
const std::wstring& a,
|
||||
const std::wstring& b,
|
||||
const std::wstring& c,
|
||||
const std::wstring& d) {
|
||||
return GetStringFUTF16(message_id, a, b, c, d);
|
||||
}
|
||||
#else
|
||||
std::wstring GetStringF(int message_id,
|
||||
const std::wstring& a);
|
||||
std::wstring GetStringF(int message_id,
|
||||
@@ -85,6 +125,7 @@ std::wstring GetStringF(int message_id,
|
||||
const std::wstring& b,
|
||||
const std::wstring& c,
|
||||
const std::wstring& d);
|
||||
#endif
|
||||
std::string GetStringFUTF8(int message_id,
|
||||
const string16& a);
|
||||
std::string GetStringFUTF8(int message_id,
|
||||
@@ -314,7 +355,7 @@ bool StringComparator<std::wstring>::operator()(const std::wstring& lhs,
|
||||
// want to be sorted. |end_index| points to the end position of elements in the
|
||||
// vector which want to be sorted
|
||||
template <class Element>
|
||||
void SortVectorWithStringKey(const std::wstring& locale,
|
||||
void SortVectorWithStringKey(const std::string& locale,
|
||||
std::vector<Element>* elements,
|
||||
unsigned int begin_index,
|
||||
unsigned int end_index,
|
||||
@@ -322,7 +363,7 @@ void SortVectorWithStringKey(const std::wstring& locale,
|
||||
DCHECK(begin_index >= 0 && begin_index < end_index &&
|
||||
end_index <= static_cast<unsigned int>(elements->size()));
|
||||
UErrorCode error = U_ZERO_ERROR;
|
||||
Locale loc(WideToASCII(locale).c_str());
|
||||
Locale loc(locale.c_str());
|
||||
scoped_ptr<Collator> collator(Collator::createInstance(loc, error));
|
||||
if (U_FAILURE(error))
|
||||
collator.reset();
|
||||
@@ -337,7 +378,7 @@ void SortVectorWithStringKey(const std::wstring& locale,
|
||||
}
|
||||
|
||||
template <class Element>
|
||||
void SortVectorWithStringKey(const std::wstring& locale,
|
||||
void SortVectorWithStringKey(const std::string& locale,
|
||||
std::vector<Element>* elements,
|
||||
bool needs_stable_sort) {
|
||||
SortVectorWithStringKey<Element>(locale, elements, 0, elements->size(),
|
||||
@@ -346,7 +387,7 @@ void SortVectorWithStringKey(const std::wstring& locale,
|
||||
|
||||
// In place sorting of strings using collation rules for |locale|.
|
||||
// TODO(port): this should take string16.
|
||||
void SortStrings(const std::wstring& locale,
|
||||
void SortStrings(const std::string& locale,
|
||||
std::vector<std::wstring>* strings);
|
||||
|
||||
// Returns a vector of available locale codes. E.g., a vector containing
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace l10n_util {
|
||||
|
||||
// Return true blindly for now.
|
||||
bool IsLocaleSupportedByOS(const std::wstring& locale) {
|
||||
bool IsLocaleSupportedByOS(const std::string& locale) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+46
-46
@@ -84,8 +84,8 @@ TEST_F(L10nUtilTest, TruncateString) {
|
||||
EXPECT_EQ(L"\x2026", l10n_util::TruncateString(L" ", 2));
|
||||
}
|
||||
|
||||
void SetICUDefaultLocale(const std::wstring& locale_string) {
|
||||
Locale locale(WideToASCII(locale_string).c_str());
|
||||
void SetICUDefaultLocale(const std::string& locale_string) {
|
||||
Locale locale(locale_string.c_str());
|
||||
UErrorCode error_code = U_ZERO_ERROR;
|
||||
Locale::setDefault(locale, error_code);
|
||||
EXPECT_TRUE(U_SUCCESS(error_code));
|
||||
@@ -136,71 +136,71 @@ TEST_F(L10nUtilTest, GetAppLocale) {
|
||||
// Keep a copy of ICU's default locale before we overwrite it.
|
||||
Locale locale = Locale::getDefault();
|
||||
|
||||
SetICUDefaultLocale(L"en-US");
|
||||
EXPECT_EQ(L"en-US", l10n_util::GetApplicationLocale(L""));
|
||||
SetICUDefaultLocale("en-US");
|
||||
EXPECT_EQ("en-US", l10n_util::GetApplicationLocale(L""));
|
||||
|
||||
SetICUDefaultLocale(L"en-GB");
|
||||
EXPECT_EQ(L"en-GB", l10n_util::GetApplicationLocale(L""));
|
||||
SetICUDefaultLocale("en-GB");
|
||||
EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale(L""));
|
||||
|
||||
SetICUDefaultLocale(L"fr-CA");
|
||||
EXPECT_EQ(L"fr", l10n_util::GetApplicationLocale(L""));
|
||||
SetICUDefaultLocale("fr-CA");
|
||||
EXPECT_EQ("fr", l10n_util::GetApplicationLocale(L""));
|
||||
|
||||
SetICUDefaultLocale(L"xx");
|
||||
EXPECT_EQ(L"en-US", l10n_util::GetApplicationLocale(L""));
|
||||
SetICUDefaultLocale("xx");
|
||||
EXPECT_EQ("en-US", l10n_util::GetApplicationLocale(L""));
|
||||
|
||||
SetICUDefaultLocale(L"en-US");
|
||||
EXPECT_EQ(L"fr", l10n_util::GetApplicationLocale(L"fr"));
|
||||
EXPECT_EQ(L"fr", l10n_util::GetApplicationLocale(L"fr-CA"));
|
||||
SetICUDefaultLocale("en-US");
|
||||
EXPECT_EQ("fr", l10n_util::GetApplicationLocale(L"fr"));
|
||||
EXPECT_EQ("fr", l10n_util::GetApplicationLocale(L"fr-CA"));
|
||||
|
||||
SetICUDefaultLocale(L"en-US");
|
||||
SetICUDefaultLocale("en-US");
|
||||
// Aliases iw, no, tl to he, nb, fil.
|
||||
EXPECT_EQ(L"he", l10n_util::GetApplicationLocale(L"iw"));
|
||||
EXPECT_EQ(L"nb", l10n_util::GetApplicationLocale(L"no"));
|
||||
EXPECT_EQ(L"fil", l10n_util::GetApplicationLocale(L"tl"));
|
||||
EXPECT_EQ("he", l10n_util::GetApplicationLocale(L"iw"));
|
||||
EXPECT_EQ("nb", l10n_util::GetApplicationLocale(L"no"));
|
||||
EXPECT_EQ("fil", l10n_util::GetApplicationLocale(L"tl"));
|
||||
// es-419 and es-XX (where XX is not Spain) should be
|
||||
// mapped to es-419 (Latin American Spanish).
|
||||
EXPECT_EQ(L"es-419", l10n_util::GetApplicationLocale(L"es-419"));
|
||||
EXPECT_EQ(L"es", l10n_util::GetApplicationLocale(L"es-ES"));
|
||||
EXPECT_EQ(L"es-419", l10n_util::GetApplicationLocale(L"es-AR"));
|
||||
EXPECT_EQ("es-419", l10n_util::GetApplicationLocale(L"es-419"));
|
||||
EXPECT_EQ("es", l10n_util::GetApplicationLocale(L"es-ES"));
|
||||
EXPECT_EQ("es-419", l10n_util::GetApplicationLocale(L"es-AR"));
|
||||
|
||||
SetICUDefaultLocale(L"es-MX");
|
||||
EXPECT_EQ(L"es-419", l10n_util::GetApplicationLocale(L""));
|
||||
SetICUDefaultLocale("es-MX");
|
||||
EXPECT_EQ("es-419", l10n_util::GetApplicationLocale(L""));
|
||||
|
||||
SetICUDefaultLocale(L"es-AR");
|
||||
EXPECT_EQ(L"es-419", l10n_util::GetApplicationLocale(L""));
|
||||
EXPECT_EQ(L"es", l10n_util::GetApplicationLocale(L"es"));
|
||||
SetICUDefaultLocale("es-AR");
|
||||
EXPECT_EQ("es-419", l10n_util::GetApplicationLocale(L""));
|
||||
EXPECT_EQ("es", l10n_util::GetApplicationLocale(L"es"));
|
||||
|
||||
SetICUDefaultLocale(L"es-ES");
|
||||
EXPECT_EQ(L"es", l10n_util::GetApplicationLocale(L""));
|
||||
SetICUDefaultLocale("es-ES");
|
||||
EXPECT_EQ("es", l10n_util::GetApplicationLocale(L""));
|
||||
|
||||
SetICUDefaultLocale(L"es");
|
||||
EXPECT_EQ(L"es", l10n_util::GetApplicationLocale(L""));
|
||||
SetICUDefaultLocale("es");
|
||||
EXPECT_EQ("es", l10n_util::GetApplicationLocale(L""));
|
||||
|
||||
SetICUDefaultLocale(L"zh-HK");
|
||||
EXPECT_EQ(L"zh-TW", l10n_util::GetApplicationLocale(L""));
|
||||
EXPECT_EQ(L"zh-CN", l10n_util::GetApplicationLocale(L"zh-CN"));
|
||||
SetICUDefaultLocale("zh-HK");
|
||||
EXPECT_EQ("zh-TW", l10n_util::GetApplicationLocale(L""));
|
||||
EXPECT_EQ("zh-CN", l10n_util::GetApplicationLocale(L"zh-CN"));
|
||||
|
||||
SetICUDefaultLocale(L"zh-MK");
|
||||
EXPECT_EQ(L"zh-TW", l10n_util::GetApplicationLocale(L""));
|
||||
SetICUDefaultLocale("zh-MK");
|
||||
EXPECT_EQ("zh-TW", l10n_util::GetApplicationLocale(L""));
|
||||
|
||||
SetICUDefaultLocale(L"zh-SG");
|
||||
EXPECT_EQ(L"zh-CN", l10n_util::GetApplicationLocale(L""));
|
||||
SetICUDefaultLocale("zh-SG");
|
||||
EXPECT_EQ("zh-CN", l10n_util::GetApplicationLocale(L""));
|
||||
|
||||
SetICUDefaultLocale(L"he");
|
||||
EXPECT_EQ(L"en-US", l10n_util::GetApplicationLocale(L"en"));
|
||||
SetICUDefaultLocale("he");
|
||||
EXPECT_EQ("en-US", l10n_util::GetApplicationLocale(L"en"));
|
||||
|
||||
#if defined(OS_WIN)
|
||||
// Oriya should be blocked unless OS is Vista or newer.
|
||||
if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) {
|
||||
SetICUDefaultLocale(L"or");
|
||||
EXPECT_EQ(L"en-US", l10n_util::GetApplicationLocale(L""));
|
||||
SetICUDefaultLocale(L"en-GB");
|
||||
EXPECT_EQ(L"en-GB", l10n_util::GetApplicationLocale(L"or"));
|
||||
SetICUDefaultLocale("or");
|
||||
EXPECT_EQ("en-US", l10n_util::GetApplicationLocale(L""));
|
||||
SetICUDefaultLocale("en-GB");
|
||||
EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale(L"or"));
|
||||
} else {
|
||||
SetICUDefaultLocale(L"or");
|
||||
EXPECT_EQ(L"or", l10n_util::GetApplicationLocale(L""));
|
||||
SetICUDefaultLocale(L"en-GB");
|
||||
EXPECT_EQ(L"or", l10n_util::GetApplicationLocale(L"or"));
|
||||
SetICUDefaultLocale("or");
|
||||
EXPECT_EQ("or", l10n_util::GetApplicationLocale(L""));
|
||||
SetICUDefaultLocale("en-GB");
|
||||
EXPECT_EQ("or", l10n_util::GetApplicationLocale(L"or"));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ void HWNDSetRTLLayout(HWND hwnd) {
|
||||
}
|
||||
}
|
||||
|
||||
bool IsLocaleSupportedByOS(const std::wstring& locale) {
|
||||
bool IsLocaleSupportedByOS(const std::string& locale) {
|
||||
// Block Oriya on Windows XP.
|
||||
return !(LowerCaseEqualsASCII(locale, "or") &&
|
||||
win_util::GetWinVersion() < win_util::WINVERSION_VISTA);
|
||||
|
||||
@@ -95,11 +95,11 @@ FilePath ResourceBundle::GetLocaleFilePath(const std::wstring& pref_locale) {
|
||||
FilePath locale_path;
|
||||
PathService::Get(app::DIR_LOCALES, &locale_path);
|
||||
|
||||
const std::wstring app_locale = l10n_util::GetApplicationLocale(pref_locale);
|
||||
const std::string app_locale = l10n_util::GetApplicationLocale(pref_locale);
|
||||
if (app_locale.empty())
|
||||
return FilePath();
|
||||
|
||||
return locale_path.Append(WideToASCII(app_locale + L".pak"));
|
||||
return locale_path.AppendASCII(app_locale + ".pak");
|
||||
}
|
||||
|
||||
void ResourceBundle::LoadThemeResources() {
|
||||
|
||||
@@ -65,11 +65,11 @@ FilePath ResourceBundle::GetLocaleFilePath(const std::wstring& pref_locale) {
|
||||
FilePath locale_path;
|
||||
PathService::Get(app::DIR_LOCALES, &locale_path);
|
||||
|
||||
const std::wstring app_locale = l10n_util::GetApplicationLocale(pref_locale);
|
||||
const std::string app_locale = l10n_util::GetApplicationLocale(pref_locale);
|
||||
if (app_locale.empty())
|
||||
return FilePath();
|
||||
|
||||
return locale_path.Append(app_locale + L".dll");
|
||||
return locale_path.AppendASCII(app_locale + ".dll");
|
||||
}
|
||||
|
||||
void ResourceBundle::LoadThemeResources() {
|
||||
|
||||
+6
-1
@@ -26,8 +26,9 @@
|
||||
#include <vector>
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "base/scoped_ptr.h"
|
||||
#include "base/file_path.h"
|
||||
#include "base/scoped_ptr.h"
|
||||
#include "base/string16.h"
|
||||
|
||||
namespace base {
|
||||
class Time;
|
||||
@@ -113,6 +114,10 @@ void ReplaceExtension(FilePath* file_name,
|
||||
// 'replace_char' is '-'.
|
||||
void ReplaceIllegalCharacters(std::wstring* file_name, int replace_char);
|
||||
|
||||
// Returns true if file_name does not have any illegal character. The input
|
||||
// param has the same restriction as that for ReplaceIllegalCharacters.
|
||||
bool IsFilenameLegal(const string16& file_name);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Functions that involve filesystem access or modification:
|
||||
|
||||
|
||||
+55
-16
@@ -12,14 +12,35 @@
|
||||
|
||||
#include "base/file_util.h"
|
||||
|
||||
#include "base/singleton.h"
|
||||
#include "base/string_util.h"
|
||||
#include "unicode/uniset.h"
|
||||
|
||||
namespace file_util {
|
||||
namespace {
|
||||
class IllegalCharacters {
|
||||
public:
|
||||
bool contains(UChar32 ucs4) {
|
||||
return !!set->contains(ucs4);
|
||||
}
|
||||
|
||||
void ReplaceIllegalCharacters(std::wstring* file_name, int replace_char) {
|
||||
DCHECK(file_name);
|
||||
bool containsNone(const string16 &s) {
|
||||
return !!set->containsNone(UnicodeString(s.c_str(), s.size()));
|
||||
}
|
||||
|
||||
private:
|
||||
friend class Singleton<IllegalCharacters>;
|
||||
friend struct DefaultSingletonTraits<IllegalCharacters>;
|
||||
|
||||
IllegalCharacters();
|
||||
~IllegalCharacters() { }
|
||||
|
||||
scoped_ptr<UnicodeSet> set;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(IllegalCharacters);
|
||||
};
|
||||
|
||||
IllegalCharacters::IllegalCharacters() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
// Control characters, formatting characters, non-characters, and
|
||||
// some printable ASCII characters regarded as dangerous ('"*/:<>?\\').
|
||||
// See http://blogs.msdn.com/michkap/archive/2006/11/03/941420.aspx
|
||||
@@ -30,29 +51,47 @@ void ReplaceIllegalCharacters(std::wstring* file_name, int replace_char) {
|
||||
// Also, consider wrapping the set with our Singleton class to create and
|
||||
// freeze it only once. Note that there's a trade-off between memory and
|
||||
// speed.
|
||||
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
#if defined(WCHAR_T_IS_UTF16)
|
||||
UnicodeSet illegal_characters(UnicodeString(
|
||||
L"[[\"*/:<>?\\\\|][:Cc:][:Cf:] - [\u200c\u200d]]"), status);
|
||||
set.reset(new UnicodeSet(UnicodeString(
|
||||
L"[[\"*/:<>?\\\\|][:Cc:][:Cf:] - [\u200c\u200d]]"), status));
|
||||
#else
|
||||
UnicodeSet illegal_characters(UNICODE_STRING_SIMPLE(
|
||||
"[[\"*/:<>?\\\\|][:Cc:][:Cf:] - [\\u200c\\u200d]]").unescape(), status);
|
||||
set.reset(new UnicodeSet(UNICODE_STRING_SIMPLE(
|
||||
"[[\"*/:<>?\\\\|][:Cc:][:Cf:] - [\\u200c\\u200d]]").unescape(),
|
||||
status));
|
||||
#endif
|
||||
DCHECK(U_SUCCESS(status));
|
||||
// Add non-characters. If this becomes a performance bottleneck by
|
||||
// any chance, check |ucs4 & 0xFFFEu == 0xFFFEu|, instead.
|
||||
illegal_characters.add(0xFDD0, 0xFDEF);
|
||||
// any chance, do not add these to |set| and change IsFilenameLegal()
|
||||
// to check |ucs4 & 0xFFFEu == 0xFFFEu|, in addiition to calling
|
||||
// containsNone().
|
||||
set->add(0xFDD0, 0xFDEF);
|
||||
for (int i = 0; i <= 0x10; ++i) {
|
||||
int plane_base = 0x10000 * i;
|
||||
illegal_characters.add(plane_base + 0xFFFE, plane_base + 0xFFFF);
|
||||
set->add(plane_base + 0xFFFE, plane_base + 0xFFFF);
|
||||
}
|
||||
illegal_characters.freeze();
|
||||
DCHECK(!illegal_characters.contains(replace_char) && replace_char < 0x10000);
|
||||
set->freeze();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace file_util {
|
||||
|
||||
bool IsFilenameLegal(const string16& file_name) {
|
||||
return Singleton<IllegalCharacters>()->containsNone(file_name);
|
||||
}
|
||||
|
||||
void ReplaceIllegalCharacters(std::wstring* file_name, int replace_char) {
|
||||
DCHECK(file_name);
|
||||
|
||||
DCHECK(!(Singleton<IllegalCharacters>()->contains(replace_char)) &&
|
||||
replace_char < 0x10000);
|
||||
|
||||
// Remove leading and trailing whitespace.
|
||||
TrimWhitespace(*file_name, TRIM_ALL, file_name);
|
||||
|
||||
if (IsFilenameLegal(WideToUTF16(*file_name)))
|
||||
return;
|
||||
|
||||
std::wstring::size_type i = 0;
|
||||
std::wstring::size_type length = file_name->size();
|
||||
const wchar_t* wstr = file_name->data();
|
||||
@@ -65,7 +104,7 @@ void ReplaceIllegalCharacters(std::wstring* file_name, int replace_char) {
|
||||
UChar32 ucs4;
|
||||
std::wstring::size_type prev = i;
|
||||
U16_NEXT(wstr, i, length, ucs4);
|
||||
if (illegal_characters.contains(ucs4)) {
|
||||
if (Singleton<IllegalCharacters>()->contains(ucs4)) {
|
||||
temp.push_back(replace_char);
|
||||
} else if (ucs4 < 0x10000) {
|
||||
temp.push_back(ucs4);
|
||||
@@ -77,7 +116,7 @@ void ReplaceIllegalCharacters(std::wstring* file_name, int replace_char) {
|
||||
file_name->swap(temp);
|
||||
#elif defined(WCHAR_T_IS_UTF32)
|
||||
while (i < length) {
|
||||
if (illegal_characters.contains(wstr[i])) {
|
||||
if (Singleton<IllegalCharacters>()->contains(wstr[i])) {
|
||||
(*file_name)[i] = replace_char;
|
||||
}
|
||||
++i;
|
||||
|
||||
@@ -1315,7 +1315,7 @@ void AutomationProvider::GetActiveTabIndex(int handle, int* active_tab_index) {
|
||||
|
||||
void AutomationProvider::GetBrowserLocale(string16* locale) {
|
||||
DCHECK(g_browser_process);
|
||||
*locale = WideToUTF16(g_browser_process->GetApplicationLocale());
|
||||
*locale = ASCIIToUTF16(g_browser_process->GetApplicationLocale());
|
||||
}
|
||||
|
||||
void AutomationProvider::GetBrowserWindowCount(int* window_count) {
|
||||
|
||||
@@ -330,7 +330,7 @@ void BookmarkModel::SortChildren(BookmarkNode* parent) {
|
||||
UErrorCode error = U_ZERO_ERROR;
|
||||
scoped_ptr<Collator> collator(
|
||||
Collator::createInstance(
|
||||
Locale(WideToUTF8(g_browser_process->GetApplicationLocale()).c_str()),
|
||||
Locale(g_browser_process->GetApplicationLocale().c_str()),
|
||||
error));
|
||||
if (U_FAILURE(error))
|
||||
collator.reset(NULL);
|
||||
|
||||
@@ -129,7 +129,7 @@ class BrowserProcess {
|
||||
virtual GoogleURLTracker* google_url_tracker() = 0;
|
||||
|
||||
// Returns the locale used by the application.
|
||||
virtual const std::wstring& GetApplicationLocale() = 0;
|
||||
virtual const std::string& GetApplicationLocale() = 0;
|
||||
|
||||
virtual MemoryModel memory_model() = 0;
|
||||
|
||||
|
||||
@@ -262,11 +262,11 @@ printing::PrintJobManager* BrowserProcessImpl::print_job_manager() {
|
||||
return print_job_manager_.get();
|
||||
}
|
||||
|
||||
const std::wstring& BrowserProcessImpl::GetApplicationLocale() {
|
||||
const std::string& BrowserProcessImpl::GetApplicationLocale() {
|
||||
DCHECK(CalledOnValidThread());
|
||||
if (locale_.empty()) {
|
||||
locale_ = l10n_util::GetApplicationLocale(local_state()->GetString(
|
||||
prefs::kApplicationLocale));
|
||||
locale_ = l10n_util::GetApplicationLocale(
|
||||
local_state()->GetString(prefs::kApplicationLocale));
|
||||
}
|
||||
return locale_;
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ class BrowserProcessImpl : public BrowserProcess, public NonThreadSafe {
|
||||
return google_url_tracker_.get();
|
||||
}
|
||||
|
||||
virtual const std::wstring& GetApplicationLocale();
|
||||
virtual const std::string& GetApplicationLocale();
|
||||
|
||||
virtual MemoryModel memory_model() {
|
||||
DCHECK(CalledOnValidThread());
|
||||
@@ -268,7 +268,7 @@ class BrowserProcessImpl : public BrowserProcess, public NonThreadSafe {
|
||||
// Ensures that all the print jobs are finished before closing the browser.
|
||||
scoped_ptr<printing::PrintJobManager> print_job_manager_;
|
||||
|
||||
std::wstring locale_;
|
||||
std::string locale_;
|
||||
|
||||
MemoryModel memory_model_;
|
||||
|
||||
|
||||
@@ -344,7 +344,7 @@ std::wstring CharacterEncoding::GetCanonicalEncodingNameByAliasName(
|
||||
// At last, we put all rest encoding items.
|
||||
const std::vector<CharacterEncoding::EncodingInfo>*
|
||||
CharacterEncoding::GetCurrentDisplayEncodings(
|
||||
const std::wstring& locale,
|
||||
const std::string& locale,
|
||||
const std::wstring& locale_encodings,
|
||||
const std::wstring& recently_select_encodings) {
|
||||
std::vector<int>* const locale_dependent_encoding_list =
|
||||
|
||||
@@ -79,7 +79,7 @@ class CharacterEncoding {
|
||||
// is from user recently selected. THIS FUNCTION IS NOT THREADSAFE. You must
|
||||
// run this function only in UI thread.
|
||||
static const std::vector<EncodingInfo>* GetCurrentDisplayEncodings(
|
||||
const std::wstring& locale,
|
||||
const std::string& locale,
|
||||
const std::wstring& locale_encodings,
|
||||
const std::wstring& recently_select_encodings);
|
||||
|
||||
|
||||
@@ -523,7 +523,7 @@ bool FirstRun::ImportSettings(Profile* profile, int browser_type,
|
||||
// current command line as fallback.
|
||||
import_cmd.AppendSwitchWithValue(
|
||||
switches::kLang,
|
||||
g_browser_process->GetApplicationLocale());
|
||||
ASCIIToWide(g_browser_process->GetApplicationLocale()));
|
||||
|
||||
import_cmd.CommandLine::AppendSwitchWithValue(switches::kImport,
|
||||
EncodeImportParams(browser_type, items_to_import, parent_window));
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace google_util {
|
||||
|
||||
GURL AppendGoogleLocaleParam(const GURL& url) {
|
||||
return AppendParam(url, "hl",
|
||||
WideToUTF8(g_browser_process->GetApplicationLocale()));
|
||||
g_browser_process->GetApplicationLocale());
|
||||
}
|
||||
|
||||
GURL AppendGoogleTLDParam(const GURL& url) {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "chrome/browser/plugin_service.h"
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/string_util.h"
|
||||
#include "base/thread.h"
|
||||
#include "base/waitable_event.h"
|
||||
#include "chrome/browser/browser_process.h"
|
||||
@@ -33,7 +34,7 @@ PluginService* PluginService::GetInstance() {
|
||||
PluginService::PluginService()
|
||||
: main_message_loop_(MessageLoop::current()),
|
||||
resource_dispatcher_host_(NULL),
|
||||
ui_locale_(g_browser_process->GetApplicationLocale()) {
|
||||
ui_locale_(ASCIIToWide(g_browser_process->GetApplicationLocale())) {
|
||||
// Have the NPAPI plugin list search for Chrome plugins as well.
|
||||
ChromePluginLib::RegisterPluginsWithNPAPI();
|
||||
// Load the one specified on the command line as well.
|
||||
|
||||
@@ -307,8 +307,8 @@ bool BrowserRenderProcessHost::Init() {
|
||||
}
|
||||
|
||||
// Pass on the browser locale.
|
||||
const std::wstring locale = g_browser_process->GetApplicationLocale();
|
||||
cmd_line.AppendSwitchWithValue(switches::kLang, locale);
|
||||
const std::string locale = g_browser_process->GetApplicationLocale();
|
||||
cmd_line.AppendSwitchWithValue(switches::kLang, ASCIIToWide(locale));
|
||||
|
||||
// If we run a FieldTrial that we want to pass to the renderer, this is where
|
||||
// the SINGULAR trial name and value should be specified. Note that only one
|
||||
|
||||
@@ -317,7 +317,8 @@ std::wstring TemplateURLRef::ReplaceSearchTerms(
|
||||
}
|
||||
|
||||
case LANGUAGE:
|
||||
url.insert(i->index, g_browser_process->GetApplicationLocale());
|
||||
url.insert(i->index,
|
||||
ASCIIToWide(g_browser_process->GetApplicationLocale()));
|
||||
break;
|
||||
|
||||
case SEARCH_TERMS:
|
||||
|
||||
@@ -238,7 +238,7 @@ TEST_F(TemplateURLTest, ReplaceSearchTerms) {
|
||||
EXPECT_TRUE(ref.SupportsReplacement());
|
||||
std::string expected_result = data[i].expected_result;
|
||||
ReplaceSubstringsAfterOffset(&expected_result, 0, "{language}",
|
||||
WideToASCII(g_browser_process->GetApplicationLocale()));
|
||||
g_browser_process->GetApplicationLocale());
|
||||
GURL result = GURL(WideToUTF8(ref.ReplaceSearchTerms(turl, L"X",
|
||||
TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())));
|
||||
EXPECT_TRUE(result.is_valid());
|
||||
|
||||
@@ -84,7 +84,8 @@ void RenderViewContextMenu::AppendLinkItems() {
|
||||
|
||||
if (params_.link_url.SchemeIs(chrome::kMailToScheme)) {
|
||||
AppendMenuItem(IDS_CONTENT_CONTEXT_COPYLINKLOCATION,
|
||||
l10n_util::GetString(IDS_CONTENT_CONTEXT_COPYEMAILADDRESS));
|
||||
l10n_util::GetStringUTF16(
|
||||
IDS_CONTENT_CONTEXT_COPYEMAILADDRESS));
|
||||
} else {
|
||||
AppendMenuItem(IDS_CONTENT_CONTEXT_COPYLINKLOCATION);
|
||||
}
|
||||
@@ -136,9 +137,10 @@ void RenderViewContextMenu::AppendSearchProvider() {
|
||||
std::wstring selection_text =
|
||||
l10n_util::TruncateString(params_.selection_text, 50);
|
||||
if (!selection_text.empty()) {
|
||||
std::wstring label(l10n_util::GetStringF(IDS_CONTENT_CONTEXT_SEARCHWEBFOR,
|
||||
default_provider->short_name(),
|
||||
selection_text));
|
||||
string16 label(WideToUTF16(
|
||||
l10n_util::GetStringF(IDS_CONTENT_CONTEXT_SEARCHWEBFOR,
|
||||
default_provider->short_name(),
|
||||
selection_text)));
|
||||
AppendMenuItem(IDS_CONTENT_CONTEXT_SEARCHWEBFOR, label);
|
||||
}
|
||||
}
|
||||
@@ -150,7 +152,7 @@ void RenderViewContextMenu::AppendEditableItems() {
|
||||
IDC_SPELLCHECK_SUGGESTION_0 + i <= IDC_SPELLCHECK_SUGGESTION_LAST;
|
||||
++i) {
|
||||
AppendMenuItem(IDC_SPELLCHECK_SUGGESTION_0 + static_cast<int>(i),
|
||||
params_.dictionary_suggestions[i]);
|
||||
WideToUTF16(params_.dictionary_suggestions[i]));
|
||||
}
|
||||
if (params_.dictionary_suggestions.size() > 0)
|
||||
AppendSeparator();
|
||||
@@ -159,7 +161,8 @@ void RenderViewContextMenu::AppendEditableItems() {
|
||||
if (!params_.misspelled_word.empty()) {
|
||||
if (params_.dictionary_suggestions.size() == 0) {
|
||||
AppendMenuItem(0,
|
||||
l10n_util::GetString(IDS_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS));
|
||||
l10n_util::GetStringUTF16(
|
||||
IDS_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS));
|
||||
}
|
||||
AppendMenuItem(IDS_CONTENT_CONTEXT_ADD_TO_DICTIONARY);
|
||||
AppendSeparator();
|
||||
@@ -176,19 +179,19 @@ void RenderViewContextMenu::AppendEditableItems() {
|
||||
|
||||
// Add Spell Check options sub menu.
|
||||
StartSubMenu(IDC_SPELLCHECK_MENU,
|
||||
l10n_util::GetString(IDS_CONTENT_CONTEXT_SPELLCHECK_MENU));
|
||||
l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLCHECK_MENU));
|
||||
|
||||
// Add Spell Check languages to sub menu.
|
||||
SpellChecker::Languages display_languages;
|
||||
SpellChecker::Languages spellcheck_languages;
|
||||
SpellChecker::GetSpellCheckLanguages(profile_,
|
||||
&display_languages);
|
||||
DCHECK(display_languages.size() <
|
||||
&spellcheck_languages);
|
||||
DCHECK(spellcheck_languages.size() <
|
||||
IDC_SPELLCHECK_LANGUAGES_LAST - IDC_SPELLCHECK_LANGUAGES_FIRST);
|
||||
const std::wstring app_locale = g_browser_process->GetApplicationLocale();
|
||||
for (size_t i = 0; i < display_languages.size(); ++i) {
|
||||
std::wstring local_language(l10n_util::GetLocalName(
|
||||
display_languages[i], app_locale, true));
|
||||
AppendRadioMenuItem(IDC_SPELLCHECK_LANGUAGES_FIRST + i, local_language);
|
||||
const std::string app_locale = g_browser_process->GetApplicationLocale();
|
||||
for (size_t i = 0; i < spellcheck_languages.size(); ++i) {
|
||||
string16 display_name(l10n_util::GetDisplayNameForLocale(
|
||||
spellcheck_languages[i], app_locale, true));
|
||||
AppendRadioMenuItem(IDC_SPELLCHECK_LANGUAGES_FIRST + i, display_name);
|
||||
}
|
||||
|
||||
// Add item in the sub menu to pop up the fonts and languages options menu.
|
||||
@@ -198,7 +201,8 @@ void RenderViewContextMenu::AppendEditableItems() {
|
||||
// Add 'Check the spelling of this field' item in the sub menu.
|
||||
AppendCheckboxMenuItem(
|
||||
IDC_CHECK_SPELLING_OF_THIS_FIELD,
|
||||
l10n_util::GetString(IDS_CONTENT_CONTEXT_CHECK_SPELLING_OF_THIS_FIELD));
|
||||
l10n_util::GetStringUTF16(
|
||||
IDS_CONTENT_CONTEXT_CHECK_SPELLING_OF_THIS_FIELD));
|
||||
|
||||
FinishSubMenu();
|
||||
|
||||
|
||||
@@ -36,13 +36,13 @@ class RenderViewContextMenu {
|
||||
virtual void AppendMenuItem(int id) = 0;
|
||||
|
||||
// Append a normal menu item, using |label| for the name.
|
||||
virtual void AppendMenuItem(int id, const std::wstring& label) = 0;
|
||||
virtual void AppendMenuItem(int id, const string16& label) = 0;
|
||||
|
||||
// Append a radio menu item.
|
||||
virtual void AppendRadioMenuItem(int id, const std::wstring& label) = 0;
|
||||
virtual void AppendRadioMenuItem(int id, const string16& label) = 0;
|
||||
|
||||
// Append a checkbox menu item.
|
||||
virtual void AppendCheckboxMenuItem(int id, const std::wstring& label) = 0;
|
||||
virtual void AppendCheckboxMenuItem(int id, const string16& label) = 0;
|
||||
|
||||
// Append a separator.
|
||||
virtual void AppendSeparator() = 0;
|
||||
@@ -52,7 +52,7 @@ class RenderViewContextMenu {
|
||||
// the main menu we are building. We only support at most single-depth
|
||||
// submenus, so calls to StartSubMenu() while we are already building a
|
||||
// submenu will be ignored.
|
||||
virtual void StartSubMenu(int id, const std::wstring& label) = 0;
|
||||
virtual void StartSubMenu(int id, const string16& label) = 0;
|
||||
|
||||
// Finish creating the submenu and attach it to the main menu.
|
||||
virtual void FinishSubMenu() = 0;
|
||||
|
||||
@@ -61,29 +61,29 @@ void RenderViewContextMenuGtk::StoppedShowing() {
|
||||
}
|
||||
|
||||
void RenderViewContextMenuGtk::AppendMenuItem(int id) {
|
||||
AppendItem(id, std::wstring(), MENU_NORMAL);
|
||||
AppendItem(id, string16(), MENU_NORMAL);
|
||||
}
|
||||
|
||||
void RenderViewContextMenuGtk::AppendMenuItem(int id,
|
||||
const std::wstring& label) {
|
||||
const string16& label) {
|
||||
AppendItem(id, label, MENU_NORMAL);
|
||||
}
|
||||
|
||||
void RenderViewContextMenuGtk::AppendRadioMenuItem(int id,
|
||||
const std::wstring& label) {
|
||||
const string16& label) {
|
||||
AppendItem(id, label, MENU_RADIO);
|
||||
}
|
||||
|
||||
void RenderViewContextMenuGtk::AppendCheckboxMenuItem(int id,
|
||||
const std::wstring& label) {
|
||||
const string16& label) {
|
||||
AppendItem(id, label, MENU_CHECKBOX);
|
||||
}
|
||||
|
||||
void RenderViewContextMenuGtk::AppendSeparator() {
|
||||
AppendItem(0, std::wstring(), MENU_SEPARATOR);
|
||||
AppendItem(0, string16(), MENU_SEPARATOR);
|
||||
}
|
||||
|
||||
void RenderViewContextMenuGtk::StartSubMenu(int id, const std::wstring& label) {
|
||||
void RenderViewContextMenuGtk::StartSubMenu(int id, const string16& label) {
|
||||
AppendItem(id, label, MENU_NORMAL);
|
||||
making_submenu_ = true;
|
||||
}
|
||||
@@ -104,7 +104,7 @@ void RenderViewContextMenuGtk::DidWriteURLToClipboard(
|
||||
}
|
||||
|
||||
void RenderViewContextMenuGtk::AppendItem(
|
||||
int id, const std::wstring& label, MenuItemType type) {
|
||||
int id, const string16& label, MenuItemType type) {
|
||||
MenuCreateMaterial menu_create_material = {
|
||||
type, id, 0, 0, NULL
|
||||
};
|
||||
@@ -112,7 +112,7 @@ void RenderViewContextMenuGtk::AppendItem(
|
||||
if (label.empty())
|
||||
menu_create_material.label_id = id;
|
||||
else
|
||||
label_map_[id] = WideToUTF8(label);
|
||||
label_map_[id] = UTF16ToUTF8(label);
|
||||
|
||||
std::vector<MenuCreateMaterial>* menu =
|
||||
making_submenu_ ? &submenu_ : &menu_;
|
||||
|
||||
@@ -41,16 +41,16 @@ class RenderViewContextMenuGtk : public RenderViewContextMenu,
|
||||
// RenderViewContextMenu implementation --------------------------------------
|
||||
virtual void DoInit();
|
||||
virtual void AppendMenuItem(int id);
|
||||
virtual void AppendMenuItem(int id, const std::wstring& label);
|
||||
virtual void AppendRadioMenuItem(int id, const std::wstring& label);
|
||||
virtual void AppendCheckboxMenuItem(int id, const std::wstring& label);
|
||||
virtual void AppendMenuItem(int id, const string16& label);
|
||||
virtual void AppendRadioMenuItem(int id, const string16& label);
|
||||
virtual void AppendCheckboxMenuItem(int id, const string16& label);
|
||||
virtual void AppendSeparator();
|
||||
virtual void StartSubMenu(int id, const std::wstring& label);
|
||||
virtual void StartSubMenu(int id, const string16& label);
|
||||
virtual void FinishSubMenu();
|
||||
virtual void DidWriteURLToClipboard(const std::string& url);
|
||||
|
||||
private:
|
||||
void AppendItem(int id, const std::wstring& label, MenuItemType type);
|
||||
void AppendItem(int id, const string16& label, MenuItemType type);
|
||||
static void DoneMakingMenu(std::vector<MenuCreateMaterial>* menu);
|
||||
|
||||
scoped_ptr<MenuGtk> gtk_menu_;
|
||||
|
||||
@@ -29,15 +29,15 @@ class RenderViewContextMenuMac : public RenderViewContextMenu {
|
||||
// RenderViewContextMenu implementation-
|
||||
virtual void DoInit();
|
||||
virtual void AppendMenuItem(int id);
|
||||
virtual void AppendMenuItem(int id, const std::wstring& label);
|
||||
virtual void AppendRadioMenuItem(int id, const std::wstring& label);
|
||||
virtual void AppendCheckboxMenuItem(int id, const std::wstring& label);
|
||||
virtual void AppendMenuItem(int id, const string16& label);
|
||||
virtual void AppendRadioMenuItem(int id, const string16& label);
|
||||
virtual void AppendCheckboxMenuItem(int id, const string16& label);
|
||||
virtual void AppendSeparator();
|
||||
virtual void StartSubMenu(int id, const std::wstring& label);
|
||||
virtual void StartSubMenu(int id, const string16& label);
|
||||
virtual void FinishSubMenu();
|
||||
|
||||
// Do things like remove the windows accelerators.
|
||||
static NSString* PrepareLabelForDisplay(const std::wstring& label);
|
||||
static NSString* PrepareLabelForDisplay(const string16& label);
|
||||
|
||||
private:
|
||||
NSMenu* menu_;
|
||||
|
||||
@@ -68,10 +68,10 @@ void RenderViewContextMenuMac::DoInit() {
|
||||
// TODO(pinkerton): Do we want to do anything like make a maximum string width
|
||||
// and middle-truncate?
|
||||
NSString* RenderViewContextMenuMac::PrepareLabelForDisplay(
|
||||
const std::wstring& label) {
|
||||
const string16& label) {
|
||||
// Strip out any "&"'s that are windows accelerators and we don't use.
|
||||
NSMutableString* title =
|
||||
[NSMutableString stringWithString:base::SysWideToNSString(label)];
|
||||
[NSMutableString stringWithString:base::SysUTF16ToNSString(label)];
|
||||
DCHECK(title);
|
||||
NSRange range = NSMakeRange(0, [title length]);
|
||||
[title replaceOccurrencesOfString:@"&" withString:@"" options:0 range:range];
|
||||
@@ -79,11 +79,11 @@ NSString* RenderViewContextMenuMac::PrepareLabelForDisplay(
|
||||
}
|
||||
|
||||
void RenderViewContextMenuMac::AppendMenuItem(int command_id) {
|
||||
AppendMenuItem(command_id, l10n_util::GetString(command_id));
|
||||
AppendMenuItem(command_id, l10n_util::GetStringUTF16(command_id));
|
||||
}
|
||||
|
||||
void RenderViewContextMenuMac::AppendMenuItem(int command_id,
|
||||
const std::wstring& label) {
|
||||
const string16& label) {
|
||||
// Create the item and set its target/action to |target_| with the command
|
||||
// as |command_id|. Then add it to the menu at the end.
|
||||
NSMenuItem* item =
|
||||
@@ -97,12 +97,12 @@ void RenderViewContextMenuMac::AppendMenuItem(int command_id,
|
||||
}
|
||||
|
||||
void RenderViewContextMenuMac::AppendRadioMenuItem(int id,
|
||||
const std::wstring& label) {
|
||||
const string16& label) {
|
||||
NOTIMPLEMENTED();
|
||||
}
|
||||
|
||||
void RenderViewContextMenuMac::AppendCheckboxMenuItem(int id,
|
||||
const std::wstring& label) {
|
||||
const string16& label) {
|
||||
NOTIMPLEMENTED();
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ void RenderViewContextMenuMac::AppendSeparator() {
|
||||
}
|
||||
|
||||
void RenderViewContextMenuMac::StartSubMenu(int command_id,
|
||||
const std::wstring& label) {
|
||||
const string16& label) {
|
||||
// I'm not a fan of this kind of API, but the other platforms have similar
|
||||
// guards so at least we know everyone will break together if someone
|
||||
// tries to mis-use the API.
|
||||
|
||||
@@ -46,7 +46,7 @@ class DefaultEncodingComboboxModel : public views::Combobox::Model {
|
||||
// Initialize the vector of all sorted encodings according to current
|
||||
// UI locale.
|
||||
if (!sorted_encoding_list.size()) {
|
||||
std::wstring locale = g_browser_process->GetApplicationLocale();
|
||||
std::string locale = g_browser_process->GetApplicationLocale();
|
||||
for (int i = 0; i < canonical_encoding_names_length_; i++) {
|
||||
sorted_encoding_list.push_back(CharacterEncoding::EncodingInfo(
|
||||
CharacterEncoding::GetEncodingCommandIdByIndex(i)));
|
||||
|
||||
@@ -33,8 +33,7 @@ LanguageComboboxModel::LanguageComboboxModel(
|
||||
|
||||
void LanguageComboboxModel::InitNativeNames(
|
||||
const std::vector<std::string>& locale_codes) {
|
||||
const std::string app_locale = WideToASCII(
|
||||
g_browser_process->GetApplicationLocale());
|
||||
const std::string app_locale = g_browser_process->GetApplicationLocale();
|
||||
for (size_t i = 0; i < locale_codes.size(); ++i) {
|
||||
std::string locale_code_str = locale_codes[i];
|
||||
const char* locale_code = locale_codes[i].c_str();
|
||||
|
||||
@@ -291,17 +291,18 @@ void AddLanguageWindowView::ViewHierarchyChanged(bool is_add,
|
||||
void AddLanguageWindowView::Init() {
|
||||
// Determine Locale Codes.
|
||||
std::vector<std::string> locale_codes;
|
||||
const std::wstring app_locale = g_browser_process->GetApplicationLocale();
|
||||
const std::string app_locale = g_browser_process->GetApplicationLocale();
|
||||
for (size_t i = 0; i < arraysize(accept_language_list); ++i) {
|
||||
std::wstring local_name =
|
||||
l10n_util::GetLocalName(accept_language_list[i], app_locale, false);
|
||||
string16 display_name =
|
||||
l10n_util::GetDisplayNameForLocale(accept_language_list[i],
|
||||
app_locale, false);
|
||||
// This is a hack. If ICU doesn't have a translated name for
|
||||
// this language, GetLocalName will just return the language code.
|
||||
// In that case, we skip it.
|
||||
// this language, GetDisplayNameForLocale will just return the
|
||||
// language code. In that case, we skip it.
|
||||
// TODO(jungshik) : Put them at the of the list with language codes
|
||||
// enclosed by brackets.
|
||||
if (IsStringASCII(local_name) &&
|
||||
WideToASCII(local_name) == accept_language_list[i])
|
||||
if (IsStringASCII(display_name) &&
|
||||
UTF16ToASCII(display_name) == accept_language_list[i])
|
||||
continue;
|
||||
locale_codes.push_back(accept_language_list[i]);
|
||||
}
|
||||
@@ -381,8 +382,10 @@ void LanguageOrderTableModel::SetObserver(TableModelObserver* observer) {
|
||||
|
||||
std::wstring LanguageOrderTableModel::GetText(int row, int column_id) {
|
||||
DCHECK(row >= 0 && row < RowCount());
|
||||
const std::wstring app_locale = g_browser_process->GetApplicationLocale();
|
||||
return l10n_util::GetLocalName(languages_.at(row), app_locale, true);
|
||||
const std::string app_locale = g_browser_process->GetApplicationLocale();
|
||||
return l10n_util::GetDisplayNameForLocale(languages_.at(row),
|
||||
app_locale,
|
||||
true);
|
||||
}
|
||||
|
||||
void LanguageOrderTableModel::Add(const std::string& language) {
|
||||
@@ -702,7 +705,7 @@ void LanguagesPageView::NotifyPrefChanged(const std::wstring* pref_name) {
|
||||
// The pref value for locale isn't valid. Use the current app locale
|
||||
// (which is what we're currently using).
|
||||
index = ui_language_model_->GetIndexFromLocale(
|
||||
WideToASCII(g_browser_process->GetApplicationLocale()));
|
||||
g_browser_process->GetApplicationLocale());
|
||||
}
|
||||
DCHECK(-1 != index);
|
||||
change_ui_language_combobox_->SetSelectedItem(index);
|
||||
|
||||
@@ -397,7 +397,7 @@ bool AutomatedUITest::DoAction(const std::string & action) {
|
||||
|
||||
bool AutomatedUITest::ChangeEncoding() {
|
||||
// Get the encoding list that is used to populate the UI (encoding menu)
|
||||
std::wstring cur_locale = g_browser_process->GetApplicationLocale();
|
||||
std::string cur_locale = g_browser_process->GetApplicationLocale();
|
||||
const std::vector<CharacterEncoding::EncodingInfo>* encodings =
|
||||
CharacterEncoding::GetCurrentDisplayEncodings(
|
||||
cur_locale, L"ISO-8859-1,windows-1252", L"");
|
||||
|
||||
@@ -131,10 +131,10 @@ class TestingBrowserProcess : public BrowserProcess {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
virtual const std::wstring& GetApplicationLocale() {
|
||||
static std::wstring* value = NULL;
|
||||
virtual const std::string& GetApplicationLocale() {
|
||||
static std::string* value = NULL;
|
||||
if (!value)
|
||||
value = new std::wstring(L"en");
|
||||
value = new std::string("en");
|
||||
return *value;
|
||||
}
|
||||
|
||||
|
||||
@@ -101,9 +101,9 @@ class ChromeTestSuite : public TestSuite {
|
||||
mac_util::SetOverrideAppBundlePath(path);
|
||||
#endif
|
||||
|
||||
// Force unittests to run using en-us so if we test against string
|
||||
// Force unittests to run using en-US so if we test against string
|
||||
// output, it'll pass regardless of the system language.
|
||||
ResourceBundle::InitSharedInstance(L"en-us");
|
||||
ResourceBundle::InitSharedInstance(L"en-US");
|
||||
ResourceBundle::GetSharedInstance().LoadThemeResources();
|
||||
|
||||
// initialize the global StatsTable for unit_tests
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário