| 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/spellchecker/spelling_service_client.h" | 5 #include "chrome/browser/spellchecker/spelling_service_client.h" |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/json/string_escape.h" | 8 #include "base/json/string_escape.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_util.h" |
| 10 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
| 11 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 12 #include "base/values.h" | 13 #include "base/values.h" |
| 13 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 16 #include "chrome/common/spellcheck_result.h" | 17 #include "chrome/common/spellcheck_result.h" |
| 17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/common/url_fetcher.h" | 19 #include "content/public/common/url_fetcher.h" |
| 19 #include "net/base/load_flags.h" | 20 #include "net/base/load_flags.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 // Also, we convert the given text to a JSON string, i.e. quote all its | 65 // Also, we convert the given text to a JSON string, i.e. quote all its |
| 65 // non-ASCII characters. | 66 // non-ASCII characters. |
| 66 UErrorCode error = U_ZERO_ERROR; | 67 UErrorCode error = U_ZERO_ERROR; |
| 67 char id[ULOC_LANG_CAPACITY + ULOC_SCRIPT_CAPACITY + ULOC_COUNTRY_CAPACITY]; | 68 char id[ULOC_LANG_CAPACITY + ULOC_SCRIPT_CAPACITY + ULOC_COUNTRY_CAPACITY]; |
| 68 uloc_addLikelySubtags(locale.c_str(), id, arraysize(id), &error); | 69 uloc_addLikelySubtags(locale.c_str(), id, arraysize(id), &error); |
| 69 | 70 |
| 70 error = U_ZERO_ERROR; | 71 error = U_ZERO_ERROR; |
| 71 uloc_getLanguage(id, language, arraysize(language), &error); | 72 uloc_getLanguage(id, language, arraysize(language), &error); |
| 72 country = uloc_getISO3Country(id); | 73 country = uloc_getISO3Country(id); |
| 73 } | 74 } |
| 75 if (type == SPELLCHECK && base::strcasecmp(language, ULOC_ENGLISH)) |
| 76 return false; |
| 74 | 77 |
| 75 // Format the JSON request to be sent to the Spelling service. | 78 // Format the JSON request to be sent to the Spelling service. |
| 76 std::string encoded_text; | 79 std::string encoded_text; |
| 77 base::JsonDoubleQuote(text, false, &encoded_text); | 80 base::JsonDoubleQuote(text, false, &encoded_text); |
| 78 | 81 |
| 79 static const char kSpellingRequest[] = | 82 static const char kSpellingRequest[] = |
| 80 "{" | 83 "{" |
| 81 "\"method\":\"spelling.check\"," | 84 "\"method\":\"spelling.check\"," |
| 82 "\"apiVersion\":\"v%d\"," | 85 "\"apiVersion\":\"v%d\"," |
| 83 "\"params\":{" | 86 "\"params\":{" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 if (!suggestions->GetDictionary(0, &suggestion) || | 199 if (!suggestions->GetDictionary(0, &suggestion) || |
| 197 !suggestion->GetString("suggestion", &replacement)) { | 200 !suggestion->GetString("suggestion", &replacement)) { |
| 198 return false; | 201 return false; |
| 199 } | 202 } |
| 200 SpellCheckResult result( | 203 SpellCheckResult result( |
| 201 SpellCheckResult::SPELLING, start, length, replacement); | 204 SpellCheckResult::SPELLING, start, length, replacement); |
| 202 results->push_back(result); | 205 results->push_back(result); |
| 203 } | 206 } |
| 204 return true; | 207 return true; |
| 205 } | 208 } |
| OLD | NEW |