| 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/string_util.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 if (!pref->GetBoolean(prefs::kEnableSpellCheck) || | 117 if (!pref->GetBoolean(prefs::kEnableSpellCheck) || |
| 118 !pref->GetBoolean(prefs::kSpellCheckUseSpellingService)) | 118 !pref->GetBoolean(prefs::kSpellCheckUseSpellingService)) |
| 119 return false; | 119 return false; |
| 120 | 120 |
| 121 // Enable the suggest service only on languages not supported by the | 121 // Enable the suggest service only on languages not supported by the |
| 122 // spellcheck service. When this client calls the spellcheck service, it | 122 // spellcheck service. When this client calls the spellcheck service, it |
| 123 // returns not only spellcheck results but also spelling suggestions provided | 123 // returns not only spellcheck results but also spelling suggestions provided |
| 124 // by the suggest service. That is, it is not useful to use the suggest | 124 // by the suggest service. That is, it is not useful to use the suggest |
| 125 // service when this client can use the spellcheck service. | 125 // service when this client can use the spellcheck service. |
| 126 std::string locale = pref->GetString(prefs::kSpellCheckDictionary); | 126 std::string locale = pref->GetString(prefs::kSpellCheckDictionary); |
| 127 #if defined(OS_MACOSX) |
| 128 bool spellcheck_available = locale.empty(); |
| 129 #else |
| 127 bool spellcheck_available = locale.empty() || !locale.compare(0, 2, "en"); | 130 bool spellcheck_available = locale.empty() || !locale.compare(0, 2, "en"); |
| 131 #endif |
| 128 return type == SUGGEST ? !spellcheck_available : spellcheck_available; | 132 return type == SUGGEST ? !spellcheck_available : spellcheck_available; |
| 129 } | 133 } |
| 130 | 134 |
| 131 void SpellingServiceClient::OnURLFetchComplete( | 135 void SpellingServiceClient::OnURLFetchComplete( |
| 132 const net::URLFetcher* source) { | 136 const net::URLFetcher* source) { |
| 133 scoped_ptr<net::URLFetcher> clean_up_fetcher(fetcher_.release()); | 137 scoped_ptr<net::URLFetcher> clean_up_fetcher(fetcher_.release()); |
| 134 bool success = false; | 138 bool success = false; |
| 135 std::vector<SpellCheckResult> results; | 139 std::vector<SpellCheckResult> results; |
| 136 if (source->GetResponseCode() / 100 == 2) { | 140 if (source->GetResponseCode() / 100 == 2) { |
| 137 std::string data; | 141 std::string data; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 if (!suggestions->GetDictionary(0, &suggestion) || | 219 if (!suggestions->GetDictionary(0, &suggestion) || |
| 216 !suggestion->GetString("suggestion", &replacement)) { | 220 !suggestion->GetString("suggestion", &replacement)) { |
| 217 return false; | 221 return false; |
| 218 } | 222 } |
| 219 SpellCheckResult result( | 223 SpellCheckResult result( |
| 220 SpellCheckResult::SPELLING, start, length, replacement); | 224 SpellCheckResult::SPELLING, start, length, replacement); |
| 221 results->push_back(result); | 225 results->push_back(result); |
| 222 } | 226 } |
| 223 return true; | 227 return true; |
| 224 } | 228 } |
| OLD | NEW |