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 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_MESSAGE_BUNDLE_H_ | 5 #ifndef CHROME_COMMON_EXTENSIONS_MESSAGE_BUNDLE_H_ |
6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_MESSAGE_BUNDLE_H_ | 6 #define CHROME_COMMON_EXTENSIONS_MESSAGE_BUNDLE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/memory/linked_ptr.h" | 12 #include "base/memory/linked_ptr.h" |
13 | 13 |
14 namespace base { | 14 namespace base { |
15 class DictionaryValue; | 15 class DictionaryValue; |
16 } | 16 } |
17 | 17 |
| 18 namespace extensions { |
| 19 |
18 // Contains localized extension messages for one locale. Any messages that the | 20 // Contains localized extension messages for one locale. Any messages that the |
19 // locale does not provide are pulled from the default locale. | 21 // locale does not provide are pulled from the default locale. |
20 class ExtensionMessageBundle { | 22 class MessageBundle { |
21 public: | 23 public: |
22 typedef std::map<std::string, std::string> SubstitutionMap; | 24 typedef std::map<std::string, std::string> SubstitutionMap; |
23 typedef std::vector<linked_ptr<base::DictionaryValue> > CatalogVector; | 25 typedef std::vector<linked_ptr<base::DictionaryValue> > CatalogVector; |
24 | 26 |
25 // JSON keys of interest for messages file. | 27 // JSON keys of interest for messages file. |
26 static const char* kContentKey; | 28 static const char* kContentKey; |
27 static const char* kMessageKey; | 29 static const char* kMessageKey; |
28 static const char* kPlaceholdersKey; | 30 static const char* kPlaceholdersKey; |
29 | 31 |
30 // Begin/end markers for placeholders and messages | 32 // Begin/end markers for placeholders and messages |
(...skipping 14 matching lines...) Expand all Loading... |
45 static const char* kBidiEndEdgeKey; | 47 static const char* kBidiEndEdgeKey; |
46 // Extension id gets added in the | 48 // Extension id gets added in the |
47 // browser/renderer_host/resource_message_filter.cc to enable message | 49 // browser/renderer_host/resource_message_filter.cc to enable message |
48 // replacement for non-localized extensions. | 50 // replacement for non-localized extensions. |
49 static const char* kExtensionIdKey; | 51 static const char* kExtensionIdKey; |
50 | 52 |
51 // Values for some of the reserved messages. | 53 // Values for some of the reserved messages. |
52 static const char* kBidiLeftEdgeValue; | 54 static const char* kBidiLeftEdgeValue; |
53 static const char* kBidiRightEdgeValue; | 55 static const char* kBidiRightEdgeValue; |
54 | 56 |
55 // Creates ExtensionMessageBundle or returns NULL if there was an error. | 57 // Creates MessageBundle or returns NULL if there was an error. Expects |
56 // Expects locale_catalogs to be sorted from more specific to less specific, | 58 // locale_catalogs to be sorted from more specific to less specific, with |
57 // with default catalog at the end. | 59 // default catalog at the end. |
58 static ExtensionMessageBundle* Create(const CatalogVector& locale_catalogs, | 60 static MessageBundle* Create(const CatalogVector& locale_catalogs, |
59 std::string* error); | 61 std::string* error); |
60 | 62 |
61 // Get message from the catalog with given key. | 63 // Get message from the catalog with given key. |
62 // Returned message has all of the internal placeholders resolved to their | 64 // Returned message has all of the internal placeholders resolved to their |
63 // value (content). | 65 // value (content). |
64 // Returns empty string if it can't find a message. | 66 // Returns empty string if it can't find a message. |
65 // We don't use simple GetMessage name, since there is a global | 67 // We don't use simple GetMessage name, since there is a global |
66 // #define GetMessage GetMessageW override in Chrome code. | 68 // #define GetMessage GetMessageW override in Chrome code. |
67 std::string GetL10nMessage(const std::string& name) const; | 69 std::string GetL10nMessage(const std::string& name) const; |
68 | 70 |
69 // Get message from the given catalog with given key. | 71 // Get message from the given catalog with given key. |
(...skipping 23 matching lines...) Expand all Loading... |
93 std::string* message, | 95 std::string* message, |
94 std::string* error); | 96 std::string* error); |
95 | 97 |
96 // Allow only ascii 0-9, a-z, A-Z, and _ in the variable name. | 98 // Allow only ascii 0-9, a-z, A-Z, and _ in the variable name. |
97 // Returns false if the input is empty or if it has illegal characters. | 99 // Returns false if the input is empty or if it has illegal characters. |
98 static bool IsValidName(const std::string& name); | 100 static bool IsValidName(const std::string& name); |
99 | 101 |
100 // Getter for dictionary_. | 102 // Getter for dictionary_. |
101 const SubstitutionMap* dictionary() const { return &dictionary_; } | 103 const SubstitutionMap* dictionary() const { return &dictionary_; } |
102 | 104 |
103 ~ExtensionMessageBundle(); | 105 ~MessageBundle(); |
104 | 106 |
105 private: | 107 private: |
106 // Testing friend. | 108 // Testing friend. |
107 friend class ExtensionMessageBundleTest; | 109 friend class MessageBundleTest; |
108 | 110 |
109 // Use Create to create ExtensionMessageBundle instance. | 111 // Use Create to create MessageBundle instance. |
110 ExtensionMessageBundle(); | 112 MessageBundle(); |
111 | 113 |
112 // Initializes the instance from the contents of vector of catalogs. | 114 // Initializes the instance from the contents of vector of catalogs. |
113 // If the key is not present in more specific catalog we fall back to next one | 115 // If the key is not present in more specific catalog we fall back to next one |
114 // (less specific). | 116 // (less specific). |
115 // Returns false on error. | 117 // Returns false on error. |
116 bool Init(const CatalogVector& locale_catalogs, std::string* error); | 118 bool Init(const CatalogVector& locale_catalogs, std::string* error); |
117 | 119 |
118 // Appends locale specific reserved messages to the dictionary. | 120 // Appends locale specific reserved messages to the dictionary. |
119 // Returns false if there was a conflict with user defined messages. | 121 // Returns false if there was a conflict with user defined messages. |
120 bool AppendReservedMessagesForLocale(const std::string& application_locale, | 122 bool AppendReservedMessagesForLocale(const std::string& application_locale, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 157 |
156 // A map of extension ID to l10n message map. | 158 // A map of extension ID to l10n message map. |
157 typedef std::map<std::string, L10nMessagesMap > ExtensionToL10nMessagesMap; | 159 typedef std::map<std::string, L10nMessagesMap > ExtensionToL10nMessagesMap; |
158 | 160 |
159 // Returns the extension_id to messages map. | 161 // Returns the extension_id to messages map. |
160 ExtensionToL10nMessagesMap* GetExtensionToL10nMessagesMap(); | 162 ExtensionToL10nMessagesMap* GetExtensionToL10nMessagesMap(); |
161 | 163 |
162 // Returns message map that matches given extension_id, or NULL. | 164 // Returns message map that matches given extension_id, or NULL. |
163 L10nMessagesMap* GetL10nMessagesMap(const std::string& extension_id); | 165 L10nMessagesMap* GetL10nMessagesMap(const std::string& extension_id); |
164 | 166 |
165 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_MESSAGE_BUNDLE_H_ | 167 } // namsepace extensions |
| 168 |
| 169 #endif // CHROME_COMMON_EXTENSIONS_MESSAGE_BUNDLE_H_ |
OLD | NEW |