diff options
author | adriansc@google.com <adriansc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-18 21:46:11 +0000 |
---|---|---|
committer | adriansc@google.com <adriansc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-18 21:46:11 +0000 |
commit | f8cc62e64f6c43deb5973cadecf74e63d7162410 (patch) | |
tree | 022aeec91c32e1fc42ccf2a40336b1735ef88129 /chrome/common/extensions | |
parent | d8214f5e1cde6f9ded0ae6a749208c33dc3bf2be (diff) | |
download | chromium_src-f8cc62e64f6c43deb5973cadecf74e63d7162410.zip chromium_src-f8cc62e64f6c43deb5973cadecf74e63d7162410.tar.gz chromium_src-f8cc62e64f6c43deb5973cadecf74e63d7162410.tar.bz2 |
Added code for localizing scripts CSS before injection takes place.
BUG=39899
TEST=browser_tests:ExtensionApiTest.ContentScriptCSSLocalization
Review URL: http://codereview.chromium.org/7552028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97365 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions')
-rw-r--r-- | chrome/common/extensions/extension_file_util.cc | 25 | ||||
-rw-r--r-- | chrome/common/extensions/extension_file_util.h | 9 | ||||
-rw-r--r-- | chrome/common/extensions/extension_set.cc | 10 | ||||
-rw-r--r-- | chrome/common/extensions/extension_set.h | 7 |
4 files changed, 51 insertions, 0 deletions
diff --git a/chrome/common/extensions/extension_file_util.cc b/chrome/common/extensions/extension_file_util.cc index e7ba195..55ca7de 100644 --- a/chrome/common/extensions/extension_file_util.cc +++ b/chrome/common/extensions/extension_file_util.cc @@ -20,6 +20,8 @@ #include "chrome/common/extensions/extension_action.h" #include "chrome/common/extensions/extension_constants.h" #include "chrome/common/extensions/extension_l10n_util.h" +#include "chrome/common/extensions/extension_messages.h" +#include "chrome/common/extensions/extension_message_bundle.h" #include "chrome/common/extensions/extension_resource.h" #include "chrome/common/extensions/extension_sidebar_defaults.h" #include "content/common/json_value_serializer.h" @@ -400,6 +402,29 @@ ExtensionMessageBundle* LoadExtensionMessageBundle( return message_bundle; } +SubstitutionMap* LoadExtensionMessageBundleSubstitutionMap( + const FilePath& extension_path, + const std::string& extension_id, + const std::string& default_locale) { + SubstitutionMap* returnValue = new SubstitutionMap(); + if (!default_locale.empty()) { + // Touch disk only if extension is localized. + std::string error; + scoped_ptr<ExtensionMessageBundle> bundle( + LoadExtensionMessageBundle(extension_path, default_locale, &error)); + + if (bundle.get()) + *returnValue = *bundle->dictionary(); + } + + // Add @@extension_id reserved message here, so it's available to + // non-localized extensions too. + returnValue->insert( + std::make_pair(ExtensionMessageBundle::kExtensionIdKey, extension_id)); + + return returnValue; +} + static bool ValidateLocaleInfo(const Extension& extension, std::string* error) { // default_locale and _locales have to be both present or both missing. const FilePath path = extension.path().Append(Extension::kLocaleFolder); diff --git a/chrome/common/extensions/extension_file_util.h b/chrome/common/extensions/extension_file_util.h index 7913e2f..ce60673 100644 --- a/chrome/common/extensions/extension_file_util.h +++ b/chrome/common/extensions/extension_file_util.h @@ -10,6 +10,7 @@ #include <map> #include "chrome/common/extensions/extension.h" +#include "chrome/common/extensions/extension_message_bundle.h" class Extension; class ExtensionMessageBundle; @@ -66,6 +67,14 @@ ExtensionMessageBundle* LoadExtensionMessageBundle( const std::string& default_locale, std::string* error); +// Loads the extension message bundle substitution map. Contains at least +// extension_id item. +ExtensionMessageBundle::SubstitutionMap* + LoadExtensionMessageBundleSubstitutionMap( + const FilePath& extension_path, + const std::string& extension_id, + const std::string& default_locale); + // We need to reserve the namespace of entries that start with "_" for future // use by Chrome. // If any files or directories are found using "_" prefix and are not on diff --git a/chrome/common/extensions/extension_set.cc b/chrome/common/extensions/extension_set.cc index 0825089..c839fd6d 100644 --- a/chrome/common/extensions/extension_set.cc +++ b/chrome/common/extensions/extension_set.cc @@ -79,3 +79,13 @@ bool ExtensionSet::ExtensionBindingsAllowed(const GURL& url) const { return false; } + +void ExtensionSet::GetExtensionsPathAndDefaultLocale( + std::map<std::string, ExtensionPathAndDefaultLocale>& info) const { + info.clear(); + ExtensionMap::const_iterator i = extensions_.begin(); + for (; i != extensions_.end(); ++i) { + info[i->first] = std::make_pair(i->second->path(), + i->second->default_locale()); + } +} diff --git a/chrome/common/extensions/extension_set.h b/chrome/common/extensions/extension_set.h index dbd16ad..d50086b 100644 --- a/chrome/common/extensions/extension_set.h +++ b/chrome/common/extensions/extension_set.h @@ -6,6 +6,7 @@ #define CHROME_COMMON_EXTENSIONS_EXTENSION_SET_H_ #pragma once +#include <map> #include <string> #include <vector> @@ -18,6 +19,8 @@ // Only one extension can be in the set with a given ID. class ExtensionSet { public: + typedef std::pair<FilePath, std::string> ExtensionPathAndDefaultLocale; + ExtensionSet(); ~ExtensionSet(); @@ -57,6 +60,10 @@ class ExtensionSet { // permissions the given extension has been granted. bool ExtensionBindingsAllowed(const GURL& url) const; + // Populates map with the path and default locale for all extension IDs. + void GetExtensionsPathAndDefaultLocale( + std::map<std::string, ExtensionPathAndDefaultLocale>& info) const; + private: FRIEND_TEST_ALL_PREFIXES(ExtensionSetTest, ExtensionSet); |