summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/browser_uitest.cc2
-rw-r--r--chrome/browser/profile.cc7
-rw-r--r--chrome/browser/render_view_context_menu.cc5
-rw-r--r--chrome/browser/render_view_context_menu_controller.cc45
-rw-r--r--chrome/browser/spellchecker.cc132
-rw-r--r--chrome/browser/spellchecker.h12
-rw-r--r--chrome/browser/views/toolbar_view.cc6
7 files changed, 99 insertions, 110 deletions
diff --git a/chrome/browser/browser_uitest.cc b/chrome/browser/browser_uitest.cc
index d849860..740b2ea 100644
--- a/chrome/browser/browser_uitest.cc
+++ b/chrome/browser/browser_uitest.cc
@@ -256,7 +256,7 @@ TEST_F(BrowserTest, DuplicateTab) {
ASSERT_TRUE(window_count == initial_window_count);
tab_proxy.reset(browser_proxy->GetTab(1));
-
+ ASSERT_TRUE(tab_proxy != NULL);
ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(kWaitForActionMsec));
// Verify the stack of urls.
diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc
index 60f2022..d8f2f64 100644
--- a/chrome/browser/profile.cc
+++ b/chrome/browser/profile.cc
@@ -938,13 +938,12 @@ void ProfileImpl::InitializeSpellChecker(bool need_to_broadcast) {
if (enable_spellcheck) {
std::wstring dict_dir;
PathService::Get(chrome::DIR_APP_DICTIONARIES, &dict_dir);
- std::wstring language = prefs->GetString(prefs::kSpellCheckDictionary);
-
// Note that, as the object pointed to by previously by spellchecker_
// 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, language, GetRequestContext(),
- L"");
+ spellchecker_ = new SpellChecker(dict_dir,
+ prefs->GetString(prefs::kSpellCheckDictionary), GetRequestContext(),
+ std::wstring());
spellchecker_->AddRef(); // Manual refcounting.
} else {
spellchecker_ = NULL;
diff --git a/chrome/browser/render_view_context_menu.cc b/chrome/browser/render_view_context_menu.cc
index 8a073a2..75bc4d8 100644
--- a/chrome/browser/render_view_context_menu.cc
+++ b/chrome/browser/render_view_context_menu.cc
@@ -151,16 +151,15 @@ void RenderViewContextMenu::AppendEditableItems() {
l10n_util::GetString(IDS_CONTENT_CONTEXT_SPELLCHECK_MENU));
// Add Spell Check languages to sub menu.
- std::vector<std::wstring> language_vector;
+ std::vector<std::wstring> language_vector;
SpellChecker::GetSpellCheckLanguagesToDisplayInContextMenu(profile_,
&language_vector);
- // Add the spell check languages.
DCHECK(language_vector.size() <
IDC_SPELLCHECK_LANGUAGES_LAST - IDC_SPELLCHECK_LANGUAGES_FIRST);
const std::wstring app_locale = g_browser_process->GetApplicationLocale();
for (size_t i = 0; i < language_vector.size(); ++i) {
std::wstring local_language(l10n_util::GetLocalName(
- language_vector.at(i), app_locale, true));
+ language_vector[i], app_locale, true));
spellchecker_sub_menu_->AppendMenuItem(
IDC_SPELLCHECK_LANGUAGES_FIRST + i, local_language, RADIO);
}
diff --git a/chrome/browser/render_view_context_menu_controller.cc b/chrome/browser/render_view_context_menu_controller.cc
index bedad0e..cbcef59 100644
--- a/chrome/browser/render_view_context_menu_controller.cc
+++ b/chrome/browser/render_view_context_menu_controller.cc
@@ -115,12 +115,12 @@ bool RenderViewContextMenuController::IsCommandEnabled(int id) const {
case IDS_CONTENT_CONTEXT_FORWARD:
return source_web_contents_->controller()->CanGoForward();
- case IDS_CONTENT_CONTEXT_RELOAD:
- return true;
+
case IDS_CONTENT_CONTEXT_VIEWPAGESOURCE:
case IDS_CONTENT_CONTEXT_VIEWFRAMESOURCE:
case IDS_CONTENT_CONTEXT_INSPECTELEMENT:
return IsDevCommandEnabled(id);
+
case IDS_CONTENT_CONTEXT_OPENLINKNEWTAB:
case IDS_CONTENT_CONTEXT_OPENLINKNEWWINDOW:
case IDS_CONTENT_CONTEXT_COPYLINKLOCATION:
@@ -137,8 +137,10 @@ bool RenderViewContextMenuController::IsCommandEnabled(int id) const {
case IDS_CONTENT_CONTEXT_OPENIMAGENEWTAB:
case IDS_CONTENT_CONTEXT_COPYIMAGELOCATION:
return params_.image_url.is_valid();
+
case IDS_CONTENT_CONTEXT_SAVEPAGEAS:
return SavePackage::IsSavableURL(source_web_contents_->GetURL());
+
case IDS_CONTENT_CONTEXT_OPENFRAMENEWTAB:
case IDS_CONTENT_CONTEXT_OPENFRAMENEWWINDOW:
return params_.frame_url.is_valid();
@@ -172,6 +174,13 @@ bool RenderViewContextMenuController::IsCommandEnabled(int id) const {
return !source_web_contents_->profile()->IsOffTheRecord() &&
params_.frame_url.is_valid();
+ case IDS_CONTENT_CONTEXT_ADD_TO_DICTIONARY:
+ return !params_.misspelled_word.empty();
+
+ case IDS_CONTENT_CONTEXT_VIEWPAGEINFO:
+ return (source_web_contents_->controller()->GetActiveEntry() != NULL);
+
+ case IDS_CONTENT_CONTEXT_RELOAD:
case IDS_CONTENT_CONTEXT_COPYIMAGE:
case IDS_CONTENT_CONTEXT_PRINT:
case IDS_CONTENT_CONTEXT_SEARCHWEBFOR:
@@ -180,17 +189,11 @@ bool RenderViewContextMenuController::IsCommandEnabled(int id) const {
case IDC_SPELLCHECK_SUGGESTION_2:
case IDC_SPELLCHECK_SUGGESTION_3:
case IDC_SPELLCHECK_SUGGESTION_4:
- return true;
case IDC_SPELLCHECK_MENU:
- return true;
- case IDS_CONTENT_CONTEXT_ADD_TO_DICTIONARY:
- return !params_.misspelled_word.empty();
case IDS_CONTENT_CONTEXT_LANGUAGE_SETTINGS:
- return true;
- case IDS_CONTENT_CONTEXT_VIEWPAGEINFO:
- return (source_web_contents_->controller()->GetActiveEntry() != NULL);
case IDS_CONTENT_CONTEXT_VIEWFRAMEINFO:
return true;
+
case IDS_CONTENT_CONTEXT_SAVEFRAMEAS:
case IDS_CONTENT_CONTEXT_PRINTFRAME:
case IDS_CONTENT_CONTEXT_ADDSEARCHENGINE: // Not implemented.
@@ -200,14 +203,16 @@ bool RenderViewContextMenuController::IsCommandEnabled(int id) const {
}
bool RenderViewContextMenuController::IsItemChecked(int id) const {
- std::vector<std::wstring> display_language_vector;
- int spellcheck_language_index = SpellChecker::
- GetSpellCheckLanguagesToDisplayInContextMenu(
- source_web_contents_->profile(), &display_language_vector);
- if (id - IDC_SPELLCHECK_LANGUAGES_FIRST == spellcheck_language_index)
- return true;
+ // Don't bother getting the display language vector if this isn't a spellcheck
+ // language.
+ if ((id < IDC_SPELLCHECK_LANGUAGES_FIRST) ||
+ (id >= IDC_SPELLCHECK_LANGUAGES_LAST))
+ return false;
- return false;
+ std::vector<std::wstring> display_language_vector;
+ return SpellChecker::GetSpellCheckLanguagesToDisplayInContextMenu(
+ source_web_contents_->profile(), &display_language_vector) ==
+ (id - IDC_SPELLCHECK_LANGUAGES_FIRST);
}
bool RenderViewContextMenuController::GetAcceleratorInfo(
@@ -248,20 +253,20 @@ void RenderViewContextMenuController::ExecuteCommand(int id) {
// Check to see if one of the spell check language ids have been clicked.
if (id >= IDC_SPELLCHECK_LANGUAGES_FIRST &&
id < IDC_SPELLCHECK_LANGUAGES_LAST) {
+ const size_t language_number = id - IDC_SPELLCHECK_LANGUAGES_FIRST;
std::vector<std::wstring> display_language_vector;
SpellChecker::GetSpellCheckLanguagesToDisplayInContextMenu(
source_web_contents_->profile(), &display_language_vector);
- if (id - IDC_SPELLCHECK_LANGUAGES_FIRST <
- static_cast<int>(display_language_vector.size())) {
+ if (language_number < display_language_vector.size()) {
StringPrefMember dictionary_language;
dictionary_language.Init(prefs::kSpellCheckDictionary,
source_web_contents_->profile()->GetPrefs(), NULL);
- dictionary_language.SetValue(display_language_vector.at(
- id - IDC_SPELLCHECK_LANGUAGES_FIRST));
+ dictionary_language.SetValue(display_language_vector[language_number]);
}
return;
}
+
switch (id) {
case IDS_CONTENT_CONTEXT_OPENLINKNEWTAB:
OpenURL(params_.link_url, NEW_BACKGROUND_TAB, PageTransition::LINK);
diff --git a/chrome/browser/spellchecker.cc b/chrome/browser/spellchecker.cc
index 9718cd1..aac3692 100644
--- a/chrome/browser/spellchecker.cc
+++ b/chrome/browser/spellchecker.cc
@@ -75,11 +75,8 @@ const wchar_t* const g_supported_spellchecker_languages[] = {
}
void SpellChecker::SpellCheckLanguages(std::vector<std::wstring>* languages) {
- for (size_t i = 0;
- i < arraysize(g_supported_spellchecker_languages);
- i++) {
+ for (size_t i = 0; i < arraysize(g_supported_spellchecker_languages); ++i)
languages->push_back(g_supported_spellchecker_languages[i]);
- }
}
std::wstring SpellChecker::GetCorrespondingSpellCheckLanguage(
@@ -98,15 +95,12 @@ std::wstring 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.
- std::wstring::size_type hyphen_pos = language.find(L'-');
- std::wstring language_part(language, 0, hyphen_pos);
+ std::wstring language_part(language, 0, language.find(L'-'));
for (int i = 0; i < arraysize(g_supported_spellchecker_languages); ++i) {
- std::wstring spellchecker_language_name =
- g_supported_spellchecker_languages[i];
- std::wstring::size_type hyphen_pos = spellchecker_language_name.find(L'-');
- std::wstring spellcheck_language(spellchecker_language_name, 0, hyphen_pos);
- if (spellcheck_language == language_part)
- return spellchecker_language_name;
+ std::wstring spellcheck_language(g_supported_spellchecker_languages[i]);
+ if (spellcheck_language.substr(0, spellcheck_language.find(L'-')) ==
+ language_part)
+ return spellcheck_language;
}
// No match found - return blank.
@@ -114,35 +108,32 @@ std::wstring SpellChecker::GetCorrespondingSpellCheckLanguage(
}
int SpellChecker::GetSpellCheckLanguagesToDisplayInContextMenu(
- Profile* profile, std::vector<std::wstring>* display_language_list) {
- std::vector<std::wstring> language_list;
- StringPrefMember accept_languages;
- StringPrefMember dictionary_language;
- accept_languages.Init(prefs::kAcceptLanguages,
- profile->GetPrefs(), NULL);
- dictionary_language.Init(prefs::kSpellCheckDictionary,
- profile->GetPrefs(), NULL);
+ Profile* profile,
+ std::vector<std::wstring>* display_language_list) {
+ 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);
+ std::wstring dictionary_language(dictionary_language_pref.GetValue());
// The current dictionary language should be there.
- display_language_list->push_back(dictionary_language.GetValue().c_str());
+ display_language_list->push_back(dictionary_language);
// Now scan through the list of accept languages, and find possible mappings
// from this list to the existing list of spell check languages.
std::vector<std::wstring> accept_language_vector;
- SplitString(accept_languages.GetValue(), L',', &accept_language_vector);
- for (size_t i = 0; i < accept_language_vector.size(); i++) {
+ SplitString(accept_languages_pref.GetValue(), L',', &accept_language_vector);
+ for (size_t i = 0; i < accept_language_vector.size(); ++i) {
std::wstring language = GetCorrespondingSpellCheckLanguage(
- accept_language_vector.at(i));
+ accept_language_vector[i]);
if (!language.empty()) {
// Check for duplication.
- bool duplicate = false;
- for (size_t j = 0; j < display_language_list->size(); j++) {
- if (display_language_list->at(j) == language)
- duplicate = true;
- }
-
- if (!duplicate)
- display_language_list->push_back(language.c_str());
+ if (std::find(display_language_list->begin(),
+ display_language_list->end(), language) ==
+ display_language_list->end())
+ display_language_list->push_back(language);
}
}
@@ -150,13 +141,12 @@ int SpellChecker::GetSpellCheckLanguagesToDisplayInContextMenu(
l10n_util::SortStrings(g_browser_process->GetApplicationLocale(),
display_language_list);
- int current_spell_check_language_index = -1;
- for (size_t i = 0; i < display_language_list->size(); i++) {
- if (dictionary_language.GetValue() == display_language_list->at(i))
- current_spell_check_language_index = i;
+ for (size_t i = 0; i < display_language_list->size(); ++i) {
+ if ((*display_language_list)[i] == dictionary_language)
+ return i;
}
- return current_spell_check_language_index;
+ return -1;
}
// This is a helper class which acts as a proxy for invoking a task from the
@@ -341,8 +331,8 @@ std::wstring SpellChecker::GetVersionedFileName(const std::wstring& language,
std::wstring versioned_bdict_file_name(language + kDefaultVersionString +
L".bdic");
std::string language_string(WideToUTF8(language));
- for (int i = 0; i < arraysize(special_version_string); i++ ) {
- if (language_string.compare(special_version_string[i].language) == 0) {
+ for (int i = 0; i < arraysize(special_version_string); ++i) {
+ if (language_string == special_version_string[i].language) {
versioned_bdict_file_name =
language + UTF8ToWide(special_version_string[i].version) + L".bdic";
break;
@@ -430,7 +420,7 @@ bool SpellChecker::Initialize() {
// Return false if tried to init and failed - don't try multiple times in
// this session.
if (tried_to_init_)
- return hunspell_ != NULL ? true : false;
+ return hunspell_ != NULL;
StatsScope<StatsCounterTimer> timer(chrome::Counters::spellcheck_init());
@@ -439,13 +429,10 @@ bool SpellChecker::Initialize() {
if (file_loop_ && !tried_to_download_ && url_request_context_) {
Task* dic_task = dic_download_state_changer_factory_.NewRunnableMethod(
&SpellChecker::set_file_is_downloading, false);
- ddc_dic_ = new DictionaryDownloadController(dic_task,
- bdict_file_name_,
- url_request_context_,
- ui_loop_);
+ ddc_dic_ = new DictionaryDownloadController(dic_task, bdict_file_name_,
+ url_request_context_, ui_loop_);
set_file_is_downloading(true);
- file_loop_->PostTask(FROM_HERE, NewRunnableMethod(
- ddc_dic_.get(),
+ file_loop_->PostTask(FROM_HERE, NewRunnableMethod(ddc_dic_.get(),
&DictionaryDownloadController::StartDownload));
}
}
@@ -457,16 +444,13 @@ bool SpellChecker::Initialize() {
// Control has come so far - both files probably exist.
TimeTicks begin_time = TimeTicks::Now();
-
const unsigned char* bdict_data;
size_t bdict_length;
if (MapBdictFile(&bdict_data, &bdict_length)) {
hunspell_ = new Hunspell(bdict_data, bdict_length);
AddCustomWordsToHunspell();
}
-
- TimeTicks end_time = TimeTicks::Now();
- DHISTOGRAM_TIMES(L"Spellcheck.InitTime", end_time - begin_time);
+ DHISTOGRAM_TIMES(L"Spellcheck.InitTime", TimeTicks::Now() - begin_time);
tried_to_init_ = true;
return false;
@@ -483,8 +467,8 @@ void SpellChecker::AddCustomWordsToHunspell() {
SplitString(contents, '\n', &list_of_words);
if (hunspell_) {
for (std::vector<std::string>::iterator it = list_of_words.begin();
- it < list_of_words.end(); ++it) {
- hunspell_->put_word((*it).c_str());
+ it != list_of_words.end(); ++it) {
+ hunspell_->put_word(it->c_str());
}
}
}
@@ -494,10 +478,10 @@ bool SpellChecker::MapBdictFile(const unsigned char** data, size_t* length) {
FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (bdict_file_ == INVALID_HANDLE_VALUE)
return false;
- DWORD size = GetFileSize(bdict_file_, NULL);
- bdict_mapping_ = CreateFileMapping(bdict_file_, NULL, PAGE_READONLY, 0,
- size, NULL);
+ DWORD size = GetFileSize(bdict_file_, NULL);
+ bdict_mapping_ =
+ CreateFileMapping(bdict_file_, NULL, PAGE_READONLY, 0, size, NULL);
if (!bdict_mapping_) {
CloseHandle(bdict_file_);
bdict_file_ = NULL;
@@ -525,11 +509,12 @@ bool SpellChecker::MapBdictFile(const unsigned char** data, size_t* length) {
// (e.g. "in'n'out") but each word is valid.
bool SpellChecker::IsValidContraction(const std::wstring& contraction) {
SpellcheckWordIterator word_iterator;
+ word_iterator.Initialize(&character_attributes_, contraction.c_str(),
+ contraction.length(), false);
+
std::wstring word;
int word_start;
int word_length;
- word_iterator.Initialize(&character_attributes_, contraction.c_str(),
- contraction.length(), false);
while (word_iterator.GetNextWord(&word, &word_start, &word_length)) {
if (!hunspell_->spell(WideToUTF8(word).c_str()))
return false;
@@ -570,18 +555,18 @@ bool SpellChecker::SpellCheckWord(
std::wstring word;
int word_start;
int word_length;
- word_iterator.Initialize(&character_attributes_, in_word, in_word_len,
- true);
+ word_iterator.Initialize(&character_attributes_, in_word, in_word_len, true);
while (word_iterator.GetNextWord(&word, &word_start, &word_length)) {
// Found a word (or a contraction) that hunspell can check its spelling.
std::string encoded_word = WideToUTF8(word);
- TimeTicks begin_time = TimeTicks::Now();
- bool word_ok = !!hunspell_->spell(encoded_word.c_str());
- DHISTOGRAM_TIMES(L"Spellcheck.CheckTime", TimeTicks::Now() - begin_time);
-
- if (word_ok)
- continue;
+ {
+ TimeTicks begin_time = TimeTicks::Now();
+ bool word_ok = !!hunspell_->spell(encoded_word.c_str());
+ DHISTOGRAM_TIMES(L"Spellcheck.CheckTime", TimeTicks::Now() - begin_time);
+ if (word_ok)
+ continue;
+ }
// If the given word is a concatenated word of two or more valid words
// (e.g. "hello:hello"), we should treat it as a valid word.
@@ -593,7 +578,7 @@ bool SpellChecker::SpellCheckWord(
// Get the list of suggested words.
if (optional_suggestions) {
- char **suggestions;
+ char** suggestions;
TimeTicks begin_time = TimeTicks::Now();
int number_of_suggestions = hunspell_->suggest(&suggestions,
encoded_word.c_str());
@@ -610,6 +595,7 @@ bool SpellChecker::SpellCheckWord(
}
return false;
}
+
return true;
}
@@ -649,13 +635,11 @@ void SpellChecker::AddWord(const std::wstring& word) {
if (!word_to_add.empty())
hunspell_->put_word(word_to_add.c_str());
- // Now add the word to the custom dictionary file in the file loop.
- if (file_loop_) {
- file_loop_->PostTask(FROM_HERE, new AddWordToCustomDictionaryTask(
- custom_dictionary_file_name_, word));
- } else { // just run it in this thread.
- Task* write_word_task = new AddWordToCustomDictionaryTask(
- custom_dictionary_file_name_, word);
+ // Now add the word to the custom dictionary file.
+ Task* write_word_task =
+ new AddWordToCustomDictionaryTask(custom_dictionary_file_name_, word);
+ if (file_loop_)
+ file_loop_->PostTask(FROM_HERE, write_word_task);
+ else
write_word_task->Run();
- }
}
diff --git a/chrome/browser/spellchecker.h b/chrome/browser/spellchecker.h
index 07be6120..1283712 100644
--- a/chrome/browser/spellchecker.h
+++ b/chrome/browser/spellchecker.h
@@ -78,14 +78,14 @@ 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.
- static int SpellChecker::GetSpellCheckLanguagesToDisplayInContextMenu(
- Profile* profile, std::vector<std::wstring>* display_language_list);
+ static int GetSpellCheckLanguagesToDisplayInContextMenu(
+ Profile* profile,
+ std::vector<std::wstring>* display_language_list);
+ private:
// Download dictionary files when required.
class DictionaryDownloadController;
- SpellChecker::SpellChecker();
-
// Initializes the Hunspell Dictionary.
bool Initialize();
@@ -124,7 +124,7 @@ class SpellChecker : public base::RefCountedThreadSafe<SpellChecker> {
const unsigned char* bdict_mapped_data_;
// The hunspell dictionary in use.
- Hunspell *hunspell_;
+ Hunspell* hunspell_;
// Represents character attributes used for filtering out characters which
// are not supported by this SpellChecker object.
@@ -168,7 +168,7 @@ class SpellChecker : public base::RefCountedThreadSafe<SpellChecker> {
// using NewRunableMethod on these objects.
ScopedRunnableMethodFactory<SpellChecker> dic_download_state_changer_factory_;
- DISALLOW_EVIL_CONSTRUCTORS(SpellChecker);
+ DISALLOW_COPY_AND_ASSIGN(SpellChecker);
};
#endif // #ifndef CHROME_BROWSER_SPELLCHECKER_H__
diff --git a/chrome/browser/views/toolbar_view.cc b/chrome/browser/views/toolbar_view.cc
index 766ecf8..6032d3b 100644
--- a/chrome/browser/views/toolbar_view.cc
+++ b/chrome/browser/views/toolbar_view.cc
@@ -610,18 +610,20 @@ void BrowserToolbarView::OnGetProfilesDone(
// Store the latest list of profiles in the browser.
browser_->set_user_data_dir_profiles(profiles);
- std::vector<std::wstring>::const_iterator iter = profiles.begin();
// Add direct sub menu items for profiles.
+ std::vector<std::wstring>::const_iterator iter = profiles.begin();
for (int i = IDC_NEW_WINDOW_PROFILE_0;
- i <= IDC_NEW_WINDOW_PROFILE_LAST && iter != profiles.end();
+ (i <= IDC_NEW_WINDOW_PROFILE_LAST) && (iter != profiles.end());
++i, ++iter)
profiles_menu_->AppendMenuItemWithLabel(i, *iter);
+
// If there are more profiles then show "Other" link.
if (iter != profiles.end()) {
profiles_menu_->AppendSeparator();
profiles_menu_->AppendMenuItemWithLabel(
IDC_SELECT_PROFILE, l10n_util::GetString(IDS_SELECT_PROFILE));
}
+
// Always show a link to select a new profile.
profiles_menu_->AppendSeparator();
profiles_menu_->AppendMenuItemWithLabel(