Chromium Code Reviews| 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" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 19 #include "chrome/common/spellcheck_result.h" | 19 #include "chrome/common/spellcheck_result.h" |
| 20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 21 #include "google_apis/google_api_keys.h" | |
| 21 #include "net/base/load_flags.h" | 22 #include "net/base/load_flags.h" |
| 22 #include "net/url_request/url_fetcher.h" | 23 #include "net/url_request/url_fetcher.h" |
| 23 #include "unicode/uloc.h" | 24 #include "unicode/uloc.h" |
| 24 | 25 |
| 25 #if defined(GOOGLE_CHROME_BUILD) | 26 // Use the public URL to the Spelling service on Chromium. |
| 26 #include "chrome/browser/spellchecker/internal/spellcheck_internal.h" | |
| 27 #endif | |
| 28 | |
| 29 // Use the public URL to the Spelling service on Chromium. Unfortunately, this | |
| 30 // service is an experimental service and returns an error without a key. | |
| 31 #ifndef SPELLING_SERVICE_KEY_V1 | |
| 32 #define SPELLING_SERVICE_KEY_V1 "" | |
| 33 #endif | |
| 34 | |
| 35 #ifndef SPELLING_SERVICE_KEY_V2 | |
| 36 #define SPELLING_SERVICE_KEY_V2 "" | |
| 37 #endif | |
| 38 | |
| 39 #ifndef SPELLING_SERVICE_URL | 27 #ifndef SPELLING_SERVICE_URL |
| 40 #define SPELLING_SERVICE_URL "https://www.googleapis.com/rpc" | 28 #define SPELLING_SERVICE_URL "https://www.googleapis.com/rpc" |
| 41 #endif | 29 #endif |
| 42 | 30 |
| 43 SpellingServiceClient::SpellingServiceClient() : tag_(0) { | 31 SpellingServiceClient::SpellingServiceClient() : tag_(0) { |
| 44 } | 32 } |
| 45 | 33 |
| 46 SpellingServiceClient::~SpellingServiceClient() { | 34 SpellingServiceClient::~SpellingServiceClient() { |
| 47 } | 35 } |
| 48 | 36 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 std::string encoded_text; | 69 std::string encoded_text; |
| 82 base::JsonDoubleQuote(text, false, &encoded_text); | 70 base::JsonDoubleQuote(text, false, &encoded_text); |
| 83 | 71 |
| 84 static const char kSpellingRequest[] = | 72 static const char kSpellingRequest[] = |
| 85 "{" | 73 "{" |
| 86 "\"method\":\"spelling.check\"," | 74 "\"method\":\"spelling.check\"," |
| 87 "\"apiVersion\":\"v%d\"," | 75 "\"apiVersion\":\"v%d\"," |
| 88 "\"params\":{" | 76 "\"params\":{" |
| 89 "\"text\":\"%s\"," | 77 "\"text\":\"%s\"," |
| 90 "\"language\":\"%s\"," | 78 "\"language\":\"%s\"," |
| 91 "\"origin_country\":\"%s\"," | 79 "\"originCountry\":\"%s\"," |
| 92 "\"key\":\"%s\"" | 80 "\"key\":\"%s\"" |
| 93 "}" | 81 "}" |
| 94 "}"; | 82 "}"; |
| 83 std::string api_key = google_apis::GetAPIKey(); | |
| 95 std::string request = base::StringPrintf( | 84 std::string request = base::StringPrintf( |
| 96 kSpellingRequest, | 85 kSpellingRequest, |
| 97 type, | 86 type, |
| 98 encoded_text.c_str(), | 87 encoded_text.c_str(), |
| 99 language, | 88 language, |
| 100 country, | 89 country, |
| 101 type == SUGGEST ? SPELLING_SERVICE_KEY_V1 : SPELLING_SERVICE_KEY_V2); | 90 api_key.c_str()); |
|
groby-ooo-7-16
2012/09/19 23:06:05
Oh. Now I see it :)
| |
| 102 | 91 |
| 103 static const char kSpellingServiceURL[] = SPELLING_SERVICE_URL; | 92 static const char kSpellingServiceURL[] = SPELLING_SERVICE_URL; |
| 104 GURL url = GURL(kSpellingServiceURL); | 93 GURL url = GURL(kSpellingServiceURL); |
| 105 fetcher_.reset(CreateURLFetcher(url)); | 94 fetcher_.reset(CreateURLFetcher(url)); |
| 106 fetcher_->SetRequestContext(profile->GetRequestContext()); | 95 fetcher_->SetRequestContext(profile->GetRequestContext()); |
| 107 fetcher_->SetUploadData("application/json", request); | 96 fetcher_->SetUploadData("application/json", request); |
| 108 fetcher_->SetLoadFlags( | 97 fetcher_->SetLoadFlags( |
| 109 net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES); | 98 net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES); |
| 110 fetcher_->Start(); | 99 fetcher_->Start(); |
| 111 tag_ = tag; | 100 tag_ = tag; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 if (!suggestions->GetDictionary(0, &suggestion) || | 216 if (!suggestions->GetDictionary(0, &suggestion) || |
| 228 !suggestion->GetString("suggestion", &replacement)) { | 217 !suggestion->GetString("suggestion", &replacement)) { |
| 229 return false; | 218 return false; |
| 230 } | 219 } |
| 231 SpellCheckResult result( | 220 SpellCheckResult result( |
| 232 SpellCheckResult::SPELLING, start, length, replacement); | 221 SpellCheckResult::SPELLING, start, length, replacement); |
| 233 results->push_back(result); | 222 results->push_back(result); |
| 234 } | 223 } |
| 235 return true; | 224 return true; |
| 236 } | 225 } |
| OLD | NEW |