| 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/string_escape.h" | 9 #include "base/json/string_escape.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 DCHECK(pref); | 62 DCHECK(pref); |
| 63 | 63 |
| 64 std::string language_code; | 64 std::string language_code; |
| 65 std::string country_code; | 65 std::string country_code; |
| 66 chrome::spellcheck_common::GetISOLanguageCountryCodeFromLocale( | 66 chrome::spellcheck_common::GetISOLanguageCountryCodeFromLocale( |
| 67 pref->GetString(prefs::kSpellCheckDictionary), | 67 pref->GetString(prefs::kSpellCheckDictionary), |
| 68 &language_code, | 68 &language_code, |
| 69 &country_code); | 69 &country_code); |
| 70 | 70 |
| 71 // Format the JSON request to be sent to the Spelling service. | 71 // Format the JSON request to be sent to the Spelling service. |
| 72 std::string encoded_text; | 72 std::string encoded_text = base::GetQuotedJSONString(text); |
| 73 base::JsonDoubleQuote(text, false, &encoded_text); | |
| 74 | 73 |
| 75 static const char kSpellingRequest[] = | 74 static const char kSpellingRequest[] = |
| 76 "{" | 75 "{" |
| 77 "\"method\":\"spelling.check\"," | 76 "\"method\":\"spelling.check\"," |
| 78 "\"apiVersion\":\"v%d\"," | 77 "\"apiVersion\":\"v%d\"," |
| 79 "\"params\":{" | 78 "\"params\":{" |
| 80 "\"text\":\"%s\"," | 79 "\"text\":%s," |
| 81 "\"language\":\"%s\"," | 80 "\"language\":\"%s\"," |
| 82 "\"originCountry\":\"%s\"," | 81 "\"originCountry\":\"%s\"," |
| 83 "\"key\":%s" | 82 "\"key\":%s" |
| 84 "}" | 83 "}" |
| 85 "}"; | 84 "}"; |
| 86 std::string api_key = base::GetDoubleQuotedJson(google_apis::GetAPIKey()); | 85 std::string api_key = base::GetQuotedJSONString(google_apis::GetAPIKey()); |
| 87 std::string request = base::StringPrintf( | 86 std::string request = base::StringPrintf( |
| 88 kSpellingRequest, | 87 kSpellingRequest, |
| 89 type, | 88 type, |
| 90 encoded_text.c_str(), | 89 encoded_text.c_str(), |
| 91 language_code.c_str(), | 90 language_code.c_str(), |
| 92 country_code.c_str(), | 91 country_code.c_str(), |
| 93 api_key.c_str()); | 92 api_key.c_str()); |
| 94 | 93 |
| 95 GURL url = GURL(kSpellingServiceURL); | 94 GURL url = GURL(kSpellingServiceURL); |
| 96 net::URLFetcher* fetcher = CreateURLFetcher(url); | 95 net::URLFetcher* fetcher = CreateURLFetcher(url); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 fetcher->GetResponseAsString(&data); | 254 fetcher->GetResponseAsString(&data); |
| 256 success = ParseResponse(data, &results); | 255 success = ParseResponse(data, &results); |
| 257 } | 256 } |
| 258 callback_data->callback.Run(success, callback_data->text, results); | 257 callback_data->callback.Run(success, callback_data->text, results); |
| 259 spellcheck_fetchers_.erase(fetcher.get()); | 258 spellcheck_fetchers_.erase(fetcher.get()); |
| 260 } | 259 } |
| 261 | 260 |
| 262 net::URLFetcher* SpellingServiceClient::CreateURLFetcher(const GURL& url) { | 261 net::URLFetcher* SpellingServiceClient::CreateURLFetcher(const GURL& url) { |
| 263 return net::URLFetcher::Create(url, net::URLFetcher::POST, this); | 262 return net::URLFetcher::Create(url, net::URLFetcher::POST, this); |
| 264 } | 263 } |
| OLD | NEW |