OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/speech/speech_recognition_request.h" | 5 #include "content/browser/speech/speech_recognition_request.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "content/common/net/url_fetcher.h" | 13 #include "content/common/net/url_fetcher_impl.h" |
14 #include "net/base/escape.h" | 14 #include "net/base/escape.h" |
15 #include "net/base/load_flags.h" | 15 #include "net/base/load_flags.h" |
16 #include "net/url_request/url_request_context.h" | 16 #include "net/url_request/url_request_context.h" |
17 #include "net/url_request/url_request_context_getter.h" | 17 #include "net/url_request/url_request_context_getter.h" |
18 #include "net/url_request/url_request_status.h" | 18 #include "net/url_request/url_request_status.h" |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 const char* const kDefaultSpeechRecognitionUrl = | 22 const char* const kDefaultSpeechRecognitionUrl = |
23 "https://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&"; | 23 "https://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&"; |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 | 175 |
176 if (!grammar.empty()) | 176 if (!grammar.empty()) |
177 parts.push_back("lm=" + net::EscapeQueryParamValue(grammar, true)); | 177 parts.push_back("lm=" + net::EscapeQueryParamValue(grammar, true)); |
178 if (!hardware_info.empty()) | 178 if (!hardware_info.empty()) |
179 parts.push_back("xhw=" + net::EscapeQueryParamValue(hardware_info, true)); | 179 parts.push_back("xhw=" + net::EscapeQueryParamValue(hardware_info, true)); |
180 parts.push_back("maxresults=" + base::IntToString(kMaxResults)); | 180 parts.push_back("maxresults=" + base::IntToString(kMaxResults)); |
181 parts.push_back(filter_profanities ? "pfilter=2" : "pfilter=0"); | 181 parts.push_back(filter_profanities ? "pfilter=2" : "pfilter=0"); |
182 | 182 |
183 GURL url(std::string(kDefaultSpeechRecognitionUrl) + JoinString(parts, '&')); | 183 GURL url(std::string(kDefaultSpeechRecognitionUrl) + JoinString(parts, '&')); |
184 | 184 |
185 url_fetcher_.reset(URLFetcher::Create(url_fetcher_id_for_tests, | 185 url_fetcher_.reset(URLFetcherImpl::Create(url_fetcher_id_for_tests, |
186 url, | 186 url, |
187 URLFetcher::POST, | 187 URLFetcherImpl::POST, |
188 this)); | 188 this)); |
189 url_fetcher_->SetChunkedUpload(content_type); | 189 url_fetcher_->SetChunkedUpload(content_type); |
190 url_fetcher_->SetRequestContext(url_context_); | 190 url_fetcher_->SetRequestContext(url_context_); |
191 url_fetcher_->SetReferrer(origin_url); | 191 url_fetcher_->SetReferrer(origin_url); |
192 | 192 |
193 // The speech recognition API does not require user identification as part | 193 // The speech recognition API does not require user identification as part |
194 // of requests, so we don't send cookies or auth data for these requests to | 194 // of requests, so we don't send cookies or auth data for these requests to |
195 // prevent any accidental connection between users who are logged into the | 195 // prevent any accidental connection between users who are logged into the |
196 // domain for other services (e.g. bookmark sync) with the speech requests. | 196 // domain for other services (e.g. bookmark sync) with the speech requests. |
197 url_fetcher_->SetLoadFlags( | 197 url_fetcher_->SetLoadFlags( |
198 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_COOKIES | | 198 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_COOKIES | |
(...skipping 18 matching lines...) Expand all Loading... |
217 !ParseServerResponse(data, &result)) { | 217 !ParseServerResponse(data, &result)) { |
218 result.error = kErrorNetwork; | 218 result.error = kErrorNetwork; |
219 } | 219 } |
220 | 220 |
221 DVLOG(1) << "SpeechRecognitionRequest: Invoking delegate with result."; | 221 DVLOG(1) << "SpeechRecognitionRequest: Invoking delegate with result."; |
222 url_fetcher_.reset(); | 222 url_fetcher_.reset(); |
223 delegate_->SetRecognitionResult(result); | 223 delegate_->SetRecognitionResult(result); |
224 } | 224 } |
225 | 225 |
226 } // namespace speech_input | 226 } // namespace speech_input |
OLD | NEW |