| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/tab_contents/spelling_menu_observer.h" | 5 #include "chrome/browser/tab_contents/spelling_menu_observer.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/i18n/case_conversion.h" | 9 #include "base/i18n/case_conversion.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 bool use_spelling_service = SpellingServiceClient::IsAvailable( | 148 bool use_spelling_service = SpellingServiceClient::IsAvailable( |
| 149 profile, SpellingServiceClient::SPELLCHECK); | 149 profile, SpellingServiceClient::SPELLCHECK); |
| 150 if (use_suggestions || use_spelling_service) | 150 if (use_suggestions || use_spelling_service) |
| 151 proxy_->AddSeparator(); | 151 proxy_->AddSeparator(); |
| 152 } else { | 152 } else { |
| 153 proxy_->AddSeparator(); | 153 proxy_->AddSeparator(); |
| 154 | 154 |
| 155 // |spellcheck_service| can be null when the suggested word is | 155 // |spellcheck_service| can be null when the suggested word is |
| 156 // provided by Web SpellCheck API. | 156 // provided by Web SpellCheck API. |
| 157 SpellcheckService* spellcheck_service = | 157 SpellcheckService* spellcheck_service = |
| 158 SpellcheckServiceFactory::GetForProfile(profile); | 158 SpellcheckServiceFactory::GetForContext(profile); |
| 159 if (spellcheck_service && spellcheck_service->GetMetrics()) | 159 if (spellcheck_service && spellcheck_service->GetMetrics()) |
| 160 spellcheck_service->GetMetrics()->RecordSuggestionStats(1); | 160 spellcheck_service->GetMetrics()->RecordSuggestionStats(1); |
| 161 } | 161 } |
| 162 | 162 |
| 163 // If word is misspelled, give option for "Add to dictionary" and a check item | 163 // If word is misspelled, give option for "Add to dictionary" and a check item |
| 164 // "Ask Google for suggestions". | 164 // "Ask Google for suggestions". |
| 165 proxy_->AddMenuItem(IDC_SPELLCHECK_ADD_TO_DICTIONARY, | 165 proxy_->AddMenuItem(IDC_SPELLCHECK_ADD_TO_DICTIONARY, |
| 166 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_ADD_TO_DICTIONARY)); | 166 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_ADD_TO_DICTIONARY)); |
| 167 | 167 |
| 168 #if defined(TOOLKIT_GTK) | 168 #if defined(TOOLKIT_GTK) |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 if (command_id >= IDC_SPELLCHECK_SUGGESTION_0 && | 253 if (command_id >= IDC_SPELLCHECK_SUGGESTION_0 && |
| 254 command_id <= IDC_SPELLCHECK_SUGGESTION_LAST) { | 254 command_id <= IDC_SPELLCHECK_SUGGESTION_LAST) { |
| 255 int suggestion_index = command_id - IDC_SPELLCHECK_SUGGESTION_0; | 255 int suggestion_index = command_id - IDC_SPELLCHECK_SUGGESTION_0; |
| 256 proxy_->GetRenderViewHost()->ReplaceMisspelling( | 256 proxy_->GetRenderViewHost()->ReplaceMisspelling( |
| 257 suggestions_[suggestion_index]); | 257 suggestions_[suggestion_index]); |
| 258 // GetSpellCheckHost() can return null when the suggested word is provided | 258 // GetSpellCheckHost() can return null when the suggested word is provided |
| 259 // by Web SpellCheck API. | 259 // by Web SpellCheck API. |
| 260 Profile* profile = proxy_->GetProfile(); | 260 Profile* profile = proxy_->GetProfile(); |
| 261 if (profile) { | 261 if (profile) { |
| 262 SpellcheckService* spellcheck = | 262 SpellcheckService* spellcheck = |
| 263 SpellcheckServiceFactory::GetForProfile(profile); | 263 SpellcheckServiceFactory::GetForContext(profile); |
| 264 if (spellcheck) { | 264 if (spellcheck) { |
| 265 if (spellcheck->GetMetrics()) | 265 if (spellcheck->GetMetrics()) |
| 266 spellcheck->GetMetrics()->RecordReplacedWordStats(1); | 266 spellcheck->GetMetrics()->RecordReplacedWordStats(1); |
| 267 spellcheck->GetFeedbackSender()->SelectedSuggestion( | 267 spellcheck->GetFeedbackSender()->SelectedSuggestion( |
| 268 misspelling_hash_, suggestion_index); | 268 misspelling_hash_, suggestion_index); |
| 269 } | 269 } |
| 270 } | 270 } |
| 271 return; | 271 return; |
| 272 } | 272 } |
| 273 | 273 |
| 274 // When we choose the suggestion sent from the Spelling service, we replace | 274 // When we choose the suggestion sent from the Spelling service, we replace |
| 275 // the misspelled word with the suggestion and add it to our custom-word | 275 // the misspelled word with the suggestion and add it to our custom-word |
| 276 // dictionary so this word is not marked as misspelled any longer. | 276 // dictionary so this word is not marked as misspelled any longer. |
| 277 if (command_id == IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION) { | 277 if (command_id == IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION) { |
| 278 proxy_->GetRenderViewHost()->ReplaceMisspelling(result_); | 278 proxy_->GetRenderViewHost()->ReplaceMisspelling(result_); |
| 279 misspelled_word_ = result_; | 279 misspelled_word_ = result_; |
| 280 } | 280 } |
| 281 | 281 |
| 282 if (command_id == IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION || | 282 if (command_id == IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION || |
| 283 command_id == IDC_SPELLCHECK_ADD_TO_DICTIONARY) { | 283 command_id == IDC_SPELLCHECK_ADD_TO_DICTIONARY) { |
| 284 // GetHostForProfile() can return null when the suggested word is provided | 284 // GetHostForProfile() can return null when the suggested word is provided |
| 285 // by Web SpellCheck API. | 285 // by Web SpellCheck API. |
| 286 Profile* profile = proxy_->GetProfile(); | 286 Profile* profile = proxy_->GetProfile(); |
| 287 if (profile) { | 287 if (profile) { |
| 288 SpellcheckService* spellcheck = | 288 SpellcheckService* spellcheck = |
| 289 SpellcheckServiceFactory::GetForProfile(profile); | 289 SpellcheckServiceFactory::GetForContext(profile); |
| 290 if (spellcheck) { | 290 if (spellcheck) { |
| 291 spellcheck->GetCustomDictionary()->AddWord(UTF16ToUTF8( | 291 spellcheck->GetCustomDictionary()->AddWord(UTF16ToUTF8( |
| 292 misspelled_word_)); | 292 misspelled_word_)); |
| 293 spellcheck->GetFeedbackSender()->AddedToDictionary(misspelling_hash_); | 293 spellcheck->GetFeedbackSender()->AddedToDictionary(misspelling_hash_); |
| 294 } | 294 } |
| 295 } | 295 } |
| 296 #if defined(OS_MACOSX) | 296 #if defined(OS_MACOSX) |
| 297 spellcheck_mac::AddWord(misspelled_word_); | 297 spellcheck_mac::AddWord(misspelled_word_); |
| 298 #endif | 298 #endif |
| 299 } | 299 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 } | 352 } |
| 353 } | 353 } |
| 354 } | 354 } |
| 355 } | 355 } |
| 356 | 356 |
| 357 void SpellingMenuObserver::OnMenuCancel() { | 357 void SpellingMenuObserver::OnMenuCancel() { |
| 358 Profile* profile = proxy_->GetProfile(); | 358 Profile* profile = proxy_->GetProfile(); |
| 359 if (!profile) | 359 if (!profile) |
| 360 return; | 360 return; |
| 361 SpellcheckService* spellcheck = | 361 SpellcheckService* spellcheck = |
| 362 SpellcheckServiceFactory::GetForProfile(profile); | 362 SpellcheckServiceFactory::GetForContext(profile); |
| 363 if (!spellcheck) | 363 if (!spellcheck) |
| 364 return; | 364 return; |
| 365 spellcheck->GetFeedbackSender()->IgnoredSuggestions(misspelling_hash_); | 365 spellcheck->GetFeedbackSender()->IgnoredSuggestions(misspelling_hash_); |
| 366 } | 366 } |
| 367 | 367 |
| 368 void SpellingMenuObserver::OnTextCheckComplete( | 368 void SpellingMenuObserver::OnTextCheckComplete( |
| 369 SpellingServiceClient::ServiceType type, | 369 SpellingServiceClient::ServiceType type, |
| 370 bool success, | 370 bool success, |
| 371 const string16& text, | 371 const string16& text, |
| 372 const std::vector<SpellCheckResult>& results) { | 372 const std::vector<SpellCheckResult>& results) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 void SpellingMenuObserver::OnAnimationTimerExpired() { | 410 void SpellingMenuObserver::OnAnimationTimerExpired() { |
| 411 // Append '.' characters to the end of "Checking". | 411 // Append '.' characters to the end of "Checking". |
| 412 loading_frame_ = (loading_frame_ + 1) & 3; | 412 loading_frame_ = (loading_frame_ + 1) & 3; |
| 413 string16 loading_message = loading_message_ + string16(loading_frame_,'.'); | 413 string16 loading_message = loading_message_ + string16(loading_frame_,'.'); |
| 414 | 414 |
| 415 // Update the menu item with the text. We disable this item to prevent users | 415 // Update the menu item with the text. We disable this item to prevent users |
| 416 // from selecting it. | 416 // from selecting it. |
| 417 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, false, false, | 417 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, false, false, |
| 418 loading_message); | 418 loading_message); |
| 419 } | 419 } |
| OLD | NEW |