summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_file_util.cc
diff options
context:
space:
mode:
authorcira@chromium.org <cira@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-19 20:45:14 +0000
committercira@chromium.org <cira@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-19 20:45:14 +0000
commit300cc58db6bc8d78e279dc07c46f15d9702148c6 (patch)
tree01eb9d8585bc43b01850c226bc4d5f2a3ec00cea /chrome/browser/extensions/extension_file_util.cc
parentcceaf1fbf3f4963c59a49268217f1e3edfb372ef (diff)
downloadchromium_src-300cc58db6bc8d78e279dc07c46f15d9702148c6.zip
chromium_src-300cc58db6bc8d78e279dc07c46f15d9702148c6.tar.gz
chromium_src-300cc58db6bc8d78e279dc07c46f15d9702148c6.tar.bz2
This change enables Chrome to load locale information for the extension. It detects default locale, and filters out all locales not supported
by Chrome or with invalid names/missing messages. It also checks for folders that start with _ and are not in the reserved list. We don't validate messages file with this CL. Added support for loading supplied locale information to the extension_file_util, and detecting default locale. Added new constants to extension class (_locales directory name, messages filename). Added new error messages to _constants. Added new unittests. BUG=12131 TEST=There should be no visible changes, except in case of error when loading extension (e.g. create empty _locales folder and try loading). Review URL: http://codereview.chromium.org/170015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23739 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_file_util.cc')
-rw-r--r--chrome/browser/extensions/extension_file_util.cc60
1 files changed, 60 insertions, 0 deletions
diff --git a/chrome/browser/extensions/extension_file_util.cc b/chrome/browser/extensions/extension_file_util.cc
index 07ef77f..bf6cd9c 100644
--- a/chrome/browser/extensions/extension_file_util.cc
+++ b/chrome/browser/extensions/extension_file_util.cc
@@ -8,6 +8,7 @@
#include "base/logging.h"
#include "base/scoped_temp_dir.h"
#include "base/string_util.h"
+#include "chrome/browser/extensions/extension_l10n_util.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/json_value_serializer.h"
@@ -276,6 +277,27 @@ Extension* LoadExtension(const FilePath& extension_path, bool require_key,
}
}
+ // 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.get(),
+ error)) {
+ return NULL;
+ }
+
+ if (!extension_l10n_util::ValidateDefaultLocale(extension.get())) {
+ *error = extension_manifest_errors::kLocalesNoDefaultLocaleSpecified;
+ return NULL;
+ }
+ }
+
+ // 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)) {
+ return NULL;
+ }
+
return extension.release();
}
@@ -349,4 +371,42 @@ void GarbageCollectExtensions(const FilePath& install_directory) {
}
}
+bool CheckForIllegalFilenames(const FilePath& extension_path,
+ std::string* error) {
+ // Reserved underscore names.
+ static const char* reserved_names[] = {
+ Extension::kLocaleFolder
+ };
+ static std::set<std::string> reserved_underscore_names(
+ reserved_names, reserved_names + arraysize(reserved_names));
+
+ // Enumerate all files and directories in the extension root.
+ // There is a problem when using pattern "_*" with FileEnumerator, so we have
+ // to cheat with find_first_of and match all.
+ file_util::FileEnumerator all_files(
+ extension_path,
+ false,
+ static_cast<file_util::FileEnumerator::FILE_TYPE>(
+ file_util::FileEnumerator::DIRECTORIES |
+ file_util::FileEnumerator::FILES));
+
+ FilePath files;
+ while (!(files = all_files.Next()).empty()) {
+ std::string filename =
+ WideToASCII(files.BaseName().ToWStringHack());
+ // Skip all that don't start with "_".
+ if (filename.find_first_of("_") != 0) continue;
+ if (reserved_underscore_names.find(filename) ==
+ reserved_underscore_names.end()) {
+ *error = StringPrintf(
+ "Cannot load extension with file or directory name %s."
+ "Filenames starting with \"_\" are reserved for use by the system",
+ filename.c_str());
+ return false;
+ }
+ }
+
+ return true;
+}
+
} // extensionfile_util