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

Side by Side Diff: chrome/common/extensions/manifest_handler_helpers.cc

Issue 11588004: Move ScriptBadge, ActionInfo out of Extension; preparation for BrowserAction (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/common/extensions/manifest_handler_helpers.h"
6
7 #include "base/logging.h"
8 #include "base/string_number_conversions.h"
9 #include "base/values.h"
10 #include "chrome/common/extensions/extension_icon_set.h"
11 #include "chrome/common/extensions/extension_manifest_constants.h"
12 #include "extensions/common/error_utils.h"
13
14 namespace errors = extension_manifest_errors;
15
16 namespace extensions {
17 namespace manifest_handler_helpers {
18
19 bool NormalizeAndValidatePath(std::string* path) {
20 size_t first_non_slash = path->find_first_not_of('/');
21 if (first_non_slash == std::string::npos) {
22 *path = "";
23 return false;
24 }
25
26 *path = path->substr(first_non_slash);
27 return true;
28 }
29
30 bool LoadIconsFromDictionary(const base::DictionaryValue* icons_value,
31 const int* icon_sizes,
32 size_t num_icon_sizes,
33 ExtensionIconSet* icons,
34 string16* error) {
35 DCHECK(icons);
36 for (size_t i = 0; i < num_icon_sizes; ++i) {
37 std::string key = base::IntToString(icon_sizes[i]);
38 if (icons_value->HasKey(key)) {
39 std::string icon_path;
40 if (!icons_value->GetString(key, &icon_path)) {
41 *error = ErrorUtils::FormatErrorMessageUTF16(
42 errors::kInvalidIconPath, key);
43 return false;
44 }
45
46 if (!NormalizeAndValidatePath(&icon_path)) {
47 *error = ErrorUtils::FormatErrorMessageUTF16(
48 errors::kInvalidIconPath, key);
49 return false;
50 }
51
52 icons->Add(icon_sizes[i], icon_path);
53 }
54 }
55 return true;
56 }
57
58 } // namespace extensions
59 } // namespace manifest_handler_extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698