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/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 const PrefService* pref = user_prefs::UserPrefs::Get(context); | 59 const PrefService* pref = user_prefs::UserPrefs::Get(context); |
60 DCHECK(pref); | 60 DCHECK(pref); |
61 | 61 |
62 std::string language_code; | 62 std::string language_code; |
63 std::string country_code; | 63 std::string country_code; |
64 chrome::spellcheck_common::GetISOLanguageCountryCodeFromLocale( | 64 chrome::spellcheck_common::GetISOLanguageCountryCodeFromLocale( |
65 pref->GetString(prefs::kSpellCheckDictionary), | 65 pref->GetString(prefs::kSpellCheckDictionary), |
66 &language_code, | 66 &language_code, |
67 &country_code); | 67 &country_code); |
68 | 68 |
69 // Replace typographical apostrophes with typewriter apostrophes, so that | |
70 // server word breaker behaves correctly. | |
71 base::string16 text_copy = text; | |
72 for (base::char16& c : text_copy) { | |
groby-ooo-7-16
2015/06/17 19:12:02
std::replace(text_copy.begin(), text_copy.end(), L
please use gerrit instead
2015/06/17 20:21:35
Ooh, I like.
| |
73 if (c == L'\x2019') | |
74 c = '\''; | |
75 } | |
76 | |
69 // Format the JSON request to be sent to the Spelling service. | 77 // Format the JSON request to be sent to the Spelling service. |
70 std::string encoded_text = base::GetQuotedJSONString(text); | 78 std::string encoded_text = base::GetQuotedJSONString(text_copy); |
71 | 79 |
72 static const char kSpellingRequest[] = | 80 static const char kSpellingRequest[] = |
73 "{" | 81 "{" |
74 "\"method\":\"spelling.check\"," | 82 "\"method\":\"spelling.check\"," |
75 "\"apiVersion\":\"v%d\"," | 83 "\"apiVersion\":\"v%d\"," |
76 "\"params\":{" | 84 "\"params\":{" |
77 "\"text\":%s," | 85 "\"text\":%s," |
78 "\"language\":\"%s\"," | 86 "\"language\":\"%s\"," |
79 "\"originCountry\":\"%s\"," | 87 "\"originCountry\":\"%s\"," |
80 "\"key\":%s" | 88 "\"key\":%s" |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 | 258 |
251 // The callback may release the last (transitive) dependency on |this|. It | 259 // The callback may release the last (transitive) dependency on |this|. It |
252 // MUST be the last function called. | 260 // MUST be the last function called. |
253 callback_data->callback.Run(success, callback_data->text, results); | 261 callback_data->callback.Run(success, callback_data->text, results); |
254 } | 262 } |
255 | 263 |
256 scoped_ptr<net::URLFetcher> SpellingServiceClient::CreateURLFetcher( | 264 scoped_ptr<net::URLFetcher> SpellingServiceClient::CreateURLFetcher( |
257 const GURL& url) { | 265 const GURL& url) { |
258 return net::URLFetcher::Create(url, net::URLFetcher::POST, this); | 266 return net::URLFetcher::Create(url, net::URLFetcher::POST, this); |
259 } | 267 } |
OLD | NEW |