summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/profile.cc5
-rw-r--r--chrome/browser/spellcheck_unittest.cc10
-rw-r--r--chrome/browser/spellcheck_worditerator.cc10
-rw-r--r--chrome/browser/spellcheck_worditerator.h12
-rw-r--r--chrome/browser/spellchecker.cc116
-rw-r--r--chrome/browser/spellchecker.h13
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.cc6
-rw-r--r--chrome/browser/views/options/language_combobox_model.cc11
-rw-r--r--chrome/browser/views/options/language_combobox_model.h5
-rw-r--r--chrome/browser/views/options/languages_page_view.cc6
-rw-r--r--chrome/common/l10n_util.h1
11 files changed, 111 insertions, 84 deletions
diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc
index 88bc072..1bc6956 100644
--- a/chrome/browser/profile.cc
+++ b/chrome/browser/profile.cc
@@ -62,6 +62,7 @@ void Profile::RegisterUserPrefs(PrefService* prefs) {
prefs->RegisterBooleanPref(prefs::kSearchSuggestEnabled, true);
prefs->RegisterBooleanPref(prefs::kSessionExitedCleanly, true);
prefs->RegisterBooleanPref(prefs::kSafeBrowsingEnabled, true);
+ // TODO(estade): IDS_SPELLCHECK_DICTIONARY should be an ASCII string.
#if defined(OS_MACOSX)
// MASSIVE HACK!!! We don't have localization working yet. Undo this once we
// do. TODO(port): take this out
@@ -381,7 +382,6 @@ void ProfileImpl::InitExtensions() {
FilePath script_dir;
if (user_scripts_enabled) {
-
if (command_line->HasSwitch(switches::kUserScriptsDir)) {
std::wstring path_string =
command_line->GetSwitchValue(switches::kUserScriptsDir);
@@ -803,7 +803,8 @@ void ProfileImpl::InitializeSpellChecker(bool need_to_broadcast) {
// is being deleted in the io thread, the spellchecker_ can be made to point
// to a new object (RE-initialized) in parallel in this UI thread.
spellchecker_ = new SpellChecker(dict_dir,
- prefs->GetString(prefs::kSpellCheckDictionary), GetRequestContext(),
+ WideToASCII(prefs->GetString(prefs::kSpellCheckDictionary)),
+ GetRequestContext(),
FilePath());
spellchecker_->AddRef(); // Manual refcounting.
} else {
diff --git a/chrome/browser/spellcheck_unittest.cc b/chrome/browser/spellcheck_unittest.cc
index cf3fe1b..8a9731f 100644
--- a/chrome/browser/spellcheck_unittest.cc
+++ b/chrome/browser/spellcheck_unittest.cc
@@ -265,7 +265,7 @@ TEST_F(SpellCheckTest, SpellCheckStrings_EN_US) {
ASSERT_FALSE(hunspell_directory.empty());
scoped_refptr<SpellChecker> spell_checker(new SpellChecker(
- hunspell_directory, L"en-US", NULL, FilePath()));
+ hunspell_directory, "en-US", NULL, FilePath()));
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
size_t input_length = 0;
@@ -318,7 +318,7 @@ TEST_F(SpellCheckTest, SpellCheckSuggestions_EN_US) {
ASSERT_FALSE(hunspell_directory.empty());
scoped_refptr<SpellChecker> spell_checker(new SpellChecker(
- hunspell_directory, L"en-US", NULL, FilePath()));
+ hunspell_directory, "en-US", NULL, FilePath()));
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
std::vector<std::wstring> suggestions;
@@ -366,7 +366,7 @@ TEST_F(SpellCheckTest, DISABLED_SpellCheckAddToDictionary_EN_US) {
ASSERT_FALSE(hunspell_directory.empty());
scoped_refptr<SpellChecker> spell_checker(new SpellChecker(
- hunspell_directory, L"en-US", NULL, custom_dictionary_file));
+ hunspell_directory, "en-US", NULL, custom_dictionary_file));
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
// Add the word to spellchecker.
@@ -392,7 +392,7 @@ TEST_F(SpellCheckTest, DISABLED_SpellCheckAddToDictionary_EN_US) {
// Now initialize another spellchecker to see that AddToWord is permanent.
scoped_refptr<SpellChecker> spell_checker_new(new SpellChecker(
- hunspell_directory, L"en-US", NULL, custom_dictionary_file));
+ hunspell_directory, "en-US", NULL, custom_dictionary_file));
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
// Now check whether it is added to Spellchecker.
@@ -434,7 +434,7 @@ TEST_F(SpellCheckTest, DISABLED_SpellCheckSuggestionsAddToDictionary_EN_US) {
ASSERT_FALSE(hunspell_directory.empty());
scoped_refptr<SpellChecker> spell_checker(new SpellChecker(
- hunspell_directory, L"en-US", NULL, custom_dictionary_file));
+ hunspell_directory, "en-US", NULL, custom_dictionary_file));
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
// Add the word to spellchecker.
diff --git a/chrome/browser/spellcheck_worditerator.cc b/chrome/browser/spellcheck_worditerator.cc
index 9291b66..1b98b4a 100644
--- a/chrome/browser/spellcheck_worditerator.cc
+++ b/chrome/browser/spellcheck_worditerator.cc
@@ -9,6 +9,7 @@
#include "base/basictypes.h"
#include "base/string_util.h"
+#include "chrome/browser/spellchecker.h"
#include "third_party/icu38/public/common/unicode/normlzr.h"
#include "third_party/icu38/public/common/unicode/schriter.h"
@@ -59,13 +60,10 @@ SpellcheckCharAttribute::~SpellcheckCharAttribute() {
// Sets the default language for this object.
// This function retrieves the exemplar set to set up the default character
// attributes.
-void SpellcheckCharAttribute::SetDefaultLanguage(const std::wstring& language) {
- // Retrieves the locale data of the given language.
- std::string language_encoded;
- WideToCodepage(language, "us-ascii", OnStringUtilConversionError::SKIP,
- &language_encoded);
+void SpellcheckCharAttribute::SetDefaultLanguage(
+ const SpellChecker::Language& language) {
UErrorCode status = U_ZERO_ERROR;
- ULocaleData* locale_data = ulocdata_open(language_encoded.c_str(), &status);
+ ULocaleData* locale_data = ulocdata_open(language.c_str(), &status);
if (U_FAILURE(status))
return;
diff --git a/chrome/browser/spellcheck_worditerator.h b/chrome/browser/spellcheck_worditerator.h
index f9e7830..c0fb8e1 100644
--- a/chrome/browser/spellcheck_worditerator.h
+++ b/chrome/browser/spellcheck_worditerator.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_SPELLCHECK_WORDITERATOR_H__
-#define CHROME_BROWSER_SPELLCHECK_WORDITERATOR_H__
+#ifndef CHROME_BROWSER_SPELLCHECK_WORDITERATOR_H_
+#define CHROME_BROWSER_SPELLCHECK_WORDITERATOR_H_
#include <map>
#include <string>
@@ -25,7 +25,7 @@ class SpellcheckCharAttribute {
// Sets the default language of the spell checker. This controls which
// characters are considered parts of words of the given language.
- void SetDefaultLanguage(const std::wstring& language);
+ void SetDefaultLanguage(const std::string& language);
// Returns whether or not the given character is a character used by the
// selected dictionary.
@@ -73,7 +73,7 @@ class SpellcheckCharAttribute {
// Represents a table of characters used by contractions.
std::map<UChar32, bool> middle_letters_;
- DISALLOW_EVIL_CONSTRUCTORS(SpellcheckCharAttribute);
+ DISALLOW_COPY_AND_ASSIGN(SpellcheckCharAttribute);
};
// A class which implements methods for finding the location of word boundaries
@@ -177,7 +177,7 @@ class SpellcheckWordIterator {
// The character attributes used for filtering out non-word characters.
const SpellcheckCharAttribute* attribute_;
- DISALLOW_EVIL_CONSTRUCTORS(SpellcheckWordIterator);
+ DISALLOW_COPY_AND_ASSIGN(SpellcheckWordIterator);
};
-#endif // CHROME_BROWSER_SPELLCHECK_WORDITERATOR_H__
+#endif // CHROME_BROWSER_SPELLCHECK_WORDITERATOR_H_
diff --git a/chrome/browser/spellchecker.cc b/chrome/browser/spellchecker.cc
index 78a46f5..2ce324c 100644
--- a/chrome/browser/spellchecker.cc
+++ b/chrome/browser/spellchecker.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <set>
+
#include "chrome/browser/spellchecker.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
@@ -31,47 +33,46 @@ static const int kMaxSuggestions = 5; // Max number of dictionary suggestions.
namespace {
-// TODO(rohitrao): Convert these constants from wchar_t* to char*.
static const struct {
// The language.
- const wchar_t* language;
+ const char* language;
// The corresponding language and region, used by the dictionaries.
- const wchar_t* language_region;
+ const char* language_region;
} g_supported_spellchecker_languages[] = {
- {L"en-US", L"en-US"},
- {L"en-GB", L"en-GB"},
- {L"fr", L"fr-FR"},
- {L"it", L"it-IT"},
- {L"de", L"de-DE"},
- {L"es", L"es-ES"},
- {L"nl", L"nl-NL"},
- {L"pt-BR", L"pt-BR"},
- {L"ru", L"ru-RU"},
- {L"pl", L"pl-PL"},
- // {L"th", L"th-TH"}, // Not to be included in Spellchecker as per B=1277824
- {L"sv", L"sv-SE"},
- {L"da", L"da-DK"},
- {L"pt-PT", L"pt-PT"},
- {L"ro", L"ro-RO"},
- // {L"hu", L"hu-HU"}, // Not to be included in Spellchecker as per B=1277824
- {L"he", L"he-IL"},
- {L"id", L"id-ID"},
- {L"cs", L"cs-CZ"},
- {L"el", L"el-GR"},
- {L"nb", L"nb-NO"},
- {L"vi", L"vi-VN"},
- // {L"bg", L"bg-BG"}, // Not to be included in Spellchecker as per B=1277824
- {L"hr", L"hr-HR"},
- {L"lt", L"lt-LT"},
- {L"sk", L"sk-SK"},
- {L"sl", L"sl-SI"},
- {L"ca", L"ca-ES"},
- {L"lv", L"lv-LV"},
- // {L"uk", L"uk-UA"}, // Not to be included in Spellchecker as per B=1277824
- {L"hi", L"hi-IN"},
- {L"et", L"et-EE"},
- {L"tr", L"tr-TR"},
+ {"en-US", "en-US"},
+ {"en-GB", "en-GB"},
+ {"fr", "fr-FR"},
+ {"it", "it-IT"},
+ {"de", "de-DE"},
+ {"es", "es-ES"},
+ {"nl", "nl-NL"},
+ {"pt-BR", "pt-BR"},
+ {"ru", "ru-RU"},
+ {"pl", "pl-PL"},
+ // {"th", "th-TH"}, // Not to be included in Spellchecker as per B=1277824
+ {"sv", "sv-SE"},
+ {"da", "da-DK"},
+ {"pt-PT", "pt-PT"},
+ {"ro", "ro-RO"},
+ // {"hu", "hu-HU"}, // Not to be included in Spellchecker as per B=1277824
+ {"he", "he-IL"},
+ {"id", "id-ID"},
+ {"cs", "cs-CZ"},
+ {"el", "el-GR"},
+ {"nb", "nb-NO"},
+ {"vi", "vi-VN"},
+ // {"bg", "bg-BG"}, // Not to be included in Spellchecker as per B=1277824
+ {"hr", "hr-HR"},
+ {"lt", "lt-LT"},
+ {"sk", "sk-SK"},
+ {"sl", "sl-SI"},
+ {"ca", "ca-ES"},
+ {"lv", "lv-LV"},
+ // {"uk", "uk-UA"}, // Not to be included in Spellchecker as per B=1277824
+ {"hi", "hi-IN"},
+ {"et", "et-EE"},
+ {"tr", "tr-TR"},
};
}
@@ -127,12 +128,12 @@ SpellChecker::Language SpellChecker::GetCorrespondingSpellCheckLanguage(
// 'az-Latn-AZ' vs 'az-Arab-AZ', either, but we don't use 3-part
// locale ids with a script code in the middle, yet.
// TODO(jungshik): Add a better fallback.
- Language language_part(language, 0, language.find(L'-'));
+ Language language_part(language, 0, language.find('-'));
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(g_supported_spellchecker_languages);
++i) {
Language spellcheck_language(
g_supported_spellchecker_languages[i].language_region);
- if (spellcheck_language.substr(0, spellcheck_language.find(L'-')) ==
+ if (spellcheck_language.substr(0, spellcheck_language.find('-')) ==
language_part)
return spellcheck_language;
}
@@ -143,14 +144,14 @@ SpellChecker::Language SpellChecker::GetCorrespondingSpellCheckLanguage(
int SpellChecker::GetSpellCheckLanguagesToDisplayInContextMenu(
Profile* profile,
- Languages* display_languages) {
+ DisplayLanguages* display_languages) {
StringPrefMember accept_languages_pref;
StringPrefMember dictionary_language_pref;
accept_languages_pref.Init(prefs::kAcceptLanguages, profile->GetPrefs(),
NULL);
dictionary_language_pref.Init(prefs::kSpellCheckDictionary,
profile->GetPrefs(), NULL);
- Language dictionary_language(dictionary_language_pref.GetValue());
+ std::wstring dictionary_language = dictionary_language_pref.GetValue();
// The current dictionary language should be there.
display_languages->push_back(dictionary_language);
@@ -158,18 +159,20 @@ int SpellChecker::GetSpellCheckLanguagesToDisplayInContextMenu(
// Now scan through the list of accept languages, and find possible mappings
// from this list to the existing list of spell check languages.
Languages accept_languages;
- SplitString(accept_languages_pref.GetValue(), L',', &accept_languages);
- for (Languages::const_iterator i(accept_languages.begin());
+ std::set<Language> unique_languages;
+ SplitString(WideToASCII(accept_languages_pref.GetValue()), ',',
+ &accept_languages);
+ for (Languages::const_iterator i = accept_languages.begin();
i != accept_languages.end(); ++i) {
Language language(GetCorrespondingSpellCheckLanguage(*i));
- if (!language.empty()) {
- // Check for duplication.
- if (std::find(display_languages->begin(), display_languages->end(),
- language) == display_languages->end())
- display_languages->push_back(language);
- }
+ if (!language.empty())
+ unique_languages.insert(language);
}
+ for (std::set<Language>::const_iterator i = unique_languages.begin();
+ i != unique_languages.end(); ++i)
+ display_languages->push_back(ASCIIToWide(*i));
+
// Sort using locale specific sorter.
l10n_util::SortStrings(g_browser_process->GetApplicationLocale(),
display_languages);
@@ -329,7 +332,7 @@ FilePath SpellChecker::GetVersionedFileName(const Language& input_language,
const FilePath& dict_dir) {
// The default dictionary version is 1-2. These versions have been augmented
// with additional words found by the translation team.
- static const wchar_t kDefaultVersionString[] = L"-1-2";
+ static const char kDefaultVersionString[] = "-1-2";
// The following dictionaries have either not been augmented with additional
// words (version 1-1) or have new words, as well as an upgraded dictionary
@@ -357,23 +360,22 @@ FilePath SpellChecker::GetVersionedFileName(const Language& input_language,
// Generate the bdict file name using default version string or special
// version string, depending on the language.
- std::wstring language = GetSpellCheckLanguageRegion(input_language);
- std::wstring versioned_bdict_file_name(language + kDefaultVersionString +
- L".bdic");
- std::string language_string(WideToUTF8(language));
+ std::string language = GetSpellCheckLanguageRegion(input_language);
+ std::string versioned_bdict_file_name(language + kDefaultVersionString +
+ ".bdic");
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(special_version_string); ++i) {
- if (language_string == special_version_string[i].language) {
+ if (language == special_version_string[i].language) {
versioned_bdict_file_name =
- language + UTF8ToWide(special_version_string[i].version) + L".bdic";
+ language + special_version_string[i].version + ".bdic";
break;
}
}
- return dict_dir.Append(FilePath::FromWStringHack(versioned_bdict_file_name));
+ return dict_dir.AppendASCII(versioned_bdict_file_name);
}
SpellChecker::SpellChecker(const FilePath& dict_dir,
- const std::wstring& language,
+ const Language& language,
URLRequestContext* request_context,
const FilePath& custom_dictionary_file_name)
: custom_dictionary_file_name_(custom_dictionary_file_name),
diff --git a/chrome/browser/spellchecker.h b/chrome/browser/spellchecker.h
index ede737a..7b8e72b 100644
--- a/chrome/browser/spellchecker.h
+++ b/chrome/browser/spellchecker.h
@@ -41,8 +41,13 @@ class MemoryMappedFile;
// deleted on the I/O thread itself.
class SpellChecker : public base::RefCountedThreadSafe<SpellChecker> {
public:
- typedef std::wstring Language;
- typedef std::vector<Language> Languages;
+ // ASCII string representing a language and/or region, e.g. "en-US".
+ typedef std::string Language;
+ typedef std::vector<Language> Languages;
+ // Languages that are suitable for display to the user.
+ // TODO(port): this should be string16, but we need to port
+ // l10n_util::SortStrings to string16 first.
+ typedef std::vector<std::wstring> DisplayLanguages;
// Creates the spellchecker by reading dictionaries from the given directory,
// and defaulting to the given language. Both strings must be provided.
@@ -85,9 +90,11 @@ class SpellChecker : public base::RefCountedThreadSafe<SpellChecker> {
// This function computes a vector of strings which are to be displayed in
// the context menu over a text area for changing spell check languages. It
// returns the index of the current spell check language in the vector.
+ // TODO(port): this should take a vector of string16, but the implementation
+ // has some dependencies in l10n util that need porting first.
static int GetSpellCheckLanguagesToDisplayInContextMenu(
Profile* profile,
- Languages* display_languages);
+ DisplayLanguages* display_languages);
// This function returns the corresponding language-region code for the
// spell check language. For example, for hi, it returns hi-IN.
diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc
index 457f6f5..3f94dc7 100644
--- a/chrome/browser/tab_contents/render_view_context_menu.cc
+++ b/chrome/browser/tab_contents/render_view_context_menu.cc
@@ -168,7 +168,7 @@ void RenderViewContextMenu::AppendEditableItems() {
l10n_util::GetString(IDS_CONTENT_CONTEXT_SPELLCHECK_MENU));
// Add Spell Check languages to sub menu.
- SpellChecker::Languages display_languages;
+ SpellChecker::DisplayLanguages display_languages;
SpellChecker::GetSpellCheckLanguagesToDisplayInContextMenu(profile_,
&display_languages);
DCHECK(display_languages.size() <
@@ -317,7 +317,7 @@ bool RenderViewContextMenu::ItemIsChecked(int id) const {
(id >= IDC_SPELLCHECK_LANGUAGES_LAST))
return false;
- SpellChecker::Languages display_languages;
+ SpellChecker::DisplayLanguages display_languages;
return SpellChecker::GetSpellCheckLanguagesToDisplayInContextMenu(
source_web_contents_->profile(), &display_languages) ==
(id - IDC_SPELLCHECK_LANGUAGES_FIRST);
@@ -328,7 +328,7 @@ void RenderViewContextMenu::ExecuteItemCommand(int id) {
if (id >= IDC_SPELLCHECK_LANGUAGES_FIRST &&
id < IDC_SPELLCHECK_LANGUAGES_LAST) {
const size_t language_number = id - IDC_SPELLCHECK_LANGUAGES_FIRST;
- SpellChecker::Languages display_languages;
+ SpellChecker::DisplayLanguages display_languages;
SpellChecker::GetSpellCheckLanguagesToDisplayInContextMenu(
source_web_contents_->profile(), &display_languages);
if (language_number < display_languages.size()) {
diff --git a/chrome/browser/views/options/language_combobox_model.cc b/chrome/browser/views/options/language_combobox_model.cc
index eccaaa7..556cd06 100644
--- a/chrome/browser/views/options/language_combobox_model.cc
+++ b/chrome/browser/views/options/language_combobox_model.cc
@@ -31,6 +31,17 @@ LanguageComboboxModel::LanguageComboboxModel(
InitNativeNames(locale_codes);
}
+LanguageComboboxModel::LanguageComboboxModel(
+ Profile* profile, const std::vector<std::string>& locale_codes)
+ : profile_(profile) {
+ std::vector<std::wstring> locale_codes_w;
+ for (std::vector<std::string>::const_iterator iter = locale_codes.begin();
+ iter != locale_codes.end(); ++iter) {
+ locale_codes_w.push_back(ASCIIToWide(*iter));
+ }
+ InitNativeNames(locale_codes_w);
+}
+
void LanguageComboboxModel::InitNativeNames(const std::vector<std::wstring>&
locale_codes) {
const std::string app_locale = WideToASCII(
diff --git a/chrome/browser/views/options/language_combobox_model.h b/chrome/browser/views/options/language_combobox_model.h
index 896834c..de23de8 100644
--- a/chrome/browser/views/options/language_combobox_model.h
+++ b/chrome/browser/views/options/language_combobox_model.h
@@ -29,6 +29,11 @@ class LanguageComboboxModel : public views::ComboBox::Model {
LanguageComboboxModel(Profile* profile,
const std::vector<std::wstring>& locale_codes);
+ // Temporary compatibility constructor.
+ // TODO(port): remove this once locale codes are all switched to ASCII.
+ LanguageComboboxModel(Profile* profile,
+ const std::vector<std::string>& locale_codes);
+
virtual ~LanguageComboboxModel() {}
void InitNativeNames(const std::vector<std::wstring>& locale_codes);
diff --git a/chrome/browser/views/options/languages_page_view.cc b/chrome/browser/views/options/languages_page_view.cc
index 1eb821f..25fc147 100644
--- a/chrome/browser/views/options/languages_page_view.cc
+++ b/chrome/browser/views/options/languages_page_view.cc
@@ -39,6 +39,7 @@
#include "skia/include/SkBitmap.h"
#include "unicode/uloc.h"
+// TODO(port): this should be a char* list.
static const wchar_t* const accept_language_list[] = {
L"af", // Afrikaans
L"am", // Amharic
@@ -719,8 +720,9 @@ void LanguagesPageView::NotifyPrefChanged(const std::wstring* pref_name) {
DCHECK(local_state);
const std::wstring& lang_region = local_state->GetString(
prefs::kSpellCheckDictionary);
- dictionary_language_.SetValue(
- SpellChecker::GetLanguageFromLanguageRegion(lang_region));
+ dictionary_language_.SetValue(ASCIIToWide(
+ SpellChecker::GetLanguageFromLanguageRegion(
+ WideToASCII(lang_region))));
index = dictionary_language_model_->GetSelectedLanguageIndex(
prefs::kSpellCheckDictionary);
}
diff --git a/chrome/common/l10n_util.h b/chrome/common/l10n_util.h
index 6d7166e..676c691 100644
--- a/chrome/common/l10n_util.h
+++ b/chrome/common/l10n_util.h
@@ -312,6 +312,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,
std::vector<std::wstring>* strings);