Update CrOS OOBE throbber to MD throbber; delete old asset
[chromium-blink-merge.git] / chrome / common / extensions / manifest_handlers / linked_app_icons.cc
blob316cf606e4cc613e7a3696ff3b49f27b575f8c80
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/common/extensions/manifest_handlers/linked_app_icons.h"
7 #include "base/lazy_instance.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "base/values.h"
10 #include "extensions/common/manifest.h"
11 #include "extensions/common/manifest_constants.h"
13 namespace extensions {
15 namespace keys = manifest_keys;
16 namespace errors = manifest_errors;
18 namespace {
20 static base::LazyInstance<LinkedAppIcons> g_empty_linked_app_icons =
21 LAZY_INSTANCE_INITIALIZER;
23 const LinkedAppIcons& GetInfo(const Extension* extension) {
24 LinkedAppIcons* info = static_cast<LinkedAppIcons*>(
25 extension->GetManifestData(keys::kLinkedAppIcons));
26 return info ? *info : g_empty_linked_app_icons.Get();
29 } // namespace
31 LinkedAppIcons::IconInfo::IconInfo() {
34 LinkedAppIcons::IconInfo::~IconInfo() {
37 LinkedAppIcons::LinkedAppIcons() {
40 LinkedAppIcons::~LinkedAppIcons() {
43 // static
44 const LinkedAppIcons& LinkedAppIcons::GetLinkedAppIcons(
45 const Extension* extension) {
46 return GetInfo(extension);
49 LinkedAppIconsHandler::LinkedAppIconsHandler() {
52 LinkedAppIconsHandler::~LinkedAppIconsHandler() {
55 bool LinkedAppIconsHandler::Parse(Extension* extension, base::string16* error) {
56 scoped_ptr<LinkedAppIcons> linked_app_icons(new LinkedAppIcons);
58 const base::Value* icons_value = nullptr;
59 const base::ListValue* icons_list = nullptr;
60 if (extension->manifest()->Get(keys::kLinkedAppIcons, &icons_value)) {
61 if (!icons_value->GetAsList(&icons_list)) {
62 *error = base::UTF8ToUTF16(
63 extensions::manifest_errors::kInvalidLinkedAppIcons);
64 return false;
67 for (const base::Value* icon_value : *icons_list) {
68 const base::DictionaryValue* icon_dict = nullptr;
69 if (!icon_value->GetAsDictionary(&icon_dict)) {
70 *error = base::UTF8ToUTF16(
71 extensions::manifest_errors::kInvalidLinkedAppIcon);
72 return false;
75 std::string url_string;
76 if (!icon_dict->GetString(keys::kLinkedAppIconURL, &url_string)) {
77 *error = base::UTF8ToUTF16(
78 extensions::manifest_errors::kInvalidLinkedAppIconURL);
79 return false;
82 LinkedAppIcons::IconInfo info;
83 info.url = GURL(url_string);
84 if (!info.url.is_valid()) {
85 *error = base::UTF8ToUTF16(
86 extensions::manifest_errors::kInvalidLinkedAppIconURL);
87 return false;
90 if (!icon_dict->GetInteger(keys::kLinkedAppIconSize, &info.size)) {
91 *error = base::UTF8ToUTF16(
92 extensions::manifest_errors::kInvalidLinkedAppIconSize);
93 return false;
96 linked_app_icons->icons.push_back(info);
100 extension->SetManifestData(keys::kLinkedAppIcons, linked_app_icons.release());
101 return true;
104 const std::vector<std::string> LinkedAppIconsHandler::Keys() const {
105 return SingleKey(keys::kLinkedAppIcons);
108 } // namespace extensions