| 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/common/extensions/api/speech/tts_engine_manifest_handler.h" | 5 #include "chrome/common/extensions/api/speech/tts_engine_manifest_handler.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 } | 45 } |
| 46 | 46 |
| 47 TtsEngineManifestHandler::~TtsEngineManifestHandler() { | 47 TtsEngineManifestHandler::~TtsEngineManifestHandler() { |
| 48 } | 48 } |
| 49 | 49 |
| 50 bool TtsEngineManifestHandler::Parse(Extension* extension, | 50 bool TtsEngineManifestHandler::Parse(Extension* extension, |
| 51 base::string16* error) { | 51 base::string16* error) { |
| 52 scoped_ptr<TtsVoices> info(new TtsVoices); | 52 scoped_ptr<TtsVoices> info(new TtsVoices); |
| 53 const base::DictionaryValue* tts_dict = NULL; | 53 const base::DictionaryValue* tts_dict = NULL; |
| 54 if (!extension->manifest()->GetDictionary(keys::kTtsEngine, &tts_dict)) { | 54 if (!extension->manifest()->GetDictionary(keys::kTtsEngine, &tts_dict)) { |
| 55 *error = ASCIIToUTF16(errors::kInvalidTts); | 55 *error = base::ASCIIToUTF16(errors::kInvalidTts); |
| 56 return false; | 56 return false; |
| 57 } | 57 } |
| 58 | 58 |
| 59 if (!tts_dict->HasKey(keys::kTtsVoices)) | 59 if (!tts_dict->HasKey(keys::kTtsVoices)) |
| 60 return true; | 60 return true; |
| 61 | 61 |
| 62 const base::ListValue* tts_voices = NULL; | 62 const base::ListValue* tts_voices = NULL; |
| 63 if (!tts_dict->GetList(keys::kTtsVoices, &tts_voices)) { | 63 if (!tts_dict->GetList(keys::kTtsVoices, &tts_voices)) { |
| 64 *error = ASCIIToUTF16(errors::kInvalidTtsVoices); | 64 *error = base::ASCIIToUTF16(errors::kInvalidTtsVoices); |
| 65 return false; | 65 return false; |
| 66 } | 66 } |
| 67 | 67 |
| 68 for (size_t i = 0; i < tts_voices->GetSize(); i++) { | 68 for (size_t i = 0; i < tts_voices->GetSize(); i++) { |
| 69 const base::DictionaryValue* one_tts_voice = NULL; | 69 const base::DictionaryValue* one_tts_voice = NULL; |
| 70 if (!tts_voices->GetDictionary(i, &one_tts_voice)) { | 70 if (!tts_voices->GetDictionary(i, &one_tts_voice)) { |
| 71 *error = ASCIIToUTF16(errors::kInvalidTtsVoices); | 71 *error = base::ASCIIToUTF16(errors::kInvalidTtsVoices); |
| 72 return false; | 72 return false; |
| 73 } | 73 } |
| 74 | 74 |
| 75 TtsVoice voice_data; | 75 TtsVoice voice_data; |
| 76 if (one_tts_voice->HasKey(keys::kTtsVoicesVoiceName)) { | 76 if (one_tts_voice->HasKey(keys::kTtsVoicesVoiceName)) { |
| 77 if (!one_tts_voice->GetString( | 77 if (!one_tts_voice->GetString( |
| 78 keys::kTtsVoicesVoiceName, &voice_data.voice_name)) { | 78 keys::kTtsVoicesVoiceName, &voice_data.voice_name)) { |
| 79 *error = ASCIIToUTF16(errors::kInvalidTtsVoicesVoiceName); | 79 *error = base::ASCIIToUTF16(errors::kInvalidTtsVoicesVoiceName); |
| 80 return false; | 80 return false; |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 if (one_tts_voice->HasKey(keys::kTtsVoicesLang)) { | 83 if (one_tts_voice->HasKey(keys::kTtsVoicesLang)) { |
| 84 if (!one_tts_voice->GetString( | 84 if (!one_tts_voice->GetString( |
| 85 keys::kTtsVoicesLang, &voice_data.lang) || | 85 keys::kTtsVoicesLang, &voice_data.lang) || |
| 86 !l10n_util::IsValidLocaleSyntax(voice_data.lang)) { | 86 !l10n_util::IsValidLocaleSyntax(voice_data.lang)) { |
| 87 *error = ASCIIToUTF16(errors::kInvalidTtsVoicesLang); | 87 *error = base::ASCIIToUTF16(errors::kInvalidTtsVoicesLang); |
| 88 return false; | 88 return false; |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 if (one_tts_voice->HasKey(keys::kTtsVoicesGender)) { | 91 if (one_tts_voice->HasKey(keys::kTtsVoicesGender)) { |
| 92 if (!one_tts_voice->GetString( | 92 if (!one_tts_voice->GetString( |
| 93 keys::kTtsVoicesGender, &voice_data.gender) || | 93 keys::kTtsVoicesGender, &voice_data.gender) || |
| 94 (voice_data.gender != keys::kTtsGenderMale && | 94 (voice_data.gender != keys::kTtsGenderMale && |
| 95 voice_data.gender != keys::kTtsGenderFemale)) { | 95 voice_data.gender != keys::kTtsGenderFemale)) { |
| 96 *error = ASCIIToUTF16(errors::kInvalidTtsVoicesGender); | 96 *error = base::ASCIIToUTF16(errors::kInvalidTtsVoicesGender); |
| 97 return false; | 97 return false; |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 if (one_tts_voice->HasKey(keys::kTtsVoicesRemote)) { | 100 if (one_tts_voice->HasKey(keys::kTtsVoicesRemote)) { |
| 101 if (!one_tts_voice->GetBoolean( | 101 if (!one_tts_voice->GetBoolean( |
| 102 keys::kTtsVoicesRemote, &voice_data.remote)) { | 102 keys::kTtsVoicesRemote, &voice_data.remote)) { |
| 103 *error = ASCIIToUTF16(errors::kInvalidTtsVoicesRemote); | 103 *error = base::ASCIIToUTF16(errors::kInvalidTtsVoicesRemote); |
| 104 return false; | 104 return false; |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 if (one_tts_voice->HasKey(keys::kTtsVoicesEventTypes)) { | 107 if (one_tts_voice->HasKey(keys::kTtsVoicesEventTypes)) { |
| 108 const base::ListValue* event_types_list; | 108 const base::ListValue* event_types_list; |
| 109 if (!one_tts_voice->GetList( | 109 if (!one_tts_voice->GetList( |
| 110 keys::kTtsVoicesEventTypes, | 110 keys::kTtsVoicesEventTypes, |
| 111 &event_types_list)) { | 111 &event_types_list)) { |
| 112 *error = ASCIIToUTF16( | 112 *error = base::ASCIIToUTF16( |
| 113 errors::kInvalidTtsVoicesEventTypes); | 113 errors::kInvalidTtsVoicesEventTypes); |
| 114 return false; | 114 return false; |
| 115 } | 115 } |
| 116 for (size_t i = 0; i < event_types_list->GetSize(); i++) { | 116 for (size_t i = 0; i < event_types_list->GetSize(); i++) { |
| 117 std::string event_type; | 117 std::string event_type; |
| 118 if (!event_types_list->GetString(i, &event_type)) { | 118 if (!event_types_list->GetString(i, &event_type)) { |
| 119 *error = ASCIIToUTF16(errors::kInvalidTtsVoicesEventTypes); | 119 *error = base::ASCIIToUTF16(errors::kInvalidTtsVoicesEventTypes); |
| 120 return false; | 120 return false; |
| 121 } | 121 } |
| 122 if (event_type != keys::kTtsVoicesEventTypeEnd && | 122 if (event_type != keys::kTtsVoicesEventTypeEnd && |
| 123 event_type != keys::kTtsVoicesEventTypeError && | 123 event_type != keys::kTtsVoicesEventTypeError && |
| 124 event_type != keys::kTtsVoicesEventTypeMarker && | 124 event_type != keys::kTtsVoicesEventTypeMarker && |
| 125 event_type != keys::kTtsVoicesEventTypeSentence && | 125 event_type != keys::kTtsVoicesEventTypeSentence && |
| 126 event_type != keys::kTtsVoicesEventTypeStart && | 126 event_type != keys::kTtsVoicesEventTypeStart && |
| 127 event_type != keys::kTtsVoicesEventTypeWord) { | 127 event_type != keys::kTtsVoicesEventTypeWord) { |
| 128 *error = ASCIIToUTF16(errors::kInvalidTtsVoicesEventTypes); | 128 *error = base::ASCIIToUTF16(errors::kInvalidTtsVoicesEventTypes); |
| 129 return false; | 129 return false; |
| 130 } | 130 } |
| 131 if (voice_data.event_types.find(event_type) != | 131 if (voice_data.event_types.find(event_type) != |
| 132 voice_data.event_types.end()) { | 132 voice_data.event_types.end()) { |
| 133 *error = ASCIIToUTF16(errors::kInvalidTtsVoicesEventTypes); | 133 *error = base::ASCIIToUTF16(errors::kInvalidTtsVoicesEventTypes); |
| 134 return false; | 134 return false; |
| 135 } | 135 } |
| 136 voice_data.event_types.insert(event_type); | 136 voice_data.event_types.insert(event_type); |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 | 139 |
| 140 info->voices.push_back(voice_data); | 140 info->voices.push_back(voice_data); |
| 141 } | 141 } |
| 142 | 142 |
| 143 extension->SetManifestData(keys::kTtsVoices, info.release()); | 143 extension->SetManifestData(keys::kTtsVoices, info.release()); |
| 144 return true; | 144 return true; |
| 145 } | 145 } |
| 146 | 146 |
| 147 const std::vector<std::string> TtsEngineManifestHandler::Keys() const { | 147 const std::vector<std::string> TtsEngineManifestHandler::Keys() const { |
| 148 return SingleKey(keys::kTtsEngine); | 148 return SingleKey(keys::kTtsEngine); |
| 149 } | 149 } |
| 150 | 150 |
| 151 } // namespace extensions | 151 } // namespace extensions |
| OLD | NEW |