| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/common/extensions/manifest_handlers/icons_handler.h" | 5 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.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 "chrome/common/extensions/extension.h" | 13 #include "chrome/common/extensions/extension.h" |
| 14 #include "chrome/common/extensions/extension_file_util.h" | 14 #include "chrome/common/extensions/extension_file_util.h" |
| 15 #include "chrome/common/extensions/extension_manifest_constants.h" | 15 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 16 #include "chrome/common/extensions/manifest_handler_helpers.h" | 16 #include "chrome/common/extensions/manifest_handler_helpers.h" |
| 17 #include "content/public/child/image_decoder_utils.h" |
| 17 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
| 18 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
| 19 #include "third_party/skia/include/core/SkBitmap.h" | 20 #include "third_party/skia/include/core/SkBitmap.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
| 21 #include "webkit/glue/image_decoder.h" | 22 #include "ui/gfx/size.h" |
| 22 | 23 |
| 23 namespace keys = extension_manifest_keys; | 24 namespace keys = extension_manifest_keys; |
| 24 | 25 |
| 25 namespace extensions { | 26 namespace extensions { |
| 26 | 27 |
| 27 static base::LazyInstance<ExtensionIconSet> g_empty_icon_set = | 28 static base::LazyInstance<ExtensionIconSet> g_empty_icon_set = |
| 28 LAZY_INSTANCE_INITIALIZER; | 29 LAZY_INSTANCE_INITIALIZER; |
| 29 | 30 |
| 30 const int IconsInfo::kPageActionIconMaxSize = 19; | 31 const int IconsInfo::kPageActionIconMaxSize = 19; |
| 31 const int IconsInfo::kBrowserActionIconMaxSize = 19; | 32 const int IconsInfo::kBrowserActionIconMaxSize = 19; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 65 |
| 65 std::string file_contents; | 66 std::string file_contents; |
| 66 if (!file_util::ReadFileToString(icon_path, &file_contents)) { | 67 if (!file_util::ReadFileToString(icon_path, &file_contents)) { |
| 67 DLOG(ERROR) << "Could not read icon file: " << icon_path.LossyDisplayName(); | 68 DLOG(ERROR) << "Could not read icon file: " << icon_path.LossyDisplayName(); |
| 68 return; | 69 return; |
| 69 } | 70 } |
| 70 | 71 |
| 71 // Decode the image using WebKit's image decoder. | 72 // Decode the image using WebKit's image decoder. |
| 72 const unsigned char* data = | 73 const unsigned char* data = |
| 73 reinterpret_cast<const unsigned char*>(file_contents.data()); | 74 reinterpret_cast<const unsigned char*>(file_contents.data()); |
| 74 webkit_glue::ImageDecoder decoder; | |
| 75 scoped_ptr<SkBitmap> decoded(new SkBitmap()); | 75 scoped_ptr<SkBitmap> decoded(new SkBitmap()); |
| 76 *decoded = decoder.Decode(data, file_contents.length()); | 76 *decoded = content::DecodeImage(data, gfx::Size(), file_contents.length()); |
| 77 if (decoded->empty()) { | 77 if (decoded->empty()) { |
| 78 DLOG(ERROR) << "Could not decode icon file: " | 78 DLOG(ERROR) << "Could not decode icon file: " |
| 79 << icon_path.LossyDisplayName(); | 79 << icon_path.LossyDisplayName(); |
| 80 return; | 80 return; |
| 81 } | 81 } |
| 82 | 82 |
| 83 if (decoded->width() != icon_size || decoded->height() != icon_size) { | 83 if (decoded->width() != icon_size || decoded->height() != icon_size) { |
| 84 DLOG(ERROR) << "Icon file has unexpected size: " | 84 DLOG(ERROR) << "Icon file has unexpected size: " |
| 85 << base::IntToString(decoded->width()) << "x" | 85 << base::IntToString(decoded->width()) << "x" |
| 86 << base::IntToString(decoded->height()); | 86 << base::IntToString(decoded->height()); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 extension, | 154 extension, |
| 155 IDS_EXTENSION_LOAD_ICON_FAILED, | 155 IDS_EXTENSION_LOAD_ICON_FAILED, |
| 156 error); | 156 error); |
| 157 } | 157 } |
| 158 | 158 |
| 159 const std::vector<std::string> IconsHandler::Keys() const { | 159 const std::vector<std::string> IconsHandler::Keys() const { |
| 160 return SingleKey(keys::kIcons); | 160 return SingleKey(keys::kIcons); |
| 161 } | 161 } |
| 162 | 162 |
| 163 } // namespace extensions | 163 } // namespace extensions |
| OLD | NEW |