Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Side by Side Diff: chrome/browser/spellchecker/spelling_service_client.cc

Issue 1092243002: Handle typographical apostrophe with spelling service client (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
7 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
8 #include "base/json/string_escape.h" 10 #include "base/json/string_escape.h"
9 #include "base/logging.h" 11 #include "base/logging.h"
10 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
11 #include "base/stl_util.h" 13 #include "base/stl_util.h"
12 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
13 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
14 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
15 #include "base/values.h" 17 #include "base/values.h"
16 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 const PrefService* pref = user_prefs::UserPrefs::Get(context); 61 const PrefService* pref = user_prefs::UserPrefs::Get(context);
60 DCHECK(pref); 62 DCHECK(pref);
61 63
62 std::string language_code; 64 std::string language_code;
63 std::string country_code; 65 std::string country_code;
64 chrome::spellcheck_common::GetISOLanguageCountryCodeFromLocale( 66 chrome::spellcheck_common::GetISOLanguageCountryCodeFromLocale(
65 pref->GetString(prefs::kSpellCheckDictionary), 67 pref->GetString(prefs::kSpellCheckDictionary),
66 &language_code, 68 &language_code,
67 &country_code); 69 &country_code);
68 70
71 // Replace typographical apostrophes with typewriter apostrophes, so that
72 // server word breaker behaves correctly.
73 base::string16 text_copy = text;
74 std::replace(text_copy.begin(), text_copy.end(), L'\x2019', L'\'');
75
69 // Format the JSON request to be sent to the Spelling service. 76 // Format the JSON request to be sent to the Spelling service.
70 std::string encoded_text = base::GetQuotedJSONString(text); 77 std::string encoded_text = base::GetQuotedJSONString(text_copy);
71 78
72 static const char kSpellingRequest[] = 79 static const char kSpellingRequest[] =
73 "{" 80 "{"
74 "\"method\":\"spelling.check\"," 81 "\"method\":\"spelling.check\","
75 "\"apiVersion\":\"v%d\"," 82 "\"apiVersion\":\"v%d\","
76 "\"params\":{" 83 "\"params\":{"
77 "\"text\":%s," 84 "\"text\":%s,"
78 "\"language\":\"%s\"," 85 "\"language\":\"%s\","
79 "\"originCountry\":\"%s\"," 86 "\"originCountry\":\"%s\","
80 "\"key\":%s" 87 "\"key\":%s"
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 257
251 // The callback may release the last (transitive) dependency on |this|. It 258 // The callback may release the last (transitive) dependency on |this|. It
252 // MUST be the last function called. 259 // MUST be the last function called.
253 callback_data->callback.Run(success, callback_data->text, results); 260 callback_data->callback.Run(success, callback_data->text, results);
254 } 261 }
255 262
256 scoped_ptr<net::URLFetcher> SpellingServiceClient::CreateURLFetcher( 263 scoped_ptr<net::URLFetcher> SpellingServiceClient::CreateURLFetcher(
257 const GURL& url) { 264 const GURL& url) {
258 return net::URLFetcher::Create(url, net::URLFetcher::POST, this); 265 return net::URLFetcher::Create(url, net::URLFetcher::POST, this);
259 } 266 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698