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