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

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

Issue 106793004: Revert of Stop doing unnecessary UTF-8 to UTF-16 conversions in JSONWriter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/search/iframe_source.cc ('k') | chrome/browser/ui/webui/about_ui.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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
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 = base::GetQuotedJSONString(text); 72 std::string encoded_text;
73 base::JsonDoubleQuote(text, false, &encoded_text);
73 74
74 static const char kSpellingRequest[] = 75 static const char kSpellingRequest[] =
75 "{" 76 "{"
76 "\"method\":\"spelling.check\"," 77 "\"method\":\"spelling.check\","
77 "\"apiVersion\":\"v%d\"," 78 "\"apiVersion\":\"v%d\","
78 "\"params\":{" 79 "\"params\":{"
79 "\"text\":%s," 80 "\"text\":\"%s\","
80 "\"language\":\"%s\"," 81 "\"language\":\"%s\","
81 "\"originCountry\":\"%s\"," 82 "\"originCountry\":\"%s\","
82 "\"key\":%s" 83 "\"key\":%s"
83 "}" 84 "}"
84 "}"; 85 "}";
85 std::string api_key = base::GetQuotedJSONString(google_apis::GetAPIKey()); 86 std::string api_key = base::GetDoubleQuotedJson(google_apis::GetAPIKey());
86 std::string request = base::StringPrintf( 87 std::string request = base::StringPrintf(
87 kSpellingRequest, 88 kSpellingRequest,
88 type, 89 type,
89 encoded_text.c_str(), 90 encoded_text.c_str(),
90 language_code.c_str(), 91 language_code.c_str(),
91 country_code.c_str(), 92 country_code.c_str(),
92 api_key.c_str()); 93 api_key.c_str());
93 94
94 GURL url = GURL(kSpellingServiceURL); 95 GURL url = GURL(kSpellingServiceURL);
95 net::URLFetcher* fetcher = CreateURLFetcher(url); 96 net::URLFetcher* fetcher = CreateURLFetcher(url);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 fetcher->GetResponseAsString(&data); 255 fetcher->GetResponseAsString(&data);
255 success = ParseResponse(data, &results); 256 success = ParseResponse(data, &results);
256 } 257 }
257 callback_data->callback.Run(success, callback_data->text, results); 258 callback_data->callback.Run(success, callback_data->text, results);
258 spellcheck_fetchers_.erase(fetcher.get()); 259 spellcheck_fetchers_.erase(fetcher.get());
259 } 260 }
260 261
261 net::URLFetcher* SpellingServiceClient::CreateURLFetcher(const GURL& url) { 262 net::URLFetcher* SpellingServiceClient::CreateURLFetcher(const GURL& url) {
262 return net::URLFetcher::Create(url, net::URLFetcher::POST, this); 263 return net::URLFetcher::Create(url, net::URLFetcher::POST, this);
263 } 264 }
OLDNEW
« no previous file with comments | « chrome/browser/search/iframe_source.cc ('k') | chrome/browser/ui/webui/about_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698