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/stringprintf.h" | 10 #include "base/stringprintf.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
16 #include "chrome/common/spellcheck_result.h" | 16 #include "chrome/common/spellcheck_result.h" |
17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/common/content_url_request_user_data.h" |
18 #include "content/public/common/url_fetcher.h" | 19 #include "content/public/common/url_fetcher.h" |
19 #include "net/base/load_flags.h" | 20 #include "net/base/load_flags.h" |
20 #include "unicode/uloc.h" | 21 #include "unicode/uloc.h" |
21 | 22 |
22 #if defined(GOOGLE_CHROME_BUILD) | 23 #if defined(GOOGLE_CHROME_BUILD) |
23 #include "chrome/browser/spellchecker/internal/spellcheck_internal.h" | 24 #include "chrome/browser/spellchecker/internal/spellcheck_internal.h" |
24 #endif | 25 #endif |
25 | 26 |
26 // Use the public URL to the Spelling service on Chromium. Unfortunately, this | 27 // Use the public URL to the Spelling service on Chromium. Unfortunately, this |
27 // service is an experimental service and returns an error without a key. | 28 // service is an experimental service and returns an error without a key. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 "}"; | 87 "}"; |
87 std::string request = base::StringPrintf(kSpellingRequest, | 88 std::string request = base::StringPrintf(kSpellingRequest, |
88 encoded_text.c_str(), | 89 encoded_text.c_str(), |
89 language, country); | 90 language, country); |
90 | 91 |
91 static const char kSpellingServiceURL[] = SPELLING_SERVICE_URL; | 92 static const char kSpellingServiceURL[] = SPELLING_SERVICE_URL; |
92 GURL url = GURL(kSpellingServiceURL); | 93 GURL url = GURL(kSpellingServiceURL); |
93 fetcher_.reset(content::URLFetcher::Create( | 94 fetcher_.reset(content::URLFetcher::Create( |
94 url, content::URLFetcher::POST, this)); | 95 url, content::URLFetcher::POST, this)); |
95 fetcher_->SetRequestContext(context); | 96 fetcher_->SetRequestContext(context); |
| 97 // TODO(jochen): Do cookie audit. |
| 98 fetcher_->SetContentURLRequestUserData( |
| 99 new content::ContentURLRequestUserData()); |
96 fetcher_->SetUploadData("application/json", request); | 100 fetcher_->SetUploadData("application/json", request); |
97 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); | 101 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); |
98 fetcher_->Start(); | 102 fetcher_->Start(); |
99 tag_ = tag; | 103 tag_ = tag; |
100 callback_ = callback; | 104 callback_ = callback; |
101 return true; | 105 return true; |
102 } | 106 } |
103 | 107 |
104 void SpellingServiceClient::OnURLFetchComplete( | 108 void SpellingServiceClient::OnURLFetchComplete( |
105 const content::URLFetcher* source) { | 109 const content::URLFetcher* source) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 if (!suggestions->GetDictionary(0, &suggestion) || | 187 if (!suggestions->GetDictionary(0, &suggestion) || |
184 !suggestion->GetString("suggestion", &replacement)) { | 188 !suggestion->GetString("suggestion", &replacement)) { |
185 return false; | 189 return false; |
186 } | 190 } |
187 SpellCheckResult result( | 191 SpellCheckResult result( |
188 SpellCheckResult::SPELLING, start, length, replacement); | 192 SpellCheckResult::SPELLING, start, length, replacement); |
189 results->push_back(result); | 193 results->push_back(result); |
190 } | 194 } |
191 return true; | 195 return true; |
192 } | 196 } |
OLD | NEW |