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" |
11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
17 #include "chrome/common/spellcheck_result.h" | 17 #include "chrome/common/spellcheck_result.h" |
18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
19 #include "content/public/common/url_fetcher.h" | |
20 #include "net/base/load_flags.h" | 19 #include "net/base/load_flags.h" |
| 20 #include "net/url_request/url_fetcher.h" |
21 #include "unicode/uloc.h" | 21 #include "unicode/uloc.h" |
22 | 22 |
23 #if defined(GOOGLE_CHROME_BUILD) | 23 #if defined(GOOGLE_CHROME_BUILD) |
24 #include "chrome/browser/spellchecker/internal/spellcheck_internal.h" | 24 #include "chrome/browser/spellchecker/internal/spellcheck_internal.h" |
25 #endif | 25 #endif |
26 | 26 |
27 // Use the public URL to the Spelling service on Chromium. Unfortunately, this | 27 // Use the public URL to the Spelling service on Chromium. Unfortunately, this |
28 // service is an experimental service and returns an error without a key. | 28 // service is an experimental service and returns an error without a key. |
29 #ifndef SPELLING_SERVICE_KEY_V1 | 29 #ifndef SPELLING_SERVICE_KEY_V1 |
30 #define SPELLING_SERVICE_KEY_V1 "" | 30 #define SPELLING_SERVICE_KEY_V1 "" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 std::vector<SpellCheckResult> results; | 135 std::vector<SpellCheckResult> results; |
136 if (source->GetResponseCode() / 100 == 2) { | 136 if (source->GetResponseCode() / 100 == 2) { |
137 std::string data; | 137 std::string data; |
138 source->GetResponseAsString(&data); | 138 source->GetResponseAsString(&data); |
139 success = ParseResponse(data, &results); | 139 success = ParseResponse(data, &results); |
140 } | 140 } |
141 callback_.Run(tag_, success, text_, results); | 141 callback_.Run(tag_, success, text_, results); |
142 } | 142 } |
143 | 143 |
144 net::URLFetcher* SpellingServiceClient::CreateURLFetcher(const GURL& url) { | 144 net::URLFetcher* SpellingServiceClient::CreateURLFetcher(const GURL& url) { |
145 return content::URLFetcher::Create(url, net::URLFetcher::POST, this); | 145 return net::URLFetcher::Create(url, net::URLFetcher::POST, this); |
146 } | 146 } |
147 | 147 |
148 bool SpellingServiceClient::ParseResponse( | 148 bool SpellingServiceClient::ParseResponse( |
149 const std::string& data, | 149 const std::string& data, |
150 std::vector<SpellCheckResult>* results) { | 150 std::vector<SpellCheckResult>* results) { |
151 // When this JSON-RPC call finishes successfully, the Spelling service returns | 151 // When this JSON-RPC call finishes successfully, the Spelling service returns |
152 // an JSON object listed below. | 152 // an JSON object listed below. |
153 // * result - an envelope object representing the result from the APIARY | 153 // * result - an envelope object representing the result from the APIARY |
154 // server, which is the JSON-API front-end for the Spelling service. This | 154 // server, which is the JSON-API front-end for the Spelling service. This |
155 // object consists of the following variable: | 155 // object consists of the following variable: |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 if (!suggestions->GetDictionary(0, &suggestion) || | 215 if (!suggestions->GetDictionary(0, &suggestion) || |
216 !suggestion->GetString("suggestion", &replacement)) { | 216 !suggestion->GetString("suggestion", &replacement)) { |
217 return false; | 217 return false; |
218 } | 218 } |
219 SpellCheckResult result( | 219 SpellCheckResult result( |
220 SpellCheckResult::SPELLING, start, length, replacement); | 220 SpellCheckResult::SPELLING, start, length, replacement); |
221 results->push_back(result); | 221 results->push_back(result); |
222 } | 222 } |
223 return true; | 223 return true; |
224 } | 224 } |
OLD | NEW |