summaryrefslogtreecommitdiffstats
path: root/extensions/common/manifest_handler_helpers.cc
diff options
context:
space:
mode:
authorrockot@chromium.org <rockot@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-08 18:48:52 +0000
committerrockot@chromium.org <rockot@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-08 18:48:52 +0000
commitaadde5988b5b71abcf99d1c4d8fa77290165b801 (patch)
treea73e811c055e968eaf712efad26234ae51a9108c /extensions/common/manifest_handler_helpers.cc
parent3bd9be0e7330b753699e200e31f48342a591c68c (diff)
downloadchromium_src-aadde5988b5b71abcf99d1c4d8fa77290165b801.zip
chromium_src-aadde5988b5b71abcf99d1c4d8fa77290165b801.tar.gz
chromium_src-aadde5988b5b71abcf99d1c4d8fa77290165b801.tar.bz2
Move manifest_handler_helpers to //extensions
BUG=359836 Review URL: https://codereview.chromium.org/228603004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@262464 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'extensions/common/manifest_handler_helpers.cc')
-rw-r--r--extensions/common/manifest_handler_helpers.cc64
1 files changed, 64 insertions, 0 deletions
diff --git a/extensions/common/manifest_handler_helpers.cc b/extensions/common/manifest_handler_helpers.cc
new file mode 100644
index 0000000..d3dfea6
--- /dev/null
+++ b/extensions/common/manifest_handler_helpers.cc
@@ -0,0 +1,64 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "extensions/common/manifest_handler_helpers.h"
+
+#include "base/logging.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/strings/utf_string_conversions.h"
+#include "base/values.h"
+#include "extensions/common/error_utils.h"
+#include "extensions/common/extension.h"
+#include "extensions/common/extension_icon_set.h"
+#include "extensions/common/manifest_constants.h"
+
+
+namespace extensions {
+
+namespace errors = manifest_errors;
+
+namespace manifest_handler_helpers {
+
+bool NormalizeAndValidatePath(std::string* path) {
+ size_t first_non_slash = path->find_first_not_of('/');
+ if (first_non_slash == std::string::npos) {
+ *path = "";
+ return false;
+ }
+
+ *path = path->substr(first_non_slash);
+ return true;
+}
+
+bool LoadIconsFromDictionary(const base::DictionaryValue* icons_value,
+ const int* icon_sizes,
+ size_t num_icon_sizes,
+ ExtensionIconSet* icons,
+ base::string16* error) {
+ DCHECK(icons);
+ for (size_t i = 0; i < num_icon_sizes; ++i) {
+ std::string key = base::IntToString(icon_sizes[i]);
+ if (icons_value->HasKey(key)) {
+ std::string icon_path;
+ if (!icons_value->GetString(key, &icon_path)) {
+ *error = ErrorUtils::FormatErrorMessageUTF16(
+ errors::kInvalidIconPath, key);
+ return false;
+ }
+
+ if (!NormalizeAndValidatePath(&icon_path)) {
+ *error = ErrorUtils::FormatErrorMessageUTF16(
+ errors::kInvalidIconPath, key);
+ return false;
+ }
+
+ icons->Add(icon_sizes[i], icon_path);
+ }
+ }
+ return true;
+}
+
+} // namespace manifest_handler_helpers
+
+} // namespace extensions