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/theme_handler.h" | 5 #include "chrome/common/extensions/manifest_handlers/theme_handler.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 iter.Advance()) { | 30 iter.Advance()) { |
31 // The value may be a dictionary of scales and files paths. | 31 // The value may be a dictionary of scales and files paths. |
32 // Or the value may be a file path, in which case a scale | 32 // Or the value may be a file path, in which case a scale |
33 // of 100% is assumed. | 33 // of 100% is assumed. |
34 if (iter.value().IsType(base::Value::TYPE_DICTIONARY)) { | 34 if (iter.value().IsType(base::Value::TYPE_DICTIONARY)) { |
35 const base::DictionaryValue* inner_value = NULL; | 35 const base::DictionaryValue* inner_value = NULL; |
36 if (iter.value().GetAsDictionary(&inner_value)) { | 36 if (iter.value().GetAsDictionary(&inner_value)) { |
37 for (base::DictionaryValue::Iterator inner_iter(*inner_value); | 37 for (base::DictionaryValue::Iterator inner_iter(*inner_value); |
38 !inner_iter.IsAtEnd(); inner_iter.Advance()) { | 38 !inner_iter.IsAtEnd(); inner_iter.Advance()) { |
39 if (!inner_iter.value().IsType(base::Value::TYPE_STRING)) { | 39 if (!inner_iter.value().IsType(base::Value::TYPE_STRING)) { |
40 *error = ASCIIToUTF16(errors::kInvalidThemeImages); | 40 *error = base::ASCIIToUTF16(errors::kInvalidThemeImages); |
41 return false; | 41 return false; |
42 } | 42 } |
43 } | 43 } |
44 } else { | 44 } else { |
45 *error = ASCIIToUTF16(errors::kInvalidThemeImages); | 45 *error = base::ASCIIToUTF16(errors::kInvalidThemeImages); |
46 return false; | 46 return false; |
47 } | 47 } |
48 } else if (!iter.value().IsType(base::Value::TYPE_STRING)) { | 48 } else if (!iter.value().IsType(base::Value::TYPE_STRING)) { |
49 *error = ASCIIToUTF16(errors::kInvalidThemeImages); | 49 *error = base::ASCIIToUTF16(errors::kInvalidThemeImages); |
50 return false; | 50 return false; |
51 } | 51 } |
52 } | 52 } |
53 theme_info->theme_images_.reset(images_value->DeepCopy()); | 53 theme_info->theme_images_.reset(images_value->DeepCopy()); |
54 } | 54 } |
55 return true; | 55 return true; |
56 } | 56 } |
57 | 57 |
58 bool LoadColors(const base::DictionaryValue* theme_value, | 58 bool LoadColors(const base::DictionaryValue* theme_value, |
59 base::string16* error, | 59 base::string16* error, |
(...skipping 11 matching lines...) Expand all Loading... |
71 // ... and either 3 items (RGB) or 4 (RGBA). | 71 // ... and either 3 items (RGB) or 4 (RGBA). |
72 ((color_list->GetSize() != 3) && | 72 ((color_list->GetSize() != 3) && |
73 ((color_list->GetSize() != 4) || | 73 ((color_list->GetSize() != 4) || |
74 // For RGBA, the fourth item must be a real or int alpha value. | 74 // For RGBA, the fourth item must be a real or int alpha value. |
75 // Note that GetDouble() can get an integer value. | 75 // Note that GetDouble() can get an integer value. |
76 !color_list->GetDouble(3, &alpha))) || | 76 !color_list->GetDouble(3, &alpha))) || |
77 // For both RGB and RGBA, the first three items must be ints (R,G,B). | 77 // For both RGB and RGBA, the first three items must be ints (R,G,B). |
78 !color_list->GetInteger(0, &color) || | 78 !color_list->GetInteger(0, &color) || |
79 !color_list->GetInteger(1, &color) || | 79 !color_list->GetInteger(1, &color) || |
80 !color_list->GetInteger(2, &color)) { | 80 !color_list->GetInteger(2, &color)) { |
81 *error = ASCIIToUTF16(errors::kInvalidThemeColors); | 81 *error = base::ASCIIToUTF16(errors::kInvalidThemeColors); |
82 return false; | 82 return false; |
83 } | 83 } |
84 } | 84 } |
85 theme_info->theme_colors_.reset(colors_value->DeepCopy()); | 85 theme_info->theme_colors_.reset(colors_value->DeepCopy()); |
86 } | 86 } |
87 return true; | 87 return true; |
88 } | 88 } |
89 | 89 |
90 bool LoadTints(const base::DictionaryValue* theme_value, | 90 bool LoadTints(const base::DictionaryValue* theme_value, |
91 base::string16* error, | 91 base::string16* error, |
92 ThemeInfo* theme_info) { | 92 ThemeInfo* theme_info) { |
93 const base::DictionaryValue* tints_value = NULL; | 93 const base::DictionaryValue* tints_value = NULL; |
94 if (!theme_value->GetDictionary(keys::kThemeTints, &tints_value)) | 94 if (!theme_value->GetDictionary(keys::kThemeTints, &tints_value)) |
95 return true; | 95 return true; |
96 | 96 |
97 // Validate that the tints are all reals. | 97 // Validate that the tints are all reals. |
98 for (base::DictionaryValue::Iterator iter(*tints_value); !iter.IsAtEnd(); | 98 for (base::DictionaryValue::Iterator iter(*tints_value); !iter.IsAtEnd(); |
99 iter.Advance()) { | 99 iter.Advance()) { |
100 const base::ListValue* tint_list = NULL; | 100 const base::ListValue* tint_list = NULL; |
101 double v = 0.0; | 101 double v = 0.0; |
102 if (!iter.value().GetAsList(&tint_list) || | 102 if (!iter.value().GetAsList(&tint_list) || |
103 tint_list->GetSize() != 3 || | 103 tint_list->GetSize() != 3 || |
104 !tint_list->GetDouble(0, &v) || | 104 !tint_list->GetDouble(0, &v) || |
105 !tint_list->GetDouble(1, &v) || | 105 !tint_list->GetDouble(1, &v) || |
106 !tint_list->GetDouble(2, &v)) { | 106 !tint_list->GetDouble(2, &v)) { |
107 *error = ASCIIToUTF16(errors::kInvalidThemeTints); | 107 *error = base::ASCIIToUTF16(errors::kInvalidThemeTints); |
108 return false; | 108 return false; |
109 } | 109 } |
110 } | 110 } |
111 theme_info->theme_tints_.reset(tints_value->DeepCopy()); | 111 theme_info->theme_tints_.reset(tints_value->DeepCopy()); |
112 return true; | 112 return true; |
113 } | 113 } |
114 | 114 |
115 bool LoadDisplayProperties(const base::DictionaryValue* theme_value, | 115 bool LoadDisplayProperties(const base::DictionaryValue* theme_value, |
116 base::string16* error, | 116 base::string16* error, |
117 ThemeInfo* theme_info) { | 117 ThemeInfo* theme_info) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 163 |
164 ThemeHandler::ThemeHandler() { | 164 ThemeHandler::ThemeHandler() { |
165 } | 165 } |
166 | 166 |
167 ThemeHandler::~ThemeHandler() { | 167 ThemeHandler::~ThemeHandler() { |
168 } | 168 } |
169 | 169 |
170 bool ThemeHandler::Parse(Extension* extension, base::string16* error) { | 170 bool ThemeHandler::Parse(Extension* extension, base::string16* error) { |
171 const base::DictionaryValue* theme_value = NULL; | 171 const base::DictionaryValue* theme_value = NULL; |
172 if (!extension->manifest()->GetDictionary(keys::kTheme, &theme_value)) { | 172 if (!extension->manifest()->GetDictionary(keys::kTheme, &theme_value)) { |
173 *error = ASCIIToUTF16(errors::kInvalidTheme); | 173 *error = base::ASCIIToUTF16(errors::kInvalidTheme); |
174 return false; | 174 return false; |
175 } | 175 } |
176 | 176 |
177 scoped_ptr<ThemeInfo> theme_info(new ThemeInfo); | 177 scoped_ptr<ThemeInfo> theme_info(new ThemeInfo); |
178 if (!LoadImages(theme_value, error, theme_info.get())) | 178 if (!LoadImages(theme_value, error, theme_info.get())) |
179 return false; | 179 return false; |
180 if (!LoadColors(theme_value, error, theme_info.get())) | 180 if (!LoadColors(theme_value, error, theme_info.get())) |
181 return false; | 181 return false; |
182 if (!LoadTints(theme_value, error, theme_info.get())) | 182 if (!LoadTints(theme_value, error, theme_info.get())) |
183 return false; | 183 return false; |
(...skipping 29 matching lines...) Expand all Loading... |
213 } | 213 } |
214 } | 214 } |
215 return true; | 215 return true; |
216 } | 216 } |
217 | 217 |
218 const std::vector<std::string> ThemeHandler::Keys() const { | 218 const std::vector<std::string> ThemeHandler::Keys() const { |
219 return SingleKey(keys::kTheme); | 219 return SingleKey(keys::kTheme); |
220 } | 220 } |
221 | 221 |
222 } // namespace extensions | 222 } // namespace extensions |
OLD | NEW |