| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| 11 #include "base/json/string_escape.h" | 11 #include "base/json/string_escape.h" |
| 12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/app/chrome_command_ids.h" | 15 #include "chrome/app/chrome_command_ids.h" |
| 16 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/spellchecker/spellcheck_host.h" | 18 #include "chrome/browser/spellchecker/spellcheck_host.h" |
| 19 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" | 19 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" |
| 20 #include "chrome/browser/spellchecker/spellchecker_platform_engine.h" | 20 #include "chrome/browser/spellchecker/spellchecker_mac.h" |
| 21 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 21 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
| 22 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
| 23 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 24 #include "content/browser/renderer_host/render_view_host.h" | 24 #include "content/browser/renderer_host/render_view_host.h" |
| 25 #include "content/public/common/url_fetcher.h" | 25 #include "content/public/common/url_fetcher.h" |
| 26 #include "googleurl/src/gurl.h" | 26 #include "googleurl/src/gurl.h" |
| 27 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
| 29 #include "unicode/uloc.h" | 29 #include "unicode/uloc.h" |
| 30 #include "webkit/glue/context_menu.h" | 30 #include "webkit/glue/context_menu.h" |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 misspelled_word_ = result_; | 212 misspelled_word_ = result_; |
| 213 } | 213 } |
| 214 | 214 |
| 215 if (command_id == IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION || | 215 if (command_id == IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION || |
| 216 command_id == IDC_SPELLCHECK_ADD_TO_DICTIONARY) { | 216 command_id == IDC_SPELLCHECK_ADD_TO_DICTIONARY) { |
| 217 // GetSpellCheckHost() can return null when the suggested word is | 217 // GetSpellCheckHost() can return null when the suggested word is |
| 218 // provided by Web SpellCheck API. | 218 // provided by Web SpellCheck API. |
| 219 Profile* profile = proxy_->GetProfile(); | 219 Profile* profile = proxy_->GetProfile(); |
| 220 if (profile && profile->GetSpellCheckHost()) | 220 if (profile && profile->GetSpellCheckHost()) |
| 221 profile->GetSpellCheckHost()->AddWord(UTF16ToUTF8(misspelled_word_)); | 221 profile->GetSpellCheckHost()->AddWord(UTF16ToUTF8(misspelled_word_)); |
| 222 SpellCheckerPlatform::AddWord(misspelled_word_); | 222 #if defined(OS_MACOSX) |
| 223 SpellCheckerMac::AddWord(misspelled_word_); |
| 224 #endif |
| 223 } | 225 } |
| 224 } | 226 } |
| 225 | 227 |
| 226 bool SpellingMenuObserver::Invoke(const string16& text, | 228 bool SpellingMenuObserver::Invoke(const string16& text, |
| 227 const std::string& locale, | 229 const std::string& locale, |
| 228 net::URLRequestContextGetter* context) { | 230 net::URLRequestContextGetter* context) { |
| 229 // Create the parameters needed by Spelling API. Spelling API needs three | 231 // Create the parameters needed by Spelling API. Spelling API needs three |
| 230 // parameters: ISO language code, ISO3 country code, and text to be checked by | 232 // parameters: ISO language code, ISO3 country code, and text to be checked by |
| 231 // the service. On the other hand, Chrome uses an ISO locale ID and it may | 233 // the service. On the other hand, Chrome uses an ISO locale ID and it may |
| 232 // not include a country ID, e.g. "fr", "de", etc. To create the input | 234 // not include a country ID, e.g. "fr", "de", etc. To create the input |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 loading_frame_ = (loading_frame_ + 1) & 3; | 401 loading_frame_ = (loading_frame_ + 1) & 3; |
| 400 string16 loading_message = loading_message_; | 402 string16 loading_message = loading_message_; |
| 401 for (int i = 0; i < loading_frame_; ++i) | 403 for (int i = 0; i < loading_frame_; ++i) |
| 402 loading_message.push_back('.'); | 404 loading_message.push_back('.'); |
| 403 | 405 |
| 404 // Update the menu item with the text. We disable this item to prevent users | 406 // Update the menu item with the text. We disable this item to prevent users |
| 405 // from selecting it. | 407 // from selecting it. |
| 406 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, false, false, | 408 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, false, false, |
| 407 loading_message); | 409 loading_message); |
| 408 } | 410 } |
| OLD | NEW |