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 <algorithm> | |
8 | |
9 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
10 #include "base/json/string_escape.h" | 8 #include "base/json/string_escape.h" |
11 #include "base/logging.h" | 9 #include "base/logging.h" |
12 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
13 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
14 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
15 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
16 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
17 #include "base/values.h" | 15 #include "base/values.h" |
18 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 const PrefService* pref = user_prefs::UserPrefs::Get(context); | 59 const PrefService* pref = user_prefs::UserPrefs::Get(context); |
62 DCHECK(pref); | 60 DCHECK(pref); |
63 | 61 |
64 std::string language_code; | 62 std::string language_code; |
65 std::string country_code; | 63 std::string country_code; |
66 chrome::spellcheck_common::GetISOLanguageCountryCodeFromLocale( | 64 chrome::spellcheck_common::GetISOLanguageCountryCodeFromLocale( |
67 pref->GetString(prefs::kSpellCheckDictionary), | 65 pref->GetString(prefs::kSpellCheckDictionary), |
68 &language_code, | 66 &language_code, |
69 &country_code); | 67 &country_code); |
70 | 68 |
71 // Replace typographical apostrophes with typewriter apostrophes, so that | |
72 // server word breaker behaves correctly. | |
73 const base::char16 kApostrophe = 0x27; | |
74 const base::char16 kRightSingleQuotationMark = 0x2019; | |
75 base::string16 text_copy = text; | |
76 std::replace(text_copy.begin(), text_copy.end(), kRightSingleQuotationMark, | |
77 kApostrophe); | |
78 | |
79 // Format the JSON request to be sent to the Spelling service. | 69 // Format the JSON request to be sent to the Spelling service. |
80 std::string encoded_text = base::GetQuotedJSONString(text_copy); | 70 std::string encoded_text = base::GetQuotedJSONString(text); |
81 | 71 |
82 static const char kSpellingRequest[] = | 72 static const char kSpellingRequest[] = |
83 "{" | 73 "{" |
84 "\"method\":\"spelling.check\"," | 74 "\"method\":\"spelling.check\"," |
85 "\"apiVersion\":\"v%d\"," | 75 "\"apiVersion\":\"v%d\"," |
86 "\"params\":{" | 76 "\"params\":{" |
87 "\"text\":%s," | 77 "\"text\":%s," |
88 "\"language\":\"%s\"," | 78 "\"language\":\"%s\"," |
89 "\"originCountry\":\"%s\"," | 79 "\"originCountry\":\"%s\"," |
90 "\"key\":%s" | 80 "\"key\":%s" |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 | 250 |
261 // The callback may release the last (transitive) dependency on |this|. It | 251 // The callback may release the last (transitive) dependency on |this|. It |
262 // MUST be the last function called. | 252 // MUST be the last function called. |
263 callback_data->callback.Run(success, callback_data->text, results); | 253 callback_data->callback.Run(success, callback_data->text, results); |
264 } | 254 } |
265 | 255 |
266 scoped_ptr<net::URLFetcher> SpellingServiceClient::CreateURLFetcher( | 256 scoped_ptr<net::URLFetcher> SpellingServiceClient::CreateURLFetcher( |
267 const GURL& url) { | 257 const GURL& url) { |
268 return net::URLFetcher::Create(url, net::URLFetcher::POST, this); | 258 return net::URLFetcher::Create(url, net::URLFetcher::POST, this); |
269 } | 259 } |
OLD | NEW |