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

Unified Diff: chrome/common/extensions/extension_message_bundle.cc

Issue 546040: Add reserved messages to ExtensionMessageBundle dictionary. They are of the f... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/extension_message_bundle.cc
===================================================================
--- chrome/common/extensions/extension_message_bundle.cc (revision 36561)
+++ chrome/common/extensions/extension_message_bundle.cc (working copy)
@@ -7,12 +7,19 @@
#include <string>
#include <vector>
+#include "app/l10n_util.h"
#include "base/hash_tables.h"
#include "base/linked_ptr.h"
#include "base/scoped_ptr.h"
+#include "base/stl_util-inl.h"
#include "base/string_util.h"
#include "base/values.h"
+#include "chrome/common/extensions/extension_constants.h"
+#include "chrome/common/extensions/extension_error_utils.h"
+#include "chrome/common/extensions/extension_l10n_util.h"
+namespace errors = extension_manifest_errors;
+
const wchar_t* ExtensionMessageBundle::kContentKey = L"content";
const wchar_t* ExtensionMessageBundle::kMessageKey = L"message";
const wchar_t* ExtensionMessageBundle::kPlaceholdersKey = L"placeholders";
@@ -22,6 +29,18 @@
const char* ExtensionMessageBundle::kMessageBegin = "__MSG_";
const char* ExtensionMessageBundle::kMessageEnd = "__";
+// Reserved messages names.
+const char* ExtensionMessageBundle::kUILocaleKey = "@@ui_locale";
+const char* ExtensionMessageBundle::kBidiDirectionKey = "@@bidi_dir";
+const char* ExtensionMessageBundle::kBidiReversedDirectionKey =
+ "@@bidi_reversed_dir";
+const char* ExtensionMessageBundle::kBidiStartEdgeKey = "@@bidi_start_edge";
+const char* ExtensionMessageBundle::kBidiEndEdgeKey = "@@bidi_end_edge";
+
+// Reserved messages values.
+const char* ExtensionMessageBundle::kBidiLeftEdgeValue = "left";
+const char* ExtensionMessageBundle::kBidiRightEdgeValue = "right";
+
// Formats message in case we encounter a bad formed key in the JSON object.
// Returns false and sets |error| to actual error message.
static bool BadKeyMessage(const std::string& name, std::string* error) {
@@ -62,9 +81,48 @@
}
}
+ if (!AppendReservedMessages(extension_l10n_util::CurrentLocaleOrDefault(),
+ error))
+ return false;
+
return true;
}
+bool ExtensionMessageBundle::AppendReservedMessages(
+ const std::string& app_locale, std::string* error) {
+ SubstitutionMap append_messages;
+ append_messages[kUILocaleKey] = app_locale;
+
+ // Calling l10n_util::GetTextDirection on non-UI threads doesn't seems safe,
+ // so we use GetTextDirectionForLocale instead.
+ if (l10n_util::GetTextDirectionForLocale(app_locale.c_str()) ==
+ l10n_util::RIGHT_TO_LEFT) {
+ append_messages[kBidiDirectionKey] = "rtl";
+ append_messages[kBidiReversedDirectionKey] = "ltr";
+ append_messages[kBidiStartEdgeKey] = kBidiRightEdgeValue;
+ append_messages[kBidiEndEdgeKey] = kBidiLeftEdgeValue;
+ } else {
+ append_messages[kBidiDirectionKey] = "ltr";
+ append_messages[kBidiReversedDirectionKey] = "rtl";
+ append_messages[kBidiStartEdgeKey] = kBidiLeftEdgeValue;
+ append_messages[kBidiEndEdgeKey] = kBidiRightEdgeValue;
+ }
+
+ // Add all reserved messages to the dictionary, but check for collisions.
+ SubstitutionMap::iterator it = append_messages.begin();
+ for (; it != append_messages.end(); ++it) {
+ if (ContainsKey(dictionary_, it->first)) {
+ *error = ExtensionErrorUtils::FormatErrorMessage(
+ errors::kReservedMessageFound, it->first);
+ return false;
+ } else {
+ dictionary_[it->first] = it->second;
+ }
+ }
+
+ return true;
+}
+
bool ExtensionMessageBundle::GetMessageValue(const std::wstring& wkey,
const DictionaryValue& catalog,
std::string* value,
@@ -215,7 +273,7 @@
for (typename str::const_iterator it = name.begin(); it != name.end(); ++it) {
// Allow only ascii 0-9, a-z, A-Z, and _ in the name.
- if (!IsAsciiAlpha(*it) && !IsAsciiDigit(*it) && *it != '_')
+ if (!IsAsciiAlpha(*it) && !IsAsciiDigit(*it) && *it != '_' && *it != '@')
return false;
}

Powered by Google App Engine
This is Rietveld 408576698