diff options
-rw-r--r-- | base/file_path.cc | 12 | ||||
-rw-r--r-- | base/file_path.h | 5 | ||||
-rw-r--r-- | chrome/browser/spellcheck_host.cc | 8 | ||||
-rw-r--r-- | chrome/common/extensions/extension_l10n_util.cc | 13 |
4 files changed, 32 insertions, 6 deletions
diff --git a/base/file_path.cc b/base/file_path.cc index 5f1375a..907a412 100644 --- a/base/file_path.cc +++ b/base/file_path.cc @@ -520,6 +520,12 @@ string16 FilePath::LossyDisplayName() const { return WideToUTF16(base::SysNativeMBToWide(path_)); } +std::string FilePath::MaybeAsASCII() const { + if (IsStringASCII(path_)) + return path_; + return ""; +} + // The *Hack functions are temporary while we fix the remainder of the code. // Remember to remove the #includes at the top when you remove these. @@ -535,6 +541,12 @@ string16 FilePath::LossyDisplayName() const { return path_; } +std::string FilePath::MaybeAsASCII() const { + if (IsStringASCII(path_)) + return WideToASCII(path_); + return ""; +} + // static FilePath FilePath::FromWStringHack(const std::wstring& wstring) { return FilePath(wstring); diff --git a/base/file_path.h b/base/file_path.h index 84bb350..1afa7a6 100644 --- a/base/file_path.h +++ b/base/file_path.h @@ -283,6 +283,11 @@ class FilePath { // want to stuff a string16 into some other API. string16 LossyDisplayName() const; + // Return the path as ASCII, or the empty string if the path is not ASCII. + // This should only be used for cases where the FilePath is representing a + // known-ASCII filename. + std::string MaybeAsASCII() const; + // Older Chromium code assumes that paths are always wstrings. // These functions convert wstrings to/from FilePaths, and are // useful to smooth porting that old code to the FilePath API. diff --git a/chrome/browser/spellcheck_host.cc b/chrome/browser/spellcheck_host.cc index 0ea7ba8..d532b36 100644 --- a/chrome/browser/spellcheck_host.cc +++ b/chrome/browser/spellcheck_host.cc @@ -268,9 +268,13 @@ void SpellCheckHost::DownloadDictionary() { // Determine URL of file to download. static const char kDownloadServerUrl[] = "http://cache.pack.google.com/edgedl/chrome/dict/"; + std::string bdict_file = bdict_file_path_.BaseName().MaybeAsASCII(); + if (bdict_file.empty()) { + NOTREACHED(); + return; + } GURL url = GURL(std::string(kDownloadServerUrl) + - StringToLowerASCII(WideToUTF8( - bdict_file_path_.BaseName().ToWStringHack()))); + StringToLowerASCII(bdict_file)); fetcher_.reset(new URLFetcher(url, URLFetcher::GET, this)); fetcher_->set_request_context(request_context_getter_); tried_to_download_ = true; diff --git a/chrome/common/extensions/extension_l10n_util.cc b/chrome/common/extensions/extension_l10n_util.cc index dff8f5e..dad4d06 100644 --- a/chrome/common/extensions/extension_l10n_util.cc +++ b/chrome/common/extensions/extension_l10n_util.cc @@ -277,13 +277,18 @@ bool ShouldSkipValidation(const FilePath& locales_path, // skipping any strings with '.'. This happens sometimes, for example with // '.svn' directories. FilePath relative_path; - if (!locales_path.AppendRelativePath(locale_path, &relative_path)) + if (!locales_path.AppendRelativePath(locale_path, &relative_path)) { NOTREACHED(); - std::wstring subdir(relative_path.ToWStringHack()); - if (std::find(subdir.begin(), subdir.end(), L'.') != subdir.end()) + return true; + } + std::string subdir = relative_path.MaybeAsASCII(); + if (subdir.empty()) + return true; // Non-ASCII. + + if (std::find(subdir.begin(), subdir.end(), '.') != subdir.end()) return true; - if (all_locales.find(WideToASCII(subdir)) == all_locales.end()) + if (all_locales.find(subdir) == all_locales.end()) return true; return false; |