| 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/speech/extension_api/tts_engine_extension_api.h" | 5 #include "chrome/browser/speech/extension_api/tts_engine_extension_api.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 } | 133 } |
| 134 | 134 |
| 135 void TtsExtensionEngine::Speak(Utterance* utterance, | 135 void TtsExtensionEngine::Speak(Utterance* utterance, |
| 136 const VoiceData& voice) { | 136 const VoiceData& voice) { |
| 137 // See if the engine supports the "end" event; if so, we can keep the | 137 // See if the engine supports the "end" event; if so, we can keep the |
| 138 // utterance around and track it. If not, we're finished with this | 138 // utterance around and track it. If not, we're finished with this |
| 139 // utterance now. | 139 // utterance now. |
| 140 bool sends_end_event = voice.events.find(TTS_EVENT_END) != voice.events.end(); | 140 bool sends_end_event = voice.events.find(TTS_EVENT_END) != voice.events.end(); |
| 141 | 141 |
| 142 scoped_ptr<base::ListValue> args(new base::ListValue()); | 142 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 143 args->Set(0, new base::StringValue(utterance->text())); | 143 args->AppendString(utterance->text()); |
| 144 | 144 |
| 145 // Pass through most options to the speech engine, but remove some | 145 // Pass through most options to the speech engine, but remove some |
| 146 // that are handled internally. | 146 // that are handled internally. |
| 147 scoped_ptr<base::DictionaryValue> options(static_cast<base::DictionaryValue*>( | 147 scoped_ptr<base::DictionaryValue> options(static_cast<base::DictionaryValue*>( |
| 148 utterance->options()->DeepCopy())); | 148 utterance->options()->DeepCopy())); |
| 149 if (options->HasKey(constants::kRequiredEventTypesKey)) | 149 if (options->HasKey(constants::kRequiredEventTypesKey)) |
| 150 options->Remove(constants::kRequiredEventTypesKey, NULL); | 150 options->Remove(constants::kRequiredEventTypesKey, NULL); |
| 151 if (options->HasKey(constants::kDesiredEventTypesKey)) | 151 if (options->HasKey(constants::kDesiredEventTypesKey)) |
| 152 options->Remove(constants::kDesiredEventTypesKey, NULL); | 152 options->Remove(constants::kDesiredEventTypesKey, NULL); |
| 153 if (sends_end_event && options->HasKey(constants::kEnqueueKey)) | 153 if (sends_end_event && options->HasKey(constants::kEnqueueKey)) |
| 154 options->Remove(constants::kEnqueueKey, NULL); | 154 options->Remove(constants::kEnqueueKey, NULL); |
| 155 if (options->HasKey(constants::kSrcIdKey)) | 155 if (options->HasKey(constants::kSrcIdKey)) |
| 156 options->Remove(constants::kSrcIdKey, NULL); | 156 options->Remove(constants::kSrcIdKey, NULL); |
| 157 if (options->HasKey(constants::kIsFinalEventKey)) | 157 if (options->HasKey(constants::kIsFinalEventKey)) |
| 158 options->Remove(constants::kIsFinalEventKey, NULL); | 158 options->Remove(constants::kIsFinalEventKey, NULL); |
| 159 if (options->HasKey(constants::kOnEventKey)) | 159 if (options->HasKey(constants::kOnEventKey)) |
| 160 options->Remove(constants::kOnEventKey, NULL); | 160 options->Remove(constants::kOnEventKey, NULL); |
| 161 | 161 |
| 162 // Add the voice name and language to the options if they're not | 162 // Add the voice name and language to the options if they're not |
| 163 // already there, since they might have been picked by the TTS controller | 163 // already there, since they might have been picked by the TTS controller |
| 164 // rather than directly by the client that requested the speech. | 164 // rather than directly by the client that requested the speech. |
| 165 if (!options->HasKey(constants::kVoiceNameKey)) | 165 if (!options->HasKey(constants::kVoiceNameKey)) |
| 166 options->SetString(constants::kVoiceNameKey, voice.name); | 166 options->SetString(constants::kVoiceNameKey, voice.name); |
| 167 if (!options->HasKey(constants::kLangKey)) | 167 if (!options->HasKey(constants::kLangKey)) |
| 168 options->SetString(constants::kLangKey, voice.lang); | 168 options->SetString(constants::kLangKey, voice.lang); |
| 169 | 169 |
| 170 args->Set(1, options.release()); | 170 args->Append(options.release()); |
| 171 args->Set(2, base::Value::CreateIntegerValue(utterance->id())); | 171 args->AppendInteger(utterance->id()); |
| 172 | 172 |
| 173 scoped_ptr<extensions::Event> event(new extensions::Event( | 173 scoped_ptr<extensions::Event> event(new extensions::Event( |
| 174 tts_engine_events::kOnSpeak, args.Pass())); | 174 tts_engine_events::kOnSpeak, args.Pass())); |
| 175 event->restrict_to_browser_context = utterance->profile(); | 175 event->restrict_to_browser_context = utterance->profile(); |
| 176 EventRouter::Get(utterance->profile()) | 176 EventRouter::Get(utterance->profile()) |
| 177 ->DispatchEventToExtension(utterance->extension_id(), event.Pass()); | 177 ->DispatchEventToExtension(utterance->extension_id(), event.Pass()); |
| 178 } | 178 } |
| 179 | 179 |
| 180 void TtsExtensionEngine::Stop(Utterance* utterance) { | 180 void TtsExtensionEngine::Stop(Utterance* utterance) { |
| 181 scoped_ptr<base::ListValue> args(new base::ListValue()); | 181 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 utterance_id, TTS_EVENT_PAUSE, char_index, std::string()); | 275 utterance_id, TTS_EVENT_PAUSE, char_index, std::string()); |
| 276 } else if (event_type == constants::kEventTypeResume) { | 276 } else if (event_type == constants::kEventTypeResume) { |
| 277 controller->OnTtsEvent( | 277 controller->OnTtsEvent( |
| 278 utterance_id, TTS_EVENT_RESUME, char_index, std::string()); | 278 utterance_id, TTS_EVENT_RESUME, char_index, std::string()); |
| 279 } else { | 279 } else { |
| 280 EXTENSION_FUNCTION_VALIDATE(false); | 280 EXTENSION_FUNCTION_VALIDATE(false); |
| 281 } | 281 } |
| 282 | 282 |
| 283 return true; | 283 return true; |
| 284 } | 284 } |
| OLD | NEW |