diff options
author | cira@chromium.org <cira@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-18 21:07:39 +0000 |
---|---|---|
committer | cira@chromium.org <cira@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-18 21:07:39 +0000 |
commit | 42b6f0f83579563a94bd9fdeec83574a1a932f18 (patch) | |
tree | bfdb770830f27f306eaeca8da46a6dd9e7ed8647 /chrome/browser/extensions/extension_file_util.cc | |
parent | 60ad3e2b8540ba00a2e5d0624fd2796e7780b11c (diff) | |
download | chromium_src-42b6f0f83579563a94bd9fdeec83574a1a932f18.zip chromium_src-42b6f0f83579563a94bd9fdeec83574a1a932f18.tar.gz chromium_src-42b6f0f83579563a94bd9fdeec83574a1a932f18.tar.bz2 |
CL is the same as http://codereview.chromium.org/173487, but had to be moved to new CL number because I switched machines.
Implemented the rest of loading/parsing logic for extension i18n:
1. Loading message catalogs for default and application locale.
2. Parsing JSON and replacing placeholders with actual content within a message.
3. Creating unified dictionary (union of default and application dictionaries,
where application dict. has priority for common messages).
New class ExtensionMessageBundle holds new dictionary, and parses data. It's
injected into Extension.
ExtensionMessageHandler::ReplaceVariablesInString can replace both
$placeholders$ and __MSG_messages__ in given string (HTML, manifest, actual
message string...).
Implemented actual manifest name/description replacement too, as an example.
Extension is now pretty agnostic about localization, and this makes it easier to use message bundles
with things that are not extensions...
BUG=12131
Review URL: http://codereview.chromium.org/202063
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26609 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_file_util.cc')
-rw-r--r-- | chrome/browser/extensions/extension_file_util.cc | 65 |
1 files changed, 46 insertions, 19 deletions
diff --git a/chrome/browser/extensions/extension_file_util.cc b/chrome/browser/extensions/extension_file_util.cc index 9c15da3..1692c67 100644 --- a/chrome/browser/extensions/extension_file_util.cc +++ b/chrome/browser/extensions/extension_file_util.cc @@ -4,6 +4,7 @@ #include "chrome/browser/extensions/extension_file_util.h" +#include "app/l10n_util.h" #include "base/file_util.h" #include "base/logging.h" #include "base/scoped_temp_dir.h" @@ -94,7 +95,8 @@ bool InstallExtension(const FilePath& src_dir, return true; } -Extension* LoadExtension(const FilePath& extension_path, bool require_key, +Extension* LoadExtension(const FilePath& extension_path, + bool require_key, std::string* error) { FilePath manifest_path = extension_path.AppendASCII(Extension::kManifestFilename); @@ -113,9 +115,16 @@ Extension* LoadExtension(const FilePath& extension_path, bool require_key, return NULL; } + DictionaryValue* manifest = static_cast<DictionaryValue*>(root.get()); + ExtensionMessageBundle* message_bundle = + LoadLocaleInfo(extension_path, *manifest, error); + if (!message_bundle && !error->empty()) + return NULL; + scoped_ptr<Extension> extension(new Extension(extension_path)); - if (!extension->InitFromValue(*static_cast<DictionaryValue*>(root.get()), - require_key, error)) + // Assign message bundle to extension. + extension->set_message_bundle(message_bundle); + if (!extension->InitFromValue(*manifest, require_key, error)) return NULL; if (!ValidateExtension(extension.get(), error)) @@ -218,22 +227,6 @@ bool ValidateExtension(Extension* extension, std::string* error) { } } - // Load locale information if available. - FilePath locale_path = - extension->path().AppendASCII(Extension::kLocaleFolder); - if (file_util::PathExists(locale_path)) { - if (!extension_l10n_util::AddValidLocales(locale_path, - extension, - error)) { - return false; - } - - if (!extension_l10n_util::ValidateDefaultLocale(extension)) { - *error = extension_manifest_errors::kLocalesNoDefaultLocaleSpecified; - return false; - } - } - // Check children of extension root to see if any of them start with _ and is // not on the reserved list. if (!CheckForIllegalFilenames(extension->path(), error)) { @@ -311,6 +304,40 @@ void GarbageCollectExtensions(const FilePath& install_directory, } } +ExtensionMessageBundle* LoadLocaleInfo(const FilePath& extension_path, + const DictionaryValue& manifest, + std::string* error) { + error->clear(); + // Load locale information if available. + FilePath locale_path = extension_path.AppendASCII(Extension::kLocaleFolder); + if (!file_util::PathExists(locale_path)) + return NULL; + + std::set<std::string> locales; + if (!extension_l10n_util::GetValidLocales(locale_path, &locales, error)) + return NULL; + + std::string default_locale = + extension_l10n_util::GetDefaultLocaleFromManifest(manifest, error); + if (default_locale.empty() || + locales.find(default_locale) == locales.end()) { + *error = extension_manifest_errors::kLocalesNoDefaultLocaleSpecified; + return NULL; + } + + // We can't call g_browser_process->GetApplicationLocale() since we are not + // on the main thread. + static std::string app_locale = l10n_util::GetApplicationLocale(L""); + if (locales.find(app_locale) == locales.end()) + app_locale = ""; + ExtensionMessageBundle* message_bundle = + extension_l10n_util::LoadMessageCatalogs(locale_path, + default_locale, + app_locale, + error); + return message_bundle; +} + bool CheckForIllegalFilenames(const FilePath& extension_path, std::string* error) { // Reserved underscore names. |