diff options
author | cira@google.com <cira@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-30 00:01:05 +0000 |
---|---|---|
committer | cira@google.com <cira@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-30 00:01:05 +0000 |
commit | 1baafb37dc6b6462a58644e4d64c543827ead8ad (patch) | |
tree | 675a792670ac9e6de1e8890df75cbd41cbc4e4f7 /chrome/common/extensions/extension_message_bundle.h | |
parent | ad0c2e1b9d23279fabdad09f2ca00397dc197b4d (diff) | |
download | chromium_src-1baafb37dc6b6462a58644e4d64c543827ead8ad.zip chromium_src-1baafb37dc6b6462a58644e4d64c543827ead8ad.tar.gz chromium_src-1baafb37dc6b6462a58644e4d64c543827ead8ad.tar.bz2 |
Trying to re-land. It's the same as http://codereview.chromium.org/546040. Moved IsValidName to public (where it was before the change),
and made test cases for it cleaner by explicitly using std::string() around var name. Template IsValidName method had to be defined within .h file to avoid linking error on mac release build.
Add reserved messages to ExtensionMessageBundle dictionary. They are of the form @@somename, i.e. @@ui_locale.
TEST=If user specified any reserved messages in the messages.json we should show error. In memory dictionary should have @@ui_locale set to current Chrome UI locale.
Review URL: http://codereview.chromium.org/555159
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37571 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions/extension_message_bundle.h')
-rw-r--r-- | chrome/common/extensions/extension_message_bundle.h | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/chrome/common/extensions/extension_message_bundle.h b/chrome/common/extensions/extension_message_bundle.h index b44805c..eb6eaa4 100644 --- a/chrome/common/extensions/extension_message_bundle.h +++ b/chrome/common/extensions/extension_message_bundle.h @@ -30,6 +30,21 @@ class ExtensionMessageBundle { static const char* kMessageBegin; static const char* kMessageEnd; + // Reserved message names in the dictionary. + // Update i18n documentation when adding new reserved value. + static const char* kUILocaleKey; + // See http://code.google.com/apis/gadgets/docs/i18n.html#BIDI for + // description. + // TODO(cira): point to chrome docs once they are out. + static const char* kBidiDirectionKey; + static const char* kBidiReversedDirectionKey; + static const char* kBidiStartEdgeKey; + static const char* kBidiEndEdgeKey; + + // Values for some of the reserved messages. + static const char* kBidiLeftEdgeValue; + static const char* kBidiRightEdgeValue; + // Creates ExtensionMessageBundle or returns NULL if there was an error. // Expects locale_catalogs to be sorted from more specific to less specific, // with default catalog at the end. @@ -70,14 +85,28 @@ class ExtensionMessageBundle { // Allow only ascii 0-9, a-z, A-Z, and _ in the variable name. // Returns false if the input is empty or if it has illegal characters. - // Public for easier unittesting. template<typename str> - static bool IsValidName(const str& name); + static bool IsValidName(const str& name) { + if (name.empty()) + return false; + + typename str::const_iterator it = name.begin(); + for (; it != name.end(); ++it) { + // Allow only ascii 0-9, a-z, A-Z, and _ in the name. + if (!IsAsciiAlpha(*it) && !IsAsciiDigit(*it) && *it != '_' && *it != '@') + return false; + } + + return true; + } // Getter for dictionary_. const SubstitutionMap* dictionary() const { return &dictionary_; } private: + // Testing friend. + friend class ExtensionMessageBundleTest; + // Use Create to create ExtensionMessageBundle instance. ExtensionMessageBundle(); @@ -87,6 +116,11 @@ class ExtensionMessageBundle { // Returns false on error. bool Init(const CatalogVector& locale_catalogs, std::string* error); + // Appends locale specific reserved messages to the dictionary. + // Returns false if there was a conflict with user defined messages. + bool AppendReservedMessagesForLocale(const std::string& application_locale, + std::string* error); + // Helper methods that navigate JSON tree and return simplified message. // They replace all $PLACEHOLDERS$ with their value, and return just key/value // of the message. |