Index: extensions/common/file_util.cc |
diff --git a/extensions/common/file_util.cc b/extensions/common/file_util.cc |
index ba8abe416415831d3d3a7794b6d0b665a48809c1..e6e70667ffd3f6f99a3f9e71b97effce2202a451 100644 |
--- a/extensions/common/file_util.cc |
+++ b/extensions/common/file_util.cc |
@@ -8,11 +8,30 @@ |
#include "base/file_util.h" |
#include "base/files/file_path.h" |
+#include "base/strings/utf_string_conversions.h" |
+#include "extensions/common/extension.h" |
+#include "extensions/common/extension_icon_set.h" |
#include "net/base/escape.h" |
+#include "ui/base/l10n/l10n_util.h" |
#include "url/gurl.h" |
namespace extensions { |
namespace file_util { |
+namespace { |
+ |
+// Returns true if the given file path exists and is not zero-length. |
+bool ValidateFilePath(const base::FilePath& path) { |
+ int64 size = 0; |
+ if (!base::PathExists(path) || |
+ !base::GetFileSize(path, &size) || |
+ size == 0) { |
+ return false; |
+ } |
+ |
+ return true; |
+} |
+ |
+} // namespace |
base::FilePath ExtensionURLToRelativeFilePath(const GURL& url) { |
std::string url_path = url.path(); |
@@ -57,5 +76,23 @@ base::FilePath ExtensionResourceURLToFilePath(const GURL& url, |
return path; |
} |
+bool ValidateExtensionIconSet(const ExtensionIconSet& icon_set, |
+ const Extension* extension, |
+ int error_message_id, |
+ std::string* error) { |
+ for (ExtensionIconSet::IconMap::const_iterator iter = icon_set.map().begin(); |
+ iter != icon_set.map().end(); |
+ ++iter) { |
+ const base::FilePath path = |
+ extension->GetResource(iter->second).GetFilePath(); |
+ if (!ValidateFilePath(path)) { |
+ *error = l10n_util::GetStringFUTF8(error_message_id, |
+ base::UTF8ToUTF16(iter->second)); |
+ return false; |
+ } |
+ } |
+ return true; |
+} |
+ |
} // namespace file_util |
} // namespace extensions |