| 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_handlers/icons_handler.h" | 5 #include "extensions/common/manifest_handlers/icons_handler.h" |
| 6 | 6 |
| 7 #include <memory> |
| 8 |
| 7 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 8 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/values.h" | 13 #include "base/values.h" |
| 13 #include "extensions/common/constants.h" | 14 #include "extensions/common/constants.h" |
| 14 #include "extensions/common/extension.h" | 15 #include "extensions/common/extension.h" |
| 15 #include "extensions/common/file_util.h" | 16 #include "extensions/common/file_util.h" |
| 16 #include "extensions/common/manifest_constants.h" | 17 #include "extensions/common/manifest_constants.h" |
| 17 #include "extensions/common/manifest_handler_helpers.h" | 18 #include "extensions/common/manifest_handler_helpers.h" |
| 18 #include "grit/extensions_strings.h" | 19 #include "grit/extensions_strings.h" |
| 19 #include "ui/gfx/geometry/size.h" | 20 #include "ui/gfx/geometry/size.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 49 return path.empty() ? GURL() : extension->GetResourceURL(path); | 50 return path.empty() ? GURL() : extension->GetResourceURL(path); |
| 50 } | 51 } |
| 51 | 52 |
| 52 IconsHandler::IconsHandler() { | 53 IconsHandler::IconsHandler() { |
| 53 } | 54 } |
| 54 | 55 |
| 55 IconsHandler::~IconsHandler() { | 56 IconsHandler::~IconsHandler() { |
| 56 } | 57 } |
| 57 | 58 |
| 58 bool IconsHandler::Parse(Extension* extension, base::string16* error) { | 59 bool IconsHandler::Parse(Extension* extension, base::string16* error) { |
| 59 scoped_ptr<IconsInfo> icons_info(new IconsInfo); | 60 std::unique_ptr<IconsInfo> icons_info(new IconsInfo); |
| 60 const base::DictionaryValue* icons_dict = NULL; | 61 const base::DictionaryValue* icons_dict = NULL; |
| 61 if (!extension->manifest()->GetDictionary(keys::kIcons, &icons_dict)) { | 62 if (!extension->manifest()->GetDictionary(keys::kIcons, &icons_dict)) { |
| 62 *error = base::ASCIIToUTF16(manifest_errors::kInvalidIcons); | 63 *error = base::ASCIIToUTF16(manifest_errors::kInvalidIcons); |
| 63 return false; | 64 return false; |
| 64 } | 65 } |
| 65 | 66 |
| 66 if (!manifest_handler_helpers::LoadIconsFromDictionary( | 67 if (!manifest_handler_helpers::LoadIconsFromDictionary( |
| 67 icons_dict, &icons_info->icons, error)) { | 68 icons_dict, &icons_info->icons, error)) { |
| 68 return false; | 69 return false; |
| 69 } | 70 } |
| 70 | 71 |
| 71 extension->SetManifestData(keys::kIcons, icons_info.release()); | 72 extension->SetManifestData(keys::kIcons, icons_info.release()); |
| 72 return true; | 73 return true; |
| 73 } | 74 } |
| 74 | 75 |
| 75 bool IconsHandler::Validate(const Extension* extension, | 76 bool IconsHandler::Validate(const Extension* extension, |
| 76 std::string* error, | 77 std::string* error, |
| 77 std::vector<InstallWarning>* warnings) const { | 78 std::vector<InstallWarning>* warnings) const { |
| 78 return file_util::ValidateExtensionIconSet(IconsInfo::GetIcons(extension), | 79 return file_util::ValidateExtensionIconSet(IconsInfo::GetIcons(extension), |
| 79 extension, | 80 extension, |
| 80 IDS_EXTENSION_LOAD_ICON_FAILED, | 81 IDS_EXTENSION_LOAD_ICON_FAILED, |
| 81 error); | 82 error); |
| 82 } | 83 } |
| 83 | 84 |
| 84 const std::vector<std::string> IconsHandler::Keys() const { | 85 const std::vector<std::string> IconsHandler::Keys() const { |
| 85 return SingleKey(keys::kIcons); | 86 return SingleKey(keys::kIcons); |
| 86 } | 87 } |
| 87 | 88 |
| 88 } // namespace extensions | 89 } // namespace extensions |
| OLD | NEW |