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 "chrome/browser/speech/speech_recognition_request.h" | 5 #include "chrome/browser/speech/speech_recognition_request.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 : url_context_(context), | 116 : url_context_(context), |
117 delegate_(delegate) { | 117 delegate_(delegate) { |
118 DCHECK(delegate); | 118 DCHECK(delegate); |
119 } | 119 } |
120 | 120 |
121 SpeechRecognitionRequest::~SpeechRecognitionRequest() {} | 121 SpeechRecognitionRequest::~SpeechRecognitionRequest() {} |
122 | 122 |
123 bool SpeechRecognitionRequest::Send(const std::string& language, | 123 bool SpeechRecognitionRequest::Send(const std::string& language, |
124 const std::string& grammar, | 124 const std::string& grammar, |
125 const std::string& hardware_info, | 125 const std::string& hardware_info, |
| 126 const std::string& origin_url, |
126 const std::string& content_type, | 127 const std::string& content_type, |
127 const std::string& audio_data) { | 128 const std::string& audio_data) { |
128 DCHECK(!url_fetcher_.get()); | 129 DCHECK(!url_fetcher_.get()); |
129 | 130 |
130 std::vector<std::string> parts; | 131 std::vector<std::string> parts; |
131 | 132 |
132 std::string lang_param = language; | 133 std::string lang_param = language; |
133 if (lang_param.empty() && url_context_) { | 134 if (lang_param.empty() && url_context_) { |
134 // If no language is provided then we use the first from the accepted | 135 // If no language is provided then we use the first from the accepted |
135 // language list. If this list is empty then it defaults to "en-US". | 136 // language list. If this list is empty then it defaults to "en-US". |
(...skipping 18 matching lines...) Expand all Loading... |
154 parts.push_back("maxresults=3"); | 155 parts.push_back("maxresults=3"); |
155 | 156 |
156 GURL url(std::string(kDefaultSpeechRecognitionUrl) + JoinString(parts, '&')); | 157 GURL url(std::string(kDefaultSpeechRecognitionUrl) + JoinString(parts, '&')); |
157 | 158 |
158 url_fetcher_.reset(URLFetcher::Create(url_fetcher_id_for_tests, | 159 url_fetcher_.reset(URLFetcher::Create(url_fetcher_id_for_tests, |
159 url, | 160 url, |
160 URLFetcher::POST, | 161 URLFetcher::POST, |
161 this)); | 162 this)); |
162 url_fetcher_->set_upload_data(content_type, audio_data); | 163 url_fetcher_->set_upload_data(content_type, audio_data); |
163 url_fetcher_->set_request_context(url_context_); | 164 url_fetcher_->set_request_context(url_context_); |
| 165 url_fetcher_->set_referrer(origin_url); |
164 | 166 |
165 // The speech recognition API does not require user identification as part | 167 // The speech recognition API does not require user identification as part |
166 // of requests, so we don't send cookies or auth data for these requests to | 168 // of requests, so we don't send cookies or auth data for these requests to |
167 // prevent any accidental connection between users who are logged into the | 169 // prevent any accidental connection between users who are logged into the |
168 // domain for other services (e.g. bookmark sync) with the speech requests. | 170 // domain for other services (e.g. bookmark sync) with the speech requests. |
169 url_fetcher_->set_load_flags( | 171 url_fetcher_->set_load_flags( |
170 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_COOKIES | | 172 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_COOKIES | |
171 net::LOAD_DO_NOT_SEND_AUTH_DATA); | 173 net::LOAD_DO_NOT_SEND_AUTH_DATA); |
172 url_fetcher_->Start(); | 174 url_fetcher_->Start(); |
173 return true; | 175 return true; |
(...skipping 12 matching lines...) Expand all Loading... |
186 SpeechInputResultArray result; | 188 SpeechInputResultArray result; |
187 if (!error) | 189 if (!error) |
188 error = !ParseServerResponse(data, &result); | 190 error = !ParseServerResponse(data, &result); |
189 url_fetcher_.reset(); | 191 url_fetcher_.reset(); |
190 | 192 |
191 DVLOG(1) << "SpeechRecognitionRequest: Invoking delegate with result."; | 193 DVLOG(1) << "SpeechRecognitionRequest: Invoking delegate with result."; |
192 delegate_->SetRecognitionResult(error, result); | 194 delegate_->SetRecognitionResult(error, result); |
193 } | 195 } |
194 | 196 |
195 } // namespace speech_input | 197 } // namespace speech_input |
OLD | NEW |