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

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

Issue 1547413002: Reland of Change extension icon load errors to warnings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months 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
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"
16 #include "extensions/common/manifest_constants.h" 17 #include "extensions/common/manifest_constants.h"
18 #include "grit/extensions_strings.h"
19 #include "ui/base/l10n/l10n_util.h"
17 20
18 namespace extensions { 21 namespace extensions {
19 22
20 namespace errors = manifest_errors; 23 namespace errors = manifest_errors;
21 24
22 namespace manifest_handler_helpers { 25 namespace manifest_handler_helpers {
23 26
24 bool NormalizeAndValidatePath(std::string* path) { 27 bool NormalizeAndValidatePath(std::string* path) {
25 size_t first_non_slash = path->find_first_not_of('/'); 28 size_t first_non_slash = path->find_first_not_of('/');
26 if (first_non_slash == std::string::npos) { 29 if (first_non_slash == std::string::npos) {
27 *path = ""; 30 *path = "";
28 return false; 31 return false;
29 } 32 }
30 33
31 *path = path->substr(first_non_slash); 34 *path = path->substr(first_non_slash);
32 return true; 35 return true;
33 } 36 }
34 37
35 bool LoadIconsFromDictionary(const base::DictionaryValue* icons_value, 38 bool LoadIconsFromDictionary(Extension* extension,
39 const base::DictionaryValue* icons_value,
36 ExtensionIconSet* icons, 40 ExtensionIconSet* icons,
37 base::string16* error) { 41 base::string16* error) {
38 DCHECK(icons); 42 DCHECK(icons);
39 DCHECK(error); 43 DCHECK(error);
40 for (base::DictionaryValue::Iterator iterator(*icons_value); 44 for (base::DictionaryValue::Iterator iterator(*icons_value);
41 !iterator.IsAtEnd(); iterator.Advance()) { 45 !iterator.IsAtEnd(); iterator.Advance()) {
42 int size = 0; 46 int size = 0;
43 std::string icon_path; 47 std::string icon_path;
44 if (!base::StringToInt(iterator.key(), &size) || 48 if (!base::StringToInt(iterator.key(), &size) ||
45 !iterator.value().GetAsString(&icon_path) || 49 !iterator.value().GetAsString(&icon_path) ||
46 !NormalizeAndValidatePath(&icon_path)) { 50 !NormalizeAndValidatePath(&icon_path)) {
47 *error = ErrorUtils::FormatErrorMessageUTF16(errors::kInvalidIconPath, 51 *error = ErrorUtils::FormatErrorMessageUTF16(errors::kInvalidIconPath,
48 iterator.key()); 52 iterator.key());
49 return false; 53 return false;
50 } 54 }
51 55
52 icons->Add(size, icon_path); 56 // For backwards compatibility, only warn (don't error out) if an icon is
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 }
53 } 73 }
54 return true; 74 return true;
55 } 75 }
56 76
57 } // namespace manifest_handler_helpers 77 } // namespace manifest_handler_helpers
58 78
59 } // namespace extensions 79 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698