| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 options->SetString(constants::kVoiceNameKey, voice.name); | 188 options->SetString(constants::kVoiceNameKey, voice.name); |
| 189 if (!options->HasKey(constants::kLangKey)) | 189 if (!options->HasKey(constants::kLangKey)) |
| 190 options->SetString(constants::kLangKey, voice.lang); | 190 options->SetString(constants::kLangKey, voice.lang); |
| 191 | 191 |
| 192 args->Append(std::move(options)); | 192 args->Append(std::move(options)); |
| 193 args->AppendInteger(utterance->id()); | 193 args->AppendInteger(utterance->id()); |
| 194 | 194 |
| 195 std::string json; | 195 std::string json; |
| 196 base::JSONWriter::Write(*args, &json); | 196 base::JSONWriter::Write(*args, &json); |
| 197 | 197 |
| 198 std::unique_ptr<extensions::Event> event( | |
| 199 new extensions::Event(extensions::events::TTS_ENGINE_ON_SPEAK, | |
| 200 tts_engine_events::kOnSpeak, std::move(args))); | |
| 201 Profile* profile = Profile::FromBrowserContext(utterance->browser_context()); | 198 Profile* profile = Profile::FromBrowserContext(utterance->browser_context()); |
| 202 event->restrict_to_browser_context = profile; | 199 auto event = base::MakeUnique<extensions::Event>( |
| 200 extensions::events::TTS_ENGINE_ON_SPEAK, tts_engine_events::kOnSpeak, |
| 201 std::move(args), profile); |
| 203 EventRouter::Get(profile) | 202 EventRouter::Get(profile) |
| 204 ->DispatchEventToExtension(utterance->extension_id(), std::move(event)); | 203 ->DispatchEventToExtension(utterance->extension_id(), std::move(event)); |
| 205 } | 204 } |
| 206 | 205 |
| 207 void TtsExtensionEngine::Stop(Utterance* utterance) { | 206 void TtsExtensionEngine::Stop(Utterance* utterance) { |
| 208 std::unique_ptr<base::ListValue> args(new base::ListValue()); | 207 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
| 209 std::unique_ptr<extensions::Event> event( | |
| 210 new extensions::Event(extensions::events::TTS_ENGINE_ON_STOP, | |
| 211 tts_engine_events::kOnStop, std::move(args))); | |
| 212 Profile* profile = Profile::FromBrowserContext(utterance->browser_context()); | 208 Profile* profile = Profile::FromBrowserContext(utterance->browser_context()); |
| 213 event->restrict_to_browser_context = profile; | 209 auto event = base::MakeUnique<extensions::Event>( |
| 210 extensions::events::TTS_ENGINE_ON_STOP, tts_engine_events::kOnStop, |
| 211 std::move(args), profile); |
| 214 EventRouter::Get(profile) | 212 EventRouter::Get(profile) |
| 215 ->DispatchEventToExtension(utterance->extension_id(), std::move(event)); | 213 ->DispatchEventToExtension(utterance->extension_id(), std::move(event)); |
| 216 } | 214 } |
| 217 | 215 |
| 218 void TtsExtensionEngine::Pause(Utterance* utterance) { | 216 void TtsExtensionEngine::Pause(Utterance* utterance) { |
| 219 std::unique_ptr<base::ListValue> args(new base::ListValue()); | 217 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
| 220 std::unique_ptr<extensions::Event> event( | |
| 221 new extensions::Event(extensions::events::TTS_ENGINE_ON_PAUSE, | |
| 222 tts_engine_events::kOnPause, std::move(args))); | |
| 223 Profile* profile = Profile::FromBrowserContext(utterance->browser_context()); | 218 Profile* profile = Profile::FromBrowserContext(utterance->browser_context()); |
| 224 event->restrict_to_browser_context = profile; | 219 auto event = base::MakeUnique<extensions::Event>( |
| 220 extensions::events::TTS_ENGINE_ON_PAUSE, tts_engine_events::kOnPause, |
| 221 std::move(args), profile); |
| 225 EventRouter* event_router = EventRouter::Get(profile); | 222 EventRouter* event_router = EventRouter::Get(profile); |
| 226 std::string id = utterance->extension_id(); | 223 std::string id = utterance->extension_id(); |
| 227 event_router->DispatchEventToExtension(id, std::move(event)); | 224 event_router->DispatchEventToExtension(id, std::move(event)); |
| 228 WarnIfMissingPauseOrResumeListener(profile, event_router, id); | 225 WarnIfMissingPauseOrResumeListener(profile, event_router, id); |
| 229 } | 226 } |
| 230 | 227 |
| 231 void TtsExtensionEngine::Resume(Utterance* utterance) { | 228 void TtsExtensionEngine::Resume(Utterance* utterance) { |
| 232 std::unique_ptr<base::ListValue> args(new base::ListValue()); | 229 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
| 233 std::unique_ptr<extensions::Event> event( | |
| 234 new extensions::Event(extensions::events::TTS_ENGINE_ON_RESUME, | |
| 235 tts_engine_events::kOnResume, std::move(args))); | |
| 236 Profile* profile = Profile::FromBrowserContext(utterance->browser_context()); | 230 Profile* profile = Profile::FromBrowserContext(utterance->browser_context()); |
| 237 event->restrict_to_browser_context = profile; | 231 auto event = base::MakeUnique<extensions::Event>( |
| 232 extensions::events::TTS_ENGINE_ON_RESUME, tts_engine_events::kOnResume, |
| 233 std::move(args), profile); |
| 238 EventRouter* event_router = EventRouter::Get(profile); | 234 EventRouter* event_router = EventRouter::Get(profile); |
| 239 std::string id = utterance->extension_id(); | 235 std::string id = utterance->extension_id(); |
| 240 event_router->DispatchEventToExtension(id, std::move(event)); | 236 event_router->DispatchEventToExtension(id, std::move(event)); |
| 241 WarnIfMissingPauseOrResumeListener(profile, event_router, id); | 237 WarnIfMissingPauseOrResumeListener(profile, event_router, id); |
| 242 } | 238 } |
| 243 | 239 |
| 244 bool TtsExtensionEngine::LoadBuiltInTtsExtension( | 240 bool TtsExtensionEngine::LoadBuiltInTtsExtension( |
| 245 content::BrowserContext* browser_context) { | 241 content::BrowserContext* browser_context) { |
| 246 #if defined(OS_CHROMEOS) | 242 #if defined(OS_CHROMEOS) |
| 247 Profile* profile = Profile::FromBrowserContext(browser_context); | 243 Profile* profile = Profile::FromBrowserContext(browser_context); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 utterance_id, TTS_EVENT_PAUSE, char_index, std::string()); | 320 utterance_id, TTS_EVENT_PAUSE, char_index, std::string()); |
| 325 } else if (event_type == constants::kEventTypeResume) { | 321 } else if (event_type == constants::kEventTypeResume) { |
| 326 controller->OnTtsEvent( | 322 controller->OnTtsEvent( |
| 327 utterance_id, TTS_EVENT_RESUME, char_index, std::string()); | 323 utterance_id, TTS_EVENT_RESUME, char_index, std::string()); |
| 328 } else { | 324 } else { |
| 329 EXTENSION_FUNCTION_VALIDATE(false); | 325 EXTENSION_FUNCTION_VALIDATE(false); |
| 330 } | 326 } |
| 331 | 327 |
| 332 return RespondNow(NoArguments()); | 328 return RespondNow(NoArguments()); |
| 333 } | 329 } |
| OLD | NEW |