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" |
| 11 #include "chrome/browser/extensions/component_loader.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" |
11 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/speech/extension_api/tts_engine_extension_observer.h" |
12 #include "chrome/browser/speech/extension_api/tts_extension_api.h" | 15 #include "chrome/browser/speech/extension_api/tts_extension_api.h" |
13 #include "chrome/browser/speech/extension_api/tts_extension_api_constants.h" | 16 #include "chrome/browser/speech/extension_api/tts_extension_api_constants.h" |
14 #include "chrome/browser/speech/tts_controller.h" | 17 #include "chrome/browser/speech/tts_controller.h" |
15 #include "chrome/common/extensions/api/speech/tts_engine_manifest_handler.h" | 18 #include "chrome/common/extensions/api/speech/tts_engine_manifest_handler.h" |
| 19 #include "chrome/common/extensions/extension_constants.h" |
16 #include "content/public/browser/render_process_host.h" | 20 #include "content/public/browser/render_process_host.h" |
17 #include "content/public/browser/render_view_host.h" | 21 #include "content/public/browser/render_view_host.h" |
18 #include "content/public/common/console_message_level.h" | 22 #include "content/public/common/console_message_level.h" |
19 #include "extensions/browser/event_router.h" | 23 #include "extensions/browser/event_router.h" |
20 #include "extensions/browser/extension_host.h" | 24 #include "extensions/browser/extension_host.h" |
21 #include "extensions/browser/extension_registry.h" | 25 #include "extensions/browser/extension_registry.h" |
22 #include "extensions/browser/extension_system.h" | 26 #include "extensions/browser/extension_system.h" |
23 #include "extensions/browser/process_manager.h" | 27 #include "extensions/browser/process_manager.h" |
24 #include "extensions/common/extension.h" | 28 #include "extensions/common/extension.h" |
25 #include "extensions/common/extension_messages.h" | 29 #include "extensions/common/extension_messages.h" |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 scoped_ptr<extensions::Event> event(new extensions::Event( | 207 scoped_ptr<extensions::Event> event(new extensions::Event( |
204 tts_engine_events::kOnResume, args.Pass())); | 208 tts_engine_events::kOnResume, args.Pass())); |
205 Profile* profile = utterance->profile(); | 209 Profile* profile = utterance->profile(); |
206 event->restrict_to_browser_context = profile; | 210 event->restrict_to_browser_context = profile; |
207 EventRouter* event_router = EventRouter::Get(profile); | 211 EventRouter* event_router = EventRouter::Get(profile); |
208 std::string id = utterance->extension_id(); | 212 std::string id = utterance->extension_id(); |
209 event_router->DispatchEventToExtension(id, event.Pass()); | 213 event_router->DispatchEventToExtension(id, event.Pass()); |
210 WarnIfMissingPauseOrResumeListener(profile, event_router, id); | 214 WarnIfMissingPauseOrResumeListener(profile, event_router, id); |
211 } | 215 } |
212 | 216 |
| 217 bool TtsExtensionEngine::LoadBuiltInTtsExtension(Profile* profile) { |
| 218 #if defined(OS_CHROMEOS) |
| 219 // Check to see if the engine was previously loaded. |
| 220 if (TtsEngineExtensionObserver::GetInstance(profile)->SawExtensionLoad( |
| 221 extension_misc::kSpeechSynthesisExtensionId, true)) { |
| 222 return false; |
| 223 } |
| 224 |
| 225 // Load the component extension into this profile. |
| 226 ExtensionService* extension_service = |
| 227 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 228 DCHECK(extension_service); |
| 229 extension_service->component_loader() |
| 230 ->AddChromeOsSpeechSynthesisExtension(); |
| 231 return true; |
| 232 #else |
| 233 return false; |
| 234 #endif |
| 235 } |
| 236 |
213 bool ExtensionTtsEngineSendTtsEventFunction::RunSync() { | 237 bool ExtensionTtsEngineSendTtsEventFunction::RunSync() { |
214 int utterance_id; | 238 int utterance_id; |
215 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &utterance_id)); | 239 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &utterance_id)); |
216 | 240 |
217 base::DictionaryValue* event; | 241 base::DictionaryValue* event; |
218 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &event)); | 242 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &event)); |
219 | 243 |
220 std::string event_type; | 244 std::string event_type; |
221 EXTENSION_FUNCTION_VALIDATE( | 245 EXTENSION_FUNCTION_VALIDATE( |
222 event->GetString(constants::kEventTypeKey, &event_type)); | 246 event->GetString(constants::kEventTypeKey, &event_type)); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 utterance_id, TTS_EVENT_PAUSE, char_index, std::string()); | 298 utterance_id, TTS_EVENT_PAUSE, char_index, std::string()); |
275 } else if (event_type == constants::kEventTypeResume) { | 299 } else if (event_type == constants::kEventTypeResume) { |
276 controller->OnTtsEvent( | 300 controller->OnTtsEvent( |
277 utterance_id, TTS_EVENT_RESUME, char_index, std::string()); | 301 utterance_id, TTS_EVENT_RESUME, char_index, std::string()); |
278 } else { | 302 } else { |
279 EXTENSION_FUNCTION_VALIDATE(false); | 303 EXTENSION_FUNCTION_VALIDATE(false); |
280 } | 304 } |
281 | 305 |
282 return true; | 306 return true; |
283 } | 307 } |
OLD | NEW |