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/extensions/extension_tts_engine_api.h" | 5 #include "chrome/browser/extensions/extension_tts_engine_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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 result_voice->SetString(constants::kLangKey, voice.lang); | 51 result_voice->SetString(constants::kLangKey, voice.lang); |
52 if (!voice.gender.empty()) | 52 if (!voice.gender.empty()) |
53 result_voice->SetString(constants::kGenderKey, voice.gender); | 53 result_voice->SetString(constants::kGenderKey, voice.gender); |
54 result_voice->SetString(constants::kExtensionIdKey, extension->id()); | 54 result_voice->SetString(constants::kExtensionIdKey, extension->id()); |
55 | 55 |
56 ListValue* event_types = new ListValue(); | 56 ListValue* event_types = new ListValue(); |
57 for (std::set<std::string>::const_iterator iter = | 57 for (std::set<std::string>::const_iterator iter = |
58 voice.event_types.begin(); | 58 voice.event_types.begin(); |
59 iter != voice.event_types.end(); | 59 iter != voice.event_types.end(); |
60 ++iter) { | 60 ++iter) { |
61 event_types->Append(Value::CreateStringValue(*iter)); | 61 event_types->Append(base::StringValue::New(*iter)); |
62 } | 62 } |
63 // If the extension sends end events, the controller will handle | 63 // If the extension sends end events, the controller will handle |
64 // queueing and send interrupted and cancelled events. | 64 // queueing and send interrupted and cancelled events. |
65 if (voice.event_types.find(constants::kEventTypeEnd) != | 65 if (voice.event_types.find(constants::kEventTypeEnd) != |
66 voice.event_types.end()) { | 66 voice.event_types.end()) { |
67 event_types->Append( | 67 event_types->Append( |
68 Value::CreateStringValue(constants::kEventTypeCancelled)); | 68 base::StringValue::New(constants::kEventTypeCancelled)); |
69 event_types->Append(Value::CreateStringValue( | 69 event_types->Append(base::StringValue::New( |
70 constants::kEventTypeInterrupted)); | 70 constants::kEventTypeInterrupted)); |
71 } | 71 } |
72 | 72 |
73 result_voice->Set(constants::kEventTypesKey, event_types); | 73 result_voice->Set(constants::kEventTypesKey, event_types); |
74 result_voices->Append(result_voice); | 74 result_voices->Append(result_voice); |
75 } | 75 } |
76 } | 76 } |
77 } | 77 } |
78 | 78 |
79 bool GetMatchingExtensionVoice( | 79 bool GetMatchingExtensionVoice( |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 size_t voice_index) { | 153 size_t voice_index) { |
154 // See if the engine supports the "end" event; if so, we can keep the | 154 // See if the engine supports the "end" event; if so, we can keep the |
155 // utterance around and track it. If not, we're finished with this | 155 // utterance around and track it. If not, we're finished with this |
156 // utterance now. | 156 // utterance now. |
157 const std::set<std::string> event_types = | 157 const std::set<std::string> event_types = |
158 extension->tts_voices()[voice_index].event_types; | 158 extension->tts_voices()[voice_index].event_types; |
159 bool sends_end_event = | 159 bool sends_end_event = |
160 (event_types.find(constants::kEventTypeEnd) != event_types.end()); | 160 (event_types.find(constants::kEventTypeEnd) != event_types.end()); |
161 | 161 |
162 ListValue args; | 162 ListValue args; |
163 args.Set(0, Value::CreateStringValue(utterance->text())); | 163 args.Set(0, base::StringValue::New(utterance->text())); |
164 | 164 |
165 // Pass through most options to the speech engine, but remove some | 165 // Pass through most options to the speech engine, but remove some |
166 // that are handled internally. | 166 // that are handled internally. |
167 DictionaryValue* options = static_cast<DictionaryValue*>( | 167 DictionaryValue* options = static_cast<DictionaryValue*>( |
168 utterance->options()->DeepCopy()); | 168 utterance->options()->DeepCopy()); |
169 if (options->HasKey(constants::kRequiredEventTypesKey)) | 169 if (options->HasKey(constants::kRequiredEventTypesKey)) |
170 options->Remove(constants::kRequiredEventTypesKey, NULL); | 170 options->Remove(constants::kRequiredEventTypesKey, NULL); |
171 if (options->HasKey(constants::kDesiredEventTypesKey)) | 171 if (options->HasKey(constants::kDesiredEventTypesKey)) |
172 options->Remove(constants::kDesiredEventTypesKey, NULL); | 172 options->Remove(constants::kDesiredEventTypesKey, NULL); |
173 if (sends_end_event && options->HasKey(constants::kEnqueueKey)) | 173 if (sends_end_event && options->HasKey(constants::kEnqueueKey)) |
174 options->Remove(constants::kEnqueueKey, NULL); | 174 options->Remove(constants::kEnqueueKey, NULL); |
175 if (options->HasKey(constants::kSrcIdKey)) | 175 if (options->HasKey(constants::kSrcIdKey)) |
176 options->Remove(constants::kSrcIdKey, NULL); | 176 options->Remove(constants::kSrcIdKey, NULL); |
177 if (options->HasKey(constants::kIsFinalEventKey)) | 177 if (options->HasKey(constants::kIsFinalEventKey)) |
178 options->Remove(constants::kIsFinalEventKey, NULL); | 178 options->Remove(constants::kIsFinalEventKey, NULL); |
179 | 179 |
180 args.Set(1, options); | 180 args.Set(1, options); |
181 args.Set(2, Value::CreateIntegerValue(utterance->id())); | 181 args.Set(2, base::NumberValue::New(utterance->id())); |
182 std::string json_args; | 182 std::string json_args; |
183 base::JSONWriter::Write(&args, false, &json_args); | 183 base::JSONWriter::Write(&args, false, &json_args); |
184 | 184 |
185 utterance->profile()->GetExtensionEventRouter()->DispatchEventToExtension( | 185 utterance->profile()->GetExtensionEventRouter()->DispatchEventToExtension( |
186 extension->id(), | 186 extension->id(), |
187 events::kOnSpeak, | 187 events::kOnSpeak, |
188 json_args, | 188 json_args, |
189 utterance->profile(), | 189 utterance->profile(), |
190 GURL()); | 190 GURL()); |
191 } | 191 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 std::string error_message; | 252 std::string error_message; |
253 event->GetString(constants::kErrorMessageKey, &error_message); | 253 event->GetString(constants::kErrorMessageKey, &error_message); |
254 controller->OnTtsEvent( | 254 controller->OnTtsEvent( |
255 utterance_id, TTS_EVENT_ERROR, char_index, error_message); | 255 utterance_id, TTS_EVENT_ERROR, char_index, error_message); |
256 } else { | 256 } else { |
257 EXTENSION_FUNCTION_VALIDATE(false); | 257 EXTENSION_FUNCTION_VALIDATE(false); |
258 } | 258 } |
259 | 259 |
260 return true; | 260 return true; |
261 } | 261 } |
OLD | NEW |