| 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/message_bundle.h" | 5 #include "chrome/common/extensions/message_bundle.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/hash_tables.h" | 10 #include "base/hash_tables.h" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 } | 127 } |
| 128 | 128 |
| 129 return true; | 129 return true; |
| 130 } | 130 } |
| 131 | 131 |
| 132 bool MessageBundle::GetMessageValue(const std::string& key, | 132 bool MessageBundle::GetMessageValue(const std::string& key, |
| 133 const DictionaryValue& catalog, | 133 const DictionaryValue& catalog, |
| 134 std::string* value, | 134 std::string* value, |
| 135 std::string* error) const { | 135 std::string* error) const { |
| 136 // Get the top level tree for given key (name part). | 136 // Get the top level tree for given key (name part). |
| 137 DictionaryValue* name_tree; | 137 const DictionaryValue* name_tree; |
| 138 if (!catalog.GetDictionaryWithoutPathExpansion(key, &name_tree)) { | 138 if (!catalog.GetDictionaryWithoutPathExpansion(key, &name_tree)) { |
| 139 *error = base::StringPrintf("Not a valid tree for key %s.", key.c_str()); | 139 *error = base::StringPrintf("Not a valid tree for key %s.", key.c_str()); |
| 140 return false; | 140 return false; |
| 141 } | 141 } |
| 142 // Extract message from it. | 142 // Extract message from it. |
| 143 if (!name_tree->GetString(kMessageKey, value)) { | 143 if (!name_tree->GetString(kMessageKey, value)) { |
| 144 *error = base::StringPrintf( | 144 *error = base::StringPrintf( |
| 145 "There is no \"%s\" element for key %s.", kMessageKey, key.c_str()); | 145 "There is no \"%s\" element for key %s.", kMessageKey, key.c_str()); |
| 146 return false; | 146 return false; |
| 147 } | 147 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 159 MessageBundle::MessageBundle() { | 159 MessageBundle::MessageBundle() { |
| 160 } | 160 } |
| 161 | 161 |
| 162 bool MessageBundle::GetPlaceholders(const DictionaryValue& name_tree, | 162 bool MessageBundle::GetPlaceholders(const DictionaryValue& name_tree, |
| 163 const std::string& name_key, | 163 const std::string& name_key, |
| 164 SubstitutionMap* placeholders, | 164 SubstitutionMap* placeholders, |
| 165 std::string* error) const { | 165 std::string* error) const { |
| 166 if (!name_tree.HasKey(kPlaceholdersKey)) | 166 if (!name_tree.HasKey(kPlaceholdersKey)) |
| 167 return true; | 167 return true; |
| 168 | 168 |
| 169 DictionaryValue* placeholders_tree; | 169 const DictionaryValue* placeholders_tree; |
| 170 if (!name_tree.GetDictionary(kPlaceholdersKey, &placeholders_tree)) { | 170 if (!name_tree.GetDictionary(kPlaceholdersKey, &placeholders_tree)) { |
| 171 *error = base::StringPrintf("Not a valid \"%s\" element for key %s.", | 171 *error = base::StringPrintf("Not a valid \"%s\" element for key %s.", |
| 172 kPlaceholdersKey, name_key.c_str()); | 172 kPlaceholdersKey, name_key.c_str()); |
| 173 return false; | 173 return false; |
| 174 } | 174 } |
| 175 | 175 |
| 176 for (DictionaryValue::key_iterator key_it = placeholders_tree->begin_keys(); | 176 for (DictionaryValue::key_iterator key_it = placeholders_tree->begin_keys(); |
| 177 key_it != placeholders_tree->end_keys(); ++key_it) { | 177 key_it != placeholders_tree->end_keys(); ++key_it) { |
| 178 DictionaryValue* placeholder; | 178 const DictionaryValue* placeholder; |
| 179 const std::string& content_key(*key_it); | 179 const std::string& content_key(*key_it); |
| 180 if (!IsValidName(content_key)) | 180 if (!IsValidName(content_key)) |
| 181 return BadKeyMessage(content_key, error); | 181 return BadKeyMessage(content_key, error); |
| 182 if (!placeholders_tree->GetDictionaryWithoutPathExpansion(content_key, | 182 if (!placeholders_tree->GetDictionaryWithoutPathExpansion(content_key, |
| 183 &placeholder)) { | 183 &placeholder)) { |
| 184 *error = base::StringPrintf("Invalid placeholder %s for key %s", | 184 *error = base::StringPrintf("Invalid placeholder %s for key %s", |
| 185 content_key.c_str(), | 185 content_key.c_str(), |
| 186 name_key.c_str()); | 186 name_key.c_str()); |
| 187 return false; | 187 return false; |
| 188 } | 188 } |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 L10nMessagesMap* GetL10nMessagesMap(const std::string& extension_id) { | 336 L10nMessagesMap* GetL10nMessagesMap(const std::string& extension_id) { |
| 337 ExtensionToL10nMessagesMap::iterator it = | 337 ExtensionToL10nMessagesMap::iterator it = |
| 338 g_extension_to_messages_map.Get().messages_map.find(extension_id); | 338 g_extension_to_messages_map.Get().messages_map.find(extension_id); |
| 339 if (it != g_extension_to_messages_map.Get().messages_map.end()) | 339 if (it != g_extension_to_messages_map.Get().messages_map.end()) |
| 340 return &(it->second); | 340 return &(it->second); |
| 341 | 341 |
| 342 return NULL; | 342 return NULL; |
| 343 } | 343 } |
| 344 | 344 |
| 345 } // namespace extensions | 345 } // namespace extensions |
| OLD | NEW |