Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Unified Diff: extensions/common/file_util.cc

Issue 229813002: Move extensions manifest IconsHandler to //extensions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: skia include (icons-handler) Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698