OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/renderer_context_menu/spelling_menu_observer.h" | 5 #include "chrome/browser/renderer_context_menu/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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 return false; | 244 return false; |
245 } | 245 } |
246 } | 246 } |
247 | 247 |
248 void SpellingMenuObserver::ExecuteCommand(int command_id) { | 248 void SpellingMenuObserver::ExecuteCommand(int command_id) { |
249 DCHECK(IsCommandIdSupported(command_id)); | 249 DCHECK(IsCommandIdSupported(command_id)); |
250 | 250 |
251 if (command_id >= IDC_SPELLCHECK_SUGGESTION_0 && | 251 if (command_id >= IDC_SPELLCHECK_SUGGESTION_0 && |
252 command_id <= IDC_SPELLCHECK_SUGGESTION_LAST) { | 252 command_id <= IDC_SPELLCHECK_SUGGESTION_LAST) { |
253 int suggestion_index = command_id - IDC_SPELLCHECK_SUGGESTION_0; | 253 int suggestion_index = command_id - IDC_SPELLCHECK_SUGGESTION_0; |
254 proxy_->GetRenderViewHost()->ReplaceMisspelling( | 254 proxy_->GetWebContents()->ReplaceMisspelling( |
255 suggestions_[suggestion_index]); | 255 suggestions_[suggestion_index]); |
256 // GetSpellCheckHost() can return null when the suggested word is provided | 256 // GetSpellCheckHost() can return null when the suggested word is provided |
257 // by Web SpellCheck API. | 257 // by Web SpellCheck API. |
258 Profile* profile = proxy_->GetProfile(); | 258 Profile* profile = proxy_->GetProfile(); |
259 if (profile) { | 259 if (profile) { |
260 SpellcheckService* spellcheck = | 260 SpellcheckService* spellcheck = |
261 SpellcheckServiceFactory::GetForContext(profile); | 261 SpellcheckServiceFactory::GetForContext(profile); |
262 if (spellcheck) { | 262 if (spellcheck) { |
263 if (spellcheck->GetMetrics()) | 263 if (spellcheck->GetMetrics()) |
264 spellcheck->GetMetrics()->RecordReplacedWordStats(1); | 264 spellcheck->GetMetrics()->RecordReplacedWordStats(1); |
265 spellcheck->GetFeedbackSender()->SelectedSuggestion( | 265 spellcheck->GetFeedbackSender()->SelectedSuggestion( |
266 misspelling_hash_, suggestion_index); | 266 misspelling_hash_, suggestion_index); |
267 } | 267 } |
268 } | 268 } |
269 return; | 269 return; |
270 } | 270 } |
271 | 271 |
272 // When we choose the suggestion sent from the Spelling service, we replace | 272 // When we choose the suggestion sent from the Spelling service, we replace |
273 // the misspelled word with the suggestion and add it to our custom-word | 273 // the misspelled word with the suggestion and add it to our custom-word |
274 // dictionary so this word is not marked as misspelled any longer. | 274 // dictionary so this word is not marked as misspelled any longer. |
275 if (command_id == IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION) { | 275 if (command_id == IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION) { |
276 proxy_->GetRenderViewHost()->ReplaceMisspelling(result_); | 276 proxy_->GetWebContents()->ReplaceMisspelling(result_); |
277 misspelled_word_ = result_; | 277 misspelled_word_ = result_; |
278 } | 278 } |
279 | 279 |
280 if (command_id == IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION || | 280 if (command_id == IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION || |
281 command_id == IDC_SPELLCHECK_ADD_TO_DICTIONARY) { | 281 command_id == IDC_SPELLCHECK_ADD_TO_DICTIONARY) { |
282 // GetHostForProfile() can return null when the suggested word is provided | 282 // GetHostForProfile() can return null when the suggested word is provided |
283 // by Web SpellCheck API. | 283 // by Web SpellCheck API. |
284 Profile* profile = proxy_->GetProfile(); | 284 Profile* profile = proxy_->GetProfile(); |
285 if (profile) { | 285 if (profile) { |
286 SpellcheckService* spellcheck = | 286 SpellcheckService* spellcheck = |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 // Append '.' characters to the end of "Checking". | 409 // Append '.' characters to the end of "Checking". |
410 loading_frame_ = (loading_frame_ + 1) & 3; | 410 loading_frame_ = (loading_frame_ + 1) & 3; |
411 base::string16 loading_message = | 411 base::string16 loading_message = |
412 loading_message_ + base::string16(loading_frame_,'.'); | 412 loading_message_ + base::string16(loading_frame_,'.'); |
413 | 413 |
414 // Update the menu item with the text. We disable this item to prevent users | 414 // Update the menu item with the text. We disable this item to prevent users |
415 // from selecting it. | 415 // from selecting it. |
416 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, false, false, | 416 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, false, false, |
417 loading_message); | 417 loading_message); |
418 } | 418 } |
OLD | NEW |