Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: chrome/common/extensions/extension_message_bundle.h

Issue 3207002: FBTF: Forward declare and move constructors in chrome/common/extensions/. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Win fixes Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_EXTENSION_MESSAGE_BUNDLE_H_
6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_MESSAGE_BUNDLE_H_ 6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_MESSAGE_BUNDLE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/linked_ptr.h" 13 #include "base/linked_ptr.h"
14 #include "base/string_util.h" 14
15 #include "base/values.h" 15 class DictionaryValue;
16 16
17 // Contains localized extension messages for one locale. Any messages that the 17 // Contains localized extension messages for one locale. Any messages that the
18 // locale does not provide are pulled from the default locale. 18 // locale does not provide are pulled from the default locale.
19 class ExtensionMessageBundle { 19 class ExtensionMessageBundle {
20 public: 20 public:
21 typedef std::map<std::string, std::string> SubstitutionMap; 21 typedef std::map<std::string, std::string> SubstitutionMap;
22 typedef std::vector<linked_ptr<DictionaryValue> > CatalogVector; 22 typedef std::vector<linked_ptr<DictionaryValue> > CatalogVector;
23 23
24 // JSON keys of interest for messages file. 24 // JSON keys of interest for messages file.
25 static const char* kContentKey; 25 static const char* kContentKey;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 // replacement. 87 // replacement.
88 // Public for easier unittesting. 88 // Public for easier unittesting.
89 static bool ReplaceVariables(const SubstitutionMap& variables, 89 static bool ReplaceVariables(const SubstitutionMap& variables,
90 const std::string& var_begin, 90 const std::string& var_begin,
91 const std::string& var_end, 91 const std::string& var_end,
92 std::string* message, 92 std::string* message,
93 std::string* error); 93 std::string* error);
94 94
95 // Allow only ascii 0-9, a-z, A-Z, and _ in the variable name. 95 // Allow only ascii 0-9, a-z, A-Z, and _ in the variable name.
96 // Returns false if the input is empty or if it has illegal characters. 96 // Returns false if the input is empty or if it has illegal characters.
97 template<typename str> 97 static bool IsValidName(const std::string& name);
98 static bool IsValidName(const str& name) {
99 if (name.empty())
100 return false;
101
102 typename str::const_iterator it = name.begin();
103 for (; it != name.end(); ++it) {
104 // Allow only ascii 0-9, a-z, A-Z, and _ in the name.
105 if (!IsAsciiAlpha(*it) && !IsAsciiDigit(*it) && *it != '_' && *it != '@')
106 return false;
107 }
108
109 return true;
110 }
111 98
112 // Getter for dictionary_. 99 // Getter for dictionary_.
113 const SubstitutionMap* dictionary() const { return &dictionary_; } 100 const SubstitutionMap* dictionary() const { return &dictionary_; }
114 101
102 ~ExtensionMessageBundle();
103
115 private: 104 private:
116 // Testing friend. 105 // Testing friend.
117 friend class ExtensionMessageBundleTest; 106 friend class ExtensionMessageBundleTest;
118 107
119 // Use Create to create ExtensionMessageBundle instance. 108 // Use Create to create ExtensionMessageBundle instance.
120 ExtensionMessageBundle(); 109 ExtensionMessageBundle();
121 110
122 // Initializes the instance from the contents of vector of catalogs. 111 // Initializes the instance from the contents of vector of catalogs.
123 // If the key is not present in more specific catalog we fall back to next one 112 // If the key is not present in more specific catalog we fall back to next one
124 // (less specific). 113 // (less specific).
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 ExtensionToL10nMessagesMap messages_map; 161 ExtensionToL10nMessagesMap messages_map;
173 }; 162 };
174 163
175 // Returns the extension_id to messages map. 164 // Returns the extension_id to messages map.
176 ExtensionToL10nMessagesMap* GetExtensionToL10nMessagesMap(); 165 ExtensionToL10nMessagesMap* GetExtensionToL10nMessagesMap();
177 166
178 // Returns message map that matches given extension_id, or NULL. 167 // Returns message map that matches given extension_id, or NULL.
179 L10nMessagesMap* GetL10nMessagesMap(const std::string extension_id); 168 L10nMessagesMap* GetL10nMessagesMap(const std::string extension_id);
180 169
181 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_MESSAGE_BUNDLE_H_ 170 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_MESSAGE_BUNDLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698