OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "extensions/common/manifest_handler_helpers.h" | 5 #include "extensions/common/manifest_handler_helpers.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "extensions/common/error_utils.h" | 11 #include "extensions/common/error_utils.h" |
12 #include "extensions/common/extension.h" | 12 #include "extensions/common/extension.h" |
13 #include "extensions/common/extension_icon_set.h" | 13 #include "extensions/common/extension_icon_set.h" |
| 14 #include "extensions/common/file_util.h" |
14 #include "extensions/common/manifest_constants.h" | 15 #include "extensions/common/manifest_constants.h" |
15 | 16 #include "grit/extensions_strings.h" |
| 17 #include "ui/base/l10n/l10n_util.h" |
16 | 18 |
17 namespace extensions { | 19 namespace extensions { |
18 | 20 |
19 namespace errors = manifest_errors; | 21 namespace errors = manifest_errors; |
20 | 22 |
21 namespace manifest_handler_helpers { | 23 namespace manifest_handler_helpers { |
22 | 24 |
23 bool NormalizeAndValidatePath(std::string* path) { | 25 bool NormalizeAndValidatePath(std::string* path) { |
24 size_t first_non_slash = path->find_first_not_of('/'); | 26 size_t first_non_slash = path->find_first_not_of('/'); |
25 if (first_non_slash == std::string::npos) { | 27 if (first_non_slash == std::string::npos) { |
26 *path = ""; | 28 *path = ""; |
27 return false; | 29 return false; |
28 } | 30 } |
29 | 31 |
30 *path = path->substr(first_non_slash); | 32 *path = path->substr(first_non_slash); |
31 return true; | 33 return true; |
32 } | 34 } |
33 | 35 |
34 bool LoadIconsFromDictionary(const base::DictionaryValue* icons_value, | 36 bool LoadIconsFromDictionary(Extension* extension, |
| 37 const base::DictionaryValue* icons_value, |
35 ExtensionIconSet* icons, | 38 ExtensionIconSet* icons, |
36 base::string16* error) { | 39 base::string16* error) { |
37 DCHECK(icons); | 40 DCHECK(icons); |
38 DCHECK(error); | 41 DCHECK(error); |
39 for (base::DictionaryValue::Iterator iterator(*icons_value); | 42 for (base::DictionaryValue::Iterator iterator(*icons_value); |
40 !iterator.IsAtEnd(); iterator.Advance()) { | 43 !iterator.IsAtEnd(); iterator.Advance()) { |
41 int size = 0; | 44 int size = 0; |
42 std::string icon_path; | 45 std::string icon_path; |
43 if (!base::StringToInt(iterator.key(), &size) || | 46 if (!base::StringToInt(iterator.key(), &size) || |
44 !iterator.value().GetAsString(&icon_path) || | 47 !iterator.value().GetAsString(&icon_path) || |
45 !NormalizeAndValidatePath(&icon_path)) { | 48 !NormalizeAndValidatePath(&icon_path)) { |
46 *error = ErrorUtils::FormatErrorMessageUTF16(errors::kInvalidIconPath, | 49 *error = ErrorUtils::FormatErrorMessageUTF16(errors::kInvalidIconPath, |
47 iterator.key()); | 50 iterator.key()); |
48 return false; | 51 return false; |
49 } | 52 } |
50 | 53 |
51 icons->Add(size, icon_path); | 54 // For backwards compatibility, only warn (don't error out) if an icon is |
| 55 // missing. Component extensions can skip this check as their icons are not |
| 56 // located on disk. Unpacked extensions skip this check and fail later |
| 57 // during validation if the file isn't present. See crbug.com/570249 |
| 58 if (Manifest::IsComponentLocation(extension->location()) || |
| 59 Manifest::IsUnpackedLocation(extension->location()) || |
| 60 file_util::ValidateFilePath( |
| 61 extension->GetResource(icon_path).GetFilePath())) { |
| 62 icons->Add(size, icon_path); |
| 63 } else { |
| 64 extension->AddInstallWarning(InstallWarning( |
| 65 l10n_util::GetStringFUTF8(IDS_EXTENSION_LOAD_ICON_FAILED, |
| 66 base::UTF8ToUTF16(icon_path)), |
| 67 std::string())); |
| 68 } |
52 } | 69 } |
53 return true; | 70 return true; |
54 } | 71 } |
55 | 72 |
56 } // namespace manifest_handler_helpers | 73 } // namespace manifest_handler_helpers |
57 | 74 |
58 } // namespace extensions | 75 } // namespace extensions |
OLD | NEW |