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