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

Side by Side Diff: chrome/common/extensions/manifest_handlers/linked_app_icons.cc

Issue 1066623008: Sync bookmark app icon urls and sizes, and download icons for new apps. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix failing tests and extra checks Created 5 years, 8 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
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
benwells 2015/04/23 06:39:00 Self nit: 2015
benwells 2015/04/27 09:54:54 Done.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/common/extensions/manifest_handlers/linked_app_icons.h"
6
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"
12
13 namespace extensions {
14
15 namespace keys = manifest_keys;
16 namespace errors = manifest_errors;
17
18 namespace {
19
20 static base::LazyInstance<LinkedAppIcons> g_empty_linked_app_icons =
21 LAZY_INSTANCE_INITIALIZER;
22
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();
27 }
28
29 } // namespace
30
31 LinkedAppIcons::IconInfo::IconInfo() {
32 }
33
34 LinkedAppIcons::IconInfo::~IconInfo() {
35 }
36
37 LinkedAppIcons::LinkedAppIcons() {
38 }
39
40 LinkedAppIcons::~LinkedAppIcons() {
41 }
42
43 // static
44 const LinkedAppIcons& LinkedAppIcons::GetLinkedAppIcons(
45 const Extension* extension) {
46 return GetInfo(extension);
47 }
48
49 LinkedAppIconsHandler::LinkedAppIconsHandler() {
50 }
51
52 LinkedAppIconsHandler::~LinkedAppIconsHandler() {
53 }
54
55 bool LinkedAppIconsHandler::Parse(Extension* extension, base::string16* error) {
56 scoped_ptr<LinkedAppIcons> linked_app_icons(new LinkedAppIcons);
57
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;
65 }
66
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;
73 }
74
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;
80 }
81
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;
88 }
89
90 if (!icon_dict->GetInteger(keys::kLinkedAppIconSize, &info.size)) {
91 *error = base::UTF8ToUTF16(
92 extensions::manifest_errors::kInvalidLinkedAppIconSize);
93 return false;
94 }
95
96 linked_app_icons->icons.push_back(info);
97 }
98 }
99
100 extension->SetManifestData(keys::kLinkedAppIcons, linked_app_icons.release());
101 return true;
102 }
103
104 const std::vector<std::string> LinkedAppIconsHandler::Keys() const {
105 return SingleKey(keys::kLinkedAppIcons);
106 }
107
108 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698