summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
authorxji@chromium.org <xji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-21 18:32:35 +0000
committerxji@chromium.org <xji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-21 18:32:35 +0000
commit49a7c77691cc0eaa2a7028ce51cd6de9edc78c4e (patch)
treef37b16dc6e7e1f11a80ee04b6e000cb9b7ab6bf9 /chrome/common
parentd885bfe7aba1fdd42cbd86f4ba5f43416987c8ae (diff)
downloadchromium_src-49a7c77691cc0eaa2a7028ce51cd6de9edc78c4e.zip
chromium_src-49a7c77691cc0eaa2a7028ce51cd6de9edc78c4e.tar.gz
chromium_src-49a7c77691cc0eaa2a7028ce51cd6de9edc78c4e.tar.bz2
Fix problem of displaying title with parenthesis in extension.
Wrap title with correctly bidi control characters in windows for display purpose. BUG=43485 TEST=1. open RTL chrome. 2. install Google dictionary extension. 3. extension title "Google Dictionary (by Google)" should be displayed as is in chrome://extensions page, 4. right click the extension icon, title "Google Dictionary (by Google)" should be displayed in extension context menu, 5. extension title should be displayed correctly in other places, such as task manager, etc. Review URL: http://codereview.chromium.org/2015004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47937 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r--chrome/common/extensions/extension.cc8
-rw-r--r--chrome/common/extensions/extension.h5
-rw-r--r--chrome/common/extensions/extension_unittest.cc56
3 files changed, 64 insertions, 5 deletions
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc
index db6e934..956017c 100644
--- a/chrome/common/extensions/extension.cc
+++ b/chrome/common/extensions/extension.cc
@@ -14,6 +14,7 @@
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/file_version_info.h"
+#include "base/i18n/rtl.h"
#include "base/logging.h"
#include "base/stl_util-inl.h"
#include "base/third_party/nss/blapi.h"
@@ -971,10 +972,13 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key,
}
// Initialize name.
- if (!source.GetString(keys::kName, &name_)) {
+ std::wstring localized_name;
+ if (!source.GetString(keys::kName, &localized_name)) {
*error = errors::kInvalidName;
return false;
}
+ base::i18n::AdjustStringForLocaleDirection(localized_name, &localized_name);
+ name_ = WideToUTF8(localized_name);
// Initialize description (if present).
if (source.HasKey(keys::kDescription)) {
@@ -1586,7 +1590,7 @@ Extension::Icons Extension::GetIconPathAllowLargerSize(
// We support http:// and https:// as well as chrome://favicon//.
// chrome://resources/ is supported but only for component extensions.
-bool Extension::CanAccessURL(const URLPattern pattern) const{
+bool Extension::CanAccessURL(const URLPattern pattern) const {
if (pattern.scheme() == chrome::kHttpScheme ||
pattern.scheme() == chrome::kHttpsScheme) {
return true;
diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h
index 99f7898..9063b12 100644
--- a/chrome/common/extensions/extension.h
+++ b/chrome/common/extensions/extension.h
@@ -421,7 +421,10 @@ class Extension {
// The extension's version.
scoped_ptr<Version> version_;
- // The extension's human-readable name.
+ // The extension's human-readable name. Name is used for display purpose. It
+ // might be wrapped with unicode bidi control characters so that it is
+ // displayed correctly in RTL context.
+ // NOTE: Name is UTF-8 and may contain non-ascii characters.
std::string name_;
// An optional longer description of the extension.
diff --git a/chrome/common/extensions/extension_unittest.cc b/chrome/common/extensions/extension_unittest.cc
index 39061a1b..6db3f61 100644
--- a/chrome/common/extensions/extension_unittest.cc
+++ b/chrome/common/extensions/extension_unittest.cc
@@ -4,11 +4,18 @@
#include "chrome/common/extensions/extension.h"
+#if defined(TOOLKIT_GTK)
+#include <gtk/gtk.h>
+#endif
+
+#include "app/l10n_util.h"
#include "base/format_macros.h"
#include "base/file_path.h"
#include "base/file_util.h"
+#include "base/i18n/rtl.h"
#include "base/string_util.h"
#include "base/path_service.h"
+#include "base/utf_string_conversions.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/extensions/extension_action.h"
#include "chrome/common/extensions/extension_constants.h"
@@ -86,7 +93,7 @@ TEST(ExtensionTest, InitFromValueInvalid) {
EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error));
EXPECT_EQ(errors::kInvalidVersion, error);
- // Test missing and invalid names
+ // Test missing and invalid names.
input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy()));
input_value->Remove(keys::kName, NULL);
EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error));
@@ -334,6 +341,51 @@ TEST(ExtensionTest, InitFromValueValid) {
#endif
}
+TEST(ExtensionTest, InitFromValueValidNameInRTL) {
+#if defined(TOOLKIT_GTK)
+ GtkTextDirection gtk_dir = gtk_widget_get_default_direction();
+ gtk_widget_set_default_direction(GTK_TEXT_DIR_RTL);
+#else
+ std::string locale = l10n_util::GetApplicationLocale(std::wstring());
+ base::i18n::SetICUDefaultLocale("he");
+#endif
+
+#if defined(OS_WIN)
+ FilePath path(FILE_PATH_LITERAL("C:\\foo"));
+#elif defined(OS_POSIX)
+ FilePath path(FILE_PATH_LITERAL("/foo"));
+#endif
+ Extension extension(path);
+ std::string error;
+ DictionaryValue input_value;
+
+ input_value.SetString(keys::kVersion, "1.0.0.0");
+ // No strong RTL characters in name.
+ std::wstring name(L"Dictionary (by Google)");
+ input_value.SetString(keys::kName, name);
+ EXPECT_TRUE(extension.InitFromValue(input_value, false, &error));
+ EXPECT_EQ("", error);
+ std::wstring localized_name(name);
+ base::i18n::AdjustStringForLocaleDirection(localized_name, &localized_name);
+ EXPECT_EQ(localized_name, UTF8ToWide(extension.name()));
+
+ // Strong RTL characters in name.
+ name = L"Dictionary (\x05D1\x05D2"L" Google)";
+ input_value.SetString(keys::kName, name);
+ EXPECT_TRUE(extension.InitFromValue(input_value, false, &error));
+ EXPECT_EQ("", error);
+ localized_name = name;
+ base::i18n::AdjustStringForLocaleDirection(localized_name, &localized_name);
+ EXPECT_EQ(localized_name, UTF8ToWide(extension.name()));
+
+ // Reset locale.
+#if defined(TOOLKIT_GTK)
+ gtk_widget_set_default_direction(gtk_dir);
+#else
+ base::i18n::SetICUDefaultLocale(locale);
+#endif
+}
+
TEST(ExtensionTest, GetResourceURLAndPath) {
#if defined(OS_WIN)
FilePath path(FILE_PATH_LITERAL("C:\\foo"));
@@ -775,7 +827,7 @@ TEST(ExtensionTest, IsPrivilegeIncrease) {
{ "plugin2", false }, // plugin -> none
{ "plugin3", true }, // none -> plugin
{ "storage", false }, // none -> storage
- { "notifications", false } // none -> notifications
+ { "notifications", false } // none -> notifications
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) {